
uses
  SysUtils, Classes, RegExpr;

var
  SL, SL2, SL3: TStringList;
  i: integer;
  re: TRegExpr;

type TColor = (Undefined, White, Black);

var
  c: TColor = Undefined;
  
begin
(*
  if ParamCount <> 2 then
    Exit;
  *)
  SL := TStringList.Create;
  SL2 := TStringList.Create;
  SL3 := TStringList.Create;
  re := TRegExpr.Create({'"([a-h1-8 ]+)"'}'"([a-zA-Z1-8 \-\+]+)"');
  try
    //SL.Sorted := TRUE;
    SL.LoadFromFile({ParamStr(1)}'internalbookdata.cpp');
    
    for i := 0 to Pred(SL.Count) do
    begin
      if Pos('bookBlack', SL[i]) > 0 then
        c := Black
      else if Pos('bookWhite', SL[i]) > 0 then
        c := White;
      
      if Length(SL[i]) > 0 then
        if re.Exec(SL[i]) then
          if c = White then
            SL2.Append(re.Match[1])
          else
            SL3.Append(re.Match[1])
        else
          if c <> Undefined then
            WriteLn(ErrOutput, SL[i]);
    end;
    
    SL2.SaveToFile({ParamStr(2)}'white.txt');
    SL3.SaveToFile({ParamStr(2)}'black.txt');
  finally
    SL.Free;
    SL2.Free;
    SL3.Free;
    re.Free;
  end;
end.
