aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ss/test_ss.c
blob: 3eddbabef2b755c804a286917a871d56368b691e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 *------------------------------------------------------------------
 *
 * $Source$
 * $Revision$
 * $Date$
 * $State$
 * $Author$
 * $Locker$
 *
 * $Log$
 * Revision 1.8  1997/04/29 14:52:31  tytso
 * Checked in e2fsprogs 1.05
 *
 * Revision 1.1  1993/06/03  12:31:25  tytso
 * Initial revision
 *
 * Revision 1.1  1991/12/21  16:41:47  eichin
 * Initial revision
 *
 * Revision 1.1  1991/12/21  11:13:39  eichin
 * Initial revision
 *
 * Revision 1.2  89/01/25  07:52:27  raeburn
 * *** empty log message ***
 * 
 * Revision 1.1  88/01/23  15:50:26  raeburn
 * Initial revision
 *
 *
 *------------------------------------------------------------------
 */

#ifndef lint
static char const rcsid_test_c[] =
    "$Header$";
#endif /* lint */

#include <stdio.h>
#include "ss.h"

extern ss_request_table test_cmds;

#define TRUE 1
#define FALSE 0

static char def_subsystem_name[5] = "test";
static char version [4] = "1.0";
extern void ss_listen();

int main(argc, argv)
    int argc;
    char **argv;
{
    int code;
    char *argv0 = argv[0];
    char *initial_request = (char *)NULL;
    int quit = FALSE;	/* quit after processing request */
    int sci_idx;
    char *subsystem_name;

    subsystem_name = def_subsystem_name;

    for (; *argv; ++argv, --argc) {
	printf("checking arg: %s\n", *argv);
	if (!strcmp(*argv, "-prompt")) {
	    if (argc == 1) {
		fprintf(stderr,
			"No argument supplied with -prompt\n");
		exit(1);
	    }
	    argc--; argv++;
	    subsystem_name = *argv;
	}
	else if (!strcmp(*argv, "-request") || !strcmp(*argv, "-rq")) {
	    if (argc == 1) {
		fprintf(stderr,
			"No string supplied with -request.\n");
		exit(1);
	    }
	    argc--; argv++;
	    initial_request = *argv;
	}
	else if (!strcmp(*argv, "-quit"))
	    quit = TRUE;
	else if (!strcmp(*argv, "-no_quit"))
	    quit = FALSE;
	else if (**argv == '-') {
	    fprintf(stderr, "Unknown control argument %s\n",
		    *argv);
	    fprintf(stderr,
	"Usage: %s [gateway] [ -prompt name ] [ -request name ] [ -quit ]\n",
		    argv0);
	    exit(1);
	}
    }

    sci_idx = ss_create_invocation(subsystem_name, version,
				   (char *)NULL, &test_cmds, &code);
    if (code) {
	ss_perror(sci_idx, code, "creating invocation");
	exit(1);
    }

    (void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &code);
    if (code) {
	ss_perror (sci_idx, code, "adding standard requests");
	exit (1);
    }

    if (!quit)
	printf("test version %s.  Type '?' for a list of commands.\n\n",
	       version);

    if (initial_request != (char *)NULL) {
	code = ss_execute_line(sci_idx, initial_request);
	if (code != 0)
	    ss_perror(sci_idx, code, initial_request);
    }
    if (!quit || code)
	(void) ss_listen (sci_idx, &code);
    exit(0);
}


void test_cmd (argc, argv)
    int argc;
    char **argv;
{
    while (++argv, --argc)
	fputs(*argv, stdout);
    putchar ('\n');
}