Program MenuEditor;
Uses Dos,Crt,GenStr,filehandle,pullbar,fx,strl,records;
{$M 65520,0,65535}

Type
 acs   = string[80];

 MenuCommandRec = Record
                   Description  : String[35];
                   Access       : ACS;
                   CMDKey       : String[80];
                   Operation    : String[60];
                   Password     : String[20];
                   PString      : String[50];
                   CMDType      : Byte; {1=Normal,2=First,3=Every,4=Pullbar }
                   PullbarX     : Byte;
                   PullbarY     : Byte;
                   UnLitText    : String[80];
                   LitText      : String[80];
                  End;

(* Menu Record *)
  MenuRec = Record
           Name        : String[8];
           Description : String[50];
           Access      : String[80];
           Helpfile    : String[12];
           Tutorial    : String[12];
           keys        : string[50];
           Hotkeys     : Boolean;
           Useprompt   : Boolean;
           Pullbar     : Boolean;
           ClearScreen : Boolean;
           Prompt      : Array[1..2] of String[80];
           Fileconf    : 0..999;
           MsgConf     : 0..999;
           NumCommands : 0..999;
          End;

Var MenuR  : MenuRec;
    MenuC  : MenuCommandRec;
    FileName : String[15];
    f  : file;
    maxcmd:integer;
    cmds:array[1..80] of menucommandrec;

Procedure Commands;external;{$L Commands.obj}
Procedure loadtop;external; {$L loadtop.obj}
procedure cmdedit;external; {$L cmdedit.obj}
procedure cmdtop;external; {$L cmdtop.obj}
Procedure Read_In_Config;
Var Temp : String;
 begin
   assign(configf,'LUCID.CFG');
 {$I-}   reset(configf); {$I+}
    if ioresult<>0 then begin;
                        writeln('Lucid.cfg Does Not Exist, Please Configur Lucid ');
                        halt;
                        end;
  {--}
   With Config do
    Begin
     Readln(ConfigF,LongName);
     Readln(ConfigF,Shortname);
     Readln(ConfigF,SysOpName);
     Readln(ConfigF,BoardPhone);
     Readln(ConfigF,RegistrationCode);
     Readln(ConfigF,NodeNumber);
     Readln(ConfigF,TotalNodes);
     Readln(ConfigF,DefaultUserNote);
     Readln(ConfigF,Temp);
     If Pos('T',Temp) <> 0 then Use_NUV := True else Use_NUV := False;
     Readln(ConfigF,Temp);
     If Pos('T',Temp) <> 0 then Use_SPW := True else Use_SPW := False;
    {----------------------- Passwords & Shit ----------------------}
     Readln(ConfigF,NUPS[1]);
     Readln(ConfigF,NUPS[2]);
     Readln(ConfigF,NUPS[3]);
     Readln(ConfigF,NUPS[4]);
     Readln(ConfigF,NUPS[5]);
     Readln(ConfigF,NUPAccess[1]);
     Readln(ConfigF,NUPAccess[2]);
     Readln(ConfigF,NUPAccess[3]);
     Readln(ConfigF,NUPAccess[4]);
     Readln(ConfigF,NUPAccess[5]);
     Readln(ConfigF,SystemPW);
     Readln(ConfigF,BadBaudPW);
     Readln(ConfigF,ShellPW);
     Readln(ConfigF,ExitPW);
     Readln(ConfigF,SysOpPW);
     Readln(ConfigF,ChatPW);
    {------------------------- Directory Shit ----------------------}
    Readln(ConfigF,Lucid_dir);
    Readln(ConfigF,Text_dir);
    Readln(ConfigF,Board_Dir);
    Readln(ConfigF,Data_Dir);
    Readln(ConfigF,Textfile_dir);
    Readln(ConfigF,Door_dir);
    Readln(ConfigF,work_dir);
    Readln(ConfigF,menu_dir);
    Readln(ConfigF,prot_dir);
    readln(configf,arch_dir);
    Readln(ConfigF,Extract_dir);
    {-------------------------- Modem Shit -------------------------}
    Readln(ConfigF,Comport);
    Readln(ConfigF,LockBaud);
    Readln(ConfigF,LowestBaud);
    Readln(ConfigF,AnswerStr);
    Readln(ConfigF,InitStr);
    Readln(ConfigF,hangup);
    Readln(ConfigF,Temp);
    If Pos('F',Temp) <> 0 then fossil:= True else
    if Pos('A',temp) <> 0 then fossil:= false else
    if pos('T',temp) <> 0 then begin;
                               fossil:=true;
                               end;
   Readln(ConfigF,Temp);
   If Pos('T',Temp) <> 0 then changepage:= True else
   if Pos('F',temp) <> 0 then changepage:= false;

   End;
  close(configf);
