ReactOS  0.4.14-dev-845-g8381e29
log2lines.c File Reference
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "util.h"
#include "version.h"
#include "compat.h"
#include "options.h"
#include "image.h"
#include "cache.h"
#include "log2lines.h"
#include "help.h"
#include "cmd.h"
#include "match.h"
Include dependency graph for log2lines.c:

Go to the source code of this file.

Functions

static void clearLastLine (void)
 
static void log_file (FILE *outFile, char *fileName, int line)
 
static void logSource (FILE *outFile)
 
static void reportSource (FILE *outFile)
 
static void report (FILE *outFile)
 
static int print_offset (void *data, size_t offset, char *toString)
 
static int process_data (const void *FileData, size_t offset, char *toString)
 
static int process_file (const char *file_name, size_t offset, char *toString)
 
static int translate_file (const char *cpath, size_t offset, char *toString)
 
static void translate_char (int c, FILE *outFile)
 
static charremove_mark (char *Line)
 
static void translate_line (FILE *outFile, char *Line, char *path, char *LineOut)
 
static int translate_files (FILE *inFile, FILE *outFile)
 
int main (int argc, const char **argv)
 

Variables

static FILEdbgIn = NULL
 
static FILEdbgOut = NULL
 
static FILEconIn = NULL
 
static FILEconOut = NULL
 
static const charkdbg_prompt = KDBG_PROMPT
 
static const charkdbg_cont = KDBG_CONT
 
LIST sources
 
LINEINFO lastLine
 
FILElogFile = NULL
 
LIST cache
 
SUMM summ
 
REVINFO revinfo
 

Function Documentation

◆ clearLastLine()

static void clearLastLine ( void  )
static

Definition at line 41 of file log2lines.c.

42 {
43  memset(&lastLine, 0, sizeof(LINEINFO));
44 }
LINEINFO lastLine
Definition: log2lines.c:33
#define memset(x, y, z)
Definition: compat.h:39

Referenced by main(), and report().

◆ log_file()

static void log_file ( FILE outFile,
char fileName,
int  line 
)
static

Definition at line 47 of file log2lines.c.

48 {
49  int i = 0, min = 0, max = 0;
50  char s[LINESIZE];
51  FILE *src;
52 
54  strcat(s, fileName);
55 
56  max = line + opt_SrcPlus;
57  if ((src = fopen(s, "r")))
58  {
59  min = line - opt_Source;
60  min = (min < 0) ? 0 : min;
61  while (i < max && fgets(s, LINESIZE, src))
62  {
63  if (i >= min)
64  {
65  if (i == line)
66  log(outFile, "| ----\n");
67  log(outFile, "| %4.4d %s", i + 1, s);
68  }
69  i++;
70  }
71  fclose(src);
72  if ( i < min )
73  log(outFile, "| S--- source has only %d lines! (check source/revision)\n", i);
74  }
75  else
76  l2l_dbg(1, "Can't open: %s (check " SOURCES_ENV ")\n", s);
77 }
#define max(a, b)
Definition: svc.c:63
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define SOURCES_ENV
Definition: config.h:13
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int opt_SrcPlus
Definition: options.c:35
#define l2l_dbg(level,...)
Definition: util.h:35
Definition: parser.c:48
int opt_Source
Definition: options.c:34
GLdouble s
Definition: gl.h:2039
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
GLenum src
Definition: glext.h:6340
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
#define min(a, b)
Definition: monoChain.cc:55
#define LINESIZE
Definition: chargen.c:18
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define log(outFile, fmt,...)
Definition: util.h:15
char opt_SourcesPath[LINESIZE]
Definition: options.c:47

Referenced by logSource().

◆ logSource()

static void logSource ( FILE outFile)
static

Definition at line 80 of file log2lines.c.

81 {
82  log_file(outFile, lastLine.file1, lastLine.nr1);
83  if (lastLine.nr2)
84  {
85  log(outFile, "| ---- [%u] ----\n", lastLine.nr2);
86  log_file(outFile, lastLine.file2, lastLine.nr2);
87  }
88 }
LINEINFO lastLine
Definition: log2lines.c:33
char file2[LINESIZE]
Definition: log2lines.h:19
char file1[LINESIZE]
Definition: log2lines.h:16
static void log_file(FILE *outFile, char *fileName, int line)
Definition: log2lines.c:47
#define log(outFile, fmt,...)
Definition: util.h:15

