Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

692 Zeilen
20KB

  1. /*===========================================================================
  2. Copyright (c) 1998-2000, The Santa Cruz Operation
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. *Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. *Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. *Neither name of The Santa Cruz Operation nor the names of its contributors
  12. may be used to endorse or promote products derived from this software
  13. without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
  15. IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT falseT LIMITED TO,
  16. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
  18. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. CONSEQUENTIAL DAMAGES (INCLUDING, BUT falseT LIMITED TO, PROCUREMENT OF
  20. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. INTERRUPTION)
  22. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  25. DAMAGE.
  26. =========================================================================*/
  27. /* cscope - interactive C symbol cross-reference
  28. *
  29. * directory searching functions
  30. */
  31. #include "global.h"
  32. #include "vp.h" /* vpdirs and vpndirs */
  33. #include <stdlib.h>
  34. #include <sys/types.h> /* needed by stat.h and dirent.h */
  35. #include <dirent.h>
  36. #include <sys/stat.h> /* stat */
  37. #include <assert.h>
  38. #define DIRSEPS " ,:" /* directory list separators */
  39. #define DIRINC 10 /* directory list size increment */
  40. #define HASHMOD 2003 /* must be a prime number */
  41. #define SRCINC HASHMOD /* source file list size increment */
  42. /* largest known database had 22049 files */
  43. char currentdir[PATHLEN + 1]; /* current directory */
  44. char **incdirs; /* #include directories */
  45. char **srcdirs; /* source directories */
  46. char **srcfiles; /* source files */
  47. unsigned long nincdirs; /* number of #include directories */
  48. unsigned long nsrcdirs; /* number of source directories */
  49. unsigned long nsrcfiles; /* number of source files */
  50. unsigned long msrcfiles = SRCINC; /* maximum number of source files */
  51. static char **incnames; /* #include directory names without view pathing */
  52. static unsigned long mincdirs = DIRINC; /* maximum number of #include directories */
  53. static unsigned long msrcdirs; /* maximum number of source directories */
  54. static unsigned long nvpsrcdirs; /* number of view path source directories */
  55. static struct listitem { /* source file names without view pathing */
  56. char *text;
  57. struct listitem *next;
  58. } *srcnames[HASHMOD];
  59. /* Internal prototypes: */
  60. static bool accessible_file(char *file);
  61. static bool issrcfile(char *file);
  62. static void addsrcdir(char *dir);
  63. static void addincdir(char *name, char *path);
  64. static void scan_dir(const char *dirfile, bool recurse);
  65. static void makevpsrcdirs(void);
  66. /* make the view source directory list */
  67. static void makevpsrcdirs(void) {
  68. int i;
  69. /* return if this function has already been called */
  70. if(nsrcdirs > 0) { return; }
  71. /* get the current directory name */
  72. if(getcwd(currentdir, PATHLEN) == NULL) {
  73. fprintf(stderr, PROGRAM_NAME ": warning: cannot get current directory name\n");
  74. strcpy(currentdir, "<unknown>");
  75. }
  76. /* see if there is a view path and this directory is in it */
  77. vpinit(currentdir);
  78. if(vpndirs > 1) {
  79. nsrcdirs = vpndirs;
  80. } else {
  81. nsrcdirs = 1;
  82. }
  83. /* create the source directory list */
  84. msrcdirs = nsrcdirs + DIRINC;
  85. srcdirs = malloc(msrcdirs * sizeof(*srcdirs));
  86. *srcdirs = "."; /* first source dir is always current dir */
  87. for(i = 1; i < vpndirs; ++i) {
  88. srcdirs[i] = vpdirs[i];
  89. }
  90. /* save the number of original source directories in the view path */
  91. nvpsrcdirs = nsrcdirs;
  92. }
  93. /* add a source directory to the list for each view path source directory */
  94. void sourcedir(char *dirlist) {
  95. char path[PATHLEN + 1];
  96. char *dir;
  97. unsigned int i;
  98. makevpsrcdirs(); /* make the view source directory list */
  99. dirlist = strdup(dirlist); /* don't change environment variable text */
  100. /* parse the directory list */
  101. dir = strtok(dirlist, DIRSEPS);
  102. while(dir != NULL) {
  103. int dir_len = strlen(dir);
  104. addsrcdir(dir);
  105. /* if it isn't a full path name and there is a
  106. multi-directory view path */
  107. if(*dirlist != '/' && vpndirs > 1) {
  108. /* compute its path from higher view path source dirs */
  109. for(i = 1; i < nvpsrcdirs; ++i) {
  110. snprintf(path,
  111. sizeof(path),
  112. "%.*s/%s",
  113. PATHLEN - 2 - dir_len,
  114. srcdirs[i],
  115. dir);
  116. addsrcdir(path);
  117. }
  118. }
  119. dir = strtok(NULL, DIRSEPS);
  120. }
  121. free(dirlist); /* HBB 20000421: avoid memory leaks */
  122. }
  123. /* add a source directory to the list */
  124. static void addsrcdir(char *dir) {
  125. struct stat statstruct;
  126. /* make sure it is a directory */
  127. if(lstat(compath(dir), &statstruct) == 0 && S_ISDIR(statstruct.st_mode)) {
  128. /* note: there already is a source directory list */
  129. if(nsrcdirs == msrcdirs) {
  130. msrcdirs += DIRINC;
  131. srcdirs = realloc(srcdirs, msrcdirs * sizeof(*srcdirs));
  132. }
  133. srcdirs[nsrcdirs++] = strdup(dir);
  134. }
  135. }
  136. /* HBB 20000421: new function, for avoiding leaks */
  137. /* free list of src directories */
  138. void freesrclist() {
  139. if(!srcdirs) return;
  140. while(nsrcdirs > 1)
  141. free(srcdirs[--nsrcdirs]);
  142. free(srcdirs);
  143. }
  144. /* add a #include directory to the list for each view path source directory */
  145. void includedir(char *dirlist) {
  146. char path[PATHLEN + 1];
  147. char *dir;
  148. unsigned int i;
  149. makevpsrcdirs(); /* make the view source directory list */
  150. dirlist = strdup(dirlist); /* don't change environment variable text */
  151. /* parse the directory list */
  152. dir = strtok(dirlist, DIRSEPS);
  153. while(dir != NULL) {
  154. size_t dir_len = strlen(dir);
  155. addincdir(dir, dir);
  156. /* if it isn't a full path name and there is a
  157. multi-directory view path */
  158. if(*dirlist != '/' && vpndirs > 1) {
  159. /* compute its path from higher view path source dirs */
  160. for(i = 1; i < nvpsrcdirs; ++i) {
  161. snprintf(path,
  162. sizeof(path),
  163. "%.*s/%s",
  164. (int)(PATHLEN - 2 - dir_len),
  165. srcdirs[i],
  166. dir);
  167. addincdir(dir, path);
  168. }
  169. }
  170. dir = strtok(NULL, DIRSEPS);
  171. }
  172. free(dirlist); /* HBB 20000421: avoid leaks */
  173. }
  174. /* add a #include directory to the list */
  175. static void addincdir(char *name, char *path) {
  176. struct stat statstruct;
  177. /* make sure it is a directory */
  178. if(lstat(compath(path), &statstruct) == 0 && S_ISDIR(statstruct.st_mode)) {
  179. if(incdirs == NULL) {
  180. incdirs = malloc(mincdirs * sizeof(*incdirs));
  181. incnames = malloc(mincdirs * sizeof(*incnames));
  182. } else if(nincdirs == mincdirs) {
  183. mincdirs += DIRINC;
  184. incdirs = realloc(incdirs, mincdirs * sizeof(*incdirs));
  185. incnames = realloc(incnames, mincdirs * sizeof(*incnames));
  186. }
  187. incdirs[nincdirs] = strdup(path);
  188. incnames[nincdirs++] = strdup(name);
  189. }
  190. }
  191. /* HBB 2000421: new function, for avoiding memory leaks */
  192. /* free the list of include files, if wanted */
  193. void freeinclist() {
  194. if(!incdirs) return;
  195. while(nincdirs > 0) {
  196. free(incdirs[--nincdirs]);
  197. free(incnames[nincdirs]);
  198. }
  199. free(incdirs);
  200. free(incnames);
  201. }
  202. /* make the source file list */
  203. void makefilelist(void) {
  204. static bool firstbuild = true; /* first time through */
  205. FILE *names; /* name file pointer */
  206. char dir[PATHLEN + 1];
  207. char path[PATHLEN + 1];
  208. char line[PATHLEN * 10];
  209. char *file;
  210. char *s;
  211. unsigned int i;
  212. makevpsrcdirs(); /* make the view source directory list */
  213. /* if -i was falseT given and there are source file arguments */
  214. if(namefile == NULL && fileargc > 0) {
  215. /* put them in a list that can be expanded */
  216. for(i = 0; i < fileargc; ++i) {
  217. file = fileargv[i];
  218. if(infilelist(file) == false) {
  219. if((s = inviewpath(file)) != NULL) {
  220. addsrcfile(s);
  221. } else {
  222. fprintf(stderr, PROGRAM_NAME ": cannot find file %s\n", file);
  223. errorsfound = true;
  224. }
  225. }
  226. }
  227. return;
  228. }
  229. /* see if a file name file exists */
  230. if(namefile == NULL && vpaccess(NAMEFILE, READ) == 0) { namefile = NAMEFILE; }
  231. if(namefile == NULL) {
  232. /* No namefile --> make a list of all the source files
  233. * in the directories */
  234. for(i = 0; i < nsrcdirs; ++i) {
  235. scan_dir(srcdirs[i], recurse_dir);
  236. }
  237. return;
  238. }
  239. /* Came here --> there is a file of source file names */
  240. if(strcmp(namefile, "-") == 0)
  241. names = stdin;
  242. else if((names = vpfopen(namefile, "r")) == NULL) {
  243. cannotopen(namefile);
  244. myexit(1);
  245. }
  246. /* get the names in the file */
  247. while(fgets(line, 10 * PATHLEN, names) != NULL) {
  248. char *point_in_line = line + (strlen(line) - 1);
  249. size_t length_of_name = 0;
  250. int unfinished_option = 0;
  251. bool done = false;
  252. /* Kill away \n left at end of fgets()'d string: */
  253. if(*point_in_line == '\n') *point_in_line = '\0';
  254. /* Parse whitespace-terminated strings in line: */
  255. point_in_line = line;
  256. while(sscanf(point_in_line, "%" PATHLEN_STR "s", path) == 1) {
  257. /* Have to store this length --- inviewpath() will
  258. * modify path, later! */
  259. length_of_name = strlen(path);
  260. if(*path == '-') { /* if an option */
  261. if(unfinished_option) {
  262. /* Can't have another option directly after an
  263. * -I or -p option with no name after it! */
  264. fprintf(stderr,
  265. PROGRAM_NAME
  266. ": Syntax error in namelist file %s: unfinished -I or -p option\n",
  267. namefile);
  268. unfinished_option = 0;
  269. }
  270. i = path[1];
  271. switch(i) {
  272. case 'c': /* ASCII characters only in crossref */
  273. compress = false;
  274. break;
  275. case 'k': /* ignore DFLT_INCDIR */
  276. kernelmode = true;
  277. break;
  278. case 'q': /* quick search */
  279. invertedindex = true;
  280. break;
  281. case 'T': /* truncate symbols to 8 characters */
  282. trun_syms = true;
  283. break;
  284. case 'I': /* #include file directory */
  285. case 'p': /* file path components to display */
  286. /* coverity[overwrite_var] */
  287. s = path + 2; /* for "-Ipath" */
  288. if(*s == '\0') { /* if "-I path" */
  289. unfinished_option = i;
  290. break;
  291. }
  292. /* this code block used several times in here
  293. * --> make it a macro to avoid unnecessary
  294. * duplication */
  295. #define HANDLE_OPTION_ARGUMENT(i, s) \
  296. switch(i) { \
  297. case 'I': /* #include file directory */ \
  298. if(firstbuild == true) { \
  299. /* expand $ and ~ */ \
  300. shellpath(dir, sizeof(dir), (s)); \
  301. includedir(dir); \
  302. } \
  303. unfinished_option = 0; \
  304. done = true; \
  305. break; \
  306. case 'p': /* file path components to display */ \
  307. if(*(s) < '0' || *(s) > '9') { \
  308. fprintf(stderr, \
  309. "csope: -p option in file %s: missing or invalid numeric value\n", \
  310. namefile); \
  311. } \
  312. dispcomponents = atoi(s); \
  313. unfinished_option = 0; \
  314. done = true; \
  315. break; \
  316. default: \
  317. done = false; \
  318. } /* switch(i) */
  319. /* ... and now call it for the first time */
  320. HANDLE_OPTION_ARGUMENT(i, s)
  321. break;
  322. default:
  323. fprintf(stderr,
  324. PROGRAM_NAME
  325. ": only -I, -c, -k, -p, and -T options can be in file %s\n",
  326. namefile);
  327. } /* switch(i) */
  328. } /* if('-') */
  329. else if(*path == '"') {
  330. /* handle quoted filenames... */
  331. size_t in = 1, out = 0;
  332. char *newpath = malloc(PATHLEN + 1);
  333. while(in < PATHLEN && point_in_line[in] != '\0') {
  334. if(point_in_line[in] == '"') {
  335. newpath[out] = '\0';
  336. /* Tell outer loop to skip over this entire
  337. * quoted string */
  338. length_of_name = in + 1;
  339. break; /* found end of quoted string */
  340. } else if(point_in_line[in] == '\\' && in < PATHLEN - 1 &&
  341. (point_in_line[in + 1] == '"' ||
  342. point_in_line[in + 1] == '\\')) {
  343. /* un-escape \" or \\ sequence */
  344. newpath[out++] = point_in_line[in + 1];
  345. in += 2;
  346. } else {
  347. newpath[out++] = point_in_line[in++];
  348. }
  349. } /* while(in) */
  350. if(in >= PATHLEN) { /* safeguard against almost-overflow */
  351. newpath[out] = '\0';
  352. }
  353. /* If an -I or -p arguments was missing before,
  354. * treat this name as the argument: */
  355. HANDLE_OPTION_ARGUMENT(unfinished_option, newpath);
  356. if(!done) {
  357. /* coverity[overwrite_var] */
  358. if((s = inviewpath(newpath)) != NULL) {
  359. addsrcfile(s);
  360. } else {
  361. fprintf(stderr, PROGRAM_NAME ": cannot find file %s\n", newpath);
  362. errorsfound = true;
  363. }
  364. }
  365. free(newpath);
  366. } /* if(quoted name) */
  367. else {
  368. /* ... so this is an ordinary file name, unquoted */
  369. /* If an -I or -p arguments was missing before,
  370. * treat this name as the argument: */
  371. HANDLE_OPTION_ARGUMENT(unfinished_option, path);
  372. if(!done) {
  373. if((s = inviewpath(path)) != NULL) {
  374. addsrcfile(s);
  375. } else {
  376. fprintf(stderr, PROGRAM_NAME ": cannot find file %s\n", path);
  377. errorsfound = true;
  378. }
  379. }
  380. } /* else(ordinary name) */
  381. point_in_line += length_of_name;
  382. while(isspace((unsigned char)*point_in_line))
  383. point_in_line++;
  384. } /* while(sscanf(line)) */
  385. } /* while(fgets(line)) */
  386. if(names == stdin)
  387. clearerr(stdin);
  388. else
  389. fclose(names);
  390. firstbuild = false;
  391. return;
  392. }
  393. /* scan a directory (recursively?) for source files */
  394. static void scan_dir(const char *adir, bool recurse_dir) {
  395. DIR *dirfile;
  396. int adir_len = strlen(adir);
  397. /* FIXME: no guards against adir_len > PATHLEN, yet */
  398. if((dirfile = opendir(adir)) != NULL) {
  399. struct dirent *entry;
  400. char path[PATHLEN + 1];
  401. while((entry = readdir(dirfile)) != NULL) {
  402. if((strcmp(".", entry->d_name) != 0) && (strcmp("..", entry->d_name) != 0)) {
  403. struct stat buf;
  404. snprintf(path,
  405. sizeof(path),
  406. "%s/%.*s",
  407. adir,
  408. PATHLEN - 2 - adir_len,
  409. entry->d_name);
  410. if(lstat(path, &buf) == 0) {
  411. if(recurse_dir && S_ISDIR(buf.st_mode)) {
  412. scan_dir(path, recurse_dir);
  413. } else if(issrcfile(path) && infilelist(path) == false &&
  414. access(path, R_OK) == 0) {
  415. addsrcfile(path);
  416. }
  417. }
  418. }
  419. }
  420. closedir(dirfile);
  421. }
  422. return;
  423. }
  424. /* see if this is a source file */
  425. static bool issrcfile(char *path) {
  426. struct stat statstruct;
  427. const char *file = basename(path);
  428. char *s = strrchr(file, '.');
  429. bool looks_like_source = false;
  430. /* ensure there is some file suffix */
  431. if(s == NULL || *(++s) == '\0') { return false; }
  432. /* if an SCCS or versioned file */
  433. if(file[1] == '.' && file + 2 != s) { /* 1 character prefix */
  434. switch(*file) {
  435. case 's':
  436. case 'S':
  437. return (false);
  438. }
  439. }
  440. if(s[1] == '\0') { /* 1 character suffix */
  441. switch(*s) {
  442. case 'c':
  443. case 'h':
  444. case 'l':
  445. case 'y':
  446. case 'C':
  447. case 'G':
  448. case 'H':
  449. case 'L':
  450. looks_like_source = true;
  451. }
  452. } else if((s[2] == '\0') /* 2 char suffix */
  453. && ((s[0] == 'b' && s[1] == 'p') /* breakpoint listing */
  454. || (s[0] == 'q' && (s[1] == 'c' || s[1] == 'h')) /* Ingres */
  455. || (s[0] == 's' && s[1] == 'd') /* SDL */
  456. || (s[0] == 'c' && s[1] == 'c') /* C++ source */
  457. || (s[0] == 'h' && s[1] == 'h'))) { /* C++ header */
  458. looks_like_source = true;
  459. } else if((s[3] == '\0') /* 3 char suffix */
  460. /* C++ template source */
  461. && ((s[0] == 't' && s[1] == 'c' && s[2] == 'c')
  462. /* C++ source: */
  463. || (s[0] == 'c' && s[1] == 'p' && s[2] == 'p') ||
  464. (s[0] == 'c' && s[1] == 'x' && s[2] == 'x') ||
  465. (s[0] == 'h' && s[1] == 'p' && s[2] == 'p') ||
  466. (s[0] == 'h' && s[1] == 'x' && s[2] == 'x'))) {
  467. looks_like_source = true;
  468. }
  469. if(looks_like_source != true) return false;
  470. /* make sure it is a file */
  471. if(lstat(path, &statstruct) == 0 && S_ISREG(statstruct.st_mode)) { return (true); }
  472. return false;
  473. }
  474. /* add an include file to the source file list */
  475. void incfile(char *file, char *type) {
  476. char name[PATHLEN + 1];
  477. char path[PATHLEN + 1];
  478. char *s;
  479. unsigned int i;
  480. assert(file != NULL); /* should never happen, but let's make sure anyway */
  481. /* see if the file is already in the source file list */
  482. if(infilelist(file) == true) { return; }
  483. /* look in current directory if it was #include "file" */
  484. if(type[0] == '"' && (s = inviewpath(file)) != NULL) {
  485. addsrcfile(s);
  486. } else {
  487. size_t file_len = strlen(file);
  488. /* search for the file in the #include directory list */
  489. for(i = 0; i < nincdirs; ++i) {
  490. /* don't include the file from two directories */
  491. snprintf(name,
  492. sizeof(name),
  493. "%.*s/%s",
  494. (int)(PATHLEN - 2 - file_len),
  495. incnames[i],
  496. file);
  497. if(infilelist(name) == true) { break; }
  498. /* make sure it exists and is readable */
  499. snprintf(path,
  500. sizeof(path),
  501. "%.*s/%s",
  502. (int)(PATHLEN - 2 - file_len),
  503. incdirs[i],
  504. file);
  505. if(access(compath(path), READ) == 0) {
  506. addsrcfile(path);
  507. break;
  508. }
  509. }
  510. }
  511. }
  512. /* see if the file is already in the list */
  513. bool infilelist(char *path) {
  514. struct listitem *p;
  515. for(p = srcnames[hash(compath(path)) % HASHMOD]; p != NULL; p = p->next) {
  516. if(strequal(path, p->text)) { return (true); }
  517. }
  518. return (false);
  519. }
  520. /* check if a file is readable enough to be allowed in the
  521. * database */
  522. static bool accessible_file(char *file) {
  523. if(access(compath(file), READ) == 0) {
  524. struct stat stats;
  525. if(lstat(file, &stats) == 0 && S_ISREG(stats.st_mode)) { return true; }
  526. }
  527. return false;
  528. }
  529. /* search for the file in the view path */
  530. char *inviewpath(char *file) {
  531. static char path[PATHLEN + 1];
  532. unsigned int i;
  533. /* look for the file */
  534. if(accessible_file(file)) { return (file); }
  535. /* if it isn't a full path name and there is a multi-directory
  536. * view path */
  537. if(*file != '/' && vpndirs > 1) {
  538. int file_len = strlen(file);
  539. /* compute its path from higher view path source dirs */
  540. for(i = 1; i < nvpsrcdirs; ++i) {
  541. snprintf(path,
  542. sizeof(path),
  543. "%.*s/%s",
  544. PATHLEN - 2 - file_len,
  545. srcdirs[i],
  546. file);
  547. if(accessible_file(path)) { return (path); }
  548. }
  549. }
  550. return (NULL);
  551. }
  552. /* add a source file to the list */
  553. void addsrcfile(char *path) {
  554. struct listitem *p;
  555. int i;
  556. /* make sure there is room for the file */
  557. if(nsrcfiles == msrcfiles) {
  558. msrcfiles += SRCINC;
  559. srcfiles = realloc(srcfiles, msrcfiles * sizeof(*srcfiles));
  560. }
  561. /* add the file to the list */
  562. srcfiles[nsrcfiles++] = strdup(compath(path));
  563. p = malloc(sizeof(*p));
  564. p->text = strdup(compath(path));
  565. i = hash(p->text) % HASHMOD;
  566. p->next = srcnames[i];
  567. srcnames[i] = p;
  568. }
  569. /* free the memory allocated for the source file list */
  570. void freefilelist(void) {
  571. struct listitem *p, *nextp;
  572. int i;
  573. /* if '-d' option is used a string space block is allocated */
  574. if(isuptodate == false) {
  575. while(nsrcfiles > 0) {
  576. free(srcfiles[--nsrcfiles]);
  577. }
  578. } else {
  579. /* for '-d' option free the string space block */
  580. /* protect against empty list */
  581. if(nsrcfiles > 0) free(srcfiles[0]);
  582. nsrcfiles = 0;
  583. }
  584. free(srcfiles); /* HBB 20000421: avoid leak */
  585. msrcfiles = 0;
  586. srcfiles = 0;
  587. for(i = 0; i < HASHMOD; ++i) {
  588. for(p = srcnames[i]; p != NULL; p = nextp) {
  589. /* HBB 20000421: avoid memory leak */
  590. free(p->text);
  591. nextp = p->next;
  592. free(p);
  593. }
  594. srcnames[i] = NULL;
  595. }
  596. }