Annotation of qemu/roms/ipxe/src/hci/commands/config_cmd.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (C) 2010 Michael Brown <[email protected]>.
                      3:  *
                      4:  * This program is free software; you can redistribute it and/or
                      5:  * modify it under the terms of the GNU General Public License as
                      6:  * published by the Free Software Foundation; either version 2 of the
                      7:  * License, or any later version.
                      8:  *
                      9:  * This program is distributed in the hope that it will be useful, but
                     10:  * WITHOUT ANY WARRANTY; without even the implied warranty of
                     11:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     12:  * General Public License for more details.
                     13:  *
                     14:  * You should have received a copy of the GNU General Public License
                     15:  * along with this program; if not, write to the Free Software
                     16:  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
                     17:  */
                     18: 
                     19: #include <string.h>
                     20: #include <stdio.h>
                     21: #include <errno.h>
                     22: #include <getopt.h>
                     23: #include <ipxe/command.h>
                     24: #include <ipxe/parseopt.h>
                     25: #include <ipxe/settings.h>
                     26: #include <ipxe/settings_ui.h>
                     27: 
                     28: FILE_LICENCE ( GPL2_OR_LATER );
                     29: 
                     30: /** @file
                     31:  *
                     32:  * Configuration UI commands
                     33:  *
                     34:  */
                     35: 
                     36: /** "config" options */
                     37: struct config_options {};
                     38: 
                     39: /** "config" option list */
                     40: static struct option_descriptor config_opts[] = {};
                     41: 
                     42: /** "config" command descriptor */
                     43: static struct command_descriptor config_cmd =
                     44:        COMMAND_DESC ( struct config_options, config_opts, 0, 1, "[<scope>]" );
                     45: 
                     46: /**
                     47:  * Parse settings scope name
                     48:  *
                     49:  * @v text             Text
                     50:  * @ret value          Integer value
                     51:  * @ret rc             Return status code
                     52:  */
                     53: static int parse_settings ( const char *text, struct settings **value ) {
                     54: 
                     55:        /* Sanity check */
                     56:        assert ( text != NULL );
                     57: 
                     58:        /* Parse scope name */
                     59:        *value = find_settings ( text );
                     60:        if ( ! *value ) {
                     61:                printf ( "\"%s\": no such scope\n", text );
                     62:                return -EINVAL;
                     63:        }
                     64: 
                     65:        return 0;
                     66: }
                     67: 
                     68: /**
                     69:  * "config" command
                     70:  *
                     71:  * @v argc             Argument count
                     72:  * @v argv             Argument list
                     73:  * @ret rc             Return status code
                     74:  */
                     75: static int config_exec ( int argc, char **argv ) {
                     76:        struct config_options opts;
                     77:        struct settings *settings;
                     78:        int rc;
                     79: 
                     80:        /* Parse options */
                     81:        if ( ( rc = parse_options ( argc, argv, &config_cmd, &opts ) ) != 0 )
                     82:                return rc;
                     83: 
                     84:        /* Parse settings option, if present */
                     85:        if ( ( rc = parse_settings ( ( ( optind < argc ) ? argv[optind] : "" ),
                     86:                                     &settings ) ) != 0 )
                     87:                return rc;
                     88: 
                     89:        /* Run settings UI */
                     90:        if ( ( rc = settings_ui ( settings ) ) != 0 ) {
                     91:                printf ( "Could not save settings: %s\n", strerror ( rc ) );
                     92:                return rc;
                     93:        }
                     94: 
                     95:        return 0;
                     96: }
                     97: 
                     98: /** Configuration UI commands */
                     99: struct command config_command __command = {
                    100:        .name = "config",
                    101:        .exec = config_exec,
                    102: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.