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