{PICS0H1.INC  Pascal Integrated Communications System}
{ 6/4/87 vers 1.6 Copyright 1987 by Les Archambault}

Overlay  procedure mesg_save(to_loc: integer; subj: subject; var stop_msg: boolean);
  { Save message to disk }
    var
      start, line_count: integer;
      this: TextPtr;
      file_time: tad_array;
      Tstr: StrTAD;
    begin
      Writeln(USR);
      if (msg_status=private) and (test_bit(user_rec.flags,2)) then
        msg_status:=restricted;
      if (msg_status = private) and (user_rec.access >= val_acc) and
      (valid_pw) and (not test_bit(user_rec.flags,3))
        then if ask('Soll der Brief oeffentlich sein') then
          begin
            if restrict_public then msg_status:=restricted
            else msg_status:=public;
          end;
      if msg_status=restricted then
        writeln(usr,'Brief erreichbar nach Sysop-Erlaubnis...');
      start := filesize(mesg_file);
      seek(mesg_file, start);
      line_count := 0;
      this := TextBase;
      while this <> nil do
        begin
          Write(mesg_file, this^.TextMsg);
          line_count := succ(line_count);
          this := this^.next
        end;
      if line_count > 0
        then
          begin
            GetTAD(file_time);
            Tstr := FormTAD(file_time);
            seek(summ_file, 0);
            read(summ_file, summ_rec);
            with summ_rec do
              begin
                date      := file_time;
                status    := msg_status;
                area      := to_area;
                num       := succ(num);
                num_prev  := 0;   { used for protecting public msgs}
                if user_rec.access>=250 then num_next:=255
                                        else num_next:=  0; {used for foward file references}
                user_from := user_loc;
                user_to   := to_loc;
                subject   := subj;
                st_rec    := start;
                size      := line_count
              end;
            seek(summ_file, 0);
            Write(summ_file, summ_rec);
            seek(summ_file, filesize(summ_file));
            Write(summ_file, summ_rec);
            mesg_insert(2);
            case msg_status of
              private: Write(USR, 'Privater');
              public,restricted:  Write(USR, 'Oeffentlicher')
            end;
            Writeln(USR, ' Brief ', summ_rec.num, ' gespeichert ', Tstr)
          end;
      stop_msg := TRUE;
    end;

Overlay procedure mesg_quit(var stop_msg: boolean);
  { Return to command mode }
    begin
      Writeln(USR);
      Writeln(USR, 'Brief nicht gespeichert.');
      stop_msg := TRUE;
      mult_cmds:=false; cmd_queue:='';
    end;

procedure dummy_one;
   begin
   end;

