?? arsetprn.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 <roots.h>
/* ############################################################################# */
/* # SETPRN(STRING,FIRST,LNEXTL,MATCH) # */
/* # # */
/* # Purpose # */
/* # ------- # */
/* # Use SETPRN to split an input sub-list into two mutually exclusive # */
/* # output sublists. In particular, SETPRN scans each member of # */
/* # FIRST,LNEXTL; each member has an inherent LINE number which may range # */
/* # from 1 to NLINE. SETPRN uses the LINE numbers to address bit positions # */
/* # in STRING. # */
/* # # */
/* # Members whose STRING(LINE) contain a "1" are moved to output sub-list # */
/* # MATCH,LNEXTL. Members whose STRING(LINE) contain a "0" remain in # */
/* # FIRST,LNEXTL. # */
/* # # */
/* # Note: SETPRN is used typically in conjunction with SETBIT. # */
/* # # */
/* # The calling arguments to the current routine are as follows: # */
/* # ----------------------------------------------------------- # */
/* # STRING - is a LOGICAL*1 array containing a bit vector. # */
/* # # */
/* # FIRST - contains the first member of the input sub-list. # */
/* # # */
/* # LNEXTL - is a half-word array containing the input linked list. # */
/* # # */
/* # MATCH - contains the first member of the matching output sub-list. # */
/* # # */
/* # Output MATCH,LNEXTL will contain members whose STRING(LINE) # */
/* # contain a "1" # */
/* # # */
/* # Output FIRST,LNEXTL will contain the leftovers. # */
/* # # */
/* # Note: the input sort sequence is preserved in both output sublists. # */
/* ############################################################################# */
/* small internal routines */
static void sos(void) {RootsSOS("setprn sos exit\n"); abort();}
void setprn(
BYTE *string,
long *first,
unsigned short *lnextl,
long *match
)
/* --------------------------------------------------------- */
{ /* setprn START */
/* --------------------------------------------------------- */
/* local data */
long guard=MAXLIN,LastMatch;
long CurrentInputLine,PreviousInputLine,NextInputLine;
BYTE tbits[8]= {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
/* -------------------------------- */
/* setup */
/* -------------------------------- */
PreviousInputLine=LastMatch=*match=0;
if((CurrentInputLine=*first)==0)return;
if(CurrentInputLine<0)sos();
--lnextl;
/* ------------------------------------ */
/* process all members of lnextl */
/* ------------------------------------ */
while(CurrentInputLine>0)
{
if(!guard--)sos();
/* ----------------------------------------------------------------- */
/* advance to next input member if CurrentInputLine's bit is off */
/* ----------------------------------------------------------------- */
if(!( *(string+( (CurrentInputLine-1) >>3) )
&
tbits[ (CurrentInputLine-1) & 0x7]
)
)
{
PreviousInputLine=CurrentInputLine;
CurrentInputLine=*(lnextl+CurrentInputLine);
continue;
}
/* ----------------------------------------------------------------- */
/* bit(CurrentInputLine)==1) */
/* ----------------------------------------------------------------- */
RemoveFromInputList(first,lnextl,CurrentInputLine,PreviousInputLine,
NextInputLine)
InsertIntoOutputList(match,lnextl,CurrentInputLine,LastMatch)
/* step */
CurrentInputLine=NextInputLine;
}
return;
/* --------------------------------------------------------- */
} /* setprn END */
/* --------------------------------------------------------- */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -