6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
9 * Revision 1.4 1988-01-21 17:57:51 mar
10 * added capability to read from a script file, and put output in another file
12 * Revision 1.3 88/01/07 17:42:06 mar
13 * print "tuple" or "tuples" as is correct
15 * Revision 1.2 87/08/22 23:45:10 wesommer
16 * Removed extra RCS headers.
18 * Revision 1.1 87/08/22 18:31:59 wesommer
24 static char *rcsid_test_c = "$Header$";
35 extern ss_request_table sms_test;
58 ss = ss_create_invocation("sms", "1.0", (char *)NULL,
61 com_err(whoami, status, "Unable to create invocation");
64 ss_listen(ss, &status);
66 com_err(whoami, status, 0);
73 int status = sms_noop();
74 if (status) ss_perror(ss, status, 0);
79 int status = sms_connect();
80 if (status) ss_perror(ss, status, 0);
85 int status = sms_disconnect();
86 if (status) ss_perror(ss, status, 0);
91 int status = sms_auth();
92 if (status) ss_perror(ss, status, 0);
95 test_script(argc, argv)
100 char input[BUFSIZ], *cp, *index();
101 int status, oldstdout, oldstderr;
104 ss_perror(ss, 0, "too many levels deep in script files\n");
109 ss_perror(ss, 0, "Usage: script input_file [ output_file ]");
113 inp = fopen(argv[1], "r");
115 ss_perror(ss, 0, "Cannot open input file %s", argv[1]);
120 printf("Redirecting output to %s\n", argv[2]);
124 status = open(argv[2], O_CREAT|O_WRONLY|O_APPEND, 0664);
129 ss_perror(ss, errno, "Unable to redirect output to %s\n", argv[2]);
141 if (fgets(input, BUFSIZ, inp) == NULL)
143 if ((cp = index(input, '\n')) != (char *)NULL)
147 if (input[0] == '%') {
148 for (cp = &input[1]; *cp && isspace(*cp); cp++);
149 printf("Comment: %s\n", cp);
152 printf("Executing: %s\n", input);
153 ss_execute_line(ss, input, &status);
154 if (status == SS_ET_COMMAND_NOT_FOUND) {
155 printf("Bad command: %s\n", input);
174 char *concat(str1, str2)
178 extern char *malloc();
181 int len = strlen(str2) + 1 ;
183 bcopy(str2, rtn, len);
185 int len1 = strlen(str1);
186 int len2 = strlen(str2) + 1;
187 rtn = malloc(len1+len2);
188 bcopy(str1, rtn, len1);
189 bcopy(str2, rtn+len1, len2);
194 test_shutdown(argc, argv)
202 ss_perror(ss, 0, "Usage: shutdown reason ...");
206 for (i = 1 ; i < argc; i++) {
207 if (i != 1) reason = concat(reason, " ");
208 reason = concat(reason, argv[i]);
210 status = sms_shutdown(reason);
211 if (status) ss_perror(ss, status, 0);
216 print_reply(argc, argv)
221 for (i = 0; i < argc; i++) {
222 if (i != 0) printf(", ");
223 printf("%s", argv[i]);
229 test_query(argc, argv)
235 ss_perror(ss, 0, "Usage: query handle [ args ... ]");
239 status = sms_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL);
240 printf("%d tuple%s\n", count, ((count == 1) ? "" : "s"));
241 if (status) ss_perror(ss, status, 0);
244 test_access(argc, argv)
250 ss_perror(ss, 0, "Usage: access handle [ args ... ]");
253 status = sms_access(argv[1], argc-2, argv+2);
254 if (status) ss_perror(ss, status, 0);