Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

nvo_cmd.c 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <ipxe/settings.h>
  8. #include <ipxe/command.h>
  9. FILE_LICENCE ( GPL2_OR_LATER );
  10. static int show_exec ( int argc, char **argv ) {
  11. char buf[256];
  12. int rc;
  13. if ( argc != 2 ) {
  14. printf ( "Syntax: %s <identifier>\n", argv[0] );
  15. return 1;
  16. }
  17. if ( ( rc = fetchf_named_setting ( argv[1], buf,
  18. sizeof ( buf ) ) ) < 0 ){
  19. printf ( "Could not find \"%s\": %s\n",
  20. argv[1], strerror ( rc ) );
  21. return 1;
  22. }
  23. printf ( "%s = %s\n", argv[1], buf );
  24. return 0;
  25. }
  26. static int set_exec ( int argc, char **argv ) {
  27. size_t len;
  28. int i;
  29. int rc;
  30. if ( argc < 3 ) {
  31. printf ( "Syntax: %s <identifier> <value>\n", argv[0] );
  32. return 1;
  33. }
  34. /* Determine total length of command line */
  35. len = 1; /* NUL */
  36. for ( i = 2 ; i < argc ; i++ )
  37. len += ( 1 /* possible space */ + strlen ( argv[i] ) );
  38. {
  39. char buf[len];
  40. char *ptr = buf;
  41. /* Assemble command line */
  42. buf[0] = '\0';
  43. for ( i = 2 ; i < argc ; i++ ) {
  44. ptr += sprintf ( ptr, "%s%s", ( buf[0] ? " " : "" ),
  45. argv[i] );
  46. }
  47. assert ( ptr < ( buf + len ) );
  48. if ( ( rc = storef_named_setting ( argv[1], buf ) ) != 0 ) {
  49. printf ( "Could not set \"%s\"=\"%s\": %s\n",
  50. argv[1], buf, strerror ( rc ) );
  51. return 1;
  52. }
  53. }
  54. return 0;
  55. }
  56. static int clear_exec ( int argc, char **argv ) {
  57. int rc;
  58. if ( argc != 2 ) {
  59. printf ( "Syntax: %s <identifier>\n", argv[0] );
  60. return 1;
  61. }
  62. if ( ( rc = delete_named_setting ( argv[1] ) ) != 0 ) {
  63. printf ( "Could not clear \"%s\": %s\n",
  64. argv[1], strerror ( rc ) );
  65. return 1;
  66. }
  67. return 0;
  68. }
  69. struct command nvo_commands[] __command = {
  70. {
  71. .name = "show",
  72. .exec = show_exec,
  73. },
  74. {
  75. .name = "set",
  76. .exec = set_exec,
  77. },
  78. {
  79. .name = "clear",
  80. .exec = clear_exec,
  81. },
  82. };