1 /*-
2 * SPDX-License-Identifier: CC0-1.0
3 *
4 * Written in 2021 by Alfonso Sabato Siciliano.
5 * To the extent possible under law, the author has dedicated all copyright
6 * and related and neighboring rights to this software to the public domain
7 * worldwide. This software is distributed without any warranty, see:
8 * <http://creativecommons.org/publicdomain/zero/1.0/>.
9 */
10
11 #include <bsddialog.h>
12 #include <locale.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16
17 #define H BSDDIALOG_FIELDHIDDEN
18 #define RO BSDDIALOG_FIELDREADONLY
19
main()20 int main()
21 {
22 int i, output;
23 struct bsddialog_conf conf;
24 struct bsddialog_formitem items[3] = {
25 {"Input:", 0, 0, "value", 0, 10, 30, 50, NULL, 0, "desc 1"},
26 {"Input:", 1, 0, "read only", 1, 10, 30, 50, NULL, RO, "desc 2"},
27 {"Password:", 2, 0, "", 2, 10, 30, 50, NULL, H, "desc 3"}
28 };
29
30 /* Optional, unless for unicode/multi-column characters */
31 setlocale(LC_ALL, "");
32
33 if (bsddialog_init() == BSDDIALOG_ERROR) {
34 printf("Error: %s\n", bsddialog_geterror());
35 return (1);
36 }
37 bsddialog_initconf(&conf);
38 conf.title = "form";
39 conf.form.securech = '*';
40 output = bsddialog_form(&conf, "Example", 10, 50, 3, 3, items);
41 bsddialog_end();
42
43 if (output == BSDDIALOG_ERROR) {
44 printf("Error: %s", bsddialog_geterror());
45 return (1);
46 }
47
48 if (output == BSDDIALOG_CANCEL) {
49 printf("Cancel\n");
50 return (0);
51 }
52
53 for (i = 0; i < 3; i++) {
54 printf("%s \"%s\"\n", items[i].label, items[i].value);
55 free(items[i].value);
56 }
57
58 return (output);
59 }
60