end;

procedure showobj(x:byte);
begin
textattr:=7;
clrscr;
case x of
1: Move(@commands^,Mem[$b800:0000],160*25);
2: Move(@loadtop^,Mem[$b800:0000] ,160*18);
3: move(@cmdedit^,mem[$b800:0000] ,160*22);
4: move(@cmdtop^,mem[$b800:0000]  ,160*3);
end;
end;

procedure LoadMenu(Fn:string);
var x  : longint;
begin
nassign(f,config.menu_dir+fn);
nreset(f);
nread(f,menur,sizeof(menur));
{nread(f,cmds,sizeof(cmds));}
x:=0;
repeat
inc(x);
nread(f,cmds[x],sizeof(cmds[x]));
until eof(f);
maxcmd:=x;
end;

procedure writemenu(fn:string);
var mx:integer;
    gx:integer;
begin
rewrite(f,1);
nwrite(f,menur,sizeof(menur));
for gx:=1 to maxcmd do nwrite(f,cmds[gx],sizeof(cmds[gx]));
end;

procedure editcommands;
Const Opts : Array[1..16] of String[17] =
(' Description     ',
 ' Access          ',
 ' Command Key     ',
 ' Operation       ',
 ' PString         ',
 ' Command Type    ',
 ' Password        ',
 ' X Location      ',
 ' Y Location      ',
 ' Pullbar Unlit   ',
 ' Pullbar Lit     ',
 ' Next            ',
 ' Prev            ',
 ' Add Command     ',
 ' Del Command     ',
 ' Quit            ');

    var
    px,x,y:integer;
    C:char;
    p:pulld;
    temp:string;
    tmpr:menurec;
    tx:integer;
begin
x:=1;
p.currentchoice:=1;
p.maxc:=16;
for x:=1 to 16 do
begin
p.on [x]:='|B1|09'+OPTS[X];
p.off[x]:='|B0|09'+OPTS[X];
p.x  [x]:=2;
p.y  [x]:=6+x;
end;

x:=1;
repeat
textattr:=7;
clrscr;
showobj(4);
with cmds[x] do begin
              printxy(22,7,description);
              printxy(22,8,access);
              printxy(22,9,cmdkey);
              printxy(22,10,operation);
              printxy(22,11,pstring);
              if cmdtype=0 then cmdtype:=1;
              case cmdtype of
              0,1:printxy(22,12,'Normal'); 2:printxy(22,12,'First');
              3:printxy(22,12,'Every');  4:printxy(22,12,'Pullbar');
              end;
              printxy(22,13,password);
              printxy(22,14,strr(pullbarx));
              printxy(22,15,strr(pullbary));
              printxy(22,16,unlittext);
              printxy(22,17,littext);
              end;
