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