]> git.ipfire.org Git - thirdparty/newt.git/blame - whiptail.c
install python modules to purelib and platlib
[thirdparty/newt.git] / whiptail.c
CommitLineData
feef2cb5 1#include "config.h"
9be6d60e 2#include <fcntl.h>
6c049389 3#include <popt.h>
9be6d60e 4#include <stdio.h>
5#include <string.h>
6#include <stdlib.h>
feef2cb5 7#include <signal.h>
9be6d60e 8#include <unistd.h>
feef2cb5 9#include <wchar.h>
10#include <slang.h>
83fe9fde 11#include <sys/stat.h>
9be6d60e 12
feef2cb5 13#include "nls.h"
649a0152 14#include "dialogboxes.h"
9be6d60e 15#include "newt.h"
feef2cb5 16#include "newt_pr.h"
17
18enum { NO_ERROR = 0, WAS_ERROR = 1 };
9be6d60e 19
139f06bc 20enum mode { MODE_NONE, MODE_INFOBOX, MODE_MSGBOX, MODE_YESNO, MODE_CHECKLIST,
feef2cb5 21 MODE_INPUTBOX, MODE_RADIOLIST, MODE_MENU, MODE_GAUGE ,
22 MODE_TEXTBOX, MODE_PASSWORDBOX};
9be6d60e 23
6f481af2 24#define OPT_MSGBOX 1000
25#define OPT_CHECKLIST 1001
26#define OPT_YESNO 1002
27#define OPT_INPUTBOX 1003
28#define OPT_FULLBUTTONS 1004
29#define OPT_MENU 1005
30#define OPT_RADIOLIST 1006
31#define OPT_GAUGE 1007
32#define OPT_INFOBOX 1008
feef2cb5 33#define OPT_TEXTBOX 1009
34#define OPT_PASSWORDBOX 1010
35
36static void usage(int err) {
37 newtFinished();
38 fprintf (err ? stderr : stdout,
39 _("Box options: \n"
40 "\t--msgbox <text> <height> <width>\n"
41 "\t--yesno <text> <height> <width>\n"
42 "\t--infobox <text> <height> <width>\n"
43 "\t--inputbox <text> <height> <width> [init] \n"
44 "\t--passwordbox <text> <height> <width> [init] \n"
45 "\t--textbox <file> <height> <width>\n"
46 "\t--menu <text> <height> <width> <listheight> [tag item] ...\n"
47 "\t--checklist <text> <height> <width> <listheight> [tag item status]...\n"
30cfd38a 48 "\t--radiolist <text> <height> <width> <listheight> [tag item status]...\n"
feef2cb5 49 "\t--gauge <text> <height> <width> <percent>\n"
50 "Options: (depend on box-option)\n"
51 "\t--clear clear screen on exit\n"
45bffa7f 52 "\t--defaultno default no button\n"
feef2cb5 53 "\t--default-item <string> set default string\n"
6c7007a6 54 "\t--fb, --fullbuttons use full buttons\n"
feef2cb5 55 "\t--nocancel no cancel button\n"
60d3c50b 56 "\t--yes-button <text> set text of yes button\n"
57 "\t--no-button <text> set text of no button\n"
58 "\t--ok-button <text> set text of ok button\n"
59 "\t--cancel-button <text> set text of cancel button\n"
6c7007a6
ML
60 "\t--noitem don't display items\n"
61 "\t--notags don't display tags\n"
f0e9344a 62 "\t--separate-output output one line at a time\n"
feef2cb5 63 "\t--output-fd <fd> output to fd, not stdout\n"
64 "\t--title <title> display title\n"
65 "\t--backtitle <backtitle> display backtitle\n"
c3a3b1e8 66 "\t--scrolltext force vertical scrollbars\n"
6c7007a6
ML
67 "\t--topleft put window in top-left corner\n"
68 "\t-h, --help print this message\n"
69 "\t-v, --version print version information\n\n"));
feef2cb5 70 exit(err ? DLG_ERROR : 0 );
71}
72
73static void print_version(void) {
74 fprintf (stdout, _("whiptail (newt): %s\n"), VERSION);
75}
76
feef2cb5 77#if 0
78/* FIXME Copied from newt.c
79 * Place somewhere better -- dialogboxes? -- amck
80 */
81int wstrlen(const char *str, int len) {
82 mbstate_t ps;
83 wchar_t tmp;
84 int nchars = 0;
85
86 if (!str) return 0;
87 if (!len) return 0;
88 if (len < 0) len = strlen(str);
89 memset(&ps,0,sizeof(mbstate_t));
90 while (len > 0) {
91 int x,y;
92
93 x = mbrtowc(&tmp,str,len,&ps);
94 if (x >0) {
95 str += x;
96 len -= x;
97 y = wcwidth(tmp);
98 if (y>0)
99 nchars+=y;
100 } else break;
101 }
102 return nchars;
103}
104#endif
105
106/*
107 * The value of *width is increased if it is not as large as the width of
108 * the line.
109 */
110static const char * lineWidth(int * width, const char * line, int *chrs)
111{
112 const char * s = line;
113
114 if ( line == NULL )
115 return 0;
116
117 while ( *s != '\0' && *s != '\n' )
118 s++;
119
120 if ( *s == '\n' )
121 s++;
122
123 *chrs = _newt_wstrlen (line, s - line );
124 *width = max(*width, *chrs);
9be6d60e 125
feef2cb5 126 return s;
127}
128
129
130/*
131 * cleanNewlines
132 * Handle newlines in text. Hack.
133 */
134void cleanNewlines (char *text)
135{
ba84e71b
ML
136 char *p, *q;
137
138 for (p = q = text; *p; p++, q++)
139 if (*p == '\\' && p[1] == 'n') {
140 p++;
141 *q = '\n';
142 } else
143 *q = *p;
144 *q = '\0';
feef2cb5 145}
146
147/*
148 * The height of a text string is added to height, and width is increased
149 * if it is not big enough to store the text string.
150 */
151static const char * textSize(int * height, int * width,
152 int maxWidth,
153 const char * text)
154{
155 int h = 0;
156 int w = 0;
157 int chrs = 0;
158
159
160 if ( text == NULL )
161 return 0;
162
163 while ( *text != '\0' ) {
164 h++;
165 text = lineWidth(width, text, &chrs);
166 /* Allow for text overflowing. May overestimate a bit */
167 h += chrs / maxWidth;
168 }
169
170 h += 2;
171 w += 2;
172
173 *height += h;
174 *width += w;
175
176 *width = min(*width, maxWidth);
177 return text;
178}
179
180/*
181 * Add space for buttons.
182 * NOTE: when this is internationalized, the button width might change.
183 */
184static void spaceForButtons(int * height, int * width, int count, int full) {
185 /* Make space for the buttons */
186 if ( full ) {
187 *height += 4;
188 if ( count == 1 )
189 *width = max(*width, 7);
190 else
191 *width = max(*width, 20);
192 }
193 else {
194 *height += 2;
195 if ( count == 1 )
196 *width = max(*width, 7);
197 else
198 *width = max(*width, 19);
199 }
200}
201
9c4eb622 202static int menuSize(int * height, int * width, int * listHeight,
6d4088f9 203 enum mode mode, int * flags, poptContext options) {
c00a8d1b 204 const char ** argv = poptGetArgs(options);
feef2cb5 205 int h = 0;
206 int tagWidth = 0;
207 int descriptionWidth = 0;
208 int overhead = 10;
feef2cb5 209
210 if ( argv == 0 || *argv == 0 )
211 return 0;
212
feef2cb5 213 if ( mode == MODE_MENU )
214 overhead = 5;
215
216 while ( argv[0] != 0 && argv[1] ) {
ce98a323
ML
217 tagWidth = max(tagWidth, _newt_wstrlen(argv[0], -1));
218 descriptionWidth = max(descriptionWidth, _newt_wstrlen(argv[1], -1));
feef2cb5 219
6d4088f9 220 if (mode == MODE_MENU || *flags & FLAG_NOITEM)
feef2cb5 221 argv += 2;
222 else
223 argv += 3;
224 h++;
225 }
226
6d4088f9
ML
227 if (*flags & FLAG_NOTAGS) {
228 tagWidth = 0;
229 overhead -= mode == MODE_MENU ? 1 : 2;
230 }
231 if (*flags & FLAG_NOITEM) {
232 descriptionWidth = 0;
233 }
234
feef2cb5 235 *width = max(*width, tagWidth + descriptionWidth + overhead);
236 *width = min(*width, SLtt_Screen_Cols);
237
238 h = min(h, SLtt_Screen_Rows - *height - 4);
239 *height = *height + h + 1;
9c4eb622 240 *listHeight = h;
feef2cb5 241 return 0;
242}
243
244/*
245 * Guess the size of a window, given what will be displayed within it.
246 */
9c4eb622
ML
247static void guessSize(int * height, int * width, int * listHeight,
248 enum mode mode, int * flags, int fullButtons,
feef2cb5 249 const char * title, const char * text,
250 poptContext options) {
251
252 int w = 0, h = 0, chrs = 0;
253
254 textSize(&h, &w, SLtt_Screen_Cols -4 , text); /* Width and height for text */
255 lineWidth(&w, title, &chrs); /* Width for title */
256
257 if ( w > 0 )
258 w += 4;
259
260 switch ( mode ) {
261 case MODE_CHECKLIST:
262 case MODE_RADIOLIST:
263 case MODE_MENU:
264 spaceForButtons(&h, &w, *flags & FLAG_NOCANCEL ? 1 : 2,
265 fullButtons);
6d4088f9 266 menuSize(&h, &w, listHeight, mode, flags, options);
feef2cb5 267 break;
268 case MODE_YESNO:
b2a4d901
ML
269 spaceForButtons(&h, &w, 2, fullButtons);
270 break;
feef2cb5 271 case MODE_MSGBOX:
272 spaceForButtons(&h, &w, 1, fullButtons);
273 break;
274 case MODE_INPUTBOX:
275 spaceForButtons(&h, &w, *flags & FLAG_NOCANCEL ? 1 : 2,
276 fullButtons);
277 h += 1;
278 break;
279 case MODE_GAUGE:
280 h += 2;
281 break;
282 case MODE_NONE:
283 break;
284 default:
285 break;
286 };
287
288 /*
289 * Fixed window-border overhead.
290 * NOTE: This will change if we add a way to turn off drop-shadow and/or
291 * box borders. That would be desirable for display-sized screens.
292 */
293 w += 2;
294 h += 2;
295
296 if ( h > SLtt_Screen_Rows - 1 ) {
297 h = SLtt_Screen_Rows - 1;
298 *flags |= FLAG_SCROLL_TEXT;
299 w += 2; /* Add width of slider - is this right? */
300 }
301
302 *width = min(max(*width, w), SLtt_Screen_Cols);
303 *height = max(*height, h);
9be6d60e 304}
305
585f5503 306char *
307readTextFile(const char * filename)
308{
309 int fd = open(filename, O_RDONLY, 0);
310 struct stat s;
311 char * buf;
312
313 if ( fd < 0 || fstat(fd, &s) != 0 ) {
314 perror(filename);
315 exit(DLG_ERROR);
316 }
317
3341bdc5 318 if ( (buf = malloc(s.st_size + 1)) == 0 ) {
feef2cb5 319 fprintf(stderr, _("%s: too large to display.\n"), filename);
3341bdc5
ML
320 exit(DLG_ERROR);
321 }
585f5503 322
323 if ( read(fd, buf, s.st_size) != s.st_size ) {
324 perror(filename);
325 exit(DLG_ERROR);
326 }
327 close(fd);
659af8f0 328 buf[s.st_size] = '\0';
585f5503 329 return buf;
330}
331
eb0a0545 332int main(int argc, const char ** argv) {
9be6d60e 333 enum mode mode = MODE_NONE;
334 poptContext optCon;
335 int arg;
feef2cb5 336 char * text;
eb0a0545 337 const char * nextArg;
9be6d60e 338 char * end;
339 int height;
340 int width;
bb5f279b 341 int listHeight = 1;
649a0152 342 int fd = -1;
343 int needSpace = 0;
9be6d60e 344 int noCancel = 0;
57cb49e7 345 int noTags = 0;
9be6d60e 346 int noItem = 0;
347 int clear = 0;
348 int scrollText = 0;
feef2cb5 349 int rc = DLG_CANCEL;
9be6d60e 350 int flags = 0;
ff3d94b9 351 int defaultNo = 0;
9be6d60e 352 int separateOutput = 0;
feef2cb5 353 int fullButtons = 0;
9623bfae 354 int outputfd = 2;
45bffa7f 355 int topLeft = 0;
638f672c 356 FILE *output;
f40f18ae
ML
357 char * result;
358 char ** selections, ** next;
9be6d60e 359 char * title = NULL;
feef2cb5 360 char *default_item = NULL;
9be6d60e 361 char * backtitle = NULL;
60d3c50b 362 char * yes_button = NULL;
363 char * no_button = NULL;
364 char * ok_button = NULL;
365 char * cancel_button = NULL;
feef2cb5 366 int help = 0, version = 0;
9be6d60e 367 struct poptOption optionsTable[] = {
6f481af2 368 { "backtitle", '\0', POPT_ARG_STRING, &backtitle, 0 },
369 { "checklist", '\0', 0, 0, OPT_CHECKLIST },
370 { "clear", '\0', 0, &clear, 0 },
371 { "defaultno", '\0', 0, &defaultNo, 0 },
372 { "inputbox", '\0', 0, 0, OPT_INPUTBOX },
373 { "fb", '\0', 0, 0, OPT_FULLBUTTONS },
374 { "fullbuttons", '\0', 0, 0, OPT_FULLBUTTONS },
375 { "gauge", '\0', 0, 0, OPT_GAUGE },
376 { "infobox", '\0', 0, 0, OPT_INFOBOX },
377 { "menu", '\0', 0, 0, OPT_MENU },
378 { "msgbox", '\0', 0, 0, OPT_MSGBOX },
379 { "nocancel", '\0', 0, &noCancel, 0 },
380 { "noitem", '\0', 0, &noItem, 0 },
feef2cb5 381 { "default-item", '\0', POPT_ARG_STRING, &default_item, 0},
6f481af2 382 { "notags", '\0', 0, &noTags, 0 },
383 { "radiolist", '\0', 0, 0, OPT_RADIOLIST },
384 { "scrolltext", '\0', 0, &scrollText, 0 },
385 { "separate-output", '\0', 0, &separateOutput, 0 },
386 { "title", '\0', POPT_ARG_STRING, &title, 0 },
6f481af2 387 { "textbox", '\0', 0, 0, OPT_TEXTBOX },
45bffa7f 388 { "topleft", '\0', 0, &topLeft, 0 },
feef2cb5 389 { "yesno", '\0', 0, 0, OPT_YESNO },
390 { "passwordbox", '\0', 0, 0, OPT_PASSWORDBOX },
391 { "output-fd", '\0', POPT_ARG_INT, &outputfd, 0 },
60d3c50b 392 { "yes-button", '\0', POPT_ARG_STRING, &yes_button, 0},
393 { "no-button", '\0', POPT_ARG_STRING, &no_button, 0},
394 { "ok-button", '\0', POPT_ARG_STRING, &ok_button, 0},
395 { "cancel-button", '\0', POPT_ARG_STRING, &cancel_button, 0},
feef2cb5 396 { "help", 'h', 0, &help, 0, NULL, NULL },
397 { "version", 'v', 0, &version, 0, NULL, NULL },
6f481af2 398 { 0, 0, 0, 0, 0 }
9be6d60e 399 };
feef2cb5 400
970ce9d5 401#ifdef ENABLE_NLS
feef2cb5 402 setlocale (LC_ALL, "");
403 bindtextdomain (PACKAGE, LOCALEDIR);
404 textdomain (PACKAGE);
970ce9d5 405#endif
feef2cb5 406
649a0152 407 optCon = poptGetContext("whiptail", argc, argv, optionsTable, 0);
9be6d60e 408
409 while ((arg = poptGetNextOpt(optCon)) > 0) {
6f481af2 410 switch (arg) {
411 case OPT_INFOBOX:
feef2cb5 412 if (mode != MODE_NONE) usage(WAS_ERROR);
6f481af2 413 mode = MODE_INFOBOX;
414 break;
415
416 case OPT_MENU:
feef2cb5 417 if (mode != MODE_NONE) usage(WAS_ERROR);
6f481af2 418 mode = MODE_MENU;
419 break;
420
421 case OPT_MSGBOX:
feef2cb5 422 if (mode != MODE_NONE) usage(WAS_ERROR);
6f481af2 423 mode = MODE_MSGBOX;
424 break;
feef2cb5 425
426 case OPT_TEXTBOX:
427 if (mode != MODE_NONE) usage(WAS_ERROR);
428 mode = MODE_TEXTBOX;
429 break;
430
431 case OPT_PASSWORDBOX:
432 if (mode != MODE_NONE) usage(WAS_ERROR);
433 mode = MODE_PASSWORDBOX;
434 break;
435
6f481af2 436 case OPT_RADIOLIST:
feef2cb5 437 if (mode != MODE_NONE) usage(WAS_ERROR);
6f481af2 438 mode = MODE_RADIOLIST;
439 break;
440
441 case OPT_CHECKLIST:
feef2cb5 442 if (mode != MODE_NONE) usage(WAS_ERROR);
6f481af2 443 mode = MODE_CHECKLIST;
444 break;
445
446 case OPT_FULLBUTTONS:
feef2cb5 447 fullButtons = 1;
6f481af2 448 useFullButtons(1);
449 break;
450
451 case OPT_YESNO:
feef2cb5 452 if (mode != MODE_NONE) usage(WAS_ERROR);
6f481af2 453 mode = MODE_YESNO;
454 break;
455
456 case OPT_GAUGE:
feef2cb5 457 if (mode != MODE_NONE) usage(WAS_ERROR);
6f481af2 458 mode = MODE_GAUGE;
459 break;
460
461 case OPT_INPUTBOX:
feef2cb5 462 if (mode != MODE_NONE) usage(WAS_ERROR);
6f481af2 463 mode = MODE_INPUTBOX;
464 break;
465 }
9be6d60e 466 }
467
feef2cb5 468 if (help) {
469 usage(NO_ERROR);
470 exit(0);
471 }
472 if (version) {
473 print_version();
474 exit(0);
475 }
476
9be6d60e 477 if (arg < -1) {
6f481af2 478 fprintf(stderr, "%s: %s\n",
479 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
480 poptStrerror(arg));
481 exit(1);
9be6d60e 482 }
483
9623bfae 484 output = fdopen (outputfd, "w");
485 if (output == NULL ) {
486 perror ("Cannot open output-fd\n");
487 exit (DLG_ERROR);
488 }
489
feef2cb5 490 if (mode == MODE_NONE) usage(WAS_ERROR);
9be6d60e 491
c00a8d1b 492 if (!(nextArg = poptGetArg(optCon))) usage(WAS_ERROR);
493 text = strdup(nextArg);
9be6d60e 494
3341bdc5
ML
495 if (mode == MODE_TEXTBOX) {
496 char *t = text;
497 text = readTextFile(t);
498 free(t);
499 }
585f5503 500
feef2cb5 501 if (!(nextArg = poptGetArg(optCon))) usage(WAS_ERROR);
9be6d60e 502 height = strtoul(nextArg, &end, 10);
feef2cb5 503 if (*end) usage(WAS_ERROR);
9be6d60e 504
feef2cb5 505 if (!(nextArg = poptGetArg(optCon))) usage(WAS_ERROR);
9be6d60e 506 width = strtoul(nextArg, &end, 10);
feef2cb5 507 if (*end) usage(WAS_ERROR);
9be6d60e 508
9c4eb622
ML
509 switch (mode) {
510 case MODE_MENU:
511 case MODE_RADIOLIST:
512 case MODE_CHECKLIST:
513 if (!(nextArg = poptGetArg(optCon))) usage(WAS_ERROR);
514 listHeight = strtoul(nextArg, &end, 10);
515 if (*end) usage(WAS_ERROR);
516 break;
517
518 case MODE_GAUGE:
6f481af2 519 fd = dup(0);
3341bdc5
ML
520 if (fd < 0 || close(0) < 0) {
521 perror("dup/close stdin");
522 exit(DLG_ERROR);
523 }
524 if (open("/dev/tty", O_RDWR) != 0) {
525 perror("open /dev/tty");
526 exit(DLG_ERROR);
527 }
9c4eb622 528 break;
d55511bc
ML
529 default:
530 break;
9be6d60e 531 }
532
6d4088f9
ML
533 if (noCancel) flags |= FLAG_NOCANCEL;
534 if (noItem) flags |= FLAG_NOITEM;
535 if (noTags) flags |= FLAG_NOTAGS;
536 if (scrollText) flags |= FLAG_SCROLL_TEXT;
537 if (defaultNo) flags |= FLAG_DEFAULT_NO;
538
9be6d60e 539 newtInit();
540 newtCls();
feef2cb5 541
542 cleanNewlines(text);
543
73bb4086 544 if (height <= 0 || width <= 0 || listHeight <= 0) {
9c4eb622
ML
545 guessSize(&height, &width, &listHeight, mode, &flags, fullButtons,
546 title, text, optCon);
73bb4086
ML
547 if (!topLeft && backtitle && SLtt_Screen_Rows > 10 &&
548 height + 1 == SLtt_Screen_Rows &&
549 _newt_wstrlen(backtitle, -1) > (SLtt_Screen_Cols - width) / 2) {
550 height -= 1;
551 listHeight -= 1;
552 }
553 }
feef2cb5 554
9be6d60e 555 width -= 2;
556 height -= 2;
9be6d60e 557
45bffa7f 558 newtOpenWindow(topLeft ? 1 : (SLtt_Screen_Cols - width) / 2,
559 topLeft ? 1 : (SLtt_Screen_Rows - height) / 2, width, height, title);
9be6d60e 560 if (backtitle)
6f481af2 561 newtDrawRootText(0, 0, backtitle);
9be6d60e 562
60d3c50b 563 if (ok_button)
564 setButtonText(ok_button, BUTTON_OK);
565 if (cancel_button)
566 setButtonText(cancel_button, BUTTON_CANCEL);
567 if (yes_button)
568 setButtonText(yes_button, BUTTON_YES);
569 if (no_button)
570 setButtonText(no_button, BUTTON_NO);
571
9be6d60e 572 switch (mode) {
573 case MODE_MSGBOX:
585f5503 574 case MODE_TEXTBOX:
6f481af2 575 rc = messageBox(text, height, width, MSGBOX_MSG, flags);
576 break;
9be6d60e 577
139f06bc 578 case MODE_INFOBOX:
6f481af2 579 rc = messageBox(text, height, width, MSGBOX_INFO, flags);
580 break;
139f06bc 581
9be6d60e 582 case MODE_YESNO:
6f481af2 583 rc = messageBox(text, height, width, MSGBOX_YESNO, flags);
584 break;
9be6d60e 585
586 case MODE_INPUTBOX:
6f481af2 587 rc = inputBox(text, height, width, optCon, flags, &result);
f40f18ae
ML
588 if (rc == DLG_OKAY) {
589 fprintf(output, "%s", result);
590 free(result);
591 }
feef2cb5 592 break;
593
594 case MODE_PASSWORDBOX:
595 rc = inputBox(text, height, width, optCon, flags | FLAG_PASSWORD,
596 &result);
f40f18ae
ML
597 if (rc == DLG_OKAY) {
598 fprintf (output, "%s", result);
599 free(result);
600 }
6f481af2 601 break;
9be6d60e 602
603 case MODE_MENU:
9c4eb622 604 rc = listBox(text, height, width, listHeight, optCon, flags, default_item, &result);
f40f18ae
ML
605 if (rc == DLG_OKAY) {
606 fprintf(output, "%s", result);
607 free(result);
608 }
6f481af2 609 break;
9be6d60e 610
611 case MODE_RADIOLIST:
9c4eb622 612 rc = checkList(text, height, width, listHeight, optCon, 1, flags, &selections);
f40f18ae
ML
613 if (rc == DLG_OKAY && selections[0]) {
614 fprintf(output, "%s", selections[0]);
615 free(selections[0]);
6f481af2 616 free(selections);
617 }
618 break;
9be6d60e 619
620 case MODE_CHECKLIST:
9c4eb622 621 rc = checkList(text, height, width, listHeight, optCon, 0, flags, &selections);
6f481af2 622
623 if (!rc) {
624 for (next = selections; *next; next++) {
625 if (!separateOutput) {
626 if (needSpace) putc(' ', output);
627 fprintf(output, "\"%s\"", *next);
628 needSpace = 1;
629 } else {
630 fprintf(output, "%s\n", *next);
631 }
f40f18ae 632 free(*next);
6f481af2 633 }
634
635 free(selections);
636 }
637 break;
9be6d60e 638
639 case MODE_GAUGE:
6f481af2 640 rc = gauge(text, height, width, optCon, fd, flags);
641 break;
9be6d60e 642
643 default:
feef2cb5 644 usage(WAS_ERROR);
9be6d60e 645 }
646
feef2cb5 647 if (rc == DLG_ERROR) usage(WAS_ERROR);
649a0152 648
9be6d60e 649 if (clear)
6f481af2 650 newtPopWindow();
9be6d60e 651 newtFinished();
652
3341bdc5
ML
653 free(text);
654 poptFreeContext(optCon);
655
feef2cb5 656 return ( rc == DLG_ESCAPE ) ? -1 : rc;
9be6d60e 657}