Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
* eruby_lib.c: clean warnings, little refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
shugo committed Jul 21, 2005
1 parent 115154f commit a5113b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
53 changes: 28 additions & 25 deletions eruby_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,27 @@ static int set_mode(char *mode)
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(s[len])))
return len;
return 0;
}

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') {
break;
}
s = argv[i];
again:
while (isspace(*s))
while (isspace(*(unsigned char *) s))
s++;
if (*s == '-') s++;
switch (*s) {
Expand Down Expand Up @@ -157,8 +166,8 @@ int eruby_parse_options(int argc, char **argv, int *optind)
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;
Expand Down Expand Up @@ -186,37 +195,31 @@ int eruby_parse_options(int argc, char **argv, int *optind)
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;
}
Expand Down Expand Up @@ -481,7 +484,7 @@ static VALUE eruby_compile(eruby_compiler_t *compiler)
if (c == '#') {
c = nextc(compiler);
if (c == '!') {
unsigned char *p;
char *p;
char *argv[2];
char *line = RSTRING(compiler->lex_lastline)->ptr;

Expand All @@ -491,9 +494,9 @@ static VALUE eruby_compile(eruby_compiler_t *compiler)
}
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");
Expand Down

0 comments on commit a5113b4

Please sign in to comment.