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