options.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. /* U S E R O P T I O N - H A N D L I N G */
  7. #include "lint.h"
  8. #include "botch_free.h"
  9. #include <alloc.h>
  10. #include "nofloat.h"
  11. #include "nopp.h"
  12. #include "idfsize.h"
  13. #include "nobitfield.h"
  14. #include "class.h"
  15. #include "macro.h"
  16. #include "idf.h"
  17. #include "arith.h"
  18. #include "sizes.h"
  19. #include "align.h"
  20. #include "use_tmp.h"
  21. #include "dataflow.h"
  22. #include "noRoption.h"
  23. #include "dbsymtab.h"
  24. #ifndef NOPP
  25. extern char **inctable;
  26. extern int inc_pos;
  27. extern int inc_max;
  28. extern int inc_total;
  29. int do_dependencies = 0;
  30. char *dep_file = 0;
  31. #endif /* NOPP */
  32. char options[128]; /* one for every char */
  33. #ifdef LINT
  34. char loptions[128]; /* one for every char */
  35. #endif /* LINT */
  36. extern int idfsize;
  37. extern int density;
  38. static int txt2int();
  39. do_option(text)
  40. char *text;
  41. {
  42. register char opt;
  43. next_option: /* to allow combined one-char options */
  44. switch (opt = *text++) {
  45. case 0: /* to end the goto next_option loop */
  46. break;
  47. default:
  48. #ifndef LINT
  49. fatal("illegal option: %c", opt);
  50. #else /* LINT */
  51. warning("illegal option: %c", opt);
  52. #endif /* LINT */
  53. break;
  54. case '-':
  55. options[*text++] = 1; /* flags, debug options etc. */
  56. goto next_option;
  57. #ifndef LINT
  58. #ifdef DATAFLOW
  59. case 'd':
  60. #endif /* DATAFLOW */
  61. case 'p': /* procentry/procexit */
  62. case 'L' : /* no fil/lin */
  63. case 'n': /* use no registers */
  64. case 'w': /* no warnings will be given */
  65. options[opt] = 1;
  66. goto next_option;
  67. #endif /* LINT */
  68. #ifdef LINT
  69. case 'h': /* heuristic tests */
  70. case 'v': /* no complaints about unused arguments */
  71. case 'a': /* check long->int int->long conversions */
  72. case 'b': /* don't report unreachable break-statements */
  73. case 'x': /* complain about unused extern declared variables */
  74. case 'u': /* no "used but not defined"; for pass 2 */
  75. case 'L': /* lintlibrary */
  76. loptions[opt] = 1;
  77. goto next_option;
  78. #endif /* LINT */
  79. #ifndef LINT
  80. #ifndef NOPP
  81. case 'A' : /* Amake dependency generation */
  82. do_dependencies = 1;
  83. if (*text) {
  84. dep_file = text;
  85. }
  86. break;
  87. case 'i':
  88. case 'm':
  89. options[opt] = 1;
  90. break;
  91. #endif /* NOPP */
  92. #endif /* LINT */
  93. #ifdef DBSYMTAB
  94. case 'g': /* symbol table for debugger */
  95. options['g'] = 1;
  96. options['n'] = 1;
  97. break;
  98. #endif /* DBSYMTAB */
  99. case 'R': /* strict version */
  100. #ifndef NOROPTION
  101. options[opt] = 1;
  102. #else /* NOROPTION */
  103. warning("-R option not implemented");
  104. #endif /* NOROPTION */
  105. goto next_option;
  106. #ifdef ___XXX___
  107. deleted, is now a debug-flag
  108. case 'C' : /* E option + comment output */
  109. #ifndef NOPP
  110. options['E'] = 1;
  111. warning("-C: comment is not output");
  112. #else /* NOPP */
  113. warning("-C option ignored");
  114. #endif /* NOPP */
  115. break;
  116. #endif /* ___XXX___ */
  117. case 'D' : { /* -Dname : predefine name */
  118. #ifndef NOPP
  119. register char *cp = text, *name, *mactext;
  120. if (class(*cp) != STIDF) {
  121. error("identifier missing in -D%s", text);
  122. break;
  123. }
  124. name = cp;
  125. while (*cp && in_idf(*cp)) {
  126. ++cp;
  127. }
  128. if (!*cp) { /* -Dname */
  129. mactext = "1";
  130. }
  131. else
  132. if (*cp == '=') { /* -Dname=text */
  133. *cp++ = '\0'; /* end of name */
  134. mactext = cp;
  135. }
  136. else { /* -Dname?? */
  137. error("malformed option -D%s", text);
  138. break;
  139. }
  140. macro_def(str2idf(name), mactext, -1, strlen(mactext),
  141. NOFLAG);
  142. #else /* NOPP */
  143. warning("-D option ignored");
  144. #endif /* NOPP */
  145. break;
  146. }
  147. #ifdef ___XXX___
  148. deleted, is now a debug-flag
  149. case 'E' : /* run preprocessor only, with #<int> */
  150. #ifndef NOPP
  151. options['E'] = 1;
  152. #else /* NOPP */
  153. warning("-E option ignored");
  154. #endif /* NOPP */
  155. break;
  156. #endif /* ___XXX___ */
  157. case 'I' : /* -Ipath : insert "path" into include list */
  158. #ifndef NOPP
  159. if (*text) {
  160. int i;
  161. register char *new = text;
  162. if (++inc_total > inc_max) {
  163. inctable = (char **)
  164. Realloc((char *) inctable,(inc_max+=10)*sizeof(char *));
  165. }
  166. for (i = inc_pos++; i < inc_total; i++) {
  167. char *tmp = inctable[i];
  168. inctable[i] = new;
  169. new = tmp;
  170. }
  171. }
  172. else inctable[inc_pos] = 0;
  173. #else /* NOPP */
  174. warning("-I option ignored");
  175. #endif /* NOPP */
  176. break;
  177. case 'M': /* maximum identifier length */
  178. idfsize = txt2int(&text);
  179. if (*text || idfsize <= 0)
  180. fatal("malformed -M option");
  181. if (idfsize > IDFSIZE)
  182. fatal("maximum identifier length is %d", IDFSIZE);
  183. break;
  184. #ifdef ___XXX___
  185. deleted, is now a debug-flag
  186. case 'P' : /* run preprocessor stand-alone, without #'s */
  187. #ifndef NOPP
  188. options['E'] = 1;
  189. options['P'] = 1;
  190. #else /* NOPP */
  191. warning("-P option ignored");
  192. #endif /* NOPP */
  193. break;
  194. #endif /* ___XXX___ */
  195. #ifdef LINT
  196. case 'S' : { /* -Sint : static scope number for lint */
  197. extern int stat_number;
  198. stat_number = txt2int(&text);
  199. break;
  200. }
  201. #endif /* LINT */
  202. case 'T' : {
  203. #ifdef USE_TMP
  204. extern char *C_tmpdir;
  205. if (*text)
  206. C_tmpdir = text;
  207. else
  208. C_tmpdir = ".";
  209. #else /* USE_TMP */
  210. warning("-T option ignored");
  211. #endif /* USE_TMP */
  212. break;
  213. }
  214. case 'U' : { /* -Uname : undefine predefined */
  215. #ifndef NOPP
  216. register struct idf *idef;
  217. if (*text) {
  218. if ((idef = str2idf(text))->id_macro) {
  219. free_macro(idef->id_macro);
  220. idef->id_macro = (struct macro *) 0;
  221. }
  222. }
  223. #else /* NOPP */
  224. warning("-U option ignored");
  225. #endif /* NOPP */
  226. break;
  227. }
  228. #ifndef LINT
  229. case 'V' : /* set object sizes and alignment requirements */
  230. #ifdef NOCROSS
  231. warning("-V option ignored");
  232. break;
  233. #else /* NOCROSS */
  234. {
  235. register arith sz, algn;
  236. char c;
  237. while (c = *text++) {
  238. sz = txt2int(&text);
  239. algn = 0;
  240. if (*text == '.') {
  241. text++;
  242. algn = txt2int(&text);
  243. }
  244. switch (c) {
  245. case 's': /* short */
  246. if (sz != (arith)0)
  247. short_size = sz;
  248. if (algn != 0)
  249. short_align = algn;
  250. break;
  251. case 'w': /* word */
  252. if (sz != (arith)0)
  253. dword_size = (word_size = sz) << 1;
  254. if (algn != 0)
  255. word_align = algn;
  256. break;
  257. case 'i': /* int */
  258. if (sz != (arith)0)
  259. int_size = sz;
  260. if (algn != 0)
  261. int_align = algn;
  262. break;
  263. case 'l': /* long */
  264. if (sz != (arith)0)
  265. long_size = sz;
  266. if (algn != 0)
  267. long_align = algn;
  268. break;
  269. case 'f': /* float */
  270. #ifndef NOFLOAT
  271. if (sz != (arith)0)
  272. float_size = sz;
  273. if (algn != 0)
  274. float_align = algn;
  275. #endif /* NOFLOAT */
  276. break;
  277. case 'd': /* double */
  278. #ifndef NOFLOAT
  279. if (sz != (arith)0)
  280. double_size = sz;
  281. if (algn != 0)
  282. double_align = algn;
  283. #endif /* NOFLOAT */
  284. break;
  285. case 'p': /* pointer */
  286. if (sz != (arith)0)
  287. pointer_size = sz;
  288. if (algn != 0)
  289. pointer_align = algn;
  290. break;
  291. case 'r': /* adjust bitfields right */
  292. #ifndef NOBITFIELD
  293. options['r'] = 1;
  294. #else /* NOBITFIELD */
  295. warning("bitfields are not implemented");
  296. #endif /* NOBITFIELD */
  297. break;
  298. case 'S': /* initial struct alignment */
  299. if (sz != (arith)0)
  300. struct_align = sz;
  301. break;
  302. case 'U': /* initial union alignment */
  303. if (sz != (arith)0)
  304. union_align = sz;
  305. break;
  306. default:
  307. error("-V: bad type indicator %c\n", c);
  308. }
  309. }
  310. break;
  311. }
  312. #endif /* NOCROSS */
  313. case 'S':
  314. density = txt2int(&text);
  315. break;
  316. #endif /* LINT */
  317. }
  318. }
  319. static int
  320. txt2int(tp)
  321. register char **tp;
  322. {
  323. /* the integer pointed to by *tp is read, while increasing
  324. *tp; the resulting value is yielded.
  325. */
  326. register int val = 0, ch;
  327. while (ch = **tp, ch >= '0' && ch <= '9') {
  328. val = val * 10 + ch - '0';
  329. (*tp)++;
  330. }
  331. return val;
  332. }