/* dACDInfo 1.2a (c) by Marcel Döring & Dirk Heß */
/* $VER: dACDiNFO 1.2a (7.6.96) (c) by Marcel Doering & Dirk Hess
*/

IF ~SHOW('LIBRARIES','rexxsupport.library') THEN DO
   IF ~ADDLIB('rexxsupport.library',10,-30,0) THEN DO
      SAY 'Kann die <rexxsupport.library> nicht öffnen!'
      EXIT(10)
   END
END

OPTIONS FAILAT 21

SIGNAL ON BREAK_C
SIGNAL ON HALT
SIGNAL ON IOERR
SIGNAL ON SYNTAX

nodata='1'
opened='0'
davor='0'

ADDRESS COMMAND 'C:Info >T:dACDInfo.tmp'

call open(out,'T:dACDInfo.cds','W')

get=open(in,'T:dACDInfo.tmp','R')
if get=0 then do
say 'Fehler beim einlesen der Devices'
exit(10)
end

do forever
data=readln(in)
if LEFT(data,Length(data)-Length(data)+2)='CD' then
call writecd(data)
if data='Volumes available:' then break
end

call cleanup

writecd:
nodata='0'
parse var data
unit=word(data,1)
size=word(data,2)
used=word(data,3)
free=word(data,4)
full=word(data,5)
errs=word(data,6)
stat=word(data,7)
name=word(data,8)
nam2=word(data,9)
nam3=word(data,10)
nam4=word(data,11)

if nam2='' then
rnam=name

if nam2~='' then
if nam3='' then
rnam=name' 'nam2

if nam3~='' then
if nam4='' then
rnam=name' 'nam2' 'nam3

if nam4~='' then
rnam=name' 'nam2' 'nam3' 'nam4

if size='No' then; if used='disk' then; if free='present' then do
writeln(out,unit'[37m Keine CD eingelegt[0m')
return
end

if exists('S:dACDiNFO.vcd') then do
call open(verb,'S:dACDiNFO.vcd','R')
   do forever
     pcd=readln(verb)
      if eof(verb) then break
        if unit=pcd then do
         call close(verb)
         return
        end

        if rnam=pcd then do
         call close(verb)
         return
        end

        if rnam':'=pcd then do
         call close(verb)
         return
        end
   end
call close(verb)
end

writeln(out,'[38m'unit'         'size'           'full'       'rnam'[0m')
return

cleanup:
call close(in)
call close(out)
call checkdata
if nodata='1' then
call noclean

if exists('S:dacdinfo.add') then do
  op=open(input,'S:dacdinfo.add','R')
    if op=0 then break
  inline=readln(input)
  if inline='vor' then
  davor='1'
  opened='1'
end

if opened='1' then
if davor='1' then
do forever
if eof(input) then break
werbung=readln(input)
say werbung
end

call open(end,'T:dacdinfo.cds','R')
say ''
say '[35mdACDiNFO 1.2a [34m(c) by Marcel Doering & Dirk Hess'
say '[36m------------------------------------------------[0m'
say '[37mLaufwerk    Groesse    Belegt(%)      Name [0m'
do forever
in=readln(end)
say in
if eof(end) then break
end

if opened='1' then
if davor='0' then
do forever
if eof(input) then break
werbung=readln(input)
say werbung
end

call close(end)
if op='1' then
call close(input)
delete('T:dacdinfo.cds')
delete('T:dacdinfo.tmp')
exit

noclean:
say ''
say '[35mdACDiNFO 1.2a [34m(c) by Marcel Doering & Dirk Hess'
say '[36m------------------------------------------------[0m'
say '[37mKeine CD`s gefunden ![0m'
delete('T:dacdinfo.cds')
delete('T:dacdinfo.tmp')
exit

checkdata:
isda=open(toast,'T:dacdinfo.cds','R')
   if isda=0 then do
      nodata='1'
      return
   end
test=readln(toast)
   if test='' then do
      nodata='1'
      return
   end
close(toast)
return

BREAK_C:
say ''
Say 'AuA !'
Say ''
exit

HALT:
Say ''
Say 'Ein nicht definierbarer Fehler ist aufgetreten, sorry.'
say ''
exit

IOERR:
Say ''
Say ' Das System hat einen Eingabe/Ausgabe-Fehler gemeldet'
Say 'Das Programm wird aus Sicherheitsgründen sofort beendet.'
Say 'Der Fehler wurde NICHT durch dACDiNFO ausgeloest !'
Say ''
exit

SYNTAX:
Say ''
Say ' Oops, es wurde ein Fehler im Programm festgestellt :-/'
Say 'Es waehre nett, wenn Du den Vorgang des Fehlers per E-Mail'
Say 'an DonDoringo@XOX.commo.mcnet.de oder Chefchen@XOX.commo.mcnet.de'
say 'schicken koenntest. Wir werden ihn dann beseitigen.'
say ''
exit
