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