program Ernst_OLX_Editor_Caller;

{$M $4000,$0,$0}   { 16K stack, no heap }
{$B-}

uses
    Crt, Dos, Ernst, Crc;

var
    Buffer        : string;       {Buffer tempor rio para leitura de arquivos}
    C             : byte;         {Contador tempor rio}
    F             : text;         {Arquivo Texto Tempor rio}
    TempFlag      : boolean;      {Flag boleano tempor rio}
    hdr           : text;         {Arquivo HEADER.DAT}
    ori           : text;         {Arquivo ORIGINAL}
    rep           : text;         {Arquivo REPLY}
    cfgfile       : text;         {Arquivo de configuraao EOEC.INI}
    reeditflag    : boolean;      {Reediao de mensagem, Reeditflag = TRUE}
    newflag       : boolean;      {Mensagem nova, Neflag = TRUE}
    forwardtype   : byte;         {0=no forward; 1=newarea; 2=samearea}
    Kludge        : byte;         {quantidade de Kludge lines (to, from, subj)}
    work          : string[38];   {Diret¢rio de trabalho}
    reply         : string[49];   {Arquivo REPLY, com PATH}
    original      : string[49];   {Arquivo ORIGINAL, com PATH}
    header        : string[49];   {Arquivo HEADER.DAT, com PATH}
    Reg           : boolean;      {Flag de registro}

    SeuDir        : string[38];   {do EOEC.INI: Diret¢rio dos arquivos}
    SeuEditor     : string[50];   {do EOEC.INI: Editor de textos}
    SeuEditorParam: string[50];   {do EOEC.INI: Parmetros para o editor}
    SeuHeader     : string[50];   {do EOEC.INI: Arquivo com HEADER}
    SeuHeaderArea : string[50];   {do EOEC.INI: Arquivo com HEADER}
    SeuLogo       : string[50];   {do EOEC.INI: Arquivo com assinatura}
    SeuTaglines   : string[50];   {do EOEC.INI: Arquivo com taglines}
    QuoteFix      : boolean;      {do EOEC.INI: Corrige os QUOTES?}
    Saudacao      : boolean;      {do EOEC.INI: Coloca saudaao autom tica?}
    SeuTagAsk     : boolean;      {do EOEC.INI: Pergunta se  essa a tag?}
    SeuRegLine    : string[50];   {do EOEC.INI: O que aprece depois do [REG]}
    SeuQuoteSigns : string[20];   {do EOEC.INI: Caracteres de quote}
    SeuTagSign    : string[10];   {do EOEC.INI: Prefixo de taglines}
    SeuTagUseSubj : boolean;      {do EOEC.INI: Usa o Subject na procura?}
    SeuEQWK       : boolean;      {do EOEC.INI: EQWK Compatible?}
    EOECLine      : string[20];   {'~~~ EOEC/OLX v1.6' para checagem de CRC}

    OMsgDate      : string[8];    {Mensagem original: Data}
    OMsgTime      : string[5];    {Mensagem original: Hora}
    OMsgPacket    : string[8];    {Mensagem original: Pacote onde foi encontrada}

    OMsgArea      : string[3];    {Mensagem original: N£mero da  rea}
    OMsgAreaName  : string[25];   {Mensagem original: Nome da  rea}

    OMsgFrom      : string;       {Mensagem original: From}
    OMsgFFrom     : string[25];   {Mensagem original: Primeiro nome do From}
    OMsgLFrom     : string[25];   {Mensagem original: Ultimo nome do From}
    OMsgFromHandle: string[25];   {Mensagem original: Handle do From}

    OMsgTo        : string[25];   {Mensagem original: To}
    OMsgFTo       : string[25];   {Mensagem original: Primeiro nome do To}
    OMsgLTo       : string[25];   {Mensagem original: Ultimo nome do To}
    OMsgToHandle  : string[25];   {Mensagem original: Handle do To}

    OMsgSubj      : string;       {Mensagem original: Subject}

    RMsgArea      : string[4];    {Mensagem reply: N£mero da  rea}
    RMsgAreaName  : string[13];   {Mensagem reply: Nome da  rea}

    RMsgFrom      : string[25];   {Mensagem reply: From}
    RMsgFFrom     : string[25];   {Mensagem reply: Primeiro nome do From}
    RMsgLFrom     : string[25];   {Mensagem reply: Ultimo nome do From}

    RMsgTo        : string;       {Mensagem reply: To}
    RMsgFTo       : string[25];   {Mensagem reply: Primeiro nome do To}
    RMsgLTo       : string[25];   {Mensagem reply: Ultimo nome do To}
    RMsgToHandle  : string[25];   {Mensagem reply: Handle do To}

    RMsgSubj      : string;       {Mensagem reply: Subject}

    RMsgPacket    : string[11];   {Pacote de mensagens}

    EQWKTo        : string;
    EQWKSubject   : string;


(* ---------------------------------------------------------------------- *)
procedure Logo;
    (* Logo de programado por Ernesto Baschny *)

begin

    clrscr;
    HighVideo;
    writeln('EOEC v1.6 - Ernst OLX Editor Caller');
    LowVideo;
    writeln('(c) 1994,95 por Ernesto Baschny');
    writeln;

end; {Logo}

(* ---------------------------------------------------------------------- *)
procedure ErrorMsg(Errorlevel: Byte; Error1, Error2: String);
    (* Apresenta mensagem de erro e sai com errorlevel especificado *)

begin

     writeln;
     textcolor(lightred);
     writeln('ERRO: ',Error1);
     textcolor(lightgray);
     writeln;
     if Error2 <> '' then
        writeln('ž ',Error2);
     CursorOff;
     readkey;
     CursorOn;
     halt(Errorlevel);

end;


(* ---------------------------------------------------------------------- *)
procedure Verify_Param;
    (* Verifica os parmetros passados ao programa *)

begin

    if (paramstr(1) = '/?') or (paramstr(1) = '-?') or (paramstr(1) = '?') then
    begin
         writeln('Sintaxe: EOEC <EOEC.INI> <REPLY>');
         writeln;
         writeln('Verifique o manual para conhecer o formato do arquivo <EOEC.INI>');
         writeln('<REPLY>  o arquivo de resposta passado pelo OLX');
         CursorOff;
         readkey;
         CursorOn;
         halt(1);
    end;

    if paramcount<>2 then
    begin
         writeln('Sintaxe: EOEC <EOEC.INI> <REPLY>');
         CursorOff;
         readkey;
         CursorOn;
         halt(1);
    end;

    if not FileExists(paramstr(1)) then
         ErrorMsg(1,'Nao existe o arquivo de configuraao '+paramstr(1),'');

    if not DirExists(GetPathName(paramstr(2))) then
         ErrorMsg(1,'Nao existe o diret¢rio '+GetPathName(paramstr(2)),'');

end; {Verify_Param}


(* ---------------------------------------------------------------------- *)
procedure CreateVars;
    (* Cria as vari veis de acordo com os arquivos *)

begin

    reply    := GetFileName(paramstr(2));
    work     := GetPathName(paramstr(2));
    reply    := work + reply;
    original := work + 'ORIGINAL';
    header   := work + 'HEADER.DAT';

    Reeditflag    := False;
    Newflag       := False;
    Forwardtype   := 0;
    Kludge        := 0;

    {defaults}
    Reg           := false;
    QuoteFix      := false;
    Saudacao      := false;
    SeuEQWK       := false;
    SeuTagAsk     := false;
    SeuTagUseSubj := false;

end; {CreateVars}

(* ------------------------------------------------------------------ *)
procedure INISectionFind(var cfgfile: text; sessao: string; var flag: boolean);
    (* Acha uma determinada sessao no arquivo de configuraao           *)
    (* Se for encontrada, ele deixa o ponteiro na posiao e FLAG = TRUE *)
    (* Se nao for encontrado, retorna FLAG = FALSE                      *)

var done : boolean;

begin

    flag := true;
    done := false;

    reset(cfgfile);

    Buffer := 'A';

    while (Buffer[1] <> '[') and (flag = true) do
    begin

        readln(cfgfile,Buffer);

        while (flag = true) and (done = false) do
        begin

            if Upper(copy(Buffer, 2, length(Buffer)-2)) = Upper(sessao) then
                done := true;

            if Eof(cfgfile) then
                flag := false;

            if done <> true then
                readln(cfgfile,Buffer);

        end;

    end;

end; {INISectionFind}

(* ------------------------------------------------------------------ *)
procedure INILineRead(var item, valor: string; var cfgfile: text);
    (* L uma linha do arquivo de configuraao, devolvendo o item e o valor *)
    (* Se nao houver mais itens, retorna ENDSECTION em item, valor ''       *)

var Index : byte;

begin {INILineRead}

    item  := '';
    valor := '';
    Buffer := '';

    readln(cfgfile, Buffer);
    while ((Buffer = '') or
          (Buffer[1] = ';') or
          (Buffer[1] = '#') or
          (Buffer[1] = '%')) and
          (not Eof(cfgfile)) do
              readln(cfgfile,Buffer);

    if (Buffer[1] = '[') or (Eof(cfgfile)) then
    begin
        item := 'ENDSECTION';
        valor := '';
    end;

    if (item = '') then
    begin

        Index := pos('=',Buffer);

        if Index = 0 then
             ErrorMsg(1,'Verifique se o arquivo '+paramstr(1)+' est  correto.','');

        Item := RTrim(copy(Buffer,1,Index-1));
        Valor := LTrim(copy(Buffer,Index+1,length(Buffer)-Index));

    end;

end; {INILineRead}


(* ---------------------------------------------------------------------- *)
procedure CfgRead;
    (* L configuraao do arquivo *)

var I           : Byte;    {contador para separar editor do parmetro}
    item, valor : String;  {item e valor da pr¢xima linha do EOEC.INI}
    UserCRC     : longint;
    RegCode1    : string[1];
    RegCode2    : string[4];
    RegCode3    : string[1];
    RegID       : string[6];    {Registration Code}
    RegName     : string[50];   {Registration Name}


