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.

110 lines
2.9 KiB

  1. /*****************************************************************************
  2. *
  3. * crackle.c
  4. *
  5. * User-defined macros.
  6. *
  7. *****************************************************************************/
  8. #include "m4.h"
  9. /*****************************************************************************
  10. *
  11. * opcAddDollar
  12. *
  13. * Add a $* or $@ to the current token buffer.
  14. *
  15. *****************************************************************************/
  16. DeclareOpc(opcAddDollar)
  17. {
  18. if (itok > 1) {
  19. AddExpTch(tchComma);
  20. }
  21. if (dw) {
  22. AddExpTch(tchLquo);
  23. }
  24. AddExpPtok(ptok);
  25. if (dw) {
  26. AddExpTch(tchRquo);
  27. }
  28. }
  29. /*****************************************************************************
  30. *
  31. * TraceArgv
  32. *
  33. * Trace a macro call. Collect the output in the Exp hold and smear it
  34. * to stderr when it's all ready.
  35. *
  36. *****************************************************************************/
  37. void STDCALL
  38. TraceArgv(ARGV argv)
  39. {
  40. TOK tok;
  41. OpenExpPtok(&tok);
  42. AddExpPtok(&tokTraceLpar);
  43. AddExpPtok(&tokRparColonSpace);
  44. AddExpPtok(ptokArgv(0));
  45. if (ctokArgv) {
  46. AddExpTch('(');
  47. EachOpcArgvDw(opcAddDollar, argv, 0); /* Dump in $* format */
  48. AddExpTch(')');
  49. }
  50. AddExpPtok(&tokEol);
  51. CsopExpDopPdivPtok(AddPdivPtok, g_pdivErr, &tok);
  52. FlushPdiv(g_pdivErr);
  53. }
  54. /*****************************************************************************
  55. *
  56. * PushSubstPtokArgv
  57. *
  58. * Produce a macro expansion and shove the result back into the stream.
  59. *
  60. *****************************************************************************/
  61. void STDCALL
  62. PushSubstPtokArgv(PTOK ptok, ARGV argv)
  63. {
  64. PTCH ptch;
  65. TOK tok;
  66. OpenExpPtok(&tok);
  67. for (ptch = ptchPtok(ptok); ptch < ptchMaxPtok(ptok); ptch++) {
  68. if (*ptch != '$' || ptch == ptchMaxPtok(ptok) - 1) {
  69. JustAddIt:
  70. AddExpTch(*ptch);
  71. } else {
  72. switch (ptch[1]) {
  73. case '0': case '1': case '2': case '3': case '4':
  74. case '5': case '6': case '7': case '8': case '9':
  75. if (ptch[1] - '0' <= ctokArgv) {
  76. AddExpPtok(ptokArgv(ptch[1] - '0'));
  77. }
  78. break;
  79. case '#': /* $# = argc */
  80. AddExpAt(ctokArgv); /* Note: Add, not Push! */
  81. break;
  82. case '*': /* $* = comma list */
  83. EachOpcArgvDw(opcAddDollar, argv, 0);
  84. break;
  85. case '@': /* $@ = quoted comma list */
  86. EachOpcArgvDw(opcAddDollar, argv, 1);
  87. break;
  88. default:
  89. goto JustAddIt; /* Just add the '$' */
  90. }
  91. ptch++;
  92. }
  93. }
  94. CsopExpDopPdivPtok((DIVOP)PushZPtok, 0, &tok);
  95. }