Uses Crt,Dos,genstr,filehandle,init,records,msgarea,io;

{$L msgedit.obj}
Const maxbars=25;

Type PullModerec = Record
                    OnString,OffString : Array[1..maxbars] of String[40];
                    X           : Array[1..Maxbars] of 1..80;
                    Y           : Array[1..Maxbars] of 1..25;
                    Choices     : 1..Maxbars;
                    pointercmd  : Array[1..maxbars] of 1..50;
                    FirstOption : 1..Maxbars;
                   end;

procedure FillWord(var x; count:integer; w:word);
Begin
 Inline($c4/$be/x/$8b/$86/w/$8b/$8e/count/$fc/$f2/$ab);
End;

Procedure FastSetBack(Y : Byte;Pair : Word);
Begin
 FillWord(mem[$b800:(Y-1)*160],80,Pair);
End;

Procedure print(S : String);
Var x,y:integer;
    r:string;
    g:integer;
    ff:byte;
begin
g:=1;
r:='';
y:=0;
ff:=0;
for X:=1 TO LENGTH(S) DO
   BEGIN
      If ff >= wleng then Exit;
   case S[X] OF '|':
      BEGIN
        case S[X+1] OF 'B':
           BEGIN
           Y:=VALU(S[X+2]);
           CRT.TEXTBACKGROUND(Y);
           INC(X,2);
           END ELSE
          BEGIN
          R:=S[X+1]+S[X+2];
          Y:=VALU(R);
          CRT.TEXTCOLOR(Y);
          INC(X,2);
          END;
      END;
   END ELSE begin
            WRITE(S[X]);
            inc(ff);
            end;
   END;
   END;
END;


PROCEDURE PRINTXY(X,Y:BYTE;S:sTRING);
BEGIN
GOTOXY(X,Y);
PRINT(s);
END;

procedure updatescreen;
begin
TEXTATTR:=15;
gotoxy(50,2);
write(currentbasenum);
gotoxy(53,2);
WRITE(total_bases('MSGCONF1'));
PRINTXY(18,4,CURRENTBASE.NAME);
PRINTXY(18,5,CURRENTBASE.datafile);
PRINTXY(18,6,CURRENTBASE.QWKID);
{PRINTXY(18,7,strR(CURRENTBASE.basetype[1));}
PRINTXY(18,8,CURRENTBASE.sponsor);
PRINTXY(18,9,CURRENTBASE.postaccess);
PRINTXY(18,10,CURRENTBASE.readaccess);
PRINTXY(18,11,CURRENTBASE.listaccess);
PRINTXY(18,12,CURRENTBASE.password);
PRINTXY(18,13,strr(CURRENTBASE.maxmessages));
PRINTXY(18,14,yn(CURRENTBASE.usenet));
PRINTXY(18,15,CURRENTBASE.echomaildir);
PRINTXY(18,16,CURRENTBASE.netaddress);
PRINTXY(18,17,CURRENTBASE.originline);
PRINTXY(18,18,CURRENTBASE.echotag);
PRINTXY(18,19,CURRENTBASE.netid);
PRINTXY(18,20,yn(CURRENTBASE.Kill_Kludge));
PRINTXY(18,21,yn(CURRENTBASE.Kill_Seenby));
PRINTXY(18,22,yn(CURRENTBASE.Kill_TearLn));

end;


Function Pullbars(Pull:pullmoderec):integer;
var On:1..maxbars;
    ch:char;

Procedure Write_Options;
Var dummy:1..maxbars;
Begin
 For dummy := 1 to pull.choices do
  begin
   gotoxy(pull.x[dummy],pull.y[dummy]);
   print(pull.offstring[Dummy]);
  end;
  on:=pull.firstoption;
  gotoxy(pull.x[on],pull.y[on]);
  print(pull.onstring[on]);
End;

procedure Update_Options(Down:boolean); {true:forward/false:backwards}
Begin
 gotoxy(pull.x[on],pull.y[on]);
 print(pull.offstring[on]);
 If Down then
  Begin
   If On < Pull.choices then Inc(on) else On := 1;
  End else
   Begin
    If On > 1 then Dec(On) else On := Pull.Choices;
   End;
 gotoxy(pull.x[on],pull.y[on]);
 print(pull.onstring[on]);
End;

Function Get_Input : Byte;
Var CH : Char;
Begin
 CH := ReadKey;
 If CH = #0 then CH :=Readkey;
 if ch = #27 then begin
                  ch:=readkey;
                  if ch='[' then ch:=readkey;
                  end;
 Case CH of
  'A' : Get_Input := 8;
  'B' : Get_Input := 2;

  #75 : Get_Input := 9;
  #77 : Get_Input := 7;

  #72 : Get_Input := 8;
  #80 : Get_Input := 2;
  #13 : Get_Input := 5;
 End;
End;

Var Key : Byte;

begin
 On := 1;
 Write_Options;
  Repeat
   Key := Get_input;
   Case Key of
    8 : update_options(False);
    2 : update_options(True);
    9 : begin
        beep;
        inc(currentbasenum);
        if currentbasenum=total_Bases('MSGCONF1')+1 then currentbasenum:=1;
        read_base('MSGCONF1',currentbasenum,currentbase);
        end;

   End;
  Until (Key = 5);
  Pullbars := On;
end;

procedure msgscreen; external;

var p:pullmoderec;
    x:byte;
begin
wleng:=255;
fillchar(p,sizeof(p),#0);
read_in_config;
clrscr;
move(Pointer(@msgscreen)^,ptr($B800,0)^,3500);
p.firstoption:=1;
for x:=1 to 9 do
begin
p.onstring [X]:='|B1|09['+STRR(X)+']';
p.offstring[X]:='|B0|01[|07'+STRR(X)+'|01]';
p.x[x]:=2;
p.y[x]:=3+x;
end;
for x:=10 to 22 do
begin
p.onstring [X]:='|B1|09['+chr(X+55)+']';
p.offstring[X]:='|B0|01[|07'+chr(X+55)+'|01]';
p.x[x]:=2;
p.y[x]:=3+x;
end;
p.choices:=19;
fastsetback(25,$1020);
gotoxy(1,25);
print('|B1|15[|07Left|15] Previous [|07Right|15] Next [|07Del|15] Delete [|07Ins|15] Insert');
READ_BASE('MSGCONF1',1,CURRENTBASE);
CURRENTBASENUM:=1;
REPEAT
updatescreen;
X:=pullbars(p);
UNTIL X=2;
end.