begin {Main - CfgRead}

    writeln('ž Lendo configuraao [EOEC]');

    INISectionFind(cfgfile,'EOEC',Tempflag);

    if Tempflag = false then
         ErrorMsg(1,'Nao foi encontrada a sessao [EOEC] no arquivo '+paramstr(1)+Chr(13)+Chr(10)+
                    '      Verifique o arquivo EOEC.DOC para maiores detalhes','');

    item := '';

    while (item <> 'ENDSECTION') do
    begin
        INILineRead(Item, Valor, cfgfile);

        if Upper(Item) = 'EDITOR' then
        begin
            I := 0;
            for C := Length(Valor) downto 0 do
            begin
                 if (C = 0) and (I = 0) then I := Length(Valor)+1;
                 if (C > 0) and (Copy(Valor,C,1) = ' ') then I := C;
            end;

            SeuEditor := Copy(Valor,1,I-1);
            SeuEditorParam := Copy(Valor,I+1,Length(Valor)-I);
        end;

        if Upper(Item) = 'APAGADUPLOQUOTE' then
           if (Upper(Valor) = 'YES') or (Upper(Valor) = 'SIM') then
               QuoteFix := True
           else
               QuoteFix := False;

        if Upper(Item) = 'SAUDACAO' then
           if (Upper(Valor) = 'YES') or (Upper(Valor) = 'SIM') then
               Saudacao := True
           else
               Saudacao := False;

        if Upper(Item) = 'EQWK' then
           if (Upper(Valor) = 'YES') or (Upper(Valor) = 'SIM') then
               SeuEQWK := True
           else
               SeuEQWK := False;

        if Upper(Item) = 'TAGASK' then
           if (Upper(Valor) = 'YES') or (Upper(Valor) = 'SIM') then
               SeuTagAsk := True
           else
               SeuTagAsk := False;

        if Upper(Item) = 'TAGUSESUBJECT' then
           if (Upper(Valor) = 'YES') or (Upper(Valor) = 'SIM') then
               SeuTagUseSubj := True
           else
               SeuTagUseSubj := False;


        if Upper(Item) = 'TAGSIGN' then
        begin
             if Valor[1] = '"' then
             begin
                  delete(Valor, 1, 1);
                  if Valor[(length(Valor))] = '"' then
                       delete(Valor, length(Valor), 1);
                  SeuTagSign := Valor;
             end
             else
                  SeuTagSign := Valor+' ';
        end;

        if Upper(Item) = 'DIRETORIO'      then SeuDir        := ClearPath(Upper(Valor));
        if Upper(Item) = 'CABECALHO'      then SeuHeader     := Upper(Valor);
        if Upper(Item) = 'CABECALHOAREA'  then SeuHeaderArea := Upper(Valor);
        if Upper(Item) = 'ASSINATURA'     then SeuLogo       := Upper(Valor);
        if Upper(Item) = 'TAGLINES'       then SeuTaglines   := Upper(Valor);
        if Upper(Item) = 'QUOTES'         then SeuQuoteSigns := Strip(Valor,true);
        if (Upper(Item) = 'REGISTERID')   then RegID         := Valor;
        if (Upper(Item) = 'REGISTERNAME') then RegName       := Valor;
        if (Upper(Item) = 'REGISTERLINE') then SeuRegLine    := Valor;

    end;

        {verifica se os arquivos existem}

        {Se nao tiver PATH especificado, usa o do SeuDir}

    if SeuDir <> '' then
    begin

        if (GetPathName(SeuHeader) = '') and
           (SeuHeader <> '') then SeuHeader := SeuDir+SeuHeader;

        if (GetPathName(SeuHeaderArea) = '') and
           (SeuHeaderArea <> '') then SeuHeaderArea := SeuDir+SeuHeaderArea;

        if (GetPathName(SeuLogo) = '') and
           (SeuLogo <> '') then SeuLogo := SeuDir+SeuLogo;

        if (GetPathName(SeuTaglines) = '') and
           (SeuTaglines <> '') then SeuTaglines := SeuDir+SeuTaglines;

        if not DirExists(SeuDir) then
             ErrorMsg(1,'Nao foi achado o diret¢rio '+SeuDir+'.',
                        'Verifique o item Diretorio do arquivo '+paramstr(1)+'.');

    end;

    if SeuTagSign = '' then SeuTagSign := '... ';

    if SeuQuoteSigns = '' then SeuQuoteSigns := '>';

    if not FileExists(SeuEditor) then
        ErrorMsg(1,'Nao foi achado o editor de textos '+SeuEditor+'.',
                   'Verifique o item Editor do arquivo '+paramstr(1)+'.');

    if SeuHeader <> '' then
        if not FileExists(SeuHeader) then
             ErrorMsg(1,'Nao foi achado o arquivo com o header especificado como'+Chr(13)+Chr(10)+SeuHeader,
                        'Verifique o item Cabecalho do arquivo '+paramstr(1)+'.');

    if SeuHeaderArea <> '' then
        if not FileExists(SeuHeaderArea) then
             ErrorMsg(1,'Nao foi achado o arquivo com o header para  rea especificado como'+Chr(13)+Chr(10)+SeuHeaderArea,
                        'Verifique o item CabecalhoArea do arquivo '+paramstr(1)+'.');

    if SeuLogo <> '' then
        if not FileExists(SeuLogo) then
             ErrorMsg(1,'Nao foi achado o arquivo com sua assinatura especificado como'+Chr(13)+Chr(10)+SeuLogo,
                        'Verifique o item Assinatura do arquivo '+paramstr(1)+'.');

    if SeuTaglines <> '' then
        if not FileExists(SeuTaglines) then
             ErrorMsg(1,'Nao foi achado o arquivo com TAGLINES especificado como'+Chr(13)+Chr(10)+SeuTaglines,
                        'Verifique o item Taglines do arquivo '+paramstr(1)+'.');

        {V se  registrado ou nao pelo RegID e RegName}

    if (RegName <> '') and (RegID <> '') then
    begin

        UserCRC := Abs(CRC32(Upper(RegName)));
        RegCode1 := ValToChar(CopyInt(UserCRC,2,2) mod 25);
        RegCode2 := TrimVal4(CopyInt(UserCRC,6,4));
        RegCode3 := ValToChar(CopyInt(UserCRC,8,2) mod 25);
        if (RegCode1 + RegCode2 + RegCode3) = RegID then
             Reg := true
        else
             ErrorMsg(2,'C¢digo de registro inv lido para '+RegName+': '+RegID,
                        'Cheque com Ernesto Baschny o c¢digo correto.');

    end
    else
        Reg := false;

end; {CfgRead}


(* ---------------------------------------------------------------------- *)
procedure WriteMacroLine(var DestFile: Text; Level: Byte; Line: String);
    (* L linha especificada e grava ela no arquivo DestFile, usando *)
    (* vari veis, se necess rio                                      *)
    (* Level >= 1 para os itens @O...@                               *)
    (* Level >= 2 para os itens @R...@                               *)

var TempLine : String;
    Macro    : String[20];
    I        : Byte;

begin

     TempLine := '';
     Macro := '';
     I := 1;

     while I <= Length(Line) do
     begin
          if Line[I] <> '@' then TempLine := TempLine + Line[I];
          if Line[I] = '@' then
          begin
               Tempflag := false;
               inc(I);

               while Tempflag = false do
               begin
                    if (Line[I] <> '@') and (Line[I] <> ' ') then Macro := Macro + Line[I];
                    if (Line[I] = '@') or (Line[I] = ' ') then Tempflag := true;
                    inc(I);
               end;

               dec(I);
               Macro := Upper(Macro);

               if level >= 1 then
               begin

                   if Macro = 'OPACKET' then TempLine := TempLine + OMsgPacket;
                   if Macro = 'OANAME' then TempLine := TempLine + OMsgAreaName;
                   if Macro = 'OANUMBER' then TempLine := TempLine + OMsgArea;
                   if Macro = 'ODATE' then TempLine := TempLine + OMsgDate;
                   if Macro = 'OTIME' then TempLine := TempLine + OMsgTime;
                   if Macro = 'OFROM' then TempLine := TempLine + OMsgFrom;
                   if Macro = 'OFFROM' then TempLine := TempLine + OMsgFFrom;
                   if Macro = 'OLFROM' then TempLine := TempLine + OMsgLFrom;
                   if Macro = 'OFROMHANDLE' then TempLine := TempLine + OMsgFromHandle;
                   if Macro = 'OTO' then TempLine := TempLine + OMsgTo;
                   if Macro = 'OFTO' then TempLine := TempLine + OMsgFTo;
                   if Macro = 'OLTO' then TempLine := TempLine + OMsgLTo;
                   if Macro = 'OTOHANDLE' then TempLine := TempLine + OMsgToHandle;
                   if Macro = 'OSUBJ' then TempLine := TempLine + OMsgSubj;

               end;

               if level >= 2 then
               begin

                   if Macro = 'RANAME' then TempLine := TempLine + RMsgAreaName;
                   if Macro = 'RANUMBER' then TempLine := TempLine + RMsgArea;
                   if Macro = 'RFROM' then TempLine := TempLine + RMsgFrom;
                   if Macro = 'RFFROM' then TempLine := TempLine + RMsgFFrom;
                   if Macro = 'RLFROM' then TempLine := TempLine + RMsgLFrom;
                   if Macro = 'RTO' then TempLine := TempLine + RMsgTo;
                   if Macro = 'RFTO' then TempLine := TempLine + RMsgFTo;
                   if Macro = 'RLTO' then TempLine := TempLine + RMsgLTo;
                   if Macro = 'RTOHANDLE' then TempLine := TempLine + RMsgToHandle;
                   if Macro = 'RSUBJ' then TempLine := TempLine + RMsgSubj;
                   if Macro = 'CURDATE' then TempLine := TempLine + Current_Date;
                   if Macro = 'CURTIME' then TempLine := TempLine + Current_Time;
                   if Macro = 'CURDOW' then TempLine := TempLine + Current_DOW;

               end;

               if Macro = '' then TempLine := TempLine + '@';
               Macro := '';
               Tempflag := false;

          end;
          inc(I);

     end;

     if I <= Length(Line) then
          TempLine := TempLine + Buffer[I];

     if Line <> '' then
         writeln(DestFile,TempLine)
     else
         writeln(DestFile);

