Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / gnu / lib / libdialog / TESTS / radio3.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/radio3.c,v 1.7 2000/01/10 11:52:09 phantom Exp $
17  * $DragonFly: src/gnu/lib/libdialog/TESTS/radio3.c,v 1.2 2003/06/17 04:25:44 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 spending;
30
31 static int
32 check(dialogMenuItem *self)
33 {
34     return ((int)self->data == spending);
35 }
36
37 static int
38 spend(dialogMenuItem *self)
39 {
40     spending = (int)self->data;
41     return DITEM_SUCCESS | DITEM_REDRAW;
42 }
43
44 static void
45 ask(dialogMenuItem *self, int is_selected)
46 {
47     if (is_selected) {
48         char *str;
49         
50         if (!strcmp(self->prompt, "1000"))
51             str = "You'd better ask both your parents first! ";
52         else if (!strcmp(self->prompt, "500"))
53             str = "You'd better at least ask your Dad!       ";
54         else
55             str = "Yes, being frugal is probably a good idea!";
56         DialogX = 15;
57         DialogY = 17;
58         dialog_msgbox("Free Advice", str, -1, -1, 0);
59     }
60 }
61
62 /*
63  * menu5 - Show a simple radiolist menu that inherits the radio appearance by default and appears at
64  * a different location, leaving room for a msg box below it.  This shows off the DialogX/DialogY extensions.
65  */
66
67 /* prompt       title                   checked         fire            sel     data */
68 static dialogMenuItem menu5[] = {
69     { "1000",   "Spend $1,000",         check,          spend,          ask,    (void *)1000 },
70     { "500",    "Spend $500",           check,          spend,          ask,    (void *)500 },
71     { "100",    "Spend $100",           check,          spend,          ask,    (void *)100 },
72 };
73
74 /* End of hook functions */
75
76 /* Kick it off, James! */
77 int
78 main(int argc, char **argv)
79 {
80     int retval;
81     
82     init_dialog();
83     
84     
85     DialogX = 5;
86     DialogY = 1;
87     retval = dialog_radiolist("this is dialog_radiolist() in action, test #3",
88                               "This radio menu shows off the ability to put dialog menus and other\n"
89                               "controls at different locations, as well as the `selected' hook which\n"
90                               "lets you follow the traversal of the selection bar as well as what's\n"
91                               "selected.",
92                               -1, -1, 3, -3, menu5, NULL);
93     dialog_clear();
94     fprintf(stderr, "returned value for dialog_radiolist was %d (money set to %d)\n", retval, spending);
95     
96     end_dialog();
97     return 0;
98 }