skip.c 1.6 KB

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