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