iPXE
dynui_cmd.c File Reference

Dynamic user interface commands. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <ipxe/dynui.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <ipxe/settings.h>
#include <ipxe/features.h>

Go to the source code of this file.

Data Structures

struct  dynui_options
 "dynui" options More...
struct  item_options
 "item" options More...
struct  choose_options
 "choose" options More...
struct  present_options
 "present" options More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
 FEATURE (FEATURE_MISC, "Menu", DHCP_EB_FEATURE_MENU, 1)
static int dynui_exec (int argc, char **argv)
 The "dynui" command.
static int item_exec (int argc, char **argv)
 The "item" command.
static int choose_exec (int argc, char **argv)
 The "choose" command.
static int present_exec (int argc, char **argv)
 The "present" command.
 COMMAND (menu, dynui_exec)
 Dynamic user interface commands.
 COMMAND (form, dynui_exec)
 COMMAND (item, item_exec)
 COMMAND (choose, choose_exec)
 COMMAND (present, present_exec)

Variables

static struct option_descriptor dynui_opts []
 "dynui" option list
static struct command_descriptor dynui_cmd
 "dynui" command descriptor
static struct option_descriptor item_opts []
 "item" option list
static struct command_descriptor item_cmd
 "item" command descriptor
static struct option_descriptor choose_opts []
 "choose" option list
static struct command_descriptor choose_cmd
 "choose" command descriptor
static struct option_descriptor present_opts []
 "present" option list
static struct command_descriptor present_cmd
 "present" command descriptor

Detailed Description

Dynamic user interface commands.

Definition in file dynui_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ FEATURE()

FEATURE ( FEATURE_MISC ,
"Menu" ,
DHCP_EB_FEATURE_MENU ,
1  )

◆ dynui_exec()

int dynui_exec ( int argc,
char ** argv )
static

The "dynui" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 74 of file dynui_cmd.c.

74 {
75 struct dynui_options opts;
76 struct dynamic_ui *dynui;
77 char *title;
78 int rc;
79
80 /* Parse options */
81 if ( ( rc = parse_options ( argc, argv, &dynui_cmd, &opts ) ) != 0 )
82 goto err_parse_options;
83
84 /* Parse title */
85 title = concat_args ( &argv[optind] );
86 if ( ! title ) {
87 rc = -ENOMEM;
88 goto err_parse_title;
89 }
90
91 /* Create dynamic user interface */
92 dynui = create_dynui ( opts.name, title );
93 if ( ! dynui ) {
94 rc = -ENOMEM;
95 goto err_create_dynui;
96 }
97
98 /* Destroy dynamic user interface, if applicable */
99 if ( opts.delete )
100 destroy_dynui ( dynui );
101
102 /* Success */
103 rc = 0;
104
105 err_create_dynui:
106 free ( title );
107 err_parse_title:
108 err_parse_options:
109 return rc;
110}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
void destroy_dynui(struct dynamic_ui *dynui)
Destroy dynamic user interface.
Definition dynui.c:150
struct dynamic_ui * create_dynui(const char *name, const char *title)
Create dynamic user interface.
Definition dynui.c:49
static struct command_descriptor dynui_cmd
"dynui" command descriptor
Definition dynui_cmd.c:63
char * concat_args(char **args)
Concatenate arguments.
Definition exec.c:359
int optind
Current option index.
Definition getopt.c:52
#define ENOMEM
Not enough space.
Definition errno.h:535
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
A dynamic user interface.
Definition dynui.h:16
const char * title
Title.
Definition dynui.h:22
"dynui" options
Definition dynui_cmd.c:47

References concat_args(), create_dynui(), destroy_dynui(), dynui_cmd, ENOMEM, free, optind, opts, parse_options(), rc, and dynamic_ui::title.

Referenced by COMMAND(), and COMMAND().

◆ item_exec()

int item_exec ( int argc,
char ** argv )
static

The "item" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 154 of file dynui_cmd.c.

