/* Call me tstMark5Com. I call Mark5Com() to connect to socket m5drive * (cf., /etc/services) on the Mark5A machine specified on my command * line or defaulted below. The program Mark5A must be running on that * machine, else this connection fails. Then I read Mark5A commands * (cf., Mark5A.c) from stdin, send them through Mark5Com() through the * socket to Mark5A, and print the responses to stdout. I loop and try * to read and send more commands until ^C. See also tstMark5A.c. * Usage: tstMark5Com [ [ msglev ] machine ] * Revised: 2002 August 27, JAB */ #include "Mark5Com.h" #define MACHINE "mark5-05" /* Default machine name, default domain */ char * me; /* My name */ int msglev = 1; /* Debug level */ int main(int argc, char * argv[]) { /* tstMark5Com */ char * machine = MACHINE; /* Mark5A machine name */ char inLine[256]; /* Input from stdin */ int len; /* Length of inLine[] */ char * outLine; /* Answer from Mark5Com() to stdout */ int i; /* Scratch */ double tot; /* TOT */ long long byte; struct discinfo dinfo[MAXDISCS]; /* Disk info (in ivex.h) */ /* ** Initialize ** */ me = (me = strrchr(argv[0], '/')) == NULL ? argv[0] : me+1; /* My name */ if (argc > 1) /* Debug msglev on command line? */ msglev = atoi(argv[1]); /* Yes, replace default */ if (argc > 2) /* Machine name on command line? */ machine = argv[2]; /* Yes, replace default */ /* ** Main working loop ** */ while (TRUE) { /* Loop forever */ /* * Prompt and read a command * */ (void) printf("> "); (void) fgets(inLine, sizeof(inLine), stdin); /* Read from stdin */ if (msglev < 1) /* Debuggery? */ (void) fprintf(stderr, /* Yes */ "%s DEBUG: Got inLine[] = %s", me, inLine); if ((len = strlen(inLine)) < 5) { /* OK? */ (void) fprintf(stderr, /* Nope */ "%s ERROR: \007 Illegal command, try again \n", me); continue; /* Next while loop */ } /* * Send command and get reply * */ if ((outLine = Mark5Com(machine, inLine)) == NULL) { /* OK? */ (void) fprintf(stderr, /* Nope */ "%s ERROR: Mark5Com() returned NULL \n", me); continue; /* Error, but we try to go on */ } /* * Else print reply * */ (void) fputs(outLine, stdout); /* Print to stdout */ if (msglev < 1 && (i = Error5Com(outLine)) != 0) /* Also debuggery? */ (void) fprintf(stderr, "%s DEBUG: Error code %d \n", me, i); /* Yes */ if (msglev < 1 && /* More debuggery? */ strstr(inLine, "data_check") != NULL && (TOT5Com(outLine, &tot, &byte)) == 0) /* TOT also? */ (void) fprintf(stderr, "%s DEBUG: TOT %.0lf at byte %lld \n", me, tot, byte); if (msglev < 1 && /* Still more debuggery? */ strstr(inLine, "disc_") != NULL) (void) DiskInfo(machine, dinfo); /* (Mark5A debug prints) */ } /* End of while loop forever */ return(0); /* Not used */ } /* End of main = tstMark5Com */