end; {WriteMacroLine}


(* ---------------------------------------------------------------------- *)
function LimpaLinha(linha: string): string;
    (* LimpaLinha(l) tira ocorrencias de  l  do  tipo 'ENY>EB>' ficando  *)
    (* apenas com 'EB>'                                                  *)

var  temp, I, C, I2 : byte;
     posi : array[0..10] of byte;

begin

    temp   := 1;     {para se o quote for "EB>   > texto"               }
    I2     := 0;     {contador para ver se nao passa dos 6 caracteres   }
    C      := 1;     {contador para verificador de caracter por caracter}
    I      := 1;     {indice para as posioes                           }
    posi[0] := 1;    {posioes para os quotes                           }

        {tenta a cada 6 caracteres, ou at chegar no fim da linha}

    while (I2 < 5) and (C < length(linha)) do

    begin

        inc(C);
        inc(I2);
        if pos(linha[C],SeuQuoteSigns) > 0 then
        begin
            temp := C;
            inc(C);

            while (linha[C] = ' ') do
                inc(C);

            if pos(linha[C],SeuQuoteSigns) > 0 then
            begin
                posi[I] := temp + 1;
                C := temp + 1;
            end
            else
                posi[I] := C;

            I2 := 0;
            inc(I);
        end;

    end;

    LimpaLinha := copy(linha,posi[I-2],length(linha)-posi[I-2]+1);

end;  {LimpaLinha}


(* ---------------------------------------------------------------------- *)
procedure DoVars;
    (* produz as vari veis para uso nos arquivos *)

var InetAreaName: string[13];   {do EOEC.INI: Area de Internet: Nome}
    InetArea    : string[4];    {do EOEC.INI: Area de Internet: Numero}
    Item, Valor : string;
    KludgeTimes : byte;
    SeuAddress  : string[49];   {do EOEC.INI: Arquivo com E-Mails}

    (* ------------------------------------------------------------------ *)
    function DoInet(Nome: string): string;
    begin

        if pos(Nome, '@') > 0 then
            DoInet := copy(Nome, 1, pos(Nome, '@')-1)
        else
            DoInet := Nome;

    end; {DoInet}
    (* ------------------------------------------------------------------ *)

    (* ------------------------------------------------------------------ *)
    function DoHandle(Nome: string): string;
            (* Retorna Handle do Nome, caso exista                    *)
            (* Para nomes com mais de 1 handle, faz sorteio aleat¢rio *)

    var Item, Valor: String;  {item e valor da pr¢xima linha do EOEC.INI}
        TempHandle : array [1..10] of string;
                              {array com os poss”veis 10 handles para posterior
                               sorteio aleat¢rio}
        Counter    : byte;    {contador para os handles}

    begin {DoHandle}

        Tempflag := false;
        Item := '';
        Counter := 0;

            {acha sessao APELIDOS, posiciona o ponteiro na primeira linha}

        INISectionFind(cfgfile,'APELIDOS',Tempflag);

        if Tempflag <> false then               {se achou a sessao, entao}
        begin

            while item <> 'ENDSECTION' do       {l do arquivo as linhas v lidas}
            begin                               {at chegar ao final do arquivo}

                INILineRead(item, valor, cfgfile);

                if Upper(item) = Upper(Nome) then  {caso v  encontrando nomes}
                begin                              {correspondentes ao handle}
                    inc(Counter);                  {os vai guardando na array}
                    TempHandle[Counter] := valor;
                end;

            end;

            if Counter = 0 then               {se ele nao achou nenhum handle}
                DoHandle := DoInet(Capitalize(FirstName(Nome)))
            else                              {se ele achou handles, ele faz}
            begin                             {sorteio entre os existentes}
                randomize;
                DoHandle := TempHandle[random(Counter)+1];
            end;

        end
        else
            DoHandle := DoInet(Capitalize(FirstName(Nome)));

    end; {DoHandle}
    (* ------------------------------------------------------------------ *)

    (* ------------------------------------------------------------------ *)
    procedure DoKludge;
            (* Grava vari veis Kludge *)

    begin {DoKludge}

        if pos('From: ',Buffer) > 0 then
        begin
            EQWKTo := Upper(copy(Buffer,Pos('From: ',Buffer)+6,255));
            inc(Kludge);
        end;

        if pos('Subject: ',Buffer) > 0 then
        begin
            EQWKSubject := copy(Buffer,pos('Subject: ',Buffer)+9,255);
            inc(Kludge);
        end;

        if pos('To: ',Buffer) > 0 then
            inc(Kludge);

    end; {DoKludge}
    (* ------------------------------------------------------------------ *)


