📄 arscanpr.c
字号:
/*
Copyright (c) 2003, Dan Kranz and Arnold Rom
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* The names of its contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <roots.h>
/* ############################################################################# */
/* # SCANPR (BLOCK,CPL,FIELD,TEXT,TFIELD,FIRST,LNEXTL,MATCH) # */
/* # # */
/* # For all block lines of FIRST,LNEXTL BLOCK(FIELD) is scanned for a # */
/* # substrings of TEXT(TFIELD). # */
/* # # */
/* # Matching entries are entered in MATCH, LNEXTL. # */
/* # # */
/* # Non-matching entries remain in FIRST,LNEXTL. # */
/* # # */
/* # SCANPR is a scanning-search prune subroutine. The routine is usefull # */
/* # for general data base prune operations. The scan for a match with # */
/* # TEXT(TFIELD) recycles for each block line of LNEXTL; i.e. the search # */
/* # operation is simmilar to the lgscan operation. Unlike LGSCAN, SCANPR # */
/* # does not return the matching position within a matching line. # */
/* # # */
/* # Except for the scanning search, and the fact that SCANPR is not case # */
/* # sensitive, SCANPR is functionally identical to TXTPRN. # */
/* # # */
/* # Note: the input case and the block lines examined are both converted to # */
/* # upper case before comparing! # */
/* ############################################################################# */
#define MAXTOKEN 256
/* small internal routines */
static void sos(void) {RootsSOS("scanprn sos exit\n"); abort();}
void scanpr(
BYTE *call_block,
long *cpl,
long *field,
BYTE *call_text,
long *tfield,
long *first,
unsigned short *lnextl,
long *match
)
/* --------------------------------------------------------- */
{ /* scanpr START */
/* --------------------------------------------------------- */
/* local data */
static BYTE HmapL[256],mapset;
static BYTE H[26]=
{'A','B','C','D','E','F','G','H','I','J','K','L','M','N',
'O','P','Q','R','S','T','U','V','W','X','Y','Z'};
static BYTE L[26]=
{'a','b','c','d','e','f','g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v','w','x','y','z'};
long guard=MAXLIN,LastMatch,InBlockCpl=*(field+1),InTextCpl=*(tfield+1);
long CurrentInputLine,PreviousInputLine,NextInputLine,i;
BlockCplNline block;
BYTE *text=call_text+(*tfield-1),*k;
ByteArray BlockToken={NULL,0};
BYTE SearchToken[MAXTOKEN];
block.block=call_block+(*field-1); block.cpl=*cpl; block.nline=0;
/* ---------------------------------------------- */
/* define transaltion map the first time in */
/* ---------------------------------------------- */
if(!mapset)
{
for(i=0;i<sizeof(HmapL);i++) HmapL[i]=(BYTE)i;
for(i=0;i<sizeof(L); i++) HmapL[L[i]]=H[i];
mapset=TRUE;
}
/* ----------------- */
/* verify args */
/* ----------------- */
if(
block.cpl <=0 ||
*(field+0)<=0 ||
InBlockCpl<=0 ||
*(field)+InBlockCpl-1>(block.cpl) ||
*(tfield+0)<=0 ||
InTextCpl>InBlockCpl ||
InTextCpl >=MAXTOKEN
)
{
RootsError("Argument Error in scanpr");
sos();
}
ExpandByte(BlockToken,(InBlockCpl+1));
/* ---------------------------------------- */
/* move text converted to upper case */
/* ---------------------------------------- */
for(i=0;i<InTextCpl;i++)SearchToken[i]=HmapL[*(text+i)];
SearchToken[i]='\0';
/* close out block token now */
BlockToken.array[InBlockCpl]='\0';
/* -------------------------------- */
/* set up for scan */
/* -------------------------------- */
PreviousInputLine=LastMatch=*match=0;
if((CurrentInputLine=*first)==0){FreeArray(BlockToken); return;}
if(CurrentInputLine<0)sos();
--lnextl;
/* ------------------------------------ */
/* process all members of lnextl */
/* ------------------------------------ */
while(CurrentInputLine>0)
{
if(!guard--)sos();
/* ------------------------------------------------------------------ */
/* advance to next member if CurrentInputLine does not match */
/* ------------------------------------------------------------------ */
k=BlockPointer(block,CurrentInputLine);
for(i=0;i<InBlockCpl;i++)BlockToken.array[i]=HmapL[*(k+i)];
if(strstr(BlockToken.array,SearchToken)==NULL)
{
PreviousInputLine=CurrentInputLine;
CurrentInputLine=*(lnextl+CurrentInputLine);
continue;
}
/* ----------------------------------------------------------------- */
/* CurrentInputLine has a match */
/* ----------------------------------------------------------------- */
RemoveFromInputList(first,lnextl,CurrentInputLine,PreviousInputLine,
NextInputLine)
InsertIntoOutputList(match,lnextl,CurrentInputLine,LastMatch)
/* step */
CurrentInputLine=NextInputLine;
}
FreeArray(BlockToken);
return;
/* --------------------------------------------------------- */
} /* scanpr END */
/* --------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -