Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / cmd / test / itest.c
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 #include <roken.h>
14
15 #include <afs/com_err.h>
16 #include <afs/cmd.h>
17
18 static int
19 cproc1(struct cmd_syndesc *as, void *arock)
20 {
21 printf("in the apple command\n");
22 return 0;
23 }
24
25 static int
26 cproc2(struct cmd_syndesc *as, void *arock)
27 {
28 struct cmd_item *ti;
29 printf("in the pear command\n");
30 printf("number is %s\n", as->parms[0].items->data);
31 if (as->parms[1].items)
32 printf("running unauthenticated\n");
33 for (ti = as->parms[2].items; ti; ti = ti->next) {
34 printf("spotspos %s\n", ti->data);
35 }
36 if (as->parms[8].items)
37 printf("cell name %s\n", as->parms[8].items->data);
38 return 0;
39 }
40
41 static int
42 cproc3(struct cmd_syndesc *as, void *arock)
43 {
44 exit(0);
45 }
46
47 int
48 main(int argc, char **argv)
49 {
50 struct cmd_syndesc *ts;
51 char tline[1000];
52 afs_int32 tc;
53 char *tp;
54 long code;
55 char *tv[100];
56
57 initialize_CMD_error_table();
58
59 ts = cmd_CreateSyntax("apple", cproc1, NULL, 0, "describe apple");
60
61 ts = cmd_CreateSyntax("pear", cproc2, NULL, 0, "describe pear");
62 cmd_AddParm(ts, "-num", CMD_LIST, 0, "number of pears");
63 cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");
64 cmd_AddParm(ts, "-spotpos", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS, 0);
65 cmd_Seek(ts, 8);
66 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
67 cmd_CreateAlias(ts, "alias");
68
69 ts = cmd_CreateSyntax("quit", cproc3, 0, 0, "quit");
70
71 while (1) {
72 printf("> ");
73 tp = gets(tline);
74 if (tp == NULL)
75 break;
76 code = cmd_ParseLine(tline, tv, &tc, 100);
77 if (code) {
78 printf("itest: parsing failure: %s\n", afs_error_message(code));
79 exit(1);
80 }
81 code = cmd_Dispatch(tc, tv);
82 cmd_FreeArgv(tv);
83 if (code) {
84 printf("itest: execution failed: %s\n", afs_error_message(code));
85 }
86 }
87 return 0;
88 }