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