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