init.c 2.3 KB

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