Machine-Independent MDL for TOPS-20 and VAX.
[pdp10-muddle.git] / mim / development / mim / vax / mimlib / l-query-base.mud
1 ;"*****************************************************************************
2
3   This file defines a means for mapping over all records in LOCAL library.
4   Used by iterative queries in L-QUERY and the server for handling the same
5   over the network.
6
7   L-QUERY-BASE.MUD: EDIT HISTORY                            Machine Independent
8
9   COMPILATION: Spliced in at compile time.
10
11   JUN84   [Shane] - Created.
12   8OCT84  [Shane] - Commented, cleaned up.
13
14   ****************************************************************************"
15
16 ;"MAP-RECORDS --
17   Effect:    Create a state descriptor for NEXT-RECORD (somewhat like
18              ASSOCIATIONS). The state descriptor is a UVECTOR with the
19              following format:
20
21              [next-bucket bucket-cdr last-bucket]
22
23              where next-bucket is the file address of the next bucket in
24                    the hash table to examine (initially the first bucket).
25                    bucket-cdr is the file address of the next cons in the
26                    current bucket if it contained a list, else nil (0).
27                    (initially nil).
28                    last-bucket is the file address of the last bucket in
29                    the hash table.
30    Modifies: STATE, LIB (the channel access pointer).
31    Returns:  state descriptor (UVECTOR).
32    Requires: LIB is channel to correctly formatted library file (as defined
33              in LIBRARY.FORMAT), size(STATE) >= 3.
34    Note:     The offsets are defined in L-DEFS.MUD."
35
36 <DEFINE MAP-RECORDS (LIB:<CHANNEL 'DISK>
37                      "OPT" (STATE:<UVECTOR [3 FIX]> <IUVECTOR 3>))
38    ;"The address of the first bucket is DIR-HDRLEN. The address of the
39      last bucket is DIR-HDRLEN+DIR-TABSIZ-1. Point to DIR-TABSIZ and read."
40    <SETADR .LIB ,DIR-TABSIZ>
41    <LAST-BUCKET .STATE <+ <RDWRD .LIB>:FIX %<- ,DIR-HDRLEN 1>>>
42    <BUCKET-CDR .STATE 0>
43    <NEXT-BUCKET .STATE ,DIR-HDRLEN>>
44 \f
45 ;"NEXT-RECORD --
46   Effect:   Determine the file address of the next record in the iteration
47             over the library. Addresses are yielded in bucket order, position
48             in bucket list (if bucket contains a list).
49   Modifies: STATE, LIB (the channel access pointer).
50   Returns:  File address of next record in sequence if any, else false.
51   Requires: LIB is channel to correctly formatted library file (as defined in
52             LIBRARY.FORMAT), STATE is a state descriptor created by MAP-RECORDS
53             and modified by NEXT-RECORD (only!)."
54
55 <DEFINE NEXT-RECORD (LIB:<CHANNEL 'DISK> STATE:<UVECTOR [3 FIX]>)
56    <REPEAT ((LAST:FIX <LAST-BUCKET .STATE>) (BKT:FIX <NEXT-BUCKET .STATE>)
57             (BCDR:FIX <BUCKET-CDR .STATE>) BCAR:FIX "NAME" NEXTR)
58       <COND (<N==? .BCDR 0>                    ;"Are we in a list?"
59              <SETADR .LIB .BCDR   >            ;"Point to cons."
60              <SET BCAR <RDWRD .LIB>>           ;"Pointer to car."
61              <SET BCDR <RDWRD .LIB>>           ;"Pointer to cdr."
62              <COND (<TESTBIT .BCAR ,BKT-P>     ;"Package?"
63                     <NEXT-BUCKET .STATE .BKT>  ;"Set things up for next time."
64                     <BUCKET-CDR .STATE .BCDR>
65                     <RETURN <ADDRESS .BCAR> .NEXTR>)
66                    (T
67                     <AGAIN .NEXTR>)>)          ;"Check out the cdr."
68             (T                                 ;"Empty bucket or end of list."
69              <REPEAT ()
70                 <COND (<G? .BKT .LAST>         ;"Every bucket done?"
71                        <NEXT-BUCKET .STATE .BKT>
72                        <BUCKET-CDR .STATE 0>
73                        <RETURN %<> .NEXTR>)
74                       (T
75                        <SETADR .LIB .BKT>       ;"Point to next bucket."
76                        <SET BKT <+ .BKT 1>>     ;"Bump next."
77                        <SET BCAR <RDWRD .LIB>>  ;"Read current bucket."
78                        <COND (<TESTBIT .BCAR ,BKT-M>    ;"List?"
79                               <SET BCDR <ADDRESS .BCAR>>
80                               <RETURN>)     ;"Check out first cons above."
81                              (<TESTBIT .BCAR ,BKT-P>    ;"Package?"
82                               <NEXT-BUCKET .STATE .BKT>;"Next."
83                               <BUCKET-CDR .STATE 0>     ;"Not in list."
84                               <RETURN <ADDRESS .BCAR> .NEXTR>)>)>>)>>>