📄 dir.c
字号:
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: (void) fprintf(stderr, "cscope: only -I, -c, -k, -p, and -T options can be in file %s\n", namefile); } } else if (*path == '"') { /* handle quoted filenames... */ size_t in = 1, out = 0; char *newpath = mymalloc(PATHLEN + 1); while (in < PATHLEN && point_in_line[in] != '\0') { if (point_in_line[in] == '"') { newpath[out] = '\0'; /* Make sure we skip over the part just read */ point_in_line += in + 1; /* ... to deactive step by strlen() path at end * of loop */ path[0]='\0'; break; /* found end of quoted string */ } else if (point_in_line[in] == '\\' && in < PATHLEN - 1 && (point_in_line[in + 1]== '"' || point_in_line[in + 1] == '\\')) { /* un-escape \" or \\ sequence */ newpath[out++] = point_in_line[in + 1]; in += 2; } else { newpath[out++] = point_in_line[in++]; } } /* while */ if (in >= PATHLEN) { /* safeguard against almost-overflow */ 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 ++; } } if (names == stdin) clearerr(stdin); else (void) fclose(names); firstbuild = NO; return; } /* make a list of all the source files in the directories */ for (i = 0; i < nsrcdirs; ++i) { scan_dir(srcdirs[i], recurse_dir); }}/* scan a directory (recursively?) for source files */static voidscan_dir(const char *adir, BOOL recurse_dir){ DIR *dirfile; int adir_len = strlen(adir); /* FIXME: no guards against adir_len > PATHLEN, yet */ if ((dirfile = opendir(adir)) != NULL) { struct dirent *entry; char path[PATHLEN + 1]; char *file; while ((entry = readdir(dirfile)) != NULL) { if ((strcmp(".",entry->d_name) != 0) && (strcmp("..",entry->d_name) != 0)) { struct stat buf; sprintf(path,"%s/%.*s", adir, PATHLEN - 2 - adir_len, entry->d_name); if (lstat(path,&buf) == 0) { file = entry->d_name; if (recurse_dir && S_ISDIR(buf.st_mode) ) { scan_dir(path, recurse_dir); } else if (#ifdef __DJGPP__ /* FIXME: should test for feature, not platform */ 1 /* DJGPP doesn't have this field in dirent */#else entry->d_ino != 0#endif && issrcfile(mybasename(path)) && infilelist(path) == NO) { addsrcfile(path); } } } } closedir(dirfile); } return;}/* see if this is a source file */static BOOLissrcfile(char *file){ struct stat statstruct; char *s; /* if there is a file suffix */ if ((s = strrchr(file, '.')) != NULL && *++s != '\0') { /* if an SCCS or versioned file */ if (file[1] == '.' && file + 2 != s) { /* 1 character prefix */ switch (*file) { case 's': case 'S': return(NO); } } if (s[1] == '\0') { /* 1 character suffix */ switch (*s) { case 'c': case 'h': case 'l': case 'y': case 'C': case 'G': case 'H': case 'L': return(YES); } } else if (s[2] == '\0') { /* 2 character suffix */ if ((*s == 'b' && s[1] == 'p') || /* breakpoint listing */ (*s == 'q' && (s[1] == 'c' || s[1] == 'h')) || /* Ingres */ (*s == 's' && s[1] == 'd') || /* SDL */ (*s == 'c' && s[1] == 'c') || /* C++ source */ (*s == 'h' && s[1] == 'h')) { /* C++ header */ /* some directories have 2 character suffixes so make sure it is a file */ if (lstat(file, &statstruct) == 0 && S_ISREG(statstruct.st_mode)) { return(YES); } } } else if( s[3] == '\0' ) { /* 3 char suffix */ if( (*s == 't' && s[1] == 'c' && s[2] == 'c' ) || /* C++ template source */ 0) { /* make sure it is a file */ if (lstat(file, &statstruct) == 0 && S_ISREG(statstruct.st_mode)) { return(YES); } } } } return(NO);}/* add an include file to the source file list */voidincfile(char *file, char *type){ char name[PATHLEN + 1]; char path[PATHLEN + 1]; char *s; int i; /* see if the file is already in the source file list */ if (infilelist(file) == YES) { return; } /* look in current directory if it was #include "file" */ if (type[0] == '"' && (s = inviewpath(file)) != NULL) { addsrcfile(s); } else { int file_len = strlen(file); /* search for the file in the #include directory list */ for (i = 0; i < nincdirs; ++i) { /* don't include the file from two directories */ (void) sprintf(name, "%.*s/%s", PATHLEN - 2 - file_len, incnames[i], file); if (infilelist(name) == YES) { break; } /* make sure it exists and is readable */ (void) sprintf(path, "%.*s/%s", PATHLEN - 2 - file_len, incdirs[i], file); if (access(compath(path), READ) == 0) { addsrcfile(path); break; } } }}/* see if the file is already in the list */BOOLinfilelist(char *path){ struct listitem *p; for (p = srcnames[hash(compath(path)) % HASHMOD]; p != NULL; p = p->next) { if (strequal(path, p->text)) { return(YES); } } return(NO);}/* search for the file in the view path */char *inviewpath(char *file){ static char path[PATHLEN + 1]; int i; /* look for the file */ if (access(compath(file), READ) == 0) { return(file); } /* if it isn't a full path name and there is a multi-directory view path */ if (*file != '/' && vpndirs > 1) { int file_len = strlen(file); /* compute its path from higher view path source dirs */ for (i = 1; i < nvpsrcdirs; ++i) { (void) sprintf(path, "%.*s/%s", PATHLEN - 2 - file_len, srcdirs[i], file); if (access(compath(path), READ) == 0) { return(path); } } } return(NULL);}/* add a source file to the list */voidaddsrcfile(char *path){ struct listitem *p; int i; /* make sure there is room for the file */ if (nsrcfiles == msrcfiles) { msrcfiles += SRCINC; srcfiles = myrealloc(srcfiles, msrcfiles * sizeof(char *)); } /* add the file to the list */ srcfiles[nsrcfiles++] = stralloc(compath(path)); p = mymalloc(sizeof(struct listitem)); p->text = stralloc(compath(path)); i = hash(p->text) % HASHMOD; p->next = srcnames[i]; srcnames[i] = p;}/* free the memory allocated for the source file list */voidfreefilelist(void){ struct listitem *p, *nextp; int i; /* if '-d' option is used a string space block is allocated */ if (isuptodate == NO) { while (nsrcfiles > 0) { free (srcfiles[--nsrcfiles]); } } else { /* for '-d' option free the string space block */ if (nsrcfiles > 0) /* protect against empty list */ free (srcfiles[0]); nsrcfiles = 0; } free (srcfiles); /* HBB 20000421: avoid leak */ msrcfiles = 0; srcfiles=0; for (i = 0; i < HASHMOD; ++i) { for (p = srcnames[i]; p != NULL; p = nextp) { /* HBB 20000421: avoid memory leak */ free(p->text); nextp = p->next; free(p); } srcnames[i] = NULL; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -