home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR4 / VIEWSRCH.ZIP / VSEARCH.TPX < prev   
Text File  |  1993-10-27  |  19KB  |  411 lines

  1. #!-------------------------------------------------------------------------------#!
  2. #!      VSEARCH.TPX
  3. #!
  4. #!      ViewAndSearch View a selected text file in a listbox w/search
  5. #!
  6. #!------------------------------------------------------------------------------
  7. #PROCEDURE(ViewAndSearch,'View a selected text file in a listbox'),SCREEN,REPORT,PULLDOWN
  8. #!------------------------------------------------------------------------------
  9. #!
  10. #!                           The View And Search Template
  11. #!
  12. #!------------------------------------------------------------------------------
  13. #PROTOTYPE('')
  14. #MAP('GETLIST.INC')
  15. #PROJECT('%clapfx%ASCII.LIB')
  16. #INSERT(%StandardHeader)
  17. #DISPLAY(' ')
  18. #PROMPT('File to &View',@s30),%ListFile
  19. #PROMPT('Warning Size (in K)',@s6),%FileWarningSize
  20. #PROMPT('Ma&ximum Line Length',@s6),%FileLineLength
  21. #PROMPT('Progress &Indicator',CHECK), %ShowProg
  22. #PROMPT('Progress Character',@S8),%ProgChar
  23. #PROMPT('Always Show Pulldown',CHECK),%AlwaysPulldown
  24. #!
  25. #IF(%ListFile = %Null)
  26.   #SET(%ListFile, 'GLO:FileSpec')
  27. #ENDIF
  28.  
  29. %Procedure       PROCEDURE
  30.  
  31. %LocalData
  32. SaveRows         BYTE                            !Initial screen rows
  33. SaveCols         BYTE                            !Initial screen columns
  34. FirstPage        BYTE                            !First page display flag
  35.  
  36. FieldNo          USHORT                          !Equate of List Box
  37. Bar              USHORT                          !Position in Queue
  38. Elem             USHORT                          !Element of List Box
  39.  
  40. CaseSensitive    BYTE(0)                         !Type of Search
  41. SearchFor        CSTRING(21)                     !What to Search for
  42. SaveStyle        STRING(256)                     !Save Colour Scheme
  43.  
  44.  
  45.                  ! File to View, With 3K of buffering
  46. RptFile          FILE,DRIVER('ASCII','/FILEBUFFERS=6'),NAME(%ListFile),PRE(Dos) #<! Declare Input File
  47.                    RECORD
  48.   #IF(%FileLineLength)
  49. Fline                STRING(%FileLineLength)
  50.   #ELSE
  51. Fline                STRING(255)
  52.   #ENDIF
  53.                  . .
  54.  
  55. SaveScreen       SCREEN(25,80).
  56. %ReportStructure
  57.  
  58. SCREEN           %ScreenAttributes
  59. %ScreenPaintDeclarations
  60. %ScreenStringDeclarations
  61.                   Entry,Use(?FIRST_FIELD)
  62. %ScreenFieldDeclarations
  63.           .
  64.  
  65. SearchInput      SCREEN(13,45),CENTER,SHADOW,FALL,CUA,COLOR(112)
  66.                    !dimensions=25,80,25,80
  67.                    ROW(1,1)    STRING('█{45}'),COLOR(121)
  68.                    ROW(4,6)    STRING('What phrase should be searched for?')
  69.                    ROW(13,1)   STRING('█▄{43}█'),COLOR(121)
  70.                                REPEAT(11)
  71.                    ROW(2,1)      STRING('█'),COLOR(121)
  72.                    ROW(2,45)     STRING('█'),COLOR(121)
  73.                                .
  74.                    ROW(4,45)   ENTRY(),USE(?FirstField),COLOR(126,7,120)
  75.                    ROW(6,13)   ENTRY(@S20),USE(SearchFor),COLOR(113,7,120)
  76.                    ROW(8,14)   CHECK('Case Sensitive'),USE(CaseSensitive),COLOR(112,7,120,127,15)
  77.                    ROW(11,11)  BUTTON('  &Ok  '),SHADOW,KEY(EnterKey),USE(?Ok2),COLOR(23,71,24,31,79)
  78.                      COL(28)   BUTTON(' E&xit '),SHADOW,KEY(EscKey),USE(?Exit2),COLOR(23,71,24,31,79)
  79.                  .
  80.  
  81.  
  82. #IF(%ShowProg)
  83. VEW::Length      BYTE                            !Progress variable
  84. VEW::ProgString  STRING('»{50}')                 !Progress display variable
  85. #ENDIF
  86. #EMBED('Data Section')
  87.  
  88.   CODE
  89.   #EMBED('Setup Procedure')
  90.   #IF(%ProgChar)                                #!If showing the progress
  91.   VEW::ProgString = ALL(%ProgChar)             #<!Fill the progress string
  92.   #ENDIF
  93.   IF NOT %ListFile THEN RETURN.                #<!If %ListFile is blank
  94.   FieldNo=?List
  95.  
  96.   OPEN(RptFile)                                  !Open the Dos File
  97.   IF DiskError('Cannot Locate Selected File') THEN RETURN.
  98.   OldState#=SEND (RptFile, 'QUICKSCAN=ON')       ! Faster Access
  99.   #IF(%FileWarningSize)
  100.   IF Bytes(RptFile) > (%FileWarningSize * 1024)#<!If oversized file
  101.     GLO:Message1 = 'This is a large file and may take a while'
  102.     GLO:Message2 = 'to load.  You may press the Esc key'
  103.     GLO:Message3 = 'while the file is loading to exit.'
  104.     ShowWarning                                  ! Show a warning screen
  105.   END                                            !End IF
  106.   #ENDIF
  107.   IF GRAPHIC(1) = 5Ah                            !If in text mode
  108.     OPEN(SaveScreen)                             ! Open a save screen
  109.   END                                            !End IF
  110.   OPEN(Screen)                                   !Open the Screen
  111.  
  112.   #SET(%PrintFieldExists,'')
  113.   #FOR(%ScreenField)
  114.     #IF(%ScreenField = '?PrintDevice')
  115.   DISABLE(?PrintDevice)                          !Disable the device field
  116.     #ENDIF
  117.     #IF(%ScreenField = '?Print')
  118.       #SET(%PrintFieldExists,'True')
  119.     #ENDIF
  120.     #IF(%ScreenField = '?ChangeMode')
  121.   IF GRAPHIC(1) <> 5Ah                           !If not in text mode
  122.     DISABLE(?ChangeMode)                         ! Disable changemode button
  123.   END                                            !End IF
  124.     #ENDIF
  125.   #ENDFOR
  126.   #IF(%Pulldown)                                #!If a Pulldown exists
  127.   #IF(%AlwaysPulldown)                          #!If a Pulldown exists
  128.   OPEN(%Pulldown,1)                            #<!Open the Pulldown Always
  129.   #ELSE
  130.   OPEN(%Pulldown)                              #<!Open the Pulldown
  131.   #ENDIF
  132.   #ENDIF
  133.   SaveRows = Rows(SCREEN)                        !Save the Screen Rows
  134.   SaveCols = Cols(SCREEN)                        !Save the Screen Columns
  135.   #EMBED('Setup Screen')
  136.   FirstPage = 1                                  !Set flag for Page 1
  137.   SET(RptFile)                                   !Set to the file
  138.   LOOP                                           !Loop through the dos file
  139.     #INSERT(%GenerateFormulas)
  140.     #EMBED('Top of Accept Loop')
  141.     NEXT(RptFile)                                ! Get the next record
  142.     IF ERRORCODE() THEN BREAK.                   ! Break if error occurs
  143.   #IF(%FileLineLength)
  144.     IF Bytes(RptFile) > %FileLineLength          ! Line is longer than allowed
  145.       GLO:Message1 = 'The line length is greater than %FileLineLength.'
  146.   #ELSE
  147.     IF Bytes(RptFile) > 255                      ! Line is longer than allowed
  148.       GLO:Message1 = 'The line length is greater than 255.'
  149.   #ENDIF
  150.       GLO:Message2 = 'The selected file is not an ASCII file.'
  151.       GLO:Message3 = 'No view on this file is available.'
  152.       ShowWarning                                ! Show an error message
  153.       FREE(ListQueue)                            ! Free memory table
  154.       CLOSE(RptFile)                             ! Close the DOS file
  155.   #IF(%Pulldown)                                #!If a Pulldown exists
  156.       CLOSE(%Pulldown)                         #<! Close the Pulldown
  157.   #ENDIF
  158.       CLOSE(SCREEN)                              ! Close the Screen
  159.       #EMBED('Immediately before RETURN for non-ASCII file error')
  160.       RETURN                                     ! Return back to caller
  161.     END                                          !End IF
  162.   #IF(%ShowProg)                                #!If showing the progress
  163.     #INSERT(%ShowProgress)
  164.   #ENDIF
  165.     #EMBED('After NEXT in RptFile LOOP')
  166.     Que:QueueLine = Dos:Fline                    ! Fill the queue line.
  167.     ADD(ListQueue)                               ! Add to the queue
  168.     IF ERRORCODE()                               ! If out of memory
  169.       GLO:Message1 = 'Error: ' & ERROR()         ! Create the error message
  170.       GLO:Message2 = 'This file is too large to be read into memory.'
  171.       GLO:Message3 = 'The entire file will not be displayed.'
  172.       ShowWarning                                !  Show the error message
  173.       BREAK                                      !  Break out of read loop
  174.     END                                          ! End IF
  175.  
  176.     IF FirstPage                                 ! If page 1
  177.       IF RECORDS(ListQueue) = ROWS(SCREEN)       !  If we have a full screen
  178.         FirstPage = 0                            !   Turn off the page flag
  179.         DISPLAY(?List)                           !   Display page 1
  180.       END                                        !  End IF
  181.     END                                          ! End IF
  182.     LOOP WHILE KEYBOARD()                        ! While Keyboard Input
  183.       SELECT(?List)                              !  Select the List box
  184.       ACCEPT                                     !  Handle internal keystrokes
  185.     END                                          ! End LOOP
  186.     IF KEYCODE() = EscKey THEN BREAK.
  187.   END                                            !End LOOP
  188.   StatusLine = 'Viewing: ' & %ListFile         #<!Fill the status line
  189.   DISPLAY                                        !Redisplay the screen
  190.   PrintDevice = ''                               !Blank the PrintDevice field
  191.   LOOP                                           !Process the screen
  192.   #FOR(%ScreenField)
  193.     #IF(%ScreenFieldSetup)
  194.     CASE SELECTED()                            #<! Jump to field setup routine
  195.     #INSERT(%ScreenSetupRoutines)
  196.     END                                        #<! End CASE
  197.     #ENDIF
  198.   #ENDFOR
  199.     ACCEPT                                       ! Accept keyboard input
  200.     IF KEYCODE()=CtrlEsc OR (KEYCODE()=EscKey AND FIELD()=1)
  201.        BREAK                                     ! Allow 2.1 style exit
  202.     .
  203.  
  204.     #INSERT(%HotKeyRoutines)
  205.     CASE FIELD()                                 ! Which field was completed
  206.   #FOR(%ScreenField)
  207.     #IF(%ScreenField = '?Exit')
  208.     OF ?Exit                                     ! Completed Exit Button
  209.       #IF(%ScreenFieldEdit)
  210.       %ScreenFieldEdit                         #<!  Exit edit routine
  211.       #ENDIF
  212.       BREAK                                      !  Break out of the loop
  213.     #ELSIF(%ScreenField = '?Next')
  214.     OF ?Next
  215.       #IF(%ScreenFieldEdit)
  216.       %ScreenFieldEdit                         #<!  Edit routine
  217.       #ENDIF
  218.        GetList(FieldNo,Bar,Elem)
  219.        DO SearchText
  220.  
  221.     #ELSIF(%ScreenField = '?Search')
  222.     OF ?Search
  223.       #IF(%ScreenFieldEdit)
  224.       %ScreenFieldEdit                         #<!  Edit routine
  225.       #ENDIF
  226.        GetList(FieldNo,Bar,Elem)
  227.        SaveStyle = STYLES()                    #<!Save current style
  228.        GETSTYLES('')                           #<!Turn off Styles
  229.        OPEN(SearchInput)
  230.        LOOP                                      !Process the screen
  231.          ACCEPT                                  ! Accept keyboard input
  232.          IF KEYCODE()=EscKey OR KEYCODE()=CtrlEsc OR FIELD()=?Exit2
  233.             BREAK                               ! Used for 2.1 style
  234.          .                                      ! screens
  235.          IF KEYCODE()=CtrlEnter OR FIELD()=?Ok2 OR KEYCODE()=EnterKey
  236.             BREAK
  237.          .
  238.        .
  239.        SETSTYLES(SaveStyle)                    #<!Restore user styles
  240.        IF KEYCODE()=EscKey OR KEYCODE()=CtrlEsc OR FIELD()=?Exit2
  241.           CLOSE(SearchInput)
  242.           CYCLE
  243.        .
  244.        CLOSE(SearchInput)
  245.  
  246.        DO SearchText
  247.  
  248.     #ELSIF(%ScreenField = '?ChangeMode')
  249.     OF ?ChangeMode                               ! Completed mode button
  250.       IF ROWS(SCREEN) = 25                       !  If in 25 line mode
  251.         CLOSE(SCREEN)                            !   Close the current screen
  252.         SETTEXT(50,80)                           !   Set to 50 line mode
  253.       ELSE                                       !  Else in 43 or 50 line mode
  254.         CLOSE(SCREEN)                            !   Close the current screen
  255.         SETTEXT(25,80)                           !   Set to 25 line mode
  256.         SETAREA(25,80)                           !   Resize the screen area
  257.         LOADSYMBOLS                              !   Reload graphic mouse
  258.       END                                        !  End IF
  259.       OPEN(SCREEN)                               !  Open screen in new mode
  260.   #FOR(%ScreenField)
  261.     #IF(%ScreenField = '?PrintDevice')
  262.       DISABLE(?PrintDevice)                      !  Disable the device field
  263.     #ENDIF
  264.     #IF(%ScreenField = '?ChangeMode')
  265.       IF GRAPHIC(1) <> 5Ah                       !  If not in text mode
  266.          DISABLE(?ChangeMode)                    !   Disable ChangeMode button
  267.       END                                        !  End IF
  268.     #ENDIF
  269.   #ENDFOR
  270.       #IF(%MouseSupport)
  271.       SETMOUSE(ROW(?ChangeMode),COL(?ChangeMode))!  Reset the mouse position
  272.       #ENDIF
  273.       #IF(%ScreenFieldEdit)
  274.       %ScreenFieldEdit                         #<!  ChangeMode edit routine
  275.       #ENDIF
  276.       DISPLAY                                    !  Display the fields
  277.       PrintDevice = ''                           !  Blank PrintDevice field
  278.     #ELSIF(%ScreenField = '?Print')
  279.     OF ?Print                                    ! Completed Print Button
  280.       #IF(%ScreenFieldEdit)
  281.       %ScreenFieldEdit                         #<!  Print button edit routine
  282.       #ENDIF
  283.       IF NOT PrintDevice                         !  If no print device
  284.         DISABLE(?StatusLine)                     !   Disable the StatusLine
  285.         ENABLE(?PrintDevice)                     !   Enable the PrintDevice
  286.         SELECT(?PrintDevice)                     !   Select the PrintDevice
  287.         CYCLE                                    !   Cycle to ACCEPT input
  288.       END                                        !  End IF
  289.       IF NOT STATUS(PrintDevice)                 !  If PrintDevice not ready
  290.         GLO:Message1 = CLIP(PrintDevice) & ' is not ready.'
  291.         GLO:Message2 = 'Be sure the Printer is online and attached to'
  292.         GLO:Message3 = 'the specified device and try again.'
  293.         ShowWarning                              !   Show an error message
  294.         PrintDevice = ''                         !   Blank PrintDevice field
  295.         CYCLE                                    !   Cycle to ACCEPT input
  296.       END                                        !  End IF
  297.       StatusLine = 'Printing: ' & %ListFile    #<!  Fill the status line
  298.       DISPLAY(?StatusLine)                       !  Display the status line
  299.       OPEN(REPORT)                               !  Open the report to print
  300.       LOOP I# = 1 to RECORDS(ListQueue)          !  Loop while QUEUE records
  301.         GET(ListQueue,I#)                        !   Get the QUEUE entry
  302.         IF ERRORCODE() THEN BREAK.               !   Break if an error occurs
  303.         %ReportDetailPre
  304.         PRINT(%ReportPre:%ReportDetail)        #<!Print Detail band
  305.         %ReportDetailPost
  306.         IF KEYBOARD()                            !   If keyboard input
  307.           ACCEPT                                 !    Get the keystroke
  308.           IF KEYCODE() = EscKey                  !    If the ESCAPE key
  309.             PrintDevice = ''                     !     Blank PrintDevice field
  310.             BREAK                                !     Break from printing
  311.           END                                    !    End IF
  312.         END                                      !   End IF
  313.       END                                        !  End LOOP
  314.       CLOSE(REPORT)                              !  Close the report
  315.       StatusLine = 'Viewing: ' & %ListFile     #<!  Fill the status line
  316.       DISPLAY(?StatusLine)                       !  Display the status line
  317.       PrintDevice = ''                           !  Blank PrintDevice field
  318.     #ELSIF(%ScreenField = '?PrintDevice')
  319.     OF ?PrintDevice                              ! Selected a port for printer
  320.       #IF(%ScreenFieldEdit)
  321.       %ScreenFieldEdit                         #<!  PrintDevice edit routine
  322.       #ENDIF
  323.       DISABLE(?PrintDevice)                      !  Disable the PrintDevice
  324.       ENABLE(?StatusLine)                        !  Enable the StatusLine
  325.       IF KEYCODE() = EscKey                      !  If escape key pressed
  326.         SELECT(?Exit)                            !   Select the exit button
  327.         PrintDevice = ''                         !   Blank PrintDevice field
  328.         CYCLE                                    !   Cycle to ACCEPT input
  329.       END                                        !  End IF
  330.       #IF(%PrintFieldExists='True')
  331.       SELECT(?Print)                             !  Select the Print button
  332.       #ENDIF
  333.       PRESS(EnterKey)                            !  And complete it.
  334.     #ELSIF(%ScreenFieldEdit)
  335.     OF %ScreenField                              ! Completed %ScreenField
  336.       %ScreenFieldEdit                           !  %ScreenField edit routine
  337.     #ENDIF
  338.   #ENDFOR
  339.     #INSERT(%PulldownEditRoutines)
  340.     END                                          ! End CASE FIELD()
  341.   END                                            !End LOOP
  342.   #EMBED('Immediately after LOOP, before FREE(Queue)')
  343.   FREE(ListQueue)                                !Free memory table
  344.   CLOSE(RptFile)                                 !Close the DOS file
  345.   #IF(%Pulldown)                                #!If a Pulldown exists
  346.   CLOSE(%Pulldown)                             #<!Close the Pulldown
  347.   #ENDIF
  348.   IF Rows(SCREEN) <> SaveRows |                  !If the mode is not the same
  349.       OR SaveCols <> Cols(SCREEN)                !   as when procedure started
  350.     CLOSE(SCREEN)                                !Close the Screen
  351.     SETTEXT(SaveRows,SaveCols)                   ! Reset to the entry mode
  352.     SETAREA(SaveRows,SaveCols)                   ! Resize the screen area
  353.     LOADSYMBOLS                                  ! Reload graphic mouse
  354.   END                                            !End IF
  355.  
  356.   #FOR(%ScreenField)
  357.     #IF(%ScreenField = '?Search')
  358. SearchText ROUTINE                              ! Routine to Search Text
  359.    IF ~CaseSensitive
  360.        SearchFor=UPPER(SearchFor)
  361.    .
  362.    SaveElem#=Elem
  363.    SaveBar#=Bar
  364.    Found#=0
  365.  
  366.    LOOP
  367.       Elem+=1
  368.       Get(ListQueue,Elem+Bar-1)                ! Get Next Line
  369.       #EMBED('Searching, after Get List')
  370.       IF ERRORCODE()                           ! End, or other Error?
  371.          BREAK                                 ! We're Done!
  372.       .
  373.       IF INSTRING(SearchFor,Que:QueueLine,1)>0 OR (~CaseSensitive AND INSTRING(SearchFor,UPPER(Que:QueueLine),1)>0)
  374.          DISPLAY
  375.          Found#=1                              ! Found Text
  376.          BREAK
  377.    .  .
  378.  
  379.    IF Found#
  380.       SetList(FieldNo,Bar,Elem)                ! Set LISTBOX to new position
  381.       #EMBED('Found, after Set List')
  382.       DISPLAY
  383.    ELSE
  384.       Elem=SaveElem#                           ! Set LISTBOX to old position
  385.       Bar=SaveBar#
  386.       Get(ListQueue,Elem+Bar-1)
  387.       #EMBED('Not Found - Get List')
  388.       StatusLine=SearchFor&' Not Found. {50}'
  389.       DISPLAY
  390.    .
  391.    SELECT(?List)
  392.     #ENDIF
  393.   #ENDFOR
  394.  
  395. #EMBED('End of Procedure')
  396. #!
  397. #!***************************************************************************
  398. #!
  399. #GROUP(%ShowProgress)
  400. IF NOT (((POINTER(RptFile)+100)%%100))           !Show the progess indicator
  401.   VEW::Length += 1
  402.   StatusLine = ' Reading File: ' & SUB(VEW::ProgString,1,VEW::Length)
  403.   IF VEW::Length = 50
  404.     VEW::Length = 1
  405.     StatusLine = ' Reading File: ' & ' {70}'
  406.   END
  407.   Display(?StatusLine)
  408. END
  409. #!
  410. #!***************************************************************************
  411.