]> andersk Git - moira.git/commitdiff
added capability to read from a script file, and put output in another file
authormar <mar>
Thu, 21 Jan 1988 17:57:51 +0000 (17:57 +0000)
committermar <mar>
Thu, 21 Jan 1988 17:57:51 +0000 (17:57 +0000)
clients/mrtest/mrtest.c

index aa29f4141524a1153483a59e196636b423dd349e..1699444ca2c1e2e36e1ff0c61266978c603abb05 100644 (file)
@@ -6,9 +6,12 @@
  *     Copyright (C) 1987 by the Massachusetts Institute of Technology
  *
  *     $Log$
- *     Revision 1.3  1988-01-07 17:42:06  mar
- *     print "tuple" or "tuples" as is correct
+ *     Revision 1.4  1988-01-21 17:57:51  mar
+ *     added capability to read from a script file, and put output in another file
  *
+ * Revision 1.3  88/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.
  * 
@@ -22,10 +25,13 @@ static char *rcsid_test_c = "$Header$";
 #endif lint
 
 #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;
 
 #ifndef __SABER__
@@ -49,7 +55,7 @@ sms()
        init_sms_err_tbl();
        init_krb_err_tbl();
 
-       ss = ss_create_invocation("sms", "0.1", (char *)NULL,
+       ss = ss_create_invocation("sms", "1.0", (char *)NULL,
                                  &sms_test, &status);
        if (status != 0) {
                com_err(whoami, status, "Unable to create invocation");
@@ -86,6 +92,85 @@ test_auth()
        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)
+         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;
 {
This page took 0.202207 seconds and 5 git commands to generate.