jrb@wdl1.UUCP (John R Blaker) (02/17/84)
/*===========================================================================* * == M I S C == * *===========================================================================* * John R Blaker -- Ford Aerospace & Communications Corporation -- Oct. 1982 * *===========================================================================* * This file contains various miscellaneous routines which are not directly * * connected with the logic of rt11. * * This file contains the following functions: * * getargs() Picks command line arguments and sets appropriate * * flags * * error() Prints an error message on the standard error output * * message() Prints an arbitrary message on the standard output * * verbose() Prints a message on the standard output if the * * VERBOSE flag is set * * trace() Prints a tracing string on the standard error output * * if the TRACE flag is set * * lock() Locks process out if a lockfile exists * * unlock() Unlocks processes waiting on a lock * * The flags and their default settings are defined in the file rt11.h * *===========================================================================* */ /* * Include files */ #include "rt11.h" /* Header file. Contains global definitions */ /* * Command line processing utility * Picks off arguments and sets boolean flags */ getargs(argc, argv) int argc; /* Argument count */ char **argv; /* Argument vector */ { char *ch; /* First character of an argument */ int index; /* Loop index */ while (--argc > 0 && (*++argv)[0] == '-') { for (ch = argv[0] + 1; *ch != '\0'; ch++) { switch(*ch) { case 'v': VERBOSE = TRUE; trace("Verbose set"); break; case 'w': WRITE = TRUE; EXTRACT = FALSE; LIST = FALSE; trace("Write set"); break; case 'c': CREATE = TRUE; LIST = FALSE; trace("Create set"); break; case 'x': EXTRACT = TRUE; WRITE = FALSE; LIST = FALSE; trace("Extract set"); break; case 'l': LIST = TRUE; trace("list set"); break; case 't': TRACE = TRUE; trace("TRACING TURNED ON"); break; case '0': DRIVE = ZERO; break; case '1': DRIVE = ONE; break; default: error("Usage: rt11 [-lxwcv01]"); exit(1); break; } /* switch */ } /* for */ } /* while */ COUNT = argc; for (index = 0; index < COUNT; index++) { FILES[index] = *argv; ++argv; trace(FILES[index]); } /* for */ if (TRACE) printf("TRACE: COUNT = %d\n", COUNT); } /* getargs */ /* * error() * This routine is used to print out * an error message prepended with the * string 'ERROR' ont the standard error * output */ error(str) char str[]; { fprintf(stderr, "ERROR: %s\n", str); } /* error */ /* * message() * This routine is used to print out a * message on the standard output */ message(str) char str[]; { fprintf(stdout, "%s\n", str); } /* message */ /* * trace() * This routine is used to print out a * tracing message prepended with the * string 'TRACE' on the standard error * output if the boolean flag 'TRACE' is * true */ trace(str) char str[]; { if (TRACE) { fprintf(stderr, "TRACE: %s\n", str); } /* if */ } /* trace */ /* * verbose() * This routine is used to print out a * message on the standard output if the * boolean flag 'VERBOSE' is true */ verbose(str) char str[]; { if (VERBOSE) { printf("%s\n", str); } /* if */ } /* verbose */ /* * lock() * This function tries to create a lockfile * and does a busy wait until it can */ lock(lockfile) char lockfile[]; /* Name of lockfile */ { trace("Creating lockfile"); while(1) if (creat(lockfile, 0) >= 0) break; } /* lock */ /* * unlock() * This function removes a lockfile */ unlock(lockfile) char lockfile[]; /* Name of lockfile */ { trace("Removing lockfile"); unlink(lockfile); } /* unlock */