init.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* PREPROCESSOR: INITIALIZATION ROUTINES */
  7. #include <string.h>
  8. #include <system.h>
  9. #include <alloc.h>
  10. #include "LLlex.h"
  11. #include "class.h"
  12. #include "macro.h"
  13. #include "idf.h"
  14. #include "interface.h"
  15. static 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. void init_pp()
  33. {
  34. long clock, sys_time();
  35. static char date[30];
  36. char *ctime();
  37. /* Initialise the control line keywords (if, include, define, etc)
  38. Although the lexical analyzer treats them as identifiers, the
  39. control line handler can recognize them as keywords by the
  40. id_resmac field of the identifier.
  41. */
  42. {
  43. register struct mkey *mk = &mkey[0];
  44. while (mk->mk_reserved) {
  45. struct idf *idf = str2idf(mk->mk_reserved, 0);
  46. if (idf->id_resmac)
  47. fatal("maximum identifier length insufficient");
  48. idf->id_resmac = mk->mk_key;
  49. mk++;
  50. }
  51. }
  52. /* Initialize __DATE__, __FILE__ and __LINE__ macro
  53. definitions.
  54. */
  55. /* __DATE__ */
  56. clock = sys_time();
  57. strcpy(&date[1], ctime(&clock));
  58. date[26] = '\0'; /* zap nl */
  59. date[0] = date[25] = '"';
  60. macro_def(str2idf("__DATE__", 0), date, -1, 26, NOFLAG);
  61. /* __LINE__ */
  62. macro_def(str2idf("__LINE__", 0), "0", -1, 1, FUNC);
  63. /* __FILE__ */
  64. macro_def(str2idf("__FILE__", 0), "", -1, 1, FUNC);
  65. /* defined(??) */
  66. macro_def(str2idf("defined", 0), "", 1, 1, FUNC);
  67. }