(* CVT_USED.PAS -- show used chains in a GEOS files
** Copyright (c) 1995,1996 Jochen Metzinger
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2, or (at your option)
** any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*)

PROGRAM cvt_used;

USES global, errors, cvt;

VAR chain: BYTE;

PROCEDURE usage;
BEGIN
 WriteLn('CVT_USED  Version 0.3  Show the map of used chains of a GEOS file');
 WriteLn('Copyright (c) 1995,1996 Jochen Metzinger ');
 WriteLn;
 WriteLn(short_usage);
 WriteLn;
 WriteLn('  filename    GEOS file');
 HALT(1);
END; (* usage *)

PROCEDURE Init;
 VAR i, j: WORD; par: STRING;
  in_name: STRING;
BEGIN
 short_usage := 'CVT_USED [/?] filename';
 in_name := '';
 IF ParamCount = 0 THEN
  usage;
 FOR i := 1 TO ParamCount DO BEGIN
  par := ParamStr(i);
  IF (par[1] = '/') OR (par[1] = '-') THEN
   BEGIN
    IF Length(par) = 1 THEN
     FATAL('unknown option '+par);
    FOR j := 2 TO Length(par) DO
     CASE UpCase(par[j]) OF
      '?', 'H': usage;
      ELSE FATAL('unknown option '+par);
     END; (* case *)
   END
  ELSE IF in_name = '' THEN
   in_name := AddExt(par, CVT_EXT)
  ELSE
   FATAL('too many arguments');
 END; (* for *)
 IF in_name = '' THEN usage;
 cvt_open(in_name);
 WriteLn;
 Write('x 0123456789ABCDEF  <',in_name,'>');
 short_usage := '';
END; (* init *)

BEGIN (* cvt_used *)
 Init;
 FOR chain := 0 TO 127 DO BEGIN
  IF chain AND $0F = 0 THEN BEGIN
   WriteLn;
   Write(HexStr(chain SHR 4,1),' ');
  END; (* if *)
  IF cvt_size(chain) >= 0 THEN
   Write('*')
  ELSE
   Write('.');
 END; (* for *)
 WriteLn; WriteLn;
 cvt_close;
END. (* cvt_used *)
