Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / gnu / lib / libdialog / TESTS / check2.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/check2.c,v 1.6 2000/01/10 11:52:02 phantom Exp $
17  * $DragonFly: src/gnu/lib/libdialog/TESTS/check2.c,v 1.2 2003/06/17 04:25:43 dillon Exp $
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <sys/wait.h>
25 #include <dialog.h>
26
27 /* Hook functions */
28
29 static int
30 getBool(dialogMenuItem *self)
31 {
32     if (self->data && *((int *)self->data))
33         return TRUE;
34     return FALSE;
35 }
36
37 static int
38 setBool(dialogMenuItem *self)
39 {
40     if (self->data) {
41         *((int *)self->data) = !*((int *)self->data);
42         return DITEM_SUCCESS;
43     }
44     return DITEM_FAILURE;
45 }
46
47 static int german_book, italian_book, slang_book;
48
49 static int
50 clearBooks(dialogMenuItem *self)
51 {
52     german_book = italian_book = slang_book = FALSE;
53     return DITEM_SUCCESS | DITEM_REDRAW;
54 }
55
56 static int
57 buyBooks(dialogMenuItem *self)
58 {
59     char foo[256];
60     
61     if (german_book || italian_book || slang_book) {
62         strcpy(foo, "Ok, you're buying books on");
63         if (german_book)
64             strcat(foo, " german");
65         if (italian_book)
66             strcat(foo, " italian");
67         if (slang_book)
68             strcat(foo, " slang");
69     }
70     else
71         strcpy(foo, "You're not buying any books?");
72     dialog_mesgbox("This is a direct callback for the `Buy' button", foo, -1, -1);
73     return DITEM_SUCCESS;
74 }
75
76 /* menu3 - Look mom!  We can finally use our own OK and Cancel buttons! */
77 /* prompt       title                                   checked         fire            sel   data */
78 static dialogMenuItem menu3[] = {
79     { "Buy!",   NULL,                                   NULL,           buyBooks        }, /* New "OK" button */
80     { "No Way!",        NULL,                                   NULL,           NULL            }, /* New "Cancel" button */
81     { "German", "Buy books on learning German",         getBool,        setBool,        NULL, &german_book },
82     { "Italian",        "Buy books on learning Italian",        getBool,        setBool,        NULL, &italian_book },
83     { "Slang",  "Buy books on commonly used insults",   getBool,        setBool,        NULL, &slang_book },
84     { "Clear",  "Clear book list",                      NULL,           clearBooks,     NULL, NULL, ' ', ' ', ' ' },
85 };
86
87 /* End of hook functions */
88
89 /* Kick it off, James! */
90 int
91 main(int argc, char **argv)
92 {
93     int retval;
94     
95     init_dialog();
96     
97     retval = dialog_checklist("this is dialog_checklist() in action, test #2",
98                               "Same as before, but now we relabel the buttons and override the OK action.",
99                               -1, -1, 4, -4, menu3 + 2, (char *)TRUE);
100     dialog_clear();
101     fprintf(stderr, "returned value for dialog_checklist was %d\n", retval);
102     
103     end_dialog();
104     return 0;
105 }