/*
* 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 (c) 1990 AT&T */
/* All Rights Reserved */
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* cscope - interactive C symbol or text cross-reference
*
* text searching functions
*/
#include <fcntl.h>
#include <setjmp.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <ctype.h>
#include <unistd.h>
#include "library.h"
typedef enum {
NO = 0,
} BOOL;
typedef struct re_bm {
int *delta2;
int patlen;
} re_bm;
typedef struct Link {
} Link;
typedef struct Node {
short out;
short d;
short shift1;
short shift2;
long id;
} Node;
typedef struct re_cw {
long nodeid;
} re_cw;
typedef enum {
/* lit expression types */
/* non-lit expression types */
/* not really expression types, just helping */
} Exprtype;
typedef int ID;
typedef struct Expr {
struct Expr *l; /* pointer to Left child (or ccl count) */
struct Expr *r; /* pointer to Right child (or ccl mask) */
} Expr;
typedef struct State {
} State;
typedef struct FID {
} FID;
typedef struct Positionset {
/* 0 means not in position set */
/* -1 means first in position set */
/* n (>0) is ID of prev member of position set. */
} Positionset;
typedef struct re_re {
} re_re;
typedef struct {
} PATTERN;
typedef enum {
} FILE_STAT;
typedef struct {
} LINE;
}}
static char *format;
static char *file;
static int file_desc;
static int iflag;
static int bestlen;
static int nmalloc;
#ifdef DEBUG
#endif
static int execute(void);
static void err(char *s);
static char *message;
void
egrepcaseless(int i)
{
iflag = i; /* simulate "egrep -i" */
}
char *
{
int i;
if (firsttime) {
firsttime = 0;
for (i = 0; i < 256; i++) {
}
}
for (i = 0; i < nmalloc; i ++)
nmalloc = 0;
#ifdef DEBUG
{
PATTERN *p = match_pattern;
if (!p->fullmatch)
printf("PARTIAL BOYER_MOORE\n");
else
printf("PARTIAL B_M with GREP\n");
else
printf("FULL BOYER_MOORE\n");
printf("C_W\n");
else
printf("GENERAL\n");
}
#endif
}
return (message);
}
static void
{
#ifdef DEBUG
#endif
#ifdef DEBUG
{
uchar_t *p;
printf("\n");
}
#endif
return;
}
if (bestlen > 1) {
/* Partial Boyer Moore */
} else {
return;
}
}
/* general egrep regular expression */
}
}
static BOOL
{
/* Handle match to null string */
(*me)++;
(*me)++;
/* Handle match to new-line only */
(*me)++;
}
/* Handle match including beginning or ending new-line */
(*mb)++;
(*me)--;
return (YES);
}
static BOOL
{
uchar_t *s, *f;
}
f++;
}
return (YES);
} else {
*mb = f;
return (NO);
}
}
static void
{
unsigned int n;
/*
* This expression matches the null string!!!!
* Add EOP to beginning position set.
*/
/* (void) printf("first of root->l == 0, b=%s\n", b); */
}
stateinit(r);
savestate(r);
}
static void
{
err("internal error");
}
if (e->l) eptr(r, e->l);
if (e->r) eptr(r, e->r);
}
}
static BOOL
{
State *s, *t;
#ifdef DEBUG
if (TRACE(10)) {
}
#endif
s = startstate(r);
for (;;) {
uchar_t c;
if (s->cnt >= 0) {
#ifdef DEBUG
if (TRACE(6))
(void) printf("match at input '%s'\n", b);
#endif
*me = b;
return (YES);
}
if (b >= e) break;
#ifdef DEBUG
if (TRACE(4))
#endif
else s = nextstate(r, s, (int)c);
b++;
}
#ifdef DEBUG
if (TRACE(3)) {
}
#endif
return (NO);
}
static BOOL
{
switch (e->type) {
default: return (NO);
}
}
/*
* generates the followset for a node in fpos
*/
static void
{
Expr *p;
return;
else
p = e->parent;
switch (p->type) {
case EOP:
break;
case Plus:
case Star:
break;
case Quest:
case Alternate:
break;
case Cat:
break;
default:
break;
}
}
/*
* first_lit returns NO if e is nullable and in the process,
* ets up fpos.
*/
static BOOL
{
BOOL k;
switch (e->type) {
case Literal:
case Dot:
case Charclass:
return (YES);
case EOP:
case Star:
case Quest:
return (NO);
case Plus:
case Cat:
case Alternate:
default:
err("internal error");
}
return (NO);
}
static void
{
ID i, *p;
p = e->follow;
#ifdef DEBUG
#endif
*p++ = i;
#ifdef DEBUG
#endif
}
err("internal error");
}
}
static State *
{
ID j;
FID *p, *q;
State *s;
if (cnt) {
} else {
s = &r->istate;
s->cnt = -1;
}
p->id = j;
}
#ifdef DEBUG
if (TRACE(3)) {
}
#endif
return (s);
}
static State *
{
followstate(r, s, a, &r->tmp);
#ifdef DEBUG
if (TRACE(5)) {
a, buf);
}
#endif
#ifdef DEBUG
if (TRACE(5)) {
(void) printf("nextstate(%d, '%c'): returning %ld\n",
}
#endif
return (news);
}
static void
{
int j;
Expr *e;
if (match(e, a)) {
#ifdef DEBUG
printf("CHAR %c FC %c COUNT %d\n",
a,
#endif
}
}
}
}
static uchar_t *
{
uchar_t *x;
if (nmalloc >= MAXMALLOCS)
return (x);
}
#ifdef DEBUG
void
{
ID n;
(void) sprintf(p, "{}");
return;
}
*p++ = '{';
(void) sprintf(p, "%d,", n);
p = strchr(p, 0);
}
p[-1] = '}';
}
void
{
int i;
if (e == NULL) {
return;
}
switch (e->type) {
case Dot:
case Literal:
break;
case Charclass:
*res++ = '[';
for (i = 0; i < 256; i++)
*res++ = i;
}
*res++ = ']';
*res = '\0';
break;
case Cat:
break;
case Alternate:
break;
case Star:
break;
case Plus:
break;
case Quest:
break;
case EOP:
break;
default:
break;
}
}
static void
{
if (c > 0) {
*buf++ = '{';
*buf = '\0';
while (--c > 0) {
}
} else
}
#endif
static void
{
/* CONSTANTCONDITION */
/* CONSTANTCONDITION */
}
static void
{
r->nstates = 0; /* reclaim space for states and positions */
}
static void
{
}
static State *
{
return (&r->istate);
}
static int
{
clrstates(r);
#ifdef DEBUG
#endif
}
return (r->nstates++);
}
static State *
{
State *s;
int i;
FID *p, *e;
goto next;
return (s);
}
next:;
}
return (NULL);
}
static re_re *
{
re_re *r;
parno = 0;
maxid = 1;
eginit(r);
return (r);
}
static Expr *
{
e->type = t;
else e->id = 0;
}
}
e->flen = 0;
return (e);
}
static void
{
toklit = -1;
err("syntax error - missing character "
"after \\");
} else
break;
}
}
static int
{
int i;
int range = 0;
int count = 0;
}
}
/* scan for chars */
else range = 1;
continue;
}
if (range) {
}
} else {
}
range = 0;
}
else err("syntax error - missing ]");
if (comp) {
}
for (i = 0; i < 256; i++) {
lastc = i;
count++;
}
}
if (count == 1)
return (count);
}
/*
* egrep patterns:
*
* Alternation: d0: d1 { '|' d1 }*
* Concatenation: d1: d2 { d2 }*
* Repetition: d2: d3 { '*' | '?' | '+' }
* Literal: d3: lit | '.' | '[]' | '(' d0 ')'
*/
static Expr *
{
Expr *e;
int count;
switch (toktype) {
case Backslash:
case Literal:
break;
case Dot:
break;
case Charclass:
if (count == 1) {
} else {
}
break;
case Lpar:
else
err("syntax error - missing )");
return (e);
default:
err("syntax error");
e = NULL;
}
return (e);
}
static Expr *
{
Expr *e;
Exprtype t;
t = toktype;
}
return (e);
}
static Expr *
{
Expr *e, *f;
}
return (e);
}
static Expr *
{
Expr *e, *f;
continue;
}
return (e);
}
static Expr *
{
Expr *e;
err("syntax error");
return (e);
}
static void
err(char *s)
{
message = s;
}
static int
{
bestlen = 0;
if (bestlen < 2)
return (0);
*e = *b + bestlen - 1;
return (bestlen - 1);
}
static void
{
switch (e->type) {
case Literal:
break;
case Cat:
break;
case Plus:
FINISH /* can't go on past a + */
START /* but we can start with one! */
break;
default:
break;
}
}
static re_bm *
{
int j;
re_bm *b;
delta_2(b);
for (j = 0; j < 256; j++)
for (j = 0; j < 256; j++)
return (b);
}
static void
{
int m = b->patlen;
int i, k, j;
for (j = 0; j < m; j++) {
k = 1;
for (i = j + 1; i < m; i++) {
k++;
goto again;
}
}
b->delta2[j] = k + m - j - 1;
}
}
static BOOL
{
int k;
s += b->patlen - 1;
while ((unsigned long)s < (unsigned long)e) {
while ((unsigned long)(s += b->delta0[*s]) < (unsigned long)e)
;
if ((unsigned long)s < (unsigned long)(e + b->patlen))
return (NO); /* no match */
s -= LARGE;
}
if (k < 0) {
*me = s+1;
return (YES);
s = *mb;
} else if (k < 0) {
s++;
} else {
int j;
j = b->delta2[k];
if ((j > k) || (k == (int)LARGE))
k = j;
s = sp + k;
}
}
return (NO);
}
static re_cw *
{
return (NULL);
e = root->l;
return (NULL);
}
return (pat);
}
static BOOL
{
}
static BOOL
{
static uchar_t *p;
return (NO);
return (NO);
*p++ = e->lit;
else
return (NO);
if (buf)
return (YES);
}
static re_cw *
{
re_cw *c;
c->nodeid = 0;
c->maxdepth = 0;
c->mindepth = 10000;
return (c);
}
static void
{
Link *l;
int depth;
while (s <= --e) {
if (l->lit == *e)
break;
if (l == NULL)
break;
else
}
if (s <= e) {
state = p;
while (s <= e) {
state = p;
}
}
}
#ifdef DEBUG
static
{
Link *l;
printf("edge from \"%d\" to \"%d\" label {\"%c\"};",
}
printf(" edge from \"%d\" to \"%d\" dashed;",
}
printf("\n");
}
}
#endif
static void
{
Link *t;
int a;
}
while (qhead) {
DEL();
s = l->node;
a = l->lit;
ADD(s);
while (state) {
break;
if (ll)
/*
* do it here as only other exit is
* state 0
*/
s->out = 1;
}
break;
} else
}
}
}
}
static void
{
Link *l;
}
static void
{
Link *l;
Link *t;
int k;
for (k = 0; k < 256; k++)
}
while (qhead) {
DEL();
do {
k = r->d - state->d;
}
}
}
s = l->node;
ADD(s);
}
}
c->step[0] = 1;
}
static void
{
Link *l;
}
static void
{
Link *l;
}
}
static void
{
shift(c);
}
static BOOL
{
Link *l;
uchar_t *s;
uchar_t *e;
int k;
fake[0] = 0;
e = re;
while (s < e) {
/* scan */
goto nomatch;
} else {
if (l == NULL)
goto nomatch;
break;
}
}
}
*me = s+1;
return (YES);
}
break;
}
}
s += k;
}
return (NO);
}
static Node *
{
}
next_node->d = d;
return (next_node++);
}
static Link *
{
}
return (next_link++);
}
int
{
file = f;
output = o;
return (execute());
}
static int
execute(void)
{
return (-1);
}
/* while there is more get more text from the data stream */
for (;;) {
all_searched = NO;
/*
* Find next new-line in buffer.
* Begin after previous new line character
*/
/* There is more text in buffer */
/*
* Take our next
* "line" as the entire remaining buffer.
* However, if there is more of the file yet
* to be read in, exclude any incomplete
* line at end.
*/
all_searched = YES;
}
} else {
/*
* Find end of the last
* complete line in the buffer.
*/
}
/* end not found */
}
}
} else {
/* There is no more text in the buffer. */
}
/*
* There is no more text in the buffer,
* or no new line was found.
*/
switch (file_stat) {
case MORE: /* file partly unread */
case BEGIN:
continue; /* with while loop */
case NO_MORE:
break;
}
/* Nothing more to read in for this file. */
/* Nothing in the buffer, either */
/* We are done with the file. */
break; /* out of while loop */
}
/* There is no NL at the end of the file */
}
if (matched) {
int nc;
} else {
if (all_searched)
break; /* out of while loop */
}
}
return (0);
}
static void
{
}
static BOOL
{
return (YES);
} else {
return (NO);
}
} /* end of function pattern_match() */
static void
{
/*
* This function reads as much of the current file into the buffer
* as will fit.
*/
int save_current;
/*
* Bytes of current incomplete line, if any, save_current in buffer.
* These must be saved.
*/
/*
* A portion of the file fills the buffer. We must clear
* out the dead wood to make room for more of the file.
*/
int k = 0;
if (!k) {
/*
* We have one humungous current line,
* which fills the whole buffer.
* Toss it.
*/
save_current = 0;
}
if (save_current > 0) {
/*
* Must save portion of current line.
* Copy to beginning of buffer.
*/
}
}
/* Now read in the file. */
do {
if (bytes < 0) {
/* can't read any more of file */
bytes = 0;
}
/* No new lines or incomplete line in buffer */
} else if (bufsize) {
/* Still space in the buffer, so we have read entire file */
} else {
/* We filled entire buffer, so there may be more yet to read */
}
/* Note: bufend is 1 past last good char */
/* Set newline to character preceding the current line */
}
static void
{
while (*s++ != NL) {
}
}
static void
{
while (*--s != NL) {
}
while ((s > p) &&
++p;
}
}