113136Sjkh/*
213136Sjkh * small test-driver for new dialog functionality
313136Sjkh *
413136Sjkh * Copyright (c) 1995, Jordan Hubbard
513136Sjkh *
613136Sjkh * All rights reserved.
713136Sjkh *
813136Sjkh * This source code may be used, modified, copied, distributed, and
913136Sjkh * sold, in both source and binary form provided that the above
1013136Sjkh * copyright and these terms are retained, verbatim, as the first
1113136Sjkh * lines of this file.  Under no circumstances is the author
1213136Sjkh * responsible for the proper functioning of the software nor does
1313136Sjkh * the author assume any responsibility for damages incurred with
1413136Sjkh * its use.
1513136Sjkh */
1613136Sjkh
17114603Sobrien#include <sys/cdefs.h>
18114603Sobrien__FBSDID("$FreeBSD$");
19114603Sobrien
2013136Sjkh#include <stdio.h>
2113136Sjkh#include <stdlib.h>
2213136Sjkh#include <string.h>
2313136Sjkh#include <unistd.h>
2413136Sjkh#include <sys/wait.h>
2513136Sjkh#include <dialog.h>
2613136Sjkh
2713136Sjkh/* Start of hook functions */
2813136Sjkhstatic enum { nowhere, berlin, rome, ny } where;
2913136Sjkh
3013136Sjkhstatic int
3113136Sjkh_menu1_berlin_action(dialogMenuItem *self)
3213136Sjkh{
3315273Sjkh    if (where == berlin) {
3415273Sjkh	dialog_mesgbox("excuse me?", "But you're already *in* Berlin!", -1, -1);
3515273Sjkh    }
3615273Sjkh    else {
3715273Sjkh	where = berlin;
3815273Sjkh	dialog_mesgbox("whoosh!", "Welcome to Berlin!  Have a beer!", -1, -1);
3915273Sjkh    }
4015289Sjkh    return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
4113136Sjkh}
4213136Sjkh
4313136Sjkhstatic int
4413136Sjkh_menu1_rome_action(dialogMenuItem *self)
4513136Sjkh{
4615273Sjkh    if (where == rome) {
4715273Sjkh	dialog_mesgbox("The wine must be getting to you..", "You're already in Rome!", -1, -1);
4815273Sjkh    }
4915273Sjkh    else {
5015273Sjkh	where = rome;
5115273Sjkh	dialog_mesgbox("whoosh!", "Welcome to Rome!  Have a coffee!", -1, -1);
5215273Sjkh    }
5315289Sjkh    return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
5413136Sjkh}
5513136Sjkh
5613136Sjkhstatic int
5713136Sjkh_menu1_ny_action(dialogMenuItem *self)
5813136Sjkh{
5915273Sjkh    if (where == ny) {
6015273Sjkh	dialog_mesgbox("Say what?", "You're already there!", -1, -1);
6115273Sjkh    }
6215273Sjkh    else {
6315273Sjkh	where = ny;
6415273Sjkh	dialog_mesgbox("whoosh!", "Welcome to New York!  Now go someplace else!", -1, -1);
6515273Sjkh    }
6615289Sjkh    return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
6713136Sjkh}
6813136Sjkh
6913136Sjkh/* menu1 - show off the "fire" action hook */
7015273Sjkh/* prompt	title					checked		fire */
7113136Sjkhstatic dialogMenuItem menu1[] = {
7215273Sjkh    { "Berlin",	"Go visit Germany's new capitol",	NULL,	_menu1_berlin_action	},
7315273Sjkh    { "Rome",	"Go visit the Roman ruins",		NULL,	_menu1_rome_action	},
7415273Sjkh    { "New York",	"Go visit the streets of New York",	NULL,	_menu1_ny_action	},
7513136Sjkh};
7613136Sjkh
7713136Sjkh/* End of hook functions */
7813136Sjkh
7913136Sjkh/* Kick it off, James! */
8013136Sjkhint
8155752Sphantommain(int argc, char **argv)
8213136Sjkh{
8315273Sjkh    int retval;
8415273Sjkh
8515273Sjkh    init_dialog();
8615273Sjkh
8715273Sjkh    retval = dialog_menu("this is dialog_menu() in action, test #1",
8815273Sjkh			 "this simple menu shows off some of the straight-forward features\n"
8915273Sjkh			 "of the new menu system's action dispatch hooks.  Select Cancel to leave",
9015273Sjkh			 -1, -1, 3, -3, menu1, NULL, NULL, NULL);
9115273Sjkh    dialog_clear();
9215273Sjkh    fprintf(stderr, "returned value for dialog_menu was %d\n", retval);
9315273Sjkh
9415273Sjkh    end_dialog();
9515273Sjkh    return 0;
9613136Sjkh}
97