begin {DoVars}

        {l arquivo HEADER.DAT e guarda resultados}

    reset(hdr);
    readln(hdr,Buffer);

    if Buffer <> 'Reply Header File' then
         ErrorMsg(2,'Problemas no arquivo HEADER.DAT do OLX.'+Chr(13)+Chr(10)+
                    'Tente sair do OLX e entrar de novo.','');

    readln(hdr,RMsgFrom);                     {Reply message: From}
    RMsgFrom := Capitalize(RMsgFrom);
    RMsgFFrom := FirstName(RMsgFrom);         {First name of From}
    RMsgLFrom := LastName(RMsgFrom);          {Last name of From}

    readln(hdr,RMsgTo);                       {Reply message: To}
    RMsgTo := DoInet(RMsgTo);

    RMsgTo    := Capitalize(RMsgTo);
    RMsgFTo   := FirstName(RMsgTo);           {First name of To}
    RMsgLTo   := LastName(RMsgTo);            {Last name of To}

    RMsgToHandle := DoHandle(RMsgTo);

    readln(hdr,RMsgSubj);                     {Reply message: Subject}
    readln(hdr,RMsgArea);                     {Reply message: Area number}
    readln(hdr,RMsgAreaName);                 {Reply message: Area Name}

    close(hdr);

        {se for o caso, l vari veis do ORIGINAL (header do OLX)}

    if (NewFlag <> true) and (Reeditflag <> true) then
    begin
        reset(ori);
        readln(ori);
        readln(ori, Buffer);

        OMsgPacket := RTrim(Copy(Buffer,9,8));   {Pacote: 'STIBBS'}

        readln(ori, Buffer);
        OMsgDate   := RTrim(Copy(Buffer,7,8));   {Data: 'DD-MM-AA'}
        OMsgTime   := Copy(Buffer,17,5);         {Hora: 'HH:MM'}

        readln(ori, Buffer);
        OMsgFrom   := Capitalize(RTrim(Copy(Buffer,7,25)));  {From: 'xxxxxxxx'}
        OMsgFFrom  := FirstName(OMsgFrom);       {First name of From}
        OMsgLFrom  := LastName(OMsgFrom);        {Last name of From}

        OMsgFromHandle := DoHandle(OMsgFrom);

        readln(ori, Buffer);
        OMsgTo     := DoInet(Capitalize(RTrim(Copy(Buffer,7,25))));  {To: 'xxxxxxxxx'}
        OMsgFTo    := FirstName(OMsgTo);         {First name of To}
        OMsgLTo    := LastName(OMsgTo);          {Last name of To}

        OMsgToHandle := DoHandle(OMsgTo);

        readln(ori, Buffer);
        OMsgSubj   := RTrim(Copy(Buffer,7,25));  {Subj: 'xxxxxxxxx'}
        OMsgArea   := Copy(Buffer,45,3);

           {ajuste do nome da  rea}

        readln(ori);                             {linha com "------"}

        KludgeTimes := 10;

        while KludgeTimes > 0 do
        begin
            readln(ori, Buffer);                 {linha N da mensagem}
            DoKludge;
            dec(KludgeTimes);
            if Buffer = '' then KludgeTimes := 0;
        end;

        close(ori);

        if Copy(OMsgArea,2,1) = ')' then OMsgArea := Copy(OMsgArea,1,1);
        if Copy(OMsgArea,3,1) = ')' then OMsgArea := Copy(OMsgArea,1,2);

        if Length(OMsgArea) = 1 then OMsgAreaName := RTrim(FileString(ori,6,48,25));
        if Length(OMsgArea) = 2 then OMsgAreaName := RTrim(FileString(ori,6,49,25));
        if Length(OMsgArea) = 3 then OMsgAreaName := RTrim(FileString(ori,6,50,25));

    end;

    INISectionFind(cfgfile, 'INTERNET', Tempflag);

    if TempFlag = true then
    begin

        item := '';

        while (item <> 'ENDSECTION') do
        begin

            INILineRead(Item, Valor, cfgfile);
            if Upper(Item) = 'AREANAME'   then InetAreaName := Valor;
            if Upper(Item) = 'AREANUMBER' then InetArea     := Valor;

        end;

        if (InetAreaName = RMsgAreaName) and (InetArea = RMsgArea) then
        begin

            writeln('ž Mensagem Internet');
            INISectionFind(cfgfile, 'INTERNET', Tempflag);
            item := '';
            TempFlag := false;

            while (item <> 'ENDSECTION') do
            begin

                INILineRead(Item, Valor, cfgfile);

                if Upper(Item) = 'CABECALHO'  then
                begin
                    SeuHeader := Valor;
                    if (GetPathName(SeuHeader) = '') and
                       (SeuHeader <> '') then SeuHeader := SeuDir+SeuHeader;
                    if SeuHeader <> '' then
                        if not FileExists(SeuHeader) then
                             ErrorMsg(1,'Nao foi achado o arquivo com o header especificado como'+Chr(13)+Chr(10)+
                                        '      '+SeuHeader,
                                        'Verifique o item Cabecalho da sessao [INTERNET] do arquivo '
                                         +Chr(13)+Chr(10)+'  '+paramstr(1)+'.');
                end;

                if Upper(Item) = 'ASSINATURA' then
                begin
                    SeuLogo := Valor;
                    if (GetPathName(SeuLogo) = '') and
                       (SeuLogo <> '') then SeuLogo := SeuDir+SeuLogo;
                    if SeuLogo <> '' then
                        if not FileExists(SeuLogo) then
                             ErrorMsg(1,'Nao foi achado o arquivo com a assinatura especificado como'+Chr(13)+Chr(10)+
                                        '      '+SeuLogo,
                                        'Verifique o item Assinatura da sessao [INTERNET] do arquivo '
                                        +Chr(13)+Chr(10)+'  '+paramstr(1)+'.');
                end;

                if Upper(Item) = 'USETAGS' then
                begin
                    TempFlag := true;
                    if (Upper(Valor) <> 'YES') and (Upper(Valor) <> 'SIM') then
                        SeuTaglines := ''
                end;

                if Upper(Item) = 'TAGSIGN' then
                begin
                    if Valor[1] = '"' then
                    begin
                         delete(Valor, 1, 1);
                         if Valor[(length(Valor))] = '"' then
                         delete(Valor, length(Valor), 1);
                         SeuTagSign := Valor;
                    end
                    else
                         SeuTagSign := Valor+' ';
                end;

                if Upper(Item) = 'ADDRESSBOOK' then
                begin
                    SeuAddress := Valor;
                    if (GetPathName(SeuAddress) = '') and
                       (SeuAddress <> '') then SeuAddress := SeuDir+SeuAddress;
                    if SeuAddress <> '' then
                        if not FileExists(SeuAddress) then
                             ErrorMsg(1,'Nao foi achado o arquivo com endereos especificado como'+Chr(13)+Chr(10)+
                                        '      '+SeuAddress,
                                        'Verifique o item ADDRESSBOOK da sessao [INTERNET] do arquivo '
                                        +Chr(13)+Chr(10)+'  '+paramstr(1)+'.');
                end;

            end;

            if TempFlag = false then SeuTagLines := '';

{            if SeuAddress <> '' then
            begin
                 FastWriteStr(1, 1, 'EOEC v2.0 - (c) 1994-5 by Ernesto Baschny', white, blue, Stype);
                 DrawBox(1, 80, 2, 20, 'Email Address');
            end;}

        end;

    end;

end; {DoVars}

(* ---------------------------------------------------------------------- *)
procedure DoEQWK;
    (* Transforma mensagem no padrao EQWK *)

