]> mj.ucw.cz Git - eval.git/commitdiff
Added a filter for weeding out comments.
authorMartin Mares <mj@ucw.cz>
Sat, 17 Nov 2007 22:07:53 +0000 (23:07 +0100)
committerMartin Mares <mj@ucw.cz>
Sat, 17 Nov 2007 22:07:53 +0000 (23:07 +0100)
judge/Makefile
judge/filter-cmt.c [new file with mode: 0644]

index b140d68866c10ce84590324fb42e37e4ab26d917..e231fc268c16c8f31c5e87a79a52b307284dda24 100644 (file)
@@ -2,16 +2,17 @@ CC=gcc-4.1.1
 CFLAGS=-O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -Winline $(DEBUG) -std=gnu99
 CFLAGS+=-Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers
 
-all: test-io test-tok judge-tok
+all: test-io test-tok judge-tok filter-cmt
 
 JLIB=utils.o io.o token.o
 
 test-io: test-io.o $(JLIB)
 test-tok: test-tok.o $(JLIB)
 judge-tok: judge-tok.o $(JLIB)
+filter-cmt: filter-cmt.o $(JLIB)
 
 clean::
        rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core`
-       rm -f test-io test-tok judge-tok
+       rm -f test-io test-tok judge-tok filter-cmt
 
 .PHONY: all clean distclean
diff --git a/judge/filter-cmt.c b/judge/filter-cmt.c
new file mode 100644 (file)
index 0000000..12978ad
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ *     A filter removing C++-style comments
+ *
+ *     (c) 2007 Martin Mares <mj@ucw.cz>
+ */
+
+#include "judge.h"
+
+int main(void)
+{
+  struct stream *i = sopen_fd("stdin", 0);
+  struct stream *o = sopen_fd("stdout", 1);
+
+  int c, d, nl = 1;
+  c = sgetc(i);
+  for (;;)
+    {
+      if (c == '/')
+       {
+         if ((d = sgetc(i)) == '/')
+           {
+             // skipping a comment...
+             while ((c = sgetc(i)) >= 0 && c != '\n')
+               ;
+             if (nl)
+               continue;
+           }
+         else
+           {
+             sputc(o, c);
+             c = d;
+           }
+       }
+      if (c < 0)
+       break;
+      sputc(o, c);
+      nl = (c == '\n');
+      c = sgetc(i);
+    }
+
+  sclose(o);
+  sclose(i);
+  return 0;
+}