/* * * * The information in this document is subject to change * without notice and should not be construed as a commitment * by Digital Equipment Corporation or by DECUS. * * Neither Digital Equipment Corporation, DECUS, nor the authors * assume any responsibility for the use or reliability of this * document or the described software. * * Copyright (C) 1980, DECUS * * * General permission to copy or modify, but not for profit, is * hereby granted, provided that the above copyright notice is * included and reference made to the fact that reproduction * privileges were granted by DECUSppppp Ō@pp@pψppτOρO Oπππ@pϜ ψϜOÀϜ@CACAόOOppϜ ρOOOϜ@CϜOϐOBCOO ϐτppϐπAωO@ppψ@Oɉ@ ÀBppψ@Oɉ@ ψrep" (Decus) * * See below for more information. * */ char *documentation[] = { "grep searches a file for a given pattern. Execute by", " grep [flags] regular_expression file_list", "", "Flags are single P89221<'6<01:761436424894:2+A@A'G'@gD'D'H[ȋB [XX[H\XYYYH][H\B ]ۛH[ۋ[X][[\ȋBBH[W\u uPSWȎu_[Xt_[[ á  -uz=uW0/t9& GGu ut(u@ yt3tut xu3ù  t è@u y"t>t x@t빨t밹 tP$P4PD PTPdPtIY2$ MӰE2?ӊ -Ӱ%2ӊ$ Ӱ 2ӊ Ӱ2ӊ$ P>&EX &E: s2؋/3ø ÌȎؿFF &E3&Et =u&E&UFV gW !0!<t  ! > &u33Ҭar 4 !2` [!> u_3&E &E&M33$u8Ȏ2 3 t낀>u~ͫus3ҋ ta2ۋ; t ; t ; t  t.l Q cd ndw: ! u !k<tT<tP<t<u2  !@D T u F3FF$FV3Fu뻋D F3FF JDT FV xtw>w!_DT 3ҊDdĀf f?2ÃL t F ;u;t_ u&E !&E&M&E&M 3þ8í>tīSQ3ҋF uFV u t- u=@r=rU t@F ^Y[ÌȎ 2 vðh 3ɴ 3҈3$0>u CR3ҹ Xuր>u0GQRȃ09vCJuZY (c) 1991 Mountain Air Designs Flash Drive software: Version 1.04A-S (C) 1991 BSE Company Tustin, Calif. $XXX meg drive found: port xxxx xx sect/trk, XX heads, XXXX cyls $Power down mode not supported $XXXX second power down delay $Port XXXX not responding; load aborted. $XXXX: invalid port address. Using default port 8078 instead. $ 1234567890123456789012345678901234567890 $Logical drive x: xxx megabytes $No partitions defined $Interface test failed: xxxx xxxx $Diag. test: CONTROLLER ERROR $Diag. test: SECTOR BUFFER ERROR $Diag. test: CONTROL PROCESSOR ERROR $Diag. test: UNKNOWN TYPE ERROR $Unit xx : partition type is not compatible with this version of DOS $DOS version 2.x required. $Drive reconfigured for xxxx Cylinders, xxx Heads, xxx Sectors per Track. $Drive signature: xxxx unknown. $k Stack Stack    ..PSQRWVUȎ؉&Ȏ>&]2:~1<> &E]^_ZY[X˰&E3t&m&E3{t&}[gt&}GtÌȎ>&} (--pp > lp) /* Move pattern down */ *pp = pp[-1]; /* one byte */ *pp = (c == '*') ? STAR : (c == '-') ? MINUS : PLUS; pp = spp; /* Restore pattern end */ continue; } /* * All the rest. */ lp = pp; /* Remember start */ switch(c) { case '^': store(BOL); break; case '$': store(EOL); break; case '.': store(ANY); break; case '[': s = cclass(source, s); break; case ':': if (*s) { c = *s++; switch(tolower(c)) { case 'a': case 'A': store(ALPHA); break; case 'd': case 'D': store(DIGIT); break; case 'n': case 'N': store(NALPHA); break; case ' ': store(PUNCT); break; default: badpat("Unknown : type", source, s); } break; } else badpat("No : type", source, s); case '\\': if (*s) c = *s++; default: store(CHAR); store(tolower(c)); } } store(ENDPAT); store(0); /* Terminate string */ if (debug) { for (lp = pbuf; lp < pp;) { if ((c = (*lp++ & 0377)) < ' ') printf("\\%o ", c); else printf("%c ", c); } printf("\n"); } } /*******************************************************/ char * cclass(source, src) char *source; /* Pattern start -- for error msg. */ char *src; /* Class start */ /* * Compile a class (within []) */ { register char *s; /* Source pointer */ register char *cp; /* Pattern start */ register int c; /* Current character */ int o; /* Temp */ s = src; o = CLASS; if (*s == '^') { ++s; o = NCLASS; } store(o); cp = pp; store(0); /* Byte count */ while ((c = *s++) && c!=']') { if (c == '\\') { /* Store quoted char */ if ((c = *s++) == '\0') /* Gotta get something */ badpat("Class terminates badly", source, s); else store(tolower(c)); } else if (c == '-' && (pp - cp) > 1 && *s != ']' && *s != '\0') { c = pp[-1]; /* Range start */ pp[-1] = RANGE; /* Range signal */ store(c); /* Re-store start */ c = *s++; /* Get end char and*/ store(tolower(c)); /* Store it */ } else { store(tolower(c)); /* Store normal char */ } } if (c != ']') badpat("Unterminated class", source, s); if ((c = (pp - cp)) >= 256) badpat("Class too large", source, s); if (c == 0) badpat("Empty class", source, s); *cp = c; return(s); } /*******************************************************/ store(op) { if (pp >= &pbuf[PMAX]) error("Pattern too complex\n"); *pp++ = op; } /*******************************************************/ badpat(message, source, stop) char *message; /* Error message */ char *source; /* Pattern start */ char *stop; /* Pattern end */ { register int c; fprintf(stderr, "-GREP-E-%s, pattern is\"%s\"\n", message, source); fprintf(stderr, "-GREP-E-Stopped at byte %d, '%c'\n", stop-source, stop[-1]); error("?GREP-E-Bad pattern\n"); } /*******************************************************/ grep(fp, fn) FILE *fp; /* File to process */ char *fn; /* File name (for -f option) */ /* * Scan the file for the pattern in pbuf[] */ { register int lno, count, m; lno = 0; count = 0; while (fgets(lbuf, LMAX, fp)) { ++lno; m = match(); if ((m && !vflag) || (!m && vflag)) { ++count; if (!cflag) { if (fflag && fn) { file(fn); fn = 0; } if (nflag) printf("%d\t", lno); printf("%s\n", lbuf); } } } if (cflag) { if (fflag && fn) file(fn); printf("%d\n", count); } } /*******************************************************/ match() /* * Match the current line (in lbuf[]), return 1 if it does. */ { register char *l; /* Line pointer */ char *pmatch(); for (l = lbuf; *l; l++) { if (pmatch(l, pbuf)) return(1); } return(0); } /*******************************************************/ char * pmatch(line, pattern) char *line; /* (partial) line to match */ char *pattern; /* (partial) pattern to match */ { register char *l; /* Current line pointer */ register char *p; /* Current pattern pointer */ register char c; /* Current character */ char *e; /* End for STAR and PLUS match */ int op; /* Pattern operation */ int n; /* Class counter */ char *are; /* Start of STAR match */ l = line; if (debug > 1) printf("pmatch(\"%s\")\n", line); p = pattern; while ((op = *p++) != ENDPAT) { if (debug > 1) printf("byte[%d] = 0%o, '%c', op = 0%o\n", l-line, *l, *l, op); switch(op) { case CHAR: if (tolower(*l++) != *p++) return(0); break; case BOL: if (l != lbuf) return(0); break; case EOL: if (*l != '\0') return(0); break; case ANY: if (*l++ == '\0') return(0); break; case DIGIT: if ((c = *l++) < '0' || (c > '9')) return(0); break; case ALPHA: c = tolower(*l++); if (c < 'a' || c > 'z') return(0); break; case NALPHA: c = tolower(*l++); if (c >= 'a' && c <= 'z') break; else if (c < '0' || c > '9') return(0); break; case PUNCT: c = *l++; if (c == 0 || c > ' ') return(0); break; case CLASS: case NCLASS: c = tolower(*l++); n = *p++ & 0377; do { if (*p == RANGE) { p += 3; n -= 2; if (c >= p[-2] && c <= p[-1]) break; } else if (c == *p++) break; } while (--n > 1); if ((op == CLASS) == (n <= 1)) return(0); if (op == CLASS) p += n - 2; break; case MINUS: e = pmatch(l, p); /* Look for a match */ while (*p++ != ENDPAT); /* Skip over pattern */ if (e) /* Got a match? */ l = e; /* Yes, update string */ break; /* Always succeeds */ case PLUS: /* One or more ... */ if ((l = pmatch(l, p)) == 0) return(0); /* Gotta have a match */ case STAR: /* Zero or more ... */ are = l; /* Remember line start */ while (*l && (e = pmatch(l, p))) l = e; /* Get longest match */ while (*p++ != ENDPAT); /* Skip over pattern */ while (l >= are) { /* Try to match rest */ if (e = pmatch(l, p)) return(e); --l; /* Nope, try earlier */ } return(0); /* Nothing else worked */ default: printf("Bad op code %d\n", op); error("Cannot happen -- match\n"); } } return(l); } /*******************************************************/ error(s) char *s; { fprintf(stderr, "%s", s); exit(1); } /*******************************************************/ #ifdef DeSmet fclose(file) FILE file; { return(close(file)); } #endif