gotoxy(1,25);
clreol;
print('|B0|01(|09'+strr(X)+'|01/|09'+strr(maxcmd)+'|01)');
px:=pullmenu(p);
case px of
 1:edstr(cmds[x].description,22,07,35,09,01,35);
 2:edstr(cmds[x].access     ,22,08,50,09,01,80);
 3:edstr(cmds[x].cmdkey     ,22,09,50,09,01,60);
 4:edstr(cmds[x].operation  ,22,10,20,09,01,60);
 5:edstr(cmds[x].pstring    ,22,11,50,09,01,50);
 6:begin; inc(cmds[x].cmdtype); if cmds[x].cmdtype=5 then cmds[x].cmdtype:=1; end;
 7:edstr(cmds[x].password   ,22,13,12,09,01,12);
 8:begin; temp:=strr(cmds[x].pullbarx);
          edstr(temp         ,22,14,3,09,01,3);
          cmds[x].pullbarx:=valu(temp);
   end;
 9:begin; temp:=strr(cmds[x].pullbary);
          edstr(temp         ,22,15,3,09,01,3);
          cmds[x].pullbary:=valu(temp);
   end;
10:edstr(cmds[x].unlittext  ,22,16,50,09,01,80);
11:edstr(cmds[x].littext    ,22,17,50,09,01,80);
12:begin; inc(X); if x=maxcmd+1 then x:=1; end;
13:begin; dec(X); if x=0 then x:=maxcmd; end;
{ int 16 ah=2}
14:if maxcmd<80 then
   begin;
{  for tx:=x to 79 do cmds[tx+1]:=cmds[tx];
   fillchar(cmds[x],sizeof(cmds[x]),#0);
   inc(maxcmd);}
   for tx:=80 downto x+1 do cmds[tx]:=cmds[tx-1];
   fillchar(cmds[x],sizeof(cmds[x]),#0);
   inc(maxcmd);
   end;
15:if maxcmd>1 then
   Begin
   for tx:=x to 80 do cmds[tx]:=cmds[tx+1];
   fillchar(cmds[80],sizeof(cmds[80]),#0);
   if x=maxcmd then dec(x);
   dec(maxcmd);
   end;
end;
until px=16;
end;

procedure editmenu;

Const Opts : Array[1..16] of String[25] =
('   Description     ',
 '   Menu Access     ',
 '   Allowed Keys    ',
 '   Menu Tutorial   ',
 '   Help File       ',
 '   Hot Keys        ',
 '   Use Prompt      ',
 '   Clear Screen    ',
 '   Prompt Line 1   ',
 '   Prompt Line 2   ',
 '   Force File Conf ',
 '   Force Msg Conf  ',
 '   Menu Filename   ',
 '   Pullbar Menu    ',
 '   Command Editor  ',
 '        Quit       ');

var X  : BYTE;
    p  : pulld;
    temp : string;
    tx   : byte;
begin
fillchar(p,sizeof(p),#0);
p.maxc:=16;
p.currentchoice:=1;
for x:=1 to 16 do
begin
p.on [x]:='|B1|09'+OPTS[X];
p.off[x]:='|B0|09'+OPTS[X];
p.x  [x]:=5;
p.y  [x]:=6+x;
end;

repeat
showobj(1);
print('|B0|07');
with menur do begin
              printxy(26,7,'|B0|07' +description);
              printxy(26,8,'|B0|07' +access);
              printxy(26,9,'|B0|07' +keys);
              printxy(26,10,'|B0|07'+tutorial);
              printxy(26,11,'|B0|07'+helpfile);
              printxy(26,12,'|B0|07'+yn(hotkeys));
              printxy(26,13,'|B0|07'+yn(useprompt));
              printxy(26,14,'|B0|07'+yn(clearscreen));
              printxy(26,15,'|B0|07'+prompt[1]);
              printxy(26,16,'|B0|07'+prompt[2]);
              printxy(26,17,'|B0|07'+strr(FileConf));
              printxy(26,18,'|B0|07'+strr(MsgConf));
              printxy(26,19,'|B0|07'+name);
              printxy(26,20,'|B0|07'+yn(pullbar));
              end;
nreset(f);
nwrite(f,menur,sizeof(menur));
nreset(f);
nread(f,menur,sizeof(menur));
x:=pullmenu(p);

case x of
 1:edstr(menur.description,26,07,50,09,01,50);
 2:edstr(menur.access     ,26,08,50,09,01,80);
 3:edstr(menur.keys       ,26,09,50,09,01,50);
 4:edstr(menur.tutorial   ,26,10,12,09,01,12);
 5:edstr(menur.helpfile   ,26,11,12,09,01,12);
 6:asm xor menur.hotkeys     ,1 end;
 7:asm xor menur.useprompt   ,1 end;
 8:asm xor menur.clearscreen ,1 end;
 9:edstr(menur.prompt[1]  ,26,15,50,09,01,80);
10:edstr(menur.prompt[2]  ,26,16,50,09,01,80);
11:begin; temp:=strr(menur.fileconf);
          edstr(temp      ,26,17,3,09,01,3);
          menur.fileconf:=valu(temp);
   end;
12:begin; temp:=strr(menur.msgconf);
          edstr(temp      ,26,18,3,09,01,3);
          menur.msgconf:=valu(temp);
   end;
13:edstr(menur.name       ,26,19,08,09,01,08);
14:asm xor menur.pullbar     ,1 end;
15:editcommands;
end;
until x=16;
writemenu(menur.name);
end;

PROCEDURE GETFILE;
type frec=record
     f:string[12];
     d:string[50];
     end;

var top,max,active:integer;
    files:array[1..60] of frec;
    DirInfo: SearchRec;
    c : char;
    x,y:integer;
    maxl:byte;
    active_two:byte;
    bars:array[1..5] of string;
    begin
    bars[1]:=' iNSERT ';
    bars[2]:=' dELETE ';
    bars[3]:='  hELP  ';
    bars[4]:=' eDIT ';
    bars[5]:=' eXIT ';

    showobj(2);
    fillchar(files,sizeof(files),#0);
    top:=1;
    active:=1;
    max:=0;
    maxl:=0;
    active_two:=1;
    FindFirst(config.menu_dir+'*.MNU', Archive, DirInfo);
          while DosError = 0 do
                begin
                 nassign(f,config.menu_dir+dirinfo.name);
                 nread(f,menur,sizeof(menur));
                 nclose(f);
                 inc(max);
                 inc(maxl);
                 files[max].f:=(DirInfo.Name);
                 files[max].d:=(menur.description);
                 FindNext(DirInfo);
                end;

    repeat
    if  max<>0 then
    for x:=0 to 9 do begin
                      if x=active-1 then
                      printxy(1,5+x,PADSTRING('|B1|15'+FILES[X+TOP].f,18)) ELSE
                      printxy(1,5+x,PADSTRING('|B0|15'+files[x+top].f,18));
                      TEXTATTR:=7;
                      CLREOL;
                      printxy(30,5+x,'|B0|15'+FILES[X+TOP].D);
                      textattr:=7;
                      clreol;
                      if x=max+1 then x:=9;
                      end;

    for x:=1 to 5 do
    begin
    if x=active_two then printXY(3+(14*x)-10,17,'|B1|15'+BARS[X]) ELSE
                         printXY(3+(14*x)-10,17,'|B0|15'+BARS[X]);
    end;

    c:=readkey;
    case c of
   #72 : If Active > 1 then Dec(Active) else If Top > 1 then Dec(Top);
   #75 : If Active_Two > 1 then Dec(Active_Two);
   #77 : If Active_Two < 5 then Inc(Active_Two);
   #27 : Begin
          asm mov ax,3; int 10h; end;
          print('|B0|07');
          Halt(0);
         End;
   #80 : if active=max then begin end else
        Begin
          If max > 10 then
           Begin
            If Active < 10 then Inc(Active) else If Top+10 < max then Inc(Top);
            End else If Active < max then Inc(Active);
         End;
    end;
    until c=#13;
    case active_two of
    1:begin;
      textattr:=7;
      clrscr;
      fillchar(menur,sizeof(menur),#0);
      fillchar(menuc,sizeof(menuc),#0);
      fillchar(cmds,sizeof(cmds),#0);
      println('|B0|15|13ÄÄÄ-Ä|05ÄÄ--|08ÄÄ -   - iNSERT Menu ');
      print('Menu File Name =>');
      edstr(menur.name,19,2,12,09,1,12);
      if menur.name='' then exit;
      menur.description:='New Menu';
      assign(f,menur.name+'.MNU');
      rewrite(f,1);
      writemenu(menur.name+'.MNU');
      cmds[1].description:='New Command';
      nwrite(f,cmds[1],sizeof(cmds[1]));
      fillchar(cmds,sizeof(cmds),#0);
      close(f);
      loadmenu(menur.name+'.MNU');
      editmenu;
      writemenu(menur.name+'.MNU');
      end;
    2:;
    3:;
    4:begin;
      loadmenu(files[active].f);
      editmenu;
      {writemenu(files[active].f);}
      end;
    5:begin; print('|B0|07'); halt(0); END;
    end;
end;

Procedure loadcfg;
Var Temp : String;
    configf:text;
 begin
   assign(configf,'LUCID.CFG');
 {$I-}   reset(configf); {$I+}
    if ioresult<>0 then begin
                        textattr:=7;
                        writeln('Lucid.cfg Does Not Exist, Please Configur Lucid ');
                        halt(12);
                        end;
  {--}
   With Config do
    Begin
     Readln(ConfigF,LongName);
     Readln(ConfigF,Shortname);
     Readln(ConfigF,SysOpName);
     Readln(ConfigF,BoardPhone);
     Readln(ConfigF,RegistrationCode);
     Readln(ConfigF,NodeNumber);
     Readln(ConfigF,TotalNodes);
     Readln(ConfigF,DefaultUserNote);
     Readln(ConfigF,Temp);
     If Pos('T',Temp) <> 0 then Use_NUV := True else Use_NUV := False;
     Readln(ConfigF,Temp);
     If Pos('T',Temp) <> 0 then Use_SPW := True else Use_SPW := False;
    {----------------------- Passwords & Shit ----------------------}
     Readln(ConfigF,NUPS[1]);
     Readln(ConfigF,NUPS[2]);
     Readln(ConfigF,NUPS[3]);
     Readln(ConfigF,NUPS[4]);
     Readln(ConfigF,NUPS[5]);
     Readln(ConfigF,NUPAccess[1]);
     Readln(ConfigF,NUPAccess[2]);
     Readln(ConfigF,NUPAccess[3]);
     Readln(ConfigF,NUPAccess[4]);
     Readln(ConfigF,NUPAccess[5]);
     Readln(ConfigF,SystemPW);
     Readln(ConfigF,BadBaudPW);
     Readln(ConfigF,ShellPW);
     Readln(ConfigF,ExitPW);
     Readln(ConfigF,SysOpPW);
     Readln(ConfigF,ChatPW);
    {------------------------- Directory Shit ----------------------}
    Readln(ConfigF,Lucid_dir);
    Readln(ConfigF,Text_dir);
    Readln(ConfigF,Board_Dir);
    Readln(ConfigF,Data_Dir);
    Readln(ConfigF,Textfile_dir);
    Readln(ConfigF,Door_dir);
    Readln(ConfigF,work_dir);
    Readln(ConfigF,menu_dir);
    Readln(ConfigF,prot_dir);
    readln(configf,arch_dir);
    Readln(ConfigF,Extract_dir);
    {-------------------------- Modem Shit -------------------------}
    Readln(ConfigF,Comport);
    Readln(ConfigF,LockBaud);
    Readln(ConfigF,LowestBaud);
    Readln(ConfigF,AnswerStr);
    Readln(ConfigF,InitStr);
    Readln(ConfigF,hangup);
    Readln(ConfigF,Temp);
    If Pos('T',Temp) <> 0 then fossil:= True else fossil:= False;

   End;
  close(configf);
end;

begin
TEXTATTR:=7;
CLRSCR;
loadcfg;
getfile;
print('|B0|07');
end.