begin

    writeln('ž Suporte ao formato EQWK');

    Tempflag := false;

        {Recria o arquivo de resposta}

    rewrite(rep);

        {1o Faz coisas com o FROM/TO}

        {Se no TO do OLX j  tiver mais de 25 caracteres, usa ele no To:}

    if length(RMsgTo) > 25 then
    begin
        writeln(rep,'To: '+Capitalize(RMsgTo));
        TempFlag := true;
    end
    
    else

        {Se TO tiver 25 ou menos, e tiver EQWKTo, coloca ele na primeira linha}

    begin

        if EQWKTo <> '' then
        begin

            if Upper(copy(EQWKTo,1,25)) = Upper(RMsgTo) then
            begin

                writeln(rep,'To: '+Capitalize(EQWKTo));
                Tempflag := true;
                RMsgTo := Capitalize(EQWKTo);
                RMsgFTo := FirstName(RMsgTo);           {First name of To}
                RMsgLTo := LastName(RMsgTo);            {Last name of To}
                OMsgFrom := Capitalize(EQWKTo);
                OMsgFFrom := FirstName(OMsgFrom);       {First name of To}
                OMsgLFrom := LastName(OMsgFrom);        {Last name of To}

            end;

        end;

    end;

        {2o Faz coisas com o SUBJ}

        {Se no SUBJ do OLX j  tiver mais de 25 caracteres, usa ele no Subject:}

    if length(RMsgSubj) > 25 then
    begin
        writeln(rep,'Subject: '+Capitalize(RMsgSubj));
        TempFlag := true;
    end
    
    else

        {Se SUBJ tiver 25 ou menos, e tiver EQWKSubj, coloca ele na primeira linha}

    begin

        if EQWKSubject <> '' then
        begin

            if copy(EQWKSubject,1,25) = RMsgSubj then
            begin

                writeln(rep,'Subject: '+EQWKSubject);
                Tempflag := true;

                RMsgSubj := EQWKSubject;
                OMsgSubj := EQWKSubject;

            end;

        end;

    end;

    if Tempflag then writeln(rep);

    close(rep);

end; {DoEQWK}


(* ---------------------------------------------------------------------- *)
procedure DoHeader;
    (* Coloca um HEADER na mensagem *)

begin

    writeln('ž Colocando cabealho na mensagem');

        {Appenda ao arquivo de resposta}

    if SeuEQWK = true then
        append(rep)
    else
        rewrite(rep);

        {Caso tenha havido mudana de  rea da mensagem, inclui essa informaao}

    if (RMsgArea <> OMsgArea) and (SeuHeaderArea <> '') then
    begin

        assign(F,SeuHeaderArea);
        reset(F);

        while not Eof(F) do
        begin
             readln(F,Buffer);
             WriteMacroLine(rep,2,Buffer);
        end;

        close(F);

    end;

    { if (Upper(OMsgTo) = Upper(SeuNome)) or (Upper(OMsgTo) = Upper(SeuHandle)) then
       OMsgTo := 'mim';
    if (Upper(OMsgFrom) = Upper(RMsgTo)) then
       OMsgFrom := 'voc'; }

        {Criaao do HEADER conforme arquivo indicado no EOEC.INI}

    if SeuHeader <> '' then
    begin

        assign(F,SeuHeader);
        reset(F);

        { Buffer := ''; }

            {l cada linha do arquivo de header e aplica macros correspondentes}

        while not Eof(F) do
        begin
             readln(F,Buffer);
             WriteMacroLine(rep,2,Buffer);
        end;

    end;

end; {DoHeader}

(* ---------------------------------------------------------------------- *)
procedure DoSaudacao;
    (* Coloca uma saudaao aleat¢ria na mensagem *)

var Saudacoes : word;
    Aleatorio : word;

begin

    writeln('ž Colocando saudaao na mensagem');

    if Saudacao = true then
    begin

        INISectionFind(cfgfile,'SAUDACOES',Tempflag);

        if Tempflag <> false then
        begin

            Saudacoes := 0;
            Buffer := 'A';

            while (Buffer[1] <> '[') and (not Eof(cfgfile)) do
            begin

                readln(cfgfile, Buffer);
                if (Buffer <> '') and
                   (Buffer[1] <> ';') and
                   (Buffer[1] <> '#') and
                   (Buffer[1] <> '%') and
                   (Buffer[1] <> '[') then
                        inc(Saudacoes);

            end;

            randomize;
            Aleatorio := Random(Saudacoes)+1;

            INISectionFind(cfgfile,'SAUDACOES',Tempflag);

            Saudacoes := 0;
            Buffer := '';

            while Saudacoes < Aleatorio do
            begin
                inc(Saudacoes);

                readln(cfgfile, Buffer);

                while ((Buffer = '') or
                       (Buffer[1] = ';') or
                       (Buffer[1] = '#') or
                       (Buffer[1] = '%')) do
                            readln(cfgfile, Buffer);

            end;

            WriteMacroLine(rep,2,Buffer);
            writeln(rep);

        end
        else
        begin

            writeln(rep,'Oi ',RMsgToHandle,'.');
            writeln(rep);

        end;

    end;

end; {DoSaudacao}

(* ---------------------------------------------------------------------- *)
procedure DoQuotes(lines: byte; Quote: boolean);
    (* "Appenda" os quotes na mensagem *)
    (* Se QUOTE for TRUE, ele utiliza o Limpalinha, se necess rio *)

begin

    writeln('ž Acrescentando quotes  mensagem');

    append(rep);
    reset(ori);

    if lines > 1 then
        for C := 1 to (lines-1) do readln(ori);

    while not Eof(ori) do
    begin
          readln(ori,Buffer);
          if (QuoteFix = true) and (Quote = true) then
              writeln(rep,LimpaLinha(Buffer))
          else
              writeln(rep,Buffer);
    end;

    close(ori);

end; {DoQuotes}


(* ---------------------------------------------------------------------- *)
procedure DoBottom;
    (* Coloca assinatura e tagline *)

