options.c 6.6 KB

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