home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 31
/
CDASC_31_1996_juillet_aout.iso
/
vrac
/
4dcat10.zip
/
4DCAT.BTM
next >
Wrap
Text File
|
1996-03-06
|
6KB
|
195 lines
: 4DCAT.BTM is a floppy catalog program by Hans Tenkink. Email: tenkink@nfra.nl
: First published in march 1996. Developed for 4DOS v. 5.5
echo.
echo.
setlocal
unalias *
unset /q ans astation col db dbak dnrs disk diska diskb disks dtmp h_db ser sern station text1
: Define the filenames (rename them at will)
set db=database.txt
set dtmp=database.tmp
set dbak=databack.txt
set dnrs=database.dnr
: Backup the datafile.
copy %db %dbak /q
if %@index[%&,?] != -1 goto HELP
iff "%1"=="b" then
scrput %_row %_column %_fg on %_bg Reading disk b:
set station=1^set astation=b
: read the disk's directory
dir /s b:>dir.tmp
else
scrput %_row %_column %_fg on %_bg Reading disk a:
set station=0^set astation=a
: read the disk's directory
dir /s a:>dir.tmp
endiff
: Read first line of dir.tmp to get the serial nr.
set ser=%@trim[%@instr[54,9,%@line[dir.tmp,1]]]
iff %@len[%ser]=0 then
echo Please reformat this disk. (format %astation:/q/u)
set sern=no
goto askit
else
gosub getsn
endiff
goto end
:addlabel
: If the disk is to be added to the database it gets a new label
: Find the last label in the file dnrs
gosub getdnr
: add the directory to the database
gosub addisk
: Increment the disklabel number
gosub putdnr
goto end
:askit
iff %2==r then^set ans=r
elseiff %2==a then^set ans=a
elseiff %1==r then^set ans=r
elseiff %1==a then^set ans=a
else
inkey /k"ar" Refresh or Add? r/a: %%ans
endiff
iff %ans==a then
goto addlabel
elseiff %ans==r then
: No disklabel is given.
: The disk has a serial number, but it does not match.
if "%sern" != "no" echo Disk has been reformatted.
input /l4 Give disk#: %%disk
: Check the input somewhat
iff %@len[%disk] gt 1 then
iff %@index[%disk,a] gt 0 then
goto refresh
elseiff %@index[%disk,b] gt 0 then
goto refresh
endiff
endiff
echo Please finish with 'a' or 'b' (e.g. 22a)
endiff
echo No action taken.
goto end
:getsn
: Read database to find the same serialnr. and pass the disklabel to disk.
ffind /kmt"%ser" %db|set disk=%@word[0,%@line[con,0]]
iff %disk ne **EOF** then
echo Volume nr. %ser is already present
echo This should be disk %disk
goto refresh
endiff
: The disk read has a volumenumber but it can not be found in the database.
: The disk probably must be added, but it might have been reformatted.
: Ask the user what he wants.
echo This disk volume is not found in the database.
goto askit
return
:refresh
: Delete all items with disklabel %disk
: Search only in the first four columns. (numbers range from 1 to 999 + a/b)
fgrep -xs0 -i1,4 '%disk' %db && (echo ERROR disklabel %disk NOT found.^goto end)
: Do an inverse search.
fgrep -xsv -i1,4 '%disk' %db>%dtmp
: In the above statement we cannot redirect the output to the inputfile
: We have to use an intermediate file '%dtmp'
: Redirecting the output to the input works only for small filesizes.
: (Up to about 10k)
copy %dtmp %db /q
gosub addisk
set text1=`Data of disk `
set text2=`refreshed `
gosub tellem
del %dtmp /q
: The next line sorts the database in volumelabel order.
: Just remove the rem statement if you want that. (rpsort permits redirection of
: outputfile to inputfile.)
rem rpsort/q /+1:4 database.txt database.txt
goto end
:getdnr
: Get the disknumbers.
: Get the first word. (The format in %dnrs="na mb")
set diska=%@word[0,%@line[%dnrs,0]]
set diskb=%@word[1,%@line[%dnrs,0]]
: Strip the last character from the string (e.g. 55a --> 55)
: And add 1 to the number (e.g. 55 --> 56) and add the 'a' or 'b'.
iff %station==0 then
set disk=%@substr[%diska,0,%@eval[%@len[%diska]-1]]
set disk=%@inc[%disk]a
set disks=%disk %diskb
else
set disk=%@substr[%diskb,0,%@eval[%@len[%diskb]-1]]
set disk=%@inc[%disk]b
set disks=%diska %disk
endiff
return
:addisk
set h_db=%@fileopen[%db,append,t]
: Don't let the '<DIR>' string (which might be present in dir.tmp) be
: interpreted as redirection.
setdos /x-6
do i = 0 to %@lines[dir.tmp]
set err=%@filewrite[%h_db,%@format[4,%disk] %@line[dir.tmp,%i]]
enddo
setdos /x0
set err=%@fileclose[%h_db]
return
:putdnr
echo %disks>%dnrs
echo %disk added to the database.
set text1=`Label this disk as `
set text2=
gosub tellem
goto end
:tellem
set col=5
echo.^echo.
scrput %@eval[%_row-1] %@eval[%col+2] bri whi on %_bg %text1
scrput %@eval[%_row-1] %@eval[%col+2+%@len[%text1]] bri yel on %_bg %disk
scrput %@eval[%_row-1] %@eval[%col+2+%@len[%text1]+%@len[%@trim[%disk]]+1] bri whi on %_bg %text2
drawbox %@eval[%_row-2] %col %_row %@eval[%col+2+%@len[%text1]+%@len[%text2]+%@len[%@trim[%disk]]+1] 1 %_fg on %_bg
echo.
return
:end
: Clean up
del/q dir.tmp
unset /q ans astation col db dbak dnrs disk diska diskb disks dtmp ser sern station text1
endlocal
quit
:help
text
-------------------------------------------------------------------------------
4DCAT a floppy cataloguer by Hans Tenkink. Email: tenkink@nfra.nl
-------------------------------------------------------------------------------
Usage:
4dcat to catalog a disk in drive A:
4dcat b to catalog a disk in drive B:
Command line parameters are: a b r
Examples:
To ADD a disk in station A: to the database type: 4dcat [a] a
To ADD a disk in station B: to the database type: 4dcat b a
To REFRESH a disk in station A: to the database type: 4dcat [a] r
To REFRESH a disk in station B: to the database type: 4dcat b r
(a: is the default station so you can leave it out.)
endtext