You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
3.7KB

  1. #include "global.h"
  2. #include "build.h"
  3. #include "vp.h"
  4. #include "version.h" /* FILEVERSION and FIXVERSION */
  5. #include <stdlib.h> /* atoi */
  6. #include <getopt.h>
  7. bool remove_symfile_onexit = false;
  8. bool onesearch; /* one search only in line mode */
  9. char *reflines; /* symbol reference lines file */
  10. char **parse_options(int *argc, char **argv) {
  11. int opt;
  12. int longind;
  13. char path[PATHLEN + 1]; /* file path */
  14. char *s;
  15. int argcc = *argc;
  16. struct option lopts[] = {
  17. {"help", 0, NULL, 'h'},
  18. {"version", 0, NULL, 'V'},
  19. {0, 0, 0, 0 }
  20. };
  21. while((opt = getopt_long(argcc,
  22. argv,
  23. "hVbcCdeF:f:I:i:kLl0:1:2:3:4:5:6:7:8:9:P:p:qRs:TUuvX",
  24. lopts,
  25. &longind)) != -1) {
  26. switch(opt) {
  27. case '?':
  28. usage();
  29. myexit(1);
  30. break;
  31. case 'X':
  32. remove_symfile_onexit = true;
  33. break;
  34. case '0':
  35. case '1':
  36. case '2':
  37. case '3':
  38. case '4':
  39. case '5':
  40. case '6':
  41. case '7':
  42. case '8':
  43. case '9':
  44. /* The input fields numbers for line mode operation */
  45. field = opt - '0';
  46. if(strlen(optarg) > PATHLEN) {
  47. postfatal("\
  48. cscope: pattern too long, cannot be > \
  49. %d characters\n",
  50. PATLEN);
  51. }
  52. strcpy(input_line, optarg);
  53. break;
  54. case 'b': /* only build the cross-reference */
  55. buildonly = true;
  56. linemode = true;
  57. break;
  58. case 'c': /* ASCII characters only in crossref */
  59. compress = false;
  60. break;
  61. case 'C': /* turn on caseless mode for symbol searches */
  62. caseless = true;
  63. egrepcaseless(caseless); /* simulate egrep -i flag */
  64. break;
  65. case 'd': /* consider crossref up-to-date */
  66. isuptodate = true;
  67. break;
  68. case 'e': /* suppress ^E prompt between files */
  69. editallprompt = false;
  70. break;
  71. case 'h':
  72. longusage();
  73. myexit(1);
  74. break;
  75. case 'k': /* ignore DFLT_INCDIR */
  76. kernelmode = true;
  77. break;
  78. case 'L':
  79. onesearch = true;
  80. /* FALLTHROUGH */
  81. case 'l':
  82. linemode = true;
  83. break;
  84. case 'v':
  85. verbosemode = true;
  86. break;
  87. case 'V':
  88. fprintf(stderr, PROGRAM_NAME ": version %d%s\n", FILEVERSION, FIXVERSION);
  89. myexit(0);
  90. break;
  91. case 'q': /* quick search */
  92. invertedindex = true;
  93. break;
  94. case 'T': /* truncate symbols to 8 characters */
  95. trun_syms = true;
  96. break;
  97. case 'u': /* unconditionally build the cross-reference */
  98. unconditional = true;
  99. break;
  100. case 'U': /* assume some files have changed */
  101. fileschanged = true;
  102. break;
  103. case 'R':
  104. recurse_dir = true;
  105. break;
  106. case 'f': /* alternate cross-reference file */
  107. reffile = optarg;
  108. if(strlen(reffile) > sizeof(path) - 3) {
  109. postfatal("\
  110. cscope: reffile too long, cannot \
  111. be > %d characters\n",
  112. sizeof(path) - 3);
  113. /* NOTREACHED */
  114. }
  115. strcpy(path, reffile);
  116. s = path + strlen(path);
  117. strcpy(s, ".in");
  118. /*coverity[overwrite_var]*/
  119. invname = strdup(path);
  120. strcpy(s, ".po");
  121. /*coverity[overwrite_var]*/
  122. invpost = strdup(path);
  123. break;
  124. case 'F': /* symbol reference lines file */
  125. reflines = optarg;
  126. break;
  127. case 'i': /* file containing file names */
  128. namefile = optarg;
  129. break;
  130. case 'I': /* #include file directory */
  131. includedir(optarg);
  132. break;
  133. case 'p': /* file path components to display */
  134. dispcomponents = atoi(optarg);
  135. break;
  136. case 'P': /* prepend path to file names */
  137. prependpath = optarg;
  138. break;
  139. case 's': /* additional source file directory */
  140. sourcedir(optarg);
  141. break;
  142. }
  143. }
  144. /*
  145. * This adjusts argv so that we only see the remaining
  146. * args. Its ugly, but we need to do it so that the rest
  147. * of the main routine doesn't get all confused
  148. */
  149. *argc = *argc - optind;
  150. return argv + optind;
  151. }