options.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  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(char **tp);
  24. void do_option(char *text)
  25. {
  26. switch(*text++) {
  27. case '-':
  28. options[*text] = 1;
  29. break;
  30. case 'u':
  31. if (! strcmp(text,"ndef")) {
  32. /* ignore -undef */
  33. break;
  34. }
  35. /* fall through */
  36. default:
  37. error("illegal option: %c", text[-1]);
  38. break;
  39. case 'C' : /* comment output */
  40. case 'P' : /* run preprocessor stand-alone, without #'s */
  41. options[*(text-1)] = 1;
  42. break;
  43. case 'A' : /* for Amake */
  44. case 'd' : /* dependency generation */
  45. do_dependencies = 1;
  46. if (*text) {
  47. dep_file = text;
  48. }
  49. else {
  50. do_preprocess = 0;
  51. }
  52. break;
  53. case 'm':
  54. case 'i':
  55. options[*(text-1)] = 1;
  56. break;
  57. case 'D' : /* -Dname : predefine name */
  58. {
  59. register char *cp = text, *name, *mactext;
  60. if (class(*cp) != STIDF) {
  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. mactext = "1";
  69. else
  70. if (*cp == '=') { /* -Dname=text */
  71. *cp++ = '\0'; /* end of name */
  72. mactext = cp;
  73. }
  74. else { /* -Dname?? */
  75. error("malformed option -D%s", text);
  76. break;
  77. }
  78. macro_def(str2idf(name, 0), mactext, -1, strlen(mactext), NOFLAG);
  79. break;
  80. }
  81. case 'I' : /* -Ipath : insert "path" into include list */
  82. if (*text) {
  83. register int i;
  84. register char *new = text;
  85. if (++inc_total > inc_max) {
  86. inctable = (char **)
  87. Realloc((void*) inctable,(inc_max+=10)*sizeof(char *));
  88. }
  89. for(i = inc_pos++; i < inc_total; i++) {
  90. char *tmp = inctable[i];
  91. inctable[i] = new;
  92. new = tmp;
  93. }
  94. }
  95. else inctable[inc_pos] = 0;
  96. break;
  97. case 'M': /* maximum identifier length */
  98. idfsize = txt2int(&text);
  99. if (*text)
  100. error("malformed -M option");
  101. if (idfsize > IDFSIZE) {
  102. warning("maximum identifier length is %d", IDFSIZE);
  103. idfsize = IDFSIZE;
  104. }
  105. if (idfsize < 8) {
  106. warning("minimum identifier length is 8");
  107. idfsize = 8;
  108. }
  109. break;
  110. case 'U' : /* -Uname : undefine predefined */
  111. if (*text) {
  112. register struct idf *idef = findidf(text);
  113. if (idef && idef->id_macro) {
  114. free_macro(idef->id_macro);
  115. idef->id_macro = (struct macro *) 0;
  116. }
  117. }
  118. break;
  119. }
  120. }
  121. int txt2int(char **tp)
  122. {
  123. /* the integer pointed to by *tp is read, while increasing
  124. *tp; the resulting value is yielded.
  125. */
  126. register int val = 0;
  127. register int ch;
  128. while (ch = **tp, ch >= '0' && ch <= '9') {
  129. val = val * 10 + ch - '0';
  130. (*tp)++;
  131. }
  132. return val;
  133. }