Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[games.git] / gnu / lib / libdialog / TESTS / check1.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/check1.c,v 1.7 2000/01/10 11:52:02 phantom Exp $
17  * $DragonFly: src/gnu/lib/libdialog/TESTS/check1.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 /* menu2 - A more advanced way of using checked and fire hooks to manipulate the backing-variables directly */
57 /* prompt       title                                   checked         fire            sel   data */
58 static dialogMenuItem menu2[] = {
59     { "German", "Buy book on learning German",          getBool,        setBool,        NULL, &german_book},
60     { "Italian",        "Buy book on learning Italian",         getBool,        setBool,        NULL, &italian_book },
61     { "Slang",  "Buy book on commonly used insults",    getBool,        setBool,        NULL, &slang_book },
62     { "Clear",  "Clear book list",                      NULL,           clearBooks,     NULL, NULL,     ' ', ' ', ' ' },
63 };
64
65 /* End of hook functions */
66
67 /* Kick it off, James! */
68 int
69 main(int argc, char **argv)
70 {
71     int retval;
72     
73     init_dialog();
74     
75     retval = dialog_checklist("this is a dialog_checklist() in action, test #1",
76                               "this checklist menu shows off some of the straight-forward features\n"
77                               "of the new menu system's check & fire dispatch hooks", -1, -1, 4, -4, menu2, NULL);
78     dialog_clear();
79     fprintf(stderr, "returned value for dialog_checklist was %d (%d %d %d)\n", retval, german_book, italian_book, slang_book);
80     
81     end_dialog();
82     return 0;
83 }