home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1995 November
/
PCWK1195.iso
/
inne
/
podstawy
/
dos
/
4dos
/
4uzytki
/
4dhs10.exe
/
CACHE-C.BTM
next >
Wrap
Text File
|
1993-12-20
|
6KB
|
284 lines
::::: cache-c.btm ::::
:::: Caches commands for use by hindsite version 1.0::::
:::: Copyright Bob Larson ::::
::: blarson@uiuc.edu 20 December 1993 ::::
:::: main ::::
*on break *goto finish
*gosub save_alias
gosub initialize
setlocal
gosub config
gosub get_internals
gosub do_aliases
gosub do_search
gosub sort
gosub finish
quit
:::: end main ::::
::::: Configuration options ::::::
::::: Cache-c will run much faster if it can use two programs,
::::: sed and a unix-type sort (with the ability to remove
::::: duplicate lines, which the ms-dos sort does not do).
::::: If you have either, set these variables to the path
::::: and name of the program. Do not point these to aliases,
::::: as aliases are disabled within this btm.
:config
::Optional: Modify this to point to your sed program, and remove "rem"
rem set _sed_prog=sed
::Required: Make this point to your sort program, with required flags,
:: if any.
set _sort_prog=sort
::Optional If the following is set to "y", an internal subroutine
:: will remove duplicate lines. Set to "n" if your sorting
:: will have already taken care of this.
set _sort_unique=y
::Optional: If you want to add executable extensions to the command cache, add
:::: them to the following line:
set exes=*.com;*.exe;*.bat;*.btm;*.doc
::: You may alos want to edit the list of internal commands found at
::: the end of this file.
return
:::: end config :::::
:::: Subroutine save_alias :::::
:::: Saves aliases then disables them.
:::: Aliases will be resored upon termination.
:save_alias
set alias_file=%@unique[%temp]
alias >! %alias_file
unalias *
return
:::: end save_alias ::::
:::: Subroutine initialize ::::
:::: Set value of %cmd_list to the file holding the list of commands.
:::: Precedence: Command line arg., preset %cmd_line, %@unique[].
:::: Value must be saved, so occurs before setlocal.
:::: Checks that file is writable, exits if not.
:::: Deletes the file if it exists, and sets local var. %_search path
:initialize
iff %# != 0 then
set cmd_list=%1
elseiff "%cmd_list" == "" then
set cmd_list=%@unique[%temp]
endiff
set fhandle=%@fileopen[%cmd_list,write]
iff "%fhandle" == "-1" then
echo Unable to create cache in file %cmd_list
goto finish
else
echo Saving commands in %cmd_list
set fhandle=%@fileclose[%fhandle]
unset fhandle
endiff
set _search_path=%path
if "%@substr[%_search_path,0,-1]" != ";" set _search_path=%_search_path;
return
:::: end initialize ::::
::::: Subroutine do_aliases :::::
::::: Caches aliases. Uses sed to:
::::: save alias name only
::::: strip "*" from alias name
::::: skip past keystroke aliases
:do_aliases
echos Caching aliases
iff "%_sed_prog" != "" then
(%_sed_prog -e "s/=.*//" -e "/%[=]^@/d" -e "s/\*//" >>! %cmd_list) <%alias_file
else
for %%entry in (@%alias_file) gosub get_aliases
endiff
echo.
return
:::: end do_aliases ::::
:::: Subroutine get_aliases ::::
:::: Same as do_aliases, but does not use ext. program "sed".
:get_aliases
set pos=0
echos .
unset alias_name >& nul
do forever
set pos=%@inc[%pos]
set _1char=%@substr["%entry",%pos,1]
iff "%_1char" == "@" then
leave
elseiff "%_1char" == "=" then
leave
elseiff "%_1char" != "*" then
set alias_name=%[alias_name]%_1char
endiff
enddo
if "%alias_name" != "" echo %alias_name >>! %cmd_list
return
:::: end get_aliases ::::
:::: Subroutine do_search ::::
:::: With each iteration calls get_path and
:::: searches dir %one_dir for executables defined in %exes
:::: Appends file %cmd_list
:do_search
do while "%_search_path" != ""
gosub get_path
if "%@substr[%one_dir,0,-1]" != "\" set one_dir=%one_dir\
echo Searching for executables in %one_dir
dir /bkm %one_dir%%exes >>! %cmd_list >&> nul
enddo
return
:::: end do_search ::::
:::: Subroutine get_path ::::
:::: Called by do_search
:::: Extracts on dir at a time from the %_search_path var.
:::: Saves value in %one_dir
:get_path
set end=%@index[%_search_path,;]
iff %end == -1 then
set one_dir=%_search_path
set _search_path=
else
set one_dir=%@substr[%_search_path,0,%end]
set _search_path=%@substr[%_search_path,%@eval[%end+1]]
endiff
return
:::: end get_path ::::
:::: Sorts command cache. Executes external sorting program
:::: If sort program cannot remove duplicates, gosubs to
:::: subroutine unique and crawls along.
:sort
echo Sorting
set foo=%@unique[%temp]
type %cmd_list | %_sort_prog >! %foo
iff "%@lower[%_sort_unique]" != "y" then
move %foo %cmd_list >& nul
else
del /q %cmd_list
set prev=%@line[%foo,0]
echos Removing duplicates
for %%curr_line in (@%foo) gosub unique
echo.
echo %prev >>! %cmd_list
del /q %foo >& nul
endiff
return
:::: end sort ::::
:::: Subroutine unique ::::
:::: Called by subroutine sort if %sort_unique == y
:unique
iff "%@trim[%prev]" != "%@trim[%curr_line]" then
echos .
echo %prev >>! %cmd_list
endiff
set prev=%curr_line
return
:::: end unique ::::
:::: Subroutine finish ::::
:::: restores aliases, deletes files, and unsets some var's
:::: Always end up here.
:finish
endlocal
*alias /r %alias_file
*del /q %alias_file >& nul
*unset /q alias_file _search_path arg skip_next _update
*echo Done!
*return
*quit
:::: end finish ::::
:::: Subroutine get_internals ::::
:::: Subset of 4dos v.5.0 internal commands
:::: edit as desired!
:get_internals
echo Caching internal commands
text >! %cmd_list
ALIAS
ATTRIB
BEEP
BREAK
CALL
CANCEL
CDD
CHCP
CHDIR
CLS
COLOR
COPY
CTTY
DATE
DEL
DELAY
DESCRIBE
DIR
DIRS
DRAWBOX
DRAWHLINE
DRAWVLINE
ECHO
ECHOS
ERASE
ESET
EXCEPT
FOR
FREE
GLOBAL
HELP
HISTORY
INKEY
INPUT
KEYSTACK
LIST
LOADBTM
LOADHIGH
LOG
MEMORY
MKDIR
MOVE
PAUSE
PROMPT
REBOOT
RENAME
RMDIR
SCREEN
SCRPUT
SELECT
TIMER
TRUENAME
TYPE
UNALIAS
UNSET
VERIFY
VSCRPUT
endtext
return