|
|
1.1 ! root 1: /* ! 2: * uugrep <system> ! 3: * -- produce lines for named system out of Sysfiles; ! 4: * just cat all sys files if system not found in btree, ! 5: * or if btree is out of date ! 6: * ! 7: * uugrep ! 8: * -- update btree if necessary ! 9: */ ! 10: ! 11: #include <stdio.h> ! 12: #include <sys/types.h> ! 13: #include <sys/stat.h> ! 14: #include <cbt.h> ! 15: ! 16: #ifndef INSDIR ! 17: #define INSDIR "/usr/lib/uucp" ! 18: #endif ! 19: ! 20: char Bsysf[] = "Bsystems"; ! 21: char BsysfT[] = "Bsystems.T"; ! 22: char Sysf[] = "Sysfiles"; ! 23: ! 24: main(argc, argv) ! 25: char **argv; ! 26: { ! 27: bfile *bp; ! 28: char keyval[32], valval[512]; ! 29: register len, n, anyfound; ! 30: mbuf key, val, outkey; ! 31: ! 32: chdir(INSDIR); ! 33: if (outofdate()) { ! 34: if (argc < 2) ! 35: execl("./uusysmake","uusysmake",(char *)NULL); ! 36: catfiles(); ! 37: exit(0); ! 38: } ! 39: bp = bopen(Bsysf, 0); ! 40: if (bp == NULL) { ! 41: catfiles(); ! 42: exit(0); ! 43: } ! 44: if (argc < 1) ! 45: exit(0); ! 46: len = strlen(argv[1]); ! 47: if (len > 30) ! 48: exit(1); ! 49: strcpy(keyval, argv[1]); ! 50: keyval[len] = '.'; ! 51: key.mlen = len+2; ! 52: key.mdata = keyval; ! 53: val.mdata = valval; ! 54: anyfound = 0; ! 55: for (keyval[len+1] = 'A'; keyval[len+1]<='Z'; keyval[len+1]++) { ! 56: n = bseek(bp, key); ! 57: if (n != 1) ! 58: break; ! 59: if (bread(bp, (mbuf *)NULL, &val) != 0) ! 60: break; ! 61: printf("%.*s\n", val.mlen, val.mdata); ! 62: anyfound++; ! 63: } ! 64: if (anyfound==0) ! 65: catfiles(); ! 66: exit(0); ! 67: } ! 68: ! 69: outofdate() ! 70: { ! 71: char sfile[128]; ! 72: struct stat sbuf; ! 73: register FILE *mfp; ! 74: time_t t; ! 75: register char *cp; ! 76: extern char *strchr(); ! 77: ! 78: if (stat(BsysfT, &sbuf) < 0) ! 79: return(1); ! 80: t = sbuf.st_mtime; ! 81: mfp = fopen(Sysf, "r"); ! 82: if (mfp == NULL) ! 83: return(1); ! 84: if (fstat(fileno(mfp), &sbuf) < 0) ! 85: goto ood; ! 86: if (sbuf.st_mtime >= t) ! 87: goto ood; ! 88: while (fgets(sfile, 128, mfp)) { ! 89: cp = strchr(sfile, '\n'); ! 90: if (cp) ! 91: *cp = '\0'; ! 92: if (stat(sfile, &sbuf) != 0) ! 93: continue; /* nonexistent OK */ ! 94: if (sbuf.st_mtime >= t) ! 95: goto ood; ! 96: } ! 97: fclose(mfp); ! 98: return(0); ! 99: ood: ! 100: fclose(mfp); ! 101: return(1); ! 102: } ! 103: ! 104: catfiles() ! 105: { ! 106: char sfile[128]; ! 107: register FILE *mfp, *fp; ! 108: register c; ! 109: register char *cp; ! 110: extern char *strchr(); ! 111: ! 112: mfp = fopen(Sysf, "r"); ! 113: if (mfp == NULL) ! 114: return; ! 115: while (fgets(sfile, 128, mfp)) { ! 116: cp = strchr(sfile, '\n'); ! 117: if (cp) ! 118: *cp = '\0'; ! 119: fp = fopen(sfile, "r"); ! 120: if (fp == NULL) ! 121: continue; ! 122: while ((c = getc(fp)) != EOF) ! 123: if (putchar(c) == EOF) ! 124: exit(1); ! 125: fclose(fp); ! 126: } ! 127: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.