|
From: Hans-Bernhard B. <br...@us...> - 2002-03-16 15:20:31
|
Update of /cvsroot/cscope/cscope/src
In directory usw-pr-cvs1:/tmp/cvs-serv22328
Modified Files:
dir.c
Log Message:
Some more namelist file parsing bugs fixed:
1) (SF bug #529618): ./ in filenames caused cscope to search for a file '.c',
because some subroutine changed the content of makefilelists()'s variable
'path'.
2) The path argument to -I in a namelist file couldn't be quoted, and was
read directly via fscanf() --- silly oversight by me.
3) -p/-I and their argument can be on separate lines, now.
Index: dir.c
===================================================================
RCS file: /cvsroot/cscope/cscope/src/dir.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** dir.c 8 Mar 2002 15:34:05 -0000 1.16
--- dir.c 16 Mar 2002 15:20:27 -0000 1.17
***************
*** 311,314 ****
--- 311,317 ----
while (fgets(line, 10*PATHLEN, names) != NULL) {
char *point_in_line = line + (strlen(line) - 1);
+ size_t length_of_name = 0;
+ int unfinished_option = 0;
+ BOOL done = NO;
/* Kill away \n left at end of fgets()'d string: */
***************
*** 317,324 ****
/* Parse whitespace-terminated strings in line: */
! for (point_in_line = line;
! sscanf(point_in_line, "%s", path) == 1;
! point_in_line += strlen(path)) {
if (*path == '-') { /* if an option */
i = path[1];
switch (i) {
--- 320,339 ----
/* Parse whitespace-terminated strings in line: */
! point_in_line = line;
! while (sscanf(point_in_line, "%s", path) == 1) {
! /* Have to store this length --- inviewpath() will
! * modify path, later! */
! length_of_name = strlen(path);
!
if (*path == '-') { /* if an option */
+ if (unfinished_option) {
+ /* Can't have another option directly after an
+ * -I or -p option with no name after it! */
+ (void) fprintf(stderr, "\
+ cscope: Syntax error in namelist file %s: unfinished -I or -p option\n",
+ namefile);
+ unfinished_option = 0;
+ }
+
i = path[1];
switch (i) {
***************
*** 339,360 ****
s = path + 2; /* for "-Ipath" */
if (*s == '\0') { /* if "-I path" */
! (void) fscanf(names, "%s", path);
! s = path;
! }
! switch (i) {
! case 'I': /* #include file directory */
! if (firstbuild == YES) {
! shellpath(dir, sizeof(dir), s); /* expand $ and ~ */
! includedir(dir);
! }
! break;
! case 'p': /* file path components to display */
! if (*s < '0' || *s > '9') {
! (void) fprintf(stderr, "cscope: -p option in file %s: missing or invalid numeric value\n",
! namefile);
! }
! dispcomponents = atoi(s);
! break;
}
break;
default:
--- 354,391 ----
s = path + 2; /* for "-Ipath" */
if (*s == '\0') { /* if "-I path" */
! unfinished_option = i;
! break;
! }
!
! /* this code block used several times in here
! * --> make it a macro to avoid unnecessary
! * duplication */
! #define HANDLE_OPTION_ARGUMENT(i, s) \
! switch (i) { \
! case 'I': /* #include file directory */ \
! if (firstbuild == YES) { \
! /* expand $ and ~ */ \
! shellpath(dir, sizeof(dir), (s)); \
! includedir(dir); \
! } \
! unfinished_option = 0; \
! done = YES; \
! break; \
! case 'p': /* file path components to display */ \
! if (*(s) < '0' || *(s) > '9') { \
! (void) fprintf(stderr, \
! "cscope: -p option in file %s: missing or invalid numeric value\n", \
! namefile); \
! } \
! dispcomponents = atoi(s); \
! unfinished_option = 0; \
! done = YES; \
! break; \
! default: \
! done = NO; \
}
+
+ /* ... and now call it for the first time */
+ HANDLE_OPTION_ARGUMENT(i, s)
break;
default:
***************
*** 362,367 ****
namefile);
}
! }
! else if (*path == '"') {
/* handle quoted filenames... */
size_t in = 1, out = 0;
--- 393,397 ----
namefile);
}
! } else if (*path == '"') {
/* handle quoted filenames... */
size_t in = 1, out = 0;
***************
*** 391,411 ****
newpath[out]='\0';
}
! if ((s = inviewpath(newpath)) != NULL) {
! addsrcfile(s);
}
! else {
! (void) fprintf(stderr, "cscope: cannot find file %s\n",
! newpath);
! errorsfound = YES;
}
- } /* if (quoted entry) */
- else if ((s = inviewpath(path)) != NULL) {
- addsrcfile(s);
- }
- else {
- (void) fprintf(stderr, "cscope: cannot find file %s\n",
- path);
- errorsfound = YES;
}
}
}
--- 421,457 ----
newpath[out]='\0';
}
!
! /* If an -I or -p arguments was missing before,
! * treat this name as the argument: */
! HANDLE_OPTION_ARGUMENT(unfinished_option, newpath);
! if (! done) {
! if ((s = inviewpath(newpath)) != NULL) {
! addsrcfile(s);
! } else {
! (void) fprintf(stderr,
! "cscope: cannot find file %s\n",
! newpath);
! errorsfound = YES;
! }
}
! } else {
! /* ... so this is an ordinary file name, unquoted */
!
! /* If an -I or -p arguments was missing before,
! * treat this name as the argument: */
! HANDLE_OPTION_ARGUMENT(unfinished_option, path);
! if (!done) {
! if ((s = inviewpath(path)) != NULL) {
! addsrcfile(s);
! } else {
! (void) fprintf(stderr, "cscope: cannot find file %s\n",
! path);
! errorsfound = YES;
! }
}
}
+ point_in_line += length_of_name;
+ while (isspace((unsigned char) *point_in_line))
+ point_in_line ++;
}
}
|