Initial import from FreeBSD RELENG_4:
[dragonfly.git] / gnu / lib / libdialog / TESTS / check3.c
1 /*
2  * small test-driver for new dialog functionality
3  *
4  * Copyright (c) 1995, Jordan Hubbard
5  *
6  * All rights reserved.
7  *
8  * This source code may be used, modified, copied, distributed, and
9  * sold, in both source and binary form provided that the above
10  * copyright and these terms are retained, verbatim, as the first
11  * lines of this file.  Under no circumstances is the author
12  * responsible for the proper functioning of the software nor does
13  * the author assume any responsibility for damages incurred with
14  * its use.
15  *
16  * $FreeBSD: src/gnu/lib/libdialog/TESTS/check3.c,v 1.6 2000/01/10 11:52:03 phantom Exp $
17  *
18  */
19
20 #include <sys/wait.h>
21 #include <dialog.h>
22
23 /* Hook functions */
24
25 static int
26 getBool(dialogMenuItem *self)
27 {
28     if (self->data && *((int *)self->data))
29         return TRUE;
30     return FALSE;
31 }
32
33 static int
34 setBool(dialogMenuItem *self)
35 {
36     if (self->data) {
37         *((int *)self->data) = !*((int *)self->data);
38         return DITEM_SUCCESS;
39     }
40     return DITEM_FAILURE;
41 }
42
43 static int german_book, italian_book, slang_book;
44 static int spending;
45
46 static int
47 check(dialogMenuItem *self)
48 {
49     return ((int)self->data == spending);
50 }
51
52 static int
53 spend(dialogMenuItem *self)
54 {
55     spending = (int)self->data;
56     return DITEM_SUCCESS | DITEM_REDRAW;
57 }
58
59 /* menu4 - Show off a simulated compound menu (group at top is checklist, group at bottom radio) */
60 /* prompt       title                                   checked         fire     sel,  data          lbra mark rbra */
61 static dialogMenuItem menu4[] = {
62     { "German", "Buy books on learning German",         getBool,        setBool, NULL, &german_book },
63     { "Italian","Buy books on learning Italian",        getBool,        setBool, NULL, &italian_book },
64     { "Slang",  "Buy books on commonly used insults",   getBool,        setBool, NULL, &slang_book },
65     { "-----",  "----------------------------------",   NULL,           NULL,    NULL, NULL,         ' ', ' ', ' ' },
66     { "1000",   "Spend $1,000",                         check,          spend,   NULL, (void *)1000, '(', '*', ')' },
67     { "500",    "Spend $500",                           check,          spend,   NULL, (void *)500,  '(', '*', ')' },
68     { "100",    "Spend $100",                           check,          spend,   NULL, (void *)100,  '(', '*', ')' },
69 };
70
71 /* End of hook functions */
72
73 /* Kick it off, James! */
74 int
75 main(int argc, char **argv)
76 {
77     int retval;
78     
79     init_dialog();
80     
81     
82     retval = dialog_checklist("this is dialog_checklist() in action, test #3",
83                               "Now we show off some of the button 'styles' one can create.",
84                               -1, -1, 7, -7, menu4, NULL);
85     dialog_clear();
86     fprintf(stderr, "spent $%d on %s%s%s books\n", spending, german_book ? " german" : "",
87             italian_book ? " italian" : "", slang_book ? " slang" : "");
88     
89     end_dialog();
90     return 0;
91 }