program frcc;
{$APPTYPE CONSOLE}
uses
  SysUtils, Classes;


procedure MakeAllResources;
var
  sl, sl1: TStringList;
  curDir, resName: String;
  i: Integer;
begin
  curDir := GetCurrentDir;
  resName := '';
  for i := Length(curDir) downto 1 do
    if curDir[i] = '\' then
    begin
      resName := Copy(curDir, i + 1, 255);
      break;
    end;
  sl := TStringList.Create;
  sl1 := TStringList.Create;
  sl.LoadFromFile(curDir + '\frxrcClass.frc');
  sl1.AddStrings(sl);
  sl.LoadFromFile(curDir + '\frxrcDesgn.frc');
  sl1.AddStrings(sl);
  sl.LoadFromFile(curDir + '\frxrcExports.frc');
  sl1.AddStrings(sl);
  sl.LoadFromFile(curDir + '\frxrcInsp.frc');
  sl1.AddStrings(sl);
  sl1.SaveToFile(curDir + '\' + resName + '.frc');
  sl.Free;
  sl1.Free;
end;

procedure MakeResource(const fileName: String);
var
  i: Integer;
  curDir: String;
  sl, sl1: TStringList;
begin
  curDir := GetCurrentDir;
  sl := TStringList.Create;
  sl1 := TStringList.Create;

  sl.LoadFromFile(curDir + '\' + fileName);
  sl1.Add('{******************************************}');
  sl1.Add('{                                          }');
  sl1.Add('{             FastReport v3.0              }');
  sl1.Add('{          Language resource file          }');
  sl1.Add('{                                          }');
  sl1.Add('{         Copyright (c) 1998-2005          }');
  sl1.Add('{         by Alexander Tzyganenko,         }');
  sl1.Add('{            Fast Reports Inc.             }');
  sl1.Add('{                                          }');
  sl1.Add('{******************************************}');
  sl1.Add('');
  sl1.Add('unit ' + ChangeFileExt(fileName, '') + ';');
  sl1.Add('');
  sl1.Add('interface');
  sl1.Add('');
  sl1.Add('implementation');
  sl1.Add('');
  sl1.Add('uses frxRes;');
  sl1.Add('');
  sl1.Add('const resStr =');

  for i := 0 to sl.Count - 1 do
    sl1.Add(QuotedStr(Trim(sl[i])) + ' + #13#10 +');

  sl1.Add('''' + ''';');
  sl1.Add('');
  sl1.Add('initialization');
  sl1.Add('  frxResources.AddStrings(resStr);');
  sl1.Add('');
  sl1.Add('end.');
  sl1.SaveToFile(curDir + '\' + ChangeFileExt(fileName, '.pas'));

  sl.Free;
  sl1.Free;
end;

begin
  if CompareText(ParamStr(1), '-all') = 0 then
    MakeAllResources
  else if FileExists(ParamStr(1)) then
    MakeResource(ParamStr(1));
end.
