factored out arg parsing

This commit is contained in:
bdc 1997-06-09 01:47:19 +00:00
parent 88aaa91880
commit 13dbef06b1
4 changed files with 88 additions and 82 deletions

View File

@ -128,7 +128,7 @@ SCSHOBJS = \
# scsh/dbm.o scsh/dbm1.o # scsh/dbm.o scsh/dbm1.o
OBJS = unix.o dynload.o prescheme.o extension.o scheme48vm.o \ OBJS = unix.o dynload.o prescheme.o extension.o scheme48vm.o \
$(CIGOBJS) $(SCSHVMHACKS) $(SCSHOBJS) process_args.o $(CIGOBJS) $(SCSHVMHACKS) $(SCSHOBJS)
# Sources: # Sources:

82
main.c
View File

@ -35,29 +35,11 @@
#endif /* STATIC_AREAS */ #endif /* STATIC_AREAS */
#define streq(a,b) (strcmp((a),(b))==0)
char *object_file; /* specified via a command line argument */ char *object_file; /* specified via a command line argument */
char *reloc_file; /* dynamic loading will set this */ char *reloc_file; /* dynamic loading will set this */
static char *prog_name; char *prog_name;
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);
}
static void bad_args(void) { usage(); exit(1); }
char ** process_args(char **argv, char ** process_args(char **argv,
long *heap_size, long *heap_size,
long *stack_size, long *stack_size,
@ -149,65 +131,3 @@ main(argc, argv)
return(return_value); return(return_value);
} }
char ** process_args(char **argv,
long *pheap_size,
long *pstack_size,
char **pobject_file,
char **pimage_name) {
extern char **process_meta_arg(char **);
/* Handle an initial \ <fname> meta-arg expansion. */
while ( *argv && streq(*argv, "\\") ) {
argv++;
if( !*argv ) bad_args(); /* die */
argv = process_meta_arg(argv);
if( !argv ) {
fprintf(stderr, "%s: \\ <fname> expansion failed.\n",
prog_name);
exit(1);
}
}
for (; *argv; argv++)
if( argv[0][0] != '-' )
bad_args(); /* die */
else
switch (argv[0][1]) {
default:
bad_args(); /* die */
break;
case 'h': /* heapsize */
argv++;
if( !*argv ) bad_args(); /* die */
*pheap_size = atoi(*argv);
if( *pheap_size <= 0 ) bad_args();
break;
case 's':
argv++;
if( !*argv ) bad_args(); /* die */
*pstack_size = atoi(*argv);
if (*pstack_size <= 0) bad_args();
break;
case 'o': /* object file */
argv++;
if( !*argv ) bad_args(); /* die */
*pobject_file = *argv;
break;
/* These switches terminate arg scanning. */
case 'i':
argv++;
if( !*argv ) bad_args(); /* die */
*pimage_name = *argv++;
return argv;
case '-':
case 'a':
argv++;
return argv;
}
return argv;
}

80
process_args.c Normal file
View File

@ -0,0 +1,80 @@
#include <stdio.h>
extern char *prog_name;
#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);}
static void bad_args(void) {
usage();
exit(1); }
char ** process_args(char **argv,
long *pheap_size,
long *pstack_size,
char **pobject_file,
char **pimage_name) {
extern char **process_meta_arg(char **);
/* Handle an initial \ <fname> meta-arg expansion. */
while ( *argv && streq(*argv, "\\") ) {
argv++;
if( !*argv ) bad_args(); /* die */
argv = process_meta_arg(argv);
if( !argv ) {
fprintf(stderr, "%s: \\ <fname> expansion failed.\n",
prog_name);
exit(1);}}
for (; *argv; argv++)
if( argv[0][0] != '-' )
bad_args(); /* die */
else
switch (argv[0][1]) {
default:
bad_args(); /* die */
break;
case 'h': /* heapsize */
argv++;
if( !*argv ) bad_args(); /* die */
*pheap_size = atoi(*argv);
if( *pheap_size <= 0 ) bad_args();
break;
case 's':
argv++;
if( !*argv ) bad_args(); /* die */
*pstack_size = atoi(*argv);
if (*pstack_size <= 0) bad_args();
break;
case 'o': /* object file */
argv++;
if( !*argv ) bad_args(); /* die */
*pobject_file = *argv;
break;
/* These switches terminate arg scanning. */
case 'i':
argv++;
if( !*argv ) bad_args(); /* die */
*pimage_name = *argv++;
return argv;
case '-':
case 'a':
argv++;
return argv;}
return argv;}

6
scsh/process_args.c Normal file
View File

@ -0,0 +1,6 @@
char ** process_args(char **argv,
long *pheap_size,
long *pstack_size,
char **pobject_file,
char **pimage_name) {
return argv;}