options.c 2.7 KB

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