Referenced by reportSource().

◆ main()

int main ( int argc  ,
const char **  argv 
)

Definition at line 560 of file log2lines.c.

561 {
562  int res = 0;
563  int optInit = 0;
564  int optCount = 0;
565 
566  dbgIn = stdin;
567  conOut = stdout;
568  (void)conIn;
569  (void)dbgOut;
570 
571  memset(&cache, 0, sizeof(LIST));
572  memset(&sources, 0, sizeof(LIST));
573  stat_clear(&summ);
574  memset(&revinfo, 0, sizeof(REVINFO));
575  clearLastLine();
576 
577  optInit = optionInit(argc, argv);
578  optCount = optionParse(argc, argv);
579 
580  if (optCount < 0 || optInit < 0)
581  {
582  res = optCount;
583  goto cleanup;
584  }
585 
586  argc -= optCount;
587 
588  if (opt_Revision && (strcmp(opt_Revision, "update") == 0))
589  {
590  res = updateSvnlog();
591  goto cleanup;
592  }
593 
595  {
596  res = 3;
597  goto cleanup;
598  }
599 
601  if (opt_exit)
602  {
603  res = 0;
604  goto cleanup;
605  }
606 
607  read_cache();
608  l2l_dbg(4, "Cache read complete\n");
609 
610  if (set_LogFile(&logFile))
611  {
612  res = 2;
613  goto cleanup;
614  }
615  l2l_dbg(4, "opt_logFile processed\n");
616 
617  if (opt_Pipe)
618  {
619  l2l_dbg(3, "Command line: \"%s\"\n",opt_Pipe);
620 
621  if (!(dbgIn = POPEN(opt_Pipe, "r")))
622  {
623  dbgIn = stdin; //restore
624  l2l_dbg(0, "Could not popen '%s' (%s)\n", opt_Pipe, strerror(errno));
625  free(opt_Pipe);
626  opt_Pipe = NULL;
627  }
628  }
629  l2l_dbg(4, "opt_Pipe processed\n");
630 
631  if (argc > 1)
632  { // translate {<exefile> <offset>}
633  int i = 1;
634  const char *exefile = NULL;
635  const char *offset = NULL;
636  char Line[LINESIZE + 1];
637  char PathBuffer[LINESIZE + 1];
638  char LineOutBuffer[LINESIZE + 1];
639 
640  // TODO: Re-use one translate_files(), instead of repeated translate_line().
641  while (i < argc)
642  {
643  offset = argv[optCount + i++];
644  if (isOffset(offset))
645  {
646  if (exefile)
647  {
648  l2l_dbg(2, "translating %s %s\n", exefile, offset);
649 
650  snprintf(Line, LINESIZE, "<%s:%s>\n", exefile, offset);
651  translate_line(conOut, Line, PathBuffer, LineOutBuffer);
652  report(conOut);
653  }
654  else
655  {
656  l2l_dbg(0, "<exefile> expected\n");
657  res = 3;
658  break;
659  }
660  }
661  else
662  {
663  // Not an offset so must be an exefile:
664  exefile = offset;
665  }
666  }
667  }
668  else
669  { // translate logging from stdin
671  }
672 
673  if (logFile)
674  fclose(logFile);
675 
676  if (opt_Pipe)
677  PCLOSE(dbgIn);
678 
679 cleanup:
680  // See optionParse().
681  if (opt_Revision)
682  {
684  opt_Revision = NULL;
685  }
686 
687  // See optionInit().
688  if (opt_Pipe)
689  {
690  free(opt_Pipe);
691  opt_Pipe = NULL;
692  }
693 
695  list_clear(&cache);
696 
697  return res;
698 }
Definition: cache.c:48
int optionInit(int argc, const char **argv)
Definition: options.c:52
static int argc
Definition: ServiceArgs.c:12
#define create_cache(iid)
Definition: domdoc.c:1230
int updateSvnlog(void)
Definition: revision.c:257
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
static FILE * dbgIn
Definition: log2lines.c:25
#define free
Definition: debug_ros.c:5
GLintptr offset
Definition: glext.h:5920
static void translate_line(FILE *outFile, char *Line, char *path, char *LineOut)
Definition: log2lines.c:323
#define snprintf
Definition: wintirpc.h:48
FILE * stdin
int errno
static FILE * conIn
Definition: log2lines.c:27
#define PCLOSE
Definition: compat.h:22
#define argv
Definition: mplay32.c:18
const char * strerror(int err)
Definition: compat_str.c:23
FILE * stdout
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void list_clear(PLIST list)
Definition: list.c:70
#define l2l_dbg(level,...)
Definition: util.h:35
int opt_force
Definition: options.c:23
static FILE * conOut
Definition: log2lines.c:28
smooth NULL
Definition: ftsmooth.c:416
REVINFO revinfo
Definition: log2lines.c:37
GLsizei GLenum * sources
Definition: glext.h:7753
int read_cache(void)
Definition: cache.c:157
char * opt_Pipe
Definition: options.c:29
int opt_exit
Definition: options.c:24
void stat_clear(PSUMM psumm)
Definition: stat.c:41
int optionParse(int argc, const char **argv)
Definition: options.c:118
char * opt_Revision
Definition: options.c:40
static void report(FILE *outFile)
Definition: log2lines.c:100
Definition: ncftp.h:79
int set_LogFile(FILE **plogFile)
Definition: util.c:19
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define LINESIZE
Definition: chargen.c:18
FILE * logFile
Definition: log2lines.c:34
GLuint res
Definition: glext.h:9613
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
char * cleanup(char *str)
Definition: wpickclick.c:99
int isOffset(const char *a)
Definition: util.c:154
static int translate_files(FILE *inFile, FILE *outFile)
Definition: log2lines.c:411
static FILE * dbgOut
Definition: log2lines.c:26
SUMM summ
Definition: log2lines.c:36
int check_directory(int force)
Definition: cache.c:80
#define memset(x, y, z)
Definition: compat.h:39
static void clearLastLine(void)
Definition: log2lines.c:41
#define POPEN
Definition: compat.h:21

