зеркало из https://github.com/mozilla/gecko-dev.git
(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:
Родитель
e0a3f308d8
Коммит
001a0b714c
17
js/ref/js.c
17
js/ref/js.c
|
@ -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);
|
||||
|
|
17
js/src/js.c
17
js/src/js.c
|
@ -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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче