1 #include <stdint.h> 2 #include <stdlib.h> 3 #include <stdio.h> 4 #include <string.h> 5 #include <errno.h> 6 #include <getopt.h> 7 #include <gpxe/settings.h> 8 #include <gpxe/command.h> 9 10 FILE_LICENCE ( GPL2_OR_LATER ); 11 12 static int show_exec ( int argc, char **argv ) { 13 char buf[256]; 14 int rc; 15 16 if ( argc != 2 ) { 17 printf ( "Syntax: %s <identifier>\n", argv[0] ); 18 return 1; 19 } 20 21 if ( ( rc = fetchf_named_setting ( argv[1], buf, 22 sizeof ( buf ) ) ) < 0 ){ 23 printf ( "Could not find \"%s\": %s\n", 24 argv[1], strerror ( rc ) ); 25 return 1; 26 } 27 28 printf ( "%s = %s\n", argv[1], buf ); 29 return 0; 30 } 31 32 static int set_exec ( int argc, char **argv ) { 33 int rc; 34 35 if ( argc != 3 ) { 36 printf ( "Syntax: %s <identifier> <value>\n", argv[0] ); 37 return 1; 38 } 39 40 if ( ( rc = storef_named_setting ( argv[1], argv[2] ) ) != 0 ) { 41 printf ( "Could not set \"%s\"=\"%s\": %s\n", 42 argv[1], argv[2], strerror ( rc ) ); 43 return 1; 44 } 45 46 return 0; 47 } 48 49 static int clear_exec ( int argc, char **argv ) { 50 int rc; 51 52 if ( argc != 2 ) { 53 printf ( "Syntax: %s <identifier>\n", argv[0] ); 54 return 1; 55 } 56 57 if ( ( rc = delete_named_setting ( argv[1] ) ) != 0 ) { 58 printf ( "Could not clear \"%s\": %s\n", 59 argv[1], strerror ( rc ) ); 60 return 1; 61 } 62 63 return 0; 64 } 65 66 struct command nvo_commands[] __command = { 67 { 68 .name = "show", 69 .exec = show_exec, 70 }, 71 { 72 .name = "set", 73 .exec = set_exec, 74 }, 75 { 76 .name = "clear", 77 .exec = clear_exec, 78 }, 79 }; 80