home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Boston 2
/
boston-2.iso
/
DOS
/
HILFEN
/
4DOS
/
4TNT
/
WHATYPE.DOC
< prev
next >
Wrap
Text File
|
1993-12-01
|
1KB
|
45 lines
Yet another evolution of BUMP. This is a generalization of the validation
subroutine. It returns (as errorlevel) the lowest number base for which the
input string is valid. For example, "2739847" would return errorlevel 10
because the "9" in the string means the number base is at least 10.
This can be used as a general purpose base n validation routine. For example,
if you expect hexadecimal, errorlevel must be 16 or less.
if "%1" == "" goto help
Setlocal works here because no caller variables are changed.
setlocal
Standardize character case
set $foo=%@upper[%1]
The inevitable base 36 validation string.
set $wstr=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
Initialize the loop counter and return value
set $i=0
set $r=0
:valloop
Use the index into wstr for each character as a means of validation.
set $val=%@index[%$wstr,%@substr[%$foo,%$i,1]]
If the character does not exist in wstr, the string is invalid.
if %$val lt 0 quit 99
Keep the maximum value ever found (the highest digit) in the string.
if %$r le %$val set $r=%@eval[%$val+1]
Bump the loop along and test for done.
set $i=%@eval[%$i+1]
if %$i lt %@len[%$foo] goto valloop
Return with the errorlevel set.
quit %$r
:help
echo Usage %@name[%0] string
echo Errorlevel = number base (1 - 36) of string or 99 for not valid.
quit 99