{ PICS0H.INC - Pascal Integrated Communications System Overlays }
{ 5/25/87  Ver 1.6  Copyright 1987 by Les Archambault}

overlay procedure mesg_enter(to_ctrl: char);
{ Enter a new message }
  type
    TextPtr     = ^TextRecord;
    TextRecord  =
      record
        LineNo  : integer;                  { Line number }
        TextMsg : message;                  { Summary index }
        next    : TextPtr                   { Pointer to next element on list }
      end;
  var
    stop_msg,abort: boolean;
    msg_status: record_status;
    ch: char;
    last_line, to_loc,x,to_area: integer;
    TextBase, TextLast, this: TextPtr;
    to_fn: firstname;
    to_ln: lastname;
    subj: subject;
    key: StrName;
    temp_user_rec: user_list;

  procedure dummy1;
  { FORCE NEW OVERLAY }
    begin
    end;

  Overlay function In_Conference:boolean;

    var
      i:integer;
      this:areaptr;

   begin
     this:=areabase;  i:=0;
     while (this<>nil) and (this^.areaname<>areareq) do this:=this^.next;
     if this^.areaname=areareq then i:=this^.areaconf;
     In_conference:=test_bit(user_rec.conf_flags,i);
   end;

  Overlay procedure mesg_input(var last_line: integer);
  { Input message }
    var
      ch: char;
      this: TextPtr;
      msg: StrStd;
    begin
      Writeln(USR);
      msg := ' ';
      next_inpstr := '';
      while (not brk) and (msg <> '.') and (online) do
        begin
          msg := next_inpstr;
          if (last_line+1=max_msg_lines) and (limit_lines) then writeln(usr,'Nur noch 2 Zeilen.',bel);
          if (last_line>max_msg_lines) and (limit_lines) then msg:='.'
          else
            begin
              Write(USR, last_line:2, '> ');
              GetStr(msg, ch, len_msg, 'AEW');
              Writeln(USR);
            end;
          if msg <> '.'
            then if MaxAvail > 256
                 then
                   begin
                     new(this);
                     if TextBase = nil
                       then TextBase := this
                       else TextLast^.next := this;
                     TextLast := this;
                     TextLast^.LineNo := last_line;
                     TextLast^.TextMsg := msg;
                     TextLast^.next := nil;
                     last_line := succ(last_line)
                   end
                 else
                   begin
                     Writeln(USR, 'Memory voll.');
                     msg := '.'
                   end
        end
    end;

  Overlay procedure mesg_upld(var last_line: integer);
  { Upload message }
    var
      i: integer;
      ch: char;
      this: TextPtr;
      msg: StrStd;
    begin
      Writeln(USR,'ASCII-Upload jetzt starten...');
      Writeln(USR);
      msg := '';
      while (msg <> '.') and (online) and (not keypressed) do
        begin
          i := 1; msg := '';
          input_time := timeout * lps * 0.125;
          while (online) and (not input_timeout) and (i<len_msg) do
            begin
             if ch_inprdy then
               begin
                 ch := chr(ch_inp);
                 if (ch >= ' ') then
                  begin
                    msg := msg + ch;
                    i := succ(i);
                  end;
                 if (ch = CR) or (ch = ^Z) then i := len_msg
               end
            end;
          if msg <> '.'
            then if MaxAvail > 256
                 then
                   begin
                     new(this);
                     if TextBase = nil
                       then TextBase := this
                       else TextLast^.next := this;
                     TextLast := this;
                     TextLast^.LineNo := last_line;
                     TextLast^.TextMsg := msg;
                     TextLast^.next := nil;
                     last_line := succ(last_line)
                   end;
          if (ch = ^Z) then msg := '.'
        end
    end;


Overlay procedure mesg_edit(mode:char);
  { Edit selected line from message }
    var
      ch: char;
      i: integer;
      this,prev,new_line: TextPtr;
      msg: StrStd;
    begin
      Writeln(USR);
      case mode of
        'L': write(usr,'Loeschen Brief Zeile...');
        'A': write(usr,'Aendern Brief Zeile...');
      end;
      i := strint(prompt('Nummer ', 2, 'E'));
      this := TextBase;
      prev:=TextBase;
      if i>0 then
        begin
          while (i <> this^.LineNo) and (this <> nil) do    {find line}
            begin
              prev:=this;
              this := this^.next;
            end;
          if this <> nil
            then
              begin
                case mode of
                  'L':  begin
                         if (prev=textbase) and (prev=this) then textbase:=this^.next
                         else prev^.next:=this^.next;
                         dispose(this);
                         if TextLast=this then TextLast:=prev;
                         this:=prev^.next;
                           while this<>nil do
                             begin
                               this^.lineno:=pred(this^.lineno);
                               TextLast:=this;
                               this:=this^.next;
                             end;
                         last_line:=pred(last_line);
                        end;
                  'A': begin
                        msg := this^.TextMsg;
                        Write(USR, i:2, '> ');
                        GetStr(msg, ch, len_msg, 'EL');
                        Writeln(USR);
                        if msg <> '' then this^.TextMsg := msg;
                       end;
                end;           {case}
              end
            else Writeln(USR, 'Nicht gefunden.')
        end; {i>0}
    end;

Overlay procedure mesg_insert_line;
    var
      ch: char;
      i: integer;
      this,prev,new_line: TextPtr;
      msg: StrStd;
    begin
      Writeln(USR);
      i := strint(prompt('Einfuegen vor Zeile...Nummer ', 2, 'E'));
      this := TextBase;
      prev:=TextBase;
      if i>0 then
        begin
          while (i <> this^.LineNo) and (this <> nil) do    {find line}
            begin
              prev:=this;
              this := this^.next;
            end;
          if this <> nil then
              begin
               msg:='';
               write(usr,i:2,'> ');
               GetStr(msg,ch,len_msg,'EL');
               writeln(usr);
               if msg<> '' then
                 begin
                   new(new_line);
                   if (prev=textbase) and (prev=this) then textbase:=new_line
                   else prev^.next:=new_line;
                   new_line^.next:=this;
                   new_line^.lineno:=i;
                   new_line^.textmsg:=msg;
                   while this<>nil do
                     begin
                       this^.lineno:=succ(this^.lineno);
                       TextLast:=this;
                       this:=this^.next;
                     end;
                   last_line:=succ(last_line);
                 end;
              end
            else Writeln(USR, 'Nicht gefunden.')
        end; {i>0}
    end;

Overlay  procedure mesg_print;
  { Display message currently being edited }
    var
      this: TextPtr;
    begin
      writeln(usr);
      Writeln(USR, '  Von: ', user_rec.fn, ' ', user_rec.ln);
      if to_fn = ''
        then Writeln(USR, '   An: ALLE')
        else Writeln(USR, '   An: ', to_fn, ' ', to_ln);
      Writeln(USR, 'Betr.: ', subj);
      Writeln(USR);
      this := TextBase;
      while (not brk) and (this <> nil) do
        begin
          Writeln(USR, this^.LineNo:2, ': ', this^.TextMsg);
          this := this^.next
        end
    end;

{end of Pics0h.inc }

