home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1995 November
/
PCWK1195.iso
/
inne
/
podstawy
/
dos
/
4dos
/
4uzytki
/
4dhs10.exe
/
HS.BTM
< prev
Wrap
Text File
|
1993-12-20
|
6KB
|
220 lines
:::: hindsite version 1.0 ::::
:: Copyright Bob Larson ::
:: blarson@uiuc.edu ::
:: 20 December 1993 ::
::::: Main ::::
*on break *goto clean_up
@setdos /v0
setlocal
unalias *
::: The following line is all the configuration required.
::: Modify to point to the location of your grep program.
::: The -i flag makes grep searches case insensitive.
set grep_prog=grep -i
gosub check_0
iff "%@substr[%&,0,1]" == "!" then
:::: history recall
gosub check_hist
gosub get_hist
else
:::: command completion
gosub check_cc
gosub parse_cc
gosub wildcards
gosub search_commands
endiff
gosub clean_up
quit
:::: end main ::::
:::: subroutine check_0 ::::
:::: Checks for 4dos ver.5, kstack.com loaded, 1 or more command
:::: line arguments.
:check_0
iff %_4ver LT 5 .or. %_kstack == 0 then
echo hindsite requires 4dos version 5.0 or greater and
echo requires that kstack.com is loaded.
echo 4dos version detected: %_4ver
echo kstack status: %_kstack
echo (1=loaded, 0=not loaded)
goto clean_up
elseiff %# == 0 then
echo No arguments detected
goto clean_up
endiff
return
:::: end check_0 ::::
:::: Subroutine check_hist ::::
:::: Called by main. Gets input source for history recall.
:check_hist
iff "%_hlogfile" == "" then
set hist_in=%@unique[%temp]
history >! %hist_in
set del_me=%hist_in
else
set hist_in=%_hlogfile
endiff
return
:::: end check_hist ::::
:::: subroutine check_cc ::::
:::: Called by main for command completion.
:::: checks for %cmd_list and file it points to ::::
:check_cc
iff "%cmd_list" == "" then
echo Environment variable %%cmd_list not set
echo Please run cache-c.btm [cmd_file] first
goto clean_up
elseiff not exist %cmd_list then
echo File %cmd_list not found
echo Please run cache-c.btm [cmd_file] first
goto_clean_up
endiff
return
:::: end check_cc ::::
:::: subroutine parse_cc ::::
:::: Called by main for command completion.
:::: Splits command line into parts. %_2complete holds the
:::: original command without path or extention, %_tail holds the
:::: rest of the command line, if present. If path is specified,
:::: use file comp. window instead of cache
:parse_cc
set _2complete=%[1]
set _tail=%2& >& nul
:::: if a path is specified, use the file completion pop-up
iff "%@path[%1]" != "" then
set result=%@path[%1]
set key_tail=home f7
gosub clean_up
endiff
return
:::: end parse_cc ::::
:::: subroutine wildcards ::::
:::: Called by main for cc. Checks for wildcards and extensions.
:::: Translates wildcards and to equivilent grep characters.
:::: Escapes "."
:wildcards
iff "%@index[%_2complete,*]" == "-1" .and. "%@index[%_2complete,?]" == "-1" then
if "%@index[%_2complete,.]" == "-1" set _2grep=%_2complete
else
:::: %_2grep must be modified for grepping if %2_complete
:::: contains any "*", "?" , or "." chars:
:::: * -> .*
:::: ? -> .
:::: . -> \.
set pos=%@eval[0-1]
do until "%pos" == "%@len[%_2complete]"
set pos=%@inc[%pos]
set letter=%@substr[%_2complete,%pos,1]
iff "%letter" == "?" then
set _2grep=%[_2grep].
elseiff "%letter" == "*" then
set _2grep=%[_2grep].*
elseiff "%letter" == "." then
set _2grep=%[_2grep]\.
else
set _2grep=%[_2grep]%[letter]
endiff
enddo
endiff
return
:::: end wildcards ::::
:::: subroutine search_commands ::::
:::: Greps the %cmd_list file for lines matching
:::: %_2grep at the beginning of the line (%=^) only.
:::: Output writes to file %short_list
:search_commands
set short_list=%@unique[%temp]
%[grep_prog] %[=]^%[_2grep] %cmd_list >>! %short_list >&> nul
:::: Display %@select window of file %short_list if # lines
:::: in %short_list >= 1.
:::: if # lines = 0, only 1 command matched, return it.
:::: if # lines = -1, no commands matched, set %key_tail to
:::: pop up file window on exit
:::: Selected command stored in %result
set lines=%@lines[%short_list]
iff "%lines" == "-1" then
set result=%_2complete
beep
echo Hindsite: No match
set key_tail=home f7
elseiff %lines == 0 then
set result=%@word[0,%@line[%short_list,0]]
else
:::: pop up the cache window
set lines=%@eval[4+%lines]
if %lines GT %_rows set lines=%_rows
set result=%@select[%short_list,1,40,%lines,80,Commands]
iff "%result" == "" then
:::: user escaped, pop up file window on exit
set result=%_2complete
set key_tail=home f7
endiff
endiff
return
:::: end search_commands ::::
:::: subroutine get_hist :::
:::: Called by main for history recall
:get_hist
set _tail=%2& >& nul
iff "%@word[0,%&]" == "!" then
pause
beep %+ beep
echo Hindsite: Improper Usage
elseiff "%@substr[%&,0,2]" == "!!" then
set recall=%@line[%hist_in,%@dec[%@lines[%hist_in]]]
else
set short_list=%@unique[%temp]
set _2grep=%@substr[%1,1]
%[grep_prog] %[=]^%[_2grep] %hist_in >>! %short_list >&> nul
set lines=%@lines[%short_list]
iff "%lines" == "-1" then
beep
echo Hindsite: Event not found
else
set recall=%@line[%short_list,%lines]
endiff
endiff
set result=%recall
return
:::: end get_hist ::::
:::: subroutine clean_up ::::
:::: Gives the selected command and the original commmand line tail
:::: to keystack. %key_tail is either blank or contains
:::: "home f7" to pop up file window
:clean_up
del /q %short_list del_me >& nul
iff "%@substr[%result,1,-2]" == "**" then
set result=%@substr[%result,0,%@eval[%@len[%result]-2]]
elseiff "%@substr[%result,0,-1]" == "*" then
set result=%@substr[%result,0,%@eval[%@len[%result]-1]]
endiff
keystack "%result %_tail" %key_tail
endlocal
*quit