home *** CD-ROM | disk | FTP | other *** search
- \ FLOOK.SEQ File searching by Tom Zimmer
-
- ?dark
- .comment:
- Some powerful file manipulation words are now being loaded, these
- words allow printing, searching and listing the first line of
- sequential files. Here is a synopsis:
-
- FLOOK <string> <filespec#1> <filespec#2> ... to end of line
- INDEX <filespec#1> <filespec#2> ... " "
- FPRINT <filespec#1> <filespec#2> ... " "
-
- Each of the words may be followed by as many filespecs as will fit on
- a line. The filespecs will be precessed left to right. Filespecs can
- be "*.*", or "*.SEQ", or "ANYFILE", or any other filespec you want. It
- is probably not a good idea to use these words on .EXE or .COM files
- though.
-
- Here is an example of how FLOOK might be used:
-
- FLOOK <string> DF COLOR STATUS <enter>
-
- will search the files DF.SEQ, COLOR.SEQ, and STATUS.SEQ for <string>
-
- comment;
-
- >overlay
-
- only forth also editor also hidden definitions also
-
- defer donfile \ A function to do on all specified files
-
- ' noop is donfile
-
- variable fstime
-
- : .file-once ( --- )
- fstime @ 0=
- if cr .file fstime on
- then ;
-
- variable noise
-
- : searchfile ( --- )
- inlen off 0.0 seek
- fstime off noise @ if ." ." then
- 8000 1
- do ?keypause
- lineread c@ 0= ?leave
- slook.buf count outbuf count search nip
- if noise @
- if .file-once
- cr i 3 .r space
- else cr
- then outbuf count 2- type
- then
- loop fstime @ if cr then ;
-
- : searchedit ( --- )
- [ forth ]
- inlen off 0.0 seek ." ." ?cr
- 8000 1
- do ?keypause
- lineread c@ 0= ?leave
- slook.buf count outbuf count search nip
- if i loadline !
- savescr #out @ #line @ >r >r
- byte|line off
- ?readfile
- shndl @ hclose drop
- 8 scrline !
- reedit
- shndl @ memfile $>handle
- shndl @ hopen drop \ Reopen file
- restscr r> r> at
- leave
- then
- loop ;
-
- : $>tib ( a1 --- )
- count >r tib r@ cmove r@ span ! r> #tib ! >in off ;
-
- variable withname
-
- : .firstline ( --- )
- inlen off 0.0 seek
- cr lineread count 2- 0 max withname @
- if .file 20 #out @ - 0 max spaces
- 60
- else 79
- then min type
- ?keypause ;
-
- only forth also definitions editor also hidden also
-
- : fallof ( func | file_specs --- ) \ Do something to all files
- \ matching file_specs.
- is donfile \ Set function to be performed.
- begin >in @ span @ <
- while bl word \ else get the file spec
- dup 1+ c@ ascii \
- = abort" Please do not specify a path"
- dup
- exlist dup @ >r off \ Save exclude list, no excludes
- $getdir \ and read the directory files.
- r> exlist ! \ Restore exclude list
- #fls @ 0=
- if cr count type ." No matching files."
- else drop #fls @ 0
- ?do i >fadr 1+ c@ ascii . <>
- if i >fadr $hopen 0=
- if donfile
- then close ?keypause
- then
- loop
- then
- repeat cr ;
-
- : <flook> ( search_string file_specs --- )
- SAVESTATE
- >in @ span @ 1- > \ if nothing following command
- if cr ." String to LOOK for ->" query
- then bl word slook.buf over c@ 1+ 32 min cmove
- >in @ span @ 1- > \ if nothing following command
- if cr ." File spec to search ->" query
- then ['] searchfile fallof
- RESTORESTATE ;
-
- : <editall> ( search_string file_specs --- )
- SAVESTATE
- >in @ span @ 1- > \ if nothing following command
- if cr ." String to LOOK for ->" query
- then bl word slook.buf over c@ 1+ 32 min cmove
- >in @ span @ 1- > \ if nothing following command
- if cr ." File spec to search ->" query
- then ['] searchedit fallof
- RESTORESTATE ;
-
- overlay>
-
- : editall ( search_string file_specs --- ) \ edit all files containing
- ovon <editall> ovoff ;
-
- : flook ( search_string file_specs --- ) \ Search files for string
- ovon noise on <flook> ovoff ;
-
- \ : flooki ( search_string file_specs --- ) \ search, with no noise.
- \ noise off <flook> ;
-
- \ : xflook ( search_string file_specs --- ) \ Search case sensitive
- \ caps dup @ >r off flook r> caps ! ;
-
- : index ( file_spec --- ) \ Print first line of files
- ovon
- SAVESTATE
- cr cr ." **** Use SPACE to pause, and ESC to stop. ****"
- cr 3 tenths withname on
- >in @ span @ 1- > \ if nothing following command
- if " *.seq" ">$ $>tib \ substitute "*.seq"
- withname off
- then ['] .firstline fallof
- RESTORESTATE ovoff ;
-
- : fprint ( file_specs --- ) \ Print files specified.
- ovon
- SAVESTATE
- >in @ span @ 1- > \ if nothing following command
- if cr ." File spec to print ->" query
- then ['] listing fallof
- RESTORESTATE ovoff ;
-
- only forth also definitions
-