Initial import from FreeBSD RELENG_4:
[dragonfly.git] / gnu / lib / libdialog / TESTS / menu2.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/menu2.c,v 1.8 2000/01/10 11:52:07 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 /* Start of hook functions */
27 static enum { nowhere, berlin, rome, ny } where;
28
29 static int
30 _menu1_berlin_action(dialogMenuItem *self)
31 {
32     if (where == berlin)
33         dialog_mesgbox("excuse me?", "But you're already *in* Berlin!", -1, -1);
34     else {
35         where = berlin;
36         dialog_mesgbox("whoosh!", "Welcome to Berlin!  Have a beer!", -1, -1);
37     }
38     return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
39 }
40
41 static int
42 _menu1_rome_action(dialogMenuItem *self)
43 {
44     if (where == rome)
45         dialog_mesgbox("The wine must be getting to you..", "You're already in Rome!", -1, -1);
46     else {
47         where = rome;
48         dialog_mesgbox("whoosh!", "Welcome to Rome!  Have a coffee!", -1, -1);
49     }
50     return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
51 }
52
53 static int
54 _menu1_ny_action(dialogMenuItem *self)
55 {
56     if (where == ny)
57         dialog_mesgbox("Say what?", "You're already there!", -1, -1);
58     else {
59         where = ny;
60         dialog_mesgbox("whoosh!", "Welcome to New York!  Now go someplace else!", -1, -1);
61     }
62     return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
63 }
64
65 /* menu1 - show off the "fire" action hook */
66 /* prompt       title                                   checked         fire */
67 static dialogMenuItem menu1[] = {
68     { "Berlin", "Go visit Germany's new capitol",       NULL,   _menu1_berlin_action    },
69     { "Rome",   "Go visit the Roman ruins",             NULL,   _menu1_rome_action      },
70     { "New York",       "Go visit the streets of New York",     NULL,   _menu1_ny_action        },
71 };
72
73 /* End of hook functions */
74
75 /* Kick it off, James! */
76 int
77 main(int argc, char **argv)
78 {
79     int retval;
80     
81     init_dialog();
82     
83     use_helpfile("menu2.c");
84     use_helpline("Type F1 to view the source for this demo");
85     retval = dialog_menu("this is dialog_menu() in action, test #2",
86                          "this simple menu shows off some of the straight-forward features\n"
87                          "of the new menu system's action dispatch hooks as well as a helpline\n"
88                          "and a helpfile.  Select Cancel to leave",
89                          -1, -1, 3, -3, menu1, NULL, NULL, NULL);
90     dialog_clear();
91     fprintf(stderr, "returned value for dialog_menu was %d\n", retval);
92     
93     end_dialog();
94     return 0;
95 }