154 {
155 struct item_options opts;
156 struct dynamic_ui *dynui;
157 struct dynamic_item *item;
158 unsigned int flags = 0;
159 char *name = NULL;
160 char *text = NULL;
161 int rc;
162
163 /* Parse options */
164 if ( ( rc = parse_options ( argc, argv, &item_cmd, &opts ) ) != 0 )
165 goto err_parse_options;
166
167 /* Parse name, if present */
168 if ( ! opts.is_gap )
169 name = argv[optind++]; /* May be NULL */
170
171 /* Parse text, if present */
172 if ( optind < argc ) {
173 text = concat_args ( &argv[optind] );
174 if ( ! text ) {
175 rc = -ENOMEM;
176 goto err_parse_text;
177 }
178 }
179
180 /* Identify dynamic user interface */
181 if ( ( rc = parse_dynui ( opts.dynui, &dynui ) ) != 0 )
182 goto err_parse_dynui;
183
184 /* Add dynamic user interface item */
185 if ( opts.is_default )
187 if ( opts.is_secret )
189 item = add_dynui_item ( dynui, name, ( text ? text : "" ), flags,
190 opts.key );
191 if ( ! item ) {
192 rc = -ENOMEM;
193 goto err_add_dynui_item;
194 }
195
196 /* Success */
197 rc = 0;
198
199 err_add_dynui_item:
200 err_parse_dynui:
201 free ( text );
202 err_parse_text:
203 err_parse_options:
204 return rc;
205}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
const char * name
Definition ath9k_hw.c:1986
struct dynamic_item * add_dynui_item(struct dynamic_ui *dynui, const char *name, const char *text, unsigned int flags, int shortcut)
Add dynamic user interface item.
Definition dynui.c:104
#define DYNUI_DEFAULT
Dynamic user interface item is default selection.
Definition dynui.h:46
#define DYNUI_SECRET
Dynamic user interface item represents a secret.
Definition dynui.h:49
static struct command_descriptor item_cmd
"item" command descriptor
Definition dynui_cmd.c:143
uint8_t flags
Flags.
Definition ena.h:7
int parse_dynui(char *text, struct dynamic_ui **dynui)
Parse dynamic user interface name.
Definition parseopt.c:204
A dynamic user interface item.
Definition dynui.h:30
const char * text
Text.
Definition dynui.h:36
"item" options
Definition dynui_cmd.c:113

References add_dynui_item(), concat_args(), DYNUI_DEFAULT, DYNUI_SECRET, ENOMEM, flags, free, item_cmd, name, NULL, optind, opts, parse_dynui(), parse_options(), rc, and dynamic_item::text.

Referenced by COMMAND().

◆ choose_exec()

int choose_exec ( int argc,
char ** argv )
static

The "choose" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 246 of file dynui_cmd.c.

246 {
247 struct choose_options opts;
248 struct named_setting setting;
249 struct dynamic_ui *dynui;
250 struct dynamic_item *item;
251 int rc;
252
253 /* Parse options */
254 if ( ( rc = parse_options ( argc, argv, &choose_cmd, &opts ) ) != 0 )
255 goto err_parse_options;
256
257 /* Parse setting name */
258 if ( ( rc = parse_autovivified_setting ( argv[optind],
259 &setting ) ) != 0 )
260 goto err_parse_setting;
261
262 /* Identify dynamic user interface */
263 if ( ( rc = parse_dynui ( opts.dynui, &dynui ) ) != 0 )
264 goto err_parse_dynui;
265
266 /* Show as menu */
267 if ( ( rc = show_menu ( dynui, opts.timeout, opts.retimeout,
268 opts.select, &item ) ) != 0 )
269 goto err_show_menu;
270
271 /* Apply default type if necessary */
272 if ( ! setting.setting.type )
273 setting.setting.type = &setting_type_string;
274
275 /* Store setting */
276 if ( ( rc = storef_setting ( setting.settings, &setting.setting,
277 item->name ) ) != 0 ) {
278 printf ( "Could not store \"%s\": %s\n",
279 setting.setting.name, strerror ( rc ) );
280 goto err_store;
281 }
282
283 /* Success */
284 rc = 0;
285
286 err_store:
287 err_show_menu:
288 /* Destroy dynamic user interface, if applicable */
289 if ( ! opts.keep )
290 destroy_dynui ( dynui );
291 err_parse_dynui:
292 err_parse_setting:
293 err_parse_options:
294 return rc;
295}
static struct command_descriptor choose_cmd
"choose" command descriptor
Definition dynui_cmd.c:236
int show_menu(struct dynamic_ui *dynui, unsigned long timeout, unsigned long retimeout, const char *select, struct dynamic_item **selected)
Show menu.
Definition menu_ui.c:252
int parse_autovivified_setting(char *text, struct named_setting *setting)
Parse and autovivify setting name.
Definition parseopt.c:337
int storef_setting(struct settings *settings, const struct setting *setting, const char *value)
Store formatted value of setting.
Definition settings.c:1320
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
"choose" options
Definition dynui_cmd.c:208
const char * name
Name.
Definition dynui.h:34
A parsed named setting.
Definition parseopt.h:123
A setting.
Definition settings.h:24
const char * name
Name.
Definition settings.h:29
const struct setting_type * type
Setting type.
Definition settings.h:37
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465

