]> mj.ucw.cz Git - eval.git/blob - judge/filter-cmt.c
Maint: Fixed a stupid typo
[eval.git] / judge / filter-cmt.c
1 /*
2  *      A filter removing C++-style comments
3  *
4  *      (c) 2007 Martin Mares <mj@ucw.cz>
5  */
6
7 #include "judge.h"
8
9 int main(void)
10 {
11   struct stream *i = sopen_fd("stdin", 0);
12   struct stream *o = sopen_fd("stdout", 1);
13
14   int c, d, nl = 1;
15   c = sgetc(i);
16   for (;;)
17     {
18       if (c == '/')
19         {
20           if ((d = sgetc(i)) == '/')
21             {
22               // skipping a comment...
23               while ((c = sgetc(i)) >= 0 && c != '\n')
24                 ;
25               if (nl)
26                 {
27                   c = sgetc(i);
28                   continue;
29                 }
30             }
31           else
32             {
33               sputc(o, c);
34               c = d;
35             }
36         }
37       if (c < 0)
38         break;
39       sputc(o, c);
40       nl = (c == '\n');
41       c = sgetc(i);
42     }
43
44   sclose(o);
45   sclose(i);
46   return 0;
47 }