begin  {message enter}
 abort:=false;
 if (diskfree(homdrv,homusr)>maxfree_abs) or
       (not test_bit(user_rec.flags,4)) then
  begin
    if diskfree(homdrv,homusr)<=maxfree_mslimit then
      begin
        limit_lines:=true;
        max_msg_lines:=maxfree_lines; {restrict because not enough space left on disk}
      end;
    if user_rec.access < val_acc
      then list('D');
    if to_ctrl=' ' then
      repeat
        st:=prompt('<U>pload oder <M>anuelle Eingabe',1,'ES');
        to_ctrl:=st[1]
      until (to_ctrl in ['U','M',' ']) or (not online);
    Writeln(USR);
    Writeln(USR, 'Absender:   ', user_rec.fn, ' ', user_rec.ln);
    OK := FALSE;
    if in_conference then msg_status := public
    else msg_status:=private;
    repeat
      if (user_rec.access < val_acc) or
         (to_ctrl = 'S') or
         ((to_ctrl = 'A') and (summ_rec.user_from = 0))
        then
          begin
            to_fn := 'SYSOP';
            Writeln(USR, 'Empfaenger: ', to_fn);
            to_area:=1;                     {Post area}
          end
      else if (to_ctrl = 'A') and (summ_rec.user_from > 0)
        then
          begin
            to_loc := summ_rec.user_from;
            to_area:=summ_rec.area;
            OK := TRUE;
            GetRec(DatF, to_loc, temp_user_rec);
            to_fn := temp_user_rec.fn;
            to_ln := temp_user_rec.ln;
            Writeln(USR, 'Empfaenger: ', to_fn, ' ', to_ln)
          end
        else
          begin
            to_fn := prompt('An VORNAME [CR = an ALLE] ', len_fn, 'ESLU');
            if to_fn='QUIT' then abort:=true;
            if (user_rec.fn='SYSOP') and (areaset=0) then to_area:=1
            else to_area:=areaset;
          end;
      if to_fn = ''
        then
          begin
            to_loc := 0;
            if (restrict_public or test_bit(user_rec.flags,3))
            and (not in_conference) then
              msg_status:=restricted
            else
              msg_status := public;
            OK := TRUE
          end
      else if to_fn = 'SYSOP'
        then to_ln := ''
      else if (to_ctrl <> 'A') and (not abort) then
         begin
           to_ln := prompt('ZUNAME   ', len_ln, 'ESLU');
           if to_ln='QUIT' then abort:=true;
         end;
       if (not OK) and (not abort) then
         begin
           key := pad(to_ln, len_ln) + pad(to_fn, len_fn);
           FindKey(IdxF, to_loc, key);
           if not OK then
             begin
               Writeln(USR, to_fn, ' ', to_ln, ' ist in diesem System unbekannt.');
               writeln(usr,'Mit Eingabe "QUIT" beenden.');
             end;
         end;
    until (not online) or OK or abort;
    if abort then OK:=false;
    if OK then
      begin
        if not valid_pw
          then
            begin
              subj := 'Passwort-Problem';
              Writeln(USR, 'Betr.:      ', subj)
            end
        else if user_rec.access < val_acc
          then
            begin
              subj := 'Neuer Benutzer';
              Writeln(USR, 'Betr.:      ', subj)
            end
        else if To_Ctrl='A' then
            begin
             X:= Pos('Antw. auf - ',summ_rec.subject);
             If X>0 then subj:= summ_rec.subject
             else
             subj:= 'Antw. auf - ' + summ_rec.subject;
             Writeln(USR, 'Betr.: ', subj)
            end
        else subj := prompt('Betrifft ', len_subj, 'EL');
        if subj='' then subj:='ALLGEMEIN';
        Writeln(USR);
        if limit_lines then
           begin
            writeln(usr,'Briefeingabe ist begrenzt auf ',max_msg_lines,' Zeilen.');
            writeln(usr);
           end;
        Writeln(USR, 'Briefeingabe beenden mit Punkt "." und <RETURN> am Zeilenanfang.');
        TextBase := nil;
        last_line := 1;
        if to_ctrl = 'U' then mesg_upld(last_line) else
             mesg_input(last_line);
        stop_msg := FALSE;
        if TextBase<>nil then
          begin
            repeat
              Writeln(USR);
              st:=prompt('Editier Befehl <A><E><L><S><W><Z><Q><?> ',80, 'ES?');
              if length(st)=1 then ch:=st[1]
              else st:=' ';
              case ch of
                'W': mesg_input(last_line);
                'L': begin
                       mesg_edit('L');
                       mesg_print;
                     end;
                'A': mesg_edit('A');
                'E': begin
                       mesg_insert_line;
                       mesg_print;
                     end;
                'Z': mesg_print;
                'S': mesg_save(to_loc, subj, stop_msg);
                'Q': mesg_quit(stop_msg)
              else  list('E');
              end;
            until (not online) or (stop_msg and (ch in ['A','E','L','S','W','Z','Q']));
          end
        else
         Writeln(usr,'Weitere Briefeingabe unmoeglich - Abbruch. ');
        while TextBase <> nil do
          begin
            this := TextBase;                   { Get rid of list elements }
            TextBase := TextBase^.next;
            dispose(this)
          end;
      end;        {OK}
  end          {enough disk space and allowed}
  else
    begin
      if test_bit(user_rec.flags,4) then
       writeln(usr,'Annahme von Briefen momentan nicht moeglich.')
      else
       Writeln(usr,'Nicht genuegend Platz auf Diskette fuer Briefe.');
    end;
end;

{ end of PICS0H1.inc }


