Index: tools/rsym/log2lines.c =================================================================== --- tools/rsym/log2lines.c (revision 45247) +++ tools/rsym/log2lines.c (working copy) @@ -11,7 +11,7 @@ #include "rsym.h" -#define LOG2LINES_VERSION "1.9" +#define LOG2LINES_VERSION "1.11" /* Assume if an offset > ABS_TRESHOLD, then it must be absolute */ #define ABS_TRESHOLD 0x00400000L @@ -27,6 +27,8 @@ #define CACHEFILE "log2lines.cache" #define TRKBUILDPREFIX "bootcd-" #define SVN_PREFIX "/trunk/reactos/" +#define KDBG_PROMPT "kdbg>" +#define PIPEREAD_CMD "piperead -c" #if defined (__DJGPP__) || defined (__WIN32__) @@ -96,13 +98,13 @@ struct entry_struct *pnext; }; -typedef struct entry_struct LIST_ENTRY; +typedef struct entry_struct LIST_MEMBER; struct list_struct { off_t st_size; - LIST_ENTRY *phead; - LIST_ENTRY *ptail; + LIST_MEMBER *phead; + LIST_MEMBER *ptail; }; struct summ_struct @@ -149,7 +151,7 @@ static LINEINFO lastLine; static REVINFO revinfo; -static char *optchars = "bcd:fFhl:mMrR:sS:tTuUvz:"; +static char *optchars = "bcd:fFhl:mMP:rR:sS:tTuUvz:"; static int opt_buffered = 0; // -b static int opt_help = 0; // -h static int opt_force = 0; // -f @@ -158,6 +160,7 @@ static int opt_console = 0; // -c static int opt_mark = 0; // -m static int opt_Mark = 0; // -M +static char *opt_Pipe = NULL; // -P static int opt_raw = 0; // -r static int opt_stats = 0; // -s static int opt_Source = 0; // -S [+][,] @@ -172,6 +175,8 @@ static char opt_7z[MAX_PATH]; // -z static char opt_scanned[LINESIZE]; // all scanned options static FILE *logFile = NULL; +static FILE *stdIn = NULL; +static FILE *stdOut = NULL; static char *cache_name; static char *tmp_name; @@ -220,6 +225,7 @@ return res; } +#if 0 static FILE * rfopen(char *path, char *mode) { @@ -232,12 +238,13 @@ f = fopen(tmppath, mode); return f; } +#endif -static LIST_ENTRY * +static LIST_MEMBER * entry_lookup(LIST *list, char *name) { - LIST_ENTRY *pprev = NULL; - LIST_ENTRY *pnext; + LIST_MEMBER *pprev = NULL; + LIST_MEMBER *pnext; if (!name || !name[0]) return NULL; @@ -261,8 +268,8 @@ return NULL; } -static LIST_ENTRY * -entry_delete(LIST_ENTRY *pentry) +static LIST_MEMBER * +entry_delete(LIST_MEMBER *pentry) { if (!pentry) return NULL; @@ -272,8 +279,8 @@ return NULL; } -static LIST_ENTRY * -entry_insert(LIST *list, LIST_ENTRY *pentry) +static LIST_MEMBER * +entry_insert(LIST *list, LIST_MEMBER *pentry) { if (!pentry) return NULL; @@ -286,10 +293,10 @@ } #if 0 -static LIST_ENTRY * -entry_remove(LIST *list, LIST_ENTRY *pentry) +static LIST_MEMBER * +entry_remove(LIST *list, LIST_MEMBER *pentry) { - LIST_ENTRY *pprev = NULL, *p = NULL; + LIST_MEMBER *pprev = NULL, *p = NULL; if (!pentry) return NULL; @@ -320,17 +327,17 @@ } #endif -static LIST_ENTRY * +static LIST_MEMBER * cache_entry_create(char *Line) { - LIST_ENTRY *pentry; + LIST_MEMBER *pentry; char *s = NULL; int l; if (!Line) return NULL; - pentry = malloc(sizeof(LIST_ENTRY)); + pentry = malloc(sizeof(LIST_MEMBER)); if (!pentry) return NULL; @@ -372,10 +379,10 @@ } -static LIST_ENTRY * +static LIST_MEMBER * sources_entry_create(LIST *list, char *path, char *prefix) { - LIST_ENTRY *pentry; + LIST_MEMBER *pentry; char *s = NULL; int l; @@ -384,7 +391,7 @@ if (!prefix) prefix = ""; - pentry = malloc(sizeof(LIST_ENTRY)); + pentry = malloc(sizeof(LIST_MEMBER)); if (!pentry) return NULL; @@ -988,7 +995,7 @@ read_cache(void) { FILE *fr; - LIST_ENTRY *pentry; + LIST_MEMBER *pentry; char *Line = NULL; int result = 0; @@ -1117,7 +1124,7 @@ translate_file(const char *cpath, size_t offset, char *toString) { size_t base = 0; - LIST_ENTRY *pentry = NULL; + LIST_MEMBER *pentry = NULL; int res = 0; char *path, *dpath; @@ -1552,6 +1559,11 @@ " -m Prefix (mark) each translated line with '* '.\n\n" " -M Prefix (mark) each NOT translated line with '? '.\n" " ( Only for lines of the form: )\n\n" +" -P \n" +" Pipeline command line. Spawn and pipeline its output to\n" +" log2lines (as stdin). This is for shells lacking support of (one of):\n" +" - Input file redirection.\n" +" - Pipelining byte streams, needed for the -c option.\n\n" " -r Raw output without translation.\n\n" " -R \n" " Revision commands interfacing with SVN. is one of:\n" @@ -1632,6 +1644,8 @@ " log2lines -c < \\\\.\\pipe\\kdbg\n\n" " Use kdbg debugger via console, and append copy to logFile:\n" " log2lines -c -l dbg.log < \\\\.\\pipe\\kdbg\n\n" +" Same as above, but for PowerShell:\n" +" log2lines -c -l dbg.log -P \"piperead -c \\\\.\\pipe\\kdbg\"\n\n" " Use kdbg debugger to send output to logfile:\n" " log2lines < \\\\.\\pipe\\kdbg > dbg.log\n\n" " Re-translate a debug log:\n" @@ -1868,6 +1882,8 @@ int i; char *s; + stdIn = stdin; + stdOut = stdout; strcpy(opt_dir, ""); strcpy(sources_path, ""); if ((s = getenv(SOURCES_ENV))) @@ -1876,9 +1892,20 @@ strcpy(opt_scanned, ""); for (i = 1; i < argc; i++) { + if (strcmp(argv[i],"-P")==0) + { + //Because its argument can contain spaces we cant use getopt(), a known bug: + if (i+1 < argc) + { + free(opt_Pipe); + opt_Pipe = malloc(LINESIZE); + strcpy(opt_Pipe, argv[i+1]); + } + } strcat(opt_scanned, argv[i]); strcat(opt_scanned, " "); } + l2l_dbg(4,"opt_scanned=[%s]\n",opt_scanned); strcpy(opt_logFile, ""); strcpy(opt_7z, CMD_7Z); @@ -1927,8 +1954,13 @@ case 'r': opt_raw++; break; + case 'P': + optCount++; + //just count, see above + break; case 'R': optCount++; + free(opt_Revision); opt_Revision = malloc(LINESIZE); sscanf(optarg, "%s", opt_Revision); break; @@ -2001,9 +2033,8 @@ return 0; read_cache(); + l2l_dbg(4, "Cache read complete\n"); - l2l_dbg(3, "Cache read complete\n"); - if (*opt_logFile) { logFile = fopen(opt_logFile, "a"); @@ -2024,7 +2055,23 @@ return 2; } } + l2l_dbg(4, "opt_logFile processed\n"); + if (opt_Pipe) + { + l2l_dbg(3, "Command line: \"%s\"\n",opt_Pipe); + + if (!(stdIn = POPEN(opt_Pipe, "r"))) + { + stdIn = stdin; //restore + l2l_dbg(0, "Could not popen '%s' (%s)\n", opt_Pipe, strerror(errno)); + free(opt_Pipe); opt_Pipe = NULL; + } + + free(opt_Pipe); opt_Pipe = NULL; + } + l2l_dbg(4, "opt_Pipe processed\n"); + if (argc > 1) { // translate { } int i = 1; @@ -2043,7 +2090,7 @@ l2l_dbg(2, "translating %s %s\n", exefile, offset); translate_file(exefile, my_atoi(offset), Line); printf("%s\n", Line); - report(stdout); + report(stdOut); } else { @@ -2061,11 +2108,14 @@ } else { // translate logging from stdin - translate_files(stdin, stdout); + translate_files(stdIn, stdOut); } if (logFile) fclose(logFile); + if (opt_Pipe) + PCLOSE(stdIn); + return res; }