factored out arg parsing; have not gotten the static linker to support linking in a new one yet; probably no more work required here though
This commit is contained in:
parent
26b8de258e
commit
55a65c1b64
129
main.c
129
main.c
|
@ -58,15 +58,19 @@ static void usage(void)
|
|||
}
|
||||
|
||||
static void bad_args(void) { usage(); exit(1); }
|
||||
char ** process_args(char **argv,
|
||||
long *heap_size,
|
||||
long *stack_size,
|
||||
char **object_file,
|
||||
char **image_name);
|
||||
|
||||
main(argc, argv)
|
||||
int argc; char **argv;
|
||||
{
|
||||
extern char **process_meta_arg(char **);
|
||||
char **argp;
|
||||
char *image_name = DEFAULT_IMAGE_NAME;
|
||||
long heap_size = DEFAULT_HEAP_SIZE; /* in numbers of cells */
|
||||
long stack_size = DEFAULT_STACK_SIZE; /* in numbers of cells */
|
||||
char **argp;
|
||||
long return_value;
|
||||
extern void sysdep_init();
|
||||
extern long required_init_space();
|
||||
|
@ -88,62 +92,11 @@ main(argc, argv)
|
|||
prog_name = *argv++; /* Save program name. */
|
||||
|
||||
object_file = reloc_file = NULL;
|
||||
|
||||
argv=process_args(argv,
|
||||
&heap_size, &stack_size,
|
||||
&object_file, &image_name);
|
||||
|
||||
/* 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 */
|
||||
heap_size = atoi(*argv);
|
||||
if( heap_size <= 0 ) bad_args();
|
||||
break;
|
||||
|
||||
case 's':
|
||||
argv++;
|
||||
if( !*argv ) bad_args(); /* die */
|
||||
stack_size = atoi(*argv);
|
||||
if (stack_size <= 0) bad_args();
|
||||
break;
|
||||
|
||||
case 'o': /* object file */
|
||||
argv++;
|
||||
if( !*argv ) bad_args(); /* die */
|
||||
object_file = *argv;
|
||||
break;
|
||||
|
||||
/* These switches terminate arg scanning. */
|
||||
case 'i':
|
||||
argv++;
|
||||
if( !*argv ) bad_args(); /* die */
|
||||
image_name = *argv++;
|
||||
goto args_done;
|
||||
|
||||
case '-':
|
||||
case 'a':
|
||||
argv++;
|
||||
goto args_done;
|
||||
}
|
||||
|
||||
args_done:
|
||||
for(argc=0, argp=argv; *argp; argc++, argp++); /* Recompute argc. */
|
||||
|
||||
sysdep_init();
|
||||
|
@ -196,3 +149,65 @@ main(argc, argv)
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue