Property changes on: tools\log2lines ___________________________________________________________________ Added: bugtraq:url + http://www.reactos.org/bugzilla/show_bug.cgi?id=%BUGID% Added: bugtraq:message + See issue #%BUGID% for more details. Added: tsvn:logminsize + 10 Added: bugtraq:logregex + ([Ii]ssue|[Bb]ug)s? #?(\d+)(,? ?#?(\d+))*(,? ?(and |or )?#?(\d+))? (\d+) Index: tools/log2lines/cache.c =================================================================== --- tools/log2lines/cache.c (revision 45501) +++ tools/log2lines/cache.c (working copy) @@ -11,12 +11,10 @@ #include "util.h" #include "version.h" #include "compat.h" -#include "config.h" -#include "list.h" #include "options.h" #include "help.h" #include "image.h" -#include "revision.h" + #include "log2lines.h" static char *cache_name; @@ -77,11 +75,6 @@ char *check_iso; char *check_dir; - if (opt_Revision) - { - revinfo.rev = getRevision(NULL, 1); - revinfo.range = DEF_RANGE; - } check_iso = strrchr(opt_dir, '.'); l2l_dbg(1, "Checking directory: %s\n", opt_dir); if (check_iso && PATHCMP(check_iso, ".7z") == 0) @@ -139,11 +132,6 @@ return 1; } } - if (opt_Revision) - { - revinfo.buildrev = getTBRevision(opt_dir); - l2l_dbg(1, "Trunk build revision: %d\n", revinfo.buildrev); - } cache_name = malloc(MAX_PATH); tmp_name = malloc(MAX_PATH); strcpy(cache_name, opt_dir); Index: tools/log2lines/cache.h =================================================================== --- tools/log2lines/cache.h (revision 45501) +++ tools/log2lines/cache.h (working copy) @@ -13,3 +13,5 @@ int create_cache(int force, int skipImageBase); #endif /* __L2L_CACHE_H__ */ + +/* EOF */ Index: tools/log2lines/cmd.c =================================================================== --- tools/log2lines/cmd.c (revision 0) +++ tools/log2lines/cmd.c (revision 0) @@ -0,0 +1,291 @@ +/* + * ReactOS log2lines + * Written by Jan Roeloffzen + * + * - Cli for escape commands + */ +#include +#include +#include + +#include "util.h" +#include "cmd.h" +#include "options.h" +#include "log2lines.h" +#include "help.h" + +/* When you edit the cmd line and/or use the history instead of just typing, + * a bunch of editing BS and space characters + * is inserted, so the string looks right on the console but still + * starts with the original string: + */ +static char +*backSpaceEdit(char *s) +{ + char c; + char *edit = s; + char *text = s; + + while (( c = *edit++ )) + { + switch (c) + { + case KDBG_BS_CHAR: + if (text > s) + text --; + break; + default: + *text++ = c; + } + } + *text = '\0'; + + return s; +} + +static int +handle_switch(FILE *outFile, int *sw, char *arg, char *desc) +{ + int changed =0; + int x = 0; + + if (arg && (strcmp(arg,"") != 0)) + { + x = atoi(arg); + if (x != *sw) + { + *sw = x; + changed = 1; + } + } + if (desc) + { + esclog(outFile, "%s is %d (%s)\n", desc, *sw, changed ? "changed":"unchanged"); + if (!arg) + esclog(outFile, "(readonly)\n"); + } + + return changed; +} + +static int +handle_switch_str(FILE *outFile, char *sw, char *arg, char *desc) +{ + int changed =0; + + if (arg) + { + if (strcmp(arg,"") != 0) + { + if (strcmp(arg,KDBG_ESC_OFF) == 0) + { + if (*sw) + changed = 1; + *sw = '\0'; + } + else if (strcmp(arg, sw) != 0) + { + strcpy(sw, arg); + changed = 1; + } + } + } + if (desc) + { + esclog(outFile, "%s is \"%s\" (%s)\n", desc, sw, changed ? "changed":"unchanged"); + if (!arg) + esclog(outFile, "(readonly)\n"); + } + + return changed; +} + +static int +handle_switch_pstr(FILE *outFile, char **psw, char *arg, char *desc) +{ + int changed =0; + + if (arg) + { + if (strcmp(arg,"") != 0) + { + if (strcmp(arg,KDBG_ESC_OFF) == 0) + { + if (*psw) + changed = 1; + free(*psw); + *psw = NULL; + } + else + { + if (!*psw) + { + *psw = malloc(LINESIZE); + **psw = '\0'; + } + + if (strcmp(arg, *psw) != 0) + { + strcpy(*psw, arg); + changed = 1; + } + } + } + } + if (desc) + { + esclog(outFile, "%s is \"%s\" (%s)\n", desc, *psw, changed ? "changed":"unchanged"); + if (!arg) + esclog(outFile, "(readonly)\n"); + } + + return changed; +} + +char +handle_escape_cmd(FILE *outFile, char *Line, char *path, char *LineOut) +{ + char cmd; + char sep = '\n'; + char *arg; + char *l = Line; + int res = 1; + int cnt = 0; + int changed = 0; + + l = backSpaceEdit(l); + if (l[1] != KDBG_ESC_CHAR) + return l[1]; //for reprocessing as not escaped + + log(outFile, "\n"); + + l += 2; //skip space+escape character + if ( (cnt=sscanf(l,"%c%c",&cmd,&sep)) < 1) + { + esclog(outFile, "Command expected\n"); + res = 0; + } + + if (res && cnt==2 && sep != ' ') + { + esclog(outFile, "' ' expected\n"); + res = 0; + } + l++; //skip cmd + while ( *l == ' ')l++; //skip more spaces + arg = l; + opt_cli = 1; + switch (cmd) + { + case 'h': + usage(1); + break; + case 'b': + if (handle_switch(outFile, &opt_buffered, arg, "-b Logfile buffering")) + set_LogFile(logFile); //re-open same logfile + break; + case 'c': + handle_switch(outFile, &opt_console, NULL, "-c Console option"); + break; + case 'd': + handle_switch_str(outFile, opt_dir, NULL, "-d Directory option"); + break; + case 'l': + if (handle_switch_str(outFile, opt_logFile, arg, "-l logfile")) + set_LogFile(logFile); //open new logfile + break; + case 'm': + handle_switch(outFile, &opt_Mark, arg, "-m mark (*)"); + break; + case 'M': + handle_switch(outFile, &opt_Mark, arg, "-M Mark (?)"); + break; + case 'P': + handle_switch_str(outFile, opt_Pipe, NULL, "-P Pipeline option"); + break; + case 'q': + opt_quit = 1; + esclog(outFile, "Bye!\n"); + break; + case 'r': + handle_switch(outFile, &opt_raw, arg, "-r Raw"); + break; + case 'R': + changed = handle_switch_pstr(outFile, &opt_Revision, arg, NULL); + if (opt_Revision) + { + if (strstr(opt_Revision, "check") == opt_Revision) + { + esclog(outFile, "-R is \"%s\" (%s)\n", opt_Revision, changed ? "changed":"unchanged"); + } + else if (strstr(opt_Revision, "regscan") == opt_Revision) + { + char *s = strchr(opt_Revision, ','); + + revinfo.range = DEF_RANGE; + if (s) + { + *s++ = '\0'; + revinfo.range = atoi(s); + } + regscan(outFile); + } + else if (strstr(opt_Revision, "regclear") == opt_Revision) + { + list_clear(&sources); + summ.regfound = 0; + esclog(outFile, "cleared regression scan results\n"); + } + } + break; + case 's': + if (strcmp(arg,"clear") == 0) + { + memset(&summ, 0, sizeof(SUMM)); + esclog(outFile, "Statistics cleared\n"); + } + else + stat_print(outFile, &summ); + break; + case 'S': + cnt = sscanf(arg, "%d+%d", &opt_Source, &opt_SrcPlus); + if (opt_Source) + { + handle_switch(outFile, &opt_undo, "1", "-u Undo"); + handle_switch(outFile, &opt_redo, "1", "-U Undo and reprocess"); + } + esclog(outFile, "-S Sources option is %d+%d,\"%s\"\n", opt_Source, opt_SrcPlus, opt_SourcesPath); + esclog(outFile, "(Setting source tree not implemented)\n"); + break; + case 't': + handle_switch(outFile, &opt_twice, arg, "-t Translate twice"); + break; + case 'T': + handle_switch(outFile, &opt_twice, arg, NULL); + handle_switch(outFile, &opt_Twice, arg, "-T Translate for (address-1)"); + break; + case 'u': + handle_switch(outFile, &opt_undo, arg, "-u undo"); + break; + case 'U': + handle_switch(outFile, &opt_undo, arg, NULL); + handle_switch(outFile, &opt_redo, arg, "-U Undo and reprocess"); + break; + case 'v': + handle_switch(outFile, &opt_verbose, arg, "-v Verbosity"); + break; + case 'z': + handle_switch_str(outFile, opt_7z, NULL, "-z 7z path"); + break; + default: + if (strchr(optchars, cmd)) + esclog(outFile, "Command not implemented in cli: %c %s\n",cmd, arg) + else + esclog(outFile, "Unknown command: %c %s\n",cmd, arg); + } + opt_cli = 0; + + memset(Line, '\0', LINESIZE); // flushed + + return KDBG_ESC_CHAR; //handled escaped command +} Index: tools/log2lines/cmd.h =================================================================== --- tools/log2lines/cmd.h (revision 0) +++ tools/log2lines/cmd.h (revision 0) @@ -0,0 +1,26 @@ +/* + * ReactOS log2lines + * Written by Jan Roeloffzen + * + * - Cli for escape commands + */ + +#ifndef __L2L_CMD_H__ +#define __L2L_CMD_H__ + +#include + +#define KDBG_BS_CHAR 0x08 +#define KDBG_ESC_CHAR '`' +#define KDBG_ESC_STR "`" +#define KDBG_ESC_RESP "| L2L- " +#define KDBG_ESC_OFF "off" +#define KDBG_PROMPT "kdb:>" //Start interactive (-c) after this pattern +#define KDBG_CONT "---" //Also after this pattern (prompt with no line ending) +#define KDBG_DISCARD "Command '" KDBG_ESC_STR //Discard responses at l2l escape commands + +char handle_escape_cmd(FILE *outFile, char *Line, char *path, char *LineOut); + +#endif /* __L2L_CMD_H__ */ + +/* EOF */ Index: tools/log2lines/compat.h =================================================================== --- tools/log2lines/compat.h (revision 45501) +++ tools/log2lines/compat.h (working copy) @@ -37,3 +37,5 @@ #endif /* __L2L_COMPAT_H__ */ + +/* EOF */ Index: tools/log2lines/config.h =================================================================== --- tools/log2lines/config.h (revision 45501) +++ tools/log2lines/config.h (working copy) @@ -15,7 +15,6 @@ #define CACHEFILE "log2lines.cache" #define TRKBUILDPREFIX "bootcd-" #define SVN_PREFIX "/trunk/reactos/" -#define KDBG_PROMPT "kdbg>" #define PIPEREAD_CMD "piperead -c" @@ -32,3 +31,5 @@ #define NAMESIZE 80 #endif /* __L2L_CONFIG_H__ */ + +/* EOF */ Index: tools/log2lines/help.c =================================================================== --- tools/log2lines/help.c (revision 45501) +++ tools/log2lines/help.c (working copy) @@ -10,6 +10,7 @@ #include "compat.h" #include "config.h" #include "options.h" +#include "cmd.h" #include "help.h" char *verboseUsage = @@ -76,7 +77,7 @@ " - regscan[,]:\n" " Scan for regression candidates. Essentially it tries to find\n" " matches between the SVN log entries and the sources hit by\n" -" the backtrace.\n" +" a backtrace (bt) command.\n" " is the amount of revisions to look back from the build\n" " revision (default 500)\n" " The output of '-R regscan' is printed after EOF. The 'Changed path'\n" @@ -130,7 +131,25 @@ " : Specify path to 7z. See also option -d.\n" " Default: '7z'\n" "\n" -"Examples:\n" +"CLI escape commands:\n" +" It is possible to change options and perform actions from the 'kdb:>' prompt\n" +" By prepending the `(backquote) character to the option.\n" +" Example: 'kdb:> `l new.log' changes the current logfile to 'new.log'.\n" +" Flag options like 'b' are given a numeric value of 0 (off) or 1 (on).\n" +" Options accepting a string as argument can be cleared by the value '" KDBG_ESC_OFF "'.\n" +" Some ClI commands are read only or not (entirely) implemented.\n" +" If no value is provided, the current one is printed.\n" +" There are only a few extra ClI commands or with different behaviour:\n" +" - `h : shows this helptext (without exiting)\n" +" - `q : quits log2lines\n" +" - `R regscan : the output is printed immediately (do a 'bt' first)\n" +" - `R regclear : clears previous regscan matches\n" +" - `s : the output is printed immediately\n" +" - `s clear : clears all statistics.\n" +" - `S : only and can be set.\n" +" - `v : sets the current debug loglevel\n" +"\n" +"Option Examples:\n" " Setup: A VMware machine with its serial port set to: '\\\\.\\pipe\\kdbg'.\n\n" " Just recreate cache after a svn update or a new module has been added:\n" " log2lines -F\n\n" @@ -179,7 +198,42 @@ " \n" " | R--- Conflict : source(44191) > build(43850)\n" " | 2664 else\n" -" | 2665 rc = MSIREG_OpenUserDataKey(comp->ComponentId,\n" +" | 2665 rc = MSIREG_OpenUserDataKey(comp->ComponentId,\n\n" +"CLI Examples: (some are based on the option examples above)\n" +" Use '`R check' to show that action.c has been changed after the build:\n" +" kdb:> `R check\n" +" | L2L- -R is \"check\" (changed)\n" +" kdb:> bt\n" +" \n" +" | 0780 if (create)\n" +" | 0781 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);\n" +" \n" +" | R--- Conflict : source(44191) > build(43850)\n" +" | 2664 else\n" +" | 2665 rc = MSIREG_OpenUserDataKey(comp->ComponentId,\n\n" +" kdb:>\n\n" +" Generate source lines. Show 2 lines of context plus 1 additional line.\n" +" The -Uu options are dependent on -S:\n" +" kdb:> `S 2+1\n" +" | L2L- -u Undo is 1 (changed)\n" +" | L2L- -U Undo and reprocess is 1 (changed)\n" +" | L2L- -S Sources option is 2+1,\"C:\\ROS\\reactos\\\" \n" +" | L2L- (Setting source tree not implemented)\n" +" kdb:> bt\n" +" \n" +" | 0188 {\n" +" | 0189 r = MSI_ViewFetch( view, &rec );\n" +" | ----\n" +" | 0190 if( r != ERROR_SUCCESS )\n" +" kdb:>\n\n" +" Change logfile:\n" +" kdb:> `l\n" +" | L2L- -l logfile is "" (unchanged)\n" +" kdb:> `l new.log\n" +" | L2L- -l logfile is \"new.log\" (changed)\n" +" kdb:> `l off\n" +" | L2L- -l logfile is "" (changed)\n" +" kdb:>\n" "\n"; void Index: tools/log2lines/help.h =================================================================== --- tools/log2lines/help.h (revision 45501) +++ tools/log2lines/help.h (working copy) @@ -13,3 +13,5 @@ void usage(int verbose); #endif /* __L2L_HELP_H__ */ + +/* EOF */ Index: tools/log2lines/image.h =================================================================== --- tools/log2lines/image.h (revision 45501) +++ tools/log2lines/image.h (working copy) @@ -20,3 +20,5 @@ #endif /* __L2L_IMAGE_H__ */ + +/* EOF */ Index: tools/log2lines/list.c =================================================================== --- tools/log2lines/list.c (revision 45501) +++ tools/log2lines/list.c (working copy) @@ -66,6 +66,19 @@ return pentry; } +void list_clear(PLIST list) +{ + PLIST_MEMBER pentry = list->phead; + PLIST_MEMBER pnext; + while (pentry) + { + pnext = pentry->pnext; + entry_delete(pentry); + pentry = pnext; + } + list->phead = list->ptail = NULL; +} + #if 0 LIST_MEMBER * entry_remove(LIST *list, LIST_MEMBER *pentry) Index: tools/log2lines/list.h =================================================================== --- tools/log2lines/list.h (revision 45501) +++ tools/log2lines/list.h (working copy) @@ -12,7 +12,6 @@ typedef struct list_struct { - off_t st_size; PLIST_MEMBER phead; PLIST_MEMBER ptail; } LIST,*PLIST; @@ -22,5 +21,8 @@ PLIST_MEMBER entry_insert(PLIST list, PLIST_MEMBER pentry); PLIST_MEMBER cache_entry_create(char *Line); PLIST_MEMBER sources_entry_create(PLIST list, char *path, char *prefix); +void list_clear(PLIST list); #endif /* __L2L_LIST_H__ */ + +/* EOF */ Index: tools/log2lines/log2lines.c =================================================================== --- tools/log2lines/log2lines.c (revision 45501) +++ tools/log2lines/log2lines.c (working copy) @@ -2,7 +2,7 @@ * ReactOS log2lines * Written by Jan Roeloffzen * - * - Initialization and main loop + * - Initialization, translation and main loop */ #include @@ -13,17 +13,18 @@ #include "util.h" #include "version.h" #include "compat.h" -#include "config.h" -#include "list.h" #include "options.h" #include "image.h" #include "cache.h" #include "log2lines.h" #include "help.h" +#include "cmd.h" static FILE *stdIn = NULL; static FILE *stdOut = NULL; +static const char *kdbg_prompt = KDBG_PROMPT; +static const char *kdbg_cont = KDBG_CONT; LIST sources; LINEINFO lastLine; @@ -65,6 +66,8 @@ i++; } fclose(src); + if ( i < min ) + log(outFile, "| S--- source has only %d lines! (check source/revision)\n", i); } else l2l_dbg(1, "Can't open: %s (check " SOURCES_ENV ")\n", s); @@ -332,7 +335,7 @@ /* Strip all lines added by this tool: */ char buf[NAMESIZE]; if (sscanf(s, "| %s", buf) == 1) - if (buf[0] == '0' || strcmp(buf, "----") == 0 || strcmp(buf, "R---") == 0 || atoi(buf)) + if (buf[0] == '0' || strcmp(buf, "----") == 0 || strcmp(buf, "L2L-") == 0 || strcmp(buf, "S---") == 0 || strcmp(buf, "R---") == 0 || atoi(buf)) res = 0; } @@ -410,6 +413,9 @@ int c; unsigned char ch; int i = 0; + const char *pc = kdbg_cont; + const char *p = kdbg_prompt; + const char *p_eos = p + sizeof(KDBG_PROMPT) - 1; //end of string pos if (Line && path && LineOut) { @@ -418,24 +424,54 @@ { while ((c = fgetc(inFile)) != EOF) { + if (opt_quit)break; + ch = (unsigned char)c; if (!opt_raw) { switch (ch) { case '\n': - translate_line(outFile, Line, path, LineOut); + if ( strncmp(Line, KDBG_DISCARD, sizeof(KDBG_DISCARD)-1) == 0 ) + { + memset(Line, '\0', LINESIZE); // flushed + } + else + { + Line[1] = handle_escape_cmd(outFile, Line, path, LineOut); + if (Line[1] != KDBG_ESC_CHAR) + { + if (p == p_eos) + { + //kdbg prompt, so already echoed char by char + memset(Line, '\0', LINESIZE); + translate_char(c, outFile); + } + else + { + translate_line(outFile, Line, path, LineOut); + translate_char(c, outFile); + report(outFile); + } + } + } i = 0; - translate_char(c, outFile); - report(outFile); + p = kdbg_prompt; + pc = kdbg_cont; break; case '<': i = 0; Line[i++] = ch; break; case '>': - if (i) + if (ch == *p) { + p = p_eos; + translate_line(outFile, Line, path, LineOut); + } + + if (p != p_eos) + { if (i < LINESIZE) { Line[i++] = ch; @@ -452,21 +488,27 @@ i = 0; break; default: - if (i) + if (ch == *p)p++; + if (ch == *pc)pc++; + if (i < LINESIZE) { - if (i < LINESIZE) + Line[i++] = ch; + if (p == p_eos) { - Line[i++] = ch; + translate_char(c, outFile); } - else + else if (!*pc) { translate_line(outFile, Line, path, LineOut); - translate_char(c, outFile); i = 0; } } else + { + translate_line(outFile, Line, path, LineOut); translate_char(c, outFile); + i = 0; + } } } else @@ -477,6 +519,8 @@ { // Line by line, slightly faster but less interactive while (fgets(Line, LINESIZE, inFile) != NULL) { + if (opt_quit)break; + if (!opt_raw) { translate_line(outFile, Line, path, LineOut); @@ -552,26 +596,8 @@ read_cache(); l2l_dbg(4, "Cache read complete\n"); - if (*opt_logFile) - { - logFile = fopen(opt_logFile, "a"); - if (logFile) - { - // disable buffering so fflush is not needed - if (!opt_buffered) - { - l2l_dbg(1, "Disabling log buffering on %s\n", opt_logFile); - setbuf(logFile, NULL); - } - else - l2l_dbg(1, "Enabling log buffering on %s\n", opt_logFile); - } - else - { - l2l_dbg(0, "Could not open logfile %s (%s)\n", opt_logFile, strerror(errno)); - return 2; - } - } + if (set_LogFile(logFile)) + return 2; l2l_dbg(4, "opt_logFile processed\n"); if (opt_Pipe) @@ -584,8 +610,6 @@ 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"); Index: tools/log2lines/log2lines.mak =================================================================== --- tools/log2lines/log2lines.mak (revision 45501) +++ tools/log2lines/log2lines.mak (working copy) @@ -30,6 +30,7 @@ $(LOG2LINES_BASE_)image.c \ $(LOG2LINES_BASE_)stat.c \ $(LOG2LINES_BASE_)revision.c \ + $(LOG2LINES_BASE_)cmd.c \ $(LOG2LINES_BASE_)log2lines.c \ $(RSYM_BASE_)rsym_common.c @@ -83,6 +84,10 @@ $(ECHO_HOSTCC) ${host_gcc} $(LOG2LINES_HOST_CFLAGS) -c $< -o $@ +$(LOG2LINES_INT_)cmd.o: $(LOG2LINES_BASE_)cmd.c | $(LOG2LINES_INT) + $(ECHO_HOSTCC) + ${host_gcc} $(LOG2LINES_HOST_CFLAGS) -c $< -o $@ + .PHONY: log2lines_clean log2lines_clean: -@$(rm) $(LOG2LINES_TARGET) $(LOG2LINES_OBJECTS) 2>$(NUL) Index: tools/log2lines/options.c =================================================================== --- tools/log2lines/options.c (revision 45501) +++ tools/log2lines/options.c (working copy) @@ -13,6 +13,7 @@ #include "compat.h" #include "config.h" #include "help.h" +#include "log2lines.h" #include "options.h" char *optchars = "bcd:fFhl:mMP:rR:sS:tTuUvz:"; @@ -25,6 +26,8 @@ int opt_mark = 0; // -m int opt_Mark = 0; // -M char *opt_Pipe = NULL; // -P +int opt_quit = 0; // -q (cli only) +int opt_cli = 0; // (cli internal) int opt_raw = 0; // -r int opt_stats = 0; // -s int opt_Source = 0; // -S [+][,] @@ -46,29 +49,45 @@ char *s; strcpy(opt_dir, ""); + strcpy(opt_logFile, ""); + strcpy(opt_7z, CMD_7Z); strcpy(opt_SourcesPath, ""); if ((s = getenv(SOURCES_ENV))) strcpy(opt_SourcesPath, s); + revinfo.rev = getRevision(NULL, 1); + revinfo.range = DEF_RANGE; + revinfo.buildrev = getTBRevision(opt_dir); + l2l_dbg(1, "Trunk build revision: %d\n", revinfo.buildrev); strcpy(opt_scanned, ""); for (i = 1; i < argc; i++) { - if (strcmp(argv[i],"-P")==0) + if ((argv[i][0] == '-') && (i+1 < argc)) { - //Because its argument can contain spaces we cant use getopt(), a known bug: - if (i+1 < argc) + //Because these arguments can contain spaces we cant use getopt(), a known bug: + switch (argv[i][1]) { + case 'd': + strcpy(opt_dir, argv[i+1]); + break; + case 'l': + strcpy(opt_logFile, argv[i+1]); + break; + case 'P': free(opt_Pipe); opt_Pipe = malloc(LINESIZE); strcpy(opt_Pipe, argv[i+1]); + break; + case 'z': + strcpy(opt_7z, argv[i+1]); + break; } } 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); return 0; } @@ -91,7 +110,7 @@ break; case 'd': optCount++; - strcpy(opt_dir, optarg); + //just count, see optionInit() break; case 'f': opt_force++; @@ -107,7 +126,7 @@ break; case 'l': optCount++; - strcpy(opt_logFile, optarg); + //just count, see optionInit() break; case 'm': opt_mark++; @@ -120,7 +139,7 @@ break; case 'P': optCount++; - //just count, see above + //just count, see optionInit() break; case 'R': optCount++; @@ -137,6 +156,12 @@ if (i == 1) sscanf(optarg, "%*d,%s", opt_SourcesPath); l2l_dbg(3, "Sources option parse result: %d+%d,\"%s\"\n", opt_Source, opt_SrcPlus, opt_SourcesPath); + if (opt_Source) + { + /* need to retranslate for source info: */ + opt_undo++; + opt_redo++; + } break; case 't': opt_twice++; @@ -166,16 +191,15 @@ } optCount++; } + if(opt_console) + { + l2l_dbg(2, "Note: use 's' command in console mode. Statistics option disabled\n"); + opt_stats = 0; + } if (opt_SourcesPath[0]) { strcat(opt_SourcesPath, PATH_STR); } - if (opt_Source) - { - /* need to retranslate for source info: */ - opt_undo++; - opt_redo++; - } if (!opt_dir[0]) { strcpy(opt_dir, opt_SourcesPath); Index: tools/log2lines/options.h =================================================================== --- tools/log2lines/options.h (revision 45501) +++ tools/log2lines/options.h (working copy) @@ -18,6 +18,8 @@ extern int opt_mark; // -m extern int opt_Mark; // -M extern char *opt_Pipe; // -P +extern int opt_quit; // -q (cli only) +extern int opt_cli; // (cli internal) extern int opt_raw; // -r extern int opt_stats; // -s extern int opt_Source; // -S [+][,] @@ -38,3 +40,5 @@ int optionParse(int argc, const char **argv); #endif /* __L2L_OPTIONS_H__ */ + +/* EOF */ Index: tools/log2lines/revision.c =================================================================== --- tools/log2lines/revision.c (revision 45501) +++ tools/log2lines/revision.c (working copy) @@ -13,7 +13,6 @@ #include "compat.h" #include "util.h" #include "options.h" -#include "revision.h" #include "log2lines.h" static void @@ -195,7 +194,7 @@ char path[MAX_PATH]; char path2[MAX_PATH]; int wflag = 0; - log(outFile, "\nRegression candidates:\n"); + clilog(outFile, "Regression candidates:\n"); while (( pos = findRev(finx, &r) )) { if (r < (revinfo.buildrev - revinfo.range)) @@ -216,11 +215,11 @@ { if (wflag == 1) { - log(outFile, "%sChanged paths:\n", line); + clilog(outFile, "%sChanged paths:\n", line); summ.regfound++; wflag = 2; } - log(outFile, "%s", line2); + clilog(outFile, "%s", line2); } } else @@ -229,11 +228,11 @@ if (wflag == 2) { int i = 0; - log(outFile, "\n"); + clilog(outFile, "\n"); while (fgets(line2, LINESIZE, flog)) { i++; - log(outFile, "%s", line2); + clilog(outFile, "%s", line2); if (strncmp(LOGBOTTOM, line2, sizeof(LOGBOTTOM) - 1) == 0) break; } Index: tools/log2lines/revision.h =================================================================== --- tools/log2lines/revision.h (revision 45501) +++ tools/log2lines/revision.h (working copy) @@ -26,3 +26,5 @@ int updateSvnlog(void); #endif /* __L2L_REVISION_H__ */ + +/* EOF */ Index: tools/log2lines/stat.c =================================================================== --- tools/log2lines/stat.c (revision 45501) +++ tools/log2lines/stat.c (working copy) @@ -10,7 +10,7 @@ #include "version.h" #include "options.h" -#include "stat.h" +#include "util.h" #include "log2lines.h" void @@ -18,22 +18,22 @@ { if (outFile) { - fprintf(outFile, "\n*** LOG2LINES SUMMARY ***\n"); - fprintf(outFile, "Translated: %d\n", psumm->translated); - fprintf(outFile, "Reverted: %d\n", psumm->undo); - fprintf(outFile, "Retranslated: %d\n", psumm->redo); - fprintf(outFile, "Skipped: %d\n", psumm->skipped); - fprintf(outFile, "Differ: %d\n", psumm->diff); - fprintf(outFile, "Differ (function/source): %d\n", psumm->majordiff); - fprintf(outFile, "Revision conflicts: %d\n", psumm->revconflicts); - fprintf(outFile, "Regression candidates: %d\n", psumm->regfound); - fprintf(outFile, "Offset error: %d\n", psumm->offset_errors); - fprintf(outFile, "Total: %d\n", psumm->total); - fprintf(outFile, "-------------------------------\n"); - fprintf(outFile, "Log2lines version: " LOG2LINES_VERSION "\n"); - fprintf(outFile, "Directory: %s\n", opt_dir); - fprintf(outFile, "Passed options: %s\n", opt_scanned); - fprintf(outFile, "-------------------------------\n"); + clilog(outFile, "*** LOG2LINES SUMMARY ***\n"); + clilog(outFile, "Translated: %d\n", psumm->translated); + clilog(outFile, "Reverted: %d\n", psumm->undo); + clilog(outFile, "Retranslated: %d\n", psumm->redo); + clilog(outFile, "Skipped: %d\n", psumm->skipped); + clilog(outFile, "Differ: %d\n", psumm->diff); + clilog(outFile, "Differ (function/source): %d\n", psumm->majordiff); + clilog(outFile, "Revision conflicts: %d\n", psumm->revconflicts); + clilog(outFile, "Regression candidates: %d\n", psumm->regfound); + clilog(outFile, "Offset error: %d\n", psumm->offset_errors); + clilog(outFile, "Total: %d\n", psumm->total); + clilog(outFile, "-------------------------------\n"); + clilog(outFile, "Log2lines version: " LOG2LINES_VERSION "\n"); + clilog(outFile, "Directory: %s\n", opt_dir); + clilog(outFile, "Passed options: %s\n", opt_scanned); + clilog(outFile, "-------------------------------\n"); } } Index: tools/log2lines/stat.h =================================================================== --- tools/log2lines/stat.h (revision 45501) +++ tools/log2lines/stat.h (working copy) @@ -28,3 +28,5 @@ void stat_clear(PSUMM psumm); #endif /* __L2L_STAT_H__ */ + +/* EOF */ Index: tools/log2lines/util.c =================================================================== --- tools/log2lines/util.c (revision 45501) +++ tools/log2lines/util.c (working copy) @@ -16,6 +16,39 @@ #include "options.h" int +set_LogFile(FILE *logFile) +{ + if (*opt_logFile) + { + if (logFile) + fclose(logFile); + logFile = NULL; + + if (strcmp(opt_logFile,"none") == 0) + return 0; //just close + + logFile = fopen(opt_logFile, "a"); + if (logFile) + { + // disable buffering so fflush is not needed + if (!opt_buffered) + { + l2l_dbg(1, "Disabling log buffering on %s\n", opt_logFile); + setbuf(logFile, NULL); + } + else + l2l_dbg(1, "Enabling log buffering on %s\n", opt_logFile); + } + else + { + l2l_dbg(0, "Could not open logfile %s (%s)\n", opt_logFile, strerror(errno)); + return 2; + } + } + return 0; +} + +int file_exists(char *name) { FILE *f; Index: tools/log2lines/util.h =================================================================== --- tools/log2lines/util.h (revision 45501) +++ tools/log2lines/util.h (working copy) @@ -8,7 +8,10 @@ #ifndef __L2L_UTIL_H__ #define __L2L_UTIL_H__ +#include +#include "cmd.h" + #define log(outFile, fmt, ...) \ { \ fprintf(outFile, fmt, ##__VA_ARGS__); \ @@ -16,6 +19,19 @@ fprintf(logFile, fmt, ##__VA_ARGS__); \ } +#define esclog(outFile, fmt, ...) \ + { \ + log(outFile, KDBG_ESC_RESP fmt, ##__VA_ARGS__); \ + } + +#define clilog(outFile, fmt, ...) \ + { \ + if (opt_cli) \ + esclog(outFile, fmt, ##__VA_ARGS__) \ + else \ + log(logFile, fmt, ##__VA_ARGS__); \ + } + #define l2l_dbg(level, ...) \ { \ if (opt_verbose >= level) \ @@ -29,5 +45,8 @@ long my_atoi(const char *a); int isOffset(const char *a); int copy_file(char *src, char *dst); +int set_LogFile(FILE *logFile); #endif /* __L2L_UTIL_H__ */ + +/* EOF */ Index: tools/log2lines/version.h =================================================================== --- tools/log2lines/version.h (revision 45501) +++ tools/log2lines/version.h (working copy) @@ -8,6 +8,8 @@ #ifndef __L2L_VERSION_H__ #define __L2L_VERSION_H__ -#define LOG2LINES_VERSION "1.12b" +#define LOG2LINES_VERSION "2.1" #endif /* __L2L_VERSION_H__ */ + +/* EOF */