Var Taglines  : Word;  {quantidade de taglines no arquivo de tags}
    RegSign   : String[3];
    ChosenTag : string;
    TempTag   : string;
    TagSearch : string;
    Option    : char;
    Rechoose  : boolean;
    OnceSearch: boolean;

    (* ------------------------------------------------------------------ *)
    procedure EditHelp;

    begin

        gotoxy(1, 15);
        writeln(' [<-]        move o cursor para a esquerda');
        writeln(' [->]        move o cursor para a direita');
        writeln(' [HOME]      move o cursor para o in”cio da tagline');
        writeln(' [END]       move o cursor para o final da tagline');
        writeln(' [DEL]       apaga o caracter sob o cursor');
        writeln(' [Backspace] apaga o caracter anterior');
        writeln(' [INS]       muda o modo de escrever (sobreescrever/inserir)');
        writeln(' [ENTER]     aceita alteraoes');
        writeln(' [ESC]       aborta operaao');

    end;

    (* ------------------------------------------------------------------ *)
    function SubjAnalize(Subject: string): string;
    var
       Index      : byte;
       WordLength : byte;
       Start      : byte;
       Longest    : string;

    begin

    Index := 1;
    WordLength := 0;
    Longest := '';

    while (Index <= length(Subject)) do
    begin

         while Subject[Index] in [',', ' ', ';', '.', '!', '?', '+', '-'] do
             inc(Index);
         Start := Index;

         while (Index <= length(Subject)) and (not (Subject[Index] in [',', ' ', ';', '.', '!', '?', '+', '-'])) do
             inc(Index);

         if (Index-Start) > length(Longest) then Longest := copy(Subject, Start, Index-Start);

    end;

    if length(Longest) > 3 then
        SubjAnalize := Upper(Longest)
    else
        SubjAnalize := '';

    end;

    (* ------------------------------------------------------------------ *)

