skip.c 1.9 KB

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