home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac / 4dcat10.zip / 4DCAT.BTM next >
Text File  |  1996-03-06  |  6KB  |  195 lines

  1. : 4DCAT.BTM is a floppy catalog program by Hans Tenkink. Email: tenkink@nfra.nl
  2. : First published in march 1996. Developed for 4DOS v. 5.5
  3.  
  4. echo.
  5. echo.
  6. setlocal
  7. unalias *
  8. unset /q ans astation col db dbak dnrs disk diska diskb disks dtmp h_db ser sern station text1
  9.  
  10. :  Define the filenames (rename them at will)
  11. set db=database.txt
  12. set dtmp=database.tmp
  13. set dbak=databack.txt
  14. set dnrs=database.dnr
  15.  
  16. :  Backup the datafile.
  17. copy %db %dbak /q
  18.  
  19. if %@index[%&,?] != -1 goto HELP
  20.  
  21. iff "%1"=="b" then
  22.   scrput %_row %_column %_fg on %_bg Reading disk b:
  23.   set station=1^set astation=b
  24.   :  read the disk's directory
  25.   dir /s b:>dir.tmp
  26. else
  27.   scrput %_row %_column %_fg on %_bg Reading disk a:
  28.   set station=0^set astation=a
  29.   :  read the disk's directory
  30.   dir /s a:>dir.tmp
  31. endiff
  32.  
  33. :  Read first line of dir.tmp to get the serial nr.
  34. set ser=%@trim[%@instr[54,9,%@line[dir.tmp,1]]]
  35. iff %@len[%ser]=0 then
  36. echo Please reformat this disk. (format %astation:/q/u)
  37. set sern=no
  38. goto askit
  39. else
  40. gosub getsn
  41. endiff
  42. goto end
  43.  
  44. :addlabel
  45. :  If the disk is to be added to the database it gets a new label
  46. :  Find the last label in the file dnrs
  47. gosub getdnr
  48. :  add the directory to the database
  49. gosub addisk
  50. :  Increment the disklabel number
  51. gosub putdnr
  52. goto end
  53.  
  54. :askit
  55. iff %2==r then^set ans=r
  56. elseiff %2==a then^set ans=a
  57. elseiff %1==r then^set ans=r
  58. elseiff %1==a then^set ans=a
  59. else
  60.   inkey /k"ar" Refresh or Add? r/a: %%ans
  61. endiff
  62. iff %ans==a then
  63.  goto addlabel
  64. elseiff %ans==r then
  65.   :  No disklabel is given.
  66.   :  The disk has a serial number, but it does not match.
  67.   if "%sern" != "no" echo Disk has been reformatted.
  68.   input /l4 Give disk#: %%disk
  69. : Check the input somewhat
  70.   iff %@len[%disk] gt 1 then
  71.     iff %@index[%disk,a] gt 0 then
  72.       goto refresh
  73.     elseiff %@index[%disk,b] gt 0 then
  74.       goto refresh
  75.     endiff
  76.   endiff
  77.   echo Please finish with 'a' or 'b' (e.g. 22a)
  78. endiff
  79. echo No action taken.
  80. goto end
  81.  
  82. :getsn
  83. :  Read database to find the same serialnr. and pass the disklabel to disk.
  84. ffind /kmt"%ser" %db|set disk=%@word[0,%@line[con,0]]
  85. iff %disk ne **EOF** then
  86.   echo Volume nr. %ser is already present
  87.   echo This should be disk %disk
  88.   goto refresh
  89. endiff
  90. :  The disk read has a volumenumber but it can not be found in the database.
  91. :  The disk probably must be added, but it might have been reformatted.
  92. :  Ask the user what he wants.
  93. echo This disk volume is not found in the database.
  94. goto askit
  95. return
  96.  
  97. :refresh
  98. :  Delete all items with disklabel %disk
  99. :  Search only in the first four columns. (numbers range from 1 to 999 + a/b)
  100. fgrep -xs0 -i1,4 '%disk' %db && (echo ERROR disklabel %disk NOT found.^goto end)
  101. :  Do an inverse search.
  102. fgrep -xsv -i1,4 '%disk' %db>%dtmp
  103. :  In the above statement we cannot redirect the output to the inputfile
  104. :  We have to use an intermediate file '%dtmp'
  105. :  Redirecting the output to the input works only for small filesizes.
  106. :  (Up to about 10k)
  107. copy %dtmp %db /q
  108. gosub addisk
  109. set text1=`Data of disk `
  110. set text2=`refreshed `
  111. gosub tellem
  112. del %dtmp /q
  113. : The next line sorts the database in volumelabel order.
  114. : Just remove the rem statement if you want that. (rpsort permits redirection of
  115. : outputfile to inputfile.)
  116. rem rpsort/q /+1:4 database.txt database.txt
  117. goto end
  118.  
  119. :getdnr
  120. :  Get the disknumbers.
  121. :  Get the first word. (The format in %dnrs="na mb")
  122. set diska=%@word[0,%@line[%dnrs,0]]
  123. set diskb=%@word[1,%@line[%dnrs,0]]
  124. :  Strip the last character from the string (e.g. 55a --> 55)
  125. :  And add 1 to the number (e.g. 55 --> 56) and add the 'a' or 'b'.
  126. iff %station==0 then
  127.   set disk=%@substr[%diska,0,%@eval[%@len[%diska]-1]]
  128.   set disk=%@inc[%disk]a
  129.   set disks=%disk %diskb
  130. else
  131.   set disk=%@substr[%diskb,0,%@eval[%@len[%diskb]-1]]
  132.   set disk=%@inc[%disk]b
  133.   set disks=%diska %disk
  134. endiff
  135. return
  136.  
  137. :addisk
  138. set h_db=%@fileopen[%db,append,t]
  139. :  Don't let the '<DIR>' string (which might be present in dir.tmp) be
  140. :  interpreted as redirection.
  141. setdos /x-6
  142. do i = 0 to %@lines[dir.tmp]
  143.   set err=%@filewrite[%h_db,%@format[4,%disk] %@line[dir.tmp,%i]]
  144. enddo
  145. setdos /x0
  146. set err=%@fileclose[%h_db]
  147. return
  148.  
  149. :putdnr
  150. echo %disks>%dnrs
  151. echo %disk added to the database.
  152. set text1=`Label this disk as `
  153. set text2=
  154. gosub tellem
  155. goto end
  156.  
  157. :tellem
  158. set col=5
  159. echo.^echo.
  160. scrput %@eval[%_row-1] %@eval[%col+2] bri whi on %_bg %text1
  161. scrput %@eval[%_row-1] %@eval[%col+2+%@len[%text1]] bri yel on %_bg %disk
  162. scrput %@eval[%_row-1] %@eval[%col+2+%@len[%text1]+%@len[%@trim[%disk]]+1] bri whi on %_bg %text2
  163. drawbox %@eval[%_row-2] %col %_row %@eval[%col+2+%@len[%text1]+%@len[%text2]+%@len[%@trim[%disk]]+1] 1 %_fg on %_bg
  164. echo.
  165. return
  166.  
  167. :end
  168. : Clean up
  169. del/q dir.tmp
  170. unset /q ans astation col db dbak dnrs disk diska diskb disks dtmp ser sern station text1
  171. endlocal
  172. quit
  173.  
  174. :help
  175. text
  176. -------------------------------------------------------------------------------
  177. 4DCAT  a floppy cataloguer by Hans Tenkink.          Email:     tenkink@nfra.nl
  178. -------------------------------------------------------------------------------
  179.  
  180.  Usage:
  181.         4dcat       to catalog a disk in drive A:
  182.         4dcat b     to catalog a disk in drive B:
  183.  
  184.  
  185.  Command line parameters are: a b r
  186.  
  187.  Examples:
  188.         To ADD a disk in station A: to the database type:      4dcat [a] a
  189.         To ADD a disk in station B: to the database type:      4dcat b a
  190.         To REFRESH a disk in station A: to the database type:  4dcat [a] r
  191.         To REFRESH a disk in station B: to the database type:  4dcat b r
  192.  
  193.     (a: is the default station so you can leave it out.)
  194. endtext
  195.