home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol285 / brow.prg < prev    next >
Encoding:
Text File  |  1986-12-22  |  16.8 KB  |  608 lines

  1. **    Last revision: July 4, 1986 at 10:42
  2.  
  3. * Name:    BROWSE.prg    a dBASEIII Browse emulation for Clipper
  4. * Use :    RUN BROWSE <filename>
  5. *          DO Browse WITH <filename>
  6.  
  7. * 07/04/86 by: H.M. Van Tassell
  8. * This browse was inspired by a browse procedure written by S.J. Straley.
  9. * It ia a completely rewritten version of the his original procedure.
  10.  
  11. * This program is freely placed in the Public Domain with no
  12. * rights reserved. It is a non-copyrighted work!
  13.  
  14. * NOTE: uses CALLs to Curson & CursOff which are contained in the
  15. * author's CLIP-BRO.ARC CURSOR.OBJ ready for linking to this program.
  16.  
  17. ********[ If using browse as a procedure in another pgm ]***********
  18. **                                                                **
  19. ** If database file is already open, comment out "DO B_OpnFil"    **
  20. **   which is about 37 lines forward.                             **
  21. **                                                                **
  22. ** Suggest that SET ScoreBoard=Off, Confirm=On, Deleted = Off     **
  23. **   this should be done prior to calling Browse                  **
  24. **                                                                **
  25. ********************************************************************
  26.  
  27.   SET SCOREBOARD OFF 
  28. *  SET CONFIRM ON     
  29.   SET DELIMITER OFF
  30.   SET INTENSITY ON 
  31. **  PROCEDURE Browse                                               
  32. PARAMETER file
  33. PRIVATE temp, last_fld, curr_rec, curr_top, col_pos, row_pos, cur_field   
  34. PRIVATE last_posit, frst_posit, cur_posit, in_val, in_command, last_row
  35. PRIVATE curr_bot, Field_Length
  36. *                                                                             *
  37. *    last_fld    :   provides the number of fields available in given file.   *
  38. *    curr_rec    :   curr_rec record number of database highlited                       *
  39. *    curr_top    :   record number currently first on screen
  40. *    curr_bot    :   record number currently last on screen
  41. *    col_pos     :   column position of cursor on screen                      *
  42. *    row_pos     :   row position of cursor on screen                          *
  43. *    last_row    :   row count of current last row
  44. *    cur_field   :   the field number currently BROWSE is resting on in       *
  45. *                    CURRENT record of used FILE.                             *
  46. *    last_posit  :   the field number allowed to be shown in the last         *
  47. *                    column position                                          *
  48. *    frst_posit  :   the field number allowed to be shown in the first        *
  49. *                    column position                                          *
  50. *    in_val      :   the name of the field at any given cur_field              *
  51. *    in_command  :   the variable to store the INKEY()                        *
  52. *    Field_Length[]  an array of field lengths
  53. *
  54. file = UPPER(TRIM(file))
  55. IF AT(".",file) = 0
  56.    file = file + ".DBF"
  57. ENDIF
  58. **  If database file is already open, comment out "DO B_OpnFil"
  59. **  DO B_OpnFil
  60. **
  61. CALL CursOff
  62. DO B_DrMenu
  63. @ 0,62 SAY TRIM(file)
  64.  
  65. curr_rec   = RECNO()
  66. curr_top   = curr_rec 
  67.  
  68. * for speed, setup an array of field lengths
  69. last_fld = B_FLDCNT()
  70. DECLARE Field_Length[last_fld]
  71. FOR cur_posit = 1 TO last_fld
  72.   Field_Length[cur_posit] = B_FLDLEN(cur_posit)
  73. NEXT
  74. col_pos    = 1
  75. cur_field  = 1
  76. row_pos    = 9
  77. frst_posit = 1
  78. last_posit = 0
  79.  
  80. last_posit = B_R_PAN()
  81. DO B_RecNum
  82. DO B_DrHead
  83. GoTo curr_rec
  84. DO B_ReDraw
  85. GoTo curr_rec
  86. DO B_ShoRev
  87.  
  88. DO WHILE .T.
  89.    DO B_ClrKey
  90.    in_command = UPPER(CHR(INKEY(0)))
  91.    DO B_ClrKey
  92.  
  93.    DO CASE
  94.    CASE in_command = CHR(27)  && ESC quit/exit
  95.       CLEAR
  96.       CALL CursOn
  97.       SET DELIMITER ON
  98.       SET INTENSITY OFF 
  99.       RETURN
  100.  
  101.    CASE in_command = "G"   && GoTo record
  102.      temp = curr_rec
  103.      @ 23,18 SAY "GoTo which record ?"
  104.      @ 24,27 SAY "Range 1 to "
  105.      @ 24,38 SAY RECCOUNT() PICTURE "@B"
  106.      CALL CursOn
  107.      @ 23,38 GET temp PICTURE "9999999" 
  108.      READ
  109.      DO WHILE temp <1 .OR. temp > RECCOUNT()
  110.        @ 23,38 GET temp PICTURE "9999999"
  111.        READ
  112.      ENDDO
  113.      CLEAR GETS
  114.      CALL CursOff
  115.      @ 23,0
  116.      @ 24,0
  117.      IF temp <> curr_rec
  118.        curr_rec = temp
  119.        curr_top = curr_rec
  120.        GoTo curr_rec
  121.        DO B_RecNum
  122.        DO B_ReDraw
  123.        row_pos = 9
  124.        GoTo curr_rec
  125.        DO B_ShoRev
  126.      ENDIF
  127.  
  128.    CASE in_command = CHR(25)   && ^Y  delete field
  129.       in_val = FIELDNAME(cur_field)
  130.       DO CASE
  131.       CASE TYPE(in_val) = "C"
  132.          REPLACE &in_val WITH SPACE(Field_Length[cur_field])
  133.       CASE TYPE(in_val) = "N"
  134.          REPLACE &in_val WITH 0.00
  135.       CASE TYPE(in_val) = "D"
  136.          REPLACE &in_val WITH CTOD("  /  /  ")
  137.       CASE TYPE(in_val) = "L"
  138.          REPLACE &in_val WITH .F.
  139.       ENDCASE
  140.       DO B_ShoRev
  141.  
  142.    CASE in_command = "E"
  143.       IF TYPE(in_val) <> "M"
  144.         @ row_pos, col_pos GET &in_val
  145.         CALL CursOn
  146.         READ
  147.         CALL CursOff
  148.         tempin = FIELDNAME(cur_field)
  149.         REPLACE &tempin WITH &in_val
  150.         CLEAR GETS
  151.       ENDIF
  152.  
  153.    CASE in_command = CHR(21)  && ^U  delete record
  154.       IF DELETED()
  155.          RECALL
  156.          @ row_pos,0 SAY " "
  157.          @ 00,50 SAY "     "
  158.       ELSE
  159.          DELETE
  160.          @ row_pos,0 SAY "*"
  161.          @ 00,50 SAY "*DEL*"
  162.       ENDIF
  163.  
  164.    CASE in_command = CHR(4)  && RtArrow
  165.       IF cur_field < last_fld
  166.          IF cur_field < last_posit
  167.             DO B_SayRt
  168.             cur_field = cur_field + 1
  169.             DO B_ShoRev
  170.          ELSE
  171.             * pan right
  172.             IF Field_Length[last_posit]+Field_Length[last_posit+1] > 80
  173.               frst_posit = last_posit + 1
  174.             ELSE
  175.               frst_posit = last_posit
  176.             ENDIF
  177.             cur_field = frst_posit
  178.             last_posit = B_R_PAN()
  179.             DO B_DrHead
  180.             GoTo curr_top
  181.             DO B_ReDraw
  182.             GoTo curr_rec
  183.             col_pos = 1
  184.             DO B_ShoRev
  185.          ENDIF
  186.       ENDIF
  187.  
  188.    CASE in_command = CHR(19) && LtArrow
  189.       IF cur_field  > 1
  190.          IF cur_field > frst_posit
  191.             cur_field = cur_field - 1
  192.             DO B_SayLt
  193.             DO B_ShoRev
  194.           ELSE 
  195.             ** cur_field is equal to frst_posit so pan left
  196.             IF Field_Length[frst_posit]+Field_Length[frst_posit-1] > 80
  197.               last_posit = frst_posit - 1
  198.             ELSE
  199.               last_posit = frst_posit
  200.             ENDIF
  201.             cur_field = last_posit   
  202.             frst_posit = B_L_PAN()  
  203.             cur_field = frst_posit
  204.             IF cur_field = 1
  205.               * make sure max fields displayed on screen
  206.               last_posit = B_R_PAN()
  207.             ENDIF
  208.             DO B_DrHead
  209.             GoTo curr_top
  210.             DO B_ReDraw
  211.             GoTo curr_rec
  212.             col_pos = 1
  213.             DO B_ShoRev
  214.          ENDIF
  215.       ENDIF
  216.  
  217.    CASE in_command = CHR(2)  && ^RtArrow pan right
  218.       IF last_posit < last_fld
  219.          IF Field_Length[last_posit]+Field_Length[last_posit+1] > 80
  220.            frst_posit = last_posit + 1
  221.          ELSE
  222.            frst_posit = last_posit
  223.          ENDIF
  224.         cur_field = frst_posit
  225.         last_posit = B_R_PAN()
  226.         DO B_DrHead
  227.         GoTo curr_top
  228.         DO B_ReDraw
  229.         GoTo curr_rec
  230.         col_pos = 1
  231.         DO B_ShoRev
  232.       ENDIF
  233.  
  234.    CASE in_command = CHR(26) && ^LtArrow  pan left
  235.       IF frst_posit  > 1
  236.         IF Field_Length[frst_posit]+Field_Length[frst_posit-1] > 80
  237.           last_posit = frst_posit - 1
  238.         ELSE
  239.           last_posit = frst_posit
  240.         ENDIF
  241.         cur_field = last_posit   
  242.         frst_posit = B_L_PAN()  
  243.         cur_field = frst_posit
  244.          IF cur_field = 1
  245.            * make sure max fields displayed on screen
  246.            last_posit = B_R_PAN()
  247.         ENDIF
  248.         DO B_DrHead
  249.         GoTo curr_top
  250.         DO B_ReDraw
  251.         GoTo curr_rec
  252.         col_pos = 1
  253.         DO B_ShoRev
  254.       ENDIF
  255.  
  256.    CASE in_command = CHR(18) && PgUp   
  257.       GoTo curr_top
  258.       SKIP - 12
  259.       curr_rec = RECNO()
  260.       curr_top=curr_rec
  261.       DO B_RecNum
  262.       DO B_ReDraw
  263.       row_pos = 9
  264.       GoTo curr_rec
  265.       DO B_ShoRev
  266.  
  267.    CASE in_command = CHR(3)  && PgDn   
  268.       GoTo curr_bot
  269.       SKIP + 1
  270.       IF EOF()
  271.         SKIP - 1
  272.       ENDIF
  273.       curr_rec = RECNO()
  274.       curr_top = curr_rec
  275.       DO B_RecNum
  276.       DO B_ReDraw
  277.       row_pos = 9
  278.       GoTo curr_rec
  279.       DO B_ShoRev
  280.  
  281.  
  282.    CASE in_command =  CHR(31)  && ^PgUp go to top of file
  283.       GoTo TOP
  284.       curr_rec = RECNO()
  285.       curr_top=curr_rec
  286.       DO B_RecNum
  287.       DO B_ReDraw
  288.       row_pos = 9
  289.       GoTo curr_rec
  290.       DO B_ShoRev
  291.  
  292.    CASE in_command = CHR(30)  && ^PgDn go to bottom of file
  293.       GoTo BOTTOM
  294.       curr_rec = RECNO()
  295.       curr_top = curr_rec
  296.       DO B_RecNum
  297.       DO B_ReDraw
  298.       row_pos = 9
  299.       GoTo curr_rec
  300.       DO B_ShoRev
  301.  
  302.    CASE in_command = CHR(24) && DnArrow
  303.       SKIP
  304.       IF EOF()
  305.          SKIP - 1
  306.       ELSE
  307.          SKIP - 1
  308.          row_pos = row_pos + 1
  309.          DO B_DnRec
  310.          SKIP + 1
  311.          curr_rec = RECNO()
  312.          DO B_RecNum
  313.          DO B_ShoRev
  314.       ENDIF
  315.  
  316.    CASE in_command = CHR(5)  && UpArrow
  317.       SKIP - 1
  318.       IF BOF()
  319.          GoTo curr_rec
  320.       ELSE
  321.          SKIP + 1
  322.          row_pos = row_pos - 1
  323.          DO B_UpRec
  324.          SKIP - 1
  325.          curr_rec = RECNO()
  326.          DO B_RecNum
  327.          DO B_ShoRev
  328.       ENDIF
  329.  
  330.    CASE in_command = CHR(1) && HOME move to first  screen row
  331.       IF TYPE(in_val) = "M"
  332.          @ row_pos,col_pos SAY "memo"
  333.       ELSE
  334.          @ row_pos,col_pos SAY &in_val
  335.       ENDIF
  336.       row_pos = 9
  337.       GoTo curr_top 
  338.       curr_rec = RECNO()
  339.       DO B_RecNum
  340.       DO B_ShoRev
  341.  
  342.    CASE in_command = CHR(6) && END  move to bottom screen row
  343.       IF TYPE(in_val) = "M"
  344.          @ row_pos,col_pos SAY "memo"
  345.       ELSE
  346.          @ row_pos,col_pos SAY &in_val
  347.       ENDIF
  348.       GoTo curr_bot
  349.       curr_rec = RECNO()
  350.       row_pos = last_row
  351.       DO B_RecNum
  352.       DO B_ShoRev
  353.  
  354.    OTHERWISE
  355.    ENDCASE
  356.  
  357. **  Debuging stuff
  358. **     @ 23,1  SAY "Frst_posit =" + STR( frst_posit,3)
  359. **     @ 23,20 SAY "Last_posit =" + STR( last_posit,3)
  360. **     @ 23,40 SAY "cur_field =" + STR( cur_field,3) 
  361. **     @ 23,60  SAY "last_fld = " + STR( last_fld,3) 
  362. **
  363. **     @ 24,1  SAY "Row_pos =" + STR( row_pos,3) 
  364. **     @ 24,20  SAY "curr_top =" + STR( curr_top,3) 
  365. **     @ 24,40 SAY "Col_pos =" + STR( col_pos,3) 
  366. **     @ 24,60 SAY "in_val = " + in_val + SPACE(10-LEN(in_val))
  367.  
  368. ENDDO
  369.  
  370. ********* begin procedures and functions ******************
  371.  
  372. PROCEDURE B_OpnFil
  373.  
  374.   IF file = "."
  375.      file = SPACE(14)
  376.      @ ROW(),0 SAY "No database is in USE.  Enter file name: " GET file PICTURE "!!!!!!!!!!!!!!"
  377.      READ
  378.      file = TRIM(file)
  379.      IF AT(".",file) = 0
  380.         file = file + ".DBF"
  381.      ENDIF
  382.   ENDIF
  383.   IF .NOT. FILE("&file")
  384.      ? file + " not found"
  385.      WAIT
  386.      QUIT
  387.   ENDIF
  388.   USE &file
  389.   RETURN
  390.  
  391. PROCEDURE B_ClrKey
  392.    * clear out the key board buffer
  393.    PRIVATE temp
  394.    temp = 1
  395.    DO WHILE temp <> 0
  396.      temp = INKEY()
  397.    ENDDO
  398.    RETURN
  399.  
  400. PROCEDURE B_DrMenu
  401. CLEAR
  402. @ 0,1 SAY "Record No.                   BROWSE                                             "
  403. @ 1,0 SAY "╔══════════════════╦════════════════════╦══════════════════╦═══════════════════╗"
  404. @ 2,0 SAY "║ CURSOR   Lt  Rt  ║        UP   DOWN   ║      DELETE      ║      ACTION       ║"
  405. @ 3,0 SAY "║  Char:   -  -  ║ Rec:             ║ Char:     DEL    ║ GoTo Rec #:   G   ║"
  406. @ 4,0 SAY "║  Field:  -  -  ║ Page:  PgUp  PgDn  ║ Field:     ^Y    ║ Edit Field:   E   ║"
  407. @ 5,0 SAY "║  Pan:   ^- ^-  ║ File: ^PgUp ^PgDn  ║ Record:    ^U    ║ Quit/Exit:   ESC  ║"
  408. @ 6,0 SAY "╚══════════════════╩════════════════════╩══════════════════╩═══════════════════╝"
  409. RETURN              
  410.  
  411. PROCEDURE B_DrHead
  412.    * Draws the table header of fieldnames
  413.    PRIVATE temp, cur_posit, fldlen, namelen
  414.    temp = 1
  415.    @ 7,0 CLEAR
  416.    FOR cur_posit = frst_posit TO last_posit
  417.       in_val = FIELDNAME(cur_posit)
  418.       fldlen = Field_Length[cur_posit]
  419.       namelen = LEN(in_val)
  420.       @ 7,temp SAY TRIM(in_val) + REPLICATE("-",fldlen-namelen)
  421.       @ 8,temp SAY REPLICATE("═",fldlen)
  422.       temp = temp + fldlen +1
  423.    NEXT
  424.    RETURN
  425.  
  426. PROCEDURE B_ReDraw
  427.    * Draws the table of fields down and across the screen
  428.    PRIVATE down, across, cur_posit
  429.    @ 9,0 CLEAR
  430.    FOR down = 9 TO 20
  431.       last_row = down
  432.       curr_bot = RECNO()
  433.       IF DELETED()
  434.          @ down,0 SAY "*"
  435.       ENDIF
  436.       across = 1
  437.       FOR cur_posit = frst_posit TO last_posit
  438.          in_val = FIELDNAME(cur_posit)
  439.          IF TYPE(in_val) = "M"
  440.             @ down,across SAY "memo"
  441.          ELSE
  442.             @ down,across SAY &in_val
  443.          ENDIF
  444.          across = across + Field_Length[cur_posit] + 1 
  445.       NEXT
  446.       SKIP + 1
  447.       IF EOF()
  448.          down = 21
  449.          SKIP - 1
  450.       ENDIF
  451.    NEXT
  452.    RETURN
  453.  
  454. PROCEDURE B_UpRec
  455.    * B_UpRec goes up a record *
  456.    IF row_pos < 9
  457.       SKIP - 1
  458.       curr_top = RECNO()
  459.       DO B_ReDraw
  460.       GoTo curr_rec
  461.       row_pos = 9
  462.    ELSE
  463.       IF TYPE(in_val) = "M"
  464.          @ row_pos+1,col_pos SAY "memo"
  465.       ELSE
  466.          @ row_pos+1,col_pos SAY &in_val
  467.       ENDIF
  468.    ENDIF
  469.    RETURN
  470.  
  471. PROCEDURE B_DnRec
  472.    * B_DnRec getting things ready to go down *
  473.    IF row_pos > 20
  474.       SKIP
  475.       curr_top = RECNO()
  476.       DO B_ReDraw
  477.       GoTo curr_rec
  478.       row_pos = 9
  479.    ELSE
  480.       IF TYPE(in_val) = "M"
  481.          @ row_pos-1,col_pos SAY "memo"
  482.       ELSE
  483.          @ row_pos-1,col_pos SAY &in_val
  484.       ENDIF
  485.    ENDIF
  486.    RETURN
  487.  
  488. PROCEDURE B_RecNum
  489.    * B_RecNum displays the current reccord number to the screen *
  490.    @ 0,12 SAY SPACE(8)
  491.    @ 0,12 SAY curr_rec PICT "@B"
  492.    IF DELETED()
  493.      @ 00,50 SAY "*DEL*"
  494.    ELSE
  495.      @ 00,50 SAY "     "
  496.    ENDIF
  497.    RETURN
  498.  
  499. PROCEDURE B_ShoRev
  500.    PRIVATE tempit
  501.    * B_ShoRev will Reverse video the field...of current position    *
  502.    * displays accordingly to the screen at row_pos and col_pos  *
  503.    in_val = FIELDNAME(cur_field)
  504.    IF TYPE(in_val) = "M"
  505.       tempit = "memo"
  506.       @ row_pos,col_pos GET tempit
  507.    ELSE
  508.       @ row_pos,col_pos GET &in_val
  509.    ENDIF
  510.    CLEAR GETS
  511.    RETURN
  512.  
  513. PROCEDURE B_SayLt
  514.    * B_SayLT will SAY field and increment col_pos to the left *
  515.    IF TYPE(in_val) = "M"
  516.       @ row_pos,col_pos SAY "memo"
  517.    ELSE
  518.       @ row_pos,col_pos SAY &in_val
  519.    ENDIF
  520.    col_pos = col_pos - Field_Length[cur_field] - 1
  521.    RETURN
  522.  
  523. PROCEDURE B_SayRt
  524.    * B_SayRT will SAY a field and increment col_pos to the right *
  525.    IF TYPE(in_val) = "M"
  526.       @ row_pos,col_pos SAY "memo"
  527.    ELSE
  528.       @ row_pos,col_pos SAY &in_val
  529.    ENDIF
  530.    col_pos = col_pos + Field_Length[cur_field] + 1
  531.    RETURN
  532.  
  533. FUNCTION B_R_PAN
  534.    * Returns the number of the field from current first field position
  535.    * that will fit onto the screen going up in count
  536.    PRIVATE length, cnt_pos, rover
  537.    length = 0
  538.    FOR cnt_pos = cur_field TO last_fld 
  539.       rover = cnt_pos
  540.       length = length + Field_Length[cnt_pos] + 1
  541.       IF length > 80
  542.          IF rover = cur_field
  543.             RETURN(rover)
  544.          ELSE
  545.             RETURN(rover - 1)
  546.          ENDIF
  547.       ENDIF
  548.    NEXT
  549.    * The remaining fields all fit on the screen
  550.    RETURN(rover)
  551.  
  552. FUNCTION B_L_PAN
  553.    * Returns the number of the field from current last field position
  554.    * that will fit onto the screen going down in count
  555.    PRIVATE length, cnt_pos, lover
  556.    length = 0
  557.    FOR cnt_pos = cur_field TO 1 STEP -1
  558.       lover = cnt_pos
  559.       length = length + Field_Length[cnt_pos] + 1
  560.       IF length > 80
  561.          IF lover = cur_field
  562.             RETURN(lover)
  563.          ELSE
  564.             RETURN(lover + 1)
  565.          ENDIF
  566.       ENDIF
  567.    NEXT
  568.    * The remaining fields all fit on the screen
  569.    RETURN(lover)
  570.  
  571.  
  572. FUNCTION B_FLDCNT
  573.    * This function determines the number of the last field in database
  574.    PRIVATE count
  575.    count = 1
  576.    DO WHILE (count < 1025) .AND. (LEN(FIELDNAME(count+1)) > 0)
  577.       count = count + 1
  578.    ENDDO
  579.    RETURN(count)
  580.  
  581. FUNCTION B_FLDLEN
  582.    * B_FLDLEN function                     *
  583.    * Returns LEN() for character strings *
  584.    * Returns LEN(STR()) for numeric         *
  585.    * Returns 1 for logical                 *
  586.    * Returns 8 for date                     *
  587.    * Returns 4 for memo                     *
  588.    * OR Returns length of field name *
  589.    ***************************************
  590.    PARAMETER field_num
  591.    PRIVATE lenght
  592.    field_name = FIELDNAME(field_num)
  593.    DO CASE
  594.      CASE TYPE(field_name) = "C"
  595.        length = LEN(&field_name)
  596.      CASE TYPE(field_name) = "N"
  597.         length = LEN(STR(&field_name))
  598.      OTHERWISE
  599.         length = AT(TYPE(field_name), "L  M   D")
  600.    ENDCASE
  601.    IF LEN(field_name) > length
  602.      RETURN(LEN(field_name))
  603.    ELSE
  604.      RETURN(length)
  605.    ENDIF
  606.  
  607.  **[eof]
  608.