123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
-
-
- #include <stdint.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <getopt.h>
- #include <ipxe/settings.h>
- #include <ipxe/command.h>
- #include <ipxe/parseopt.h>
-
- FILE_LICENCE ( GPL2_OR_LATER );
-
-
-
-
- struct show_options {};
-
-
- static struct option_descriptor show_opts[] = {};
-
-
- static struct command_descriptor show_cmd =
- COMMAND_DESC ( struct show_options, show_opts, 1, 1, "<setting>" );
-
-
- static int show_exec ( int argc, char **argv ) {
- struct show_options opts;
- const char *name;
- char buf[256];
- int rc;
-
-
- if ( ( rc = parse_options ( argc, argv, &show_cmd, &opts ) ) != 0 )
- return rc;
-
-
- name = argv[optind];
-
-
- if ( ( rc = fetchf_named_setting ( name, buf,
- sizeof ( buf ) ) ) < 0 ) {
- printf ( "Could not find \"%s\": %s\n",
- name, strerror ( rc ) );
- return rc;
- }
-
-
- printf ( "%s = %s\n", name, buf );
-
- return 0;
- }
-
-
- struct set_options {};
-
-
- static struct option_descriptor set_opts[] = {};
-
-
- static struct command_descriptor set_cmd =
- COMMAND_DESC ( struct set_options, set_opts, 1, MAX_ARGUMENTS,
- "<setting> <value>" );
-
-
- static int set_exec ( int argc, char **argv ) {
- struct set_options opts;
- const char *name;
- char *value;
- int rc;
-
-
- if ( ( rc = parse_options ( argc, argv, &set_cmd, &opts ) ) != 0 )
- goto err_parse_options;
-
-
- name = argv[optind];
-
-
- value = concat_args ( &argv[ optind + 1 ] );
- if ( ! value ) {
- rc = -ENOMEM;
- goto err_concat_args;
- }
-
-
- if ( ( rc = storef_named_setting ( name, value ) ) != 0 ) {
- printf ( "Could not set \"%s\"=\"%s\": %s\n",
- name, value, strerror ( rc ) );
- goto err_store;
- }
-
- free ( value );
- return 0;
-
- err_store:
- free ( value );
- err_concat_args:
- err_parse_options:
- return rc;
- }
-
-
- struct clear_options {};
-
-
- static struct option_descriptor clear_opts[] = {};
-
-
- static struct command_descriptor clear_cmd =
- COMMAND_DESC ( struct clear_options, clear_opts, 1, 1, "<setting>" );
-
-
- static int clear_exec ( int argc, char **argv ) {
- struct clear_options opts;
- const char *name;
- int rc;
-
-
- if ( ( rc = parse_options ( argc, argv, &clear_cmd, &opts ) ) != 0 )
- return rc;
-
-
- name = argv[optind];
-
-
- if ( ( rc = delete_named_setting ( name ) ) != 0 ) {
- printf ( "Could not clear \"%s\": %s\n",
- name, strerror ( rc ) );
- return rc;
- }
-
- return 0;
- }
-
-
- struct command nvo_commands[] __command = {
- {
- .name = "show",
- .exec = show_exec,
- },
- {
- .name = "set",
- .exec = set_exec,
- },
- {
- .name = "clear",
- .exec = clear_exec,
- },
- };
|