(* CVT_SIZE.PAS -- show sizes of 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_size;

USES global, errors, cvt;

VAR
 chain: BYTE;
 len: LongInt;

PROCEDURE usage;
BEGIN
 WriteLn('CVT_SIZE  Version 0.3  Show the chain sizes 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_SIZE [/?] 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);
 cvt_open(ParamStr(1));
 WriteLn(ParamStr(1),':');
 short_usage := '';
END; (* init *)

BEGIN (* cvt_size *)
 Init;
 FOR chain := 0 TO 126 DO BEGIN
  len := cvt.cvt_size(chain);
  IF len >= 0 THEN
   WriteLn(chain:3,': ',len);
 END; (* for *)
 cvt_close;
END. (* cvt_size *)
