📄 agrep.c
字号:
r1 = Init1 & r2;
r0 = B[3] | r3;
B[4] = ((r3 | Next[r0>>hh] | Next1[r0&LL])&r_NO_ERR) | r1 ;
if(D == 4) goto Nextchar1mem;
}
} /* if(NOT Newline) */
else {
j++;
if (DELIMITER) CurrentByteOffset -= D_length;
else CurrentByteOffset -= 1;
r1 = Init1 & A[D]; /* match against endofline */
B[D] = ((Next[A[D]>>hh] | Next1[A[D]&LL]) & CMask) | r1;
if(TAIL) B[D] = ( Next[B[D]>>hh] | Next1[B[D]&LL] ) | B[D];
/* epsilon move */
if(( B[D] & 1 ) ^ INVERSE) {
if(FILENAMEONLY && (NEW_FILE || !POST_FILTER)) {
num_of_matched++;
if (agrep_finalfp != NULL)
fprintf(agrep_finalfp, "%s\n", CurrentFileName);
else {
int outindex;
for(outindex=0; (outindex+agrep_outpointer<agrep_outlen) &&
(CurrentFileName[outindex] != '\0'); outindex++) {
agrep_outbuffer[agrep_outpointer+outindex] = CurrentFileName[outindex];
}
if ((CurrentFileName[outindex] != '\0') || (outindex+agrep_outpointer+1>=agrep_outlen)) {
OUTPUT_OVERFLOW;
free_buf(Text, buffer);
return -1;
}
else agrep_outbuffer[agrep_outpointer+outindex++] = '\n';
agrep_outpointer += outindex;
}
free_buf(Text, buffer);
NEW_FILE = OFF;
return 0;
}
if (-1 == r_output(buffer, i, end, j)) {free_buf(Text, buffer); return -1;}
if (((LIMITOUTPUT > 0) && (LIMITOUTPUT <= num_of_matched)) ||
((LIMITPERFILE > 0) && (LIMITPERFILE <= num_of_matched - prev_num_of_matched))) {
free_buf(Text, buffer);
return 0; /* done */
}
}
for(k=0; k<=D; k++) A[k] = Init0;
r1 = Init1 & A[0];
B[0] = ((Next[A[0]>>hh] | Next1[A[0]&LL]) & CMask) | r1;
for(k=1; k<=D; k++) {
r3 = A[k];
r1 = Init1 & r3;
r2 = A[k-1] | B[k-1];
B[k] = ((Next[r3>>hh] | Next1[r3&LL]) & CMask) | ((A[k-1] | Next[r2>>hh] | Next1[r2&LL]) & r_NO_ERR) | r1;
}
if (DELIMITER) CurrentByteOffset += 1*D_length;
else CurrentByteOffset += 1*1;
}
Nextchar1mem:
i=i+1;
CurrentByteOffset ++;
} /* while i < end */
return 0;
}
#endif /*AGREP_POINTER*/
} /* re1 */
int re(Text, M, D)
int Text, M, D;
{
register unsigned i, c, r1, r2, r3, CMask, k, Newline, Init0, Init1, end;
register unsigned r_even, r_odd, r_NO_ERR ;
unsigned RMask[MAXSYM];
unsigned A[MaxRerror+1], B[MaxRerror+1];
int num_read, j=0, lasti, base, ResidueSize;
int FIRST_TIME; /* Flag */
CHAR *buffer;
base = WORD - M;
k = 2*exponen(M);
if(FIRST_IN_RE) {
compute_next(M, Next, Next1);
FIRST_IN_RE = 0;
}
for(i=0; i< MAXSYM; i++) RMask[i] = Mask[i];
r_NO_ERR = NO_ERR_MASK;
Newline = '\n';
Init0 = Init[0] = Bit[base];
if(HEAD) Init0 = Init[0] = Init0 | Bit[base+1] ;
for(i=1; i<= D; i++) Init[i] = Init[i-1] | Next[Init[i-1]]; /* can be out? */
Init1 = Init0 | 1;
r2 = r3 = Init0;
for(k=0; k<= D; k++) {
A[k] = B[k] = Init[0];
} /* can be out? */
FIRST_TIME = ON;
alloc_buf(Text, &buffer, BlockSize+Maxline+1);
if ( D == 0 )
{
#if AGREP_POINTER
if(Text != -1) {
#endif /*AGREP_POINTER*/
lasti = Maxline;
while ((num_read = fill_buf(Text, buffer + Maxline, BlockSize)) > 0)
{
i=Maxline;
end = Maxline + num_read ;
if((num_read < BlockSize)&&buffer[end-1] != '\n') buffer[end] = '\n';
if(FIRST_TIME) {
buffer[i-1] = '\n';
i--;
CurrentByteOffset --;
FIRST_TIME = 0;
}
/* RE_PROCESS_WHEN_DZERO: the while-loop below */
while (i < end)
{
c = buffer[i++];
CurrentByteOffset ++;
CMask = RMask[c];
if(c != Newline)
{
r1 = Init1 & r3;
r2 = (Next[r3] & CMask) | r1;
}
else {
r1 = Init1 & r3; /* match against '\n' */
r2 = (Next[r3] & CMask) | r1;
j++;
if (DELIMITER) CurrentByteOffset -= D_length;
else CurrentByteOffset -= 1;
if(TAIL) r2 = Next[r2] | r2 ; /* epsilon move */
if(( r2 & 1) ^ INVERSE) {
if(FILENAMEONLY && (NEW_FILE || !POST_FILTER)) {
num_of_matched++;
if (agrep_finalfp != NULL)
fprintf(agrep_finalfp, "%s\n", CurrentFileName);
else {
int outindex;
for(outindex=0; (outindex+agrep_outpointer<agrep_outlen) &&
(CurrentFileName[outindex] != '\0'); outindex++) {
agrep_outbuffer[agrep_outpointer+outindex] = CurrentFileName[outindex];
}
if ((CurrentFileName[outindex] != '\0') || (outindex+agrep_outpointer+1>=agrep_outlen)) {
OUTPUT_OVERFLOW;
free_buf(Text, buffer);
return -1;
}
else agrep_outbuffer[agrep_outpointer+outindex++] = '\n';
agrep_outpointer += outindex;
}
free_buf(Text, buffer);
NEW_FILE = OFF;
return 0;
}
if (-1 == r_output(buffer, i-1, end, j)) {free_buf(Text, buffer); return -1;}
if (((LIMITOUTPUT > 0) && (LIMITOUTPUT <= num_of_matched)) ||
((LIMITPERFILE > 0) && (LIMITPERFILE <= num_of_matched - prev_num_of_matched))) {
free_buf(Text, buffer);
return 0; /* done */
}
}
lasti = i - 1;
r3 = Init0;
r2 = (Next[r3] & CMask) | Init0;
if (DELIMITER) CurrentByteOffset += 1*D_length;
else CurrentByteOffset += 1*1;
}
c = buffer[i++];
CurrentByteOffset ++;
CMask = RMask[c];
if(c != Newline)
{
r1 = Init1 & r2;
r3 = (Next[r2] & CMask) | r1;
}
else {
j++;
if (DELIMITER) CurrentByteOffset -= D_length;
else CurrentByteOffset -= 1;
r1 = Init1 & r2; /* match against endofline */
r3 = (Next[r2] & CMask) | r1;
if(TAIL) r3 = Next[r3] | r3;
if(( r3 & 1) ^ INVERSE) {
if(FILENAMEONLY && (NEW_FILE || !POST_FILTER)) {
num_of_matched++;
if (agrep_finalfp != NULL)
fprintf(agrep_finalfp, "%s\n", CurrentFileName);
else {
int outindex;
for(outindex=0; (outindex+agrep_outpointer<agrep_outlen) &&
(CurrentFileName[outindex] != '\0'); outindex++) {
agrep_outbuffer[agrep_outpointer+outindex] = CurrentFileName[outindex];
}
if ((CurrentFileName[outindex] != '\0') || (outindex+agrep_outpointer+1>=agrep_outlen)) {
OUTPUT_OVERFLOW;
free_buf(Text, buffer);
return -1;
}
else agrep_outbuffer[agrep_outpointer+outindex++] = '\n';
agrep_outpointer += outindex;
}
free_buf(Text, buffer);
NEW_FILE = OFF;
return 0;
}
if (-1 == r_output(buffer, i-1, end, j)) {free_buf(Text, buffer); return -1;}
if (((LIMITOUTPUT > 0) && (LIMITOUTPUT <= num_of_matched)) ||
((LIMITPERFILE > 0) && (LIMITPERFILE <= num_of_matched - prev_num_of_matched))) {
free_buf(Text, buffer);
return 0; /* done */
}
}
lasti = i - 1;
r2 = Init0;
r3 = (Next[r2] & CMask) | Init0; /* match the newline */
if (DELIMITER) CurrentByteOffset += 1*D_length;
else CurrentByteOffset += 1*1;
}
} /* while */
ResidueSize = Maxline + num_read - lasti;
if(ResidueSize > Maxline) {
ResidueSize = Maxline;
}
strncpy(buffer+Maxline-ResidueSize, buffer+lasti, ResidueSize);
lasti = Maxline - ResidueSize;
} /* while fill_buf() */
free_buf(Text, buffer);
return 0;
#if AGREP_POINTER
}
else {
num_read = agrep_inlen;
buffer = (CHAR *)agrep_inbuffer;
end = num_read;
/* buffer[end-1] = '\n';*/ /* at end of the text. */
/* buffer[0] = '\n';*/ /* in front of the text. */
i = 0;
lasti = 1;
/* An exact copy of the above RE_PROCESS_WHEN_DZERO: the while-loop below */
while (i < end)
{
c = buffer[i++];
CurrentByteOffset ++;
CMask = RMask[c];
if(c != Newline)
{
r1 = Init1 & r3;
r2 = (Next[r3] & CMask) | r1;
}
else {
r1 = Init1 & r3; /* match against '\n' */
r2 = (Next[r3] & CMask) | r1;
j++;
if (DELIMITER) CurrentByteOffset -= D_length;
else CurrentByteOffset -= 1;
if(TAIL) r2 = Next[r2] | r2 ; /* epsilon move */
if(( r2 & 1) ^ INVERSE) {
if(FILENAMEONLY && (NEW_FILE || !POST_FILTER)) {
num_of_matched++;
if (agrep_finalfp != NULL)
fprintf(agrep_finalfp, "%s\n", CurrentFileName);
else {
int outindex;
for(outindex=0; (outindex+agrep_outpointer<agrep_outlen) &&
(CurrentFileName[outindex] != '\0'); outindex++) {
agrep_outbuffer[agrep_outpointer+outindex] = CurrentFileName[outindex];
}
if ((CurrentFileName[outindex] != '\0') || (outindex+agrep_outpointer+1>=agrep_outlen)) {
OUTPUT_OVERFLOW;
free_buf(Text, buffer);
return -1;
}
else agrep_outbuffer[agrep_outpointer+outindex++] = '\n';
agrep_outpointer += outindex;
}
free_buf(Text, buffer);
NEW_FILE = OFF;
return 0;
}
if (-1 == r_output(buffer, i-1, end, j)) {free_buf(Text, buffer); return -1;}
if (((LIMITOUTPUT > 0) && (LIMITOUTPUT <= num_of_matched)) ||
((LIMITPERFILE > 0) && (LIMITPERFILE <= num_of_matched - prev_num_of_matched))) {
free_buf(Text, buffer);
return 0; /* done */
}
}
lasti = i - 1;
r3 = Init0;
r2 = (Next[r3] & CMask) | Init0;
if (DELIMITER) CurrentByteOffset += 1*D_length;
else CurrentByteOffset += 1*1;
}
c = buffer[i++];
CurrentByteOffset ++;
CMask = RMask[c];
if(c != Newline)
{
r1 = Init1 & r2;
r3 = (Next[r2] & CMask) | r1;
}
else {
j++;
if (DELIMITER) CurrentByteOffset -= D_length;
else CurrentByteOffset -= 1;
r1 = Init1 & r2; /* match against endofline */
r3 = (Next[r2] & CMask) | r1;
if(TAIL) r3 = Next[r3] | r3;
if(( r3 & 1) ^ INVERSE) {
if(FILENAMEONLY && (NEW_FILE || !POST_FILTER)) {
num_of_matched++;
if (agrep_finalfp != NULL)
fprintf(agrep_finalfp, "%s\n", CurrentFileName);
else {
int outindex;
for(outindex=0; (outindex+agrep_outpointer<agrep_outlen) &&
(CurrentFileName[outindex] != '\0'); outindex++) {
agrep_outbuffer[agrep_outpointer+outindex] = CurrentFileName[outindex];
}
if ((CurrentFileName[outindex] != '\0') || (outindex+agrep_outpointer+1>=agrep_outlen)) {
OUTPUT_OVERFLOW;
free_buf(Text, buffer);
return -1;
}
else agrep_outbuffer[agrep_outpointer+outindex++] = '\n';
agrep_outpointer += outindex;
}
free_buf(Text, buffer);
NEW_FILE = OFF;
return 0;
}
if (-1 == r_output(buffer, i-1, end, j)) {free_buf(Text, buffer); return -1;}
if (((LIMITOUTPUT > 0) && (LIMITOUTPUT <= num_of_matched)) ||
((LIMITPERFILE > 0) && (LIMITPERFILE <= num_of_matched - prev_num_of_matched))) {
free_buf(Text, buffer);
return 0; /* done */
}
}
lasti = i - 1;
r2 = Init0;
r3 = (Next[r2] & CMask) | Init0; /* match the newline */
if (DELIMITER) CurrentByteOffset += 1*D_length;
else CurrentByteOffset += 1*1;
}
} /* while */
/* If a residue is left for within-memory-buffer, since nothing can be "read" after that, we can ignore it: as if only 1 iteration of while */
return 0;
}
#endif /*AGREP_POINTER*/
} /* end if(D==0) */
#if AGREP_POINTER
if (Text != -1) {
#endif /*AGREP_POINTER*/
while ((num_read = fill_buf(Text, buffer + Maxline, BlockSize)) > 0)
{
i=Maxline;
end = Maxline+num_read;
if((num_read < BlockSize) && buffer[end-1] != '\n') buffer[end] = '\n';
if(FIRST_TIME) {
buffer[i-1] = '\n';
i--;
CurrentByteOffset --;
FIRST_TIME = 0;
}
/* RE_PROCESS_WHEN_DNOTZERO: the while-loop below */
while (i < end)
{
c = buffer[i++];
CurrentByteOffset ++;
CMask = RMask[c];
if (c != Newline)
{
r_even = B[0];
r1 = Init1 & r_even;
A[0] = (Next[r_even] & CMask) | r1;
r_odd = B[1];
r1 = Init1 & r_odd;
r2 = (r_even | Next[r_even|A[0]]) &r_NO_ERR;
A[1] = (Next[r_odd] & CMask) | r2 | r1 ;
if(D == 1) goto Nextcharfile;
r_even = B[2];
r1 = Init1 & r_even;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -