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