nvo_cmd.c

Go to the documentation of this file.
00001 #include <stdint.h>
00002 #include <stdlib.h>
00003 #include <stdio.h>
00004 #include <string.h>
00005 #include <errno.h>
00006 #include <getopt.h>
00007 #include <gpxe/settings.h>
00008 #include <gpxe/command.h>
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER );
00011 
00012 static int show_exec ( int argc, char **argv ) {
00013         char buf[256];
00014         int rc;
00015 
00016         if ( argc != 2 ) {
00017                 printf ( "Syntax: %s <identifier>\n", argv[0] );
00018                 return 1;
00019         }
00020 
00021         if ( ( rc = fetchf_named_setting ( argv[1], buf,
00022                                            sizeof ( buf ) ) ) < 0 ){
00023                 printf ( "Could not find \"%s\": %s\n",
00024                          argv[1], strerror ( rc ) );
00025                 return 1;
00026         }
00027 
00028         printf ( "%s = %s\n", argv[1], buf );
00029         return 0;
00030 }
00031 
00032 static int set_exec ( int argc, char **argv ) {
00033         int rc;
00034 
00035         if ( argc != 3 ) {
00036                 printf ( "Syntax: %s <identifier> <value>\n", argv[0] );
00037                 return 1;
00038         }
00039 
00040         if ( ( rc = storef_named_setting ( argv[1], argv[2] ) ) != 0 ) {
00041                 printf ( "Could not set \"%s\"=\"%s\": %s\n",
00042                          argv[1], argv[2], strerror ( rc ) );
00043                 return 1;
00044         }
00045 
00046         return 0;
00047 }
00048 
00049 static int clear_exec ( int argc, char **argv ) {
00050         int rc;
00051 
00052         if ( argc != 2 ) {
00053                 printf ( "Syntax: %s <identifier>\n", argv[0] );
00054                 return 1;
00055         }
00056 
00057         if ( ( rc = delete_named_setting ( argv[1] ) ) != 0 ) {
00058                 printf ( "Could not clear \"%s\": %s\n",
00059                          argv[1], strerror ( rc ) );
00060                 return 1;
00061         }
00062         
00063         return 0;
00064 }
00065 
00066 struct command nvo_commands[] __command = {
00067         {
00068                 .name = "show",
00069                 .exec = show_exec,
00070         },
00071         {
00072                 .name = "set",
00073                 .exec = set_exec,
00074         },      
00075         {
00076                 .name = "clear",
00077                 .exec = clear_exec,
00078         },
00079 };

Generated on Tue Apr 6 20:01:06 2010 for gPXE by  doxygen 1.5.7.1