Re: [PATCH] eruby on tiger
Jb Evain <[email protected]> Tue, 19 Jul 2005 19:12:14 +0200
| Newsgroups | gmane.comp.apache.mod-ruby |
|---|---|
| Message-ID | <[email protected]> |
Bonjour !
> if (isspace ( *(unsigned char *)s ) ) { ... }
Yeah, or
if (isspace ((unsigned char) *s)) ...
or ... :)
Attached is a patch that respects the isspace desire to handle
unsigned char, and other functions to receive char * and add a little
refactoring. Could it be reviewed ?
Thanks.
Jb
eruby.patch
(application/octet-stream, 3.4 KB)
Index: ChangeLog =================================================================== --- ChangeLog (revision 67) +++ ChangeLog (working copy) @@ -1,3 +1,7 @@ +Tue Jul 19 19:07:12 2005 Jb Evain <[email protected]> + + * eruby_lib.c: clean warnings, little refactoring + Tue Mar 9 14:16:06 2004 Shugo Maeda <[email protected]> * Makefile.in: use $(RUBY) to execute bin2c. Index: eruby_lib.c =================================================================== --- eruby_lib.c (revision 67) +++ eruby_lib.c (working copy) @@ -114,10 +114,19 @@ return 0; } +static int is_option (const char *s, const char *opt) +{ + int len = strlen (opt); + if (strncmp (s, opt, len) == 0 + || (s[len] == '\0' || isspace ((unsigned char) s[len]))) + return 0; + return len; +} + int eruby_parse_options(int argc, char **argv, int *optind) { - int i, result = 0; - unsigned char *s; + int i, next, result = 0; + char *s; for (i = 1; i < argc; i++) { if (argv[i][0] != '-' || argv[i][1] == '\0') { @@ -125,7 +134,7 @@ } s = argv[i]; again: - while (isspace(*s)) + while (isspace((unsigned char) *s)) s++; if (*s == '-') s++; switch (*s) { @@ -146,7 +155,7 @@ goto again; case 'C': s++; - if (isspace(*s)) s++; + if (isspace((unsigned char) *s)) s++; if (*s == '\0') { i++; if (i == argc) { @@ -157,8 +166,8 @@ break; } else { - unsigned char *p = s; - while (*p && !isspace(*p)) p++; + char *p = s; + while (*p && !isspace((unsigned char) *p)) p++; eruby_charset = rb_str_new(s, p - s); s = p; goto again; @@ -186,37 +195,31 @@ result = 1; break; case '-': s++; - if (strncmp(s , "debug", 5) == 0 - && (s[5] == '\0' || isspace(s[5]))) { + if ((next = is_option (s , "debug"))) { ruby_debug = Qtrue; - s += 5; + s += next; goto again; } - else if (strncmp(s, "noheader", 8) == 0 - && (s[8] == '\0' || isspace(s[8]))) { + else if ((next = is_option (s, "noheader"))) { eruby_noheader = 1; - s += 8; + s += next; goto again; } - else if (strncmp(s, "sync", 4) == 0 - && (s[4] == '\0' || isspace(s[4]))) { + else if ((next = is_option (s, "sync"))) { eruby_sync = 1; - s += 4; + s += next; goto again; } - else if (strncmp(s, "version", 7) == 0 - && (s[7] == '\0' || isspace(s[7]))) { + else if (is_option (s, "version")) { show_version(); result = 1; break; } - else if (strncmp(s, "verbose", 7) == 0 - && (s[7] == '\0' || isspace(s[7]))) { + else if ((next = is_option (s, "verbose"))) { ruby_verbose = Qtrue; - s += 7; + s += next; goto again; } - else if (strncmp(s, "help", 4) == 0 - && (s[4] == '\0' || isspace(s[4]))) { + else if (is_option (s, "help")) { usage(argv[0]); result = 1; break; } @@ -481,7 +484,7 @@ if (c == '#') { c = nextc(compiler); if (c == '!') { - unsigned char *p; + char *p; char *argv[2]; char *line = RSTRING(compiler->lex_lastline)->ptr; @@ -491,9 +494,9 @@ } argv[0] = "eruby"; p = line; - while (isspace(*p)) p++; - while (*p && !isspace(*p)) p++; - while (isspace(*p)) p++; + while (isspace((unsigned char) *p)) p++; + while (*p && !isspace((unsigned char) *p)) p++; + while (isspace((unsigned char) *p)) p++; argv[1] = p; if (eruby_parse_options(2, argv, NULL) != 0) { rb_raise(eERubyCompileError, "invalid #! line");