◆ print_offset()

static int print_offset ( void data,
size_t  offset,
char toString 
)
static

Definition at line 109 of file log2lines.c.

110 {
112  PROSSYM_ENTRY e = NULL;
113  PROSSYM_ENTRY e2 = NULL;
114  int bFileOffsetChanged = 0;
115  char fmt[LINESIZE];
116  char *Strings = (char *)data + RosSymHeader->StringsOffset;
117 
118  fmt[0] = '\0';
119  e = find_offset(data, offset);
120  if (opt_twice)
121  {
122  e2 = find_offset(data, offset - 1);
123 
124  if (e == e2)
125  e2 = NULL;
126  else
127  summ.diff++;
128 
129  if (opt_Twice && e2)
130  {
131  e = e2;
132  e2 = NULL;
133  /* replaced (transparantly), but updated stats */
134  }
135  }
136  if (e || e2)
137  {
138  strcpy(lastLine.file1, &Strings[e->FileOffset]);
139  strcpy(lastLine.func1, &Strings[e->FunctionOffset]);
140  lastLine.nr1 = e->SourceLine;
142  lastLine.valid = 1;
143  if (e2)
144  {
147  lastLine.nr2 = e2->SourceLine;
149  bFileOffsetChanged = e->FileOffset != e2->FileOffset;
150  if (e->FileOffset != e2->FileOffset || e->FunctionOffset != e2->FunctionOffset)
151  summ.majordiff++;
152 
153  /*
154  * - "%.0s" displays nothing, but processes argument
155  * - bFileOffsetChanged implies always display 2nd SourceLine even if the same
156  * - also for FunctionOffset
157  */
158  strcat(fmt, "%s");
159  if (bFileOffsetChanged)
160  strcat(fmt, "[%s]");
161  else
162  strcat(fmt, "%.0s");
163 
164  strcat(fmt, ":%u");
165  if (e->SourceLine != e2->SourceLine || bFileOffsetChanged)
166  strcat(fmt, "[%u]");
167  else
168  strcat(fmt, "%.0u");
169 
170  strcat(fmt, " (%s");
171  if (e->FunctionOffset != e2->FunctionOffset || bFileOffsetChanged)
172  strcat(fmt, "[%s])");
173  else
174  strcat(fmt, "%.0s)");
175 
176  if (toString)
177  { // put in toString if provided
178  snprintf(toString, LINESIZE, fmt,
179  &Strings[e->FileOffset],
180  &Strings[e2->FileOffset],
181  (unsigned int)e->SourceLine,
182  (unsigned int)e2->SourceLine,
183  &Strings[e->FunctionOffset],
184  &Strings[e2->FunctionOffset]);
185  }
186  else
187  {
188  strcat(fmt, "\n");
189  printf(fmt,
190  &Strings[e->FileOffset],
191  &Strings[e2->FileOffset],
192  (unsigned int)e->SourceLine,
193  (unsigned int)e2->SourceLine,
194  &Strings[e->FunctionOffset],
195  &Strings[e2->FunctionOffset]);
196  }
197  }
198  else
199  {
200  if (toString)
201  { // put in toString if provided
202  snprintf(toString, LINESIZE, "%s:%u (%s)",
203  &Strings[e->FileOffset],
204  (unsigned int)e->SourceLine,
205  &Strings[e->FunctionOffset]);
206  }
207  else
208  {
209  printf("%s:%u (%s)\n",
210  &Strings[e->FileOffset],
211  (unsigned int)e->SourceLine,
212  &Strings[e->FunctionOffset]);
213  }
214  }
215  return 0;
216  }
217  return 1;
218 }
int opt_Twice
Definition: options.c:37
int opt_twice
Definition: options.c:36
ULONG SourceLine
Definition: rossym.h:30
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
GLintptr offset
Definition: glext.h:5920
char func1[NAMESIZE]
Definition: log2lines.h:17
ULONG StringsOffset
Definition: rsym.h:34
#define snprintf
Definition: wintirpc.h:48
Definition: rossym.h:26
struct _SYMBOLFILE_HEADER * PSYMBOLFILE_HEADER
int diff
Definition: stat.h:18
ULONG FileOffset
Definition: rossym.h:29
char func2[NAMESIZE]
Definition: log2lines.h:20
#define e
Definition: ke_i.h:82
smooth NULL
Definition: ftsmooth.c:416
GLsizei GLenum * sources
Definition: glext.h:7753
PLIST_MEMBER sources_entry_create(PLIST list, char *path, char *prefix)
Definition: list.c:173
LINEINFO lastLine
Definition: log2lines.c:33
static const WCHAR Strings[]
Definition: reg.c:35
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define SVN_PREFIX
Definition: config.h:16
char file2[LINESIZE]
Definition: log2lines.h:19
char file1[LINESIZE]
Definition: log2lines.h:16
int majordiff
Definition: stat.h:19
#define LINESIZE
Definition: chargen.c:18
PROSSYM_ENTRY find_offset(void *data, size_t offset)
Definition: image.c:38
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
ULONG FunctionOffset
Definition: rossym.h:28
SUMM summ
Definition: log2lines.c:36
Definition: dsound.c:943
#define printf
Definition: config.h:203

