options.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 "LLlex.h"
  11. #include "idfsize.h"
  12. #include "class.h"
  13. #include "macro.h"
  14. #include "idf.h"
  15. char options[128]; /* one for every char */
  16. int inc_pos = 1; /* place where next -I goes */
  17. int inc_max;
  18. int inc_total;
  19. int do_preprocess = 1;
  20. int do_dependencies = 0;
  21. char **inctable;
  22. char *dep_file = 0;
  23. extern int idfsize;
  24. int txt2int(char **tp);
  25. void do_option(char *text)
  26. {
  27. switch(*text++) {
  28. case '-':
  29. options[*(unsigned char *)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 'C' : /* comment output */
  41. case 'P' : /* run preprocessor stand-alone, without #'s */
  42. options[*(unsigned char *)(text-1)] = 1;
  43. break;
  44. case 'A' : /* for Amake */
  45. case 'd' : /* dependency generation */
  46. do_dependencies = 1;
  47. if (*text) {
  48. dep_file = text;
  49. }
  50. else {
  51. do_preprocess = 0;
  52. }
  53. break;
  54. case 'm':
  55. case 'i':
  56. options[*(unsigned char *)(text-1)] = 1;
  57. break;
  58. case 'D' : /* -Dname : predefine name */
  59. {
  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. if (!*cp) /* -Dname */
  69. mactext = "1";
  70. else
  71. if (*cp == '=') { /* -Dname=text */
  72. *cp++ = '\0'; /* end of name */
  73. mactext = cp;
  74. }
  75. else { /* -Dname?? */
  76. error("malformed option -D%s", text);
  77. break;
  78. }
  79. macro_def(str2idf(name, 0), mactext, -1, strlen(mactext), NOFLAG);
  80. break;
  81. }
  82. case 'I' : /* -Ipath : insert "path" into include list */
  83. if (*text) {
  84. register int i;
  85. register char *new = text;
  86. if (++inc_total > inc_max) {
  87. inctable = (char **)
  88. Realloc((void*) inctable,(inc_max+=10)*sizeof(char *));
  89. }
  90. for(i = inc_pos++; i < inc_total; i++) {
  91. char *tmp = inctable[i];
  92. inctable[i] = new;
  93. new = tmp;
  94. }
  95. }
  96. else inctable[inc_pos] = 0;
  97. break;
  98. case 'M': /* maximum identifier length */
  99. idfsize = txt2int(&text);
  100. if (*text)
  101. error("malformed -M option");
  102. if (idfsize > IDFSIZE) {
  103. warning("maximum identifier length is %d", IDFSIZE);
  104. idfsize = IDFSIZE;
  105. }
  106. if (idfsize < 8) {
  107. warning("minimum identifier length is 8");
  108. idfsize = 8;
  109. }
  110. break;
  111. case 'U' : /* -Uname : undefine predefined */
  112. if (*text) {
  113. register struct idf *idef = findidf(text);
  114. if (idef && idef->id_macro) {
  115. free_macro(idef->id_macro);
  116. idef->id_macro = (struct macro *) 0;
  117. }
  118. }
  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. register int val = 0;
  128. register int ch;
  129. while (ch = **tp, ch >= '0' && ch <= '9') {
  130. val = val * 10 + ch - '0';
  131. (*tp)++;
  132. }
  133. return val;
  134. }