* Sync up to trunk head (r60691).
[reactos.git] / base / applications / cmdutils / dbgprint / dbgprint.c
1 /*
2 * PROJECT: ReactOS DbgPrint Utility
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: tools/dbgprint/dbgprint.c
5 * PURPOSE: outputs a text via DbgPrint API
6 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
7 * Christoph von Wittich (Christoph_vW@ReactOS.org)
8 */
9
10 #include <stdarg.h>
11 #include <windef.h>
12 #include <winbase.h>
13 #include <tchar.h>
14 //#include <debug.h>
15 #include <stdio.h>
16
17 int _tmain(int argc, TCHAR ** argv)
18 {
19 TCHAR * buf;
20 int bufsize;
21 int i;
22 int offset;
23
24 bufsize = 0;
25 for(i = 1; i < argc; i++)
26 {
27 bufsize += _tcslen(argv[i]) + 1;
28 }
29
30 if (!bufsize)
31 {
32 return -1;
33 }
34
35 if (_tcsstr(argv[1], "--winetest") && (argc == 3))
36 {
37 char psBuffer[128];
38 char psBuffer2[128];
39 char *nlptr2;
40 char cmd[255];
41 char test[300];
42 FILE *pPipe;
43 FILE *pPipe2;
44
45 /* get available tests */
46 pPipe = _tpopen(argv[2], "r");
47 if (pPipe != NULL)
48 {
49 while(fgets(psBuffer, 128, pPipe))
50 {
51 if (psBuffer[0] == ' ')
52 {
53 strcpy(cmd, argv[2]);
54 strcat(cmd, " ");
55 strcat(cmd, psBuffer+4);
56 /* run the current test */
57 strcpy(test, "\n\nRunning ");
58 strcat(test, cmd);
59 OutputDebugStringA(test);
60 pPipe2 = _popen(cmd, "r");
61 if (pPipe2 != NULL)
62 {
63 while(fgets(psBuffer2, 128, pPipe2))
64 {
65 nlptr2 = strchr(psBuffer2, '\n');
66 if (nlptr2)
67 *nlptr2 = '\0';
68 puts(psBuffer2);
69 OutputDebugStringA(psBuffer2);
70 }
71 _pclose(pPipe2);
72 }
73 }
74 }
75 _pclose(pPipe);
76 }
77 }
78 else if (_tcsstr(argv[1], "--process") && (argc == 3))
79 {
80 char psBuffer[128];
81 FILE *pPipe;
82
83 pPipe = _tpopen(argv[2], "r");
84 if (pPipe != NULL)
85 {
86 while(fgets(psBuffer, 128, pPipe))
87 {
88 puts(psBuffer);
89 OutputDebugStringA(psBuffer);
90 }
91 _pclose(pPipe);
92 }
93 }
94 else
95 {
96 buf = HeapAlloc(GetProcessHeap(), 0, (bufsize+1) * sizeof(TCHAR));
97 if (!buf)
98 {
99 return -1;
100 }
101
102 offset = 0;
103 for(i = 1; i < argc; i++)
104 {
105 int length = _tcslen(argv[i]);
106 _tcsncpy(&buf[offset], argv[i], length);
107 offset += length;
108 if (i + 1 < argc)
109 {
110 buf[offset] = _T(' ');
111 }
112 else
113 {
114 buf[offset] = _T('\n');
115 buf[offset+1] = _T('\0');
116 }
117 offset++;
118 }
119 _putts(buf);
120 OutputDebugString(buf);
121 HeapFree(GetProcessHeap(), 0, buf);
122 }
123 return 0;
124 }