Referenced by process_data().

◆ process_data()

static int process_data ( const void FileData,
size_t  offset,
char toString 
)
static

Definition at line 221 of file log2lines.c.

222 {
223  int res;
224 
225  PIMAGE_SECTION_HEADER PERosSymSectionHeader = get_sectionheader((char *)FileData);
226  if (!PERosSymSectionHeader)
227  return 2;
228 
229  res = print_offset((char *)FileData + PERosSymSectionHeader->PointerToRawData, offset, toString);
230  if (res)
231  {
232  if (toString)
233  sprintf(toString, "??:0");
234  else
235  printf("??:0");
236  l2l_dbg(1, "Offset not found: %x\n", (unsigned int)offset);
238  }
239 
240  return res;
241 }
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
static int print_offset(void *data, size_t offset, char *toString)
Definition: log2lines.c:109
int offset_errors
Definition: stat.h:22
GLintptr offset
Definition: glext.h:5920
DWORD PointerToRawData
Definition: pedump.c:290
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define l2l_dbg(level,...)
Definition: util.h:35
PIMAGE_SECTION_HEADER get_sectionheader(const void *FileData)
Definition: image.c:59
GLuint res
Definition: glext.h:9613
SUMM summ
Definition: log2lines.c:36
#define printf
Definition: config.h:203

Referenced by process_file().

◆ process_file()

static int process_file ( const char file_name,
size_t  offset,
char toString 
)
static

Definition at line 244 of file log2lines.c.

245 {
246  void *FileData;
247  size_t FileSize;
248  int res = 1;
249 
251  if (!FileData)
252  {
253  l2l_dbg(0, "An error occured loading '%s'\n", file_name);
254  }
255  else
256  {
257  res = process_data(FileData, offset, toString);
258  free(FileData);
259  }
260  return res;
261 }
static int process_data(const void *FileData, size_t offset, char *toString)
Definition: log2lines.c:221
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
#define free
Definition: debug_ros.c:5
GLintptr offset
Definition: glext.h:5920
#define l2l_dbg(level,...)
Definition: util.h:35
static UINT load_file(MSIRECORD *row, LPVOID param)
Definition: action.c:1202
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
static LPCWSTR file_name
Definition: protocol.c:147
GLuint res
Definition: glext.h:9613

Referenced by translate_file().

◆ remove_mark()

static char* remove_mark ( char Line)
static

Definition at line 314 of file log2lines.c.

315 {
316  if (Line[1] == ' ' && Line[2] == '<')
317  if (Line[0] == '*' || Line[0] == '?')
318  return Line + 2;
319  return Line;
320 }
Definition: ncftp.h:79
struct Line Line

Referenced by translate_line().

◆ report()

static void report ( FILE outFile)
static

Definition at line 100 of file log2lines.c.

101 {
102  reportRevision(outFile);
103  reportSource(outFile);
104  clearLastLine();
105 }
static void reportSource(FILE *outFile)
Definition: log2lines.c:91
void reportRevision(FILE *outFile)
Definition: revision.c:129
static void clearLastLine(void)
Definition: log2lines.c:41

Referenced by main(), and translate_files().

◆ reportSource()

static void reportSource ( FILE outFile)
static

Definition at line 91 of file log2lines.c.

92 {
93  if (!opt_Source)
94  return;
95  if (lastLine.valid)
96  logSource(outFile);
97 }
LINEINFO lastLine
Definition: log2lines.c:33
int opt_Source
Definition: options.c:34
static void logSource(FILE *outFile)
Definition: log2lines.c:80

Referenced by report().

◆ translate_char()

static void translate_char ( int  c,
FILE outFile 
)
static

Definition at line 306 of file log2lines.c.

307 {
308  fputc(c, outFile);
309  if (logFile)
310  fputc(c, logFile);
311 }
_Check_return_opt_ _CRTIMP int __cdecl fputc(_In_ int _Ch, _Inout_ FILE *_File)
const GLubyte * c
Definition: glext.h:8905
FILE * logFile
Definition: log2lines.c:34

Referenced by translate_files().

◆ translate_file()

static int translate_file ( const char cpath,
size_t  offset,
char toString 
)
static

Definition at line 264 of file log2lines.c.

265 {
266  size_t base = 0;
267  LIST_MEMBER *pentry = NULL;
268  int res = 0;
269  char *path, *dpath;
270 
271  dpath = path = convert_path(cpath);
272  if (!path)
273  return 1;
274 
275  // The path could be absolute:
276  if (get_ImageBase(path, &base))
277  {
278  pentry = entry_lookup(&cache, path);
279  if (pentry)
280  {
281  path = pentry->path;
282  base = pentry->ImageBase;
283  if (base == INVALID_BASE)
284  {
285  l2l_dbg(1, "No, or invalid base address: %s\n", path);
286  res = 2;
287  }
288  }
289  else
290  {
291  l2l_dbg(1, "Not found in cache: %s\n", path);
292  res = 3;
293  }
294  }
295 
296  if (!res)
297  {
298  res = process_file(path, offset, toString);
299  }
300 
301  free(dpath);
302  return res;
303 }
Definition: cache.c:48
GLsizei const GLchar ** path
Definition: glext.h:7234
#define free
Definition: debug_ros.c:5
GLintptr offset
Definition: glext.h:5920
#define l2l_dbg(level,...)
Definition: util.h:35
smooth NULL
Definition: ftsmooth.c:416
PLIST_MEMBER entry_lookup(PLIST list, char *name)
Definition: list.c:19
static int process_file(const char *file_name, size_t offset, char *toString)
Definition: log2lines.c:244
size_t ImageBase
Definition: list.h:8
#define INVALID_BASE
Definition: config.h:5
char * convert_path(char *origpath)
Definition: rcopy.c:11
GLuint res
Definition: glext.h:9613
char * path
Definition: list.h:7
int get_ImageBase(char *fname, size_t *ImageBase)
Definition: image.c:101

Referenced by translate_line().

◆ translate_files()

static int translate_files ( FILE inFile,
FILE outFile 
)
static

Definition at line 411 of file log2lines.c.

412 {
413  char Line[LINESIZE + 1];
414  char path[LINESIZE + 1];
415  char LineOut[LINESIZE + 1];
416  int c;
417  unsigned char ch;
418  int i = 0;
419  const char *pc = kdbg_cont;
420  const char *p = kdbg_prompt;
421  const char *p_eos = p + sizeof(KDBG_PROMPT) - 1; //end of string pos
422 
423  memset(Line, '\0', LINESIZE + 1);
424  if (opt_console)
425  {
426  while ((c = fgetc(inFile)) != EOF)
427  {
428  if (opt_quit)break;
429 
430  ch = (unsigned char)c;
431  if (!opt_raw)
432  {
433  switch (ch)
434  {
435  case '\n':
436  if ( strncmp(Line, KDBG_DISCARD, sizeof(KDBG_DISCARD)-1) == 0 )
437  {
438  memset(Line, '\0', LINESIZE); // flushed
439  }
440  else
441  {
442  Line[1] = handle_escape_cmd(outFile, Line);
443  if (Line[1] != KDBG_ESC_CHAR)
444  {
445  if (p == p_eos)
446  {
447  // kdbg prompt, so already echoed char by char
448  memset(Line, '\0', LINESIZE);
449  translate_char(c, outFile);
450  }
451  else
452  {
453  if (match_line(outFile, Line))
454  {
455  translate_line(outFile, Line, path, LineOut);
456  translate_char(c, outFile);
457  report(outFile);
458  }
459  }
460  }
461  }
462  i = 0;
463  p = kdbg_prompt;
464  pc = kdbg_cont;
465  break;
466  case '<':
467  i = 0;
468  Line[i++] = ch;
469  break;
470  case '>':
471  if (ch == *p)
472  {
473  p = p_eos;
474  translate_line(outFile, Line, path, LineOut);
475  }
476 
477  if (p != p_eos)
478  {
479  if (i < LINESIZE)
480  {
481  Line[i++] = ch;
482  translate_line(outFile, Line, path, LineOut);
483  }
484  else
485  {
486  translate_line(outFile, Line, path, LineOut);
487  translate_char(c, outFile);
488  }
489  }
490  else
491  translate_char(c, outFile);
492  i = 0;
493  break;
494  default:
495  if (ch == *p)p++;
496  if (ch == *pc)pc++;
497  if (i < LINESIZE)
498  {
499  Line[i++] = ch;
500  if (p == p_eos)
501  {
502  translate_char(c, outFile);
503  }
504  else if (!*pc)
505  {
506  translate_line(outFile, Line, path, LineOut);
507  i = 0;
508  }
509  }
510  else
511  {
512  translate_line(outFile, Line, path, LineOut);
513  translate_char(c, outFile);
514  i = 0;
515  }
516  }
517  }
518  else
519  translate_char(c, outFile);
520  }
521  }
522  else
523  { // Line by line, slightly faster but less interactive
524  while (fgets(Line, LINESIZE, inFile) != NULL)
525  {
526  if (opt_quit)break;
527 
528  if (!opt_raw)
529  {
530  translate_line(outFile, Line, path, LineOut);
531  report(outFile);
532  }
533  else
534  log(outFile, "%s", Line);
535  }
536  }
537 
538  if (opt_Revision && (strstr(opt_Revision, "regscan") == opt_Revision))
539  {
540  char *s = strchr(opt_Revision, ',');
541  if (s)
542  {
543  *s++ = '\0';
544  revinfo.range = atoi(s);
545  }
546  regscan(outFile);
547  }
548 
549  if (opt_stats)
550  {
551  stat_print(outFile, &summ);
552  if (logFile)
554  }
555  return 0;
556 }
static const char * kdbg_prompt
Definition: log2lines.c:29
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
static void translate_line(FILE *outFile, char *Line, char *path, char *LineOut)
Definition: log2lines.c:323
int opt_raw
Definition: options.c:32
static const char * kdbg_cont
Definition: log2lines.c:30
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
REVINFO revinfo
Definition: log2lines.c:37
unsigned char
Definition: typeof.h:29
#define KDBG_PROMPT
Definition: cmd.h:17
int opt_stats
Definition: options.c:33
const GLubyte * c
Definition: glext.h:8905
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
char * opt_Revision
Definition: options.c:40
void stat_print(FILE *outFile, PSUMM psumm)
Definition: stat.c:17
static void report(FILE *outFile)
Definition: log2lines.c:100
Definition: ncftp.h:79
GLdouble s
Definition: gl.h:2039
static void translate_char(int c, FILE *outFile)
Definition: log2lines.c:306
#define KDBG_ESC_CHAR
Definition: cmd.h:13
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
#define KDBG_DISCARD
Definition: cmd.h:19
#define LINESIZE
Definition: chargen.c:18
int match_line(FILE *outFile, char *Line)
Definition: match.c:72
FILE * logFile
Definition: log2lines.c:34
char * strchr(const char *String, int ch)
Definition: utclib.c:501
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define EOF
Definition: stdio.h:24
int opt_console
Definition: options.c:26
#define c
Definition: ke_i.h:80
int opt_quit
Definition: options.c:30
char handle_escape_cmd(FILE *outFile, char *Line)
Definition: cmd.c:180
GLfloat GLfloat p
Definition: glext.h:8902
SUMM summ
Definition: log2lines.c:36
#define memset(x, y, z)
Definition: compat.h:39
int regscan(FILE *outFile)
Definition: revision.c:154
#define log(outFile, fmt,...)
Definition: util.h:15
_Check_return_opt_ _CRTIMP int __cdecl fgetc(_Inout_ FILE *_File)

Referenced by main().

◆ translate_line()

static void translate_line ( FILE outFile,
char Line,
char path,
char LineOut 
)
static

Definition at line 323 of file log2lines.c.

