Bracked-R Active File Record Separator 
Author Message
 Bracked-R Active File Record Separator

  Bracketed-R , [R] ,  is an active record separator for delimiting
records in a library file in which only selected records are to be
loaded. A number list on the stack, marked with -1 at the beginning,
specifies which record numbers to load of a given type pointed to by the
double variable &R.TYPE. Thus a source library file can contain a
mixture of record types with a number of records for each type. The
record numbers can also be of different size for the different types;
its size is application depended. For example, a file could be arranged
with 2 digit records numbers for comment records and 3 digit numbers for
source code records.
  For added flexibility the manner in which records numbers are compared
( %RCD? ) is deferred. Some example actions are given later.

\ Record separator
\ Compare record label and number. If both match, exit to
\ allow block to load; otherwise, skip to next record
\ separator. Repeat until file is exhausted.
: [R] ( -1 [n..n] "ccc" -- -1 [n...n] "ccc'")

    BL PARSE EVALUATE %RCD? IF              \ compare number
       EXIT                    \ both matched, exit and let load
    BEGIN                      \ otherwise, skip to next record
      REFILL 0= IF             \ get next line
        EXIT THEN              \ leave if file exhausted
      BL PARSE  S" [R]"        \ first word and record separator
    COMPARE 0= UNTIL           \ repeat for next line until a match
  AGAIN ;                      \ repeat everything

The following file is given as an example of usage. Note that each
record type may have its own number sequence.

    This is the first comment block
[R] CODE 001
    : FOO ." some utility" ;
[R] CODE 002
    : BAR ." some other utility" ;
[R] SML 01
    <sml><title>Simple Markup Language</title>
    <p>Example marked up text using a simplified markup aimed for
    text residing on small medium such as block files.
    <p>This could be some document that explains FOO and BAR or
    even tests them as a part of literate programming since SML
    anchors support shell operations <a dos="forth FOO BYE">.
    Another comment block

To load BAR one could enter the following:
      S" CODE" R.TYPE $!                        / store record type
      R.TYPE COUNT &R.TYPE 2!                   / point to it
      ' (RCD-SOME) IS %RCD?                     / set some record #
                                                / compare action
                                                / (see later)
      -1 2 S" MYFILE.LIB" INCLUDED              / load BAR
      XX                                        / cleanup data stack

  However, to simplify entering parameters slash-r-paren, /R( , is
provided. Slash-r-paren can accept a number list, a range of numbers or
the keyword ALL. It also checks the file specification for an appended
record type but defaults to CODE if one is not given. The stack is left
clean so XX is not needed.

To load BAR the following would be entered:

      /R( 2) MYFILE.LIB                 / loads BAR

Other examples, showing alternatives, include:
     /R( 1 2) MYFILE.LIB                / SOME,  loads both FOO and BAR
     /R( ALL) MYFILE.LIB                / ALL,   loads both FOO and BAR
     /R( 1-2) MYFILE.LIB                / RANGE, loads both FOO and BAR
     /R( 1)   MYFILE.LIB:SML            / View sml text

( The last example assumed <sml> to be a text viewer that would display
the markedup text as it loads)

Slash-r-paren may be a bit of a hack, but I give it as is for the

32 CONSTANT #RT.MX          \ maximum size of record label
CREATE R.TYPE #RT.MX ALLOT  \ storage for a record label
2VARIABLE &R.TYPE           \ pointer to a  record label

\ Parse filespec leaving file pointer on data stack
\ if record label is included then parse and store it
\ and set a pointer to it
: FILE+LABEL' ( "file[:label]" -- $)
  BL PARSE 2DUP S" :" SEARCH IF     \ have record label
     TUCK 1 /STRING R.TYPE $!       \ store it
     R.TYPE COUNT &R.TYPE 2! -      \ set pointer, adjust file stg.
  ELSE 2DROP THEN ;                                        

\ Can have 3 types of record matching--ALL, RANGE or SOME
DEFER %RCD? ( -1 [n..n] nx -- -1 [n..n] f)
\ ALL, always true
\ RANGE, match if number is within limits
\ SOME, consume top of number list when true

\ Set up parameters for [R] in a convenient manner for
\ operator entry. The type of record match is determined
\ and record numbers, if any, are placed on stack.
\ Record numbers are generated in the following fashion
\ depending on the type of match specified:
\ ALL,    /R( ALL)       --> ( -1 )
\ RANGE,  /R( n1-n2)     --> ( -1 n1 n2+1)
\ SOME,   /R( n1 n2...n) --> ( -1 n...n2 n1)
\ The file spec is parsed and its pointer placed on stack
\ If a record label was included, it is parsed and stored
\ with a pointer set to it. If no label was given, the pointer
\ will be set to a default. Load the file and clean up data
\ stack afterwards.
: /R(   ( --)
( ALL )    S" ALL" SEARCH IF 2DROP   ['] (RCD-ALL)
                          ELSE 2DUP
                               R> SWAP >R - EVALUATE R> SWAP
                               ['] (RCD-RANGE)
                          ELSE 2DROP
( SOME )
  2>R DUP 2R> EVALUATE  \ evaluate ascending set of numbers
  DEPTH 1 ?DO           \ reverse them
  THEN THEN IS %RCD?    \ set record match type
  S" CODE" &R.TYPE 2!   \ point to default record label
  FILE+LABEL' INCLUDED  \ parse filespec:label and load
  BEGIN TRUE = UNTIL ;  \ clean up data stack

-- taz

Posted from []
via Mailgate.ORG Server - http://www.*-*-*.com/

Mon, 24 May 2004 08:33:15 GMT  
 [ 1 post ] 

 Relevant Pages 

1. how to specify a blank line as record separator

2. Need help on record separator

3. Impossible Record Separator

4. is there a record separator? RS

5. Perl-style input record separator in Python?

6. tclX: scancontext: Can I change the record separator?

7. Active Record on a Browse

8. Clarion for Dos: text file separator


10. Unexpected results using File::SEPARATOR

11. File::SEPARATOR for W2k?

12. Problems with Separator nodes in VRML-file


Powered by phpBB® Forum Software