home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / d / dtu11b.zip / QSQLDEMO.EXE / QSQL.CLA < prev    next >
Text File  |  1992-09-22  |  27KB  |  593 lines

  1. QSQL         PROGRAM
  2. !       Copyright (c) 1991 Cook Database Design, Inc.
  3. !
  4. !  This source file is provided to give you a first hand view of how to
  5. !  incorporate SQL.EXE into your Clarion applications.  Feel free to
  6. !  modify this to suit your own needs.  Please note that in order to
  7. !  compile this, you need a copy of our QPREVIEW product.
  8. !
  9. !
  10.              INCLUDE('STD_KEYS.CLA')
  11.              INCLUDE('CTL_KEYS.CLA')
  12.              INCLUDE('ALT_KEYS.CLA')
  13.              INCLUDE('SHF_KEYS.CLA')
  14.              MAP
  15.              PROC(TABLE)
  16.              MODULE('XPREQSQL')
  17.                PROC(PREVIEW)
  18.                .
  19.              MODULE('QPREVIEW'),BINARY        ! REQUIRES QPREVIEW PRODUCT
  20.                PROC(QPREVIEW)
  21.                .
  22.              .
  23.  
  24. QSQLFILE     FILE,PRE(QSQ),CREATE,RECLAIM
  25. QSQLKEY        KEY(QSQ:DESCRIPTION),DUP,NOCASE,OPT
  26. RECORD         RECORD
  27. DESCRIPTION      STRING(60)                      !Description Of File
  28. L1               STRING(78)
  29. L2               STRING(78)
  30. L3               STRING(78)
  31. L4               STRING(78)
  32. L5               STRING(78)
  33. L6               STRING(78)
  34. L7               STRING(78)
  35. L8               STRING(78)
  36. L9               STRING(78)
  37. L10              STRING(78)
  38. L11              STRING(78)
  39. L12              STRING(78)
  40.              . .
  41.  
  42. SQLIN        DOS,ASCII,NAME('QSQL.IN')
  43.              RECORD
  44. RECORD       STRING(80)
  45.              ..
  46. ACTION       SHORT                               !0 = NO ACTION
  47.                                                  !1 = ADD RECORD
  48.                                                  !2 = CHANGE RECORD
  49.                                                  !3 = DELETE RECORD
  50.                                                  !4 = LOOKUP FIELD
  51.  
  52. TRUE         EQUATE(1)
  53. FALSE        EQUATE(0)
  54.  
  55. ASKDESC      SCREEN       WINDOW(4,62),HUE(15,2,0)
  56.                ROW(1,1)   STRING('╔═{60}╗')
  57.                ROW(2,1)   REPEAT(2);STRING('║<0{60}>║') .
  58.                ROW(4,1)   STRING('╚═{60}╝')
  59.                ROW(2,2)   STRING('ENTER A DESCRIPTION TO SAVE THE FILE UNDER:')
  60.                ROW(3,2)   ENTRY(@S60),USE(QSQ:DESCRIPTION),HUE(14,0),SEL(0,7)
  61.              .
  62. QUERYIN      SCREEN       WINDOW(25,80),HUE(15,1,0)
  63.                ROW(20,3)  PAINT(2,10),HUE(14,1)
  64.                ROW(18,3)  PAINT(1,13),HUE(14,1)
  65.                ROW(22,3)  PAINT(2,7),HUE(14,1)
  66.                ROW(20,43) PAINT(3,7),HUE(14,1)
  67.                ROW(24,19) PAINT(1,45),HUE(11,1)
  68.                ROW(2,28)  PAINT(2,26),HUE(12,1)
  69.                ROW(23,43) PAINT(1,8),HUE(14,1)
  70.                ROW(1,1)   STRING('<201,205{78},187>')
  71.                ROW(2,1)   REPEAT(2);STRING('<186,0{78},186>') .
  72.                ROW(4,1)   REPEAT(2),EVERY(13);STRING('<204,205{78},185>') .
  73.                ROW(5,1)   REPEAT(12);STRING('<186,0{78},186>') .
  74.                ROW(18,1)  REPEAT(7);STRING('<186,0{78},186>') .
  75.                ROW(25,1)  STRING('<200,205{78},188>')
  76.                ROW(2,3)   STRING('Version 2.5 ')
  77.                  COL(39)  STRING('QSQL')
  78.                ROW(3,3)   STRING('09/22/92')
  79.                  COL(28)  STRING('INTERACTIVE USER INTERFACE')
  80.                ROW(18,3)  STRING('QUERY SYNTAX:')
  81.                  COL(17)  STRING('SELECT fieldnames FROM files WHERE conditions')
  82.                ROW(20,3)  STRING('CTRL-ENTER')
  83.                  COL(14)  STRING('TO EXECUTE YOUR QUERY')
  84.                  COL(43)  STRING('CTRL-L')
  85.                  COL(51)  STRING('LOAD A PREVIOUSLY SAVED QUERY')
  86.                ROW(21,3)  STRING('CTRL-ESC')
  87.                  COL(14)  STRING('TO EXIT FROM THIS PACKAGE')
  88.                  COL(43)  STRING('CTRL-S')
  89.                  COL(51)  STRING('SAVE THIS QUERY')
  90.                ROW(22,3)  STRING('CTRL-V')
  91.                  COL(14)  STRING('VIEW OUTPUT FROM LAST QUERY')
  92.                  COL(43)  STRING('CTRL-F')
  93.                  COL(51)  STRING('LIST OF ALL .DAT FILES')
  94.                ROW(23,3)  STRING('CTRL-E')
  95.                  COL(14)  STRING('ERASE CURRENT QUERY')
  96.                  COL(43)  STRING('CTRL-D')
  97.                  COL(51)  STRING('TOGGLE DEBUG')
  98.                ROW(24,19) STRING('COPYRIGHT (C) 1991 COOK DATABASE DESIGN, INC.')
  99.                ROW(5,2)   TEXT(12,78),USE(QUERY),HUE(14,0),SEL(14,0)
  100. DBUGOUT        ROW(23,64) STRING(3),HUE(15,1)
  101.              .
  102.  
  103.  
  104. PSCREEN      SCREEN       WINDOW(5,45),HUE(15,2)
  105.                ROW(1,1)   STRING('╔═{43}╗')
  106.                ROW(2,1)   REPEAT(3);STRING('║<0{43}>║') .
  107.                ROW(5,1)   STRING('╚═{43}╝')
  108.                ROW(2,13)  STRING('PROCESSING YOUR QUERY')
  109.                ROW(4,3)   STRING('PRESS CTRL-BREAK TO TERMINATE PROCESSING')
  110.              .
  111.  
  112. QUERY          GROUP                             !RP COMMENT MEMO
  113. L1S              STRING(78)
  114. L2S              STRING(78)
  115. L3S              STRING(78)
  116. L4S              STRING(78)
  117. L5S              STRING(78)
  118. L6S              STRING(78)
  119. L7S              STRING(78)
  120. L8S              STRING(78)
  121. L9S              STRING(78)
  122. L10S             STRING(78)
  123. L11S             STRING(78)
  124. L12S             STRING(78)
  125.                .
  126.              GROUP,OVER(QUERY)
  127. QUERY_ROW      STRING(78),DIM(12)
  128.              .
  129. T1      LONG
  130. T2      LONG
  131. I       LONG
  132. L       LONG
  133. DEBUG   LONG
  134. OPENFLAG BYTE
  135.  
  136.   CODE
  137.   DEBUG=0
  138.   OPEN(QUERYIN)
  139.   OPENFLAG=0
  140.   LOOP
  141.      ALERT(CTRL_ESC)
  142.      ALERT(ESC_KEY)
  143.      ALERT(CTRL_ENTER)
  144.      ALERT(CTRL_E)
  145.      ALERT(CTRL_D)
  146.      ALERT(CTRL_L)
  147.      ALERT(CTRL_S)
  148.      ALERT(CTRL_F)
  149.      ALERT(CTRL_V)
  150.      IF DEBUG = 0 THEN DBUGOUT='ON'.
  151.      IF DEBUG = 1 THEN DBUGOUT='OFF'.
  152.      DISPLAY
  153.      ACCEPT
  154.      UPDATE
  155.      IF KEYCODE() = CTRL_E THEN
  156.                            QUERY=' '
  157.                            CYCLE
  158.                            .
  159.      IF KEYCODE() = CTRL_D THEN
  160.                            DEBUG=1-DEBUG
  161.                            CYCLE
  162.                            .
  163.      IF KEYCODE() = CTRL_L THEN
  164.                            DO LOAD_QUERY
  165.                            CYCLE
  166.                            .
  167.      IF KEYCODE() = CTRL_S THEN
  168.                            DO SAVE_QUERY
  169.                            CYCLE
  170.                            .
  171.      IF KEYCODE() = CTRL_F THEN
  172.                            RUNSMALL('DIR *.DAT > $DIR.OUT')
  173.                            PREVIEW('$DIR.OUT')
  174.                            CYCLE
  175.                            .
  176.      IF KEYCODE() = CTRL_V THEN
  177.                            PREVIEW('$QSQL.OUT')
  178.                            CYCLE
  179.                            .
  180.      IF KEYCODE() = ESC_KEY THEN BREAK.
  181.      IF KEYCODE() = CTRL_ESC THEN BREAK.
  182.      IF KEYCODE() <> CTRL_ENTER THEN CYCLE.
  183.      CREATE(SQLIN)
  184.      I=0
  185.      LOOP
  186.        I=I+1
  187.        IF I > 12 THEN BREAK.
  188.        IF QUERY_ROW[I] = ' ' THEN CYCLE.
  189.        RECORD=QUERY_ROW[I]
  190.        ADD(SQLIN)
  191.        .
  192.      CLOSE(SQLIN)
  193.      OPEN(PSCREEN)
  194.      IF DEBUG = 1 THEN
  195.              RUNSMALL('SQL -ds << QSQL.IN > $QSQL.OUT')
  196.            ELSE
  197.              RUNSMALL('SQL -s << QSQL.IN > $QSQL.OUT')
  198.              .
  199.      IF ERRORCODE() THEN
  200.                     SHOW(1,1,ERROR())
  201.                     SHOW(2,1,ERRORCODE())
  202.                     BEEP
  203.                     ASK
  204.                     .
  205.      CLOSE(PSCREEN)
  206.      PREVIEW('$QSQL.OUT')
  207.      .
  208.   RUNSMALL('ERASE $QSQL.OUT')
  209.   RUNSMALL('ERASE $DIR.OUT')
  210.   CLOSE(QSQLFILE)
  211.   CLOSE(QUERYIN)
  212.   RETURN                                         !EXIT TO DOS
  213. LOAD_QUERY  ROUTINE
  214.         IF OPENFLAG = 0 THEN DO OPENFILE.
  215.         ACTION=4
  216.         TABLE
  217.         IF ACTION THEN EXIT.
  218.         L1S=QSQ:L1
  219.         L2S=QSQ:L2
  220.         L3S=QSQ:L3
  221.         L4S=QSQ:L4
  222.         L5S=QSQ:L5
  223.         L6S=QSQ:L6
  224.         L7S=QSQ:L7
  225.         L8S=QSQ:L8
  226.         L9S=QSQ:L9
  227.         L10S=QSQ:L10
  228.         L11S=QSQ:L11
  229.         L12S=QSQ:L12
  230.         EXIT
  231. SAVE_QUERY  ROUTINE
  232.         IF OPENFLAG = 0 THEN DO OPENFILE.
  233.         OPEN(ASKDESC)
  234.         ALERT(CTRL_ESC)
  235.         ACCEPT
  236.         UPDATE
  237.         CLOSE(ASKDESC)
  238.         IF KEYCODE() = ESC_KEY THEN EXIT.
  239.         IF KEYCODE() = CTRL_ESC THEN EXIT.
  240.         GET(QSQLFILE,QSQ:QSQLKEY)                ! ok
  241.         IF ERROR() THEN
  242.                    DO SCR2FILE
  243.                    ADD(QSQLFILE)
  244.                    EXIT
  245.                    .
  246.         DO SCR2FILE
  247.         PUT(QSQLFILE)
  248.         EXIT
  249.  
  250. OPENFILE    ROUTINE
  251.         OPEN(QSQLFILE)
  252.         IF ERRORCODE() THEN CREATE(QSQLFILE).
  253.         OPENFLAG=1
  254.         EXIT
  255.  
  256. SCR2FILE ROUTINE
  257.         QSQ:L1=L1S
  258.         QSQ:L2=L2S
  259.         QSQ:L3=L3S
  260.         QSQ:L4=L4S
  261.         QSQ:L5=L5S
  262.         QSQ:L6=L6S
  263.         QSQ:L7=L7S
  264.         QSQ:L8=L8S
  265.         QSQ:L9=L9S
  266.         QSQ:L10=L10S
  267.         QSQ:L11=L11S
  268.         QSQ:L12=L12S
  269.         EXIT
  270. TABLE        PROCEDURE
  271. DELSCR       SCREEN       WINDOW(9,69),HUE(15,4,0)
  272.                ROW(1,1)   STRING('<201,205{67},187>')
  273.                ROW(2,1)   REPEAT(7);STRING('<186,0{67},186>') .
  274.                ROW(9,1)   STRING('<200,205{67},188>')
  275.                ROW(2,27)  STRING('Delete Screen')
  276.                ROW(6,4)   STRING('Press ENTER to DELETE the query')
  277.                ROW(7,4)   STRING('Press ESC to escape back to the table without '    |
  278.                             & 'deleting the query.')
  279. DESCOUT        ROW(4,4)   STRING(60),HUE(7,0)
  280.              .
  281.  
  282. SCREEN       SCREEN       PRE(SCR),WINDOW(21,62),HUE(15,1)
  283.                ROW(20,2)  PAINT(1,60),HUE(15,4)
  284.                ROW(2,2)   PAINT(1,60),HUE(15,3)
  285.                ROW(1,1)   STRING('╔═{60}╗')
  286.                ROW(2,1)   REPEAT(17);STRING('║<0{60}>║') .
  287.                ROW(19,1)  STRING('╠═{60}╣')
  288.                ROW(20,1)  STRING('║<0{60}>║')
  289.                ROW(21,1)  STRING('╚═{60}╝')
  290.                ROW(2,18)  STRING('Description of Stored Queries')
  291.                ROW(20,6)  STRING('To Select Query, move cursor to entry and '  |
  292.                             & 'press enter')
  293.                           ENTRY,USE(?FIRST_FIELD)
  294.                           ENTRY,USE(?PRE_POINT)
  295.                           REPEAT(16),EVERY(1),INDEX(NDX)
  296.                ROW(3,2)     POINT(1,60),USE(?POINT),ESC(?-1)
  297. DESCRIPTION      COL(2)     STRING(60)
  298.              .            .
  299.  
  300. NDX          BYTE                                !REPEAT INDEX FOR POINT AREA
  301. ROW          BYTE                                !ACTUAL ROW OF SCROLL AREA
  302. COL          BYTE                                !ACTUAL COLUMN OF SCROLL AREA
  303. COUNT        BYTE(16)                            !NUMBER OF ITEMS TO SCROLL
  304. ROWS         BYTE(16)                            !NUMBER OF ROWS TO SCROLL
  305. COLS         BYTE(60)                            !NUMBER OF COLUMNS TO SCROLL
  306. FOUND        BYTE                                !RECORD FOUND FLAG
  307. NEWPTR       LONG                                !POINTER TO NEW RECORD
  308.  
  309. TABLE        TABLE,PRE(TBL)                      !TABLE OF RECORD DATA
  310. PTR            LONG                              !  POINTER TO FILE RECORD
  311. DESCRIPTION    STRING(60)                        !Description Of File
  312.              .
  313.  
  314.   EJECT
  315.   CODE
  316.   ACTION# = ACTION                               !SAVE ACTION
  317.   OPEN(SCREEN)                                   !OPEN THE SCREEN
  318.   SETCURSOR                                      !TURN OFF ANY CURSOR
  319.   TBL:PTR = 1                                    !START AT TABLE ENTRY
  320.   NDX = 1                                        !PUT SELECTOR BAR ON TOP ITEM
  321.   ROW = ROW(?POINT)                              !REMEMBER TOP ROW AND
  322.   COL = COL(?POINT)                              !LEFT COLUMN OF SCROLL AREA
  323.   RECORDS# = TRUE                                !INITIALIZE RECORDS FLAG
  324.   CACHE(QSQ:QSQLKEY,.25)                            !CACHE KEY FILE
  325.   IF ACTION = 4                                  !  TABLE LOOKUP REQUEST
  326.     NEWPTR = POINTER(QSQLFILE)                   !  SET POINTER TO RECORD
  327.     IF NOT NEWPTR                                !  RECORD NOT PASSED TO TABLE
  328.       SET(QSQLFILE,QSQ:QSQLKEY)                  !ok   !    POSITION TO CLOSEST RECORD
  329.       NEXT(QSQLFILE)                             !    READ RECORD
  330.       NEWPTR = POINTER(QSQLFILE)                 !    SET POINTER
  331.     .
  332.     DO FIND_RECORD                               !  POSITION FILE
  333.   ELSE
  334.     NDX = 1                                      !  PUT SELECTOR BAR ON TOP ITEM
  335.     DO FIRST_PAGE                                !  BUILD MEMORY TABLE OF KEYS
  336.   .
  337.   RECORDS# = TRUE                                !  ASSUME THERE ARE RECORDS
  338.   LOOP                                           !LOOP UNTIL USER EXITS
  339.     ACTION = ACTION#                             !RESTORE ACTION
  340.     ALERT                                        !RESET ALERTED KEYS
  341.     ALERT(CTRL_ESC)                              !ALERT SCREEN REJECT KEY
  342.     ALERT(CTRL_ENTER)                            !ALERT SCREEN ACCEPT KEY
  343.     ACCEPT                                       !READ A FIELD
  344.     IF KEYCODE() = CTRL_ESC THEN BREAK. !RETURN ON SCREEN REJECT KEY
  345.     IF  KEYCODE() = CTRL_ENTER    |              !ON SCREEN ACCEPT KEY
  346.     AND FIELD() <> ?POINT                        !BUT NOT ON THE POINT FIELD
  347.       UPDATE                                     !  MOVE ALL FIELDS FROM SCREEN
  348.       SELECT(?)                                  !  START WITH CURRENT FIELD
  349.       SELECT                                     !  EDIT ALL FIELDS
  350.       CYCLE                                      !  GO TO TOP OF LOOP
  351.     .
  352.  
  353.     CASE FIELD()                                 !JUMP TO FIELD EDIT ROUTINE
  354.  
  355.     OF ?FIRST_FIELD                              !FROM THE FIRST FIELD
  356.       IF KEYCODE() = ESC_KEY   |                 !  RETURN ON ESC KEY
  357.       OR RECORDS# = FALSE                        !  OR NO RECORDS
  358.         BREAK                                    !    EXIT PROCEDURE
  359.       .
  360.     OF ?PRE_POINT                                !PRE POINT FIELD CONDITION
  361.       IF KEYCODE() = ESC_KEY                     !  BACKING UP?
  362.         SELECT(?-1)                              !    SELECT PREVIOUS FIELD
  363.       ELSE                                       !  GOING FORWARD
  364.         SELECT(?POINT)                           !    SELECT MENU FIELD
  365.       .
  366.     OF ?POINT                                    !PROCESS THE POINT FIELD
  367.       IF RECORDS(TABLE) = 0                      !IF THERE ARE NO RECORDS
  368.         CLEAR(QSQ:RECORD)                        !  CLEAR RECORD AREA
  369.         ACTION = 1                               !  SET ACTION TO ADD
  370.         GET(QSQLFILE,0)                          !  CLEAR PENDING RECORD
  371.         NEWPTR = POINTER(QSQLFILE)               !    SET POINTER TO NEW RECORD
  372.         DO FIRST_PAGE                            !  DISPLAY THE FIRST PAGE
  373.         IF RECORDS(TABLE) = 0                    !  IF THERE AREN'T ANY RECORDS
  374.           RECORDS# = FALSE                       !    INDICATE NO RECORDS
  375.           SELECT(?PRE_POINT-1)                   !    SELECT THE PRIOR FIELD
  376.         .
  377.         CYCLE                                    !    AND LOOP AGAIN
  378.       .
  379.       CASE KEYCODE()                             !PROCESS THE KEYSTROKE
  380.  
  381.       OF INS_KEY                                 !INS KEY
  382.         CLEAR(QSQ:RECORD)                        !  CLEAR RECORD AREA
  383.         ACTION = 1                               !  SET ACTION TO ADD
  384.         GET(QSQLFILE,0)                          !  CLEAR PENDING RECORD
  385.         IF ~ACTION                               !  IF RECORD WAS ADDED
  386.           NEWPTR = POINTER(QSQLFILE)             !    SET POINTER TO NEW RECORD
  387.           DO FIND_RECORD                         !    POSITION IN FILE
  388.         .
  389.       OF ENTER_KEY                               !ENTER KEY
  390.       OROF CTRL_ENTER                            !CTRL-ENTER KEY
  391.         DO GET_RECORD                            !  GET THE SELECTED RECORD
  392.         IF ACTION = 4 AND KEYCODE() = ENTER_KEY!    IF THIS IS A LOOKUP REQUEST
  393.           ACTION = 0                             !    SET ACTION TO COMPLETE
  394.           BREAK                                  !    AND RETURN TO CALLER
  395.         .
  396.         IF ~ERROR()                              !  IF RECORD IS STILL THERE
  397.           ACTION = 2                             !    SET ACTION TO CHANGE
  398.           IF ACTION THEN CYCLE.                  !    IF SUCCESSFUL RE-DISPLAY
  399.         .
  400.         NEWPTR = POINTER(QSQLFILE)               !    SET POINTER TO NEW RECORD
  401.         DO FIND_RECORD                           !    POSITION IN FILE
  402.       OF DEL_KEY                                 !DEL KEY
  403.         DO GET_RECORD                            !  READ THE SELECTED RECORD
  404.         IF ~ERROR()                              !  IF RECORD IS STILL THERE
  405.           ACTION = 3                             !    SET ACTION TO DELETE
  406.           DO DELETEIT
  407.           IF ~ACTION                             !    IF SUCCESSFUL
  408.             N# = NDX                             !      SAVE POINT INDEX
  409.             DO SAME_PAGE                         !      RE-DISPLAY
  410.             NDX = N#                             !      RESTORE POINT INDEX
  411.         . .
  412.       OF DOWN_KEY                                !DOWN ARROW KEY
  413.         DO SET_NEXT                              !  POINT TO NEXT RECORD
  414.         DO FILL_NEXT                             !  FILL A TABLE ENTRY
  415.         IF FOUND                                 !  FOUND A NEW RECORD
  416.           SCROLL(ROW,COL,ROWS,COLS,ROWS(?POINT)) !    SCROLL THE SCREEN UP
  417.           GET(TABLE,RECORDS(TABLE))              !  GET RECORD FROM TABLE
  418.           DO FILL_SCREEN                         !  DISPLAY ON SCREEN
  419.         .
  420.  
  421.       OF PGDN_KEY                                !PAGE DOWN KEY
  422.         DO SET_NEXT                              !  POINT TO NEXT RECORD
  423.         DO NEXT_PAGE                             !  DISPLAY THE NEXT PAGE
  424.  
  425.       OF CTRL_PGDN                               !CTRL-PAGE DOWN KEY
  426.         DO LAST_PAGE                             !  DISPLAY THE LAST PAGE
  427.         NDX = RECORDS(TABLE)                     !  POSITION POINT BAR
  428.  
  429.       OF UP_KEY                                  !UP ARROW KEY
  430.         DO SET_PREV                              !  POINT TO PREVIOUS RECORD
  431.         DO FILL_PREV                             !  FILL A TABLE ENTRY
  432.         IF FOUND                                 !  FOUND A NEW RECORD
  433.           SCROLL(ROW,COL,ROWS,COLS,-(ROWS(?POINT)))! SCROLL THE SCREEN DOWN
  434.           GET(TABLE,1)                           !  GET RECORD FROM TABLE
  435.           DO FILL_SCREEN                         !  DISPLAY ON SCREEN
  436.         .
  437.  
  438.       OF PGUP_KEY                                !PAGE UP KEY
  439.         DO SET_PREV                              !  POINT TO PREVIOUS RECORD
  440.         DO PREV_PAGE                             !  DISPLAY THE PREVIOUS PAGE
  441.  
  442.       OF CTRL_PGUP                               !CTRL-PAGE UP
  443.         DO FIRST_PAGE                            !  DISPLAY THE FIRST PAGE
  444.         NDX = 1                                  !  POSITION POINT BAR
  445.   . . .
  446.   FREE(TABLE)                                    !FREE MEMORY TABLE
  447.   FREE(QSQ:QSQLKEY)                                 !FREE CACHE
  448.   RETURN                                         !AND RETURN TO CALLER
  449.  
  450. SAME_PAGE ROUTINE                                !DISPLAY THE SAME PAGE
  451.   GET(TABLE,1)                                   !  GET THE FIRST TABLE ENTRY
  452.   DO FILL_RECORD                                 !  FILL IN THE RECORD
  453.   SET(QSQ:QSQLKEY,QSQ:QSQLKEY,TBL:PTR)                 !  POSITION FILE
  454.   FREE(TABLE)                                    !  EMPTY THE TABLE
  455.   DO NEXT_PAGE                                   !  DISPLAY A FULL PAGE
  456.  
  457. FIRST_PAGE ROUTINE                               !DISPLAY FIRST PAGE
  458.   FREE(TABLE)                                    !  EMPTY THE TABLE
  459.   CLEAR(QSQ:RECORD,-1)                           !  CLEAR RECORD TO LOW VALUES
  460.   CLEAR(TBL:PTR)                                 !  ZERO RECORD POINTER
  461.   SET(QSQ:QSQLKEY)                                  !  POINT TO FIRST RECORD
  462.   LOOP NDX = 1 TO COUNT                          !  FILL UP THE TABLE
  463.     DO FILL_NEXT                                 !    FILL A TABLE ENTRY
  464.     IF NOT FOUND THEN BREAK.                     !    GET OUT IF NO RECORD
  465.   .
  466.   NDX = 1                                        !  SET TO TOP OF TABLE
  467.   DO SHOW_PAGE                                   !  DISPLAY THE PAGE
  468.  
  469. LAST_PAGE ROUTINE                                !DISPLAY LAST PAGE
  470.   NDX# = NDX                                     !  SAVE SELECTOR POSITION
  471.   FREE(TABLE)                                    !  EMPTY THE TABLE
  472.   CLEAR(QSQ:RECORD,1)                            !  CLEAR RECORD TO HIGH VALUES
  473.   CLEAR(TBL:PTR,1)                               !  CLEAR PTR TO HIGH VALUE
  474.   SET(QSQ:QSQLKEY)                                  !  POINT TO FIRST RECORD
  475.   LOOP NDX = COUNT TO 1 BY -1                    !  FILL UP THE TABLE
  476.     DO FILL_PREV                                 !    FILL A TABLE ENTRY
  477.     IF NOT FOUND THEN BREAK.                     !    GET OUT IF NO RECORD
  478.   .                                              !  END OF LOOP
  479.   NDX = NDX#                                     !  RESTORE SELECTOR POSITION
  480.   DO SHOW_PAGE                                   !  DISPLAY THE PAGE
  481.  
  482. FIND_RECORD ROUTINE                              !POSITION TO SPECIFIC RECORD
  483.   SET(QSQ:QSQLKEY,QSQ:QSQLKEY,NEWPTR)                  !POSITION FILE
  484.   IF NEWPTR = 0                                  !NEWPTR NOT SET
  485.     NEXT(QSQLFILE)                               !  READ NEXT RECORD
  486.     NEWPTR = POINTER(QSQLFILE)                   !  SET NEWPTR
  487.     SKIP(QSQLFILE,-1)                            !  BACK UP TO DISPLAY RECORD
  488.   .
  489.   FREE(TABLE)                                    !  CLEAR THE RECORD
  490.   DO NEXT_PAGE                                   !  DISPLAY A PAGE
  491.  
  492. NEXT_PAGE ROUTINE                                !DISPLAY NEXT PAGE
  493.   SAVECNT# = RECORDS(TABLE)                      !  SAVE RECORD COUNT
  494.   LOOP COUNT TIMES                               !  FILL UP THE TABLE
  495.     DO FILL_NEXT                                 !    FILL A TABLE ENTRY
  496.     IF NOT FOUND                                 !    IF NONE ARE LEFT
  497.       IF NOT SAVECNT#                            !      IF REBUILDING TABLE
  498.         DO LAST_PAGE                             !      FILL IN RECORDS
  499.         EXIT                                     !      EXIT OUT OF ROUTINE
  500.       .
  501.       BREAK                                      !    EXIT LOOP
  502.   . .
  503.   DO SHOW_PAGE                                   !  DISPLAY THE PAGE
  504.  
  505. SET_NEXT ROUTINE                                 !POINT TO THE NEXT PAGE
  506.   GET(TABLE,RECORDS(TABLE))                      !  GET THE LAST TABLE ENTRY
  507.   DO FILL_RECORD                                 !  FILL IN THE RECORD
  508.   SET(QSQ:QSQLKEY,QSQ:QSQLKEY,TBL:PTR)                 !  POSITION FILE
  509.   NEXT(QSQLFILE)                                 !  READ THE CURRENT RECORD
  510.  
  511. FILL_NEXT ROUTINE                                !FILL NEXT TABLE ENTRY
  512.   FOUND = FALSE                                  !  ASSUME RECORD NOT FOUND
  513.   LOOP UNTIL EOF(QSQLFILE)                       !  LOOP UNTIL END OF FILE
  514.     NEXT(QSQLFILE)                               !    READ THE NEXT RECORD
  515.     FOUND = TRUE                                 !    SET RECORD FOUND
  516.     DO FILL_TABLE                                !    FILL IN THE TABLE ENTRY
  517.     ADD(TABLE)                                   !    ADD LAST TABLE ENTRY
  518.     GET(TABLE,RECORDS(TABLE)-COUNT)              !    GET ANY OVERFLOW RECORD
  519.     DELETE(TABLE)                                !    AND DELETE IT
  520.     EXIT                                         !    RETURN TO CALLER
  521.   .
  522. PREV_PAGE ROUTINE                                !DISPLAY PREVIOUS PAGE
  523.   LOOP COUNT TIMES                               !  FILL UP THE TABLE
  524.     DO FILL_PREV                                 !    FILL A TABLE ENTRY
  525.     IF NOT FOUND THEN BREAK.                     !    GET OUT IF NO RECORD
  526.   .
  527.   DO SHOW_PAGE                                   !  DISPLAY THE PAGE
  528.  
  529. SET_PREV ROUTINE                                 !POINT TO PREVIOUS PAGE
  530.   GET(TABLE,1)                                   !  GET THE FIRST TABLE ENTRY
  531.   DO FILL_RECORD                                 !  FILL IN THE RECORD
  532.   SET(QSQ:QSQLKEY,QSQ:QSQLKEY,TBL:PTR)                 !  POSITION FILE
  533.   PREVIOUS(QSQLFILE)                             !  READ THE CURRENT RECORD
  534.  
  535. FILL_PREV ROUTINE                                !FILL PREVIOUS TABLE ENTRY
  536.   FOUND = FALSE                                  !  ASSUME RECORD NOT FOUND
  537.   LOOP UNTIL BOF(QSQLFILE)                       !  LOOP UNTIL BEGINNING OF FILE
  538.     PREVIOUS(QSQLFILE)                           !    READ THE PREVIOUS RECORD
  539.     FOUND = TRUE                                 !    SET RECORD FOUND
  540.     DO FILL_TABLE                                !    FILL IN THE TABLE ENTRY
  541.     ADD(TABLE,1)                                 !    ADD FIRST TABLE ENTRY
  542.     GET(TABLE,COUNT+1)                           !    GET ANY OVERFLOW RECORD
  543.     DELETE(TABLE)                                !    AND DELETE IT
  544.     EXIT                                         !    RETURN TO CALLER
  545.   .
  546. SHOW_PAGE ROUTINE                                !DISPLAY THE PAGE
  547.   NDX# = NDX                                     !  SAVE SCREEN INDEX
  548.   LOOP NDX = 1 TO RECORDS(TABLE)                 !  LOOP THRU THE TABLE
  549.     GET(TABLE,NDX)                               !    GET A TABLE ENTRY
  550.     DO FILL_SCREEN                               !    AND DISPLAY IT
  551.     IF TBL:PTR = NEWPTR                          !    SET INDEX FOR NEW RECORD
  552.       NDX# = NDX                                 !    POINT TO CORRECT RECORD
  553.   . .
  554.   LOOP WHILE NDX <= COUNT                        !  FINISH BLANKING THE SCREEN
  555.     BLANK(ROW(?POINT),COL(?POINT),ROWS(?POINT),COLS(?POINT))!BLANK A LINE
  556.     NDX += 1                                     !   INCREMENT NDX
  557.   .
  558.   NDX = NDX#                                     !  RESTORE SCREEN INDEX
  559.   NEWPTR = 0                                     !  CLEAR NEW RECORD POINTER
  560.   CLEAR(QSQ:RECORD)                              !  CLEAR RECORD AREA
  561.  
  562. FILL_TABLE ROUTINE                               !MOVE FILE TO TABLE
  563.   TBL:DESCRIPTION = QSQ:DESCRIPTION
  564.   TBL:PTR = POINTER(QSQLFILE)                    !  SAVE RECORD POINTER
  565.  
  566. FILL_RECORD ROUTINE                              !MOVE TABLE TO FILE
  567.   QSQ:DESCRIPTION = TBL:DESCRIPTION
  568.  
  569. FILL_SCREEN ROUTINE                              !MOVE TABLE TO SCREEN
  570.   SCR:DESCRIPTION = TBL:DESCRIPTION
  571.  
  572. GET_RECORD ROUTINE                               !GET SELECTED RECORD
  573.   GET(TABLE,NDX)                                 !  GET TABLE ENTRY
  574.   GET(QSQLFILE,TBL:PTR)                          !  GET THE RECORD
  575.  
  576. DELETEIT   ROUTINE
  577.         OPEN(DELSCR)
  578.         DESCOUT=QSQ:DESCRIPTION
  579.         DISPLAY
  580.         LOOP
  581.            ASK
  582.            IF KEYCODE() = ENTER_KEY THEN
  583.                                     DELETE(QSQLFILE)
  584.                                     ACTION=0
  585.                                     BREAK
  586.                                     .
  587.            IF KEYCODE() = ESC_KEY THEN BREAK.
  588.            IF KEYCODE() = CTRL_ESC THEN BREAK.
  589.            BEEP
  590.            .
  591.        CLOSE(DELSCR)
  592.        EXIT
  593.