options.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /* $Header$ */
  2. /* U S E R O P T I O N - H A N D L I N G */
  3. #include "botch_free.h"
  4. #include <alloc.h>
  5. #include "nofloat.h"
  6. #include "nopp.h"
  7. #include "idfsize.h"
  8. #include "maxincl.h"
  9. #include "nobitfield.h"
  10. #include "class.h"
  11. #include "macro.h"
  12. #include "idf.h"
  13. #include "arith.h"
  14. #include "sizes.h"
  15. #include "align.h"
  16. #include "use_tmp.h"
  17. #include "dataflow.h"
  18. #ifndef NOPP
  19. extern char *inctable[MAXINCL];
  20. extern int inc_pos;
  21. #endif NOPP
  22. extern char options[];
  23. extern int idfsize;
  24. #ifdef USE_TMP
  25. extern char *tmpfdir; /* main.c */
  26. #endif USE_TMP
  27. int txt2int();
  28. do_option(text)
  29. char *text;
  30. {
  31. switch(*text++) {
  32. default:
  33. fatal("illegal option: %c", *--text);
  34. case '-':
  35. options[*text] = 1; /* flags, debug options etc. */
  36. break;
  37. #ifdef DATAFLOW
  38. case 'd':
  39. #endif DATAFLOW
  40. case 'p': /* procentry/procexit */
  41. case 'L' : /* no fil/lin */
  42. case 'n': /* use no registers */
  43. case 'w': /* no warnings will be given */
  44. case 'R': /* strict version */
  45. options[*(text-1)] = 1;
  46. break;
  47. #ifdef ___XXX___
  48. deleted, is now a debug-flag
  49. case 'C' : /* E option + comment output */
  50. #ifndef NOPP
  51. options['E'] = 1;
  52. warning("-C: comment is not output");
  53. #else NOPP
  54. warning("-C option ignored");
  55. #endif NOPP
  56. break;
  57. #endif ___XXX___
  58. case 'D' : { /* -Dname : predefine name */
  59. #ifndef NOPP
  60. register char *cp = text, *name, *mactext;
  61. if (class(*cp) != STIDF) {
  62. error("identifier missing in -D%s", text);
  63. break;
  64. }
  65. name = cp;
  66. while (*cp && in_idf(*cp)) {
  67. ++cp;
  68. }
  69. if (!*cp) { /* -Dname */
  70. mactext = "1";
  71. }
  72. else
  73. if (*cp == '=') { /* -Dname=text */
  74. *cp++ = '\0'; /* end of name */
  75. mactext = cp;
  76. }
  77. else { /* -Dname?? */
  78. error("malformed option -D%s", text);
  79. break;
  80. }
  81. macro_def(str2idf(name), mactext, -1, strlen(mactext),
  82. NOFLAG);
  83. #else NOPP
  84. warning("-D option ignored");
  85. #endif NOPP
  86. break;
  87. }
  88. #ifdef ___XXX___
  89. case 'E' : /* run preprocessor only, with #<int> */
  90. #ifndef NOPP
  91. options['E'] = 1;
  92. #else NOPP
  93. warning("-E option ignored");
  94. #endif NOPP
  95. break;
  96. #endif ___XXX___
  97. case 'I' : /* -Ipath : insert "path" into include list */
  98. #ifndef NOPP
  99. if (*text) {
  100. register int i = inc_pos++;
  101. register char *new = text;
  102. while (new) {
  103. register char *tmp = inctable[i];
  104. inctable[i++] = new;
  105. if (i == MAXINCL)
  106. fatal("too many -I options");
  107. new = tmp;
  108. }
  109. }
  110. else inctable[inc_pos] = 0;
  111. #else NOPP
  112. warning("-I option ignored");
  113. #endif NOPP
  114. break;
  115. case 'M': /* maximum identifier length */
  116. idfsize = txt2int(&text);
  117. if (*text || idfsize <= 0)
  118. fatal("malformed -M option");
  119. if (idfsize > IDFSIZE)
  120. fatal("maximum identifier length is %d", IDFSIZE);
  121. break;
  122. case 'N' :
  123. #ifdef USE_TMP
  124. options['N'] = 1;
  125. #else USE_TMP
  126. warning("-N option ignored");
  127. #endif USE_TMP
  128. break;
  129. #ifdef ___XXX___
  130. case 'P' : /* run preprocessor stand-alone, without #'s */
  131. #ifndef NOPP
  132. options['E'] = 1;
  133. options['P'] = 1;
  134. #else NOPP
  135. warning("-P option ignored");
  136. #endif NOPP
  137. break;
  138. #endif ___XXX___
  139. #ifdef USE_TMP
  140. case 'T' :
  141. if (*text)
  142. tmpfdir = text;
  143. else
  144. tmpfdir = ".";
  145. #else USE_TMP
  146. warning("-T option ignored");
  147. #endif USE_TMP
  148. break;
  149. case 'U' : { /* -Uname : undefine predefined */
  150. #ifndef NOPP
  151. struct idf *idef;
  152. if (*text) {
  153. if ((idef = str2idf(text))->id_macro) {
  154. free_macro(idef->id_macro);
  155. idef->id_macro = (struct macro *) 0;
  156. }
  157. }
  158. #else NOPP
  159. warning("-U option ignored");
  160. #endif NOPP
  161. break;
  162. }
  163. case 'V' : /* set object sizes and alignment requirements */
  164. {
  165. arith size, align;
  166. char c;
  167. while (c = *text++) {
  168. size = txt2int(&text);
  169. align = 0;
  170. if (*text == '.') {
  171. text++;
  172. align = txt2int(&text);
  173. }
  174. switch (c) {
  175. case 's': /* short */
  176. if (size != (arith)0)
  177. short_size = size;
  178. if (align != 0)
  179. short_align = align;
  180. break;
  181. case 'w': /* word */
  182. if (size != (arith)0)
  183. dword_size = (word_size = size) << 1;
  184. if (align != 0)
  185. word_align = align;
  186. break;
  187. case 'i': /* int */
  188. if (size != (arith)0)
  189. int_size = size;
  190. if (align != 0)
  191. int_align = align;
  192. break;
  193. case 'l': /* long */
  194. if (size != (arith)0)
  195. long_size = size;
  196. if (align != 0)
  197. long_align = align;
  198. break;
  199. case 'f': /* float */
  200. #ifndef NOFLOAT
  201. if (size != (arith)0)
  202. float_size = size;
  203. if (align != 0)
  204. float_align = align;
  205. #endif NOFLOAT
  206. break;
  207. case 'd': /* double */
  208. #ifndef NOFLOAT
  209. if (size != (arith)0)
  210. double_size = size;
  211. if (align != 0)
  212. double_align = align;
  213. #endif NOFLOAT
  214. break;
  215. case 'p': /* pointer */
  216. if (size != (arith)0)
  217. pointer_size = size;
  218. if (align != 0)
  219. pointer_align = align;
  220. break;
  221. case 'r': /* adjust bitfields right */
  222. #ifndef NOBITFIELD
  223. options['r'] = 1;
  224. #else NOBITFIELD
  225. warning("bitfields are not implemented");
  226. #endif NOBITFIELD
  227. break;
  228. case 'S': /* initial struct alignment */
  229. if (size != (arith)0)
  230. struct_align = size;
  231. break;
  232. case 'U': /* initial union alignment */
  233. if (size != (arith)0)
  234. union_align = size;
  235. break;
  236. default:
  237. error("-V: bad type indicator %c\n", c);
  238. }
  239. }
  240. break;
  241. }
  242. }
  243. }
  244. int
  245. txt2int(tp)
  246. char **tp;
  247. {
  248. /* the integer pointed to by *tp is read, while increasing
  249. *tp; the resulting value is yielded.
  250. */
  251. register int val = 0, ch;
  252. while (ch = **tp, ch >= '0' && ch <= '9') {
  253. val = val * 10 + ch - '0';
  254. (*tp)++;
  255. }
  256. return val;
  257. }