%%HP:T(3);
@ PBK, by Robert Noe
@ Requires DBLIB and TLLIB from Donnelly's ToolKit.
DIR
  phne
    \<<
      IF PHDAT 1 GET SIZE NOT
      THEN inp DROP
      END 3 1 view
    \>>
  view
    \<< \-> n p
      \<< { } 'PHDAT' n GET { "SORT" } { "ADDR" "PHNE" "NAME" "ADD" "DEL" "QUIT"
 } DUP n GET 1 \->LIST SDIFF + { 1 } p + p + 1 + { "Addresses" "Numbers"
"Names" } n GET + DBR 4 ROLL PHDAT SWAP n SWAP PUT 'PHDAT' STO 3 ROLL DROP
        CASE DUP 1 ==
          THEN DROP { 2 3 1 } n GET aview
          END DUP 1 NEG ==
          THEN DROP 'p' STO n sort n p view
          END DUP 2 NEG ==
          THEN DROP { 2 1 1 } n GET SWAP view
          END DUP 3 NEG ==
          THEN DROP { 3 3 2 } n GET SWAP view
          END DUP 4 NEG ==
          THEN DROP DROP inp n SWAP view
          END DUP 5 NEG ==
          THEN DROP del n 1 view
          END DUP 0 == SWAP 6 NEG == OR
          THEN DROP
          END
        END
      \>>
    \>>
  aview
    \<< \-> n p
      \<< { "Name: " "Addr: " "  Ph: " } PHDAT OBJ\-> n EXTRACT ROLLD 3 \->LIST
{ "LIST" "NEXT" "PREV" "ADD" "DEL" "QUIT" } { 1 1 } p + { 1 "Detail" } + DBR
3 ROLL DROP 3 ROLL n recsto
        CASE DUP ABS 1 ==
          THEN DROP { 3 1 2 } SWAP GET n view
          END DUP 2 NEG ==
          THEN DROP n 1 +
            IF DUP PHDAT 1 GET SIZE >
            THEN DROP 1
            END SWAP aview
          END DUP 3 NEG ==
          THEN DROP n 1 -
            IF DUP 0 ==
            THEN DROP PHDAT 1 GET SIZE
            END SWAP aview
          END DUP 4 NEG ==
          THEN DROP DROP inp 1 aview
          END DUP 5 NEG ==
          THEN DROP DROP n del 1 1 aview
          END DUP 6 NEG == 2 PICK 0 == OR
          THEN DROP DROP
          END
        END
      \>>
    \>>
  sort
    \<< PHDAT 1 GET SIZE \-> p n
      \<< 1 n
        FOR l PHDAT OBJ\-> l EXTRACT \->LIST
        NEXT n p LSORT DUP 1 + DUPN 1 EXTRACT \->LIST 1 MSWAP DUP 1 + DUPN 2
EXTRACT \->LIST 1 MSWAP 3 EXTRACT \->LIST 1 MM\->L + SWAP DROP SWAP 1 \->LIST
SW AP + 'PHDAT' STO
      \>>
    \>>
  del
    \<< \-> n
      \<< 1 3
        FOR l PHDAT l GET DUP 1 n 1 - SUB SWAP DUP SIZE n 1 + SWAP SUB +
        NEXT 3 \->LIST 'PHDAT' STO
      \>>
    \>>
  recsto
    \<< \-> rec n
      \<< PHDAT 1 GET n rec 2 GET PUT PHDAT 2 GET n rec 3 GET PUT PHDAT 3 GET n
rec 1 GET PUT 3 \->LIST 'PHDAT' STO
      \>>
    \>>
  inp
    \<< "Enter name:" { "" 1 \Ga } INPUT PHDAT 3 GET SWAP + "Enter address:" { "
" 1 \Ga } INPUT PHDAT 1 GET SWAP + "Enter phone numb:" { "" 1 \Ga } INPUT PHDAT
2 GET
SWAP + 3 ROLL 3 \->LIST 'PHDAT' STO PHDAT 1 GET SIZE
    \>>
  CST { phne }
  PHDAT { { } { } { } }
END

