+ Pass prog_name from main to process_args
+ During argument processing, skip empty arguments inserted by the meta-argument expander
This commit is contained in:
parent
ba76b7a3cc
commit
11880601dd
3
c/main.c
3
c/main.c
|
@ -32,6 +32,7 @@
|
|||
|
||||
|
||||
char ** process_args(char **argv,
|
||||
char* prog_name,
|
||||
long *heap_size,
|
||||
long *stack_size,
|
||||
char **object_file,
|
||||
|
@ -65,7 +66,7 @@ main(argc, argv)
|
|||
char *me = *argv; /* Save program name. */
|
||||
prog_name = *argv++;
|
||||
|
||||
argv=process_args(argv,
|
||||
argv=process_args(argv, prog_name,
|
||||
&heap_size, &stack_size,
|
||||
&object_file, &image_name);
|
||||
for(argc=0, argp=argv; *argp; argc++, argp++); /* Recompute argc. */
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
extern char *prog_name;
|
||||
|
||||
#define streq(a,b) (strcmp((a),(b))==0)
|
||||
|
||||
static 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"
|
||||
|
@ -18,18 +18,22 @@ static void usage(void) {
|
|||
" -a (Terminates vm args. Obsolete.)\n",
|
||||
prog_name);}
|
||||
|
||||
static void bad_args(int nr) {
|
||||
fprintf(stderr, "reason : %d\n", nr);
|
||||
static void bad_args(int reason) {
|
||||
/* fprintf(stderr, "reason : %s\n", reason); */
|
||||
usage();
|
||||
exit(1); }
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char ** process_args(char **argv,
|
||||
char * _prog_name,
|
||||
long *pheap_size,
|
||||
long *pstack_size,
|
||||
char **pobject_file,
|
||||
char **pimage_name) {
|
||||
extern char **process_meta_arg(char **);
|
||||
|
||||
prog_name = _prog_name;
|
||||
|
||||
/* Handle an initial \ <fname> meta-arg expansion. */
|
||||
while ( *argv && streq(*argv, "\\") ) {
|
||||
argv++;
|
||||
|
@ -41,7 +45,11 @@ char ** process_args(char **argv,
|
|||
exit(1);}}
|
||||
|
||||
for (; *argv; argv++)
|
||||
if( argv[0][0] != '-' )
|
||||
if (argv[0][0] == NULL)
|
||||
/* process_meta_arg inserts an empty argument for every space.
|
||||
Skip it. */
|
||||
continue;
|
||||
else if( argv[0][0] != '-' )
|
||||
bad_args(1); /* die */
|
||||
else
|
||||
switch (argv[0][1]) {
|
||||
|
@ -52,6 +60,7 @@ char ** process_args(char **argv,
|
|||
case 'h': /* heapsize */
|
||||
argv++;
|
||||
if( !*argv ) bad_args(3); /* die */
|
||||
while (argv[0][0] == NULL)argv++; /* Skip empty arguments */
|
||||
*pheap_size = atoi(*argv);
|
||||
if( *pheap_size <= 0 ) bad_args(4);
|
||||
break;
|
||||
|
@ -59,6 +68,7 @@ char ** process_args(char **argv,
|
|||
case 's':
|
||||
argv++;
|
||||
if( !*argv ) bad_args(5); /* die */
|
||||
while (argv[0][0] == NULL) argv++; /* Skip empty arguments */
|
||||
*pstack_size = atoi(*argv);
|
||||
if (*pstack_size <= 0) bad_args(6);
|
||||
break;
|
||||
|
@ -66,6 +76,7 @@ char ** process_args(char **argv,
|
|||
case 'o': /* object file */
|
||||
argv++;
|
||||
if( !*argv ) bad_args(7); /* die */
|
||||
while (argv[0][0] == NULL)argv++; /* Skip empty arguments */
|
||||
*pobject_file = *argv;
|
||||
break;
|
||||
|
||||
|
@ -73,6 +84,7 @@ char ** process_args(char **argv,
|
|||
case 'i':
|
||||
argv++;
|
||||
if( !*argv ) bad_args(8); /* die */
|
||||
while (argv[0][0] == NULL)argv++; /* Skip empty arguments */
|
||||
*pimage_name = *argv++;
|
||||
return argv;
|
||||
|
||||
|
|
Loading…
Reference in New Issue