home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1995 November
/
PCWK1195.iso
/
inne
/
podstawy
/
dos
/
4dos
/
4uzytki
/
4dtnt.exe
/
STRING.ZIP
/
BUMP.BTM
next >
Wrap
Text File
|
1991-10-29
|
2KB
|
113 lines
if "%1" == "" .or. "%2" == "" .or. "%[%2]" == "" goto help
set $foo=%@upper[%1]
set $wstr=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
iff %$foo = A then ^ gosub alpha
elseiff %$foo = B then ^ gosub binary
elseiff %$foo = O then ^ gosub octal
elseiff %$foo = H then ^ gosub hex
elseiff %$foo = D then ^ gosub dec
elseiff %$foo = N then ^ gosub an
elseiff %$foo gt 1 .and. %$foo lt 37 then ^ gosub base
else goto help
endiff
iff %$val ne 0 then^unset %2 ^ gosub cleanup ^ goto helpval
else set %2=%$foo ^gosub cleanup^quit 0
endiff
quit
:cleanup
rem unset $foo $wstr $val $max >& nul
return
:alpha
set $max=25
set $wstr=%@substr[%$wstr,10,26]
gosub bumpit
return
:binary
set $max=1
gosub bumpit
return
:octal
set $max=7
gosub bumpit
return
:hex
set $max=15
gosub bumpit
return
:dec
set $max=9
gosub bumpit
return
:an
set $max=35
gosub bumpit
return
:base
set $max=%@eval[%$foo-1]
gosub bumpit
return
:bumpit
gosub validate
if %$val ne 0 return
set $foo=%@upper[%[%2]]
set $i=%@len[%$foo]
set $j=%@eval[%$i-1]
set $k=%$j
:bumploop
set $front=
if %$j gt 0 set $front=%@substr[%$foo,0,%$j]
set $targ=%@substr[%$foo,%$j,1]
set $rear=
if %$j lt %$k set $rear=%@substr[%$foo,%@eval[%$j+1],%@eval[%$k-%$j]]
set $l=%@index[%$wstr,%$targ]
iff %$l lt %$max then ^ set $targ=%@substr[%$wstr,%@eval[%$l+1],1]^set $j=0
else set $targ=%@substr[%$wstr,0,1]
endiff
set $foo=%[$front]%[$targ]%[$rear]
if %$j gt 0 (set $j=%@eval[%$j-1]^goto bumploop)
rem unset $i $j $k $l $front $rear $targ >& nul
return
:validate
set $i=0
:valloop
set $val=%@index[%$wstr,%@substr[%[%2],%$i,1]]
if %$val lt 0 .or. %$val gt %$max (set $val=%$max^return)
set $i=%@eval[%$i+1]
iff %$i lt %@len[%[%2]] then ^ goto valloop
else set $val=0^return
endiff
return
:helpval
echo Invalid character detected.
echo .
goto help
:help
echo Usage BUMP mode var
echo
echo ! !
echo ! Any environment variable of the correct type
echo A=alpha [A-Z]
echo B=binary [0-1]
echo D=decimal [0-9]
echo H=hex [0-F]
echo N=alph/num [0-9,A-F]
echo O=octal [0-7]
echo [2-36] [0-(n-1)]
echo New value returned in var
echo Carry propagates left, overflow is ignored
quit 4