
{ *************************************************************************
  **									 **
  **  DeviceInfo  -  Version 1.0,	  (C)1992  by  Thomas Schmid     **
  **						     Im Grenzacherhof 12 **
  **   This programm is Public Domain,		     CH- 4058 Basel	 **
  **   coded 18.02.1992 in PCQ-Pascal(1.2b).                             **
  **   Gibt Info über angegebenes Device aus.				 **
  **						 Usage :		 **
  **							DeviceInfo Dfx:  **
  **									 **
  *************************************************************************
}

Program DeviceInfo;

{$I "include:libraries/dos.i"      }
{$I "include:utils/parameters.i"   }
{$I "include:exec/exec.i"          }
{$I "include:utils/stringlib.i"    }

Const
  MaxSize = 80;

Var
  MyLock	  : FileLock;
  Inf		  : InfoDataPtr;
  Ok		  : Boolean;
  Myfile	  : String;
  S, S1		  : String;
  Size, Used, Bpb : Integer;

Procedure Cls;

Begin
  WriteLn("\f   DeviceInfo V1.0 © 1992, by T.Schmid, Written in PCQ V1.2b\n");
		{ writeln("xxxxx \n") spart ein writeln !        -----^ }
End;

Procedure AsdaLaVista(warum : String ; code : Integer);

Begin
  If Inf   <> Nil Then FreeMem(Inf,SizeOf(InfoData));
  If warum <> Nil Then WriteLn("[3;32m",warum,"[0;31m");
  Exit(code);
End;


Begin
  Myfile:=AllocString(80);
  GetParam(1,Myfile);
  If strlen(Myfile) = 0 Then AsdaLaVista(" DiskInfo V1.0, © 1992 T.Schmid - Usage : DiskInfo Dfx:",0);

  Inf:=InfoDataPtr( AllocMem( SizeOf(InfoData), MEMF_PUBLIC ) );
  If Inf=Nil Then AsdaLaVista("Kein Speicher",5);

  s:=AllocString(20);		strcpy(S,"Beschreibbar");
  s1:=AllocString(20);		strcpy(S1,"Dos");

  MyLock:=Lock(Myfile,ACCESS_READ);
  If MyLock = Nil Then AsdaLaVista("Konnte Schlüssel nicht holen.",5);

  Ok:=Info(MyLock,Inf);
  Unlock(MyLock);		{ ------- Wichtig !! -------- }

  If Ok = FALSE Then AsdaLaVista("Konnte keine Info über Device holen",10);

  Bpb  := Inf^.id_BytesPerBlock;
  Size := Inf^.id_NumBlocks     * Bpb DIV 1024;
  Used := Inf^.id_NumBlocksUsed * Bpb DIV 1024;
  Cls;

  WriteLn("   Info über Device        :  [0;33m", Myfile, "[0;31m");
  WriteLn("   Grösse                  :  [0;33m", Size, " KBytes  ","[0;31m");
  WriteLn("   Belegt                  :  [0;33m", Used, " KBytes  ","[0;31m");
  WriteLn("   Frei                    :  [0;33m", Size-Used, " KBytes  ","[0;31m");
  WriteLn("   Anzahl Bytes per Block  :  [0;33m", Inf^.id_BytesPerBlock, "[0;31m");

  Case Inf^.id_DiskType of
	ID_NO_DISK_PRESENT : strcpy(S1,"Keine Disk");
	ID_UNREADABLE_DISK : strcpy(S1,"Disk nicht lesbar");
	ID_NOT_REALLY_DOS  : strcpy(S1,"Keine Dos-Disk");
	ID_KICKSTART_DISK  : strcpy(S1,"Kickstart-Disk");
  End;

  WriteLn("   Disk Type               :  [0;33m",S1,"[0;31m");
  WriteLn("   Weiche Fehler           :  [0;33m",Inf^.id_NumSoftErrors,"[0;31m");

  Case Inf^.id_DiskState of
	ID_WRITE_PROTECTED : strcpy(S,"Schreibgeschützt");
	ID_VALIDATING      : strcpy(S,"Wird Validiert");
  End;
  WriteLn("   Device Status           :  [0;33m",S,"[0;31m");

  { wichtig : }
  AsdaLaVista("\n  C U in next CF !\n",0);

End.
