skip.c 1.7 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 "nopp.h"
  8. #include "arith.h"
  9. #include "LLlex.h"
  10. #include "class.h"
  11. #include "input.h"
  12. #include "domacro.h"
  13. #include "error.h"
  14. #ifndef NOPP
  15. extern int InputLevel;
  16. int skipspaces(int ch, int skipnl)
  17. {
  18. /* skipspaces() skips any white space and returns the first
  19. non-space character.
  20. */
  21. int nlseen = 0;
  22. for (;;) {
  23. while (class(ch) == STSKIP)
  24. ch = GetChar();
  25. if (skipnl && class(ch) == STNL) {
  26. ch = GetChar();
  27. LineNumber++;
  28. nlseen++;
  29. continue;
  30. }
  31. if (ch == TOKSEP && InputLevel) {
  32. ch = GetChar();
  33. continue;
  34. }
  35. /* \\\n are handled by trigraph */
  36. if (ch == '/') {
  37. ch = GetChar();
  38. if (ch == '*' && !InputLevel) {
  39. skipcomment();
  40. ch = GetChar();
  41. }
  42. else {
  43. UnGetChar();
  44. return '/';
  45. }
  46. }
  47. else if (nlseen && ch == '#') {
  48. domacro();
  49. ch = GetChar();
  50. } else
  51. return ch;
  52. }
  53. }
  54. #endif /* NOPP */
  55. int SkipToNewLine()
  56. {
  57. int ch;
  58. int garbage = 0;
  59. #ifndef NOPP
  60. int delim = 0;
  61. #endif
  62. while ((ch = GetChar()) != '\n') {
  63. #ifndef NOPP
  64. if (delim) {
  65. if (ch == '\\') {
  66. if (GetChar() == '\n') break;
  67. } else if (ch == delim) {
  68. delim = 0;
  69. }
  70. continue;
  71. }
  72. else if (ch == '\'' || ch == '\"') {
  73. delim = ch;
  74. garbage = 1;
  75. } else if (ch == '/') {
  76. if (GetChar() == '*'
  77. && !InputLevel
  78. ) {
  79. skipcomment();
  80. continue;
  81. }
  82. else UnGetChar();
  83. }
  84. else if (ch == TOKSEP && InputLevel) {
  85. continue;
  86. }
  87. #endif
  88. if (!is_wsp(ch))
  89. garbage = 1;
  90. }
  91. #ifndef NOPP
  92. if (delim) strict("unclosed opening %c", delim);
  93. #endif
  94. ++LineNumber;
  95. return garbage;
  96. }