Listing 3

 1: /*************************************************************
 2: * Program: CMENU Menu Compiler
 3: * Module: cmenu1.c
 4: *     Menu Compiler:
 5: *     Main and Utility Functions
 6: * Written by: Leor Zolman, 7/91
 7: *************************************************************/
 8:
 9: #define MASTER
10: #include "cmenu.h"
11: #include "ccmenu.h"
12:
13: #include <string.h>
14:
15: #if __STDC______LINEEND____
16: #   include <stdarg.h>
17: #else
18: #   include <varargs.h>
19: #endif
20:
21: int main(argc,argv)
22: int argc;
23: char **argv;
24: {
25:    register i;
26:
27:    printf("CMENU Menu Compiler v%s\n", VERSION);
28:    if (argc< 2)
29:    {
30:        puts("usage: cmenu <menu-source-file(s)>\n");
31:        return 0;
32:    }
33:
34:    for (i = 1; i < argc; i++)
35:        if (dofile(argv[i]) == ERROR)         /* process source files */
36:         return 1;
37:    return 0;
38: }
39:
40: /************************************************************
41: * dofile():
42: *  Process a single .mnu source file
43: *************************************************************/
44:
45: int dofile(name)
46: char *name;
47: {
48:     register i;
49:     char *cp;
50:
51:     if ((cp = strstr(name, ".mnu")) ||
52:        (cp = strstr(name, ".MNU")))
53:                 *cp = '\0';
54:
55:     strcpy(src_name, name);
56:     strcat(src_name, ".mnu");
57:     strcpy(obj_name, name);
58:
59:     if ((fp = fopen(src_name, "r")) == NULL)
60:         return fprintf(stderr, "Can't open %s\n", src_name);
61:
62:     n_menus = 0;
63:     lineno = 1;
64:     in_menu= FALSE;
65:     fatal = FALSE;
66:
67:     /* Main processing loop. Read a token and process it,
68:      * until end of file is reached:
69:      */
70:
71:    while ((token = gettok(fp)) != T_EOF)
72:    {
73:        if (!in_menu && token != T_MENU)
74:        {
75:            error("Each menu must begin with the Menu keyword");
76:            break;
77:        }
78:        if ((*keywords[token].t_func)() == ERROR)
79:            if (fatal)                 /* If fatal error, exit loop   */
80:            break;
81:    }

/* End of File */