home *** CD-ROM | disk | FTP | other *** search
- \ VIEW.SEQ Viewing code for ZF. by Tom Zimmer
-
- variable viewlen
-
- : >VIEWLINE ( n1 --- ) \ move to line n1 of currently open file.
- dup >r 0 shndl @ movepointer
- inlen off errorline off
- r> loadline ! ;
-
- : <viewlines> ( n1 n2 --- )
- loadline @ >r viewlen off
- swap 0
- do lineread dup c@ 0= if drop leave then
- cr count 2- 0 max
- i 3 pick =
- if >attrib2 type >norm \ underline it.
- else type 77 #OUT @ - QSPACES
- then outbuf c@ viewlen +!
- loop drop cr r> loadline ! ;
-
- : VIEWLINES ( n1 n2 --- ) \ n1 lines to view, n2 line to underline.
- >rev shndl @ count type >norm <viewlines> ;
-
- : NAME>PAD ( A1 --- PAD )
- >r r@ ys: ?cs: pad r> yc@ 31 and 1+ cmovel \ move name
- pad c@ 31 and pad c! \ clip count
- pad count + 1- dup c@ 127 and swap c! \ mask last ch
- PAD ;
-
- : ?prepend.vpath ( a1 --- a1 )
- >r r@ 3 + c@ ascii \ = \ ? already have path
- if r> exit then \ then leave
- r@ count viewpath count + swap cmove
- r@ c@ viewpath c@ + \ total length
- dup r@ c! \ to a1
- viewpath 1+ r@ 1+ rot cmove \ move data to a1
- viewpath count + off \ erase extra viewpath
- r> ; \ return a1
-
- comment:
- : >viewfile ( cfa --- offset a1 ) \ returns the string name in PAD
- filelist \ of the file containing cfa as a1
- begin @ 2dup u> until \ step to proper file name.
- SWAP >view y@ \ Also returns offset to source def.
- SWAP BODY> >NAME name>pad ?prepend.vpath ;
- comment;
-
- : files_set ( --- )
- ['] files >body HERE 500 + #THREADS 2* CMOVE ;
-
- : 1file ( --- false | nfa )
- HERE 500 + #THREADS LARGEST DUP
- if DUP L>NAME >r Y@ SWAP ! r>
- else nip
- then ;
-
- 0 constant maxname
- 0 constant maxcfa
-
- : >viewfile ( cfa --- offset a1 )
- >r files_set 0 =: maxcfa 0 =: maxname
- begin 1file dup
- while r@ over name> u>
- if dup name> maxcfa u>
- if dup =: maxname
- dup name> =: maxcfa
- then
- then drop
- repeat drop r> >view y@
- maxname name>pad ?prepend.vpath ;
-
- : <VIEW> ( a1 --- f1 ) \ VIEW the name specified by a1 the cfa
- >viewfile ( --- offset f1 )
- $hopen dup 0=
- if swap dark cr
- >viewline 17 0 viewlines \ show 17 lines from file.
- else nip
- then ;
-
- variable foundit
-
- : <HELP> ( a1 --- f1 ) \ Show the HELP for a word specified by a1
- >viewfile >r drop
- " HLP" ">$ r@ $>ext
- r> $hopen dup 0=
- if inlen off 0.0 seek loadline off
- ." Looking..." foundit off
- 8000 1
- do lineread c@ 0= ?leave
- bl outbuf count + 2- c!
- \ have at least 1 blank at end of line.
- here count outbuf 1+ swap 1+ caps-comp 0=
- if dark cr ." Line " i u. ." of "
- loadline @ >viewline 17 0 viewlines
- foundit on leave
- then outbuf c@ loadline +!
- loop foundit @ 0=
- if ." ..Sorry, no information available"
- then cr
- then ;
-
- : .VIEWHELP ( --- )
- dark
- cr cr 24 spaces >rev ." HELP ME GET STARTED! " >norm
- cr cr
- ." To obtain help on a particular word, type: HELP <wordname> <enter>" cr
- ." To see the source code for a word, type: VIEW <wordname> <enter>" cr
- ." To find out what commands are available, type: WORDS <enter>" cr
- ." (space pauses, ESC stops list)" cr
- ." To find out which words contain a" cr
- ." particular letter sequence, type: WORDS <letters> <enter>" cr
- ." To see a decompiled source for a word, type: SEE <wordname> <enter>" cr
- ." To open a file, use VIEW above, or type: OPEN <filename> <enter>" cr
- ." To edit the currently open file, type: ED <enter>" cr
- ." (press ESC to leave the editor)" cr
- ." To create a file, or select a file to edit, type: SED <enter>" cr
- cr
- ." Type the following command sequence for a couple of examples: cr
- cr
- 10 spaces ." OPEN INTRO <enter>" cr
- 10 spaces ." L <enter>" cr
- cr
- ." See the accompanying .TXT files for further descriptions of FF." cr ;
-
- : VIEW ( | name --- ) \ VIEW is followed on the same line by name.
- >in @ span @ 1- > \ if nothing following command
- if .viewhelp \ display the help screen
- else ' <view>
- if cr ." File " .file ." is not available."
- then
- then ;
-
- ' view alias LL ( | name --- ) \ LL is a pseudonym for VIEW
-
- : HELP ( | name --- ) \ VIEW is followed on the same line by name.
- >in @ span @ 1- > \ if nothing following command
- if .viewhelp \ display the help screen
- else ' <help>
- if cr ." File " .file ." is not available."
- then
- then ;
-
- : ?fileopen ( --- ) \ Verify a file is open.
- shndl @ >hndle @ 0<
- abort" A file MUST be open to perform this operation." ;
-
- : L ( --- ) \ display 18 lines starting at current
- ?fileopen
- dark cr \ loadline marker.
- loadline @ >viewline
- 18 -1 viewlines ;
-
- : LIST ( n1 --- ) \ n1 is the line number to list from
- ?fileopen
- >line L ;
-
- : LOAD ( n1 --- ) \ n1 is the line number to load from
- ?fileopen
- >line \ move to line n1
- cr ." Loading.." <load> ;
-
- : +lines ( n1 --- ) \ move forward n1 lines in the current file.
- loadline @ >viewline
- 0 swap 0
- ?do lineread c@ + outbuf c@ 0= ?leave
- loop loadline +! ;
-
- : N ( --- ) \ go forward 16 lines and display 18 lines.
- ?fileopen
- 16 +lines L ;
-
- : -1line ( --- ) \ backup 1 line from current loadline
- loadline @ dup 0> swap 256 - swap
- if 0 max
- then 0 shndl @ movepointer
- 0 ( inbuf ) 256 loadline @ dup 0>
- if min else drop then
- shndl @ INBSEG EXHREAD inlen !
- inlen @ 0 ( inbuf ) over 2- 0 max bounds swap
- ?do INBSEG i c@L 10 = \ is char an LF
- if drop ( inbuf ) inlen @ ( + ) i 1+ -
- leave
- then
- -1 +loop negate loadline +! ;
-
- : -lines ( n1 --- ) \ backup n1 lines in the current file.
- 0
- ?do -1line
- loop ;
-
- : B ( --- ) \ backup 16 lines in current file and
- ?fileopen
- 16 -lines L ; \ display 18 lines.
-
-