]> andersk Git - moira.git/blobdiff - clients/mrtest/mrtest.c
removed error table initializations (they're done in sms_connect)
[moira.git] / clients / mrtest / mrtest.c
index aa29f4141524a1153483a59e196636b423dd349e..fbe3c8548d596377e67a46665dd3024cefe235ec 100644 (file)
@@ -4,29 +4,26 @@
  *     $Header$
  *
  *     Copyright (C) 1987 by the Massachusetts Institute of Technology
+ *     For copying and distribution information, please see the file
+ *     <mit-copyright.h>.
  *
- *     $Log$
- *     Revision 1.3  1988-01-07 17:42:06  mar
- *     print "tuple" or "tuples" as is correct
- *
- * Revision 1.2  87/08/22  23:45:10  wesommer
- * Removed extra RCS headers.
- * 
- * Revision 1.1  87/08/22  18:31:59  wesommer
- * Initial revision
- * 
  */
 
 #ifndef lint
 static char *rcsid_test_c = "$Header$";
 #endif lint
 
+#include <mit-copyright.h>
 #include <stdio.h>
+#include <sys/file.h>
+#include <ctype.h>
 #include <sms.h>
 #include <ss.h>
 
 int ss;
+int recursion = 0;
 extern ss_request_table sms_test;
+extern int sending_version_no;
 
 #ifndef __SABER__
 main(argc, argv)
@@ -46,10 +43,8 @@ sms()
 #endif __SABER__
        
        init_ss_err_tbl();
-       init_sms_err_tbl();
-       init_krb_err_tbl();
 
-       ss = ss_create_invocation("sms", "0.1", (char *)NULL,
+       ss = ss_create_invocation("sms", "2.0", (char *)NULL,
                                  &sms_test, &status);
        if (status != 0) {
                com_err(whoami, status, "Unable to create invocation");
@@ -60,6 +55,7 @@ sms()
                com_err(whoami, status, 0);
                exit(1);
        }
+       exit(0);
 }
 
 test_noop()
@@ -68,9 +64,31 @@ test_noop()
        if (status) ss_perror(ss, status, 0);
 }
 
-test_connect()
+test_new()
+{
+       sending_version_no = SMS_VERSION_2;
+}
+
+test_old()
+{
+       sending_version_no = SMS_VERSION_1;
+}
+
+test_connect(argc, argv)
+int argc;
+char *argv[];
 {
-       int status = sms_connect();
+       char *server = "", serverbuf[256], *index();
+       int status;
+
+       if (argc > 1) {
+           server = argv[1];
+           if (index(server, ':') == NULL) {
+               server = serverbuf;
+               sprintf(serverbuf, "%s:%s", argv[1], "sms_db");
+           }
+       }
+       status = sms_connect(server);
        if (status) ss_perror(ss, status, 0);
 }
 
@@ -82,10 +100,93 @@ test_disconnect()
 
 test_auth()
 {
-       int status = sms_auth();
+       int status;
+
+       status = sms_auth("smstest");
        if (status) ss_perror(ss, status, 0);
 }
 
+test_script(argc, argv)
+int argc;
+char *argv[];
+{
+    FILE *inp;
+    char input[BUFSIZ], *cp, *index();
+    int status, oldstdout, oldstderr;
+
+    if (recursion > 8) {
+       ss_perror(ss, 0, "too many levels deep in script files\n");
+       return;
+    }
+
+    if (argc < 2) {
+       ss_perror(ss, 0, "Usage: script input_file [ output_file ]");
+       return;
+    }
+
+    inp = fopen(argv[1], "r");
+    if (inp == NULL) {
+       ss_perror(ss, 0, "Cannot open input file %s", argv[1]);
+       return;
+    }
+
+    if (argc == 3) {
+       printf("Redirecting output to %s\n", argv[2]);
+       fflush(stdout);
+       oldstdout = dup(1);
+       close(1);
+       status = open(argv[2], O_CREAT|O_WRONLY|O_APPEND, 0664);
+       if (status != 1) {
+           close(status);
+           dup2(oldstdout, 1);
+           argc = 2;
+           ss_perror(ss, errno, "Unable to redirect output to %s\n", argv[2]);
+       } else {
+           fflush(stderr);
+           oldstderr = dup(2);
+           close(2);
+           dup2(1, 2);
+       }
+    }
+
+    recursion++;
+
+    for(;;) {
+       if (fgets(input, BUFSIZ, inp) == NULL)
+         break;
+       if ((cp = index(input, '\n')) != (char *)NULL)
+         *cp = 0;
+       if (input[0] == 0) {
+           printf("\n");
+           continue;
+       }
+       if (input[0] == '%') {
+           for (cp = &input[1]; *cp && isspace(*cp); cp++);
+           printf("Comment: %s\n", cp);
+           continue;
+       }
+       printf("Executing: %s\n", input);
+       ss_execute_line(ss, input, &status);
+       if (status == SS_ET_COMMAND_NOT_FOUND) {
+           printf("Bad command: %s\n", input);
+       }
+    }
+
+    recursion--;
+
+    fclose(inp);
+    if (argc == 3) {
+       fflush(stdout);
+       close(1);
+       dup2(oldstdout, 1);
+       close(oldstdout);
+       fflush(stderr);
+       close(2);
+       dup2(oldstderr, 2);
+       close(oldstderr);
+    }
+}
+
 char *concat(str1, str2)
        char *str1, *str2;
 {
@@ -106,25 +207,6 @@ char *concat(str1, str2)
        return rtn;
 }
 
-test_shutdown(argc, argv)
-       int argc;
-       char **argv;
-{
-       char *reason = NULL;
-       int status, i;
-       
-       if (argc < 2) {
-               ss_perror(ss, 0, "Usage: shutdown reason ...");
-               return;
-       }
-       
-       for (i = 1 ; i < argc; i++) {
-               if (i != 1) reason = concat(reason, " ");
-               reason = concat(reason, argv[i]);
-       }
-       status = sms_shutdown(reason);
-       if (status) ss_perror(ss, status, 0);
-}
 static int count;
 
 
@@ -139,6 +221,7 @@ print_reply(argc, argv)
        }
        printf("\n");
        count++;
+       return(SMS_CONT);
 }
 
 test_query(argc, argv)
@@ -150,6 +233,7 @@ test_query(argc, argv)
                ss_perror(ss, 0, "Usage: query handle [ args ... ]");
                return;
        }
+
        count = 0;
        status = sms_query(argv[1], argc-2, argv+2, print_reply, (char *)NULL);
        printf("%d tuple%s\n", count, ((count == 1) ? "" : "s"));
@@ -169,3 +253,13 @@ test_access(argc, argv)
        if (status) ss_perror(ss, status, 0);
 }
 
+
+test_dcm(argc, argv)
+       int argc;
+       char **argv;
+{
+       int status;
+
+       if (status = sms_do_update())
+         ss_perror(ss, status, " while triggering dcm");
+}
This page took 0.040358 seconds and 4 git commands to generate.