Leaked source code of windows server 2003
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.

154 lines
3.8 KiB

  1. /*****************************************************************************
  2. *
  3. * define.c
  4. *
  5. * Builtins related to object definitions.
  6. *
  7. *****************************************************************************/
  8. #include "m4.h"
  9. /*****************************************************************************
  10. *
  11. * opDefineOrPushdef
  12. *
  13. * Common worker for opDefine and opPushdef.
  14. *
  15. * If we are not pushing, then we must pop off the previous value
  16. * in order to free its memory, before pushing the new definition.
  17. *
  18. * QUIRK! GNU m4 emits a warning if $# > 2. AT&T silently ignores
  19. * extra arguments. I side with AT&T on this one.
  20. *
  21. * QUIRK! GNU m4 emits `$0' if $# = 0. AT&T silently ignores
  22. * the entire macro call. I side with GNU on this one.
  23. *
  24. * WARNING! main.c::DefinePtsz assumes that we don't look at
  25. * argv[0] if the correct number of parameters are passed!
  26. *
  27. *****************************************************************************/
  28. void STDCALL
  29. opDefineOrPushdef(ARGV argv, BOOL fPush)
  30. {
  31. if (ctokArgv > 0) {
  32. /*
  33. * Ensure that we don't mess with argv[0].
  34. */
  35. D(SIG sigOld = argv[0].sig);
  36. D(argv[0].sig = 0);
  37. if (fIdentPtok(ptokArgv(1))) {
  38. PMAC pmac = pmacGetPtok(ptokArgv(1));
  39. if (!fPush) {
  40. if (pmac->pval) {
  41. PopdefPmac(pmac); /* Pop off previous value */
  42. }
  43. }
  44. PushdefPmacPtok(pmac, ptokArgv(2));
  45. #ifdef STRICT_M4
  46. if (ctokArgv > 2) {
  47. Warn("extra arguments ignored");
  48. }
  49. #endif
  50. } else {
  51. Die("invalid macro name");
  52. }
  53. D(argv[0].sig = sigOld);
  54. } else {
  55. PushQuotedPtok(ptokArgv(0));
  56. }
  57. }
  58. /*****************************************************************************
  59. *
  60. * opDefine
  61. *
  62. * Set the expansion of $1 to $2, destroying any previous value.
  63. *
  64. * opPushdef
  65. *
  66. * Same as opDefine, except pushes the previous value.
  67. *
  68. *****************************************************************************/
  69. DeclareOp(opDefine)
  70. {
  71. opDefineOrPushdef(argv, 0);
  72. }
  73. DeclareOp(opPushdef)
  74. {
  75. opDefineOrPushdef(argv, 1);
  76. }
  77. /*****************************************************************************
  78. *
  79. * opPopdef
  80. *
  81. * Restores the most recently pushed definition.
  82. *
  83. * If the macro name is invalid, fail silently.
  84. *
  85. *****************************************************************************/
  86. DeclareOpc(opcPopdef)
  87. {
  88. PMAC pmac = pmacFindPtok(ptok);
  89. if (pmac) {
  90. Assert(pmac->pval);
  91. if (pmac->pval->pvalPrev) {
  92. PopdefPmac(pmac);
  93. } else {
  94. FreePmac(pmac);
  95. }
  96. }
  97. }
  98. DeclareOp(opPopdef)
  99. {
  100. EachOpcArgvDw(opcPopdef, argv, 0);
  101. }
  102. /*****************************************************************************
  103. *
  104. * opUndefine
  105. *
  106. * Removes the definitions of all its arguments.
  107. *
  108. *****************************************************************************/
  109. DeclareOpc(opcUndefine)
  110. {
  111. PMAC pmac = pmacFindPtok(ptok);
  112. if (pmac) {
  113. FreePmac(pmac);
  114. }
  115. }
  116. DeclareOp(opUndefine)
  117. {
  118. EachOpcArgvDw(opcUndefine, argv, 0);
  119. }
  120. /*****************************************************************************
  121. *
  122. * opDefn
  123. *
  124. * Returns the quoted definition of its argument(s), concatenated
  125. * from left to right.
  126. *
  127. *****************************************************************************/
  128. DeclareOpc(opcDefn)
  129. {
  130. PMAC pmac = pmacFindPtok(ptok);
  131. if (pmac) {
  132. PushQuotedPtok(&pmac->pval->tok);
  133. }
  134. }
  135. DeclareOp(opDefn)
  136. {
  137. EachReverseOpcArgvDw(opcDefn, argv, 0);
  138. }