Program Sed;
{* S Editor, ver 1.00.
   Copyright (C) 1994, Henri LESOURD.

   This software is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This compiler is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  *}

Uses Crt,Errorify,Editify;

Var
   J : JumpBuf;

{$F+}
Procedure Handler(S : String);
Var
   Touche : Word;
Begin
  PrintMessage(1,1,Concat(S,' -- Press any key '));
  Touche:=GetCar;
  PrintBanner(1);
  LongJump(J,1);
End;
{$F-}

{$F+}
Procedure AdjustFName(Var S : String);
Var
   Length,I,J : Word;
Begin
  UpCaseString(S);

  Length:=Byte(S[0]);
  If Length=0 Then Exit;

  J:=0; For I:=1 To Length Do
  Begin
    If S[I]='.' Then J:=I;
  End;

  If J<>0 Then
  Begin
    If J=Length Then Dec(Byte(S[0]));
  End
  Else
    S:=Concat(S,'.S');
End;
{$F-}

Var
   Resu,Touche : Word;
   P : Pointer;

Begin
{ Lecture lignedecom }
  If ParamCount>1 Then
  Begin
    Write('Usage : EDIT FileName');
    Halt;
  End;
{ Alloc buffer }
  GetMem(P,$FFFE);
  If P=Nil Then
  Begin
    Write('Out of memory');
    Halt;
  End;
{ Init scr }
  TextMode(3);
  SetCursShape($0008);
  SetBuffer(P,$FFFE);
  EditErrorHandler:=Handler;
  AdjustFileName:=AdjustFName;
  TextName:='UNNAMED.S';
  If ParamCount=1 Then If SetJump(J)=0 Then
  Begin
    TextName:=ParamStr(1);
    AdjustFName(TextName);
    LoadText(TextName);
  End;
  Resu:=SetJump(J);
  Resu:=EditText(1,25);
  ActUpModified(1,1);
  Locate(25,1);
  SetCursShape($0708);
  ResetRuntime;
End.