skip.c 1.6 KB

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