Ben B. wrote:
On Sat, Feb 09, 2008, Gerry F. wrote:
Do I have it right that any line that begins with a hash that isn’t #!
is a comment, as well as the above?
Yup! And technically #! is a comment as well, it’s just a magical
comment.
I’m not sure that I can agree with you, Ben.
static void
load_file(fname, script)
const char *fname;
int script;
{
extern VALUE rb_stdin;
VALUE f;
int line_start = 1;
if (!fname) rb_load_fail(fname);
if (strcmp(fname, "-") == 0) {
f = rb_stdin;
}
else {
FILE *fp = fopen(fname, “r”);
if (fp == NULL) {
rb_load_fail(fname);
}
fclose(fp);
f = rb_file_open(fname, “r”);
#if defined DOSISH || defined CYGWIN
{
char *ext = strrchr(fname, ‘.’);
if (ext && strcasecmp(ext, “.exe”) == 0)
rb_io_binmode(f);
}
#endif
}
if (script) {
VALUE c = 1; /* something not nil */
VALUE line;
char *p;
if (xflag) {
forbid_setid("-x");
xflag = Qfalse;
while (!NIL_P(line = rb_io_gets(f))) {
line_start++;
if (RSTRING(line)->len > 2
&& RSTRING(line)->ptr[0] == ‘#’
&& RSTRING(line)->ptr[1] == ‘!’) {
if ((p = strstr(RSTRING(line)->ptr, “ruby”)) != 0) {
goto start_read;
}
}
}
rb_raise(rb_eLoadError, “no Ruby script found in input”);
}
c = rb_io_getc(f);
if (c == INT2FIX(’#’)) {
line = rb_io_gets(f);
if (NIL_P(line)) return;
line_start++;
if (RSTRING(line)->len > 2 && RSTRING(line)->ptr[0] == '!') {
if ((p = strstr(RSTRING(line)->ptr, "ruby")) == 0) {
/* not ruby script, kick the program */
char **argv;
char *path;
char *pend = RSTRING(line)->ptr + RSTRING(line)->len;
p = RSTRING(line)->ptr + 1; /* skip `#!' */
if (pend[-1] == '\n') pend--; /* chomp line */
if (pend[-1] == '\r') pend--;
*pend = '\0';
while (p < pend && ISSPACE(*p))
p++;
path = p; /* interpreter path */
while (p < pend && !ISSPACE(*p))
p++;
*p++ = '\0';
if (p < pend) {
argv = ALLOCA_N(char*, origargc+3);
argv[1] = p;
MEMCPY(argv+2, origargv+1, char*, origargc);
}
else {
argv = origargv;
}
argv[0] = path;
execv(path, argv);
ruby_sourcefile = rb_source_filename(fname);
ruby_sourceline = 1;
rb_fatal("Can't exec %s", path);
}
start_read:
p += 4;
RSTRING(line)->ptr[RSTRING(line)->len-1] = '\0';
if (RSTRING(line)->ptr[RSTRING(line)->len-2] == '\r')
RSTRING(line)->ptr[RSTRING(line)->len-2] = '\0';
if ((p = strstr(p, " -")) != 0) {
p++; /* skip space before `-' */
while (*p == '-') {
p = moreswitches(p+1);
}
}
}
}
else if (!NIL_P©) {
rb_io_ungetc(f, c);
}
require_libraries(); /* Why here? unnatural */
if (NIL_P©) return;
}
rb_compile_file(fname, f, line_start);
if (script && ruby__end__seen) {
rb_define_global_const(“DATA”, f);
}
else if (f != rb_stdin) {
rb_io_close(f);
}
if (ruby_parser_stack_on_heap()) {
rb_gc();
}
}
end function load_file in ruby.c
What good’s a comment if you have to say the right thing?
rb_fatal(“Can’t exec %s”, path);
Gerry F.