init.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. /* $Id$ */
  6. /* PREPROCESSOR: INITIALIZATION ROUTINES */
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "nopp.h"
  10. #ifndef NOPP
  11. #include <system.h>
  12. #include <alloc.h>
  13. #include <time.h>
  14. #include <flt_arith.h>
  15. #include <em_label.h>
  16. #include "class.h"
  17. #include "macro.h"
  18. #include "idf.h"
  19. #include "arith.h"
  20. #include "print.h"
  21. #include "expr.h"
  22. #include "error.h"
  23. #include "domacro.h"
  24. struct mkey {
  25. char *mk_reserved;
  26. int mk_key;
  27. } mkey[] = {
  28. {"define", K_DEFINE},
  29. {"elif", K_ELIF},
  30. {"else", K_ELSE},
  31. {"endif", K_ENDIF},
  32. {"error", K_ERROR},
  33. {"warning", K_WARNING},
  34. {"if", K_IF},
  35. {"ifdef", K_IFDEF},
  36. {"ifndef", K_IFNDEF},
  37. {"include", K_INCLUDE},
  38. {"line", K_LINE},
  39. {"pragma", K_PRAGMA},
  40. {"undef", K_UNDEF},
  41. {0, K_UNKNOWN}
  42. };
  43. void init_pp()
  44. {
  45. static char *months[12] = {
  46. "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  47. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  48. };
  49. long clock, sys_time();
  50. static char dbuf[30];
  51. static char tbuf[30];
  52. struct tm *tp;
  53. /* Initialise the control line keywords (if, include, define, etc)
  54. Although the lexical analyzer treats them as identifiers, the
  55. control line handler can recognize them as keywords by the
  56. id_resmac field of the identifier.
  57. */
  58. {
  59. struct mkey *mk = &mkey[0];
  60. while (mk->mk_reserved) {
  61. struct idf *idf = str2idf(mk->mk_reserved, 0);
  62. if (idf->id_resmac)
  63. fatal("maximum identifier length insufficient");
  64. idf->id_resmac = mk->mk_key;
  65. mk++;
  66. }
  67. }
  68. /* Initialize __LINE__, __FILE__, __DATE__, __TIME__,
  69. and __STDC__ macro definitions.
  70. */
  71. clock = sys_time();
  72. tp = localtime(&clock);
  73. /* __DATE__ */
  74. sprint(dbuf, "\"%s %02d %d\"", months[tp->tm_mon],
  75. tp->tm_mday, tp->tm_year+1900);
  76. if (tp->tm_mday < 10) dbuf[5] = ' '; /* hack */
  77. macro_def(str2idf("__DATE__", 0), dbuf, -1, strlen(dbuf), NOUNDEF);
  78. /* __TIME__ */
  79. sprint(tbuf, "\"%02d:%02d:%02d\"", tp->tm_hour, tp->tm_min, tp->tm_sec);
  80. macro_def(str2idf("__TIME__", 0), tbuf, -1, strlen(tbuf), NOUNDEF);
  81. /* __LINE__ */
  82. macro_def(str2idf("__LINE__", 0), "0", -1, 1, NOUNDEF | FUNC);
  83. /* __FILE__ */
  84. macro_def(str2idf("__FILE__", 0), "", -1, 1, NOUNDEF | FUNC);
  85. /* __STDC__ */
  86. macro_def(str2idf("__STDC__", 0), "1", -1, 1, NOUNDEF);
  87. /* defined(??) */
  88. macro_def(str2idf("defined", 0), "", 1, 1, NOUNDEF | FUNC);
  89. }
  90. #endif /* NOPP */