options.c 7.3 KB

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