9f7f59867f29a29497415eff7de2a616ad2bdc4b
[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 RCSID
14     ("$Header$");
15
16 #include "cmd.h"
17 #include <stdio.h>
18 #include <com_err.h>
19
20 static
21 cproc1(as, arock)
22      char *arock;
23      struct cmd_syndesc *as;
24 {
25     printf("in the apple command\n");
26     return 0;
27 }
28
29 static
30 cproc2(as, arock)
31      char *arock;
32      struct cmd_syndesc *as;
33 {
34     register struct cmd_item *ti;
35     printf("in the pear command\n");
36     printf("number is %s\n", as->parms[0].items->data);
37     if (as->parms[1].items)
38         printf("running unauthenticated\n");
39     for (ti = as->parms[2].items; ti; ti = ti->next) {
40         printf("spotspos %s\n", ti->data);
41     }
42     if (as->parms[8].items)
43         printf("cell name %s\n", as->parms[8].items->data);
44     return 0;
45 }
46
47 static void
48 cproc3(as, arock)
49      char *arock;
50      struct cmd_syndesc *as;
51 {
52     exit(0);
53 }
54
55 main(argc, argv)
56      int argc;
57      char **argv;
58 {
59     register struct cmd_syndesc *ts;
60     char tline[1000];
61     long tc;
62     char *tp;
63     long code;
64     char *tv[100];
65
66     initialize_CMD_error_table();
67
68     ts = cmd_CreateSyntax("apple", cproc1, NULL, "describe apple");
69
70     ts = cmd_CreateSyntax("pear", cproc2, NULL, "describe pear");
71     cmd_AddParm(ts, "-num", CMD_LIST, 0, "number of pears");
72     cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");
73     cmd_AddParm(ts, "-spotpos", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS, 0);
74     cmd_Seek(ts, 8);
75     cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
76     cmd_CreateAlias(ts, "alias");
77
78     ts = cmd_CreateSyntax("quit", cproc3, 0, "quit");
79
80     while (1) {
81         printf("> ");
82         tp = gets(tline);
83         if (tp == NULL)
84             break;
85         code = cmd_ParseLine(tline, tv, &tc, 100);
86         if (code) {
87             printf("itest: parsing failure: %s\n", afs_error_message(code));
88             exit(1);
89         }
90         code = cmd_Dispatch(tc, tv);
91         cmd_FreeArgv(tv);
92         if (code) {
93             printf("itest: execution failed: %s\n", afs_error_message(code));
94         }
95     }
96     return 0;
97 }