References choose_cmd, destroy_dynui(), dynamic_item::name, setting::name, optind, opts, parse_autovivified_setting(), parse_dynui(), parse_options(), printf(), rc, show_menu(), storef_setting(), strerror(), and setting::type.

Referenced by COMMAND().

◆ present_exec()

int present_exec ( int argc,
char ** argv )
static

The "present" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 324 of file dynui_cmd.c.

324 {
325 struct present_options opts;
326 struct dynamic_ui *dynui;
327 int rc;
328
329 /* Parse options */
330 if ( ( rc = parse_options ( argc, argv, &present_cmd, &opts ) ) != 0 )
331 goto err_parse_options;
332
333 /* Identify dynamic user interface */
334 if ( ( rc = parse_dynui ( opts.dynui, &dynui ) ) != 0 )
335 goto err_parse_dynui;
336
337 /* Show as form */
338 if ( ( rc = show_form ( dynui ) ) != 0 )
339 goto err_show_form;
340
341 /* Success */
342 rc = 0;
343
344 err_show_form:
345 /* Destroy dynamic user interface, if applicable */
346 if ( ! opts.keep )
347 destroy_dynui ( dynui );
348 err_parse_dynui:
349 err_parse_options:
350 return rc;
351}
static struct command_descriptor present_cmd
"present" command descriptor
Definition dynui_cmd.c:314
int show_form(struct dynamic_ui *dynui)
Show form.
Definition form_ui.c:508
"present" options
Definition dynui_cmd.c:298

References destroy_dynui(), opts, parse_dynui(), parse_options(), present_cmd, rc, and show_form().

Referenced by COMMAND().

◆ COMMAND() [1/5]

COMMAND ( menu ,
dynui_exec  )

Dynamic user interface commands.

References dynui_exec().

◆ COMMAND() [2/5]

COMMAND ( form ,
dynui_exec  )

References dynui_exec().

◆ COMMAND() [3/5]

COMMAND ( item ,
item_exec  )

References item_exec().

◆ COMMAND() [4/5]

COMMAND ( choose ,
choose_exec  )

References choose_exec().

◆ COMMAND() [5/5]

COMMAND ( present ,
present_exec  )

References present_exec().

Variable Documentation

◆ dynui_opts

struct option_descriptor dynui_opts[]
static
Initial value:
= {
OPTION_DESC ( "delete", 'd', no_argument,
struct dynui_options, delete, parse_flag ),
}
@ required_argument
Option requires an argument.
Definition getopt.h:19
@ no_argument
Option does not take an argument.
Definition getopt.h:17
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition parseopt.c:227
int parse_string(char *text, char **value)
Parse string value.
Definition parseopt.c:74
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition parseopt.h:68

"dynui" option list

Definition at line 55 of file dynui_cmd.c.

55 {
56 OPTION_DESC ( "name", 'n', required_argument,
58 OPTION_DESC ( "delete", 'd', no_argument,
59 struct dynui_options, delete, parse_flag ),
60};

◆ dynui_cmd

struct command_descriptor dynui_cmd
static
Initial value:
=
"[<title>]" )
static struct option_descriptor dynui_opts[]
"dynui" option list
Definition dynui_cmd.c:55
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition parseopt.h:98
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109

"dynui" command descriptor

Definition at line 63 of file dynui_cmd.c.

Referenced by dynui_exec(), and PROVIDE_REQUIRING_SYMBOL().

