Initial import from FreeBSD RELENG_4:
[games.git] / gnu / lib / libdialog / TESTS / radio1.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/radio1.c,v 1.7 2000/01/10 11:52:08 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 spending;
29
30 static int
31 check(dialogMenuItem *self)
32 {
33     return ((int)self->data == spending);
34 }
35
36 static int
37 spend(dialogMenuItem *self)
38 {
39     spending = (int)self->data;
40     return DITEM_SUCCESS | DITEM_REDRAW;
41 }
42
43 /* menu5 - Show a simple radiolist menu that inherits the radio appearance by default */
44 /* prompt       title                   checked         fire            sel   data */
45 static dialogMenuItem menu5[] = {
46     { "1000",   "Spend $1,000",         check,          spend,          NULL, (void *)1000 },
47     { "500",    "Spend $500",           check,          spend,          NULL, (void *)500 },
48     { "100",    "Spend $100",           check,          spend,          NULL, (void *)100 },
49 };
50
51 /* End of hook functions */
52
53 /* Kick it off, James! */
54 int
55 main(int argc, char **argv)
56 {
57     int retval;
58     
59     init_dialog();
60     
61     
62     retval = dialog_radiolist("this is dialog_radiolist() in action, test #1",
63                               "this radio menu shows off some of the straight-forward features\n"
64                               "of the new menu system's check & fire dispatch hooks", -1, -1, 3, -3, menu5, NULL);
65     dialog_clear();
66     fprintf(stderr, "returned value for dialog_radiolist was %d (money set to %d)\n", retval, spending);
67     
68     end_dialog();
69     return 0;
70 }