init.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "nopp.h"
  8. #ifndef NOPP
  9. #include <system.h>
  10. #include <alloc.h>
  11. #include "class.h"
  12. #include "macro.h"
  13. #include "idf.h"
  14. #include "interface.h"
  15. PRIVATE struct mkey {
  16. char *mk_reserved;
  17. int mk_key;
  18. } mkey[] = {
  19. {"define", K_DEFINE},
  20. {"elif", K_ELIF},
  21. {"else", K_ELSE},
  22. {"endif", K_ENDIF},
  23. {"if", K_IF},
  24. {"ifdef", K_IFDEF},
  25. {"ifndef", K_IFNDEF},
  26. {"include", K_INCLUDE},
  27. {"line", K_LINE},
  28. {"undef", K_UNDEF},
  29. {"pragma", K_PRAGMA},
  30. {0, K_UNKNOWN}
  31. };
  32. char *strcpy();
  33. EXPORT
  34. init_pp()
  35. {
  36. long clock, sys_time();
  37. static char date[30];
  38. char *ctime();
  39. /* Initialise the control line keywords (if, include, define, etc)
  40. Although the lexical analyzer treats them as identifiers, the
  41. control line handler can recognize them as keywords by the
  42. id_resmac field of the identifier.
  43. */
  44. {
  45. register struct mkey *mk = &mkey[0];
  46. while (mk->mk_reserved) {
  47. register struct idf *idf = str2idf(mk->mk_reserved);
  48. if (idf->id_resmac)
  49. fatal("maximum identifier length insufficient");
  50. idf->id_resmac = mk->mk_key;
  51. mk++;
  52. }
  53. }
  54. /* Initialize __DATE__, __FILE__ and __LINE__ macro
  55. definitions.
  56. */
  57. /* __DATE__ */
  58. clock = sys_time();
  59. strcpy(&date[1], ctime(&clock));
  60. date[26] = '\0'; /* zap nl */
  61. date[0] = date[25] = '"';
  62. macro_def(str2idf("__DATE__"), date, -1, 26, NOFLAG);
  63. /* __LINE__ */
  64. macro_def(str2idf("__LINE__"), "0", -1, 1, FUNC);
  65. /* __FILE__ */
  66. macro_def(str2idf("__FILE__"), "", -1, 1, FUNC);
  67. /* defined(??) */
  68. macro_def(str2idf("defined"), "", 1, 1, FUNC);
  69. }
  70. #endif /* NOPP */