-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmgl-code
130 lines (126 loc) · 2.5 KB
/
mgl-code
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* subr.h */
/*
* MGL Runtime support code
*/
char *screen_init[] = {
"/* initialization information */",
"static int init;\n",
"#include <curses.h>",
"#include <sys/signal.h>",
"#include <ctype.h>",
"#include <stdlib.h>",
"#include \"mglyac.tab.h\"",
"#include \"mglhdr.h\"\n",
"/* structure used to store menu items */",
"struct item {",
" char *desc;",
" char *cmd;",
" int action;",
" char *act_str; /* execute string */",
" void (*act_menu)(); /* call appropriate function */",
" int attribute;",
"};\n",
"void menu_init();",
"void menu_runtime(struct item *items);",
"int casecmp(char *p, char *q);\n",
0,
};
char *menu_init[] = {
"void menu_init()",
"{",
" void menu_cleanup();\n",
" /*signal(SIGINT, menu_cleanup);*/",
" initscr();",
" crmode();",
"}\n\n",
"void menu_cleanup()",
"{",
" mvcur(0, COLS - 1, LINES - 1, 0);",
" endwin();",
"}\n",
0,
};
char *menu_runtime[] = {
"/* runtime */",
"",
"void menu_runtime(struct item *items)",
"{",
" int visible = 0;",
" int choice = 0;",
" struct item *ptr;",
" char buf[BUFSIZ];",
"",
" for(ptr = items; ptr->desc != 0; ptr++) {",
" addch('\\n'); /* skip a line */",
" if(ptr->attribute == VISIBLE) {",
" visible++;",
" printw(\"\\t%d) %s\",visible,ptr->desc);",
" }",
" }",
"",
" addstr(\"\\n\\n\\t\"); /* tab out so it looks nice */",
" refresh();",
"",
" for(;;)",
" {",
" int i, nval;",
"",
" getstr(buf);",
"",
" /* numeric choice? */",
" nval = atoi(buf);",
"",
" /* command choice ? */",
" i = 0;",
" for(ptr = items; ptr->desc != 0; ptr++) {",
" if(ptr->attribute != VISIBLE)",
" continue;",
" i++;",
" if(nval == i)",
" break;",
" if(!casecmp(buf, ptr->cmd))",
" break;",
" }",
"",
" if(!ptr->desc)",
" continue; /* no match */",
"",
" switch(ptr->action)",
" {",
" case QUIT:",
" exit(0);",
" case IGNORE:",
" refresh();",
" break;",
" case EXECUTE:",
" refresh();",
" system(ptr->act_str);",
" break;",
" case MENU:",
" refresh();",
" (*ptr->act_menu)();",
" break;",
" default:",
" printw(\"default case, no action\\n\");",
" refresh();",
" break;",
" }",
" refresh();",
" }",
"}",
"",
"int casecmp(char *p, char *q)",
"{",
" int pc, qc;",
"",
" for(; *p != 0; p++, q++) {",
" pc = tolower(*p);",
" qc = tolower(*q);",
"",
" if(pc != qc)",
" break;",
" }",
" return pc-qc;",
"}",
0
};