xref: /freebsd/contrib/dialog/dialog.h (revision 7750ad47a9a7dbc83f87158464170c8640723293)
1 /*
2  *  $Id: dialog.h,v 1.231 2011/06/29 09:51:00 tom Exp $
3  *
4  *  dialog.h -- common declarations for all dialog modules
5  *
6  *  Copyright 2000-2010,2011	Thomas E. Dickey
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU Lesser General Public License, version 2.1
10  *  as published by the Free Software Foundation.
11  *
12  *  This program is distributed in the hope that it will be useful, but
13  *  WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public
18  *  License along with this program; if not, write to
19  *	Free Software Foundation, Inc.
20  *	51 Franklin St., Fifth Floor
21  *	Boston, MA 02110, USA.
22  *
23  *  An earlier version of this program lists as authors
24  *	Savio Lam (lam836@cs.cuhk.hk)
25  */
26 
27 #ifndef DIALOG_H_included
28 #define DIALOG_H_included 1
29 /* *INDENT-OFF* */
30 
31 #include <dlg_config.h>
32 
33 #ifdef __hpux
34 #define __HP_CURSES_COMPAT	/* workaround for getattrs, etc. */
35 #endif
36 
37 #include <sys/types.h>
38 #include <fcntl.h>
39 #include <unistd.h>
40 #include <ctype.h>
41 #include <stdlib.h>
42 #include <stdarg.h>
43 #include <string.h>
44 #include <signal.h>	/* fork() etc. */
45 #include <math.h>	/* sqrt() */
46 
47 /* header conflict with Solaris xpg4 versus <sys/regset.h> */
48 #if defined(ERR) && (ERR == 13)
49 #undef ERR
50 #endif
51 
52 #if defined(HAVE_NCURSESW_NCURSES_H)
53 #include <ncursesw/ncurses.h>
54 #elif defined(HAVE_NCURSES_NCURSES_H)
55 #include <ncurses/ncurses.h>
56 #elif defined(HAVE_NCURSES_CURSES_H)
57 #include <ncurses/curses.h>
58 #elif defined(HAVE_NCURSES_H)
59 #include <ncurses.h>
60 #else
61 #include <curses.h>
62 #endif
63 
64 /* most curses.h headers include this, some do not */
65 #if defined(HAVE_UNCTRL_H)
66 #include <unctrl.h>
67 #endif
68 
69 /* Solaris xpg4 renames these */
70 #ifndef KEY_MAX
71 #ifdef __KEY_MAX
72 #define KEY_MAX __KEY_MAX
73 #endif
74 #endif
75 
76 #ifndef KEY_MIN
77 #ifdef __KEY_MIN
78 #define KEY_MIN __KEY_MIN
79 #endif
80 #endif
81 
82 /* possible conflicts with <term.h> which may be included in <curses.h> */
83 #ifdef color_names
84 #undef color_names
85 #endif
86 
87 #ifdef buttons
88 #undef buttons
89 #endif
90 
91 #ifdef ENABLE_NLS
92 #include <libintl.h>
93 #include <langinfo.h>
94 #define _(s) dgettext(PACKAGE, s)
95 #else
96 #undef _
97 #define _(s) s
98 #endif
99 
100 #ifndef GCC_NORETURN
101 #define GCC_NORETURN /*nothing*/
102 #endif
103 
104 #ifndef GCC_UNUSED
105 #define GCC_UNUSED /*nothing*/
106 #endif
107 
108 #ifndef HAVE_WGET_WCH
109 #undef USE_WIDE_CURSES
110 #endif
111 
112 /*
113  * FIXME: a configure check would be useful
114  */
115 #ifdef __hpux
116 #undef ACS_UARROW
117 #undef ACS_DARROW
118 #undef ACS_BLOCK
119 #endif
120 
121 /*
122  * Change these if you want
123  */
124 #define USE_SHADOW TRUE
125 #define USE_COLORS TRUE
126 
127 #ifdef HAVE_COLOR
128 #define SCOLS	(COLS - (dialog_state.use_shadow ? 2 : 0))
129 #define SLINES	(LINES - (dialog_state.use_shadow ? 1 : 0))
130 #else
131 #define SCOLS	COLS
132 #define SLINES	LINES
133 #endif
134 
135 #define DLG_EXIT_ESC		255
136 #define DLG_EXIT_UNKNOWN	-2	/* never return this (internal use) */
137 #define DLG_EXIT_ERROR		-1	/* the shell sees this as 255 */
138 #define DLG_EXIT_OK		0
139 #define DLG_EXIT_CANCEL		1
140 #define DLG_EXIT_HELP		2
141 #define DLG_EXIT_EXTRA		3
142 #define DLG_EXIT_ITEM_HELP	4	/* actually DLG_EXIT_HELP */
143 
144 #define DLG_CTRL(n)	((n) & 0x1f)	/* CTRL is preferred, but conflicts */
145 
146 #define CHR_HELP	DLG_CTRL('E')
147 #define CHR_BACKSPACE	DLG_CTRL('H')
148 #define CHR_REPAINT	DLG_CTRL('L')
149 #define CHR_KILL	DLG_CTRL('U')
150 #define CHR_LITERAL	DLG_CTRL('V')
151 #define CHR_DELETE	127
152 #define CHR_NEXT	DLG_CTRL('N')
153 #define CHR_PREVIOUS	DLG_CTRL('P')
154 #define CHR_TRACE	DLG_CTRL('T')
155 
156 #define ESC		27
157 #define TAB		DLG_CTRL('I')
158 
159 #define MARGIN 1
160 #define GUTTER 2
161 #define SHADOW_ROWS 1
162 #define SHADOW_COLS 2
163 #define ARROWS_COL  5
164 
165 #define MAX_LEN 2048
166 #define BUF_SIZE (10L*1024)
167 
168 #undef  MIN
169 #define MIN(x,y) ((x) < (y) ? (x) : (y))
170 
171 #undef  MAX
172 #define MAX(x,y) ((x) > (y) ? (x) : (y))
173 
174 #define DEFAULT_SEPARATE_STR "\t"
175 #define DEFAULT_ASPECT_RATIO 9
176 /* how many spaces is a tab long (default)? */
177 #define TAB_LEN 8
178 #define WTIMEOUT_VAL        10	/* minimum amount of time needed for curses */
179 
180 #ifndef A_CHARTEXT
181 #define A_CHARTEXT 0xff
182 #endif
183 
184 #define CharOf(ch)  ((ch) & 0xff)
185 
186 #ifndef ACS_ULCORNER
187 #define ACS_ULCORNER '+'
188 #endif
189 #ifndef ACS_LLCORNER
190 #define ACS_LLCORNER '+'
191 #endif
192 #ifndef ACS_URCORNER
193 #define ACS_URCORNER '+'
194 #endif
195 #ifndef ACS_LRCORNER
196 #define ACS_LRCORNER '+'
197 #endif
198 #ifndef ACS_HLINE
199 #define ACS_HLINE '-'
200 #endif
201 #ifndef ACS_VLINE
202 #define ACS_VLINE '|'
203 #endif
204 #ifndef ACS_LTEE
205 #define ACS_LTEE '+'
206 #endif
207 #ifndef ACS_RTEE
208 #define ACS_RTEE '+'
209 #endif
210 #ifndef ACS_UARROW
211 #define ACS_UARROW '^'
212 #endif
213 #ifndef ACS_DARROW
214 #define ACS_DARROW 'v'
215 #endif
216 #ifndef ACS_BLOCK
217 #define ACS_BLOCK '#'
218 #endif
219 
220 /* these definitions may work for antique versions of curses */
221 #ifndef HAVE_GETBEGYX
222 #undef  getbegyx
223 #define getbegyx(win,y,x)	(y = (win)?(win)->_begy:ERR, x = (win)?(win)->_begx:ERR)
224 #endif
225 
226 #ifndef HAVE_GETMAXYX
227 #undef  getmaxyx
228 #define getmaxyx(win,y,x)	(y = (win)?(win)->_maxy:ERR, x = (win)?(win)->_maxx:ERR)
229 #endif
230 
231 #ifndef HAVE_GETPARYX
232 #undef  getparyx
233 #define getparyx(win,y,x)	(y = (win)?(win)->_pary:ERR, x = (win)?(win)->_parx:ERR)
234 #endif
235 
236 #ifdef __cplusplus
237 extern "C" {
238 #endif
239 
240 /* these definitions may be needed for bleeding-edge curses implementations */
241 #if !(defined(HAVE_GETBEGX) && defined(HAVE_GETBEGY))
242 #undef getbegx
243 #undef getbegy
244 #define getbegx(win) dlg_getbegx(win)
245 #define getbegy(win) dlg_getbegy(win)
246 extern int dlg_getbegx(WINDOW * /*win*/);
247 extern int dlg_getbegy(WINDOW * /*win*/);
248 #endif
249 
250 #if !(defined(HAVE_GETCURX) && defined(HAVE_GETCURY))
251 #undef getcurx
252 #undef getcury
253 #define getcurx(win) dlg_getcurx(win)
254 #define getcury(win) dlg_getcury(win)
255 extern int dlg_getcurx(WINDOW * /*win*/);
256 extern int dlg_getcury(WINDOW * /*win*/);
257 #endif
258 
259 #if !(defined(HAVE_GETMAXX) && defined(HAVE_GETMAXY))
260 #undef getmaxx
261 #undef getmaxy
262 #define getmaxx(win) dlg_getmaxx(win)
263 #define getmaxy(win) dlg_getmaxy(win)
264 extern int dlg_getmaxx(WINDOW * /*win*/);
265 extern int dlg_getmaxy(WINDOW * /*win*/);
266 #endif
267 
268 #if !(defined(HAVE_GETPARX) && defined(HAVE_GETPARY))
269 #undef getparx
270 #undef getpary
271 #define getparx(win) dlg_getparx(win)
272 #define getpary(win) dlg_getpary(win)
273 extern int dlg_getparx(WINDOW * /*win*/);
274 extern int dlg_getpary(WINDOW * /*win*/);
275 #endif
276 
277 /*
278  * This is a list of "old" names, which should be helpful in updating
279  * applications that use libdialog.  Starting with 2003/11/26, all exported
280  * symbols from libdialog have "dlg_" prefix, or "dialog_" prefix or "_dialog"
281  * suffix (or suffix "_dialog", e.g., init_dialog).
282  */
283 #ifdef __DIALOG_OLD_NAMES__
284 #define color_table                       dlg_color_table
285 #define attr_clear(win,h,w,a)             dlg_attr_clear(win,h,w,a)
286 #define auto_size(t,s,h,w,xl,mc)          dlg_auto_size(t,s,h,w,xl,mc)
287 #define auto_sizefile(t,f,h,w,xl,mc)      dlg_auto_sizefile(t,f,h,w,xl,mc)
288 #define beeping()                         dlg_beeping()
289 #define box_x_ordinate(w)                 dlg_box_x_ordinate(w)
290 #define box_y_ordinate(h)                 dlg_box_y_ordinate(h)
291 #define calc_listh(h,lh,in)               dlg_calc_listh(h,lh,in)
292 #define calc_listw(in,items,group)        dlg_calc_listw(in,items,group)
293 #define color_setup()                     dlg_color_setup()
294 #define create_rc(f)                      dlg_create_rc(f)
295 #define ctl_size(h,w)                     dlg_ctl_size(h,w)
296 #define del_window(win)                   dlg_del_window(win)
297 #define dialog_clear()                    dlg_clear()
298 #define draw_bottom_box(win)              dlg_draw_bottom_box(win)
299 #define draw_box(win,y,x,h,w,xc,bc)       dlg_draw_box(win,y,x,h,w,xc,bc)
300 #define draw_shadow(win,h,w,y,x)          dlg_draw_shadow(win,h,w,y,x)
301 #define draw_title(win,t)                 dlg_draw_title(win,t)
302 #define exiterr                           dlg_exiterr
303 #define killall_bg(n)                     dlg_killall_bg(n)
304 #define mouse_bigregion(y,x)              dlg_mouse_bigregion(y,x)
305 #define mouse_free_regions()              dlg_mouse_free_regions()
306 #define mouse_mkbigregion(y,x,h,w,n,ix,iy,m) dlg_mouse_mkbigregion(y,x,h,w,n,ix,iy,m)
307 #define mouse_mkregion(y,x,h,w,n)         dlg_mouse_mkregion(y,x,h,w,n)
308 #define mouse_region(y,x)                 dlg_mouse_region(y,x)
309 #define mouse_setbase(x,y)                dlg_mouse_setbase(x,y)
310 #define mouse_wgetch(w,c)                 dlg_mouse_wgetch(w,c)
311 #define new_window(h,w,y,x)               dlg_new_window(h,w,y,x)
312 #define parse_rc()                        dlg_parse_rc()
313 #define print_autowrap(win,s,h,w)         dlg_print_autowrap(win,s,h,w)
314 #define print_size(h,w)                   dlg_print_size(h,w)
315 #define put_backtitle()                   dlg_put_backtitle()
316 #define strclone(cprompt)                 dlg_strclone(cprompt)
317 #define sub_window(win,h,w,y,x)           dlg_sub_window(win,h,w,y,x)
318 #define tab_correct_str(s)                dlg_tab_correct_str(s)
319 #endif
320 
321 /*
322  * Attribute names
323  */
324 #define DIALOG_ATR(n)                 dlg_color_table[n].atr
325 
326 #define screen_attr                   DIALOG_ATR(0)
327 #define shadow_attr                   DIALOG_ATR(1)
328 #define dialog_attr                   DIALOG_ATR(2)
329 #define title_attr                    DIALOG_ATR(3)
330 #define border_attr                   DIALOG_ATR(4)
331 #define button_active_attr            DIALOG_ATR(5)
332 #define button_inactive_attr          DIALOG_ATR(6)
333 #define button_key_active_attr        DIALOG_ATR(7)
334 #define button_key_inactive_attr      DIALOG_ATR(8)
335 #define button_label_active_attr      DIALOG_ATR(9)
336 #define button_label_inactive_attr    DIALOG_ATR(10)
337 #define inputbox_attr                 DIALOG_ATR(11)
338 #define inputbox_border_attr          DIALOG_ATR(12)
339 #define searchbox_attr                DIALOG_ATR(13)
340 #define searchbox_title_attr          DIALOG_ATR(14)
341 #define searchbox_border_attr         DIALOG_ATR(15)
342 #define position_indicator_attr       DIALOG_ATR(16)
343 #define menubox_attr                  DIALOG_ATR(17)
344 #define menubox_border_attr           DIALOG_ATR(18)
345 #define item_attr                     DIALOG_ATR(19)
346 #define item_selected_attr            DIALOG_ATR(20)
347 #define tag_attr                      DIALOG_ATR(21)
348 #define tag_selected_attr             DIALOG_ATR(22)
349 #define tag_key_attr                  DIALOG_ATR(23)
350 #define tag_key_selected_attr         DIALOG_ATR(24)
351 #define check_attr                    DIALOG_ATR(25)
352 #define check_selected_attr           DIALOG_ATR(26)
353 #define uarrow_attr                   DIALOG_ATR(27)
354 #define darrow_attr                   DIALOG_ATR(28)
355 #define itemhelp_attr                 DIALOG_ATR(29)
356 #define form_active_text_attr         DIALOG_ATR(30)
357 #define form_text_attr                DIALOG_ATR(31)
358 #define form_item_readonly_attr       DIALOG_ATR(32)
359 #define gauge_attr                    DIALOG_ATR(33)
360 
361 #define DLGK_max (KEY_MAX + 256)
362 
363 /*
364  * Callbacks are used to implement the "background" tailbox.
365  */
366 struct _dlg_callback;
367 
368 typedef void (*DIALOG_FREEBACK) (struct _dlg_callback * /* p */);
369 
370 typedef struct _dlg_callback {
371     struct _dlg_callback *next;
372     FILE *input;
373     WINDOW *win;
374     bool keep_bg;	/* keep in background, on exit */
375     bool bg_task;	/* true if this is background task */
376     bool (*handle_getc)(struct _dlg_callback *p, int ch, int fkey, int *result);
377     bool keep_win;	/* true to not erase window on exit */
378     /* data for dlg_add_callback_ref */
379     struct _dlg_callback **caller;
380     DIALOG_FREEBACK freeback;
381     /* 1.1-20110107 */
382     bool (*handle_input)(struct _dlg_callback *p);
383     bool input_ready;
384 } DIALOG_CALLBACK;
385 
386 typedef struct _dlg_windows {
387     struct _dlg_windows *next;
388     WINDOW *normal;
389     WINDOW *shadow;
390 } DIALOG_WINDOWS;
391 
392 /*
393  * Global variables, which are initialized as needed
394  */
395 typedef struct {
396     DIALOG_CALLBACK *getc_callbacks;
397     DIALOG_CALLBACK *getc_redirect;
398     DIALOG_WINDOWS *all_windows;
399     FILE *output;		/* option "--output-fd fd" */
400     FILE *pipe_input;		/* used for gauge widget */
401     FILE *screen_output;	/* newterm(), etc. */
402     bool screen_initialized;
403     bool use_colors;		/* use colors by default? */
404     bool use_scrollbar;		/* option "--scrollbar" */
405     bool use_shadow;		/* shadow dialog boxes by default? */
406     bool visit_items;		/* option "--visit-items" */
407     char *separate_str;		/* option "--separate-widget string" */
408     int aspect_ratio;		/* option "--aspect ratio" */
409     int output_count;		/* # of widgets that may have done output */
410     int tab_len;		/* option "--tab-len n" */
411     /* 1.0-20070227 */
412     FILE *input;		/* option "--input-fd fd" */
413 #ifdef HAVE_DLG_TRACE
414     FILE *trace_output;		/* option "--trace file" */
415 #endif
416     /* 1.1-20110106 */
417     bool no_mouse;		/* option "--no-mouse" */
418 } DIALOG_STATE;
419 
420 extern DIALOG_STATE dialog_state;
421 
422 /*
423  * Global variables, which dialog resets before each widget
424  */
425 typedef struct {
426     bool beep_after_signal;	/* option "--beep-after" */
427     bool beep_signal;		/* option "--beep" */
428     bool begin_set;		/* option "--begin y x" was used */
429     bool cant_kill;		/* option "--no-kill" */
430     bool colors;		/* option "--colors" */
431     bool cr_wrap;		/* option "--cr-wrap" */
432     bool defaultno;		/* option "--defaultno" */
433     bool dlg_clear_screen;	/* option "--clear" */
434     bool extra_button;		/* option "--extra-button" */
435     bool help_button;		/* option "--help-button" */
436     bool help_status;		/* option "--help-status" */
437     bool input_menu;		/* menu vs inputmenu widget */
438     bool insecure;		/* option "--insecure" */
439     bool item_help;		/* option "--item-help" */
440     bool keep_window;		/* option "--keep-window" */
441     bool nocancel;		/* option "--no-cancel" */
442     bool nocollapse;		/* option "--no-collapse" */
443     bool print_siz;		/* option "--print-size" */
444     bool separate_output;	/* option "--separate-output" */
445     bool single_quoted;		/* option "--single-quoted" */
446     bool size_err;		/* option "--size-err" */
447     bool tab_correct;		/* option "--tab-correct" */
448     bool trim_whitespace;	/* option "--trim" */
449     char *backtitle;		/* option "--backtitle backtitle" */
450     char *cancel_label;		/* option "--cancel-label string" */
451     char *default_item;		/* option "--default-item string" */
452     char *exit_label;		/* option "--exit-label string" */
453     char *extra_label;		/* option "--extra-label string" */
454     char *help_label;		/* option "--help-label string" */
455     char *input_result;
456     char *no_label;		/* option "--no-label string" */
457     char *ok_label;		/* option "--ok-label string" */
458     char *title;		/* option "--title title" */
459     char *yes_label;		/* option "--yes-label string" */
460     int begin_x;		/* option "--begin y x" (second value) */
461     int begin_y;		/* option "--begin y x" (first value) */
462     int max_input;		/* option "--max-input size" */
463     int scale_factor;		/* RESERVED */
464     int sleep_secs;		/* option "--sleep secs" */
465     int timeout_secs;		/* option "--timeout secs" */
466     unsigned input_length;	/* nonzero if input_result is allocated */
467     /* 1.0-20051207 */
468     unsigned formitem_type;	/* DIALOG_FORMITEM.type in dialog_form() */
469     /* 1.1-20070227 */
470     bool keep_tite;		/* option "--keep-tite" */
471     bool ascii_lines;		/* option "--ascii-lines" */
472     bool no_lines;		/* option "--no-lines" */
473     /* 1.1-20070930 */
474     bool nook;			/* option "--no-ok" */
475     /* 1.1-20080727 */
476     bool quoted;		/* option "--quoted" */
477     char *column_header;	/* RESERVED "--column-header" */
478     char *column_separator;	/* option "--column-separator" */
479     char *output_separator;	/* option "--output-separator" */
480     /* 1.1-20100118 */
481     char *date_format;		/* option "--date-format" */
482     char *time_format;		/* option "--time-format" */
483     /* 1.1-20110629 */
484     char *help_line;		/* option "--hline" */
485     char *help_file;		/* option "--hfile" */
486     bool in_helpfile;		/* flag to prevent recursion in --hfile */
487     bool no_nl_expand;		/* option "--no-nl-expand" */
488 } DIALOG_VARS;
489 
490 #define USE_ITEM_HELP(s)        (dialog_vars.item_help && (s) != 0)
491 #define CHECKBOX_TAGS           (dialog_vars.item_help ? 4 : 3)
492 #define MENUBOX_TAGS            (dialog_vars.item_help ? 3 : 2)
493 #define FORMBOX_TAGS            (dialog_vars.item_help ? 9 : 8)
494 #define MIXEDFORM_TAGS          (FORMBOX_TAGS + 1)
495 #define MIXEDGAUGE_TAGS         2
496 
497 extern DIALOG_VARS dialog_vars;
498 
499 #ifndef HAVE_TYPE_CHTYPE
500 #define chtype long
501 #endif
502 
503 #define UCH(ch)			((unsigned char)(ch))
504 
505 #define assert_ptr(ptr,msg) if ((ptr) == 0) dlg_exiterr("cannot allocate memory in " msg)
506 
507 #define dlg_malloc(t,n)    (t *) malloc((size_t)(n) * sizeof(t))
508 #define dlg_calloc(t,n)    (t *) calloc((size_t)(n), sizeof(t))
509 #define dlg_realloc(t,n,p) (t *) realloc((p), (n) * sizeof(t))
510 
511 /*
512  * Table for attribute- and color-values.
513  */
514 typedef struct {
515     chtype atr;
516 #ifdef HAVE_COLOR
517     int fg;
518     int bg;
519     int hilite;
520 #endif
521 #ifdef HAVE_RC_FILE
522     const char *name;
523     const char *comment;
524 #endif
525 } DIALOG_COLORS;
526 
527 extern DIALOG_COLORS dlg_color_table[];
528 
529 /*
530  * Function prototypes
531  */
532 extern const char *dialog_version(void);
533 
534 /* widgets, each in separate files */
535 extern int dialog_calendar(const char * /*title*/, const char * /*subtitle*/, int /*height*/, int /*width*/, int /*day*/, int /*month*/, int /*year*/);
536 extern int dialog_checklist(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*list_height*/, int /*item_no*/, char ** /*items*/, int /*flag*/);
537 extern int dialog_dselect(const char * /*title*/, const char * /*path*/, int /*height*/, int /*width*/);
538 extern int dialog_editbox(const char * /*title*/, const char * /*file*/, int /*height*/, int /*width*/);
539 extern int dialog_form(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*form_height*/, int /*item_no*/, char ** /*items*/);
540 extern int dialog_fselect(const char * /*title*/, const char * /*path*/, int /*height*/, int /*width*/);
541 extern int dialog_gauge(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*percent*/);
542 extern int dialog_helpfile(const char * /*title*/, const char * /*file*/, int /*height*/, int /*width*/);
543 extern int dialog_inputbox(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, const char * /*init*/, const int /*password*/);
544 extern int dialog_menu(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*menu_height*/, int /*item_no*/, char ** /*items*/);
545 extern int dialog_mixedform(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*form_height*/, int /*item_no*/, char ** /*items*/);
546 extern int dialog_mixedgauge(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*percent*/, int /*item_no*/, char ** /*items*/);
547 extern int dialog_msgbox(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*pauseopt*/);
548 extern int dialog_pause(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*seconds*/);
549 extern int dialog_prgbox(const char * /*title*/, const char * /*cprompt*/, const char * /*command*/, int /*height*/, int /*width*/, int /*pauseopt*/);
550 extern int dialog_progressbox(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/);
551 extern int dialog_tailbox(const char * /*title*/, const char * /*file*/, int /*height*/, int /*width*/, int /*bg_task*/);
552 extern int dialog_textbox(const char * /*title*/, const char * /*file*/, int /*height*/, int /*width*/);
553 extern int dialog_timebox(const char * /*title*/, const char * /*subtitle*/, int /*height*/, int /*width*/, int /*hour*/, int /*minute*/, int /*second*/);
554 extern int dialog_yesno(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/);
555 
556 /* some widgets have alternate entrypoints, to allow list manipulation */
557 typedef struct {
558     char *name;
559     char *text;
560     char *help;
561     int state;
562 } DIALOG_LISTITEM;
563 
564 typedef struct {
565     unsigned type;		/* the field type (0=input, 1=password) */
566     char *name;			/* the field label */
567     int name_len;		/* ...its length */
568     int name_y;			/* ...its y-ordinate */
569     int name_x;			/* ...its x-ordinate */
570     bool name_free;		/* ...true if .name can be freed */
571     char *text;			/* the field contents */
572     int text_len;		/* ...its length on the screen */
573     int text_y;			/* ...its y-ordinate */
574     int text_x;			/* ...its x-ordinate */
575     int text_flen;		/* ...its length on screen, or 0 if no input allowed */
576     int text_ilen;		/* ...its limit on amount to be entered */
577     bool text_free;		/* ...true if .text can be freed */
578     char *help;			/* help-message, if any */
579     bool help_free;		/* ...true if .help can be freed */
580 } DIALOG_FORMITEM;
581 
582 typedef	int (DIALOG_INPUTMENU) (DIALOG_LISTITEM * /*items*/, int /*current*/, char * /*newtext*/);
583 
584 extern int dlg_checklist(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*list_height*/, int /*item_no*/, DIALOG_LISTITEM * /*items*/, const char * /*states*/, int /*flag*/, int * /*current_item*/);
585 extern int dlg_form(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*form_height*/, int /*item_no*/, DIALOG_FORMITEM * /*items*/, int * /*current_item*/);
586 extern int dlg_menu(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*menu_height*/, int /*item_no*/, DIALOG_LISTITEM * /*items*/, int * /*current_item*/, DIALOG_INPUTMENU /*rename_menu*/);
587 extern int dlg_progressbox(const char * /*title*/, const char * /*cprompt*/, int /*height*/, int /*width*/, int /*pauseopt*/, FILE * /* fp */);
588 
589 /* argv.c */
590 extern char ** dlg_string_to_argv(char * /* blob */);
591 extern int dlg_count_argv(char ** /* argv */);
592 extern int dlg_eat_argv(int * /* argcp */, char *** /* argvp */, int /* start */, int /* count */);
593 
594 /* arrows.c */
595 extern void dlg_draw_arrows(WINDOW * /*dialog*/, int /*top_arrow*/, int /*bottom_arrow*/, int /*x*/, int /*top*/, int /*bottom*/);
596 extern void dlg_draw_arrows2(WINDOW * /*dialog*/, int /*top_arrow*/, int /*bottom_arrow*/, int /*x*/, int /*top*/, int /*bottom*/, chtype /*attr*/, chtype /*borderattr*/);
597 extern void dlg_draw_helpline(WINDOW * /*dialog*/, bool /*decorations*/);
598 extern void dlg_draw_scrollbar(WINDOW * /*dialog*/, long /* first_data */, long /* this_data */, long /* next_data */, long /* total_data */, int /* left */, int /* right */, int /*top*/, int /*bottom*/, chtype /*attr*/, chtype /*borderattr*/);
599 
600 /* buttons.c */
601 extern const char ** dlg_exit_label(void);
602 extern const char ** dlg_ok_label(void);
603 extern const char ** dlg_ok_labels(void);
604 extern const char ** dlg_yes_labels(void);
605 extern int dlg_button_count(const char ** /*labels*/);
606 extern int dlg_button_to_char(const char * /*label*/);
607 extern int dlg_button_x_step(const char ** /*labels*/, int /*limit*/, int * /*gap*/, int * /*margin*/, int * /*step*/);
608 extern int dlg_char_to_button(int /*ch*/, const char ** /*labels*/);
609 extern int dlg_exit_buttoncode(int /*button*/);
610 extern int dlg_match_char(int /*ch*/, const char * /*string*/);
611 extern int dlg_next_button(const char ** /*labels*/, int /*button*/);
612 extern int dlg_next_ok_buttonindex(int /*current*/, int /*extra*/);
613 extern int dlg_ok_buttoncode(int /*button*/);
614 extern int dlg_prev_button(const char ** /*labels*/, int /*button*/);
615 extern int dlg_prev_ok_buttonindex(int /*current*/, int /*extra*/);
616 extern int dlg_yes_buttoncode(int /*button*/);
617 extern void dlg_button_layout(const char ** /*labels*/, int * /*limit*/);
618 extern void dlg_button_sizes(const char ** /*labels*/, int /*vertical*/, int * /*longest*/, int * /*length*/);
619 extern void dlg_draw_buttons(WINDOW * /*win*/, int /*y*/, int /*x*/, const char ** /*labels*/, int /*selected*/, int /*vertical*/, int /*limit*/);
620 
621 /* columns.c */
622 extern void dlg_align_columns(char ** /* target */, int  /* per_row */, int /* num_rows */);
623 extern void dlg_free_columns(char ** /* target */, int  /* per_row */, int /* num_rows */);
624 
625 /* editbox.c */
626 extern int dlg_editbox(const char */*title*/, char ***/*list*/, int */*rows*/, int /*height*/, int /*width*/);
627 
628 /* formbox.c */
629 extern int dlg_default_formitem(DIALOG_FORMITEM * /*items*/);
630 extern int dlg_ordinate(const char * /*s*/);
631 extern void dlg_free_formitems(DIALOG_FORMITEM * /*items*/);
632 
633 /* guage.c */
634 extern void * dlg_allocate_gauge(const char * /* title */, const char * /* cprompt */, int /* height */, int /* width */, int /* percent */);
635 extern void dlg_free_gauge(void * /* objptr */);
636 extern void dlg_update_gauge(void * /* objptr */, int /* percent */);
637 
638 /* inputstr.c */
639 extern bool dlg_edit_string(char * /*string*/, int * /*offset*/, int /*key*/, int /*fkey*/, bool /*force*/);
640 extern const int * dlg_index_columns(const char * /*string*/);
641 extern const int * dlg_index_wchars(const char * /*string*/);
642 extern int dlg_count_columns(const char * /*string*/);
643 extern int dlg_count_wchars(const char * /*string*/);
644 extern int dlg_edit_offset(char * /*string*/, int /*offset*/, int /*x_last*/);
645 extern int dlg_find_index(const int * /*list*/, int  /*limit*/, int /*to_find*/);
646 extern int dlg_limit_columns(const char * /*string*/, int /*limit*/, int /*offset*/);
647 extern void dlg_show_string(WINDOW * /*win*/, const char * /*string*/, int /*offset*/, chtype /*attr*/, int /*y_base*/, int /*x_base*/, int /*x_last*/, bool /*hidden*/, bool /*force*/);
648 
649 /* rc.c */
650 #ifdef HAVE_RC_FILE
651 extern int dlg_parse_rc(void);
652 extern void dlg_create_rc(const char * /*filename*/);
653 #endif
654 
655 /* ui_getc.c */
656 extern int dlg_getc(WINDOW * /*win*/, int * /*fkey*/);
657 extern int dlg_getc_callbacks(int /*ch*/, int /*fkey*/, int * /*result*/);
658 extern int dlg_last_getc(void);
659 extern void dlg_add_callback(DIALOG_CALLBACK * /*p*/);
660 extern void dlg_add_callback_ref(DIALOG_CALLBACK ** /*p*/, DIALOG_FREEBACK /* cleanup */);
661 extern void dlg_flush_getc(void);
662 extern void dlg_remove_callback(DIALOG_CALLBACK * /*p*/);
663 extern void dlg_killall_bg(int *retval);
664 
665 /* util.c */
666 extern WINDOW * dlg_new_modal_window(WINDOW * /*parent*/, int /*height*/, int /*width*/, int /*y*/, int /*x*/);
667 extern WINDOW * dlg_new_window(int /*height*/, int /*width*/, int /*y*/, int /*x*/);
668 extern WINDOW * dlg_sub_window(WINDOW * /*win*/, int /*height*/, int /*width*/, int /*y*/, int /*x*/);
669 extern bool dlg_need_separator(void);
670 extern char * dlg_set_result(const char * /*string*/);
671 extern char * dlg_strclone(const char * /*cprompt*/);
672 extern char * dlg_strempty(void);
673 extern chtype dlg_asciibox(chtype /*ch*/);
674 extern chtype dlg_boxchar(chtype /*ch*/);
675 extern chtype dlg_get_attrs(WINDOW * /*win*/);
676 extern const char * dlg_print_line(WINDOW */*win*/, chtype */*attr*/, const char */*prompt*/, int /*lm*/, int /*rm*/, int */*x*/);
677 extern int dlg_box_x_ordinate(int /*width*/);
678 extern int dlg_box_y_ordinate(int /*height*/);
679 extern int dlg_calc_list_width(int /*item_no*/, DIALOG_LISTITEM * /*items*/);
680 extern int dlg_calc_listw(int /*item_no*/, char ** /*items*/, int /*group*/);
681 extern int dlg_check_scrolled(int /* key */, int /* last */, int /* page */, bool */* show */, int */* offset */);
682 extern int dlg_default_item(char ** /*items*/, int /*llen*/);
683 extern int dlg_default_listitem(DIALOG_LISTITEM * /*items*/);
684 extern int dlg_defaultno_button(void);
685 extern int dlg_max_input(int /*max_len*/);
686 extern int dlg_print_scrolled(WINDOW * /* win */, const char * /* prompt */, int /* offset */, int /* height */, int /* width */, int /* pauseopt */);
687 extern void dlg_add_quoted(char * /*string*/);
688 extern void dlg_add_result(const char * /*string*/);
689 extern void dlg_add_separator(void);
690 extern void dlg_add_string(char * /*string*/);
691 extern void dlg_attr_clear(WINDOW * /*win*/, int /*height*/, int /*width*/, chtype /*attr*/);
692 extern void dlg_auto_size(const char * /*title*/, const char * /*prompt*/, int * /*height*/, int * /*width*/, int /*boxlines*/, int /*mincols*/);
693 extern void dlg_auto_sizefile(const char * /*title*/, const char * /*file*/, int * /*height*/, int * /*width*/, int /*boxlines*/, int /*mincols*/);
694 extern void dlg_beeping(void);
695 extern void dlg_calc_listh(int * /*height*/, int * /*list_height*/, int /*item_no*/);
696 extern void dlg_clear(void);
697 extern void dlg_clr_result(void);
698 extern void dlg_ctl_size(int /*height*/, int /*width*/);
699 extern void dlg_del_window(WINDOW * /*win*/);
700 extern void dlg_does_output(void);
701 extern void dlg_draw_bottom_box(WINDOW * /*win*/);
702 extern void dlg_draw_box(WINDOW * /*win*/, int /*y*/, int /*x*/, int /*height*/, int /*width*/, chtype /*boxchar*/, chtype /*borderchar*/);
703 extern void dlg_draw_title(WINDOW *win, const char *title);
704 extern void dlg_exit(int /*code*/) GCC_NORETURN;
705 extern void dlg_item_help(const char * /*txt*/);
706 extern void dlg_print_autowrap(WINDOW * /*win*/, const char * /*prompt*/, int /*height*/, int /*width*/);
707 extern void dlg_print_size(int /*height*/, int /*width*/);
708 extern void dlg_print_text(WINDOW * /*win*/, const char * /*txt*/, int /*len*/, chtype * /*attr*/);
709 extern void dlg_put_backtitle(void);
710 extern void dlg_restore_vars(DIALOG_VARS * /* save */);
711 extern void dlg_save_vars(DIALOG_VARS * /* save */);
712 extern void dlg_set_focus(WINDOW * /*parent*/, WINDOW * /*win*/);
713 extern void dlg_tab_correct_str(char * /*prompt*/);
714 extern void dlg_trim_string(char * /*src*/);
715 extern void end_dialog(void);
716 extern void init_dialog(FILE * /*input*/, FILE * /*output*/);
717 
718 extern void dlg_exiterr(const char *, ...) GCC_NORETURN
719 #if defined(__GNUC__) && !defined(printf)
720 __attribute__((format(printf,1,2)))
721 #endif
722 ;
723 
724 #ifdef HAVE_COLOR
725 extern chtype dlg_color_pair(int /*foreground*/, int /*background*/);
726 extern int dlg_color_count(void);
727 extern void dlg_color_setup(void);
728 extern void dlg_draw_shadow(WINDOW * /*win*/, int /*height*/, int /*width*/, int /*y*/, int /*x*/);
729 #endif
730 
731 #ifdef HAVE_STRCASECMP
732 #define dlg_strcmp(a,b) strcasecmp(a,b)
733 #else
734 extern int dlg_strcmp(const char * /*a*/, const char * /*b*/);
735 #endif
736 
737 #ifdef HAVE_DLG_TRACE
738 #define DLG_TRACE(params) dlg_trace_msg params
739 extern void dlg_trace_msg(const char *fmt, ...)
740 #ifdef GCC_PRINTF
741     __attribute__((format(printf,1,2)))
742 #endif
743 ;
744 extern void dlg_trace_win(WINDOW * /*win*/);
745 extern void dlg_trace_chr(int /*ch*/, int /*fkey*/);
746 extern void dlg_trace(const char * /*fname*/);
747 #else
748 #define DLG_TRACE(params) /* nothing */
749 #define dlg_trace_win(win) /* nothing */
750 #define dlg_trace_chr(ch,fkey) /* nothing */
751 #define dlg_trace(fname) /* nothing */
752 #endif
753 
754 #ifdef KEY_RESIZE
755 extern void dlg_move_window(WINDOW * /*win*/, int /*height*/, int /*width*/, int /*y*/, int /*x*/);
756 #endif
757 
758 /*
759  * Normally "enter" means "ok".  Use this macro to handle the explicit
760  * check for DLGK_ENTER:
761  */
762 #define dlg_enter_buttoncode(code) (dialog_vars.nook ? DLG_EXIT_OK : dlg_ok_buttoncode(code))
763 
764 /*
765  * The following stuff is needed for mouse support
766  */
767 typedef struct mseRegion {
768     int x, y, X, Y, code;
769     int mode, step_x, step_y;
770     struct mseRegion *next;
771 } mseRegion;
772 
773 #if defined(NCURSES_MOUSE_VERSION)
774 
775 #define	mouse_open() mousemask(BUTTON1_CLICKED, (mmask_t *) 0)
776 #define	mouse_close() mousemask(0, (mmask_t *) 0)
777 
778 extern mseRegion * dlg_mouse_mkregion (int /*y*/, int /*x*/, int /*height*/, int /*width*/, int /*code*/);
779 extern void dlg_mouse_free_regions (void);
780 extern void dlg_mouse_mkbigregion (int /*y*/, int /*x*/, int /*height*/, int /*width*/, int /*code*/, int /*step_x*/, int /*step_y*/, int /*mode*/);
781 extern void dlg_mouse_setbase (int /*x*/, int /*y*/);
782 
783 #define USE_MOUSE 1
784 
785 #else
786 
787 #define	mouse_open() /*nothing*/
788 #define	mouse_close() /*nothing*/
789 #define dlg_mouse_free_regions() /* nothing */
790 #define	dlg_mouse_mkregion(y, x, height, width, code) /*nothing*/
791 #define	dlg_mouse_mkbigregion(y, x, height, width, code, step_x, step_y, mode) /*nothing*/
792 #define	dlg_mouse_setbase(x, y) /*nothing*/
793 
794 #define USE_MOUSE 0
795 
796 #endif
797 
798 extern mseRegion *dlg_mouse_region (int /*y*/, int /*x*/);
799 extern mseRegion *dlg_mouse_bigregion (int /*y*/, int /*x*/);
800 extern int dlg_mouse_wgetch (WINDOW * /*win*/, int * /*fkey*/);
801 extern int dlg_mouse_wgetch_nowait (WINDOW * /*win*/, int * /*fkey*/);
802 
803 #define mouse_mkbutton(y,x,len,code) dlg_mouse_mkregion(y,x,1,len,code);
804 
805 /*
806  * This is the base for fictitious keys, which activate
807  * the buttons.
808  *
809  * Mouse-generated keys are the following:
810  *   -- the first 32 are used as numbers, in addition to '0'-'9'
811  *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
812  */
813 #define M_EVENT (DLGK_max + 1)
814 
815 /*
816  * The `flag' parameter in checklist is used to select between
817  * radiolist and checklist
818  */
819 #define FLAG_CHECK 1
820 #define FLAG_RADIO 0
821 
822 /*
823  * This is used only for debugging (FIXME: should have a separate header).
824  */
825 #ifdef NO_LEAKS
826 extern void _dlg_inputstr_leaks(void);
827 #if defined(NCURSES_VERSION) && defined(HAVE__NC_FREE_AND_EXIT)
828 extern void _nc_free_and_exit(int);	/* nc_alloc.h normally not installed */
829 #endif
830 #endif
831 
832 #ifdef __cplusplus
833 }
834 #endif
835 /* *INDENT-ON* */
836 
837 #endif /* DIALOG_H_included */
838