aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lxdialog/lxdialog.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lxdialog/lxdialog.c')
-rw-r--r--scripts/lxdialog/lxdialog.c238
1 files changed, 112 insertions, 126 deletions
diff --git a/scripts/lxdialog/lxdialog.c b/scripts/lxdialog/lxdialog.c
index f283a8545426..2c34ea1e0a41 100644
--- a/scripts/lxdialog/lxdialog.c
+++ b/scripts/lxdialog/lxdialog.c
@@ -21,30 +21,29 @@
21 21
22#include "dialog.h" 22#include "dialog.h"
23 23
24static void Usage (const char *name); 24static void Usage(const char *name);
25 25
26typedef int (jumperFn) (const char *title, int argc, const char * const * argv); 26typedef int (jumperFn) (const char *title, int argc, const char *const *argv);
27 27
28struct Mode { 28struct Mode {
29 char *name; 29 char *name;
30 int argmin, argmax, argmod; 30 int argmin, argmax, argmod;
31 jumperFn *jumper; 31 jumperFn *jumper;
32}; 32};
33 33
34jumperFn j_menu, j_checklist, j_radiolist, j_yesno, j_textbox, j_inputbox; 34jumperFn j_menu, j_checklist, j_radiolist, j_yesno, j_textbox, j_inputbox;
35jumperFn j_msgbox, j_infobox; 35jumperFn j_msgbox, j_infobox;
36 36
37static struct Mode modes[] = 37static struct Mode modes[] = {
38{ 38 {"--menu", 9, 0, 3, j_menu},
39 {"--menu", 9, 0, 3, j_menu}, 39 {"--checklist", 9, 0, 3, j_checklist},
40 {"--checklist", 9, 0, 3, j_checklist}, 40 {"--radiolist", 9, 0, 3, j_radiolist},
41 {"--radiolist", 9, 0, 3, j_radiolist}, 41 {"--yesno", 5, 5, 1, j_yesno},
42 {"--yesno", 5,5,1, j_yesno}, 42 {"--textbox", 5, 5, 1, j_textbox},
43 {"--textbox", 5,5,1, j_textbox}, 43 {"--inputbox", 5, 6, 1, j_inputbox},
44 {"--inputbox", 5, 6, 1, j_inputbox}, 44 {"--msgbox", 5, 5, 1, j_msgbox},
45 {"--msgbox", 5, 5, 1, j_msgbox}, 45 {"--infobox", 5, 5, 1, j_infobox},
46 {"--infobox", 5, 5, 1, j_infobox}, 46 {NULL, 0, 0, 0, NULL}
47 {NULL, 0, 0, 0, NULL}
48}; 47};
49 48
50static struct Mode *modePtr; 49static struct Mode *modePtr;
@@ -53,96 +52,92 @@ static struct Mode *modePtr;
53#include <locale.h> 52#include <locale.h>
54#endif 53#endif
55 54
56int 55int main(int argc, const char *const *argv)
57main (int argc, const char * const * argv)
58{ 56{
59 int offset = 0, opt_clear = 0, end_common_opts = 0, retval; 57 int offset = 0, opt_clear = 0, end_common_opts = 0, retval;
60 const char *title = NULL; 58 const char *title = NULL;
61 59
62#ifdef LOCALE 60#ifdef LOCALE
63 (void) setlocale (LC_ALL, ""); 61 (void)setlocale(LC_ALL, "");
64#endif 62#endif
65 63
66#ifdef TRACE 64#ifdef TRACE
67 trace(TRACE_CALLS|TRACE_UPDATE); 65 trace(TRACE_CALLS | TRACE_UPDATE);
68#endif 66#endif
69 if (argc < 2) { 67 if (argc < 2) {
70 Usage (argv[0]); 68 Usage(argv[0]);
71 exit (-1); 69 exit(-1);
72 } 70 }
73 71
74 while (offset < argc - 1 && !end_common_opts) { /* Common options */ 72 while (offset < argc - 1 && !end_common_opts) { /* Common options */
75 if (!strcmp (argv[offset + 1], "--title")) { 73 if (!strcmp(argv[offset + 1], "--title")) {
76 if (argc - offset < 3 || title != NULL) { 74 if (argc - offset < 3 || title != NULL) {
77 Usage (argv[0]); 75 Usage(argv[0]);
78 exit (-1); 76 exit(-1);
79 } else { 77 } else {
80 title = argv[offset + 2]; 78 title = argv[offset + 2];
81 offset += 2; 79 offset += 2;
82 } 80 }
83 } else if (!strcmp (argv[offset + 1], "--backtitle")) { 81 } else if (!strcmp(argv[offset + 1], "--backtitle")) {
84 if (backtitle != NULL) { 82 if (backtitle != NULL) {
85 Usage (argv[0]); 83 Usage(argv[0]);
86 exit (-1); 84 exit(-1);
87 } else { 85 } else {
88 backtitle = argv[offset + 2]; 86 backtitle = argv[offset + 2];
89 offset += 2; 87 offset += 2;
90 } 88 }
91 } else if (!strcmp (argv[offset + 1], "--clear")) { 89 } else if (!strcmp(argv[offset + 1], "--clear")) {
92 if (opt_clear) { /* Hey, "--clear" can't appear twice! */ 90 if (opt_clear) { /* Hey, "--clear" can't appear twice! */
93 Usage (argv[0]); 91 Usage(argv[0]);
94 exit (-1); 92 exit(-1);
95 } else if (argc == 2) { /* we only want to clear the screen */ 93 } else if (argc == 2) { /* we only want to clear the screen */
96 init_dialog (); 94 init_dialog();
97 refresh (); /* init_dialog() will clear the screen for us */ 95 refresh(); /* init_dialog() will clear the screen for us */
98 end_dialog (); 96 end_dialog();
99 return 0; 97 return 0;
100 } else { 98 } else {
101 opt_clear = 1; 99 opt_clear = 1;
102 offset++; 100 offset++;
103 } 101 }
104 } else /* no more common options */ 102 } else /* no more common options */
105 end_common_opts = 1; 103 end_common_opts = 1;
106 } 104 }
107 105
108 if (argc - 1 == offset) { /* no more options */ 106 if (argc - 1 == offset) { /* no more options */
109 Usage (argv[0]); 107 Usage(argv[0]);
110 exit (-1); 108 exit(-1);
111 } 109 }
112 /* use a table to look for the requested mode, to avoid code duplication */ 110 /* use a table to look for the requested mode, to avoid code duplication */
113 111
114 for (modePtr = modes; modePtr->name; modePtr++) /* look for the mode */ 112 for (modePtr = modes; modePtr->name; modePtr++) /* look for the mode */
115 if (!strcmp (argv[offset + 1], modePtr->name)) 113 if (!strcmp(argv[offset + 1], modePtr->name))
116 break; 114 break;
117 115
118 if (!modePtr->name) 116 if (!modePtr->name)
119 Usage (argv[0]); 117 Usage(argv[0]);
120 if (argc - offset < modePtr->argmin) 118 if (argc - offset < modePtr->argmin)
121 Usage (argv[0]); 119 Usage(argv[0]);
122 if (modePtr->argmax && argc - offset > modePtr->argmax) 120 if (modePtr->argmax && argc - offset > modePtr->argmax)
123 Usage (argv[0]); 121 Usage(argv[0]);
124 122
125 123 init_dialog();
126 124 retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset);
127 init_dialog (); 125
128 retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset); 126 if (opt_clear) { /* clear screen before exit */
129 127 attr_clear(stdscr, LINES, COLS, screen_attr);
130 if (opt_clear) { /* clear screen before exit */ 128 refresh();
131 attr_clear (stdscr, LINES, COLS, screen_attr); 129 }
132 refresh (); 130 end_dialog();
133 } 131
134 end_dialog(); 132 exit(retval);
135
136 exit (retval);
137} 133}
138 134
139/* 135/*
140 * Print program usage 136 * Print program usage
141 */ 137 */
142static void 138static void Usage(const char *name)
143Usage (const char *name)
144{ 139{
145 fprintf (stderr, "\ 140 fprintf(stderr, "\
146\ndialog, by Savio Lam (lam836@cs.cuhk.hk).\ 141\ndialog, by Savio Lam (lam836@cs.cuhk.hk).\
147\n patched by Stuart Herbert (S.Herbert@shef.ac.uk)\ 142\n patched by Stuart Herbert (S.Herbert@shef.ac.uk)\
148\n modified/gutted for use as a Linux kernel config tool by \ 143\n modified/gutted for use as a Linux kernel config tool by \
@@ -162,65 +157,56 @@ Usage (const char *name)
162\n --inputbox <text> <height> <width> [<init>]\ 157\n --inputbox <text> <height> <width> [<init>]\
163\n --yesno <text> <height> <width>\ 158\n --yesno <text> <height> <width>\
164\n", name, name); 159\n", name, name);
165 exit (-1); 160 exit(-1);
166} 161}
167 162
168/* 163/*
169 * These are the program jumpers 164 * These are the program jumpers
170 */ 165 */
171 166
172int 167int j_menu(const char *t, int ac, const char *const *av)
173j_menu (const char *t, int ac, const char * const * av)
174{ 168{
175 return dialog_menu (t, av[2], atoi (av[3]), atoi (av[4]), 169 return dialog_menu(t, av[2], atoi(av[3]), atoi(av[4]),
176 atoi (av[5]), av[6], (ac - 6) / 2, av + 7); 170 atoi(av[5]), av[6], (ac - 6) / 2, av + 7);
177} 171}
178 172
179int 173int j_checklist(const char *t, int ac, const char *const *av)
180j_checklist (const char *t, int ac, const char * const * av)
181{ 174{
182 return dialog_checklist (t, av[2], atoi (av[3]), atoi (av[4]), 175 return dialog_checklist(t, av[2], atoi(av[3]), atoi(av[4]),
183 atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_CHECK); 176 atoi(av[5]), (ac - 6) / 3, av + 6, FLAG_CHECK);
184} 177}
185 178
186int 179int j_radiolist(const char *t, int ac, const char *const *av)
187j_radiolist (const char *t, int ac, const char * const * av)
188{ 180{
189 return dialog_checklist (t, av[2], atoi (av[3]), atoi (av[4]), 181 return dialog_checklist(t, av[2], atoi(av[3]), atoi(av[4]),
190 atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_RADIO); 182 atoi(av[5]), (ac - 6) / 3, av + 6, FLAG_RADIO);
191} 183}
192 184
193int 185int j_textbox(const char *t, int ac, const char *const *av)
194j_textbox (const char *t, int ac, const char * const * av)
195{ 186{
196 return dialog_textbox (t, av[2], atoi (av[3]), atoi (av[4])); 187 return dialog_textbox(t, av[2], atoi(av[3]), atoi(av[4]));
197} 188}
198 189
199int 190int j_yesno(const char *t, int ac, const char *const *av)
200j_yesno (const char *t, int ac, const char * const * av)
201{ 191{
202 return dialog_yesno (t, av[2], atoi (av[3]), atoi (av[4])); 192 return dialog_yesno(t, av[2], atoi(av[3]), atoi(av[4]));
203} 193}
204 194
205int 195int j_inputbox(const char *t, int ac, const char *const *av)
206j_inputbox (const char *t, int ac, const char * const * av)
207{ 196{
208 int ret = dialog_inputbox (t, av[2], atoi (av[3]), atoi (av[4]), 197 int ret = dialog_inputbox(t, av[2], atoi(av[3]), atoi(av[4]),
209 ac == 6 ? av[5] : (char *) NULL); 198 ac == 6 ? av[5] : (char *)NULL);
210 if (ret == 0) 199 if (ret == 0)
211 fprintf(stderr, dialog_input_result); 200 fprintf(stderr, dialog_input_result);
212 return ret; 201 return ret;
213} 202}
214 203
215int 204int j_msgbox(const char *t, int ac, const char *const *av)
216j_msgbox (const char *t, int ac, const char * const * av)
217{ 205{
218 return dialog_msgbox (t, av[2], atoi (av[3]), atoi (av[4]), 1); 206 return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 1);
219} 207}
220 208
221int 209int j_infobox(const char *t, int ac, const char *const *av)
222j_infobox (const char *t, int ac, const char * const * av)
223{ 210{
224 return dialog_msgbox (t, av[2], atoi (av[3]), atoi (av[4]), 0); 211 return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 0);
225} 212}
226