Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[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  * $DragonFly: src/gnu/lib/libdialog/TESTS/check3.c,v 1.2 2003/06/17 04:25:43 dillon Exp $
18  *
19  */
20
21 #include <sys/wait.h>
22 #include <dialog.h>
23
24 /* Hook functions */
25
26 static int
27 getBool(dialogMenuItem *self)
28 {
29     if (self->data && *((int *)self->data))
30         return TRUE;
31     return FALSE;
32 }
33
34 static int
35 setBool(dialogMenuItem *self)
36 {
37     if (self->data) {
38         *((int *)self->data) = !*((int *)self->data);
39         return DITEM_SUCCESS;
40     }
41     return DITEM_FAILURE;
42 }
43
44 static int german_book, italian_book, slang_book;
45 static int spending;
46
47 static int
48 check(dialogMenuItem *self)
49 {
50     return ((int)self->data == spending);
51 }
52
53 static int
54 spend(dialogMenuItem *self)
55 {
56     spending = (int)self->data;
57     return DITEM_SUCCESS | DITEM_REDRAW;
58 }
59
60 /* menu4 - Show off a simulated compound menu (group at top is checklist, group at bottom radio) */
61 /* prompt       title                                   checked         fire     sel,  data          lbra mark rbra */
62 static dialogMenuItem menu4[] = {
63     { "German", "Buy books on learning German",         getBool,        setBool, NULL, &german_book },
64     { "Italian","Buy books on learning Italian",        getBool,        setBool, NULL, &italian_book },
65     { "Slang",  "Buy books on commonly used insults",   getBool,        setBool, NULL, &slang_book },
66     { "-----",  "----------------------------------",   NULL,           NULL,    NULL, NULL,         ' ', ' ', ' ' },
67     { "1000",   "Spend $1,000",                         check,          spend,   NULL, (void *)1000, '(', '*', ')' },
68     { "500",    "Spend $500",                           check,          spend,   NULL, (void *)500,  '(', '*', ')' },
69     { "100",    "Spend $100",                           check,          spend,   NULL, (void *)100,  '(', '*', ')' },
70 };
71
72 /* End of hook functions */
73
74 /* Kick it off, James! */
75 int
76 main(int argc, char **argv)
77 {
78     int retval;
79     
80     init_dialog();
81     
82     
83     retval = dialog_checklist("this is dialog_checklist() in action, test #3",
84                               "Now we show off some of the button 'styles' one can create.",
85                               -1, -1, 7, -7, menu4, NULL);
86     dialog_clear();
87     fprintf(stderr, "spent $%d on %s%s%s books\n", spending, german_book ? " german" : "",
88             italian_book ? " italian" : "", slang_book ? " slang" : "");
89     
90     end_dialog();
91     return 0;
92 }