(* CVT2TXT.PAS -- translate GEOS text 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 cvt2txt;

USES global, errors, geos, coding, cvt, texts;

VAR chain: ShortInt;

PROCEDURE usage;
BEGIN
 WriteLn('CVT2TXT  Version 0.3',country,'  Convert GEOS text files');
 WriteLn('Copyright (c) 1995,1996 Jochen Metzinger ');
 WriteLn;
 WriteLn(short_usage);
 WriteLn;
 WriteLn('  input       GEOS text file');
 WriteLn('  output      text output file');
 WriteLn('    /V          verbose');
 WriteLn('    /F          create output file');
 Write('    /G          german');
 IF default_code = ge_coding THEN Write(' [default]');
 WriteLn;
 Write('    /E          english');
 IF default_code = uk_coding THEN Write(' [default]');
 WriteLn;
 HALT(1);
END; (* usage *)

PROCEDURE Init;
 VAR in_name, out_name: STRING;
  i, j: INTEGER; par: STRING;
  verbose, force_file: BOOLEAN;
BEGIN
 short_usage := 'CVT2TXT [/?] input [output] [options]';
 in_name := ''; out_name := '';
 verbose := FALSE; force_file := FALSE;
 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;
      'V': verbose := TRUE;
      'F': force_file := TRUE;
      'G': SetCoding(ge_coding);
      'E': SetCoding(uk_coding);
      ELSE FATAL('unknown option '+par);
     END; (* case *)
   END
  ELSE IF in_name = '' THEN
   in_name := AddExt(par, CVT_EXT)
  ELSE IF out_name = '' THEN
   out_name := AddExt(par, '.TXT')
  ELSE
   FATAL('too many arguments');
 END; (* for *)
 IF in_name = '' THEN usage;
 IF force_file THEN BEGIN
  IF out_name <> '' THEN FATAL('too many arguments');
  out_name := GetFileName(in_name) + '.TXT';
 END; (* if *)
 cvt_open(in_name);
 short_usage := '';
 open_text(out_name, verbose);
END; (* init *)

BEGIN
 Init;
 FOR chain := 0 TO last_chain DO
  text_page(chain);
 close_text;
 cvt_close;
END. (* cvt2txt *)
