This source file includes following definitions.
- main
- Usage
- j_menu
- j_checklist
- j_radiolist
- j_textbox
- j_yesno
- j_inputbox
- j_msgbox
- j_infobox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include "dialog.h"
23
24 static void Usage (const char *name);
25
26 typedef int (jumperFn) (const char *title, int argc, const char * const * argv);
27
28 struct Mode {
29 char *name;
30 int argmin, argmax, argmod;
31 jumperFn *jumper;
32 };
33
34 jumperFn j_menu, j_checklist, j_radiolist, j_yesno, j_textbox, j_inputbox;
35 jumperFn j_msgbox, j_infobox;
36
37 static struct Mode modes[] =
38 {
39 {"--menu", 9, 0, 3, j_menu},
40 {"--checklist", 9, 0, 3, j_checklist},
41 {"--radiolist", 9, 0, 3, j_radiolist},
42 {"--yesno", 5,5,1, j_yesno},
43 {"--textbox", 5,5,1, j_textbox},
44 {"--inputbox", 5, 6, 1, j_inputbox},
45 {"--msgbox", 5, 5, 1, j_msgbox},
46 {"--infobox", 5, 5, 1, j_infobox},
47 {NULL, 0, 0, 0, NULL}
48 };
49
50 static struct Mode *modePtr;
51
52 #ifdef LOCALE
53 #include <locale.h>
54 #endif
55
56 int
57 main (int argc, const char * const * argv)
58 {
59 int offset = 0, clear_screen = 0, end_common_opts = 0, retval;
60 const char *title = NULL;
61
62 #ifdef LOCALE
63 (void) setlocale (LC_ALL, "");
64 #endif
65
66 if (argc < 2) {
67 Usage (argv[0]);
68 exit (-1);
69 }
70
71 while (offset < argc - 1 && !end_common_opts) {
72 if (!strcmp (argv[offset + 1], "--title")) {
73 if (argc - offset < 3 || title != NULL) {
74 Usage (argv[0]);
75 exit (-1);
76 } else {
77 title = argv[offset + 2];
78 offset += 2;
79 }
80 } else if (!strcmp (argv[offset + 1], "--backtitle")) {
81 if (backtitle != NULL) {
82 Usage (argv[0]);
83 exit (-1);
84 } else {
85 backtitle = argv[offset + 2];
86 offset += 2;
87 }
88 } else if (!strcmp (argv[offset + 1], "--clear")) {
89 if (clear_screen) {
90 Usage (argv[0]);
91 exit (-1);
92 } else if (argc == 2) {
93 init_dialog ();
94 refresh ();
95 end_dialog ();
96 return 0;
97 } else {
98 clear_screen = 1;
99 offset++;
100 }
101 } else
102 end_common_opts = 1;
103 }
104
105 if (argc - 1 == offset) {
106 Usage (argv[0]);
107 exit (-1);
108 }
109
110
111 for (modePtr = modes; modePtr->name; modePtr++)
112 if (!strcmp (argv[offset + 1], modePtr->name))
113 break;
114
115 if (!modePtr->name)
116 Usage (argv[0]);
117 if (argc - offset < modePtr->argmin)
118 Usage (argv[0]);
119 if (modePtr->argmax && argc - offset > modePtr->argmax)
120 Usage (argv[0]);
121
122
123
124 init_dialog ();
125 retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset);
126
127 if (clear_screen) {
128 attr_clear (stdscr, LINES, COLS, screen_attr);
129 refresh ();
130 }
131 end_dialog();
132
133 exit (retval);
134 }
135
136
137
138
139 static void
140 Usage (const char *name)
141 {
142 fprintf (stderr, "\
143 \ndialog, by Savio Lam (lam836@cs.cuhk.hk).\
144 \n patched by Stuart Herbert (S.Herbert@shef.ac.uk)\
145 \n modified/gutted for use as a Linux kernel config tool by \
146 \n William Roadcap (roadcapw@cfw.com)\
147 \n\
148 \n* Display dialog boxes from shell scripts *\
149 \n\
150 \nUsage: %s --clear\
151 \n %s [--title <title>] [--backtitle <backtitle>] --clear <Box options>\
152 \n\
153 \nBox options:\
154 \n\
155 \n --menu <text> <height> <width> <menu height> <tag1> <item1>...\
156 \n --checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
157 \n --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
158 \n --textbox <file> <height> <width>\
159 \n --inputbox <text> <height> <width> [<init>]\
160 \n --yesno <text> <height> <width>\
161 ", name, name);
162 exit (-1);
163 }
164
165
166
167
168
169 int
170 j_menu (const char *t, int ac, const char * const * av)
171 {
172 return dialog_menu (t, av[2], atoi (av[3]), atoi (av[4]),
173 atoi (av[5]), av[6], (ac - 6) / 2, av + 7);
174 }
175
176 int
177 j_checklist (const char *t, int ac, const char * const * av)
178 {
179 return dialog_checklist (t, av[2], atoi (av[3]), atoi (av[4]),
180 atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_CHECK);
181 }
182
183 int
184 j_radiolist (const char *t, int ac, const char * const * av)
185 {
186 return dialog_checklist (t, av[2], atoi (av[3]), atoi (av[4]),
187 atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_RADIO);
188 }
189
190 int
191 j_textbox (const char *t, int ac, const char * const * av)
192 {
193 return dialog_textbox (t, av[2], atoi (av[3]), atoi (av[4]));
194 }
195
196 int
197 j_yesno (const char *t, int ac, const char * const * av)
198 {
199 return dialog_yesno (t, av[2], atoi (av[3]), atoi (av[4]));
200 }
201
202 int
203 j_inputbox (const char *t, int ac, const char * const * av)
204 {
205 int ret = dialog_inputbox (t, av[2], atoi (av[3]), atoi (av[4]),
206 ac == 6 ? av[5] : (char *) NULL);
207 if (ret == 0)
208 fprintf(stderr, dialog_input_result);
209 return ret;
210 }
211
212 int
213 j_msgbox (const char *t, int ac, const char * const * av)
214 {
215 return dialog_msgbox (t, av[2], atoi (av[3]), atoi (av[4]), 1);
216 }
217
218 int
219 j_infobox (const char *t, int ac, const char * const * av)
220 {
221 return dialog_msgbox (t, av[2], atoi (av[3]), atoi (av[4]), 0);
222 }
223