5bedd652433bd7d83491f123ac1c432c6481e9ed
[reactos.git] / reactos / base / applications / cmdutils / dbgprint / dbgprint.c
1 /*
2 * PROJECT: ReactOS DbgPrint Utility
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/cmdutils/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 strcpy(cmd, argv[2]);
47 strcat(cmd, " --list");
48 pPipe = _tpopen(cmd, "r");
49 if (pPipe != NULL)
50 {
51 while(fgets(psBuffer, 128, pPipe))
52 {
53 if (psBuffer[0] == ' ')
54 {
55 strcpy(cmd, argv[2]);
56 strcat(cmd, " ");
57 strcat(cmd, psBuffer+4);
58 /* run the current test */
59 strcpy(test, "\n\nRunning ");
60 strcat(test, cmd);
61 OutputDebugStringA(test);
62 pPipe2 = _popen(cmd, "r");
63 if (pPipe2 != NULL)
64 {
65 while(fgets(psBuffer2, 128, pPipe2))
66 {
67 nlptr2 = strchr(psBuffer2, '\n');
68 if (nlptr2)
69 *nlptr2 = '\0';
70 puts(psBuffer2);
71 OutputDebugStringA(psBuffer2);
72 }
73 _pclose(pPipe2);
74 }
75 }
76 }
77 _pclose(pPipe);
78 }
79 }
80 else if (_tcsstr(argv[1], "--process") && (argc == 3))
81 {
82 char psBuffer[128];
83 FILE *pPipe;
84
85 pPipe = _tpopen(argv[2], "r");
86 if (pPipe != NULL)
87 {
88 while(fgets(psBuffer, 128, pPipe))
89 {
90 puts(psBuffer);
91 OutputDebugStringA(psBuffer);
92 }
93 _pclose(pPipe);
94 }
95 }
96 else
97 {
98 buf = HeapAlloc(GetProcessHeap(), 0, (bufsize+1) * sizeof(TCHAR));
99 if (!buf)
100 {
101 return -1;
102 }
103
104 offset = 0;
105 for(i = 1; i < argc; i++)
106 {
107 int length = _tcslen(argv[i]);
108 _tcsncpy(&buf[offset], argv[i], length);
109 offset += length;
110 if (i + 1 < argc)
111 {
112 buf[offset] = _T(' ');
113 }
114 else
115 {
116 buf[offset] = _T('\n');
117 buf[offset+1] = _T('\0');
118 }
119 offset++;
120 }
121 _putts(buf);
122 OutputDebugString(buf);
123 HeapFree(GetProcessHeap(), 0, buf);
124 }
125 return 0;
126 }