home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / FileMover / Dopus5 / DC-OP55B.LZX / Opus5 / modules / Head-Tail.dopus5 < prev    next >
Encoding:
Text File  |  1996-07-07  |  2.4 KB  |  92 lines

  1. /*
  2. Short:    A 'Head' and 'Tail' command for DOpus5.5+
  3. Uploader: Dave Clarke <4wd@connexus.apana.org.au>
  4. Author:   Dave Clarke <4wd@connexus.apana.org.au>
  5. Type:     biz/dopus/
  6.  
  7. $VER: Head-Tail.dopus5 1.0b (7.7.96)
  8.  
  9. An alternative to 'reading' a 500k file only to find it's the wrong one.
  10.  
  11. The 'Head' function will let you display the first 10, 20, 30, or 40 lines
  12. of a file/s.
  13. The 'Tail' function will let you display the last 10, 20, 30, or 40 lines
  14. of a file/s.
  15.  
  16. Installation:
  17. Stick it in your DOpus5:Modules/ directory.  This will add the 'Head' and
  18. 'Tail' commands to the internal command set.
  19.  
  20. Usage:
  21. Create a button, menuitem, etc, etc, like so:
  22.  
  23. Function : Command    Head
  24.  
  25. or
  26.  
  27. Function : Command    Tail
  28.  
  29. */
  30.  
  31. parse arg portname function source dest arguments
  32. address value portname
  33. options results
  34.  
  35. if function = 'init' then do
  36.     dopus command "Head" program "Head-Tail" desc "'Display first xx lines of file'" 'source'
  37.     dopus command "Tail" program "Head-Tail" desc "'Display last xx lines of file'" 'source'
  38.     exit
  39.     end
  40.  
  41. lister query source path
  42. path = strip(result,B,'"')
  43. call pragma('d',path)
  44. lister query source selfiles stem files.
  45. if files.count = 0 | files.count = '' | files.count = 'FILES.COUNT' then call ERROR 'No files selected'
  46. "dopus request 'Number of lines to view:' 10|20|30|40|Cancel"
  47. if rc = 0 then exit
  48.   else num = rc * 10
  49. i = 0
  50. do while i < files.count
  51.   lister select source files.i off
  52.   lister refresh source full
  53.   if ~open('FILE',files.i,'R')then call ERROR 'Cannot open "'files.i'"'
  54.   else
  55.     do
  56.       call open('output','T:head.output',W)
  57.       call writeln('output',''||files.i||'')
  58.       if function = 'Head' then
  59.         do
  60.           do k = 1 to num
  61.             line.k = readln('FILE')
  62.             call writeln('output',line.k)
  63.           end
  64.         end
  65.       else if function = 'Tail' then
  66.         do
  67.           call seek 'FILE',-80 * (num),'E'
  68.           do k = 1 while ~eof('FILE')
  69.             line.k = readln('FILE')
  70.           end
  71.           j = k - 2
  72.           first = j - num + 1
  73.           if first <= 0 then first = 1
  74.           do k = first to j
  75.             call writeln('output',line.k)
  76.           end
  77.         end
  78.     end
  79.   call writeln('output','--------------------------------------------')
  80.   call writeln('output','')
  81.   call close 'FILE'
  82.   i = i + 1
  83. end
  84. call close 'output'
  85. 'dopus read delete T:head.output'
  86. exit
  87.  
  88. ERROR:
  89. parse arg error
  90. dopus request "'"error"'" "OK"
  91. exit
  92.