{Mikrounit pro editor Fontana. Jeho smysl je, ze se vola jako uplne prvni
 unitka a ma tak sanci neco provest jeste pred tim, nez se zacnout
 inicializovat dalsi jednotky.
 Vyuzivam proto, aby se okamzite osetrilo volani s parametry /? /H bez toho,
 aby dalsi a komplikovanejsi jednotky delaly svoje inicializacniprocedury.}


unit FonStart;
{$INCLUDE defines.inc}
{$ASMMODE INTEL}
{$IFDEF VER2}{$CALLING OLDFPCCALL}{$ENDIF}
{$IFDEF VER3}{$CALLING OLDFPCCALL}{$ENDIF}

interface
var fon_font_adresar:string;
{v pripade pouziti parametru /L funguje jako uplna specifikace souboru, ktery
 se ma nahrat do videopameti.}


    txt_loader_mode:boolean;           {defaultne false}
    load_file_in_prg_start:boolean;    {defaultne false}


Procedure Fontana_Start_Message(s:string);

implementation
uses Dos;

Procedure Fontana_Start_Message(s:string);
begin
writeln(s);
end;

Procedure NapisNapovedu_a_skonci;
begin
writeln;
writeln('FONTANA v1.1');
writeln('Editor for bitmap fonts');
writeln('written by Laaca  (Laaca@seznam.cz');
writeln('  http://laaca.borec.cz/blocek (english)');
writeln('  http://laaca.borec.cz (czech)');
writeln;
writeln('This program can be spread under conditions of GNU GPL licence.');
writeln;
writeln('Usage:');
writeln('/?, /H    this help screen');
writeln('/A:<path for default directory with fonts>');
writeln('    In path you can use character "$" (without quotes) which is interpreted');
writeln('    as directory path to FONTANA.EXE (without trailing "\")');
writeln('Warning: Spaces in the directory names are not allowed.');
writeln;
writeln('/F:<font file in supported format>');
writeln('    Load specified file immediately after program start.');
writeln('    You can also use character "$" in the font specification.');
writeln;
writeln('/T:<font file in FV format>');
writeln('    Do not start the user interface but load FV font for current text mode.');
writeln('    Font will not be permanent but disappears in next video mode change,');
writeln('    so it will not occupy any memory and does not affect TSR chain.');
writeln('    You can also use character "$" in the font specification.');
writeln;
writeln('Examples:');
writeln('    /A:$\NEWFONTS\');
writeln('    /A:$\FONTY\TTF_fnt\');
writeln('    /A:C:\FONTS\');
writeln('    /T:$\FONTY\866\866-16.fv');
Halt(0);
end;


Procedure Zpracuj_Adresar_s_fonty(var s,c:string);
var t:string;
begin

fon_font_adresar:=Copy(s,4,255);

if fon_font_adresar[1]='$' then
   begin
   t:=c;
   if t[Length(t)]='\' then dec(t[0]);
   delete(fon_font_adresar,1,1);
   fon_font_adresar:=t+fon_font_adresar;
   end;

if fon_font_adresar[length(fon_font_adresar)]<>'\'
   then fon_font_adresar:=fon_font_adresar+'\';
end;


const error_msg = #13#10+'Invalid paramater.'+#13#10+'Run FONTANA /?';
var s,s3,cesta,jm,ko:string;
    skonci:boolean;


begin
s:=ParamStr(0);
s:=FExpand(s);
FSplit(s,cesta,jm,ko);
fon_font_adresar:=cesta+'FONTY\';
skonci:=false;
txt_loader_mode:=false;
load_file_in_prg_start:=false;
if ParamCount=0 then Fontana_Start_Message(#13#10+'Starting...')
   else begin
   skonci:=true;
   if ParamCount=1 then
      begin
      s:=ParamStr(1);
      s3:=Copy(s,1,3);
      if s[1]='-' then s[1]:='/';
      if (s='/?') or (s='/h') or (s='/H') then NapisNapovedu_a_skonci;
      if (s3='/a:') or (s3='/A:') then
         begin
         Zpracuj_Adresar_s_fonty(s,cesta);
         skonci:=false;
         end;

      if (s3='/f:') or (s3='F:') then
         begin
         Zpracuj_Adresar_s_fonty(s,cesta);
         dec(fon_font_adresar[0]);   {smazeme ukoncovaci "\"}
         load_file_in_prg_start:=true;
         skonci:=false;
         end;

      if (s3='/t:') or (s3='T:') then
         begin
         Zpracuj_Adresar_s_fonty(s,cesta);
         dec(fon_font_adresar[0]);   {smazeme ukoncovaci "\"}
         txt_loader_mode:=true;
         skonci:=false;
         end;
      end;
   end;
if skonci=true then
   begin
   Fontana_Start_Message(error_msg);
   Halt(0);
   end;
end.

