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