skip.c 1.9 KB

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