]> git.sur5r.net Git - ngadmin/blob - cli/com_name.c
Code reorganized.
[ngadmin] / cli / com_name.c
1
2 #include "common.h"
3
4
5
6
7 static bool do_name_show (const struct TreeNode *tn UNUSED, int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
8  
9  const struct swi_attr *sa;
10  
11  
12  if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
13   printf("must be logged\n");
14   return false;
15  }
16  
17  puts(sa->name);
18  
19  
20  return true;
21  
22 }
23
24
25
26 static bool do_name_set (const struct TreeNode *tn UNUSED, int nb, const char **com, struct ngadmin *nga) {
27  
28  int i;
29  const struct swi_attr *sa;
30  
31  
32  if ( nb!=1 ) {
33   printf("Usage: name set <value>\n");
34   return false;
35  }
36  
37  if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
38   printf("must be logged\n");
39   return false;
40  }
41  
42  i=ngadmin_setName(nga, com[0]);
43  printErrCode(i);
44  
45  
46  return true;
47  
48 }
49
50
51
52 static bool do_name_clear (const struct TreeNode *tn UNUSED, int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
53  
54  int i;
55  const struct swi_attr *sa;
56  
57  
58  if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
59   printf("must be logged\n");
60   return false;
61  }
62  
63  i=ngadmin_setName(nga, NULL);
64  printErrCode(i);
65  
66  
67  return true;
68  
69 }
70
71
72
73 static struct TreeNode com_name_show=COM("show", do_name_show, false, NULL);
74 static struct TreeNode com_name_set=COM("set", do_name_set, true, NULL);
75 static struct TreeNode com_name_clear=COM("clear", do_name_clear, false, NULL);
76
77 const struct TreeNode com_name=COM("name", NULL, false, &com_name_show, &com_name_set, &com_name_clear, NULL);
78
79
80