# HG changeset patch # User Ryoma SHINYA # Date 1289384103 -32400 # Node ID 53c3ce58fc8a515df807cc12a93faf91b4de9e29 # Parent 623eccb93ca1dc85ce0f742c806b39ff28026e69 modify code gen, for no-warnings (gcc -Wall). diff -r 623eccb93ca1 -r 53c3ce58fc8a pyrect/translator/grep_translator.py --- a/pyrect/translator/grep_translator.py Mon Nov 08 10:56:55 2010 +0900 +++ b/pyrect/translator/grep_translator.py Wed Nov 10 19:15:03 2010 +0900 @@ -44,15 +44,17 @@ def emit_initialization(self): self.emit("#include ") self.emit("#define GREP grep") - self.emit("#define UCHAR unsigned char") - self.emit("#define UCHARP unsigned char *") self.emit("#include ") self.emit("#include ") self.emit("#include ") self.emit("#include ") self.emit("#include ") + self.emit("#include ") self.emit("#include ") + self.emit("typedef unsigned char UCHAR;") + self.emit("typedef unsigned char *UCHARP;") + self.emit('void reject(%s);' % self.interface) self.emit("void matcher(%s);" % self.interface, 2) self.emit('void accept(%s);' % self.interface) @@ -116,7 +118,7 @@ for i in range(l-1): skip[key[i]] = l-1-i - self.emit("UCHARP tmp1, *tmp2; buf += %d;" % (l-1), 2) + self.emit("UCHARP tmp1, tmp2; buf += %d;" % (l-1), 2) self.emiti("while (buf < end) {") self.emiti( "if (*buf == %d /* %s */) {" % (ord(key[-1]), Character.ascii(key[-1]))) @@ -167,7 +169,7 @@ for i in range(l): skip[key[i]] = l-i - self.emit("UCHARP tmp1, *tmp2, *end_ = end - %d;" % (l-1), 2) + self.emit("UCHARP tmp1, tmp2, end_ = end - %d;" % (l-1), 2) self.emiti("while (buf < end_) {") self.emiti( "if (*buf == %d /* %s */) {" % (ord(key[0]), Character.ascii(key[0]))) self.emit( "tmp1 = buf, tmp2 = (UCHARP)key;") @@ -191,12 +193,12 @@ self.emiti("void booster(%s) {" % self.interface) self.emiti( "do {") self.emit( "if (buf > end) return;") - self.emiti( "switch (*(buf+%d)) {" % (min_len-1)) + self.emiti( "switch (buf[%d]) {" % (min_len-1)) for c in chars: self.emit( "case %d: /* %s */" % (ord(c), Character.ascii(c))) self.emit( "goto ret;") self.emitd( "}") - self.emitd( "} while(buf += %d);" % (min_len-1)) + self.emitd( "} while(buf += %d);" % min_len) self.emit( "ret: return %s(%s);" % (self.state_name(self.cg.start) , self.args)) self.emitd("}", 2) diff -r 623eccb93ca1 -r 53c3ce58fc8a pyrect/translator/template/grep.c --- a/pyrect/translator/template/grep.c Mon Nov 08 10:56:55 2010 +0900 +++ b/pyrect/translator/template/grep.c Wed Nov 10 19:15:03 2010 +0900 @@ -11,7 +11,7 @@ void grep(char *regexp, int fd, char *name) { caddr_t file_mmap; - UCHARP buf, *end, *beg; + UCHARP buf, end, beg; off_t size; struct stat sb; @@ -34,7 +34,6 @@ matcher(beg, beg, end); munmap(file_mmap, size); - pthread_exit(NULL); return; } @@ -46,7 +45,7 @@ exit(0); } if (argc == 2) { - return; + return 0; } else { for (i = 2; i < argc; i++) { fd = open(argv[i], O_RDONLY, 0666);