⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 armskprn.c

📁 roots--一个轻量级的内存数据库系统。基于Hash Map的table设计。快速轻巧。
💻 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>

/* ############################################################################# */
/* #     MSKPRN (BLOCK,CPL,FIELD,TEXT,TFIELD,FIRST,LNEXTL,MATCH,DLM)           # */
/* #                                                                           # */
/* #  MSKPRN  selects  a  subset of a given block's records based on a masked  # */
/* #  search.                                                                  # */
/* #                                                                           # */
/* #  MASKPRN's compare logic is as follows:                                   # */
/* #  --------------------------------------                                   # */
/* #  TEXT(FIELD)   contains   the   input   string   to   be  compared  with  # */
/* #  BLOCK(FIELD).                                                            # */
/* #                                                                           # */
/* #  TEXT(FIELD) also defines the compare mask to be applied; i.e.  all byte  # */
/* #  positions  for  which  TEXT(FIELD) contains either a hexadecimal 0 or a  # */
/* #  hex  40  (blank)  will  be  skipped  when  comparing  TEXT(FIELD)  with  # */
/* #  BLOCK(FIELD); e.g.  Assume TEXT(FIELD) is three bytes wide and contains  # */
/* #  the  value  'A  C'.   The  blank  middle  position will be ignored.  An  # */
/* #  internal  hexadecimal  mask  containing  'FF00FF'  is  generated  to be  # */
/* #  applied when comparing text with block.                                  # */
/* #                                                                           # */
/* #  In this example all examined block lines whose BLOCK(FIELD) contain 'A'  # */
/* #  in  the  1.   position  and contain 'C' in the 3.  position are said to  # */
/* #  match TEXT(FIELD).                                                       # */
/* #                                                                           # */
/* #  The  default  blank  characters  in  TEXT  are  treated  as  wild-chard  # */
/* #  characters.                                                              # */
/* #                                                                           # */
/* #  Optional Wild-Card Character:                                            # */
/* #  ----------------------------                                             # */
/* #  Use the optional DLM argument when the TEXT argument includes blanks to  # */
/* #  be  searched  for.   DLM  is  a  single (1 byte) argument - typically a  # */
/* #  literal.  MSKPRN  will  use  DLM instead of hex 40 to build the masking  # */
/* #  string!                                                                  # */
/* #                                                                           # */
/* #  Line selection logic is as follows:                                      # */
/* #  -----------------------------------                                      # */
/* #  All  block lines of FIRST, LNEXTL are compared under mask with the text  # */
/* #  string defined by TEXT(FIELD).                                           # */
/* #                                                                           # */
/* #  All matching entries are entered in the sublist MATCH,LENXTL.            # */
/* #                                                                           # */
/* #  Non-matching entries remain in FIRST, LNEXTL.                            # */
/* ############################################################################# */

#define MAXTEXT 256

/* small internal routines */

static void sos(void) {RootsSOS("mskprn sos exit\n");
                                                          abort();}

void mskprn(
                      BYTE *call_block,
                      long *cpl,
                      long *field,
                      BYTE *call_text,
                      long *tfield,
                      long *first,
                      unsigned short *lnextl,
                      long *match,
                      BYTE *call_dlm
                      )

/* --------------------------------------------------------- */
{       /* mskprn START */
/* --------------------------------------------------------- */

/*      local data */

        long guard=MAXLIN,LastMatch,InBlockCpl=*(field+1),InTextCpl=*(tfield+1);
        long CurrentInputLine,PreviousInputLine,NextInputLine,i;
        unsigned short cmp[MAXTEXT],nComp=0,MatchFlag=TRUE;
        BlockCplNline block;
        BYTE *text=call_text+(*tfield-1),*k;
        BYTE dlm=' ';


        block.block=call_block+(*field-1);  block.cpl=*cpl; block.nline=0;

        if(call_dlm!=NULL)dlm=*call_dlm;


/* ----------------- */
/*      verify args */
/* ----------------- */

        if(
           block.cpl <=0                             ||
           *(field+0)<=0                             ||
           InBlockCpl<=0                             ||
           *(field)+InBlockCpl-1>(block.cpl)         ||

           *(tfield+0)<=0                            ||

           InTextCpl!=InBlockCpl                     ||
           InTextCpl >MAXTEXT
          )sos();

/* -------------------------------------------------------------- */
/*      build compar offsets with wild cards skipped */
/* -------------------------------------------------------------- */

        for(i=0;i<InTextCpl;i++)if(*(text+i)!=dlm)cmp[nComp++]=(unsigned short)i;

/* -------------------------------- */
/*      set up for scan */
/* -------------------------------- */

        PreviousInputLine=LastMatch=*match=0;

        if((CurrentInputLine=*first)==0)return;
        if(CurrentInputLine<0)sos();

        --lnextl;

/* ------------------------------------ */
/*      process all members of lnextl */
/* ------------------------------------ */

        while(CurrentInputLine)
        {
        if(!guard--)sos();

/*      ------------------------------------------------------------------ */
/*      advance to next member if CurrentInputLine does not match */
/*      ------------------------------------------------------------------ */

        k=BlockPointer(block,CurrentInputLine);

/*      set match flag */

        for(i=0,MatchFlag=TRUE; MatchFlag==TRUE && i<nComp; i++)
                          if(*(k+cmp[i]) != *(text+cmp[i]))MatchFlag=FALSE;

        if(MatchFlag==FALSE)
        {
        PreviousInputLine=CurrentInputLine;
        CurrentInputLine=*(lnextl+CurrentInputLine);
        continue;
        }

/*      ----------------------------------------------------------------- */
/*      CurrentInputLine has a match */
/*      ----------------------------------------------------------------- */

        RemoveFromInputList(first,lnextl,CurrentInputLine,PreviousInputLine,
                                                              NextInputLine)

        InsertIntoOutputList(match,lnextl,CurrentInputLine,LastMatch)

/*      step */

        CurrentInputLine=NextInputLine;
        }

        return;
/* --------------------------------------------------------- */
}       /* mskprn END */
/* --------------------------------------------------------- */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -