home *** CD-ROM | disk | FTP | other *** search
- /*
- Short: A 'Head' and 'Tail' command for DOpus5.5+
- Uploader: Dave Clarke <4wd@connexus.apana.org.au>
- Author: Dave Clarke <4wd@connexus.apana.org.au>
- Type: biz/dopus/
-
- $VER: Head-Tail.dopus5 1.0b (7.7.96)
-
- An alternative to 'reading' a 500k file only to find it's the wrong one.
-
- The 'Head' function will let you display the first 10, 20, 30, or 40 lines
- of a file/s.
- The 'Tail' function will let you display the last 10, 20, 30, or 40 lines
- of a file/s.
-
- Installation:
- Stick it in your DOpus5:Modules/ directory. This will add the 'Head' and
- 'Tail' commands to the internal command set.
-
- Usage:
- Create a button, menuitem, etc, etc, like so:
-
- Function : Command Head
-
- or
-
- Function : Command Tail
-
- */
-
- parse arg portname function source dest arguments
- address value portname
- options results
-
- if function = 'init' then do
- dopus command "Head" program "Head-Tail" desc "'Display first xx lines of file'" 'source'
- dopus command "Tail" program "Head-Tail" desc "'Display last xx lines of file'" 'source'
- exit
- end
-
- lister query source path
- path = strip(result,B,'"')
- call pragma('d',path)
- lister query source selfiles stem files.
- if files.count = 0 | files.count = '' | files.count = 'FILES.COUNT' then call ERROR 'No files selected'
- "dopus request 'Number of lines to view:' 10|20|30|40|Cancel"
- if rc = 0 then exit
- else num = rc * 10
- i = 0
- do while i < files.count
- lister select source files.i off
- lister refresh source full
- if ~open('FILE',files.i,'R')then call ERROR 'Cannot open "'files.i'"'
- else
- do
- call open('output','T:head.output',W)
- call writeln('output',''||files.i||'')
- if function = 'Head' then
- do
- do k = 1 to num
- line.k = readln('FILE')
- call writeln('output',line.k)
- end
- end
- else if function = 'Tail' then
- do
- call seek 'FILE',-80 * (num),'E'
- do k = 1 while ~eof('FILE')
- line.k = readln('FILE')
- end
- j = k - 2
- first = j - num + 1
- if first <= 0 then first = 1
- do k = first to j
- call writeln('output',line.k)
- end
- end
- end
- call writeln('output','--------------------------------------------')
- call writeln('output','')
- call close 'FILE'
- i = i + 1
- end
- call close 'output'
- 'dopus read delete T:head.output'
- exit
-
- ERROR:
- parse arg error
- dopus request "'"error"'" "OK"
- exit
-