home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1995 November
/
PCWK1195.iso
/
inne
/
podstawy
/
dos
/
4dos
/
4uzytki
/
ez-btm11.exe
/
ROU.BTM
< prev
next >
Wrap
Text File
|
1994-05-16
|
10KB
|
365 lines
@echo off
: ROU.BTM
: Library of useful routines for 4dos
: (no pretensions for anything fabulous)
: Some routines are simply small valuable utilitites, others
: are useful only as models for routines insertable in batches.
:
: Itamar Even-Zohar (itiez@plato.tau.ac.il)
: --------------------------------------
iff "%1" == "" then
if %_row ge 7 cls
echo Syntax is: ROU [option]
text
Where 'option' is one of the following:
drive extracts drive name from current full path
ready finds out if specified disk is ready
ramdisk/ram finds the first non-remote available drive/disk
extract eliminates sequence of characters from a string
filename |fn removes extension from specified filename
lines counts number of lines in specified file
inclusion checks inclusion of a character in given string
fullday gives today's completes days' name (SUN --> SUNDAY)
char reports given character's ASCII number
trail checks if specified character is a trailing character
in given string or variable
row puts specified message on desired row
eu-date|eu reorganize date in European form
ansi checks if ANSI installed
find_date|fd find date x days ago
name report computer's "name"
words reports number of "words" in variable (words %%variable)
endtext
quit
endiff
goto %1
:------------------------------------------get drive name
:drive
echo Extracts drive from current full path %_cwd
echo Drive is %@SUBSTR[%_cwd,0,2]
echo (The procedure is: %@SUBSTR[%_cwd,0,2])
quit
:-------------------------------find out if disk is ready
:ready
shift
: @READY[d:]: Returns "1" if the specified drive is ready;
: otherwise returns "0".
setlocal
iff %@ready[%1:] eq 1 then ^echo drive %@upper[%1]: is ready
else
gosub up&low
%ech
endiff
endlocal
quit
:up&low
iff %1 lt C then
set ech=echo Drive %@upper[%1]: is not ready
else
set ech=Echo Drive %@upper[%1]: does not exist
endiff
return
:-------------------------------------does ramdisk exist?
:ramdisk
:ramdrive
:ram
:: (finds the first non-remote available drive/disk)
set work=ZYXWVUTSRQPONMLKJIHGFEDC
set dr=%_lastdisk
:ramdloop
set place=%@index[%work,%dr]
if %_4ver lt 5 set n=0
if %_4ver ge 5 set n=1
iff %@removable[%dr] eq %n .and. %@cdrom[%dr] eq 0 .and. %@remote[%dr] eq 0 .and. %@ready[%dr] eq 1 then
set ramd=%dr
goto ramdname
else
set place=%@eval[%place+1]
set dr=%@substr[%work,%place,1]
endiff
if %place lt 24 goto ramdloop
:ramdname
if %_batch ge 2 quit
echo Ramdrive is: "%@upper[%ramd]:"
if %_batch lt 2 unset work dr ramd place n
quit
:------------------------eliminate a sequence from a string
:extract
:ext
: How to eliminate a sequence of characters from a string. For instance,
: if you type VAR-UTIL.ZIP, and you wish to retain the name of file only
: (without its extension): This example is only for demonstration, because
: in the particular case of filenames, 4dos provides built-in parsers:
: @filename[%1] and @ext[%1].
shift
if .%1 == . goto ext-h
setlocal
set string=%@substr[%1,0,%@eval[%@LEN[%1]-%2]]
echo The string without last %2 characters is: %@upper[%string]
endlocal
: In the above example, you retain all the characters of a string
: minus the last n characters (".", and three characters for the extension).
: This is done by getting the length of the string minus n:
: %@eval[%@LEN[%1&]-n] is the procedure for that. Once you know the
: length of the desired string, SUBSTR extracts it for you where %1
: denotes the original strings typed by you.
:
quit
:ext-h
echo This routine eliminates the last n characters from a string
echo (for parsing filenames better use the built-in variable functions
echo @filename[%1] and @ext[%1])
echo.
echo SYNTAX is:
echo ext[ract] string n
quit
:------------------------Counts number of lines in a file
:lines
:ln
: Counts number of lines in a file
:
if %_row ge 22 cls
shift
iff %#==0 then^echo USAGE: LINES filename ^quit^endiff
iff not exist %1 then^echo %@upper[%1] does not exist^quit^endiff
screen %@eval[%_row+1] 2
echo No. of lines in file %@upper[%1] is --%@eval[%@lines[%1]+1]--
rem Since @lines treats line No 1 as '0', it is necessary to add '1'
rem to the sum total.
drawbox %@eval[%_row-2] 0 %@eval[%_row] 70 1 whi on bla
quit
:-----------------------------check inclusion in a string
:inclusion
:inc
rem A procedure for checking inclusion of a character in a given string
shift
iff "%1"=="" .Or. "%2"=="" then ^
echo No character or string specified^
quit
Else
goto seq
endiff
:seq
setlocal
set sequence=%2
iff %@index[%sequence,%1] ge 0 then
echo %@upper[%1] is included in the %@index[%sequence,%1] position in %@upper["%sequence"]
quit
else
echo %@upper[%1] is NOT included in %@upper["%sequence"]
endiff
quit
:-----------------------------------completes days' names
:fullday
:day
@echo off
echo.
setlocal
set today=%@upper[%_DOW]
iff %today==SUN then ^ set today=SUNDAY ^
elseiff %today==MON then ^ set today=MONDAY^
elseiff %today==TUE then ^ set today=TUESDAY^
elseiff %today==WED then ^ set today=WEDNESDAY^
elseiff %today==THU then ^ set today=THURSDAY^
elseiff %today==FRI then ^ set today=FRIDAY^
elseiff %today==SAT then ^ set today=SATURDAY^
endiff
echo Today is %today
endlocal
quit
:-------------------------Finding character code (number)
:char
@echo off
shift
rem Informs about the ASCII number of a character,
rem distinguishing between "alphabetic" and "non-alphabetic"
rem characters.
rem USAGE: CHAR [character]
setlocal
iff not "%1" == "" then
set k=%1
goto setchar
endiff
echo.
inkey Type desired character: %%k
:setchar
set char=%@ascii[%k]
iff %@index[%k,@] eq 0 then
goto extended_key
endiff
iff %char ge 65 .and. %char le 90 .OR. %char ge 97 .and. %char le 122 then
echo "%k" is an alphabetic character (ASCII #%char)
quit
else
echo "%k" is NOT an alphabetic character (ASCII #%char)
endiff
endlocal
quit
:
:extended_key
echo "%k" is an extended key; use this code for evaluation
endlocal
quit
:--------------------------------------trailing character
:trail
: Checks if a character is a trailing character
shift
iff "%&" == "" then echo Syntax is: TRAIL string character^
echo To check variables add "%"
echo (for example: TRAIL %variable_string character)
quit
endiff
iff "%@substr[%1,0,-1]" == "%2" then
echo "%1" contains a trailing "%2"
else
echo "%1" does not contain a trailing "%2"
endiff
quit
:----------------------------------Putting message on row
:row
: routine to put messages on specified row (line).
shift
setlocal
cls
if .%1==. (echo.^echo Syntax: ROU ROW n [text of message]^quit)
set message=%2&
if .%message==. set message=message
set rowline=%@eval[%_row+%1]
screen %@eval[%_row+%1] 0
echo The message "%message" is put on row #%rowline
: ---------remarks on alternatives:------------
: ^........^^^^ shorter texts can come here
: (scrput can be used for 'screen' for tones / colors)
: Instead of the 'echo' procedure, you can use the text-endtext.
: The row number will not work, but for actual programs it's superfluous.)
: text
: (here you can put the desired text)
: endtext
: --------------end of remarks ----------------
endlocal
quit
:-------------------------------------------European date
:eu-date
:eu
:eudate
rem extracting date in the format dd-mm-yy from mm-dd-yy
set dd=%_date
set dy=%@substr[%dd,3,2]-%@substr[%dd,0,2]-%@substr[%dd,6,2]
echo Today's date (%_date) in European form is: %dy
quit
:------------------------------------------filename only
:fn
:filename
shift
if .%1 == . goto fn-h
setlocal
set string=%@name[%1]
echo The filename without extension is: %@upper[%string]
endlocal
quit
:fn-h
echo SYNTAX is:
echo fn string
quit
:-----------------------------------------Checks ANSI----
:ansi
:isansi
:chkansi
iff %_ansi eq 0 .or. %_ansi eq no .or. %_ansi eq 2 then
echo No ansi installed
else
echo ANSI installed
quit
:-----------------------find date x days back or forwards
:find_date
:fd
shift
if .%1=. (set 1=0^goto syntax_fd)
set dd=%_date
set xx=%@date[%dd]
iff %@index[%1,+] eq 0 then
set zz=%@makedate[%@eval[%xx+%1]]
set ech=echo The date %1 days will be:
else
set zz=%@makedate[%@eval[%xx-%1]]
set ech=echo The date %1 days ago was:
endiff
%ech %zz
quit
:syntax_fd
text
SYNTAX:
fd [n|+n]
'n' stands for 'number of days'. If no '+' is preceded,
fd will calculate the number of days BACK.
endtext
quit
:------------------------------------computer's "name"---
:name
iff"%compuname"=="" then
echo This computer has been given no name
quit
else
echo This computer's name is: "%compuname"
endiff
quit
:------------------------------------reports number of "words"
: in variable (words %%variable)
:words
:: A procedure for finding out how many items ("words")
:: there are in a string
shift
set string=%1
set num=0
do forever
set wo=%@word[%num,%string]
if "%wo"=="" leave
set num=%@eval[%num+1]
enddo
echo "%String" contains %num items ("words" separated by blanks)
unset string num
quit
:--------------------
:--------------------
: (put new routine here)
:-----------------------------------------End of routines