skip.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. /* PREPROCESSOR: INPUT SKIP FUNCTIONS */
  7. #include "nopp.h"
  8. #include "arith.h"
  9. #include "LLlex.h"
  10. #include "class.h"
  11. #include "input.h"
  12. #include "interface.h"
  13. #ifndef NOPP
  14. int
  15. skipspaces(ch, skipnl)
  16. register int ch;
  17. {
  18. /* skipspaces() skips any white space and returns the first
  19. non-space character.
  20. */
  21. register int nlseen = 0;
  22. for (;;) {
  23. while (class(ch) == STSKIP) {
  24. nlseen = 0;
  25. LoadChar(ch);
  26. }
  27. if (skipnl && class(ch) == STNL) {
  28. LoadChar(ch);
  29. LineNumber++;
  30. nlseen++;
  31. continue;
  32. }
  33. /* How about "\\\n"????????? */
  34. if (ch == '/') {
  35. LoadChar(ch);
  36. if (ch == '*') {
  37. skipcomment();
  38. LoadChar(ch);
  39. }
  40. else {
  41. PushBack();
  42. return '/';
  43. }
  44. }
  45. else if (nlseen && ch == '#') {
  46. domacro();
  47. LoadChar(ch);
  48. /* ch is the first character of a line. This means
  49. * that nlseen will still be true.
  50. */
  51. } else
  52. return ch;
  53. }
  54. }
  55. #endif /* NOPP */
  56. skipline()
  57. {
  58. /* skipline() skips all characters until a newline character
  59. is seen, not escaped by a '\\'.
  60. Any comment is skipped.
  61. */
  62. register int c;
  63. LoadChar(c);
  64. while (class(c) != STNL && c != EOI) {
  65. if (class(c) == STSTR || class(c) == STCHAR) {
  66. register int stopc = c;
  67. int escaped;
  68. do {
  69. escaped = 0;
  70. LoadChar(c);
  71. if (class(c) == STNL || c == EOI) {
  72. break;
  73. }
  74. if (c == '\\') {
  75. LoadChar(c);
  76. if (c == '\n') {
  77. ++LineNumber;
  78. }
  79. else escaped = 1;
  80. }
  81. } while (escaped || c != stopc);
  82. if (class(c) != STNL && c != EOI) {
  83. LoadChar(c);
  84. }
  85. continue;
  86. }
  87. if (c == '\\') {
  88. LoadChar(c);
  89. if (class(c) == STNL)
  90. ++LineNumber;
  91. }
  92. if (c == '/') {
  93. LoadChar(c);
  94. if (c == '*')
  95. skipcomment();
  96. else
  97. continue;
  98. }
  99. LoadChar(c);
  100. }
  101. ++LineNumber;
  102. if (c == EOI) { /* garbage input... */
  103. lexerror("unexpected EOF while skipping text");
  104. PushBack();
  105. }
  106. }