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 <stdio.h> 13 #include <stdlib.h> 14 #include <string.h> 15 16 #define H BSDDIALOG_FIELDHIDDEN 17 #define RO BSDDIALOG_FIELDREADONLY 18 19 int main() 20 { 21 int i, output; 22 struct bsddialog_conf conf; 23 struct bsddialog_formitem items[3] = { 24 {"Input:", 1, 1, "value", 1, 11, 30, 50, NULL, 0, "desc 1"}, 25 {"Input:", 2, 1, "read only", 2, 11, 30, 50, NULL, RO, "desc 2"}, 26 {"Password:", 3, 1, "", 3, 11, 30, 50, NULL, H, "desc 3"} 27 }; 28 29 if (bsddialog_init() == BSDDIALOG_ERROR) { 30 printf("Error: %s\n", bsddialog_geterror()); 31 return (1); 32 } 33 34 bsddialog_initconf(&conf); 35 conf.title = "form"; 36 conf.form.securech = '*'; 37 output = bsddialog_form(&conf, "Example", 10, 50, 3, 3, items); 38 39 bsddialog_end(); 40 41 if (output == BSDDIALOG_ERROR) { 42 printf("Error: %s", bsddialog_geterror()); 43 return (1); 44 } 45 46 if (output == BSDDIALOG_CANCEL) { 47 printf("Cancel\n"); 48 return (0); 49 } 50 51 for (i = 0; i < 3; i++) { 52 printf("%s \"%s\"\n", items[i].label, items[i].value); 53 free(items[i].value); 54 } 55 56 return (output); 57 }