1 /* 2 * ReactOS log2lines 3 * Written by Jan Roeloffzen 4 * 5 * - Custom match routines 6 */ 7 8 #include <string.h> 9 10 #include "config.h" 11 #include "log2lines.h" 12 #include "match.h" 13 14 // break pattern: show source+line 15 static int match_break(FILE *outFile, char *Line, int processed) 16 { 17 static int state = 0; 18 19 if ( processed ) return processed; 20 switch (state) 21 { 22 case 1: 23 state = 0; 24 break; 25 default: 26 state = 0; 27 } 28 return 1; 29 } 30 // "mod" command: update relocated addresses 31 static int match_mod(FILE *outFile, char *Line, int processed) 32 { 33 static int state = 0; 34 char Image[NAMESIZE]; 35 UINT Base; 36 UINT Size; 37 PLIST_MEMBER plm; 38 39 int cnt; 40 41 if ( processed ) return processed; 42 if ( (cnt = sscanf(Line," Base Size %5s", Image)) == 1 ) 43 { 44 l2l_dbg(1, "Module relocate list:\n"); 45 state = 1; 46 return 0; 47 } 48 switch (state) 49 { 50 case 1: 51 if ( (cnt = sscanf(Line,"%x %x %20s", &Base, &Size, Image)) == 3 ) 52 { 53 if (( plm = entry_lookup(&cache, Image) )) 54 { 55 plm->RelBase = Base; 56 plm->Size = Size; 57 l2l_dbg(1, "Relocated: %s %p -> %p\n", Image, (void*)plm->ImageBase, (void*)plm->RelBase); 58 } 59 return 0; 60 } 61 else 62 { 63 state = 0; 64 } 65 break; 66 default: 67 state = 0; 68 } 69 return 1; 70 } 71 72 int match_line(FILE *outFile, char *Line) 73 { 74 int processed = 1; 75 76 if ( *Line == '\n' || *Line == '\0' ) 77 return 1; 78 if ( strncmp(Line, KDBG_CONT, sizeof(KDBG_CONT)-1 ) == 0 ) 79 return 1; 80 81 processed = match_mod(outFile, Line, processed); 82 processed = match_break(outFile, Line, processed); 83 /* more to be appended here: 84 * processed = match_xxx(outFile, Line, processed ); 85 * ... 86 */ 87 88 return (int)(Line[0]); 89 } 90 91 /* EOF */ 92