]> git.sur5r.net Git - ngadmin/blobdiff - cli/com_name.c
Command functions return int instead of bool
[ngadmin] / cli / com_name.c
index 54b152e1113231c78e1fbcdaf110308b3f83f92f..dd7b0484100d842bb18cfb1bbfa6a5b09f6bb91f 100644 (file)
@@ -1,80 +1,77 @@
 
-#include "common.h"
-
-
-
-
-static bool do_name_show (const struct TreeNode *tn UNUSED, int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
- const struct swi_attr *sa;
- if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
-  printf("must be logged\n");
-  return false;
- }
- puts(sa->name);
- return true;
+#include "commands.h"
+
+
+int do_name_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+       const struct swi_attr *sa;
+       
+       
+       if (argc > 0) {
+               printf("this command takes no argument\n");
+               return 1;
+       }
+       
+       sa = ngadmin_getCurrentSwitch(nga);
+       if (sa == NULL) {
+               printf("must be logged\n");
+               return 1;
+       }
+       
+       puts(sa->name);
+       
+       
+       return 0;
 }
 
 
-
-static bool do_name_set (const struct TreeNode *tn UNUSED, int nb, const char **com, struct ngadmin *nga) {
- int i;
- const struct swi_attr *sa;
- if ( nb!=1 ) {
-  printf("Usage: name set <value>\n");
-  return false;
- }
- if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
-  printf("must be logged\n");
-  return false;
- }
- i=ngadmin_setName(nga, com[0]);
- printErrCode(i);
- return true;
+int do_name_set (int argc, const char **argv, struct ngadmin *nga)
+{
+       int i;
+       const struct swi_attr *sa;
+       
+       
+       if (argc != 1) {
+               printf("usage: name set <value>\n");
+               return 1;
+       }
+       
+       sa = ngadmin_getCurrentSwitch(nga);
+       if (sa == NULL) {
+               printf("must be logged\n");
+               return 1;
+       }
+       
+       i = ngadmin_setName(nga, argv[0]);
+       printErrCode(i);
+       
+       
+       return 0;
 }
 
 
-
-static bool do_name_clear (const struct TreeNode *tn UNUSED, int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
- int i;
- const struct swi_attr *sa;
- if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
-  printf("must be logged\n");
-  return false;
- }
- i=ngadmin_setName(nga, NULL);
- printErrCode(i);
- return true;
+int do_name_clear (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+       int i;
+       const struct swi_attr *sa;
+       
+       
+       if (argc > 0) {
+               printf("this command takes no argument\n");
+               return 1;
+       }
+       
+       sa = ngadmin_getCurrentSwitch(nga);
+       if (sa == NULL) {
+               printf("must be logged\n");
+               return 1;
+       }
+       
+       i = ngadmin_setName(nga, NULL);
+       printErrCode(i);
+       
+       
+       return 0;
 }
 
 
-
-static struct TreeNode com_name_show=COM("show", do_name_show, false, NULL);
-static struct TreeNode com_name_set=COM("set", do_name_set, true, NULL);
-static struct TreeNode com_name_clear=COM("clear", do_name_clear, false, NULL);
-
-const struct TreeNode com_name=COM("name", NULL, false, &com_name_show, &com_name_set, &com_name_clear, NULL);
-
-
-