◆ item_opts

struct option_descriptor item_opts[]
static
Initial value:
= {
struct item_options, dynui, parse_string ),
struct item_options, dynui, parse_string ),
OPTION_DESC ( "default", 'd', no_argument,
struct item_options, is_default, parse_flag ),
OPTION_DESC ( "secret", 's', no_argument,
struct item_options, is_secret, parse_flag ),
OPTION_DESC ( "gap", 'g', no_argument,
struct item_options, is_gap, parse_flag ),
}
union @162305117151260234136356364136041353210355154177 key
Sense key.
Definition scsi.h:3
int parse_key(char *text, unsigned int *key)
Parse key.
Definition parseopt.c:242

"item" option list

Definition at line 127 of file dynui_cmd.c.

127 {
128 OPTION_DESC ( "menu", 'm', required_argument,
129 struct item_options, dynui, parse_string ),
130 OPTION_DESC ( "form", 'f', required_argument,
131 struct item_options, dynui, parse_string ),
132 OPTION_DESC ( "key", 'k', required_argument,
133 struct item_options, key, parse_key ),
134 OPTION_DESC ( "default", 'd', no_argument,
135 struct item_options, is_default, parse_flag ),
136 OPTION_DESC ( "secret", 's', no_argument,
137 struct item_options, is_secret, parse_flag ),
138 OPTION_DESC ( "gap", 'g', no_argument,
139 struct item_options, is_gap, parse_flag ),
140};

◆ item_cmd

struct command_descriptor item_cmd
static
Initial value:
=
"[<name> [<text>]]" )
static struct option_descriptor item_opts[]
"item" option list
Definition dynui_cmd.c:127

"item" command descriptor

Definition at line 143 of file dynui_cmd.c.

Referenced by item_exec().

◆ choose_opts

struct option_descriptor choose_opts[]
static
Initial value:
= {
struct choose_options, dynui, parse_string ),
OPTION_DESC ( "default", 'd', required_argument,
OPTION_DESC ( "timeout", 't', required_argument,
OPTION_DESC ( "retimeout", 'r', required_argument,
struct choose_options, retimeout, parse_timeout ),
OPTION_DESC ( "keep", 'k', no_argument,
struct choose_options, keep, parse_flag ),
}
void timeout(int)
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition parseopt.c:115
int select(fd_set *readfds, int wait)
Check file descriptors for readiness.
Definition posix_io.c:229

"choose" option list

Definition at line 222 of file dynui_cmd.c.

222 {
223 OPTION_DESC ( "menu", 'm', required_argument,
224 struct choose_options, dynui, parse_string ),
225 OPTION_DESC ( "default", 'd', required_argument,
227 OPTION_DESC ( "timeout", 't', required_argument,
229 OPTION_DESC ( "retimeout", 'r', required_argument,
230 struct choose_options, retimeout, parse_timeout ),
231 OPTION_DESC ( "keep", 'k', no_argument,
232 struct choose_options, keep, parse_flag ),
233};

◆ choose_cmd

struct command_descriptor choose_cmd
static
Initial value:
=
COMMAND_DESC ( struct choose_options, choose_opts, 1, 1, "<setting>" )
static struct option_descriptor choose_opts[]
"choose" option list
Definition dynui_cmd.c:222

"choose" command descriptor

Definition at line 236 of file dynui_cmd.c.

Referenced by choose_exec().

◆ present_opts

struct option_descriptor present_opts[]
static
Initial value:
= {
struct present_options, dynui, parse_string ),
OPTION_DESC ( "keep", 'k', no_argument,
struct present_options, keep, parse_flag ),
}

"present" option list

Definition at line 306 of file dynui_cmd.c.

306 {
307 OPTION_DESC ( "form", 'f', required_argument,
308 struct present_options, dynui, parse_string ),
309 OPTION_DESC ( "keep", 'k', no_argument,
310 struct present_options, keep, parse_flag ),
311};

◆ present_cmd

struct command_descriptor present_cmd
static
Initial value:
=
static struct option_descriptor present_opts[]
"present" option list
Definition dynui_cmd.c:306

"present" command descriptor

Definition at line 314 of file dynui_cmd.c.

Referenced by present_exec().