options.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /* USER-OPTION HANDLING */
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "alloc.h"
  10. #include "idfsize.h"
  11. #include "class.h"
  12. #include "macro.h"
  13. #include "idf.h"
  14. #include "arith.h"
  15. #include "LLlex.h"
  16. char options[128]; /* one for every char */
  17. int inc_pos = 1; /* place where next -I goes */
  18. int inc_max;
  19. int inc_total;
  20. int do_preprocess = 1;
  21. int do_dependencies = 0;
  22. char **inctable;
  23. char *dep_file = 0;
  24. extern int idfsize;
  25. int txt2int(char **tp);
  26. void do_option(char *text)
  27. {
  28. switch(*text++) {
  29. case '-':
  30. options[*(unsigned char *)text] = 1;
  31. break;
  32. case 'u':
  33. if (! strcmp(text, "ndef")) {
  34. /* ignore -undef */
  35. break;
  36. }
  37. /* fall through */
  38. default:
  39. error("illegal option: %c", text[-1]);
  40. break;
  41. case 'A' : /* for Amake */
  42. case 'd' : /* dependency generation */
  43. do_dependencies = 1;
  44. if (*text) {
  45. dep_file = text;
  46. }
  47. else {
  48. do_preprocess = 0;
  49. }
  50. break;
  51. case 'i':
  52. case 'm':
  53. case 'o': /* ignore garbage after #else or #endif */
  54. case 'C' : /* comment output */
  55. options[*(unsigned char *)(text-1)] = 1;
  56. break;
  57. case 'D' : /* -Dname : predefine name */
  58. {
  59. char *cp = text, *name, *mactext;
  60. unsigned maclen;
  61. if (class(*(unsigned char *)cp) != STIDF && class(*(unsigned char *)cp) != STELL) {
  62. error("identifier missing in -D%s", text);
  63. break;
  64. }
  65. name = cp;
  66. while (*cp && in_idf(*(unsigned char *)cp))
  67. ++cp;
  68. if (!*cp) { /* -Dname */
  69. maclen = 1;
  70. mactext = Salloc("1", 2);
  71. } else
  72. if (*cp == '=') { /* -Dname=text */
  73. *cp++ = '\0'; /* end of name */
  74. maclen = strlen(cp);
  75. mactext = Salloc(cp, maclen + 1);
  76. }
  77. else { /* -Dname?? */
  78. error("malformed option -D%s", text);
  79. break;
  80. }
  81. macro_def(str2idf(name, 0), mactext, -1, (int)maclen, NOFLAG);
  82. break;
  83. }
  84. case 'I' : /* -Ipath : insert "path" into include list */
  85. if (*text) {
  86. int i;
  87. char *new = text;
  88. if (++inc_total > inc_max) {
  89. inctable = (char **)
  90. Realloc((char *)inctable,
  91. (unsigned)((inc_max+=10)*sizeof(char *)));
  92. }
  93. for(i = inc_pos++; i < inc_total; i++) {
  94. char *tmp = inctable[i];
  95. inctable[i] = new;
  96. new = tmp;
  97. }
  98. }
  99. else inctable[inc_pos] = 0;
  100. break;
  101. case 'M': /* maximum identifier length */
  102. idfsize = txt2int(&text);
  103. if (*text)
  104. error("malformed -M option");
  105. if (idfsize > IDFSIZE) {
  106. warning("maximum identifier length is %d", IDFSIZE);
  107. idfsize = IDFSIZE;
  108. }
  109. if (idfsize < 8) {
  110. warning("minimum identifier length is 8");
  111. idfsize = 8;
  112. }
  113. break;
  114. case 'P' : /* run preprocessor stand-alone, without #'s */
  115. options['P'] = 1;
  116. break;
  117. case 'U' : /* -Uname : undefine predefined */
  118. if (*text) do_undef(text);
  119. break;
  120. }
  121. }
  122. int txt2int(char **tp)
  123. {
  124. /* the integer pointed to by *tp is read, while increasing
  125. *tp; the resulting value is yielded.
  126. */
  127. int val = 0;
  128. int ch;
  129. while (ch = **tp, ch >= '0' && ch <= '9') {
  130. val = val * 10 + ch - '0';
  131. (*tp)++;
  132. }
  133. return val;
  134. }