
program extractor4;

_directive_1_

uses
  Classes, SysUtils,
  IOUtils,
  FLRE, FLREUnicode;
_comment_1_

function SubStr(const aSource: string; aStart: integer; aEnd: integer = MAXINT): string;
begin
  result := Copy(aSource, aStart, aEnd - aStart + 1);
end;

var
  txt: string;
  i, j, k: integer;
  data: TStringList;
  re: TFLRE;

procedure Extraction(var aCount: integer; const aType: string);
begin
  Inc(aCount);
  data.Append(Format(_literal_1_, [aType, aCount, SubStr(txt, j, k)]));
  txt := Format(_literal_2_, [SubStr(txt, 1, j - 1), aType, aCount, SubStr(txt, k + 1)]);
end;

type
  TReplacement = class
    function Callback(const aInput: PFLRERawByteChar; const aCaptures: TFLRECaptures): TFLRERawByteString;
  end;

function TReplacement.Callback(const aInput: PFLRERawByteChar; const aCaptures: TFLRECaptures): TFLRERawByteString;
begin
  with aCaptures[0] do result := FLREPtrCopy(aInput, Start, Length);
  result := data.Values[result];
end;

var
  c: char;
  l: integer;
  d: boolean;
  
  _comment_2_
  _comment_3_
  _comment_4_
  _comment_5_
  _comment_6_
  _comment_7_
  _comment_8_
  
  ccount, lcount, dcount: integer;
  
begin
  data := TStringList.Create;
  
  if (ParamCount = 1) and FileExists(ParamStr(1))then
    txt := TFile.ReadAllText(ParamStr(1))
  else
    txt := TFile.ReadAllText(_directive_2__literal_3__directive_3__literal_4__directive_4_);

  i := 1;
  j := 0;
  k := 0;

  c := #0;
  l := 0;
  d := FALSE;
  
  ccount := 0;
  lcount := 0;
  dcount := 0;
  
  while i <= Length(txt) do
  begin
    if c <> #0 then
    begin
      if ((c = _literal_5_) and (txt[i] = _literal_6_))
      or ((c = _literal_7_) and (txt[i] = _literal_8_) and (txt[i - 1] = _literal_9_))
      or ((c = _literal_10_) and (i < Length(txt)) and (txt[i + 1] in [#10, #13])) then
      begin
        k := i;
        
        Extraction(ccount, _literal_11_);
        
        c := #0; _comment_9_
        i := j - 1;
      end;
    end else

      if l <> 0 then
      begin
        if txt[i] = _literal_12_ then
        begin
          Inc(l);
          if (l mod 2 = 0) and (i < Length(txt)) and (txt[i + 1] <> _literal_13_) then
          begin
            k := i;
            
            Extraction(lcount, _literal_14_);
            
            l := 0; _comment_10_
            i := j - 1;
          end;
        end;
      end else

        if d then
        begin
          if txt[i] = _literal_15_ then
          begin
            k := i;
            
            Extraction(dcount, _literal_16_);
            
            d := FALSE; _comment_11_
            i := j - 1;
          end;
        end else

          if ((txt[i] = _literal_17_) and (i < Length(txt)) and (txt[i + 1] <> _literal_18_))
          or ((txt[i] = _literal_19_) and (i < Length(txt)) and (txt[i + 1] = _literal_20_))
          or ((txt[i] = _literal_21_) and (i < Length(txt)) and (txt[i + 1] = _literal_22_)) then
          begin
            j := i;
            c := txt[i]; _comment_12_
          end else

            if txt[i] = _literal_23_ then
            begin
              j := i;
              l := 1; _comment_13_
            end else

              if ((txt[i] = _literal_24_) and (i < Length(txt)) and (txt[i + 1] = _literal_25_)) then
              begin
                j := i;
                d := TRUE; _comment_14_
              end;

    Inc(i);
  end;

  TFile.WriteAllText(_literal_26_, txt);
  
  data.SaveToFile(_literal_27_);
  
  re := TFLRE.Create(_literal_28_, []);
  with TReplacement.Create do
  begin
    txt := re.ReplaceCallback(txt, Callback);
    Free;
  end;
  re.Free;

  TFile.WriteAllText(_literal_29_, txt);

  data.Free;
end.
