{ZMIENIA KODY <13,10> NA KOD <155> W PLIKU TEKSTOWYM}
USES CRT;
CONST F1:BYTE=155;
VAR Color:BYTE;
    InFile,OutFile:File Of Byte;
    Size,I,II:LONGINT;
    ZNAK1,ZNAK2:Byte;
LABEL CONTINUE,ENDE;
BEGIN
   Color:=TextAttr;
   IF ParamCount <> 2 THEN BEGIN
      WriteLn;
      TextColor(LightRed);WriteLn('AT_EOL v1.0');
      TextColor(Yellow);Writeln('Convert codes <13,10> to code <155>');
      TextColor(Green);WriteLn('   Usage: AT_EOL <infile> <outfile>');
      TextColor(Color);WriteLn;
      Halt;
   END;
   Assign(InFile,ParamStr(1));
   Assign(OutFile,ParamStr(2));
   {$I-}Reset(InFile);{$I+}
   IF IOResult<>0 THEN BEGIN
      WriteLn;
      TextColor(LightRed);WriteLn('File ',ParamStr(1),' not found');
      TextColor(Color);WriteLn;
      Halt;
   END;
   ReWrite(OutFile);
   II:=0;
   WHILE NOT EOF(InFile) DO BEGIN
      Read(InFile,ZNAK1);
CONTINUE:
      {$I-}
      Read(InFile,ZNAK2);
      {$I+}
      IF IOResult<>0 THEN BEGIN INC(II);ZNAK2:=155;END;
      IF ((ORD(ZNAK1)=13) AND (ORD(ZNAK2)=10)) OR ((ORD(ZNAK1)=10) AND (ORD(ZNAK2)=13)) THEN BEGIN
        Write(OutFile,F1);INC(II);END
      ELSE BEGIN
        IF (ORD(ZNAK2)=13) OR (ORD(ZNAK2)=10) THEN BEGIN Write(OutFile,ZNAK1);ZNAK1:=ZNAK2;GOTO CONTINUE;END;
        Write(OutFile,ZNAK1);Write(OutFile,ZNAK2);
      END
   END;
ENDE:
   Size:=FileSize(OutFile);
   Seek(OutFile,Size-1);
   Read(OutFile,ZNAK1);
   IF ZNAK1<>155 THEN BEGIN INC(II);ZNAK1:=155;Write(OutFile,ZNAK1);END;
   Close(InFile);
   Close(OutFile);
   WriteLn;
   TextColor(LightRed);
   WriteLn('Convert is successuful');
   TextColor(White);WriteLn('Number Of Changes: ',II);
   TextColor(Color);WriteLn;
END.

