Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
3.1 KiB

4 years ago
  1. /*** Macro.C - contains routines that have to do with macros *****************
  2. *
  3. * Copyright (c) 1988-1991, Microsoft Corporation. All Rights Reserved.
  4. *
  5. * Purpose:
  6. * Contains routines that have to do with macros
  7. *
  8. * Revision History:
  9. * 16-May-1991 SB Created from routines that existed elsewhere
  10. *
  11. * Notes:
  12. *
  13. * Notes:
  14. * Functions currently in this module ...
  15. *
  16. * findMacro - public
  17. * enterMacro - public
  18. * copyMacroTable - public (exec.c)
  19. * freeMacroTable - public (get from nmake.c)
  20. *
  21. *****************************************************************************/
  22. /* Standard INCLUDEs */
  23. /* Project INCLUDEs */
  24. #include "nmake.h"
  25. #include "nmmsg.h"
  26. #include "proto.h"
  27. #include "globals.h"
  28. #include "grammar.h"
  29. /* Constant DEFINEs */
  30. #define PUBLIC
  31. /* Extern PROTOTYPEs */
  32. extern void NEAR freeList(STRINGLIST*);
  33. extern STRINGLIST * NEAR makeList(STRINGLIST *);
  34. /* Local PROTOTYPEs */
  35. /* Extern VARIABLEs */
  36. /* Local VARIABLEs */
  37. static STRINGLIST **lastMacroChain = NULL;
  38. /* FUNCTIONs */
  39. /*
  40. * findMacro - look up a string in a hash table
  41. *
  42. * Look up a macro name in a hash table and return the entry
  43. * or NULL.
  44. * If a macro and undefined, return NULL.
  45. */
  46. MACRODEF * NEAR findMacro(char *str)
  47. {
  48. unsigned n;
  49. char *string = str;
  50. STRINGLIST *found;
  51. if (*string) {
  52. for (n = 0; *string; n += *string++); //Hash
  53. n %= MAXMACRO;
  54. #if defined(STATISTICS)
  55. CntfindMacro++;
  56. #endif
  57. lastMacroChain = (STRINGLIST **)&macroTable[n];
  58. for (found = *lastMacroChain; found; found = found->next) {
  59. #if defined(STATISTICS)
  60. CntmacroChains++;
  61. #endif
  62. if (!_ftcscmp(found->text, str))
  63. return((((MACRODEF *)found)->flags & M_UNDEFINED) ? NULL : (MACRODEF *)found);
  64. }
  65. }
  66. else {
  67. // set lastMacroChain, even for an empty name
  68. lastMacroChain = (STRINGLIST **)&macroTable[0];
  69. }
  70. return(NULL);
  71. }
  72. //
  73. // insertMacro
  74. //
  75. // Macro insertion requires that we JUST did a findMacro, which action set lastMacroChain.
  76. //
  77. void NEAR insertMacro(STRINGLIST * p)
  78. {
  79. #ifdef STATISTICS
  80. CntinsertMacro++;
  81. #endif
  82. assert(lastMacroChain != NULL);
  83. prependItem(lastMacroChain, p);
  84. lastMacroChain = NULL;
  85. }
  86. #if defined(SELF_RECURSE)
  87. PUBLIC void NEAR
  88. copyMacroTable(
  89. MACRODEF *old[],
  90. MACRODEF *new[]
  91. ) {
  92. MACRODEF *p, **q;
  93. unsigned n;
  94. for (n = 0; n < MAXMACRO; n++) {
  95. for (p = old[n], q = &new[n]; p; p = p->next, q = &(*q)->next) {
  96. *q = makeNewMacro();
  97. (*q)->name = makeString(p->name);
  98. (*q)->values = makeList(p->values);
  99. (*q)->flags = p->flags;
  100. }
  101. }
  102. }
  103. PUBLIC void NEAR
  104. freeMacroTable(
  105. MACRODEF *table[]
  106. ) {
  107. unsigned num;
  108. MACRODEF *tmpMacroT;
  109. MACRODEF *macroT;
  110. for (num=0;num < MAXMACRO;num++) {
  111. macroT = table[num];
  112. while (tmpMacroT = macroT) {
  113. macroT = macroT->next;
  114. FREE(tmpMacroT->name);
  115. freeList(tmpMacroT->values);
  116. FREE(tmpMacroT);
  117. }
  118. }
  119. initMacroTable(table);
  120. }
  121. #endif
  122. //
  123. // 16/May/92 Bryant Init the macro table to a known state before
  124. // continuing.
  125. PUBLIC void NEAR initMacroTable(MACRODEF *table[])
  126. {
  127. unsigned num;
  128. for (num=0;num < MAXMACRO;num++)
  129. {
  130. table[num] = NULL;
  131. }
  132. }