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 if (nlptr2) 72 *nlptr2 = '\n'; 73 OutputDebugStringA(psBuffer2); 74 } 75 _pclose(pPipe2); 76 } 77 } 78 } 79 _pclose(pPipe); 80 } 81 } 82 else if (_tcsstr(argv[1], "--process") && (argc == 3)) 83 { 84 char psBuffer[128]; 85 FILE *pPipe; 86 87 pPipe = _tpopen(argv[2], "r"); 88 if (pPipe != NULL) 89 { 90 while(fgets(psBuffer, 128, pPipe)) 91 { 92 puts(psBuffer); 93 OutputDebugStringA(psBuffer); 94 } 95 _pclose(pPipe); 96 } 97 } 98 else 99 { 100 buf = HeapAlloc(GetProcessHeap(), 0, (bufsize+1) * sizeof(TCHAR)); 101 if (!buf) 102 { 103 return -1; 104 } 105 106 offset = 0; 107 for(i = 1; i < argc; i++) 108 { 109 int length = _tcslen(argv[i]); 110 _tcsncpy(&buf[offset], argv[i], length); 111 offset += length; 112 if (i + 1 < argc) 113 { 114 buf[offset] = _T(' '); 115 } 116 else 117 { 118 buf[offset] = _T('\n'); 119 buf[offset+1] = _T('\0'); 120 } 121 offset++; 122 } 123 _putts(buf); 124 OutputDebugString(buf); 125 HeapFree(GetProcessHeap(), 0, buf); 126 } 127 return 0; 128 } 129