/*
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
*
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/** @file
*
* Menu commands
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <ipxe/parseopt.h>
#include <ipxe/settings.h>
#include <ipxe/features.h>
/** "menu" options */
struct menu_options {
/** Name */
const char *name;
/** Delete */
int delete;
};
/** "menu" option list */
};
/** "menu" command descriptor */
"[--name <name>] [--delete] [<title>]" );
/**
* The "menu" command
*
* @v argc Argument count
* @v argv Argument list
* @ret rc Return status code
*/
char *title;
int rc;
/* Parse options */
goto err_parse_options;
/* Parse title */
if ( ! title ) {
goto err_parse_title;
}
/* Create menu */
if ( ! menu ) {
goto err_create_menu;
}
/* Destroy menu, if applicable */
destroy_menu ( menu );
/* Success */
rc = 0;
return rc;
}
/** "item" options */
struct item_options {
/** Menu name */
const char *menu;
/** Shortcut key */
unsigned int key;
/** Use as default */
int is_default;
/** Use as a separator */
int is_gap;
};
/** "item" option list */
};
/** "item" command descriptor */
"[--menu <menu>] [--key <key>] [--default] "
"[<label>|--gap [<text>]]" );
/**
* The "item" command
*
* @v argc Argument count
* @v argv Argument list
* @ret rc Return status code
*/
int rc;
/* Parse options */
goto err_parse_options;
/* Parse label, if present */
/* Parse text, if present */
if ( ! text ) {
goto err_parse_text;
}
}
/* Identify menu */
goto err_parse_menu;
/* Add menu item */
if ( ! item ) {
goto err_add_menu_item;
}
/* Success */
rc = 0;
return rc;
}
/** "choose" options */
struct choose_options {
/** Menu name */
const char *menu;
/** Timeout */
unsigned int timeout;
/** Default selection */
const char *select;
/** Keep menu */
int keep;
};
/** "choose" option list */
};
/** "choose" command descriptor */
"[--menu <menu>] [--default <label>] "
"[--timeout <timeout>] [--keep] <setting>" );
/**
* The "choose" command
*
* @v argc Argument count
* @v argv Argument list
* @ret rc Return status code
*/
const char *setting;
int rc;
/* Parse options */
goto err_parse_options;
/* Parse setting name */
/* Identify menu */
goto err_parse_menu;
/* Show menu */
goto err_show_menu;
/* Store setting */
printf ( "Could not store \"%s\": %s\n",
goto err_store;
}
/* Success */
rc = 0;
/* Destroy menu, if applicable */
destroy_menu ( menu );
return rc;
}
/** Menu commands */
{
.name = "menu",
},
{
.name = "item",
},
{
.name = "choose",
.exec = choose_exec,
},
};