前田です。

At Mon, 6 Dec 1999 09:49:27 +0900,
Tadashige Morii <m_tada / sx.miracle.ne.jp> wrote:
>  ちょっと eRuby を使ってみようかと思って下記 Web Page を参考にしてま
> すが、パッチをあてて make を取ると以下のようになります。
(snip)
> > eruby_main.c:604: `eruby_no_header' undeclared (first use this function)

手元にあるのと内容が違うので、パッチがおかしかったようです。
再添付しますので、ためしていただけます?

-- 
前田 修吾

Index: eruby.c =================================================================== RCS file: /home/cvs/eruby/eruby.c,v retrieving revision 1.2 diff -u -r1.2 eruby.c --- eruby.c 1999/08/10 04:44:39 1.2 +++ eruby.c 1999/12/06 04:36:44 @@ -12,21 +12,22 @@ #include "eruby.h" -char eruby_begin_delimiter1 = '<'; -char eruby_begin_delimiter2 = '%'; -char eruby_end_delimiter1 = '%'; -char eruby_end_delimiter2 = '>'; -char eruby_expr_char = '='; -char eruby_comment_char = '#'; +static char eruby_begin_delimiter[] = "<%"; +static char eruby_end_delimiter[] = "%>"; +static char eruby_expr_char = '='; +static char eruby_comment_char = '#'; +static char eruby_line_beg_char = '%'; -enum embedded_string_type { +enum embedded_program_type { EMBEDDED_STMT, EMBEDDED_EXPR, EMBEDDED_COMMENT, }; -static int compile_embedded_string(FILE *in, FILE *out, - enum embedded_string_type type) +#define EOP (-2) + +static int parse_embedded_program(FILE *in, FILE *out, + enum embedded_program_type type) { int c, prevc = EOF; @@ -35,11 +36,11 @@ for (;;) { c = getc(in); again: - if (c == eruby_end_delimiter1) { - if (prevc == eruby_end_delimiter1) + if (c == eruby_end_delimiter[0]) { + if (prevc == eruby_end_delimiter[0]) continue; c = getc(in); - if (c == eruby_end_delimiter2) { + if (c == eruby_end_delimiter[1]) { if (type == EMBEDDED_EXPR) fputs(")); ", out); else if (type == EMBEDDED_STMT && prevc != '\n') @@ -54,8 +55,8 @@ } else { if (type != EMBEDDED_COMMENT) - putc(eruby_end_delimiter1, out); - prevc = eruby_end_delimiter1; + putc(eruby_end_delimiter[0], out); + prevc = eruby_end_delimiter[0]; goto again; } } @@ -81,6 +82,31 @@ return MISSING_END_DELIMITER; } +static int parse_embedded_line(FILE *in, FILE *out) +{ + int c; + + for (;;) { + c = getc(in); + again: + switch (c) { + case EOF: + if (ferror(in)) + return SYSTEM_ERROR; + else + return MISSING_END_DELIMITER; + case '\n': + putc(c, out); + return 0; + break; + default: + putc(c, out); + break; + } + } + return MISSING_END_DELIMITER; +} + int eruby_compile(FILE *in, FILE *out) { int c, prevc = EOF; @@ -103,66 +129,87 @@ for (;;) { c = getc(in); again: - if (c == eruby_begin_delimiter1) { + if (c == eruby_begin_delimiter[0]) { c = getc(in); - if (c == eruby_begin_delimiter2) { - if (prevc != EOF) { + if (c == eruby_begin_delimiter[1]) { + if (prevc >= 0) { fputs("\"; ", out); } c = getc(in); - if (c == eruby_begin_delimiter2) { - if (prevc == EOF) fputs("print \"", out); - putc(eruby_begin_delimiter1, out); - putc(eruby_begin_delimiter2, out); - prevc = eruby_begin_delimiter2; + if (c == EOF) { + return MISSING_END_DELIMITER; + } + else if (c == eruby_begin_delimiter[1]) { /* <%% => <% */ + if (prevc < 0) fputs("print \"", out); + putc(eruby_begin_delimiter[0], out); + putc(eruby_begin_delimiter[1], out); + prevc = eruby_begin_delimiter[1]; continue; } else if (c == eruby_comment_char) { - err = compile_embedded_string(in, out, EMBEDDED_COMMENT); + err = parse_embedded_program(in, out, EMBEDDED_COMMENT); if (err) return err; } else if (c == eruby_expr_char) { - err = compile_embedded_string(in, out, EMBEDDED_EXPR); + err = parse_embedded_program(in, out, EMBEDDED_EXPR); if (err) return err; } else { if (ungetc(c, in) == EOF) return SYSTEM_ERROR; - err = compile_embedded_string(in, out, EMBEDDED_STMT); + err = parse_embedded_program(in, out, EMBEDDED_STMT); if (err) return err; } - prevc = EOF; + prevc = EOP; } else { - if (prevc == EOF) fputs("print \"", out); - putc(eruby_begin_delimiter1, out); - prevc = eruby_begin_delimiter1; + if (prevc < 0) fputs("print \"", out); + putc(eruby_begin_delimiter[0], out); + prevc = eruby_begin_delimiter[0]; goto again; } } + else if (c == eruby_line_beg_char && prevc == EOF) { + c = getc(in); + if (c == EOF) { + return MISSING_END_DELIMITER; + } + else if (c == eruby_line_beg_char) { /* %% => % */ + if (prevc < 0) fputs("print \"", out); + fputc(c, out); + prevc = c; + } + else { + if (ungetc(c, in) == EOF) + return SYSTEM_ERROR; + err = parse_embedded_line(in, out); + if (err) return err; + prevc = EOF; + } + } else { switch (c) { case EOF: goto end; case '\n': - if (prevc == EOF) fputs("print \"", out); + if (prevc < 0) fputs("print \"", out); fputs("\\n\"\n", out); prevc = EOF; break; case '\t': - if (prevc == EOF) fputs("print \"", out); + if (prevc < 0) fputs("print \"", out); fputs("\\t", out); prevc = c; break; case '\\': case '"': case '#': - if (prevc == EOF) fputs("print \"", out); + if (prevc < 0) fputs("print \"", out); putc('\\', out); putc(c, out); prevc = c; break; default: - if (prevc == EOF) fputs("print \"", out); + if (prevc < 0) fputs("print \"", out); putc(c, out); prevc = c; break; Index: eruby.h =================================================================== RCS file: /home/cvs/eruby/eruby.h,v retrieving revision 1.5 diff -u -r1.5 eruby.h --- eruby.h 1999/08/10 04:44:39 1.5 +++ eruby.h 1999/12/06 04:36:44 @@ -14,13 +14,6 @@ SYSTEM_ERROR }; -extern char eruby_begin_delimiter1; -extern char eruby_begin_delimiter2; -extern char eruby_end_delimiter1; -extern char eruby_end_delimiter2; -extern char eruby_expr_char; -extern char eruby_comment_char; - int eruby_compile(FILE *in, FILE *out); VALUE eruby_compile_file(char *filename); VALUE eruby_load(char *filename, int wrap, int *state); Index: eruby_main.c =================================================================== RCS file: /home/cvs/eruby/eruby_main.c,v retrieving revision 1.4 diff -u -r1.4 eruby_main.c --- eruby_main.c 1999/08/10 04:44:39 1.4 +++ eruby_main.c 1999/12/06 04:36:44 @@ -40,7 +40,7 @@ static char *eruby_filename = NULL; static int eruby_mode = MODE_UNKNOWN; -static int eruby_no_header = 0; +static int eruby_noheader = 0; static char *get_charset() { @@ -439,13 +439,31 @@ } } -static VALUE str_write(VALUE self, VALUE str) +static VALUE defout_write(VALUE self, VALUE str) { str = rb_obj_as_string(str); rb_str_cat(self, RSTRING(str)->ptr, RSTRING(str)->len); return Qnil; } +static VALUE defout_cancel(VALUE self) +{ + if (RSTRING(self)->len == 0) return; + RSTRING(self)->len = 0; + RSTRING(self)->ptr[0] = '\0'; + return Qnil; +} + +static VALUE noheader_getter() +{ + return eruby_noheader ? Qtrue : Qfalse; +} + +static void noheader_setter(VALUE val) +{ + eruby_noheader = RTEST(val); +} + static int guess_mode() { if (getenv("GATEWAY_INTERFACE") == NULL) { @@ -485,8 +503,6 @@ fprintf(stderr, "\ usage: %s [switches] [inputfile]\n\n\ -d, --debug set debugging flags (set $DEBUG to true)\n\ - -B[str] set begin block delimiter\n\ - -E[str] set end block delimiter\n\ -K[kcode] specifies KANJI (Japanese) code-set\n\ -M[mode] specifies runtime mode\n\ f: filter mode\n\ @@ -540,6 +556,7 @@ set_mode(++s); s++; goto again; +#if 0 case 'B': if (*++s == '\0') { s = argv[++i]; @@ -570,6 +587,7 @@ eruby_end_delimiter1 = *s++; eruby_end_delimiter2 = *s; break; +#endif case 'K': rb_set_kcode(++s); s++; @@ -583,7 +601,7 @@ s++; goto again; case 'n': - eruby_no_header = 1; + eruby_noheader = 1; s++; goto again; case '\0': @@ -597,7 +615,7 @@ ruby_debug = Qtrue; } else if (strcmp("noheader", s) == 0) { - eruby_no_header = 1; + eruby_noheader = 1; } else if (strcmp("version", s) == 0) { show_version(); @@ -658,7 +676,9 @@ rb_set_safe_level(1); rb_defout = rb_str_new("", 0); - rb_define_singleton_method(rb_defout, "write", str_write, 1); + rb_define_singleton_method(rb_defout, "write", defout_write, 1); + rb_define_singleton_method(rb_defout, "cancel", defout_cancel, 0); + rb_define_virtual_variable("$NOHEADER", noheader_getter, noheader_setter); script = eruby_load(eruby_filename, 0, &state); if (state) { error_print(state, eruby_mode, script); @@ -672,7 +692,7 @@ unlink(RSTRING(script)->ptr); out = RSTRING(rb_defout)->ptr; nout = RSTRING(rb_defout)->len; - if (!eruby_no_header && + if (!eruby_noheader && (eruby_mode == MODE_CGI || eruby_mode == MODE_NPHCGI)) { if (eruby_mode == MODE_NPHCGI) print_http_headers();