formatting
This commit is contained in:
149
source/egrep.y
149
source/egrep.y
@ -144,17 +144,15 @@ r: r OR r
|
|||||||
;
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
static int
|
static
|
||||||
yyerror(char *s)
|
int yyerror(char *s) {
|
||||||
{
|
|
||||||
message = s;
|
message = s;
|
||||||
longjmp(env, 1);
|
longjmp(env, 1);
|
||||||
return 1; /* silence a warning */
|
return 1; /* silence a warning */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static
|
||||||
yylex(void)
|
int yylex(void) {
|
||||||
{
|
|
||||||
int cclcnt, x;
|
int cclcnt, x;
|
||||||
char c, d;
|
char c, d;
|
||||||
|
|
||||||
@ -224,15 +222,13 @@ yylex(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static
|
||||||
synerror(void)
|
void synerror(void) {
|
||||||
{
|
|
||||||
yyerror("Syntax error");
|
yyerror("Syntax error");
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int
|
static
|
||||||
enter(int x)
|
unsigned int enter(int x) {
|
||||||
{
|
|
||||||
if(line >= MAXLIN)
|
if(line >= MAXLIN)
|
||||||
overflo();
|
overflo();
|
||||||
name[line] = x;
|
name[line] = x;
|
||||||
@ -241,9 +237,8 @@ enter(int x)
|
|||||||
return(line++);
|
return(line++);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int
|
static
|
||||||
cclenter(int x)
|
unsigned int cclenter(int x) {
|
||||||
{
|
|
||||||
unsigned int linno;
|
unsigned int linno;
|
||||||
|
|
||||||
linno = enter(x);
|
linno = enter(x);
|
||||||
@ -251,9 +246,8 @@ cclenter(int x)
|
|||||||
return (linno);
|
return (linno);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static
|
||||||
node(int x, int l, int r)
|
int node(int x, int l, int r) {
|
||||||
{
|
|
||||||
if(line >= MAXLIN)
|
if(line >= MAXLIN)
|
||||||
overflo();
|
overflo();
|
||||||
name[line] = x;
|
name[line] = x;
|
||||||
@ -264,9 +258,8 @@ node(int x, int l, int r)
|
|||||||
return(line++);
|
return(line++);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static
|
||||||
unary(int x, int d)
|
int unary(int x, int d) {
|
||||||
{
|
|
||||||
if(line >= MAXLIN)
|
if(line >= MAXLIN)
|
||||||
overflo();
|
overflo();
|
||||||
name[line] = x;
|
name[line] = x;
|
||||||
@ -276,34 +269,31 @@ unary(int x, int d)
|
|||||||
return(line++);
|
return(line++);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static
|
||||||
overflo(void)
|
void overflo(void) {
|
||||||
{
|
|
||||||
yyerror("internal table overflow");
|
yyerror("internal table overflow");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static
|
||||||
cfoll(int v)
|
void cfoll(int v) {
|
||||||
{
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
if (left[v] == 0) {
|
if (left[v] == 0) {
|
||||||
count = 0;
|
count = 0;
|
||||||
for (i = 1; i <= line; i++)
|
for (i = 1; i <= line; i++)
|
||||||
tmpstat[i] = 0;
|
tmpstat[i] = 0;
|
||||||
follow(v);
|
follow(v);
|
||||||
add(foll, v);
|
add(foll, v);
|
||||||
} else if (right[v] == 0)
|
} else if (right[v] == 0) {
|
||||||
cfoll(left[v]);
|
cfoll(left[v]);
|
||||||
else {
|
} else {
|
||||||
cfoll(left[v]);
|
cfoll(left[v]);
|
||||||
cfoll(right[v]);
|
cfoll(right[v]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static
|
||||||
cgotofn(void)
|
void cgotofn(void) {
|
||||||
{
|
|
||||||
unsigned int i, n, s;
|
unsigned int i, n, s;
|
||||||
int c, k;
|
int c, k;
|
||||||
char symbol[NCHARS];
|
char symbol[NCHARS];
|
||||||
@ -316,9 +306,9 @@ cgotofn(void)
|
|||||||
for (n=3; n<=line; n++)
|
for (n=3; n<=line; n++)
|
||||||
tmpstat[n] = 0;
|
tmpstat[n] = 0;
|
||||||
if (cstate(line-1)==0) {
|
if (cstate(line-1)==0) {
|
||||||
tmpstat[line] = 1;
|
tmpstat[line] = 1;
|
||||||
count++;
|
count++;
|
||||||
out[0] = 1;
|
out[0] = 1;
|
||||||
}
|
}
|
||||||
for (n=3; n<=line; n++)
|
for (n=3; n<=line; n++)
|
||||||
initstat[n] = tmpstat[n];
|
initstat[n] = tmpstat[n];
|
||||||
@ -418,40 +408,40 @@ cstate(int v)
|
|||||||
tmpstat[v] = 1;
|
tmpstat[v] = 1;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
return(1);
|
return 1;
|
||||||
}
|
}
|
||||||
else if (right[v] == 0) {
|
else if (right[v] == 0) {
|
||||||
if (cstate(left[v]) == 0) return (0);
|
if (cstate(left[v]) == 0) { return 0; }
|
||||||
else if (name[v] == PLUS) return (1);
|
else if (name[v] == PLUS) { return 1; }
|
||||||
else return (0);
|
else { return 0; }
|
||||||
}
|
}
|
||||||
else if (name[v] == CAT) {
|
else if (name[v] == CAT) {
|
||||||
if (cstate(left[v]) == 0 && cstate(right[v]) == 0) return (0);
|
if (cstate(left[v]) == 0 && cstate(right[v]) == 0) { return 0; }
|
||||||
else return (1);
|
else { return 1; }
|
||||||
}
|
}
|
||||||
else { /* name[v] == OR */
|
else { /* name[v] == OR */
|
||||||
b = cstate(right[v]);
|
b = cstate(right[v]);
|
||||||
if (cstate(left[v]) == 0 || b == 0) return (0);
|
if (cstate(left[v]) == 0 || b == 0) { return 0; }
|
||||||
else return (1);
|
else { return 1; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static
|
||||||
member(int symb, int set, int torf)
|
int member(int symb, int set, int torf) {
|
||||||
{
|
unsigned num = chars[set];
|
||||||
unsigned int i, num, pos;
|
unsigned pos = set + 1;
|
||||||
|
|
||||||
num = chars[set];
|
for (unsigned i = 0; i < num; i++) {
|
||||||
pos = set + 1;
|
if (symb == (unsigned char)(chars[pos++])) {
|
||||||
for (i = 0; i < num; i++)
|
return torf;
|
||||||
if (symb == (unsigned char)(chars[pos++]))
|
}
|
||||||
return (torf);
|
}
|
||||||
return (!torf);
|
|
||||||
|
return !torf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static
|
||||||
notin(int n)
|
int notin(int n) {
|
||||||
{
|
|
||||||
int i, j, pos;
|
int i, j, pos;
|
||||||
for (i=0; i<=n; i++) {
|
for (i=0; i<=n; i++) {
|
||||||
if (positions[state[i]] == count) {
|
if (positions[state[i]] == count) {
|
||||||
@ -466,9 +456,8 @@ notin(int n)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static
|
||||||
add(int *array, int n)
|
void add(int *array, int n) {
|
||||||
{
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
if (nxtpos + count > MAXPOS)
|
if (nxtpos + count > MAXPOS)
|
||||||
@ -476,15 +465,14 @@ add(int *array, int n)
|
|||||||
array[n] = nxtpos;
|
array[n] = nxtpos;
|
||||||
positions[nxtpos++] = count;
|
positions[nxtpos++] = count;
|
||||||
for (i=3; i <= line; i++) {
|
for (i=3; i <= line; i++) {
|
||||||
if (tmpstat[i] == 1) {
|
if (tmpstat[i] == 1) {
|
||||||
positions[nxtpos++] = i;
|
positions[nxtpos++] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static
|
||||||
follow(unsigned int v)
|
void follow(unsigned int v) {
|
||||||
{
|
|
||||||
unsigned int p;
|
unsigned int p;
|
||||||
|
|
||||||
if (v == line)
|
if (v == line)
|
||||||
@ -518,9 +506,7 @@ follow(unsigned int v)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char * egrepinit(const char *egreppat) {
|
||||||
egrepinit(const char *egreppat)
|
|
||||||
{
|
|
||||||
/* initialize the global data */
|
/* initialize the global data */
|
||||||
memset(gotofn, 0, sizeof(gotofn));
|
memset(gotofn, 0, sizeof(gotofn));
|
||||||
memset(state, 0, sizeof(state));
|
memset(state, 0, sizeof(state));
|
||||||
@ -553,7 +539,8 @@ egrepinit(const char *egreppat)
|
|||||||
static char buf[2 * BUFSIZ];
|
static char buf[2 * BUFSIZ];
|
||||||
static const char *buf_end = buf + (sizeof(buf) / sizeof(*buf));
|
static const char *buf_end = buf + (sizeof(buf) / sizeof(*buf));
|
||||||
|
|
||||||
static size_t read_next_chunk(char **p, FILE *fptr)
|
static
|
||||||
|
size_t read_next_chunk(char **p, FILE *fptr)
|
||||||
{
|
{
|
||||||
if (*p <= (buf + BUFSIZ)) {
|
if (*p <= (buf + BUFSIZ)) {
|
||||||
/* bwlow the middle, so enough space left for one entire BUFSIZ */
|
/* bwlow the middle, so enough space left for one entire BUFSIZ */
|
||||||
@ -567,9 +554,7 @@ static size_t read_next_chunk(char **p, FILE *fptr)
|
|||||||
return fread(*p, sizeof(**p), buf_end - *p, fptr);
|
return fread(*p, sizeof(**p), buf_end - *p, fptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int egrep(char * file, FILE *output, char *format) {
|
||||||
egrep(char *file, FILE *output, char *format)
|
|
||||||
{
|
|
||||||
char *p;
|
char *p;
|
||||||
unsigned int cstat;
|
unsigned int cstat;
|
||||||
int ccount;
|
int ccount;
|
||||||
@ -656,8 +641,6 @@ egrep(char *file, FILE *output, char *format)
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void egrepcaseless(int i) {
|
||||||
egrepcaseless(int i)
|
|
||||||
{
|
|
||||||
iflag = i; /* simulate "egrep -i" */
|
iflag = i; /* simulate "egrep -i" */
|
||||||
}
|
}
|
||||||
|
@ -95,8 +95,7 @@ extern const char * incdir;
|
|||||||
|
|
||||||
/* digraph data for text compression */
|
/* digraph data for text compression */
|
||||||
extern char dichar1[]; /* 16 most frequent first chars */
|
extern char dichar1[]; /* 16 most frequent first chars */
|
||||||
extern char dichar2[]; /* 8 most frequent second chars
|
extern char dichar2[]; /* 8 most frequent second chars using the above as first chars */
|
||||||
using the above as first chars */
|
|
||||||
extern char dicode1[]; /* digraph first character code */
|
extern char dicode1[]; /* digraph first character code */
|
||||||
extern char dicode2[]; /* digraph second character code */
|
extern char dicode2[]; /* digraph second character code */
|
||||||
|
|
||||||
@ -185,9 +184,9 @@ extern int blocklen; /* length of disk block read */
|
|||||||
|
|
||||||
/* lookup.c global data */
|
/* lookup.c global data */
|
||||||
extern struct keystruct {
|
extern struct keystruct {
|
||||||
const char * text;
|
const char * text;
|
||||||
const char delim;
|
const char delim;
|
||||||
struct keystruct *next;
|
struct keystruct *next;
|
||||||
} keyword[];
|
} keyword[];
|
||||||
|
|
||||||
/* readline.c global data */
|
/* readline.c global data */
|
||||||
|
Reference in New Issue
Block a user