Initial import from FreeBSD RELENG_4:
[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  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23 #include <sys/wait.h>
24 #include <dialog.h>
25
26 /* Hook functions */
27
28 static int
29 getBool(dialogMenuItem *self)
30 {
31     if (self->data && *((int *)self->data))
32         return TRUE;
33     return FALSE;
34 }
35
36 static int
37 setBool(dialogMenuItem *self)
38 {
39     if (self->data) {
40         *((int *)self->data) = !*((int *)self->data);
41         return DITEM_SUCCESS;
42     }
43     return DITEM_FAILURE;
44 }
45
46 static int german_book, italian_book, slang_book;
47
48 static int
49 clearBooks(dialogMenuItem *self)
50 {
51     german_book = italian_book = slang_book = FALSE;
52     return DITEM_SUCCESS | DITEM_REDRAW;
53 }
54
55 /* menu2 - A more advanced way of using checked and fire hooks to manipulate the backing-variables directly */
56 /* prompt       title                                   checked         fire            sel   data */
57 static dialogMenuItem menu2[] = {
58     { "German", "Buy book on learning German",          getBool,        setBool,        NULL, &german_book},
59     { "Italian",        "Buy book on learning Italian",         getBool,        setBool,        NULL, &italian_book },
60     { "Slang",  "Buy book on commonly used insults",    getBool,        setBool,        NULL, &slang_book },
61     { "Clear",  "Clear book list",                      NULL,           clearBooks,     NULL, NULL,     ' ', ' ', ' ' },
62 };
63
64 /* End of hook functions */
65
66 /* Kick it off, James! */
67 int
68 main(int argc, char **argv)
69 {
70     int retval;
71     
72     init_dialog();
73     
74     retval = dialog_checklist("this is a dialog_checklist() in action, test #1",
75                               "this checklist menu shows off some of the straight-forward features\n"
76                               "of the new menu system's check & fire dispatch hooks", -1, -1, 4, -4, menu2, NULL);
77     dialog_clear();
78     fprintf(stderr, "returned value for dialog_checklist was %d (%d %d %d)\n", retval, german_book, italian_book, slang_book);
79     
80     end_dialog();
81     return 0;
82 }