options.c 6.6 KB

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