(Not part of the mozilla build process.)

Added support in the javascript shell for the #! unix script hack; if
the first line read by the shell (from a file, not interactive) starts
with #, the line is treated as a comment.

This should make
#!/usr/bin/js work...
This commit is contained in:
mccabe 1998-05-09 05:54:12 +00:00
Родитель e0a3f308d8
Коммит 001a0b714c
2 изменённых файлов: 32 добавлений и 2 удалений

Просмотреть файл

@ -91,8 +91,23 @@ Process(JSContext *cx, JSObject *obj, char *filename)
if (!filename)
ts->filename = "typein";
#endif
if (isatty(fileno(ts->file)))
if (isatty(fileno(ts->file))) {
ts->flags |= TSF_INTERACTIVE;
} else {
/* Support the UNIX #! shell hack; gobble the first line if it starts
* with '#'. TODO - this isn't quite compatible with sharp variables,
* as a legal js program (using sharp variables) might start with '#'.
* But that would require multi-character lookahead.
*/
char ch = fgetc(ts->file);
if (ch == '#') {
while((ch = fgetc(ts->file)) != EOF) {
if(ch == '\n' || ch == '\r')
break;
}
}
ungetc(ch, ts->file);
}
do {
js_InitCodeGenerator(cx, &cg, ts->filename, ts->lineno, ts->principals);

Просмотреть файл

@ -95,8 +95,23 @@ Process(JSContext *cx, JSObject *obj, char *filename)
if (!filename)
ts->filename = "typein";
#endif
if (isatty(fileno(ts->file)))
if (isatty(fileno(ts->file))) {
ts->flags |= TSF_INTERACTIVE;
} else {
/* Support the UNIX #! shell hack; gobble the first line if it starts
* with '#'. TODO - this isn't quite compatible with sharp variables,
* as a legal js program (using sharp variables) might start with '#'.
* But that would require multi-character lookahead.
*/
char ch = fgetc(ts->file);
if (ch == '#') {
while((ch = fgetc(ts->file)) != EOF) {
if(ch == '\n' || ch == '\r')
break;
}
}
ungetc(ch, ts->file);
}
do {
js_InitCodeGenerator(cx, &cg, ts->filename, ts->lineno, ts->principals);