1999-09-23 10:36:25 -04:00
|
|
|
#include <stdio.h>
|
2002-02-13 09:34:52 -05:00
|
|
|
#include <stdlib.h>
|
2003-05-05 03:09:35 -04:00
|
|
|
#include <stdarg.h>
|
2008-01-26 12:27:14 -05:00
|
|
|
#include <string.h>
|
1999-09-23 10:36:25 -04:00
|
|
|
|
|
|
|
#define streq(a,b) (strcmp((a),(b))==0)
|
|
|
|
|
|
|
|
static void usage(void) {
|
2003-10-02 10:32:21 -04:00
|
|
|
printf(""\
|
|
|
|
"Usage: scsh [meta-arg] [vm-option+] [end-option scheme-args]"\
|
|
|
|
""\
|
|
|
|
"meta-arg: \\ <script-file-name>"\
|
|
|
|
""\
|
|
|
|
"switch: -e <entry-point> Specify top-level entry point."\
|
|
|
|
" -o <structure> Open structure in current package."\
|
|
|
|
" -m <package> Switch to package."\
|
|
|
|
" -n <new-package> Switch to new package."\
|
|
|
|
""\
|
|
|
|
""\
|
|
|
|
" -lm <module-file-name> Load module into config package."\
|
|
|
|
" -le <exec-file-name> Load file into exec package."\
|
|
|
|
" -l <file-name> Load file into current package."\
|
|
|
|
""\
|
|
|
|
" -ll <module-file-name> As in -lm, but search the library path list."\
|
|
|
|
" +lp <dir> Add <dir> to front of library path list."\
|
|
|
|
" lp+ <dir> Add <dir> to end of library path list."\
|
|
|
|
" +lpe <dir> +lp, with env var and ~user expansion."\
|
|
|
|
" lpe+ <dir> lp+, with env var and ~user expansion."\
|
|
|
|
" +lpsd Add script-file's dir to front of path list."\
|
|
|
|
" lpsd+ Add script-file's dir to end of path list."\
|
|
|
|
" -lp-clear Clear library path list to ()."\
|
|
|
|
" -lp-default Reset library path list to system default."\
|
|
|
|
""\
|
|
|
|
" -ds Do script."\
|
|
|
|
" -dm Do script module."\
|
|
|
|
" -de Do script exec."\
|
|
|
|
""\
|
|
|
|
" -h <cells> Set heap size."\
|
|
|
|
" -i <file> Specify image."\
|
|
|
|
" -stacksize <cells> Set stack size"\
|
|
|
|
""\
|
|
|
|
"end-option: -s <script> Specify script."\
|
|
|
|
" -sfd <num> Script is on file descriptor <num>."\
|
|
|
|
" -c <exp> Evaluate expression."\
|
|
|
|
" -- Interactive session."\
|
|
|
|
"");
|
2003-05-05 03:09:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bad_args(char* msg, char* arg) {
|
|
|
|
|
|
|
|
printf ("Error:\n");
|
|
|
|
printf (msg,arg);
|
|
|
|
printf ("\n");
|
|
|
|
usage();
|
2008-01-26 12:27:14 -05:00
|
|
|
exit(1);
|
2003-05-05 03:09:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void process_args(char **argv,
|
1999-09-14 09:32:05 -04:00
|
|
|
long *pheap_size,
|
|
|
|
long *pstack_size,
|
|
|
|
char **pobject_file,
|
|
|
|
char **pimage_name) {
|
1999-09-23 10:36:25 -04:00
|
|
|
extern char **process_meta_arg(char **);
|
|
|
|
|
|
|
|
/* Handle an initial \ <fname> meta-arg expansion. */
|
|
|
|
while ( *argv && streq(*argv, "\\") ) {
|
|
|
|
argv++;
|
2003-05-05 03:09:35 -04:00
|
|
|
if( !*argv ) bad_args("No arguments after meta-arg %s","\\"); /* die */
|
1999-09-23 10:36:25 -04:00
|
|
|
argv = process_meta_arg(argv);
|
|
|
|
if( !argv ) {
|
2003-05-05 03:09:35 -04:00
|
|
|
fprintf(stderr, "scsh: \\ <fname> expansion failed.\n");
|
1999-09-23 10:36:25 -04:00
|
|
|
exit(1);}}
|
|
|
|
|
2003-05-05 03:09:35 -04:00
|
|
|
|
|
|
|
for (; *argv; argv++){
|
2008-01-26 12:27:14 -05:00
|
|
|
|
2003-05-05 03:09:35 -04:00
|
|
|
char *arg = argv[0];
|
|
|
|
#define S48_ARGCMP(s) (streq(arg,s))
|
2008-01-26 12:27:14 -05:00
|
|
|
|
2003-05-05 03:09:35 -04:00
|
|
|
if (S48_ARGCMP ("-h")) { /* heapsize */
|
|
|
|
argv++;
|
|
|
|
if( !*argv ) bad_args("Option %s requires an argument", arg); /* die */
|
|
|
|
*pheap_size = atoi(*argv);
|
|
|
|
if( *pheap_size <= 0 ) bad_args("Invalid argument to %s", arg);
|
|
|
|
}
|
|
|
|
else if (S48_ARGCMP ("-stacksize")) { /* stacksize */
|
|
|
|
argv++;
|
|
|
|
if( !*argv ) bad_args("Option %s requires an argument", arg); /* die */
|
|
|
|
*pstack_size = atoi(*argv);
|
|
|
|
if( *pstack_size <= 0 ) bad_args("Invalid argument to %s", arg);
|
|
|
|
}
|
|
|
|
else if (S48_ARGCMP ("-i")) { /* image */
|
|
|
|
argv++;
|
|
|
|
if( !*argv ) bad_args("Option %s requires an argument", arg); /* die */
|
|
|
|
*pimage_name = *argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (S48_ARGCMP ("+lpsd") ||
|
|
|
|
S48_ARGCMP ("lpsd+") ||
|
|
|
|
S48_ARGCMP ("-lp-clear") ||
|
|
|
|
S48_ARGCMP ("-lp-default") ||
|
|
|
|
S48_ARGCMP ("-ds") ||
|
|
|
|
S48_ARGCMP ("-dm") ||
|
|
|
|
S48_ARGCMP ("-de")){
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else if (S48_ARGCMP ("-e") ||
|
|
|
|
S48_ARGCMP ("-o") ||
|
|
|
|
S48_ARGCMP ("-m") ||
|
|
|
|
S48_ARGCMP ("-lm") ||
|
|
|
|
S48_ARGCMP ("-le") ||
|
|
|
|
S48_ARGCMP ("-l") ||
|
|
|
|
S48_ARGCMP ("-ll") ||
|
|
|
|
S48_ARGCMP ("+lp") ||
|
|
|
|
S48_ARGCMP ("lp+") ||
|
|
|
|
S48_ARGCMP ("+lpe") ||
|
|
|
|
S48_ARGCMP ("lpe+")){
|
|
|
|
argv++;
|
|
|
|
if( !*argv ) bad_args("Option %s requires an argument", arg);
|
|
|
|
}
|
2008-01-26 12:27:14 -05:00
|
|
|
|
2003-05-05 03:09:35 -04:00
|
|
|
/* These switches terminate arg scanning. */
|
|
|
|
else if (S48_ARGCMP ("-s") ||
|
|
|
|
S48_ARGCMP ("-sdf") ||
|
|
|
|
S48_ARGCMP ("-c")){
|
|
|
|
argv++;
|
|
|
|
if( !*argv ){
|
|
|
|
bad_args("Option %s requires an argument", arg);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (S48_ARGCMP ("--")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
bad_args("Unknown switch %s", arg);
|
|
|
|
}
|
|
|
|
}
|
2008-01-26 12:27:14 -05:00
|
|
|
|
2003-05-05 03:09:35 -04:00
|
|
|
#undef S48_ARGCMP
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|