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