grep.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1998 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* fmlgrep -- print lines matching (or not matching) a pattern
*
* status returns:
* TRUE - ok, and some matches
* FALSE - no matches or error
*/
#include <stdio.h>
#include <ctype.h>
#include "wish.h"
#include "ctl.h"
#include "eval.h"
#include "moremacros.h"
#include "message.h"
/*
* define some macros for rexexp.h
*/
char errstr[][64] = {
"Range endpoint too large." ,
"Bad number." ,
"``\\digit'' out of range." ,
"Illegal or missing delimiter." ,
"No remembered search string." ,
"\\( \\) imbalance." ,
"Too many \\(." ,
"More than 2 numbers given in \\{ \\}." ,
"} expected after \\." ,
"First number exceeds second in \\{ \\}." ,
"[ ] imbalance." ,
"Regular expression overflow." ,
"Unknown regexp error code!!" ,
};
/*
* Macros for FMLI i/o and FMLI error messages (rjk)
*/
#define PRINTF(x, y) { \
}
}
#define ESIZE 256
#define BLKSIZE 512
static int execute();
static int succeed();
static int fgetl();
char *strrchr();
static long lnum;
static int nflag;
static int bflag;
static int lflag;
static int cflag;
static int vflag;
static int sflag;
static int iflag;
static int errflg;
static int nfile;
static long tln;
static int nsucc;
static int nchars;
static int nlflag;
int argc;
char *argv[];
{
register c;
register char *arg;
extern int optind;
void regerr();
optind = 1;
switch(c) {
case 'v':
vflag++;
break;
case 'c':
cflag++;
break;
case 'n':
nflag++;
break;
case 'b':
bflag++;
break;
case 's':
sflag++;
break;
case 'l':
lflag++;
break;
case 'i':
iflag++;
break;
case '?':
errflg++;
}
errmsg("Usage: fmlgrep -blcnsvi pattern file . . .\n",
(char *)NULL);
/* exit(2); */
return(FAIL); /* rjk */
}
regerr(41);
return(FAIL); /* rjk */
}
if (iflag) {
}
if (--argc == 0)
else
while (argc-- > 0)
/* exit(nsucc == 2 ? 2 : nsucc == 0); */
}
static int
register char *file;
{
register char *lbuf;
register i, fromfile;
char *getastr(); /* rjk */
fromfile = 0;
if (!sflag)
nsucc = 2;
return;
}
fromfile++;
}
lnum = 0;
tln = 0;
/* rjk (from a file OR from Instr) */
continue;
nlflag = 1;
} else
nlflag = 0;
lnum++;
if (iflag) {
*lbuf = '\0';
} else
break; /* lflag only once */
}
if (fromfile) /* rjk */
if (cflag) {
if (nfile>1)
}
return;
}
static int
succeed(f)
register char *f;
{
if (cflag) {
tln++;
return(0);
}
if (lflag) {
PRINTF("%s\n", f);
return(1);
}
PRINTF("%s:", f);
if (bflag) /* print block number */
if (nflag) /* print line number */
if (nlflag)
/* fwrite(prntbuf, 1, nchars, stdout); old */
return(0);
}
void
register err;
{
switch(err) {
case 11:
err = 0;
break;
case 16:
err = 1;
break;
case 25:
err = 2;
break;
case 36:
err = 3;
break;
case 41:
err = 4;
break;
case 42:
err = 5;
break;
case 43:
err = 6;
break;
case 44:
err = 7;
break;
case 45:
err = 8;
break;
case 46:
err = 9;
break;
case 49:
err = 10;
break;
case 50:
err = 11;
break;
default:
err = 12;
break;
}
/* exit(2); */
}
/*
* The following code is a modified version of the fgets() stdio
* routine. The reason why it is used instead of fgets() is that
* we need to know how many characters we read into the buffer.
* Thus that value is returned here instead of the value of s1.
*/
#define MIN(x, y) (x < y ? x : y)
extern int _filbuf();
extern char *memccpy();
static int
char *ptr;
register int size;
{
register int n;
return (NULL);
break; /* no more data */
}
}
n = p - ptr;
ptr += n;
if (p != NULL)
break; /* found '\n' in buffer */
}
*ptr = '\0';
}