2006-12-05 00:40:35 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2007-01-19 02:13:12 +01:00
|
|
|
#include <stdio.h>
|
2006-12-05 00:40:35 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2006-12-08 02:26:11 +01:00
|
|
|
#include <getopt.h>
|
2010-04-19 21:16:01 +02:00
|
|
|
#include <ipxe/settings.h>
|
|
|
|
#include <ipxe/command.h>
|
2006-12-05 00:40:35 +01:00
|
|
|
|
2009-05-01 16:41:06 +02:00
|
|
|
FILE_LICENCE ( GPL2_OR_LATER );
|
|
|
|
|
2006-12-05 00:40:35 +01:00
|
|
|
static int show_exec ( int argc, char **argv ) {
|
2006-12-05 03:40:03 +01:00
|
|
|
char buf[256];
|
|
|
|
int rc;
|
2006-12-05 00:40:35 +01:00
|
|
|
|
2006-12-05 03:40:03 +01:00
|
|
|
if ( argc != 2 ) {
|
|
|
|
printf ( "Syntax: %s <identifier>\n", argv[0] );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-03-25 21:46:16 +01:00
|
|
|
if ( ( rc = fetchf_named_setting ( argv[1], buf,
|
|
|
|
sizeof ( buf ) ) ) < 0 ){
|
2006-12-05 03:40:03 +01:00
|
|
|
printf ( "Could not find \"%s\": %s\n",
|
2008-03-20 05:06:07 +01:00
|
|
|
argv[1], strerror ( rc ) );
|
2006-12-05 03:40:03 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ( "%s = %s\n", argv[1], buf );
|
|
|
|
return 0;
|
2006-12-05 00:40:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int set_exec ( int argc, char **argv ) {
|
2010-09-21 15:54:07 +02:00
|
|
|
size_t len;
|
|
|
|
int i;
|
2006-12-05 03:40:03 +01:00
|
|
|
int rc;
|
2006-12-05 00:40:35 +01:00
|
|
|
|
2010-09-21 15:54:07 +02:00
|
|
|
if ( argc < 3 ) {
|
2008-03-20 05:06:07 +01:00
|
|
|
printf ( "Syntax: %s <identifier> <value>\n", argv[0] );
|
2006-12-05 00:40:35 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-09-21 15:54:07 +02:00
|
|
|
/* Determine total length of command line */
|
|
|
|
len = 1; /* NUL */
|
|
|
|
for ( i = 2 ; i < argc ; i++ )
|
|
|
|
len += ( 1 /* possible space */ + strlen ( argv[i] ) );
|
|
|
|
|
|
|
|
{
|
|
|
|
char buf[len];
|
|
|
|
char *ptr = buf;
|
|
|
|
|
|
|
|
/* Assemble command line */
|
|
|
|
buf[0] = '\0';
|
|
|
|
for ( i = 2 ; i < argc ; i++ ) {
|
|
|
|
ptr += sprintf ( ptr, "%s%s", ( buf[0] ? " " : "" ),
|
|
|
|
argv[i] );
|
|
|
|
}
|
|
|
|
assert ( ptr < ( buf + len ) );
|
|
|
|
|
|
|
|
if ( ( rc = storef_named_setting ( argv[1], buf ) ) != 0 ) {
|
|
|
|
printf ( "Could not set \"%s\"=\"%s\": %s\n",
|
|
|
|
argv[1], buf, strerror ( rc ) );
|
|
|
|
return 1;
|
|
|
|
}
|
2006-12-05 00:40:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-12 16:52:19 +01:00
|
|
|
static int clear_exec ( int argc, char **argv ) {
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if ( argc != 2 ) {
|
2008-03-20 05:06:07 +01:00
|
|
|
printf ( "Syntax: %s <identifier>\n", argv[0] );
|
2006-12-12 16:52:19 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-03-20 05:06:07 +01:00
|
|
|
if ( ( rc = delete_named_setting ( argv[1] ) ) != 0 ) {
|
2006-12-12 16:52:19 +01:00
|
|
|
printf ( "Could not clear \"%s\": %s\n",
|
2008-03-20 05:06:07 +01:00
|
|
|
argv[1], strerror ( rc ) );
|
2006-12-12 16:52:19 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-10 06:13:20 +01:00
|
|
|
struct command nvo_commands[] __command = {
|
|
|
|
{
|
|
|
|
.name = "show",
|
|
|
|
.exec = show_exec,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "set",
|
|
|
|
.exec = set_exec,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "clear",
|
|
|
|
.exec = clear_exec,
|
|
|
|
},
|
2006-12-12 16:52:19 +01:00
|
|
|
};
|