options.c 6.7 KB

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