Whamcloud - gitweb
Many files:
[tools/e2fsprogs.git] / lib / ss / test_ss.c
1 /*
2  *------------------------------------------------------------------
3  *
4  * $Source$
5  * $Revision$
6  * $Date$
7  * $State$
8  * $Author$
9  * $Locker$
10  *
11  * $Log$
12  * Revision 1.5  1997/04/26 14:35:55  tytso
13  * Checkin of e2fsprogs 1.02.
14  *
15  * Revision 1.1  1993/06/03  12:31:25  tytso
16  * Initial revision
17  *
18  * Revision 1.1  1991/12/21  16:41:47  eichin
19  * Initial revision
20  *
21  * Revision 1.1  1991/12/21  11:13:39  eichin
22  * Initial revision
23  *
24  * Revision 1.2  89/01/25  07:52:27  raeburn
25  * *** empty log message ***
26  * 
27  * Revision 1.1  88/01/23  15:50:26  raeburn
28  * Initial revision
29  *
30  *
31  *------------------------------------------------------------------
32  */
33
34 #ifndef lint
35 static char const rcsid_test_c[] =
36     "$Header$";
37 #endif /* lint */
38
39 #include <stdio.h>
40 #include "ss.h"
41
42 extern ss_request_table test_cmds;
43
44 #define TRUE 1
45 #define FALSE 0
46
47 static char def_subsystem_name[5] = "test";
48 static char version [4] = "1.0";
49 extern void ss_listen();
50
51 int main(argc, argv)
52     int argc;
53     char **argv;
54 {
55     int code;
56     char *argv0 = argv[0];
57     char *initial_request = (char *)NULL;
58     int quit = FALSE;   /* quit after processing request */
59     int sci_idx;
60     char *subsystem_name;
61
62     subsystem_name = def_subsystem_name;
63
64     for (; *argv; ++argv, --argc) {
65         printf("checking arg: %s\n", *argv);
66         if (!strcmp(*argv, "-prompt")) {
67             if (argc == 1) {
68                 fprintf(stderr,
69                         "No argument supplied with -prompt\n");
70                 exit(1);
71             }
72             argc--; argv++;
73             subsystem_name = *argv;
74         }
75         else if (!strcmp(*argv, "-request") || !strcmp(*argv, "-rq")) {
76             if (argc == 1) {
77                 fprintf(stderr,
78                         "No string supplied with -request.\n");
79                 exit(1);
80             }
81             argc--; argv++;
82             initial_request = *argv;
83         }
84         else if (!strcmp(*argv, "-quit"))
85             quit = TRUE;
86         else if (!strcmp(*argv, "-no_quit"))
87             quit = FALSE;
88         else if (**argv == '-') {
89             fprintf(stderr, "Unknown control argument %s\n",
90                     *argv);
91             fprintf(stderr,
92         "Usage: %s [gateway] [ -prompt name ] [ -request name ] [ -quit ]\n",
93                     argv0);
94             exit(1);
95         }
96     }
97
98     sci_idx = ss_create_invocation(subsystem_name, version,
99                                    (char *)NULL, &test_cmds, &code);
100     if (code) {
101         ss_perror(sci_idx, code, "creating invocation");
102         exit(1);
103     }
104
105     (void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &code);
106     if (code) {
107         ss_perror (sci_idx, code, "adding standard requests");
108         exit (1);
109     }
110
111     if (!quit)
112         printf("test version %s.  Type '?' for a list of commands.\n\n",
113                version);
114
115     if (initial_request != (char *)NULL) {
116         code = ss_execute_line(sci_idx, initial_request);
117         if (code != 0)
118             ss_perror(sci_idx, code, initial_request);
119     }
120     if (!quit || code)
121         (void) ss_listen (sci_idx, &code);
122     exit(0);
123 }
124
125
126 void test_cmd (argc, argv)
127     int argc;
128     char **argv;
129 {
130     while (++argv, --argc)
131         fputs(*argv, stdout);
132     putchar ('\n');
133 }