xref: /freebsd/contrib/bsddialog/examples_library/yesno.c (revision 263660c061ac76d449cbca7bdd0db2ecdfad76d9)
1f499134dSBaptiste Daroussin /*-
2f499134dSBaptiste Daroussin  * SPDX-License-Identifier: CC0-1.0
3f499134dSBaptiste Daroussin  *
4f499134dSBaptiste Daroussin  * Written in 2021 by Alfonso Sabato Siciliano.
5f499134dSBaptiste Daroussin  * To the extent possible under law, the author has dedicated all copyright
6f499134dSBaptiste Daroussin  * and related and neighboring rights to this software to the public domain
7f499134dSBaptiste Daroussin  * worldwide. This software is distributed without any warranty, see:
8f499134dSBaptiste Daroussin  *   <http://creativecommons.org/publicdomain/zero/1.0/>.
9f499134dSBaptiste Daroussin  */
10f499134dSBaptiste Daroussin 
11f499134dSBaptiste Daroussin #include <stdio.h>
12f499134dSBaptiste Daroussin #include <string.h>
13f499134dSBaptiste Daroussin 
14f499134dSBaptiste Daroussin #include <bsddialog.h>
15f499134dSBaptiste Daroussin 
16f499134dSBaptiste Daroussin int main()
17f499134dSBaptiste Daroussin {
18f499134dSBaptiste Daroussin 	int output;
19f499134dSBaptiste Daroussin 	struct bsddialog_conf conf;
20f499134dSBaptiste Daroussin 
21*263660c0SAlfonso Siciliano 	if (bsddialog_init() == BSDDIALOG_ERROR) {
22*263660c0SAlfonso Siciliano 		printf("Error: %s\n", bsddialog_geterror());
23*263660c0SAlfonso Siciliano 		return (1);
24*263660c0SAlfonso Siciliano 	}
25*263660c0SAlfonso Siciliano 
26f499134dSBaptiste Daroussin 	bsddialog_initconf(&conf);
27f499134dSBaptiste Daroussin 	conf.title = "yesno";
28f499134dSBaptiste Daroussin 	output = bsddialog_yesno(&conf, "Example", 7, 25);
29f499134dSBaptiste Daroussin 
30f499134dSBaptiste Daroussin 	bsddialog_end();
31f499134dSBaptiste Daroussin 
32*263660c0SAlfonso Siciliano 	switch (output) {
33*263660c0SAlfonso Siciliano 	case BSDDIALOG_ERROR:
34*263660c0SAlfonso Siciliano 		printf("Error %s\n", bsddialog_geterror());
35*263660c0SAlfonso Siciliano 		break;
36*263660c0SAlfonso Siciliano 	case BSDDIALOG_YES:
37*263660c0SAlfonso Siciliano 		printf("YES\n");
38*263660c0SAlfonso Siciliano 		break;
39*263660c0SAlfonso Siciliano 	case BSDDIALOG_NO:
40*263660c0SAlfonso Siciliano 		printf("NO\n");
41*263660c0SAlfonso Siciliano 		break;
42*263660c0SAlfonso Siciliano 	}
43*263660c0SAlfonso Siciliano 
44*263660c0SAlfonso Siciliano 	return (output);
45f499134dSBaptiste Daroussin }