home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / browse10.zip / browse10.cmd
OS/2 REXX Batch file  |  1994-05-30  |  35KB  |  1,303 lines

  1. /*
  2. ** Browser v1.0     [B.CMD]
  3. **
  4. ** By Mark Ziller, 1994
  5. **
  6. ** Based on code by Bruce E. Högman
  7. ** Uses VREXX 
  8. **
  9. */
  10.  
  11.  
  12. /* Get any command line args */
  13. ProgName = "Browser v1.0"
  14. InFileSpec=""; 
  15. parse upper arg a1 a2 a3 a4
  16. UsesVRexx = 0
  17.  
  18.  
  19.  
  20. /* ================================================================== */
  21. /* Check to see if all REXX utility functions have been Loaded        */
  22. /* NOTE:  RxFuncQuery tests for REXX load.                            */
  23. /* ================================================================== */
  24. if 0 < RxFuncQuery('SysLoadFuncs') then do; 
  25.    Call rxfuncadd 'SysLoadFuncs','REXXUTIL','SysLoadFuncs'; 
  26.    Call SysLoadFuncs; 
  27. end;
  28.  
  29.  
  30. /* ================================================================== 
  31. ** Load in VREXX functions now (while there is sure to be enough memory)
  32. ** ================================================================== 
  33. */
  34.  
  35. call CheckVRexx
  36.  
  37.  
  38. /* ================================================================== 
  39. ** Save the original screen data
  40. ** ================================================================== 
  41. */
  42.  
  43. screen = SysTextScreenRead( 0, 0 )
  44. parse value SysCurPos() with OrigRow OrigCol
  45. OrigRow = OrigRow - 1
  46. call SysCurState 'OFF'
  47.  
  48.  
  49.  
  50. /* ================================================================== 
  51. ** GLOBALS
  52. ** ================================================================== 
  53. */
  54.  
  55. Globals:
  56.  
  57. ErrorFlag = ""            /* No errors have occurred */
  58. Yes = 1
  59. No  = 0
  60. OUTR='~'||'fa'x||'fa'x||'fa'x||'fa'x||'fa'x||'fa'x||'fa'x||'fa'x;
  61. INTR=''||'06'x||'07'x||'08'x||'09'x||'0a'x||'0b'x||'0c'x||'0d'x;
  62. bShowBlank  = 1        /* default = Show Blank Lines (1) */
  63. bFoldLines   = 0        /* default = Do NOT Wrap Long Lines (0) */
  64. bShowCursor = 0        /* default = Do NOT Show Cursor (0) */
  65. Cursor   = 0            /* hide cursor if not in use */
  66. FToggle  = 0            /* View Found Lines Only = NO (0) */
  67. HasSearched = 0        /* No search has been performed */
  68. BookMark.rows = 0        /* book mark data structure */
  69. BookMark.cols  = 2
  70. BookMark.label.1 = "Line #"
  71. BookMark.label.2 = "Line Text"
  72. BookMark.width.1 = 7
  73. BookMark.width.2 = 70
  74. SCurPos = 0
  75. zMaxCol = 80
  76. ColrTxt=40    
  77. ColrTxtBg=44;
  78. BriteTxt=0; 
  79. BriteHd=0; 
  80. ColrHd=30; 
  81. ColrHdBg=46;
  82.  
  83.  
  84. /* ================================================================== 
  85. ** Check for any command line arguments
  86. ** ================================================================== 
  87. */
  88.  
  89. passed.1  = a1
  90. passed.2  = a2
  91. passed.3  = a3
  92. passed.4  = a4
  93.  
  94.  
  95. do i = 1 to 3
  96.   InFileSpec = passed.i;
  97.   c = substr(passed.i, 1, 1)
  98.   if c = '-' | c = '+' then 
  99.      call ParseArg passed.i;
  100.   else leave;
  101. end;
  102.  
  103.  
  104.  
  105. /* ================================================================== 
  106. ** See if any legit filename was passed; otherwise, popup file box to get one
  107. ** ================================================================== 
  108. */
  109.  
  110. if InFileSpec = "" then do;
  111.   InFileSpec = "*.*"
  112.   signal FILEBOX
  113. end
  114. signal on syntax name File_Err
  115. call SysFileTree InFileSpec, 'list', 'F'
  116. signal off syntax
  117. if list.0 = 1 then do;
  118.   FName = InFileSpec
  119.   signal ENTRY
  120. end
  121. if list.0 > 1 then signal FileBox;
  122.  
  123.  
  124. /* ================================================================== 
  125. ** File_Error
  126. ** ================================================================== 
  127. */
  128. File_Err:
  129.  
  130. InFileSpec = "*.*"
  131. signal off syntax
  132.  
  133.  
  134.  
  135. /* ================================================================== 
  136. ** FileBox
  137. ** ================================================================== 
  138. */
  139.  
  140. FileBox:
  141.  
  142. /* first, setup VRexx calls */
  143. call CheckVRexx;
  144.  
  145. button = VFileBox('Select file to browse:', InFileSpec, 'file')
  146. if button = 'CANCEL' then signal CLEANUP
  147. FName = file.vstring
  148.  
  149.  
  150.  
  151. /* ================================================================== 
  152. ** Main Entry Point (for re-entry to the program, e.g. after an EDIT command)
  153. ** ================================================================== 
  154. */
  155.  
  156. Entry:
  157.  
  158. FFName = FILESPEC("name", FName)    /* get just the file name */
  159. call READ;
  160.  
  161.  
  162.  
  163.  
  164. /* ================================================================== 
  165. ** MAINLOOP
  166. ** ================================================================== 
  167. */
  168.  
  169. MAINLOOP:
  170. do while Action \= "EXIT"
  171.    ReDraw = Yes            /* by default, redraw entire screen w/ each move */
  172.    NoStatus = No            /* Don't supress status update */
  173.    call KeyStroke
  174.  
  175.    if bShowCursor = No then do;
  176.    select;
  177.      when Action = "UP" then
  178.         CurrLine = MAX(Top, CurrLine - 1)
  179.      when Action = "DOWN" then
  180.         CurrLine = MIN(CurrLine + 1, Bottom)
  181.      when Action = "PAGEUP" then
  182.         CurrLine = MAX(Top, CurrLine - LinesPerPage)
  183.      when Action = "PAGEDOWN" then
  184.         CurrLine = MIN(CurrLine + LinesPerPage, Bottom)
  185.      when Action = "HOME" then
  186.          CurrLine = Top;
  187.      when Action = "END" then
  188.          CurrLine = Bottom;
  189.      when Action = "CURSOR" then do;
  190.           bShowCursor = Yes;
  191.           Action = "XXXX";
  192.           Cursor = 1;
  193.           end;
  194.      when Action = "HELP" then
  195.           call DoHelp;
  196.      when Action = "SEARCH" then
  197.           call DoSearch;
  198.      when Action = "NEXT" then
  199.           call DoNextSearch;
  200.      when Action = "PREV" then
  201.           call DoLastSearch;
  202.      when Action = "WRITE" then
  203.           call DoWriteResults;
  204.      when Action = "EDIT" then
  205.           call DoEdit;
  206.      when Action = "GOTO" then 
  207.           call DoGoto;
  208.      when Action = "TVIEW" then
  209.           call ToggleFound;
  210.      when Action = "MARK" then
  211.           call MarkToBook;
  212.      when Action = "BOOK" then
  213.           call ShowBookMark;
  214.      when Action = "UNMARK" then
  215.           call UnMarkBook;
  216.      when Action = "MARKDISK" then
  217.           call WriteBook;
  218.      otherwise nop;
  219.    end;  /* select */
  220.    end; /* bShow Cursor = NO (0) */
  221.  
  222.    if bShowCursor = Yes then do;
  223.      select;
  224.      when Action = "UP" then do;
  225.         if Cursor > 2 then do;
  226.            temp = CurrLine + Cursor - 1;
  227.            if bFoldLines = 0 & LENGTH(LineArray.temp) > 80 then do;      
  228.           call ScrDisplay  Cursor+1 No TRANSLATE(LineArray.Temp, OUTR, INTR)
  229.               temp = CurrLine + Cursor;
  230.               call ScrDisplay  Cursor+2 No TRANSLATE(LineArray.Temp, OUTR, INTR)
  231.               end;   /* if bFoldLines = 0 then do */
  232.            else do;
  233.          call ScrDisplay  Cursor+1 No TRANSLATE(LineArray.Temp, OUTR, INTR)
  234.            end;   /* else do;  */
  235.            Cursor = Cursor - 1;
  236.            temp = CurrLine + Cursor - 1;
  237.        call ScrDisplay  Cursor+1 Yes TRANSLATE(LineArray.Temp, OUTR, INTR)
  238.            ReDraw = No;
  239.            end; /* if Cursor > 1 then do; */
  240.         else do;
  241.            CurrLine = MAX(Top, CurrLine - 1)
  242.            Cursor = 1;
  243.            end; /* else do */
  244.        end;   /*  when Action = "UP" then do;  */
  245.      when Action = "DOWN" then do;
  246.         if Cursor < LinesPerPage then do;
  247.            temp = CurrLine + Cursor - 1;
  248.        call ScrDisplay  Cursor+1 No TRANSLATE(LineArray.Temp, OUTR, INTR)
  249.            Cursor = Cursor + 1;
  250.            temp = CurrLine + Cursor - 1;
  251.        call ScrDisplay  Cursor+1 Yes TRANSLATE(LineArray.Temp, OUTR, INTR) 
  252.            ReDraw = No;
  253.            end;   /*  if Cursor < LinesPerPage then do;  */
  254.         else do;
  255.            CurrLine = MIN(CurrLine + 1, Bottom)
  256.            Cursor = LinesPerPage;
  257.            end;  /* else do */
  258.         end;   /*  when Action = "DOWN" then do;  */
  259.      when Action = "PAGEUP" then do;
  260.         CurrLine = MAX(Top, CurrLine - LinesPerPage)
  261.         Cursor   = 1;
  262.         end;  /*  when Action = "PAGEUP" then do;  */
  263.      when Action = "PAGEDOWN" then do;
  264.         CurrLine = MIN(CurrLine + LinesPerPage, Bottom)
  265.         Cursor   = LinesPerPage;
  266.         end;   /*  when Action = "PAGEDOWN" then do;  */
  267.      when Action = "HOME" then do;
  268.          CurrLine = Top;
  269.          Cursor   = 1;
  270.          end;  /*  when Action = "HOME" then do;  */
  271.      when Action = "END" then do;
  272.          CurrLine = Bottom;
  273.          Cursor   = LinesPerPage;
  274.          end;  /* when Action = "END" then do;  */
  275.      when Action = "CURSOR" then do;
  276.           bShowCursor = No;
  277.           Cursor = 0;
  278.           end;
  279.      when Action = "HELP" then
  280.           call DoHelp;
  281.      when Action = "SEARCH" then
  282.           call DoSearch;
  283.      when Action = "NEXT" then
  284.           call DoNextSearch;
  285.      when Action = "PREV" then
  286.           call DoLastSearch;
  287.      when Action = "WRITE" then
  288.           call DoWriteResults;
  289.      when Action = "EDIT" then
  290.           call DoEdit;
  291.      when Action = "GOTO" then 
  292.           call DoGoto;
  293.      when Action = "TVIEW" then
  294.           call ToggleFound;
  295.      when Action = "MARK" then
  296.           call MarkToBook;
  297.      when Action = "BOOK" then
  298.           call ShowBookMark;
  299.      when Action = "UNMARK" then
  300.           call UnMarkBook;
  301.      when Action = "MARKDISK" then
  302.           call WriteBook;
  303.      otherwise nop;
  304.     end;  /* select */
  305.    end; /* bShow Cursor = YES (1) */
  306.  
  307. if CurrLine > (Bottom - LinesPerPage + 1) then do;
  308.    CurrLine = Bottom - LinesPerPage + 1;
  309.    if CurrLine < 1 then 
  310.       CurrLine = 1;
  311. end;
  312.  
  313. if ReDraw = Yes then
  314.    call DisplayData
  315. if ReDraw = No & NoStatus = No then do;
  316.   if FToggle = 0 then
  317.      ViewText = "View ALL"
  318.   else
  319.      ViewText = "View FOUND"
  320.   if bShowCursor = 1 then
  321.      CursorText = "Cursor ON"
  322.   else
  323.      CursorText = "Cursor OFF"
  324.   StatusLine = "[" FFName "]     Line "||CurrLine+Cursor-1||" of "||Bottom||"    "||ViewText||"   "||CursorText||"  Marked = "||BookMark.rows
  325.   call ScrDisplay 1 No StatusLine
  326. end;
  327.  
  328. end /* do while action \= "EXIT" */
  329. signal CLEANUP
  330.  
  331.  
  332.  
  333. /* ================================================================== 
  334. ** READ file into memory
  335. ** ================================================================== 
  336. */
  337.  
  338. READ:
  339. say "Working...";
  340. Drv=FILESPEC('d',FName);
  341. if Drv='A:' | Drv='B:' then 
  342.    OdoTrip=49; 
  343. else 
  344.    OdoTrip=99;
  345.  
  346. /* set up some data vars */
  347. LineLast=0; 
  348. LineFirst=1; 
  349. Odo=0; 
  350. MaxLineLen=0;
  351. bBlankLast=0; 
  352. InBlanks=0; 
  353. InLines=0;
  354.  
  355. /* now read the file into the array */
  356. do forever;
  357.    if Lines(FName) = 0 then 
  358.        leave;  /* at end of file? */
  359.    LineLast=LineLast+1; 
  360.    InLines=InLines+1;
  361.    LineArray.LineLast=LINEIN(FName);
  362.    Odo=Odo+1; 
  363.  
  364. /* check to see if the line should be folded (for long lines) */
  365.    if bFoldLines > 0 then do
  366.      LLen=LENGTH(LineArray.LineLast);
  367.      do while LLen > zMaxCol;
  368.        LP1=LineLast+1;
  369.        LineArray.LP1=substr(LineArray.LineLast,zMaxCol+1);
  370.        LineArray.LineLast=substr(LineArray.LineLast,1,zMaxCol);
  371.        LineLast=LP1;
  372.        LLen=LENGTH(LineArray.LineLast);
  373.      end; /* do while LLen > zMaxCol; */
  374.     end; /* if bFoldLines > 0 then do */
  375.    else 
  376.      nop;
  377.  
  378. /* check to see if we need to condense blank lines */
  379.    if bShowBlank < 1 then do;
  380.       if LineArray.LineLast="" | LineArray.LineLast=COPIES('20'x,LLen) then do;
  381.          if bBlankLast > 0 then do;
  382.             LineLast=LineLast-1; 
  383.             InBlanks=InBlanks+1;
  384.          end;
  385.          bBlankLast=1;
  386.       end;
  387.       else bBlankLast=0;
  388.    end;
  389.  
  390.    if Odo>OdoTrip THEN DO; 
  391.       Odo=0;
  392.       irc=charout(,"s"InLines "lines read," InBlanks "blank lines dropped," InLines-InBlanks "lines kept.u");
  393.    END;
  394.  
  395. END; /* do forever */
  396. irc=stream(FName,'c','close');
  397.  
  398.  
  399. /* ================================================================== 
  400. ** Now get ready to display the text (part of READ)
  401. ** ================================================================== 
  402. */
  403.  
  404. Action   = ""
  405. CurrLine = 1
  406. Bottom  = LineLast
  407. Top      = 1
  408. LineArray.LineLast="*************** END OF FILE ***************"  
  409. LineArray.LineLast=TRANSLATE(LineArray.LineLast,OUTR,INTR);
  410. call GetVideoSize
  411.  
  412. if LinesPerPage > LineLast then         /* fill in at least LinesPerPage of stuff */
  413.   do temp = LineLast+1 to LinesPerPage+2
  414.     LineArray.temp = " "
  415.   end
  416. call DisplayData
  417. return;
  418.  
  419.  
  420.  
  421.  
  422. /* ================================================================== 
  423. ** DisplayData (Redraw entire screen)
  424. ** ================================================================== 
  425. */
  426.  
  427. DisplayData:
  428. curr        = CurrLine
  429. if FToggle = 0 then
  430.    ViewText = "View ALL"
  431. else
  432.    ViewText = "View FOUND"
  433. if bShowCursor = 1 then
  434.    CursorText = "Cursor ON"
  435. else
  436.    CursorText = "Cursor OFF"
  437. if bShowCursor = No then
  438.    StatusLine = "[" FFName "]     Lines "||curr||" - "||curr+LinesPerPage||" of "||Bottom||"   "||ViewText||"  "||CursorText||"  Marked = "||BookMark.rows
  439. else
  440.    StatusLine = "[" FFName "]     Line "||curr+Cursor-1||" of "||Bottom||"    "||ViewText||"  "||CursorText||"  Marked = "||BookMark.rows
  441. call ScrDisplay 1 No StatusLine
  442. do lp = 2 to LinesPerPage+1
  443.   if lp = Cursor + 1 then
  444.     call ScrDisplay lp Yes TRANSLATE(LineArray.curr, OUTR, INTR) 
  445.   else
  446.     call ScrDisplay lp No TRANSLATE(LineArray.curr, OUTR, INTR) 
  447.   curr = curr + 1
  448. end /* for i = 1 to nLines */
  449. return
  450.  
  451.  
  452.  
  453. /* ================================================================== 
  454. ** Display one line of data
  455. ** ================================================================== 
  456. */
  457.  
  458. ScrDisplay:;
  459. parse arg RowNr IsCursor LineData;
  460. if RowNr = 1 then do; 
  461.   SFgColr=ColrHd; 
  462.   Bright=BriteHd; 
  463.   SBgColr=ColrHdBg; 
  464. end;
  465. else do; 
  466.   SFgColr=ColrTxt; 
  467.   Bright=BriteTxt; 
  468.   SBgColr=ColrTxtBg; 
  469. end;
  470. if IsCursor = 1 then do;
  471.   SFgColr=32; 
  472.   Bright=BriteTxt; 
  473.   SBgColr=40; 
  474. end;
  475.  
  476. irc=CHAROUT(,""RowNr";1H"Bright";"SFgColr";"SBgColr"m"LineData""RowNr";1H");
  477. return;
  478.  
  479.  
  480.  
  481.  
  482. /* ================================================================== 
  483. ** Get a keystroke from the keybroad and return the appropriate action
  484. ** ================================================================== 
  485. */
  486.  
  487. KeyStroke:;
  488. Action = ""        /* nothing selected yet */
  489. do forever;
  490.    parse value SysCurPos() with VidRow VidCol;
  491.    key=SysGetKey('noecho');
  492.    if c2x(key)='1B' THEN DO; 
  493.       Action="EXIT"; 
  494.       return; 
  495.       END;
  496.    kv=c2d(key);
  497.    if c2x(key)='E0' THEN DO;
  498.       kv=1000; 
  499.       key=SysGetkey('noecho'); 
  500.       kv=kv+c2d(key);
  501.    END;
  502.    else do;
  503.       if kv=0 THEN DO; 
  504.          kv=1000; 
  505.          key=SysGetKey('noecho'); 
  506.          kv=kv+c2d(key);
  507.       END;
  508.    END;
  509.       SELECT;
  510.       when kv=1072        THEN DO; Action="UP"; return; END;
  511.       when kv=1080        THEN DO; Action="DOWN"; return; END;
  512.       when kv=1071        THEN DO; Action="HOME"; return; END;
  513.       when kv=1079        THEN DO; Action="END"; return; END;
  514.       when kv=1073        THEN DO; Action="PAGEUP"; return; END;
  515.       when kv=1081        THEN DO; Action="PAGEDOWN"; return; END;
  516.       when kv=99        THEN DO; Action="CURSOR"; return; END;
  517.       when kv=1059        THEN DO; Action="HELP";return;END;
  518.       when kv=115        THEN DO; Action="SEARCH";return;END;
  519.       when kv=110        THEN DO; Action="NEXT";return;END;
  520.       when kv=112        THEN DO; Action="PREV";return;END;
  521.       when kv=43        THEN DO; Action="NEXT";return;END;
  522.       when kv=45        THEN DO; Action="PREV";return;END;
  523.       when kv=119        THEN DO; Action="WRITE";return;END;
  524.       when kv=101        THEN DO; Action="EDIT";return;END
  525.       when kv=103        THEN DO; Action="GOTO";return;END;
  526.       when kv=118        THEN DO; Action="TVIEW";return;END;
  527.       when kv=109        THEN DO; Action="MARK";return;END;
  528.       when kv=98        THEN DO; Action="BOOK";return;END;
  529.       when kv=117        THEN DO; Action="UNMARK";return;END;
  530.       when kv=100        THEN DO; Action="MARKDISK";return;END;
  531.       otherwise nop;
  532.       END; /* select */
  533.    if Action \= "" then return;
  534. END;
  535. return;
  536.  
  537.  
  538.  
  539. /* ================================================================== 
  540. ** GetVideoSize
  541. ** ================================================================== 
  542. */
  543.  
  544. GetVideoSize:;
  545.    parse value SysTextScreenSize() with gMaxRow gMaxCol;
  546.    LinesPerPage=gMaxRow-2;
  547.    return;
  548.  
  549.  
  550.  
  551.  
  552. /* ================================================================== 
  553. ** Parse a command line argument
  554. ** ================================================================== 
  555. */
  556.  
  557. ParseArg:;
  558. parse upper arg vvv;
  559. s = substr(vvv, 1, 1);
  560. if s = '-' then sign = 0;
  561. if s = '+' then sign = 1;
  562. c = substr(vvv, 2, 2);
  563.  
  564. if c = 'W' then bFoldLines = sign;
  565. if c = 'B'  then bShowBlank = sign;
  566. if c = 'S' then do;
  567.    bShowCursor = sign;
  568.    Cursor   = 1
  569. end;
  570. return
  571.  
  572.  
  573.  
  574. /* ================================================================== 
  575. ** CheckVRexx (Load if not already loaded)
  576. ** ================================================================== 
  577. */
  578.  
  579. CheckVRexx:
  580.  
  581. if UsesVRexx = No then do;
  582.   UsesVRexx = Yes;
  583.   call RxFuncAdd 'VInit', 'VREXX', 'VINIT'
  584.   initcode = VInit()
  585.   if initcode = 'ERROR' then signal CLEAN_EI
  586.   signal on failure name CLEAN_EF
  587.   signal on halt name CLEAN_EH
  588.   signal on syntax name CLEAN_ES
  589.   call VDialogPos 50, 50
  590. end;
  591. return;
  592.  
  593.  
  594.  
  595.  
  596. /* ================================================================== 
  597. ** Do a Search
  598. ** ================================================================== 
  599. */
  600.  
  601. DoSearch:
  602.  
  603. call CheckVRexx;
  604.  
  605. if FToggle = 1 then do            /* if we are in the VIEW FOUND mode */
  606.   msg.0 = 1
  607.   msg.1 = " Not allowed from the VIEW FOUND mode"
  608.   call VMsgBox "Warning", msg, 1
  609.   return;
  610. end;
  611.   
  612.  
  613. /* Prompt user for search text */
  614. prompt.0 = 1
  615. prompt.1 = 'Enter the text to search for:'
  616. prompt.vstring = ''
  617. button = VInputBox('Text', prompt, 30, 3)
  618. if button = 'CANCEL' then return
  619. SearchText = prompt.vstring
  620.  
  621. /* if another search has already been performed, then free up that memory first */
  622. if HasSearched = 1 then 
  623.   drop SList. SResults.
  624.  
  625.  
  626. /* Now do the initial search */
  627. rc = SysFileSearch( SearchText, FName, 'SResults', 'N' )
  628.  
  629. /* report any errors */
  630. if rc > 0 then do;
  631.   msg.0 = 1
  632.   msg.1 = '   Search Error '
  633.   rb = VMsgBox('Search', msg, 1)
  634.   return;
  635. end;
  636.  
  637. if SResults.0 = 0 then do;
  638.   msg.0 = 1
  639.   msg.1 = '   No Matching Text Found'
  640.   rb = VMsgBox('Search', msg, 1)
  641.   return;
  642. end;
  643.  
  644. /* And put them in a useful format */
  645. SList.0 = SResults.0
  646. do i = 1 to SResults.0
  647.    call GetNum SResults.i
  648.    SList.i    = num
  649.    SResults.i = newText
  650. end; /* do i = 1 to SResults.0 */
  651.  
  652. /* Position the cursor on the first one founds */
  653. SCurPos = 0
  654. HasSearched = 1
  655. call DoNextSearch
  656.  
  657.  
  658. /* And give user some info and choices */
  659.   msg.0 = 7
  660.   msg.1 = 'Found ' || SList.0 || ' Instances of Text'
  661.   msg.2 = ''
  662.   msg.3 = 'Search Commands:'
  663.   msg.4 = '   N = Goto Next Found Line'
  664.   msg.5 = '   P = Goto Previous Found Line'
  665.   msg.6 = '   W = Write List to disk'
  666.   msg.7 = '   V = Toggle View Found Lines Only'
  667.   rb = VMsgBox('Search Results', msg, 1)
  668.  
  669. /* and then return */
  670. return;
  671.  
  672.  
  673.  
  674. /* ================================================================== 
  675. ** Get the line number for a search result and return it (part of SEARCH)
  676. ** ================================================================== 
  677. */
  678.  
  679. GetNum:
  680.  
  681. parse arg line;
  682. rev       = REVERSE( line );
  683. lst       = LASTPOS( ' ', rev );
  684. rgt       = RIGHT( rev, LENGTH(rev) - lst );
  685. num       = reverse( rgt );        /* just the line number */
  686. newText = RIGHT( line, lst );        /* the line w/o the line number */
  687. return;
  688.  
  689.  
  690.  
  691.  
  692. /* ================================================================== 
  693. ** Show the next item in the found search list
  694. ** ================================================================== 
  695. */
  696.  
  697. DoNextSearch:
  698.  
  699. call CheckVRexx;
  700.  
  701. if FToggle = 1 then do            /* if we are in the VIEW FOUND mode */
  702.   msg.0 = 1
  703.   msg.1 = " Not allowed from the VIEW FOUND mode"
  704.   call VMsgBox "Warning", msg, 1
  705.   return;
  706. end;
  707.  
  708.  
  709. /* has any search been performed? */
  710. if HasSearched = 0 then do;
  711.   msg.0 = 1
  712.   msg.1 = "  No Search Has Been Performed! "
  713.   rb = VMsgBox("Show Next Found Line", msg, 1)
  714.   return;
  715. end;
  716.  
  717.  
  718. SCurPos = SCurPos + 1
  719. if SCurPos > SList.0 then do;
  720.   msg.0 = 1
  721.   msg.1 = '   Bottom of Document Reached '
  722.   rb = VMsgBox('Search Results', msg, 1)
  723.   return;
  724. end;
  725.  
  726. if bShowCursor = Yes then do;
  727.    Cursor   = 11;        /* sort of in the middle of the screen */
  728.    CurrLine = SList.SCurPos - 10;
  729.    if CurrLine < 1 then do;
  730.       CurrLine = 1;
  731.       Cursor   = SList.SCurPos;
  732.       end;
  733.    call DisplayData;
  734.    return;
  735. end;
  736.  
  737. if bShowCursor = No then do;
  738.    if SList.SCurPos > 10 then do;
  739.      CurrLine = SList.SCurPos - 10;
  740.      call DisplayData;
  741.      temp = SList.SCurPos;
  742.      call ScrDisplay  12 Yes TRANSLATE(LineArray.Temp, OUTR, INTR)
  743.      end;
  744.    else do;
  745.      CurrLine = 1;
  746.      call DisplayData;
  747.      temp = SList.SCurPos;
  748.      call ScrDisplay  temp+1 Yes TRANSLATE(LineArray.Temp, OUTR, INTR)
  749.      end;
  750.    ReDraw = No;
  751.    NoStatus = Yes;
  752.    return;
  753.  end;
  754.  
  755. return;
  756.  
  757.  
  758.  
  759.  
  760. /* ================================================================== 
  761. ** Show the last item in the found search list
  762. ** ================================================================== 
  763. */
  764.  
  765. DoLastSearch:
  766.  
  767. call CheckVRexx;
  768.  
  769. if FToggle = 1 then do            /* if we are in the VIEW FOUND mode */
  770.   msg.0 = 1
  771.   msg.1 = " Not allowed from the VIEW FOUND mode"
  772.   call VMsgBox "Warning", msg, 1
  773.   return;
  774. end;
  775.  
  776.  
  777. /* has any search been performed? */
  778. if HasSearched = 0 then do;
  779.   msg.0 = 1
  780.   msg.1 = "  No Search Has Been Performed! "
  781.   rb = VMsgBox("Show Previous Found Line", msg, 1)
  782.   return;
  783. end;
  784.  
  785.  
  786. SCurPos = SCurPos - 1
  787. if SCurPos < 1 then do;
  788.   msg.0 = 1
  789.   msg.1 = '   Top of Document Reached '
  790.   rb = VMsgBox('Search Results', msg, 1)
  791.   return;
  792. end;
  793.  
  794. if bShowCursor = Yes then do;
  795.    Cursor   = 11;        /* sort of in the middle of the screen */
  796.    CurrLine = SList.SCurPos - 10;
  797.    if CurrLine < 1 then do;
  798.       CurrLine = 1;
  799.       Cursor   = SList.SCurPos;
  800.       end;
  801.    call DisplayData;
  802.    return;
  803. end;
  804.  
  805. if bShowCursor = No then do;
  806.    if SList.SCurPos > 10 then do;
  807.      CurrLine = SList.SCurPos - 10;
  808.      call DisplayData;
  809.      temp = SList.SCurPos;
  810.      call ScrDisplay  12 Yes TRANSLATE(LineArray.Temp, OUTR, INTR)
  811.      end;
  812.    else do;
  813.      CurrLine = 1;
  814.      call DisplayData;
  815.      temp = SList.SCurPos;
  816.      call ScrDisplay  temp+1 Yes TRANSLATE(LineArray.Temp, OUTR, INTR)
  817.      end;
  818.    ReDraw = No;
  819.    NoStatus = Yes;
  820.    return;
  821.  end;
  822.  
  823. return;
  824.  
  825.  
  826.  
  827.  
  828. /* ================================================================== 
  829. ** DoWriteResults       (Write search results to disk)
  830. ** ================================================================== 
  831. */
  832.  
  833. DoWriteResults:
  834.  
  835. call CheckVRexx;
  836.  
  837. if SList.0 = 0 then do;
  838.   msg.0 = 1
  839.   msg.1 = "  No Search Results to Write!"
  840.   rb = VMsgBox("Write Search Results", msg, 1)
  841.   return;
  842. end;
  843.  
  844. /* get a filename */
  845. button = VFileBox('Select file to write results to:', '*.*', 'file')
  846. if button = 'CANCEL' then return;
  847. TFName = file.vstring
  848.  
  849. /* see if the file already exits */
  850. rc=SysFileTree(TFName, xme, 'F', '*****','*****')
  851. if xme.0 = 0 then signal WRITEIT
  852.  
  853. /* since it already exits, prompt for desired action */
  854. msg.0 = 3
  855. msg.1 = "Overwrite file ["||FILESPEC("name",TFName)||"]"
  856. msg.2 = "Append to file ["||FILESPEC("name",TFName)||"]"
  857. msg.3 = "Abort operation (do not write)          "
  858. msg.vstring = msg.1                    /* the default */
  859. button = VRadioBox('File Already Exists!', msg, 1)
  860.  
  861. /* now take the approprite action */
  862. if msg.vstring = msg.1 then        /* delete the old file first */
  863.   rc = SysFileDelete(TFName)
  864. if msg.vstring = msg.2 then 
  865.   signal WRITEIT            /* no action required -- will overwrite */
  866. if msg.vstring = msg.3 then
  867.   return;                /* changed their mind -- return */
  868.  
  869. /* now write the results */
  870. WRITEIT:
  871. '@echo off'
  872. do i = 1 to SResults.0
  873.   irc=lineout(TFName, SResults.i);
  874. end;
  875. irc = Stream(TFName, 'c', 'close')
  876.  
  877. /* and show use that is was done */
  878. msg.0 = 1
  879. msg.1 = ' ' || SList.0 || ' Lines Written to File ' || TFName
  880. rb = VMsgBox('Search Results', msg, 1)
  881. return;
  882.  
  883.  
  884.  
  885.  
  886. /* ================================================================== 
  887. ** Toggle View Found Lines Only
  888. ** ================================================================== 
  889. */
  890.  
  891. ToggleFound:
  892.  
  893. /* see if there are any search results! */
  894. if HasSearched = 0 then do;
  895.   call CheckVRexx;
  896.   msg.0 = 1
  897.   msg.1 = "  No Search Results to View! "
  898.   rb = VMsgBox("Write Search Results", msg, 1)
  899.   return;
  900. end;
  901.  
  902.  
  903. /* Switch ON (start to show only found lines) */
  904. if FToggle = 0    then do;        /* is View Found Lines Only OFF */
  905.   do i = 0 to Bottom            /* copy the file into temp space */
  906.     tempArray.i = LineArray.i
  907.   end;  /* do i = 0 to Bottom */
  908.   tempBottom = Bottom;        /* and save the other vars, too */
  909.   do i = 1 to SResults.0            /* copy the search results to the view screen */
  910.     LineArray.i = SResults.i
  911.   end;  /* do i = 1 to SResults.0 */
  912.   Bottom = SResults.0            /* and reset other vars */
  913.   CurrLine = 1
  914.   if bShowCursor = Yes then
  915.     Cursor = 1;
  916. end;  /* if FToggle = 0    then do; */
  917.  
  918. /* Switch OFF (go back to normal display) */
  919. if FToggle = 1    then do;        /* is View Found Lines Only ON */
  920.   do i = 1 to tempBottom        /* copy file back into line array */
  921.     LineArray.i = tempArray.i
  922.   end;  /*  do i = 1 to tempBottom  */
  923.   Bottom = tempBottom        /* and reset other vars */
  924.   CurrLine = 1
  925.   if bShowCursor = Yes then
  926.     Cursor = 1;
  927.   drop tempArray.            /* free up memory */
  928. end;  /* if FToggle = 1 then do; */
  929.  
  930. /* now flip the toggle indicator switch */
  931. if FToggle = 1 then
  932.    FToggle = 0
  933. else
  934.    FToggle = 1
  935.  
  936. return;
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943. /* ================================================================== 
  944. ** DoEdit     (Call OS/2 editor for the file being viewed.)
  945. ** ================================================================== 
  946. */
  947.  
  948. DoEdit:
  949.  
  950. /* Make sure that is what the user really wants */
  951. call CheckVRexx;
  952. msg.0 = 1
  953. msg.1 = "  Edit this file?"
  954. rb = VMsgBox('Help', msg, 3)
  955. if rb = "CANCEL" then return;    
  956.  
  957. /* call the system editor with for the file */
  958. 'E 'FName
  959.  
  960. /* and then re-load the file (in case it changed) */
  961. call READ
  962.  
  963. /* and then return to calling routine */
  964. return;
  965.  
  966.  
  967.  
  968.  
  969.  
  970. /* ================================================================== 
  971. ** DoGoto           (Goto a specified line number in the file)
  972. ** ================================================================== 
  973. */
  974.  
  975. DoGoto:
  976.  
  977. /* Make sure that is what the user really wants */
  978. call CheckVRexx;
  979. prompt.0 = 1
  980. prompt.1 = '  Enter line number:      '
  981. prompt.vstring = ''
  982. button = VInputBox('Goto', prompt, 20, 3)
  983. if button = 'CANCEL' then return
  984. LineNumber = prompt.vstring
  985.  
  986. /* make sure it is in bounds */
  987. if LineNumber < 1 | LineNumber > Bottom then do;
  988.   msg.0 = 1
  989.   msg.1 = "  Line number out of range!"
  990.   rb = VMsgBox('Error', msg, 1)
  991.   return;
  992. end;
  993.  
  994. /* otherwise, goto that line number and redisplay screen */
  995. CurrLine = LineNumber
  996. if bShowCursor = Yes then
  997.   Cursor = 1;
  998. return;
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005. /* ================================================================== 
  1006. ** MarkToBook                          (Mark a line and add to the book mark list)
  1007. ** ================================================================== 
  1008. */
  1009.  
  1010. MarkToBook:
  1011.  
  1012. /* first, setup VRexx calls */
  1013. call CheckVRexx;
  1014.  
  1015. /* if the cursor is not on, how can the select a line? */
  1016. if bShowCursor = 0 then do;
  1017.   msg.0 = 1
  1018.   msg.1 = "  Cursor must be on to mark lines!"
  1019.   call VMsgBox "Mark Line to BookMark", msg, 1
  1020.   return;
  1021. end;
  1022.  
  1023. /* then add the line to the bookmark list */
  1024. temp1 = BookMark.rows + 1
  1025. temp2 = CurrLine + Cursor - 1
  1026. BookMark.temp1.1 = CurrLine + Cursor - 1
  1027. BookMark.temp1.2 = LEFT(LineArray.temp2, 70)
  1028. BookMark.rows = BookMark.rows + 1
  1029.  
  1030. return;
  1031.  
  1032.  
  1033.  
  1034.  
  1035. /* ================================================================== 
  1036. ** UnMarkBook                          (un-Mark a line from the book mark list)
  1037. ** ================================================================== 
  1038. */
  1039.  
  1040. UnMarkBook:
  1041.  
  1042. /* first, setup VRexx calls */
  1043. call CheckVRexx;
  1044.  
  1045. /* is the bookmark empty? */
  1046. if BookMark.rows = 0 then do;
  1047.   msg.0 = 1
  1048.   msg.1 = "  No lines marked "
  1049.   call VMsgBox "BookMark", msg, 1
  1050.   return;
  1051. end;
  1052.  
  1053. /* get the current line and see if it is in the bookmark */
  1054. temp1 = CurrLine + Cursor - 1        /* the line we are on now */
  1055. found = 0
  1056. do i = 1 to BookMark.rows
  1057.    if BookMark.i.1 = temp1 then do;
  1058.       found = i 
  1059.       leave
  1060.    end;
  1061. end;  /* do i = 1 to BookMark.rows */
  1062.  
  1063. /* did we find it? */
  1064. if found = 0 then do;
  1065.   msg.0 = 1
  1066.   msg.1 = "  That line is not marked! "
  1067.   call VMsgBox "UnMark Line", msg, 1
  1068.   return;
  1069. end;
  1070.  
  1071. /* unmark the line */
  1072. do i = found to BookMark.rows        /* move data up one row */
  1073.   nxt = i + 1
  1074.   BookMark.i.1 = BookMark.nxt.1
  1075.   BookMark.i.2 = BookMark.nxt.2
  1076. end;   /* do i = found to BookMark.rows */
  1077. BookMark.rows = BookMark.rows - 1        /* now one less row */
  1078.  
  1079. /* and return */
  1080. return;
  1081.  
  1082.  
  1083.  
  1084.  
  1085. /* ================================================================== 
  1086. ** ShowBookMark                 (Display the BookMark List)
  1087. ** ================================================================== 
  1088. */
  1089.  
  1090. ShowBookMark:
  1091.  
  1092. MarkToBook:
  1093.  
  1094. /* first, setup VRexx calls */
  1095. call CheckVRexx;
  1096.  
  1097. /* make sure that at least one line has been entered */
  1098. if BookMark.rows = 0 then do;
  1099.   msg.0 = 1
  1100.   msg.1 = "  No lines marked "
  1101.   call VMsgBox "BookMark", msg, 1
  1102.   return;
  1103. end;
  1104.  
  1105. /* show it */
  1106. button = VTableBox("BookMark List", BookMark, 1, 75, 10, 3)
  1107. if button = "CANCEL" then return;
  1108.  
  1109. /* go to the selected line */
  1110. temp1 = BookMark.vstring
  1111. temp2 = BookMark.temp1.1
  1112. Cursor   = 11;    
  1113. CurrLine = temp2 - 10;
  1114. if CurrLine < 1 then do;
  1115.   CurrLine = 1;
  1116.   Cursor   = temp2;
  1117. end;
  1118. call DisplayData;
  1119.  
  1120. /* and return */
  1121. return;
  1122.  
  1123.  
  1124.  
  1125.  
  1126. /* ================================================================== 
  1127. ** WriteBook               (Write marked lines to disk)
  1128. ** ================================================================== 
  1129. */
  1130.  
  1131. WriteBook:
  1132.  
  1133. call CheckVRexx;
  1134.  
  1135. if BookMark.rows = 0 then do;
  1136.   msg.0 = 1
  1137.   msg.1 = "  No Marked Lines to Write!"
  1138.   rb = VMsgBox("Write Marked Lines", msg, 1)
  1139.   return;
  1140. end;
  1141.  
  1142. /* get a filename */
  1143. button = VFileBox('Select file to write marked lines to:', '*.*', 'file')
  1144. if button = 'CANCEL' then return;
  1145. TFName = file.vstring
  1146.  
  1147. /* see if the file already exits */
  1148. rc=SysFileTree(TFName, xme, 'F', '*****','*****')
  1149. if xme.0 = 0 then signal WRITEIT2
  1150.  
  1151. /* since it already exits, prompt for desired action */
  1152. msg.0 = 3
  1153. msg.1 = "Overwrite file ["||FILESPEC("name",TFName)||"]"
  1154. msg.2 = "Append to file ["||FILESPEC("name",TFName)||"]"
  1155. msg.3 = "Abort operation (do not write)          "
  1156. msg.vstring = msg.1                    /* the default */
  1157. button = VRadioBox('File Already Exists!', msg, 1)
  1158.  
  1159. /* now take the approprite action */
  1160. if msg.vstring = msg.1 then        /* delete the old file first */
  1161.   rc = SysFileDelete(TFName)
  1162. if msg.vstring = msg.2 then 
  1163.   signal WRITEIT2            /* no action required -- will overwrite */
  1164. if msg.vstring = msg.3 then
  1165.   return;                /* changed their mind -- return */
  1166.  
  1167. /* now write the results */
  1168. WRITEIT2:
  1169. '@echo off'
  1170. do i = 1 to BookMark.rows;
  1171.   temp = BookMark.i.1
  1172.   irc=lineout(TFName, LineArray.temp);
  1173. end;
  1174. irc = Stream(TFName, 'c', 'close')
  1175.  
  1176. /* and show use that is was done */
  1177. msg.0 = 1
  1178. msg.1 = ' ' || BookMark.rows || ' Lines Written to File ' || TFName
  1179. rb = VMsgBox('Write Marked Lines', msg, 1)
  1180. return;
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187. /* ================================================================== 
  1188. ** DoHelp (Display help screens)
  1189. ** ================================================================== 
  1190. */
  1191.  
  1192. DoHelp:
  1193.  
  1194. /* first, setup VRexx calls */
  1195. call CheckVRexx;
  1196.  
  1197. /* Show help screen */
  1198.  
  1199. msg.0 = 9
  1200. msg.1 = "CURSOR MOVEMENT/SCROLLING"
  1201. msg.2 = ""
  1202. msg.3 = "  Page Up/Down            = PgUp/PgDn"
  1203. msg.4 = "  Top of Document          = Home"
  1204. msg.5 = "  Bottom of Document      = End"
  1205. msg.6 = "  Scroll                      = Up/Down"
  1206. msg.7 = "  Toggle Cursor On/Off     = C"
  1207. msg.8 = "  Goto to line number       = G"
  1208. msg.9 = "  Exit Program              = ESC"
  1209. rb = VMsgBox(ProgName"      Help - Page 1 of 5", msg, 3)
  1210. if rb = "CANCEL" then return;    /* do they want to see more? */
  1211.  
  1212. msg.0 = 7
  1213. msg.1 = "SEARCH COMMANDS"
  1214. msg.2 = ""
  1215. msg.3 = "  Perform a new Search      = S"
  1216. msg.4 = "  Go to Next Found Line      = N or +"
  1217. msg.5 = "  Go to Previous Found Line = P or -"
  1218. msg.6 = "  Write Search Results       = W"
  1219. msg.7 = "  Toggle View Found Only    = V"
  1220. rb = VMsgBox(ProgName"      Help - Page 2 of 5", msg, 3)
  1221. if rb = "CANCEL" then return;    /* do they want to see more? */
  1222.  
  1223. msg.0 = 6
  1224. msg.1 = "BOOKMARK COMMANDS"
  1225. msg.2 = ""
  1226. msg.3 = "  Mark Line to BookMark      = M"
  1227. msg.4 = "  Unmark Line from BookMark = U"
  1228. msg.5 = "  Show BookMark List         = B"
  1229. msg.6 = "  Write Marked Lines to Disk = D"
  1230. rb = VMsgBox(ProgName"      Help - Page 4 of 3", msg, 3)
  1231. if rb = "CANCEL" then return;    /* do they want to see more? */
  1232.  
  1233. msg.0 = 4
  1234. msg.1 = "OTHER COMMANDS"
  1235. msg.2 = ""
  1236. msg.3 = "  Edit document             = E"
  1237. msg.4 = "  Exit Program              = ESC"
  1238. rb = VMsgBox(ProgName"      Help - Page 4 of 5", msg, 3)
  1239. if rb = "CANCEL" then return;    /* do they want to see more? */
  1240.  
  1241. msg.0 = 10
  1242. msg.1 = "Usage:"
  1243. msg.2 = "    B [options] [filename or filespec]"
  1244. msg.3 = ""
  1245. msg.4 = "Options:   +option or -option"
  1246. msg.5 = "    s = Show cursor (OFF)"
  1247. msg.6 = "    w = Wrap long lines (OFF)"
  1248. msg.7 = "    b = kill groups of Blank lines (OFF)"
  1249. msg.8 = ""
  1250. msg.9 = "Filename:"
  1251. msg.10= "  e.g. c:\config.sys OR c:\docs\*.txt"
  1252. rb = VMsgBox(ProgName"      Help - Page 5 of 4", msg, 1)
  1253.  
  1254.  
  1255. return;
  1256. end;
  1257.  
  1258.  
  1259.  
  1260.  
  1261. /* ================================================================== 
  1262. ** Exit Code and Error Traps
  1263. ** ================================================================== 
  1264. */
  1265.  
  1266. CLEAN_E:    /* an error occured */
  1267.   ErrorFlag = "Error"
  1268.   Signal CLEANUP
  1269.  
  1270. CLEAN_EI:
  1271.   ErrorFlag = "Init"
  1272.   UsesVRexx = Yes
  1273.   signal CLEANUP
  1274.  
  1275. CLEAN_EF:
  1276.   ErrorFlag = "Failure"
  1277.   Signal CLEANUP
  1278.  
  1279. CLEAN_EH:
  1280.   ErrorFlag = "Halt"
  1281.   signal CLEANUP
  1282.  
  1283. CLEAN_ES:
  1284.   ErrorFlag = "Syntax"
  1285.   signal CLEANUP
  1286.  
  1287.  
  1288. CLEANUP:    /* normal exit */
  1289. if UsesVRexx = Yes then
  1290.    call VExit                /* clean up VRexx stuff */
  1291. FgColr    = 40                /* restore default colors */
  1292. SBgColr  = 40
  1293. RowNr   = 1
  1294. LineData = "Test Pattern"
  1295. irc=CHAROUT(,""RowNr";1H"Bright";"FgColr";"SBgColr"m"LineData""RowNr";1H");  /* set the colors to the correct default */
  1296. call SysCls
  1297. call SysCurState 'ON'            /* turn the cursor back on */
  1298. irc  = CHAROUT(,screen)        /* restore the original screen */
  1299. pos = SysCurPos(OrigRow, OrigCol)    /* and cursor position */
  1300. if ErrorFlag \= "" then 
  1301.   say "An Error Occurred. Type = " ErrorFlag
  1302. exit;
  1303.