options.c 6.6 KB

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