From 58b825a4dc94cad805944db3edb17dcb8812bb7d Mon Sep 17 00:00:00 2001 From: mar Date: Thu, 21 Jan 1988 17:57:51 +0000 Subject: [PATCH] added capability to read from a script file, and put output in another file --- clients/mrtest/mrtest.c | 91 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 3 deletions(-) diff --git a/clients/mrtest/mrtest.c b/clients/mrtest/mrtest.c index aa29f414..1699444c 100644 --- a/clients/mrtest/mrtest.c +++ b/clients/mrtest/mrtest.c @@ -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 +#include +#include #include #include 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; { -- 2.45.2