init.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* $Header$ */
  2. /* PREPROCESSOR: INITIALIZATION ROUTINES */
  3. #include "nopp.h"
  4. #ifndef NOPP
  5. #include <system.h>
  6. #include "predefine.h" /* UF */
  7. #include "alloc.h"
  8. #include "class.h"
  9. #include "macro.h"
  10. #include "idf.h"
  11. #include "interface.h"
  12. PRIVATE struct mkey {
  13. char *mk_reserved;
  14. int mk_key;
  15. } mkey[] = {
  16. {"define", K_DEFINE},
  17. {"elif", K_ELIF},
  18. {"else", K_ELSE},
  19. {"endif", K_ENDIF},
  20. {"if", K_IF},
  21. {"ifdef", K_IFDEF},
  22. {"ifndef", K_IFNDEF},
  23. {"include", K_INCLUDE},
  24. {"line", K_LINE},
  25. {"undef", K_UNDEF},
  26. {0, K_UNKNOWN}
  27. };
  28. char *strcpy();
  29. EXPORT
  30. init_pp()
  31. {
  32. long clock;
  33. static char date[30];
  34. char *ctime();
  35. /* Initialise the control line keywords (if, include, define, etc)
  36. Although the lexical analyzer treats them as identifiers, the
  37. control line handler can recognize them as keywords by the
  38. id_resmac field of the identifier.
  39. */
  40. {
  41. register struct mkey *mk = &mkey[0];
  42. while (mk->mk_reserved) {
  43. struct idf *idf = str2idf(mk->mk_reserved);
  44. if (idf->id_resmac)
  45. fatal("maximum identifier length insufficient");
  46. idf->id_resmac = mk->mk_key;
  47. mk++;
  48. }
  49. }
  50. /* Initialize __DATE__, __FILE__ and __LINE__ macro
  51. definitions. The compile-time specified predefined macros
  52. are also predefined: if this file is compiled with
  53. -DPREDEFINE="vax,pdp", the macro definitions "vax" and
  54. "pdp" are predefined macros.
  55. */
  56. /* __DATE__ */
  57. clock = sys_time();
  58. strcpy(&date[1], ctime(&clock));
  59. date[26] = '\0'; /* zap nl */
  60. date[0] = date[25] = '"';
  61. macro_def(str2idf("__DATE__"), date, -1, 26, NOFLAG);
  62. /* __LINE__ */
  63. macro_def(str2idf("__LINE__"), "0", -1, 1, FUNC);
  64. /* __FILE__ */
  65. macro_def(str2idf("__FILE__"), "", -1, 1, FUNC);
  66. #ifdef PREDEFINE
  67. {
  68. /* PREDEFINE is a compile-time defined string
  69. containing a number of identifiers to be
  70. predefined at the host machine (for example
  71. -DPREDEFINE="vax,unix,pmds").
  72. Note that PREDEF causes the identifier not
  73. to be substituted.
  74. */
  75. register char *s = PREDEFINE;
  76. register char *id;
  77. char c;
  78. for (;;) {
  79. while (*s && class(*s++) != STIDF);
  80. if (*s) {
  81. /* gobble identifier */
  82. id = s - 1;
  83. while (in_idf(*s++));
  84. c = *--s;
  85. *s = '\0';
  86. macro_def(str2idf(id), "", -1, 0, PREDEF);
  87. *s = c;
  88. }
  89. else
  90. break;
  91. }
  92. }
  93. #endif PREDEFINE
  94. }
  95. #endif NOPP