📄 dkstrprn.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.
*/
/* Prune by bit-string.
Entries for which bit string(block(field)) is on are entered
in match/lnextl. Non-matching entries remain in first/lnextl.
*/
#include <stdio.h>
#include <stdlib.h>
#include <roots.h>
static long c__1 = 1;
void strprn_0(int flag, void *arg_block, long *cpl, long *field,
void *arg_string, long *first, unsigned short *lnextl,
long *match)
{
BYTE *block=arg_block, *b, *string=arg_string;
long cur_line, prev_line, next_line, last_match;
long n, lguard=MAXLIN;
static BYTE tbits[8]= {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
if (*cpl < 1 ||
*field < 1 ||
*(field+1) < 1 ||
*field + *(field+1) - 1 > *cpl )
{
RootsSOS("strprn() sos!");
abort();
}
block -= *cpl;
--lnextl;
*match = prev_line = last_match = 0;
cur_line = *first;
while (cur_line != 0) {
if (!lguard--) {
RootsSOS("strprn() Bad input list!");
abort();
}
next_line = *(lnextl+cur_line);
/* Get the index number from block */
b = block + ((*cpl) * cur_line);
if (!flag)
bunpac(b,field,&n,&c__1);
else
bunpacArray(b,field,&n,&c__1);
if (n==0)
prev_line = cur_line;
else {
n -= 1;
/* Is the index bit on? */
if (*(string+(n>>3)) & tbits[n&0x7]) {
/* Disconnect current line from top of input list */
if (prev_line == 0)
*first = next_line;
/* Disconnect current line from spot other than top of input list */
else *(lnextl+prev_line) = (unsigned short) next_line;
/* Insert current line into match list */
/* First member of match list */
if (last_match==0)
*match = cur_line;
/* Extend match list */
else *(lnextl+last_match) = (unsigned short) cur_line;
last_match = cur_line;
}
else prev_line = cur_line;
}
cur_line = next_line;
}
if (last_match != 0)
*(lnextl+last_match) = 0;
}
void strprn(BYTE *block, long *cpl, long *field, void *string,
long *first, unsigned short *lnextl, long *match)
{
strprn_0(0,block,cpl,field,string,first,lnextl,match);
}
void strprnArray(void *block, long *cpl, long *field, void *string,
long *first, unsigned short *lnextl, long *match)
{
strprn_0(1,block,cpl,field,string,first,lnextl,match);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -