- Turn two instances of stricmp(...,".[Cc]") into one of strcaseccmp(...,".c")
  in filename parsing.
- Streamline line parsing a bit:
  - Scan the line only once, looking for any line terminator
  - Ignore leading and trailing blanks
  - Handle comments properly

svn path=/trunk/; revision=11557
This commit is contained in:
Art Yerkes 2004-11-06 17:37:29 +00:00
parent de2ab6cf8b
commit 03c08fd7b9

View file

@ -175,7 +175,7 @@ register_test(char *filename,
memset(ext, 0, sizeof(ext)); memset(ext, 0, sizeof(ext));
strncpy(&ext[0], &filename[i], strlen(&filename[i])); strncpy(&ext[0], &filename[i], strlen(&filename[i]));
if ((strncmp(ext, ".c", 2) != 0) && (strncmp(ext, ".C", 2) != 0)) if (strcasecmp(ext, ".c") != 0)
{ {
return; return;
} }
@ -609,73 +609,87 @@ create_stubs_and_hooks(
FILE *stubs_out, FILE *stubs_out,
FILE *hooks_out) FILE *hooks_out)
{ {
char line[INPUT_BUFFER_SIZE]; char line[INPUT_BUFFER_SIZE];
char *s; char *s, *start;
char *dllname; char *dllname;
char *decoratedname_and_forward; char *decoratedname_and_forward;
int stub_index; int stub_index;
write_stubs_header(stubs_out); write_stubs_header(stubs_out);
write_hooks_header(hooks_out); write_hooks_header(hooks_out);
/*
* Scan the database. The database is a text file; each
* line is a record, which contains data for one stub.
* Each record has two columns:
*
* DLLNAME (e.g. ntdll.dll)
* DECORATED NAME (e.g. NtCreateProcess@32, @InterlockedIncrement@4 or printf)
*/
stub_index = 0; /* First stub has index zero */
for (
;
/* Go on until EOF or read zero bytes */
((!feof(in)) && (fgets(line, sizeof line, in) != NULL));
/* Next stub index */
)
{
/*
* Ignore leading blanks
*/
for( start = line; *start && isspace(*start); start++ );
/*
* Strip comments, eols
*/
for( s = start; *s && !strchr("#\n\r", *s); s++ );
*s = '\0';
/* /*
* Scan the database. The database is a text file; each * Remove trailing blanks. Backup off the char that ended our
* line is a record, which contains data for one stub. * run before.
* Each record has two columns:
*
* DLLNAME (e.g. ntdll.dll)
* DECORATED NAME (e.g. NtCreateProcess@32, @InterlockedIncrement@4 or printf)
*/ */
stub_index = 0; /* First stub has index zero */ for( s--; s > start && isspace(*s); s-- ) *s = '\0';
for ( /*
; * Skip empty lines
/* Go on until EOF or read zero bytes */ */
((!feof(in)) && (fgets(line, sizeof line, in) != NULL)); if (s > start)
/* Next stub index */ {
) /* Extract the DLL name */
{ dllname = (char *) strtok(start, " \t");
/* if (dllname != NULL && strlen(dllname) > 0)
* Remove, if present, the trailing LF. {
*/ /*
if ((s = (char *) strchr(line,'\n')) != NULL) * Extract the decorated function name and possibly forwarded export.
{ * Format:
*s = '\0'; * decoratedname=forwardedexport (no DLL name)
} */
decoratedname_and_forward = (char *) strtok(NULL, " \t");
/* /* Extract the argument count */
* Remove, if present, the trailing CR.
*/ /* Something went wrong finding the separator ...
if ((s = (char *) strchr(line,'\r')) != NULL) * print an error and bail. */
{ if( !decoratedname_and_forward ) {
*s = '\0'; fprintf
} ( stderr,
"Could not find separator between decorated "
/* "function name and dll name.\n"
* Skip comments (#) and empty lines. "Format entries as <dllname> <import>\n"
*/ "Legal comments start with #\n");
s = & line[0]; exit(1);
if ((*s) != '#' && (*s) != '\0') }
{
/* Extract the DLL name */ write_stub(stubs_out, hooks_out, dllname, decoratedname_and_forward, stub_index);
dllname = (char *) strtok(s, " \t"); stub_index++;
if (dllname != NULL && strlen(dllname) > 0) }
{ }
/* }
* Extract the decorated function name and possibly forwarded export.
* Format: write_hooks_footer(hooks_out, stub_index);
* decoratedname=forwardedexport (no DLL name)
*/
decoratedname_and_forward = (char *) strtok(NULL, " \t");
/* Extract the argument count */
write_stub(stubs_out, hooks_out, dllname, decoratedname_and_forward, stub_index);
stub_index++;
}
}
}
write_hooks_footer(hooks_out, stub_index);
} }
int run_stubs(int argc, int run_stubs(int argc,
@ -684,7 +698,7 @@ int run_stubs(int argc,
FILE *in; FILE *in;
FILE *stubs_out; FILE *stubs_out;
FILE *hooks_out; FILE *hooks_out;
in = fopen(argv[2], "rb"); in = fopen(argv[2], "rb");
if (in == NULL) if (in == NULL)
{ {