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

Commit

Permalink
added new option -s.
Browse files Browse the repository at this point in the history
  • Loading branch information
shugo committed Nov 2, 2004
1 parent 8e9e0ba commit f9c2721
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 116 deletions.
3 changes: 1 addition & 2 deletions README.ja
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
== eRuby�Ȥ�?

eRuby��Ruby�Υ����ɤ���ᤳ�ޤ줿�ƥ����ȥե��������¹Ԥ��ޤ���
���Ȥ��С�eRuby��Ȥ��С�HTML��Ruby�Υ����ɤ�HTML�ե��������ᤳ��
���Ȥ��Ǥ��ޤ���
���Ȥ��С�eRuby��Ȥ��С�HTML��Ruby�Υ����ɤ���ᤳ�ळ�Ȥ��Ǥ��ޤ���

== �׵ᤵ���Ķ�

Expand Down
11 changes: 6 additions & 5 deletions eruby.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! it was generated by rd2
.TH eruby 1 "September 2000"
.TH eruby 1 "November 2004"
.SH NAME
.PP
eruby \- Embedded Ruby Language
Expand All @@ -10,13 +10,15 @@ eruby [options] [inputfile]
.PP
eruby interprets a Ruby code embedded text file. For example, eruby
enables you to embed a Ruby code to a HTML file.
.PP
A Ruby block starts with `<%' and ends with `%>'. eRuby replaces
the block with its output.
.PP
If `<%' is followed by `=', eRuby replaces the block with a value
of the block.
.PP
If `<%' is followed by `#', the block is ignored as a comment.
.SH OPTIONS
.PP
.TP
.fi
.B
Expand All @@ -36,8 +38,7 @@ specifies runtime mode
\& f: filter mode
\& c: CGI mode
\& n: NPH\-CGI mode
.fi
.TP
.fi.TP
.fi
.B
\-C charset
Expand All @@ -55,7 +56,7 @@ enables verbose mode
.TP
.fi
.B
\-\-version
\-\-version
print version information and exit
.SH AUTHOR
.PP
Expand Down
6 changes: 4 additions & 2 deletions eruby.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* $Id: eruby.h,v 1.31 2003/12/23 15:11:54 shugo Exp $
* $Id$
* Copyright (C) 2000 ZetaBITS, Inc.
* Copyright (C) 2000 Information-technology Promotion Agency, Japan
*/

#ifndef ERUBY_H
#define ERUBY_H

#define ERUBY_VERSION "1.0.5"
#define ERUBY_VERSION "1.0.6"

#define ERUBY_MIME_TYPE "application/x-httpd-eruby"

Expand All @@ -28,13 +28,15 @@ enum eruby_mode {
extern char *eruby_filename;
extern int eruby_mode;
extern int eruby_noheader;
extern int eruby_sync;
extern VALUE eruby_charset;
extern VALUE eruby_default_charset;
#define ERUBY_CHARSET RSTRING(eruby_charset)->ptr

const char *eruby_version();
int eruby_parse_options(int argc, char **argv, int *optind);
VALUE eruby_compiler_new();
VALUE eruby_compiler_set_sourcefile(VALUE self, VALUE filename);
VALUE eruby_compiler_compile_file(VALUE self, VALUE file);
VALUE eruby_compiler_compile_string(VALUE self, VALUE s);
VALUE eruby_load(char *filename, int wrap, int *state);
Expand Down
86 changes: 13 additions & 73 deletions eruby_lib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: eruby_lib.c,v 1.19 2003/07/29 03:42:56 shugo Exp $
* $Id$
* Copyright (C) 2000 ZetaBITS, Inc.
* Copyright (C) 2000 Information-technology Promotion Agency, Japan
* Copyright (C) 2000 Shugo Maeda <[email protected]>
Expand Down Expand Up @@ -48,6 +48,7 @@ static VALUE eERubyCompileError;
char *eruby_filename = NULL;
int eruby_mode = MODE_UNKNOWN;
int eruby_noheader = 0;
int eruby_sync = 0;
VALUE eruby_charset;
VALUE eruby_default_charset;

Expand Down Expand Up @@ -82,6 +83,7 @@ usage: %s [switches] [inputfile]\n\n\
n: NPH-CGI mode\n\
-C [charset] specifies charset parameter for Content-Type\n\
-n, --noheader disables CGI header output\n\
-s, --sync sync output\n\
-v, --verbose enables verbose mode\n\
--version print version information and exit\n\
\n", progname);
Expand Down Expand Up @@ -173,6 +175,10 @@ int eruby_parse_options(int argc, char **argv, int *optind)
eruby_noheader = 1;
s++;
goto again;
case 's':
eruby_sync = 1;
s++;
goto again;
case '\0':
break;
case 'h':
Expand All @@ -192,6 +198,12 @@ int eruby_parse_options(int argc, char **argv, int *optind)
s += 8;
goto again;
}
else if (strncmp(s, "sync", 4) == 0
&& (s[4] == '\0' || isspace(s[4]))) {
eruby_sync = 1;
s += 4;
goto again;
}
else if (strncmp(s, "version", 7) == 0
&& (s[7] == '\0' || isspace(s[7]))) {
show_version();
Expand Down Expand Up @@ -632,78 +644,6 @@ VALUE eruby_compiler_compile_file(VALUE self, VALUE file)
return eruby_compile(compiler);
}

static VALUE file_open(VALUE filename)
{
return rb_file_open((char *) filename, "r");
}

typedef struct compile_arg {
VALUE compiler;
VALUE input;
} compile_arg_t;

static VALUE eruby_compile_file(VALUE arg)
{
return eruby_compiler_compile_file(((compile_arg_t *) arg)->compiler,
((compile_arg_t *) arg)->input);
}

typedef struct eval_arg {
VALUE src;
VALUE filename;
} eval_arg_t;

static VALUE eval_string(VALUE arg)
{
return rb_funcall(ruby_top_self, rb_intern("eval"), 3,
((eval_arg_t *) arg)->src,
Qnil,
((eval_arg_t *) arg)->filename);
}

VALUE eruby_load(char *filename, int wrap, int *state)
{
VALUE compiler;
VALUE code;
VALUE f;
VALUE vfilename = rb_str_new2(filename);
compile_arg_t carg;
eval_arg_t earg;
int status;

if (strcmp(filename, "-") == 0) {
f = rb_stdin;
}
else {
f = rb_protect(file_open, (VALUE) filename, &status);
if (status) {
if (state) *state = status;
return Qnil;
}
}
compiler = eruby_compiler_new();
eruby_compiler_set_sourcefile(compiler, vfilename);
carg.compiler = compiler;
carg.input = f;
code = rb_protect(eruby_compile_file, (VALUE) &carg, &status);
if (status) {
if (state) *state = status;
return Qnil;
}
if (wrap) {
rb_eval_string_wrap(STR2CSTR(code), &status);
}
else {
earg.src = code;
earg.filename = vfilename;
rb_protect(eval_string, (VALUE) &earg, &status);
}
if (state) *state = status;
if (f != rb_stdin)
rb_io_close(f);
return code;
}

static VALUE noheader_getter()
{
return eruby_noheader ? Qtrue : Qfalse;
Expand Down
Loading

0 comments on commit f9c2721

Please sign in to comment.