Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Main
Synchronet
Commits
02209233
Commit
02209233
authored
Jul 17, 2003
by
rswindell
Browse files
Added support for Unix shell scripts by ignoring the first line if it starts with #!.
parent
93f453e1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
23 deletions
+23
-23
src/sbbs3/jsexec.c
src/sbbs3/jsexec.c
+23
-23
No files found.
src/sbbs3/jsexec.c
View file @
02209233
...
...
@@ -489,6 +489,7 @@ static const char* js_ext(const char* fname)
long
js_exec
(
const
char
*
fname
,
char
**
args
)
{
int
argc
=
0
;
uint
line_no
;
char
path
[
MAX_PATH
+
1
];
char
line
[
1024
];
char
*
js_buf
=
NULL
;
...
...
@@ -540,13 +541,19 @@ long js_exec(const char *fname, char** args)
JS_SetBranchCallback
(
js_cx
,
js_BranchCallback
);
if
(
fname
==
NULL
)
{
/* Use stdin for script source */
fprintf
(
statfp
,
"Reading script from stdin
\n
"
);
if
(
fname
==
NULL
)
/* Use stdin for script source */
SAFECOPY
(
path
,
"stdin"
);
fprintf
(
statfp
,
"Reading script from %s
\n
"
,
path
);
line_no
=
0
;
js_buflen
=
0
;
while
(
!
feof
(
stdin
))
{
if
(
!
fgets
(
line
,
sizeof
(
line
),
stdin
))
break
;
line_no
++
;
#ifdef __unix__
/* Support Unix Shell Scripts that start with #!/path/to/jsexec */
if
(
line_no
==
1
&&
strncmp
(
line
,
"#!"
,
2
))
continue
;
#endif
if
((
js_buf
=
realloc
(
js_buf
,
js_buflen
+
strlen
(
line
)))
==
NULL
)
{
fprintf
(
errfp
,
"!Error allocating %u bytes of memory
\n
"
,
js_buflen
+
strlen
(
line
));
...
...
@@ -555,19 +562,12 @@ long js_exec(const char *fname, char** args)
strcpy
(
js_buf
+
js_buflen
,
line
);
js_buflen
+=
strlen
(
line
);
}
if
((
js_script
=
JS_CompileScript
(
js_cx
,
js_scope
,
js_buf
,
js_buflen
,
NULL
,
1
))
==
NULL
)
{
if
((
js_script
=
JS_CompileScript
(
js_cx
,
js_scope
,
js_buf
,
js_buflen
,
fname
==
NULL
?
NULL
:
path
,
1
))
==
NULL
)
{
fprintf
(
errfp
,
"!Error compiling script from stdin
\n
"
);
return
(
-
1
);
}
}
else
{
if
((
js_script
=
JS_CompileFile
(
js_cx
,
js_scope
,
path
))
==
NULL
)
{
fprintf
(
errfp
,
"!Error compiling %s
\n
"
,
path
);
return
(
-
1
);
}
}
JS_ExecuteScript
(
js_cx
,
js_scope
,
js_script
,
&
rval
);
JS_GetProperty
(
js_cx
,
js_glob
,
"exit_code"
,
&
rval
);
if
(
rval
!=
JSVAL_VOID
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment