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