File: process_args.c

package info (click to toggle)
scsh 0.5.1-2
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 6,540 kB
  • ctags: 8,656
  • sloc: lisp: 39,346; ansic: 13,466; sh: 1,669; makefile: 624
file content (80 lines) | stat: -rw-r--r-- 2,465 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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;}