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