comerr-behave-like-the-rest-of-the-world-20010918
[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("$Header$");
14
15 #include "cmd.h"
16 #include <stdio.h>
17 #include <com_err.h>
18
19 static cproc1 (as, arock)
20 char *arock;
21 struct cmd_syndesc *as; {
22     printf("in the apple command\n");
23     return 0;
24 }
25
26 static cproc2 (as, arock)
27 char *arock;
28 struct cmd_syndesc *as; {
29     register struct cmd_item *ti;
30     printf("in the pear command\n");
31     printf("number is %s\n", as->parms[0].items->data);
32     if (as->parms[1].items) 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 void cproc3(as, arock)
42 char *arock;
43 struct cmd_syndesc *as; {
44     exit(0);
45 }
46
47 main(argc, argv)
48 int argc;
49 char **argv; {
50     register struct cmd_syndesc *ts;
51     char tline[1000];
52     long tc;
53     char *tp;
54     long code;
55     char *tv[100];
56     
57     initialize_CMD_error_table();
58
59     ts = cmd_CreateSyntax("apple", cproc1, (char *) 0, "describe apple");
60
61     ts = cmd_CreateSyntax("pear", cproc2, (char *) 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, "quit");
70     
71     while (1) {
72         printf("> ");
73         tp = gets(tline);
74         if (tp == (char *) 0) break;
75         code = cmd_ParseLine(tline, tv, &tc, 100);
76         if (code) {
77             printf("itest: parsing failure: %s\n", error_message(code));
78             exit(1);
79         }
80         code = cmd_Dispatch(tc, tv);
81         cmd_FreeArgv(tv);
82         if (code) {
83             printf("itest: execution failed: %s\n", error_message(code));
84         }
85     }
86     return 0;
87 }