Changeset 68b5dd11 in mainline for uspace/lib/clui/nchoice.c
- Timestamp:
- 2015-10-20T10:08:15Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b598460a
- Parents:
- 44fe800
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/clui/nchoice.c
r44fe800 r68b5dd11 35 35 #include <errno.h> 36 36 #include <nchoice.h> 37 #include <stdio.h> 37 38 #include <stdlib.h> 38 39 #include <str.h> … … 94 95 } 95 96 96 #include <stdio.h>97 97 /** Add option to numerical choice */ 98 int nchoice_add(nchoice_t *choice, const char *opttext, void *arg) 98 int nchoice_add(nchoice_t *choice, const char *opttext, void *arg, 99 nchoice_flag_t flags) 99 100 { 100 101 nchoice_opt_t *opt; … … 114 115 opt->arg = arg; 115 116 list_append(&opt->lchoice, &choice->opts); 117 118 if ((flags & ncf_default) != 0) { 119 /* Set this option as the default */ 120 assert(choice->def_opt == NULL); 121 122 choice->def_opt = opt; 123 } 124 116 125 return EOK; 117 126 } … … 125 134 unsigned long c; 126 135 char *eptr; 136 char *istr; 137 int def_i; 127 138 128 139 again: 129 140 printf("%s\n", choice->prompt); 130 141 142 def_i = 0; 131 143 i = 1; 132 144 list_foreach(choice->opts, lchoice, nchoice_opt_t, opt) { 133 printf("%d: %s\n", i, opt->text); 145 printf("%d: %s%s\n", i, opt->text, opt == choice->def_opt ? 146 " [default]" : ""); 147 if (opt == choice->def_opt) 148 def_i = i; 134 149 ++i; 135 150 } 136 151 137 rc = tinput_read(choice->tinput, &str); 152 if (def_i > 0) { 153 rc = asprintf(&istr, "%d", def_i); 154 if (rc < 0) 155 return ENOMEM; 156 } else { 157 istr = str_dup(""); 158 if (istr == NULL) 159 return ENOMEM; 160 } 161 162 rc = tinput_read_i(choice->tinput, istr, &str); 163 free(istr); 164 138 165 if (rc != EOK) { 139 166 assert(rc == EIO || rc == ENOENT);
Note:
See TracChangeset
for help on using the changeset viewer.