324 {
325  unsigned int offset;
326  int cnt, res;
327  char *sep, *tail, *mark, *s;
328  unsigned char ch;
329 
330  if (!*Line)
331  return;
332 
333  res = 1;
334  mark = "";
335  s = remove_mark(Line);
336  if (opt_undo)
337  {
338  /* Strip all lines added by this tool: */
339  char buf[NAMESIZE];
340  if (sscanf(s, "| %s", buf) == 1)
341  if (buf[0] == '0' || strcmp(buf, "----") == 0 || strcmp(buf, "L2L-") == 0 || strcmp(buf, "S---") == 0 || strcmp(buf, "R---") == 0 || atoi(buf))
342  res = 0;
343  }
344 
345  sep = strchr(s, ':');
346  if (sep)
347  {
348  *sep = ' ';
349  cnt = sscanf(s, "<%s %x%c", path, &offset, &ch);
350  if (opt_undo)
351  {
352  if (cnt == 3 && ch == ' ')
353  {
354  tail = strchr(s, '>');
355  tail = tail ? tail - 1 : tail;
356  if (tail && tail[0] == ')' && tail[1] == '>')
357  {
358  res = 0;
359  tail += 2;
360  mark = opt_mark ? "* " : "";
361  if (opt_redo && !(res = translate_file(path, offset, LineOut)))
362  {
363  log(outFile, "%s<%s:%x (%s)>%s", mark, path, offset, LineOut, tail);
364  summ.redo++;
365  }
366  else
367  {
368  log(outFile, "%s<%s:%x>%s", mark, path, offset, tail);
369  summ.undo++;
370  }
371  }
372  else
373  {
374  mark = opt_Mark ? "? " : "";
375  summ.skipped++;
376  }
377  summ.total++;
378  }
379  }
380 
381  if (!opt_undo || opt_redo)
382  {
383  if (cnt == 3 && ch == '>')
384  {
385  tail = strchr(s, '>') + 1;
386  if (!(res = translate_file(path, offset, LineOut)))
387  {
388  mark = opt_mark ? "* " : "";
389  log(outFile, "%s<%s:%x (%s)>%s", mark, path, offset, LineOut, tail);
390  summ.translated++;
391  }
392  else
393  {
394  mark = opt_Mark ? "? " : "";
395  summ.skipped++;
396  }
397  summ.total++;
398  }
399  }
400  }
401  if (res)
402  {
403  if (sep)
404  *sep = ':'; // restore because not translated
405  log(outFile, "%s%s", mark, s);
406  }
407  memset(Line, '\0', LINESIZE); // flushed
408 }
struct outqueuenode * tail
Definition: adnsresfilter.c:66
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
int opt_Mark
Definition: options.c:28
GLintptr offset
Definition: glext.h:5920
int opt_undo
Definition: options.c:38
static char * remove_mark(char *Line)
Definition: log2lines.c:314
int opt_mark
Definition: options.c:27
#define NAMESIZE
Definition: config.h:35
int skipped
Definition: stat.h:17
int opt_redo
Definition: options.c:39
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
Definition: ncftp.h:79
int translated
Definition: stat.h:14
GLdouble s
Definition: gl.h:2039
int undo
Definition: stat.h:15
static int translate_file(const char *cpath, size_t offset, char *toString)
Definition: log2lines.c:264
#define LINESIZE
Definition: chargen.c:18
char * strchr(const char *String, int ch)
Definition: utclib.c:501
int redo
Definition: stat.h:16
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
GLuint res
Definition: glext.h:9613
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
SUMM summ
Definition: log2lines.c:36
#define memset(x, y, z)
Definition: compat.h:39
int total
Definition: stat.h:23
#define log(outFile, fmt,...)
Definition: util.h:15

Referenced by main(), and translate_files().

Variable Documentation

◆ cache

Definition at line 35 of file log2lines.c.

◆ conIn

FILE* conIn = NULL
static

Definition at line 27 of file log2lines.c.

Referenced by main().

◆ conOut

FILE* conOut = NULL
static

Definition at line 28 of file log2lines.c.

Referenced by main().

◆ dbgIn

FILE* dbgIn = NULL
static

Definition at line 25 of file log2lines.c.

Referenced by main().

◆ dbgOut

FILE* dbgOut = NULL
static

Definition at line 26 of file log2lines.c.

Referenced by main().

◆ kdbg_cont

const char* kdbg_cont = KDBG_CONT
static

Definition at line 30 of file log2lines.c.

Referenced by translate_files().

◆ kdbg_prompt

const char* kdbg_prompt = KDBG_PROMPT
static

Definition at line 29 of file log2lines.c.

Referenced by translate_files().

◆ lastLine

LINEINFO lastLine

◆ logFile

FILE* logFile = NULL

Definition at line 34 of file log2lines.c.

Referenced by main(), translate_char(), and translate_files().

◆ revinfo

◆ sources

Definition at line 32 of file log2lines.c.

◆ summ