options.c 7.4 KB

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