Merged arguments of VM and scsh.

Non-backward comptaible changes:

-o for specifying the object file is gone
-i does not terminate argument scanning
-s for specifying the size of the stack is now -stacksize
This commit is contained in:
mainzelm 2003-05-05 07:09:35 +00:00
parent 0951ec5b42
commit 26fcfcd8b2
5 changed files with 141 additions and 72 deletions

View File

@ -378,7 +378,7 @@ inst-script:
echo '#!/bin/sh' >$$script && \
echo >>$$script && \
echo 'lib=$(LIB)' >>$$script && \
echo 'exec $$lib/$(VM) -o $$lib/$(VM) -i $$lib/$(IMAGE) "$$@"' \
echo 'exec $$lib/$(VM) -i $$lib/$(IMAGE) "$$@"' \
>>$$script && \
chmod +x $$script
@ -387,7 +387,7 @@ go:
echo '#!/bin/sh' >$@ && \
echo >>$@ && \
echo "lib=`pwd`" >>$@ && \
echo 'exec $$lib/$(VM) -o $$lib/$(VM) -i $$lib/scsh/scsh.image "$$@"' \
echo 'exec $$lib/$(VM) -i $$lib/scsh/scsh.image "$$@"' \
>>$@ && \
chmod +x $@
@ -832,7 +832,7 @@ scsh/scsh.image: $(VM) $(SCHEME) $(IMAGE)
echo ",open $(opens)"; \
echo "(dump-scsh \"$@\")"; \
) \
| ./$(VM) -o ./$(VM) -i $(IMAGE) -h 10000000
| ./$(VM) -i $(IMAGE) -h 10000000
# ,flush files => 0k
# ,flush names => -= 17k
@ -847,7 +847,7 @@ scsh/stripped-scsh.image: $(VM) $(SCHEME) $(IMAGE)
echo ",open $(opens)"; \
echo ",flush"; \
echo "(dump-scsh \"$@\")";) \
| ./$(VM) -o ./$(VM) -i $(IMAGE) -h 10000000
| ./$(VM) -i $(IMAGE) -h 10000000
install-scsh: scsh install-scsh-image install-stripped-scsh-image
$(RM) $(bindir)/$(RUNNABLE)

View File

@ -9,7 +9,7 @@ vm=$4
initial=$5
USER=${USER-`logname 2>/dev/null || echo '*GOK*'`}
./$vm -o ./$vm -i $initial batch <<EOF
./$vm -o ./$vm -i $initial -- batch <<EOF
,load $srcdir/scheme/env/init-defpackage.scm
((*structure-ref filenames 'set-translation!)
"=scheme48/" "$srcdir/scheme/")

View File

@ -31,11 +31,11 @@
char ** process_args(char **argv,
long *heap_size,
long *stack_size,
char **object_file,
char **image_name);
void process_args(char **argv,
long *heap_size,
long *stack_size,
char **object_file,
char **image_name);
extern int
internal_s48_main(long heap_size, long stack_size,
@ -65,9 +65,9 @@ main(argc, argv)
char *me = *argv; /* Save program name. */
prog_name = *argv++;
argv=process_args(argv,
&heap_size, &stack_size,
&object_file, &image_name);
process_args(argv,
&heap_size, &stack_size,
&object_file, &image_name);
for(argc=0, argp=argv; *argp; argc++, argp++); /* Recompute argc. */
return internal_s48_main(heap_size, stack_size, prog_name, object_file, image_name, argc, argv);
}

View File

@ -1,29 +1,61 @@
#include <stdio.h>
#include <stdlib.h>
extern char *prog_name;
#include <stdarg.h>
#define streq(a,b) (strcmp((a),(b))==0)
static void usage(void) {
fprintf(stderr, "Usage: %s [meta-arg] [vm-option+] [end-option scheme-args]\n"
"meta-arg: \\ <script file name>\n"
"\n"
"vm-option: -h <total heap size in words>\n"
" -s <stack size in words>\n"
" -o <object file name>\n"
"\n"
"end-option: -i <image file name>\n"
" -- (Terminates vm args.)\n"
" -a (Terminates vm args. Obsolete.)\n",
prog_name);}
printf("
Usage: scsh [meta-arg] [vm-option+] [end-option scheme-args]
static void bad_args(int nr) {
fprintf(stderr, "reason : %d\n", nr);
usage();
exit(1); }
meta-arg: \\ <script-file-name>
char ** process_args(char **argv,
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.
");
}
static void bad_args(char* msg, char* arg) {
printf ("Error:\n");
printf (msg,arg);
printf ("\n");
usage();
exit(1);
}
void process_args(char **argv,
long *pheap_size,
long *pstack_size,
char **pobject_file,
@ -33,51 +65,79 @@ char ** process_args(char **argv,
/* Handle an initial \ <fname> meta-arg expansion. */
while ( *argv && streq(*argv, "\\") ) {
argv++;
if( !*argv ) bad_args(0); /* die */
if( !*argv ) bad_args("No arguments after meta-arg %s","\\"); /* die */
argv = process_meta_arg(argv);
if( !argv ) {
fprintf(stderr, "%s: \\ <fname> expansion failed.\n",
prog_name);
fprintf(stderr, "scsh: \\ <fname> expansion failed.\n");
exit(1);}}
for (; *argv; argv++)
if( argv[0][0] != '-' )
bad_args(1); /* die */
else
switch (argv[0][1]) {
default:
bad_args(2); /* die */
break;
case 'h': /* heapsize */
argv++;
if( !*argv ) bad_args(3); /* die */
*pheap_size = atoi(*argv);
if( *pheap_size <= 0 ) bad_args(4);
break;
for (; *argv; argv++){
char *arg = argv[0];
#define S48_ARGCMP(s) (streq(arg,s))
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;
}
case 's':
argv++;
if( !*argv ) bad_args(5); /* die */
*pstack_size = atoi(*argv);
if (*pstack_size <= 0) bad_args(6);
break;
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);
}
/* 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);
}
}
#undef S48_ARGCMP
case 'o': /* object file */
argv++;
if( !*argv ) bad_args(7); /* die */
*pobject_file = *argv;
break;
/* These switches terminate arg scanning. */
case 'i':
argv++;
if( !*argv ) bad_args(8); /* die */
*pimage_name = *argv++;
return argv;
case '-':
case 'a':
argv++;
return argv;}
return argv;}
return;
}

View File

@ -177,6 +177,11 @@
(lp (cdr args) switches
(string->symbol (car args)) need-script?))
((or (string=? arg "-i")
(string=? arg "-h")
(string=? arg "-stacksize"))
(lp (cdr args) switches top-entry need-script?))
(else (bad-arg "Unknown switch" arg))))
(values (reverse switches) #f #f top-entry '()))))
@ -537,6 +542,10 @@ switch: -e <entry-point> Specify top-level entry point.
-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.