options.c 7.2 KB

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