modified dll/win32/kernel32/kernel32.rbuild
[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 <windows.h>
12 #include <tchar.h>
13 #include <debug.h>
14 #include <stdio.h>
15
16 int _tmain(int argc, TCHAR ** argv)
17 {
18 TCHAR * buf;
19 int bufsize;
20 int i;
21 int offset;
22
23 bufsize = 0;
24 for(i = 1; i < argc; i++)
25 {
26 bufsize += _tcslen(argv[i]) + 1;
27 }
28
29 if (!bufsize)
30 {
31 return -1;
32 }
33
34 if (_tcsstr(argv[1], "--winetest") && (argc == 3))
35 {
36 char psBuffer[128];
37 char psBuffer2[128];
38 char cmd[255];
39 char test[300];
40 FILE *pPipe;
41 FILE *pPipe2;
42
43 /* get available tests */
44 pPipe = _tpopen(argv[2], "r");
45 if (pPipe != NULL)
46 {
47 while(fgets(psBuffer, 128, pPipe))
48 {
49 if (psBuffer[0] == ' ')
50 {
51 strcpy(cmd, argv[2]);
52 strcat(cmd, " ");
53 strcat(cmd, psBuffer+4);
54 /* run the current test */
55 strcpy(test, "\n\nRunning ");
56 strcat(test, cmd);
57 OutputDebugStringA(test);
58 pPipe2 = _popen(cmd, "r");
59 if (pPipe2 != NULL)
60 {
61 while(fgets(psBuffer2, 128, pPipe2))
62 {
63 char *nlptr2 = strchr(psBuffer2, '\n');
64 if (nlptr2)
65 *nlptr2 = '\0';
66 OutputDebugStringA(psBuffer2);
67 }
68 _pclose(pPipe2);
69 }
70 }
71 }
72 _pclose(pPipe);
73 }
74 }
75 else if (_tcsstr(argv[1], "--process") && (argc == 3))
76 {
77 char psBuffer[128];
78 FILE *pPipe;
79
80 pPipe = _tpopen(argv[2], "r");
81 if (pPipe != NULL)
82 {
83 while(fgets(psBuffer, 128, pPipe))
84 {
85 OutputDebugStringA(psBuffer);
86 }
87 _pclose(pPipe);
88 }
89 }
90 else
91 {
92 buf = HeapAlloc(GetProcessHeap(), 0, (bufsize+1) * sizeof(TCHAR));
93 if (!buf)
94 {
95 return -1;
96 }
97
98 offset = 0;
99 for(i = 1; i < argc; i++)
100 {
101 int length = _tcslen(argv[i]);
102 _tcsncpy(&buf[offset], argv[i], length);
103 offset += length;
104 if (i + 1 < argc)
105 {
106 buf[offset] = _T(' ');
107 }
108 else
109 {
110 buf[offset] = _T('\n');
111 buf[offset+1] = _T('\0');
112 }
113 offset++;
114 }
115 OutputDebugString(buf);
116 HeapFree(GetProcessHeap(), 0, buf);
117 }
118 return 0;
119 }