begin

    writeln('ž Acrescentando assinatura  mensagem');

    if SeuLogo <> '' then
    begin

        assign(F,SeuLogo);
        reset(F);

        append(rep);

        while not Eof(F) do
        begin
             Readln(F, Buffer);
             WriteMacroLine(rep,2,Buffer);
        end;

        close(F);

        writeln(rep);

    end;

    writeln('ž Acrescentando tagline  mensagem');

    if SeuTaglines <> '' then
    begin

        Taglines := 0;

        assign(F,SeuTaglines);
        reset(F);

        while not Eof(F) do
        begin
             Readln(F);
             Inc(Taglines);
        end;

        append(rep);

        if SeuTagAsk = true then

        begin

            TempFlag := false;
            Rechoose := true;
            OnceSearch := false;
            if SeuTagUseSubj then TagSearch := SubjAnalize(RMsgSubj)
               else TagSearch := '';
            Logo;
            gotoxy(1, 5);
            writeln('Tagline selecionada:');
            gotoxy(1, 9);
            writeln('Sua opao: (O)utra, (N)enhuma, (E)ditar esta ou <ENTER> para aceitar.');
              write('           (F)ind (Procura), (A)gain (Novamente) ');

 {ChosenTag  (string)   A tag escolhida at aqui
  TempTag    (string)   Tag que vai ser editada (aceita ou nao)
  TagSearch  (string)   A palavra-chave a ser procurada
  TempFlag   (boolean)  Continua o loop ou acabou
  OnceSearch (boolean)  Ja pesquisou uma tag por uma string ou nao
  Rechoose   (boolean)  Quando voltar o loop, escolhe outra no random ou nao
  }

            while TempFlag = false do
            begin

                CursorOff;
                if Rechoose then
                begin
                     randomize;
                     ChosenTag := GetLine(F,Random(Taglines)+1);
                end;
                CleanLines(7, 7);
                gotoxy(1, 7);
                HighVideo;
                writeln(SeuTagSign+ChosenTag);
                LowVideo;
                while pos(Option, 'OoNnEeFfAa'+#13+#27) = 0 do
                     Option := readkey;
                Option := UpCase(Option);
                if Option = #27 then Option := 'N';
                case Option of
                     #13 : begin
                                WriteMacroLine(rep,2,SeuTagSign+ChosenTag);
                                TempFlag := true;
                           end;
                     'O' : begin
                                TempFlag := false;
                                Rechoose := true;
                                CleanLines(12, 12);
                                OnceSearch := false;
                           end;
                     'N' : TempFlag := true;
                     'E' : begin
                                Rechoose := false;
                                TempFlag := false;
                                TempTag := ChosenTag;
                                CleanLines(12, 12);
                                gotoxy(1, 12);
                                writeln('Reedite a tagline para ser enviada:');
                                EditHelp;
                                InputStringShift(TempTag, 78-length(SeuTagSign), 78-length(SeuTagSign), 1, 13, 'C', 176);
                                if key in [CarriageReturn] then
                                     ChosenTag := TempTag
                                else
                                     TempTag := '';
                                CleanLines(12, 23);
                           end;
                     'F' : begin
                                Rechoose := false;
                                TempFlag := false;
                                TempTag := ChosenTag;
                                Buffer := '';
                                CleanLines(12, 12);
                                gotoxy(1, 12);
                                writeln('Procura por qual palavra-chave:');
                                EditHelp;
                                InputStringShift(TagSearch, 20, 20, 1, 13, 'C', 176);
                                CleanLines(12, 23);
                                if (TagSearch <> '') and (key in [CarriageReturn]) then
                                begin
                                     gotoxy(1, 12);
                                     writeln('Procurando por: '+Upper(TagSearch));
                                     reset(F);
                                     while (pos(Upper(TagSearch), Upper(Buffer)) = 0) and (not Eof(F)) do
                                          readln(F, Buffer);
                                     CleanLines(12, 23);
                                     if pos(Upper(TagSearch), Upper(Buffer)) = 0 then
                                     begin
                                         ChosenTag := TempTag;
                                         gotoxy(1, 12);
                                         textcolor(lightred);
                                         writeln('Nao foi encontrado: ',Upper(TagSearch));
                                         textcolor(lightgray);
                                         OnceSearch := false;
                                         Rechoose := false;
                                     end
                                     else
                                     begin
                                         ChosenTag := Buffer;
                                         OnceSearch := true;
                                         Rechoose := false;
                                     end;
                                end;
                           end;
                     'A' : begin
                                TempTag := ChosenTag;
                                Rechoose := false;
                                if (TagSearch <> '') and OnceSearch then
                                begin
                                     readln(F, Buffer);
                                     if not Eof(F) then
                                     begin
                                          CleanLines(12, 23);
                                          gotoxy(1, 12);
                                          writeln('Procurando por: '+TagSearch);
                                          while (pos(Upper(TagSearch), Upper(Buffer)) = 0) and (not Eof(F)) do
                                                readln(F, Buffer);
                                          CleanLines(12, 23);
                                          if pos(TagSearch, Buffer) = 0 then
                                          begin
                                               ChosenTag := TempTag;
                                               gotoxy(1, 12);
                                               textcolor(lightred);
                                               writeln('Nao foi mais encontrado: '+Upper(TagSearch));
                                               textcolor(lightgray);
                                          end
                                          else
                                               ChosenTag := Buffer;
                                     end;
                                end
                                else
                                begin
                                     CleanLines(12, 23);
                                     gotoxy(1, 12);
                                     textcolor(lightred);
                                     writeln('Use antes o comando <F>ind');
                                     textcolor(lightgray);
                                end;
                           end;


                end;
                Option := 'x';

            end;
            CursorOn;

        end
        else
        begin
            randomize;
            ChosenTag := GetLine(F,Random(Taglines)+1);
            WriteMacroLine(rep,2,SeuTagSign+ChosenTag);
        end;

    end;

    if (reg = true) then
    begin
        RegSign := 'REG';
        if SeuRegLine <> '' then
             SeuRegLine := ' - '+SeuRegLine;
    end;

    if reg = false then
    begin
        SeuRegLine := 'not registered evalution copy';
        if Crc32(SeuRegLine) <> 1000789730 then
            ErrorMsg(2,'EOEC.EXE foi modificado',' recomendado que se pegue o pacote EOEC15.ZIP novamente.');
        SeuRegLine := ' - '+SeuRegLine;
        RegSign := 'NR';
    end;

    writeln(rep,EOECLine+' ['+RegSign+']'+SeuRegLine);

    close(rep);

end; {DoBottom}

(* ---------------------------------------------------------------------- *)
{function FileCRC(FileName: string) : word;

var
    CRC : word;
    FL : file;
    LongBuffer : array [1..1024] of byte;
    BuffCnt, i : integer;

begin

    assign(FL, FileName);

        {Open a file}
{    reset(FL, 1);

        {Start the CRC at 0}
{    CRC := 0;

        {Read all of the bytes in the file and use them to make a CRC}
{    repeat
        BlockRead(FL, LongBuffer, 1024, BuffCnt );
        for I := 1 to BuffCnt do
            CRC := CalcCRC(CRC, LongBuffer[I]);
    until BuffCnt <> 1024;

        {Close the file}
{    Close(FL);

        {Show the CRC}

{end;}

(* ---------------------------------------------------------------------- *)
procedure ShareDelay(Tempo: Byte);
    (* D  um delay de "tempo" segundos, com mensagem de pausa *)

begin

    CursorOff;
    while Tempo > 0 do
    begin
         write('Pausa por ',Tempo,' segundos...   ',Chr(13));
         delay(1000);
         dec(Tempo);
    end;
    writeln('Ok. Pausa encerrada.                          ');
    CursorOn;

end; {ShareDelay}


(* ====================================================================== *)
begin {Main Program}

    GetScreenType(Stype);

    Logo;                     {Logotipo inicial do programa}
    Verify_Param;             {Verifica a entrada de um parmetro (REPLY)}

    EOECLine := '~~~ EOEC/OLX v1.6';

    if Crc32(EOECLine) <> 1525288913 then
        ErrorMsg(2,'EOEC.EXE foi modificado',' recomendado que se pegue o pacote EOEC16.ZIP novamente.');

    assign(cfgfile, paramstr(1));
    CreateVars;               {Cria vari veis work, reply, original e header}
    CfgRead;                  {L configuraao do arquivo EOEC.INI}

    assign(rep,reply);        {Arquivo REPLY = rep}
    assign(hdr,header);       {Arquivo HEADER.DAT = hdr}
    assign(ori,original);     {Arquivo ORIGINAL = ori}

    if FileExists(reply) then   {Verifica se a mensagem  reediao de mensagem}
        Reeditflag := True      {pr¢pria ou nao      1a ediao    Reediao}
    else                                   {           Ori Rep     Ori Rep}
        if not FileExists(original) then   {  New       n   n       n   s }
            Newflag := True;               {  Reply     s   n       s   s }
                                           {  Mensagem minha        s   s }

    if (Reeditflag) and (not Newflag) then
    begin
        reset(rep);
        readln(rep,Buffer);

        if copy(Buffer,1,21) = 'This message was from' then
        begin

            readln(rep,Buffer);

            if copy(Buffer,1,24) = 'originally in conference' then
                Forwardtype := 2
            else
                Forwardtype := 1;

            Reeditflag := False;

        end;

        close(rep);
    end;

    DoVars;

    if (not Reeditflag) and (not Newflag) and (Forwardtype = 0) then
    begin
        if SeuEQWK = true then
            DoEQWK;
        DoHeader;
        DoSaudacao;
        if Kludge > 0 then inc(Kludge);
        DoQuotes(8+Kludge,true);     {Poe quotes a partir da linha depois dos Kudges}
        close(rep);
    end;

    if Forwardtype > 0 then
    begin
        rewrite(rep);
        DoSaudacao;
        writeln(rep,'                    ---------- Forwarded message -----------');
        DoQuotes(1,false);   {Poe texto a partir da linha 1, sem LimpaLinha}
        writeln(rep,'                    ---------------[EOEC 1.6]---------------');
        close(rep);
    end;

    if (not Reeditflag) and (Newflag) then
    begin
        rewrite(rep);
        if SeuEQWK = true then
        begin
            DoEQWK;
            append(rep);
        end;
        DoSaudacao;
        close(rep);
    end;

{    RepCRC := FileCRC(Reply);}

    writeln('ž Carregando editor de textos');

    SwapVectors;
    Exec(SeuEditor,SeuEditorParam+' '+reply);
    SwapVectors;

{    if RepCRC = FileCRC(Reply) then
         ErrorMsg(2,'Nao foi criada uma resposta no arquivo '+reply,'Pressione alguma tecla para retornar ao OLX.');
}
    if DosError <> 0 then
         ErrorMsg(2,'Erro de execuao no EOEC:','Contate Ernesto Baschny, informando erro #001-'+IntToStr(DosError));

    if not FileExists(reply) then
         ErrorMsg(2,'Nao foi criada uma resposta no arquivo '+reply,'Pressione alguma tecla para retornar ao OLX.');

    if not Reeditflag then
        DoBottom;

    clrscr;
    writeln('Obrigado por usar o EOEC v1.6.');
    CheckBreak := False;

    if reg = false then
    begin
        writeln;
        writeln('Contate ERNESTO BASCHNY para retirar essa mensagem. Nao  necess rio nenhum');
        write('pagamento. ');
        TextColor(White);
        writeln('Este programa  Freeware.');
        TextColor(LightGray);
        writeln;
        writeln('O contato s¢ precisa ser feito para que eu possa manter o controle de quem');
        writeln('o usa.');
        writeln;
        writeln('Leia a documentaao do EOEC para maiores detalhes.');
        writeln;
        writeln('Obrigado pela compreensao,');
        writeln('       Ernesto Baschny');
        writeln;
        writeln('  E VIVA O OLX!');
        writeln;
        ShareDelay(5);
    end;

end. {Main Program}
