]> andersk Git - moira.git/blame - clients/mrtest/mrtest.c
Added exit(0) to the end of main().
[moira.git] / clients / mrtest / mrtest.c
CommitLineData
6e6374cb 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
c801de4c 7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
6e6374cb 9 *
6e6374cb 10 */
11
12#ifndef lint
13static char *rcsid_test_c = "$Header$";
14#endif lint
15
c801de4c 16#include <mit-copyright.h>
6e6374cb 17#include <stdio.h>
58b825a4 18#include <sys/file.h>
19#include <ctype.h>
6e6374cb 20#include <sms.h>
21#include <ss.h>
22
23int ss;
58b825a4 24int recursion = 0;
6e6374cb 25extern ss_request_table sms_test;
59af7b90 26extern int sending_version_no;
6e6374cb 27
28#ifndef __SABER__
29main(argc, argv)
30 int argc;
31 char **argv;
32#else __SABER__
33sms()
34#endif __SABER__
35{
36 int status;
37 char *whoami;
38
39#ifndef __SABER__
40 whoami = argv[0];
41#else
42 whoami = "sms";
43#endif __SABER__
44
45 init_ss_err_tbl();
46 init_sms_err_tbl();
47 init_krb_err_tbl();
48
59af7b90 49 ss = ss_create_invocation("sms", "2.0", (char *)NULL,
6e6374cb 50 &sms_test, &status);
51 if (status != 0) {
52 com_err(whoami, status, "Unable to create invocation");
53 exit(1);
54 }
55 ss_listen(ss, &status);
56 if (status != 0) {
57 com_err(whoami, status, 0);
58 exit(1);
59 }
a4b41593 60 exit(0);
6e6374cb 61}
62
63test_noop()
64{
65 int status = sms_noop();
66 if (status) ss_perror(ss, status, 0);
67}
68
59af7b90 69test_new()
70{
71 sending_version_no = SMS_VERSION_2;
72}
73
74test_old()
75{
76 sending_version_no = SMS_VERSION_1;
77}
78
011e0a54 79test_connect(argc, argv)
80int argc;
81char *argv[];
6e6374cb 82{
011e0a54 83 char *server = "";
84 int status;
85
86 if (argc > 1)
87 server = argv[1];
88 status = sms_connect(server);
6e6374cb 89 if (status) ss_perror(ss, status, 0);
90}
91
92test_disconnect()
93{
94 int status = sms_disconnect();
95 if (status) ss_perror(ss, status, 0);
96}
97
98test_auth()
99{
59af7b90 100 int status;
101
102 status = sms_auth("smstest");
6e6374cb 103 if (status) ss_perror(ss, status, 0);
104}
105
58b825a4 106test_script(argc, argv)
107int argc;
108char *argv[];
109{
110 FILE *inp;
111 char input[BUFSIZ], *cp, *index();
112 int status, oldstdout, oldstderr;
113
114 if (recursion > 8) {
115 ss_perror(ss, 0, "too many levels deep in script files\n");
116 return;
117 }
118
119 if (argc < 2) {
120 ss_perror(ss, 0, "Usage: script input_file [ output_file ]");
121 return;
122 }
123
124 inp = fopen(argv[1], "r");
125 if (inp == NULL) {
126 ss_perror(ss, 0, "Cannot open input file %s", argv[1]);
127 return;
128 }
129
130 if (argc == 3) {
131 printf("Redirecting output to %s\n", argv[2]);
132 fflush(stdout);
133 oldstdout = dup(1);
134 close(1);
135 status = open(argv[2], O_CREAT|O_WRONLY|O_APPEND, 0664);
136 if (status != 1) {
137 close(status);
138 dup2(oldstdout, 1);
139 argc = 2;
140 ss_perror(ss, errno, "Unable to redirect output to %s\n", argv[2]);
141 } else {
142 fflush(stderr);
143 oldstderr = dup(2);
144 close(2);
145 dup2(1, 2);
146 }
147 }
148
149 recursion++;
150
151 for(;;) {
152 if (fgets(input, BUFSIZ, inp) == NULL)
153 break;
154 if ((cp = index(input, '\n')) != (char *)NULL)
155 *cp = 0;
6a592314 156 if (input[0] == 0) {
157 printf("\n");
158 continue;
159 }
58b825a4 160 if (input[0] == '%') {
161 for (cp = &input[1]; *cp && isspace(*cp); cp++);
162 printf("Comment: %s\n", cp);
163 continue;
164 }
165 printf("Executing: %s\n", input);
166 ss_execute_line(ss, input, &status);
167 if (status == SS_ET_COMMAND_NOT_FOUND) {
168 printf("Bad command: %s\n", input);
169 }
170 }
171
172 recursion--;
173
174 fclose(inp);
175 if (argc == 3) {
176 fflush(stdout);
177 close(1);
178 dup2(oldstdout, 1);
179 close(oldstdout);
180 fflush(stderr);
181 close(2);
182 dup2(oldstderr, 2);
183 close(oldstderr);
184 }
185}
186
6e6374cb 187char *concat(str1, str2)
188 char *str1, *str2;
189{
190 char *rtn;
191 extern char *malloc();
192
193 if (!str1) {
194 int len = strlen(str2) + 1 ;
195 rtn = malloc(len);
196 bcopy(str2, rtn, len);
197 } else {
198 int len1 = strlen(str1);
199 int len2 = strlen(str2) + 1;
200 rtn = malloc(len1+len2);
201 bcopy(str1, rtn, len1);
202 bcopy(str2, rtn+len1, len2);
203 }
204 return rtn;
205}
206
6e6374cb 207static int count;
208
209
210print_reply(argc, argv)
211 int argc;
212 char **argv;
213{
214 int i;
215 for (i = 0; i < argc; i++) {
216 if (i != 0) printf(", ");
217 printf("%s", argv[i]);
218 }
219 printf("\n");
220 count++;
fc3ac28e 221 return(SMS_CONT);
6e6374cb 222}
223
224test_query(argc, argv)
225 int argc;
226 char **argv;
227{
228 int status;
229 if (argc < 2) {
230 ss_perror(ss, 0, "Usage: query handle [ args ... ]");
231 return;
232 }
59af7b90 233
6e6374cb 234 count = 0;
235 status = sms_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL);
303cb414 236 printf("%d tuple%s\n", count, ((count == 1) ? "" : "s"));
6e6374cb 237 if (status) ss_perror(ss, status, 0);
238}
239
240test_access(argc, argv)
241 int argc;
242 char **argv;
243{
244 int status;
245 if (argc < 2) {
246 ss_perror(ss, 0, "Usage: access handle [ args ... ]");
247 return;
248 }
249 status = sms_access(argv[1], argc-2, argv+2);
250 if (status) ss_perror(ss, status, 0);
251}
fc3ac28e 252
253
254test_dcm(argc, argv)
255 int argc;
256 char **argv;
257{
258 int status;
259
260 if (status = sms_do_update())
261 ss_perror(ss, status, " while triggering dcm");
262}
This page took 0.089695 seconds and 5 git commands to generate.