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.

158 lines
3.4 KiB

  1. // Copyright (c) 1993-1999 Microsoft Corporation
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include "y2.h"
  5. void
  6. cpyact( SSIZE_T offset)
  7. {
  8. /* copy C action to the next ; or closing } */
  9. int brac, c, match, s;
  10. SSIZE_T j, tok;
  11. writeline(faction);
  12. brac = 0;
  13. loop:
  14. c = unix_getc(finput);
  15. swt:
  16. switch( c )
  17. {
  18. case ';':
  19. if( brac == 0 )
  20. {
  21. putc( c , faction );
  22. return;
  23. }
  24. goto lcopy;
  25. case '{':
  26. brac++;
  27. goto lcopy;
  28. case '$':
  29. s = 1;
  30. tok = -1;
  31. c = unix_getc(finput);
  32. if( c == '<' )
  33. {
  34. /* type description */
  35. yungetc( c, finput );
  36. if( gettok() != TYPENAME ) error( "bad syntax on $<ident> clause" );
  37. tok = numbval;
  38. c = unix_getc(finput);
  39. }
  40. if( c == '$' )
  41. {
  42. fprintf( faction, "yyval");
  43. if( ntypes )
  44. {
  45. /* put out the proper tag... */
  46. if( tok < 0 ) tok = fdtype( *prdptr[nprod] );
  47. fprintf( faction, ".%s", typeset[tok] );
  48. }
  49. goto loop;
  50. }
  51. if( c == '-' )
  52. {
  53. s = -s;
  54. c = unix_getc(finput);
  55. }
  56. if( isdigit(c) )
  57. {
  58. j=0;
  59. while( isdigit(c) )
  60. {
  61. j= j*10+c-'0';
  62. c = unix_getc(finput);
  63. }
  64. j = j*s - offset;
  65. if( j > 0 )
  66. {
  67. error( "Illegal use of $%d", j+offset );
  68. }
  69. fprintf( faction, "yypvt[-%d]", -j );
  70. if( ntypes )
  71. {
  72. /* put out the proper tag */
  73. if( j+offset <= 0 && tok < 0 ) error( "must specify type of $%d", j+offset );
  74. if( tok < 0 ) tok = fdtype( prdptr[nprod][j+offset] );
  75. fprintf( faction, ".%s", typeset[tok] );
  76. }
  77. goto swt;
  78. }
  79. putc( '$' , faction );
  80. if( s<0 ) putc('-', faction );
  81. goto swt;
  82. case '}':
  83. if( --brac ) goto lcopy;
  84. putc( c, faction );
  85. return;
  86. case '/': /* look for comments */
  87. putc( c , faction );
  88. c = unix_getc(finput);
  89. if( c != '*' ) goto swt;
  90. /* it really is a comment */
  91. putc( c , faction );
  92. c = unix_getc(finput);
  93. while( c != EOF )
  94. {
  95. while( c=='*' )
  96. {
  97. putc( c , faction );
  98. if( (c=unix_getc(finput)) == '/' ) goto lcopy;
  99. }
  100. putc( c , faction );
  101. if( c == '\n' )++lineno;
  102. c = unix_getc(finput);
  103. }
  104. error( "EOF inside comment" );
  105. case '\'': /* character constant */
  106. match = '\'';
  107. goto string;
  108. case '"': /* character string */
  109. match = '"';
  110. string:
  111. putc( c , faction );
  112. while( c=unix_getc(finput) )
  113. {
  114. if( c=='\\' )
  115. {
  116. putc( c , faction );
  117. c=unix_getc(finput);
  118. if( c == '\n' ) ++lineno;
  119. }
  120. else if( c==match ) goto lcopy;
  121. else if( c=='\n' ) error( "newline in string or char. const." );
  122. putc( c , faction );
  123. }
  124. error( "EOF in string or character constant" );
  125. case -1: /* EOF */
  126. error("action does not terminate" );
  127. case '\n':
  128. ++lineno;
  129. goto lcopy;
  130. }
  131. lcopy:
  132. putc( c , faction );
  133. goto loop;
  134. }