uses dos,crt,tpansi,pullmode;

    TYPE
    Datamci = Record
                     Description : String[15];
                     Mci         : String[3];
                     Length      : 0..80;
                     YesNo       : Boolean;
                     Msg         : Boolean;
                     phone       : boolean;
                     date        : boolean;
                     change      : string[25];
                     END;

    Datarec = Record
                     AreaName    : STRING[20];
                     Nondata     : boolean;
                     filename    : String[8];
                     Access,
                     AddACS      : STRING[20];
                     ListAnsi    : string[3];
                     ShowAnsi    : string[8];
                     AddAnsi     : STRING[8];
                     Sponsor     : STRING[30];
                     AllowAnon   : Boolean;
                     StorMessage : Boolean;
                     totalentry  : string[6];
                     End;
type
   Configrec = record
    {------------------------ Main System Shit ---------------------}
      LongName   : String[40];
      Shortname  : String[10];
      SysOpName  : String[30];
      BoardPhone : String[12];
      RegistrationCode : String[20];
      NodeNumber       : Byte;
      TotalNodes       : Byte;
      DefaultUserNote  : String[50];
      Use_NUV          : Boolean;
      Use_SPW          : Boolean;
    {----------------------- Passwords & Shit ----------------------}
      NUPS      : Array[1..5] of String[30];
      NUPAccess : Array[1..5] of Byte;
      SystemPW  : String[30];
      BadBaudPW : String[30];
      ShellPW   : String[30];
      ExitPW    : String[30];
      SysOpPW   : String[30];
      ChatPW    : String[30];
    {------------------------- Directory Shit ----------------------}
      Lucid_dir,
      Text_dir,
      Board_Dir,
      Data_Dir,
      Textfile_dir,
      Door_dir,
      work_dir,
      prot_dir,
      arch_dir,
      menu_dir,
      Extract_dir : String[80];
    {-------------------------- Modem Shit -------------------------}
      Comport     : 0..8;
      LockBaud    : 300..115200;
      LowestBaud  : Longint;
      AnswerStr   : String[30];
      InitStr     : String[50];
      Hangup      : string[50];
      fossil      : boolean;
    {---------------------------------------------------------------}
   End; {ConfigRec}

    TYPE MCIARR=ARRAY[1..25] OF DATAMCI;

    VAR
    datafile:file OF DATAREC;
    DATAI:DATAREC;
    DMCI:MCIARR;
    DMF:FILE OF MCIARR;
    config:configrec;
var pm:pulld;

{$L mciedit.obj}
{$L dataedit.OBJ}

Procedure mcied;External;
Procedure dataedit;External;

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;
Procedure editline (Var S : String;BUF:BYTE);
Var Ch : Char;
    X:INTEGER;
    sx,sy:integer;
    buflen:byte;
Begin
  BUFLEN:=BUF;
  textcolor(15);
  textbackground(4);
  sx:=wherex;
  sy:=wherey;
  for x:=1 to buflen do write('°');
  gotoxy(sx,sy);
  X:=1;
  write(S);
  x:=length(s);
  Repeat
    Ch := ReadKey;
    IF X<BUFLEN THEN
    If Ord (Ch) in [32..255] Then
    Begin
      INC(X);
      S := S + Ch;
      write(ch);
          End;
    If Ord (Ch) = Ord (8) Then
    Begin
      If Length (S) > 0 Then
      Begin
        Write (#8'°'#8);
        Delete (S, Length (S), 1);
        DEC(X);
      End;
    End;
  Until (Ord (Ch) = 13);
  Write (#13#10);
End;

procedure display(x:byte);
var t:text;
    c:char;
begin
{assign(t,S);
reset(T);
repeat
read(t,c);
write(ansi,c);
until eof(t);
close(T);}
textattr:=7;
clrscr;
case x of
1:move(Pointer(@dataedit)^,ptr($B800,0)^,21*160);      { Config Editing Screen }
2:move(Pointer(@mcied)^,ptr($B800,0)^   ,15*160);      { Config Editing Screen }
end;
end;

procedure setupbar;
VAR X:BYTE;
begin
fillchar(pm,sizeof(pm),#0);
PM.CH[1] :='A';
PM.CH[2] :='B';
PM.CH[3] :='C';
PM.CH[4] :='D';
PM.CH[5] :='E';
PM.CH[6] :='F';
PM.CH[7] :='G';
PM.CH[8] :='H';
PM.CH[9] :='I';
PM.CH[10]:='J';
PM.CH[11]:='K';
PM.CH[12]:='L';
PM.CH[13]:='M';
PM.CH[14]:='N';
PM.CH[15]:='O';
PM.CH[16]:='P';
PM.CH[17]:='Q';

pm.ON[1] :='|B1|07Þ|B4|15A|B1|08Ý';
pm.ON[2] :='|B1|07Þ|B4|15B|B1|08Ý';
pm.ON[3] :='|B1|07Þ|B4|15C|B1|08Ý';
pm.ON[4] :='|B1|07Þ|B4|15D|B1|08Ý';
pm.ON[5] :='|B1|07Þ|B4|15E|B1|08Ý';
pm.ON[6] :='|B1|07Þ|B4|15F|B1|08Ý';
pm.ON[7] :='|B1|07Þ|B4|15G|B1|08Ý';
pm.ON[8] :='|B1|07Þ|B4|15H|B1|08Ý';
pm.ON[9] :='|B1|07Þ|B4|15I|B1|08Ý';
pm.ON[10]:='|B1|07Þ|B4|15J|B1|08Ý';
pm.ON[11]:='|B1|07Þ|B4|15K|B1|08Ý';
pm.ON[12]:='|B1|07Þ|B4|15L|B1|08Ý';
pm.ON[13]:='|B1|07Þ|B4|15M|B1|08Ý';
pm.ON[14]:='|B1|07Þ|B4|15N|B1|08Ý';
pm.ON[15]:='|B1|07Þ|B4|15O|B1|08Ý';
pm.ON[16]:='|B1|07Þ|B4|15P|B1|08Ý';
pm.ON[17]:='|B1|07Þ|B4|15R|B1|08Ý';
pm.ON[18]:='|B1|07Þ|B4|15Q|B1|08Ý';

pm.OFF[1] :='|B0|07Þ|B4|15A|B0|08Ý';
pm.OFF[2] :='|B0|07Þ|B4|15B|B0|08Ý';
pm.OFF[3] :='|B0|07Þ|B4|15C|B0|08Ý';
pm.OFF[4] :='|B0|07Þ|B4|15D|B0|08Ý';
pm.OFF[5] :='|B0|07Þ|B4|15E|B0|08Ý';
pm.OFF[6] :='|B0|07Þ|B4|15F|B0|08Ý';
pm.OFF[7] :='|B0|07Þ|B4|15G|B0|08Ý';
pm.OFF[8] :='|B0|07Þ|B4|15H|B0|08Ý';
pm.OFF[9] :='|B0|07Þ|B4|15I|B0|08Ý';
pm.OFF[10]:='|B0|07Þ|B4|15J|B0|08Ý';
pm.OFF[11]:='|B0|07Þ|B4|15K|B0|08Ý';
pm.OFF[12]:='|B0|07Þ|B4|15L|B0|08Ý';
pm.OFF[13]:='|B0|07Þ|B4|15M|B0|08Ý';
pm.OFF[14]:='|B0|07Þ|B4|15N|B0|08Ý';
pm.OFF[15]:='|B0|07Þ|B4|15O|B0|08Ý';
pm.OFF[16]:='|B0|07Þ|B4|15P|B0|08Ý';
pm.OFF[17]:='|B0|07Þ|B4|15R|B0|08Ý';
pm.OFF[18]:='|B0|07Þ|B4|15Q|B0|08Ý';

FOR X:=1 TO 18 DO BEGIN
                   PM.CX[X]:=2;
                   PM.CY[X]:=3+X;
                   END;
PM.MAXC:=18;
PM.CURRENTCHOICE:=1;
end;

procedure showinfo;
var x:integer;
begin
textattr:=15;
for x:=1 to 10 do begin
                  gotoxy(18,3+x);
                  clreol;
                  end;
textattr:=15;
gotoxy(19,4);
write(DATAI.AREANAME);
gotoxy(19,5);
write(DATAI.nondata);
gotoxy(19,6);
write(DATAI.FILENAME);
gotoxy(19,7);
write(DATAI.ACCESS);
gotoxy(19,8);
write(DATAI.addacs);
gotoxy(19,9);
write(DATAI.listANSI);
gotoxy(19,10);
write(DATAI.showANSI);
gotoxy(19,11);
write(DATAI.addansi);
gotoxy(19,12);
write(DATAI.sponsor);
gotoxy(19,13);
write(DATAI.allowanon,'  ');
gotoxy(19,14);
write(DATAI.stormessage,'  ');
gotoxy(19,15);
write(DATAI.totalentry);
end;

PROCEDURE NEXTAREA;
BEGIN
if filepos(datafile)=filesize(datafile) then seek(datafile,0);
read(datafile,DATAI);
end;

procedure prevarea;
begin
if filepos(datafile)=1 then seek(datafile,filesize(datafile)+1);
seek(datafile,filepos(datafile)-2);
read(datafile,DATAI);
end;

PROCEDURE YESNO(VAR B:BOOLEAN);
BEGIN
IF B=TRUE THEN B:=FALSE ELSE B:=TRUE;
END;

PROCEDURE DELETEIT;
VAR SX:INTEGER;
BEGIN
IF FILESIZE(datafile)>1 THEN BEGIN
                                         SX:=FILEPOS(datafile)-1;
                                         IF SX=FILESIZE(datafile)-1 THEN
                                            BEGIN
                                            SEEK(datafile,FILESIZE(datafile)-1);
                                            TRUNCATE(datafile);
                                            SEEK(datafile,FILESIZE(datafile)-1);
                                            READ(datafile,DATAI);
                                            SHOWINFO;
                                            EXIT;                                            EXIT;
                                            END;
                                         REPEAT
                                         SEEK(datafile,SX+1);
                                         READ(datafile,DATAI);
                                         SEEK(datafile,SX);
                                         WRITE(datafile,DATAI);
                                         INC(SX);
                                         UNTIL SX=FILESIZE(datafile)-1;
                                         TRUNCATE(datafile);
                                         END;
END;

PROCEDURE MCIINFO(F:BYTE);
VAR X:BYTE;
BEGIN
textattr:=15;
for x:=1 to 8 do begin
                  gotoxy(16,3+x);
                  clreol;
                  end;
GOTOXY(16,4);
WRITE(DMCI[F].description);
GOTOXY(16,5);
WRITE(DMCI[F].MCI);
GOTOXY(16,6);
WRITE(DMCI[F].length);
GOTOXY(16,7);
WRITE(DMCI[F].yesno,'  ');
GOTOXY(16,8);
WRITE(DMCI[F].msg,'  ');
GOTOXY(16,9);
WRITE(DMCI[F].phone,'  ');
GOTOXY(16,10);
WRITE(DMCI[F].date,'  ');
GOTOXY(16,11);
WRITE(DMCI[F].change,'  ');

END;

procedure mciedit;
VAR INT:BYTE;
    CUR:BYTE;
    S:STRING;
    X:INTEGER;
begin
assign(DMF,config.data_dir+DATAI.FILENAME+'.MCI');
{$I-} RESET(DMF); {$I+}
if ioresult<>0 then begin
                    rewrite(dmf);
                    FILLCHAR(DMCI,SIZEOF(DMCI),#0);
                    FOR X:=1 TO 25 DO BEGIN
                                      DMCI[X].MCI:='New Mci';
                                      END;
                    write(dmf,dmci)
                    END;
                    reset(dmf);
                    read(dmf,dmci);
pm.OFF[10]:='|B0|07Þ|B4|15Q|B0|08Ý';
pm.ON[10]:='|B1|07Þ|B4|15Q|B1|08Ý';
PM.CH[10] :='Q';
display(2);
PM.MAXC:=11;
PM.CURRENTCHOICE:=1;
MCIINFO(1);
CUR:=1;
REPEAT
GOTOXY(3,13);
PRINT('|B0|15  ');

IF CUR<12 THEN GOTOXY(4,15) ELSE GOTOXY(3,15);

PRINT('|B0|15'+STRR(CUR));

INT:=PULLMENU(PM);
GOTOXY(16,3+INT);
CASE INT OF
1:editline(dmci[cur].description,15);
2:EDITLINE(DMCI[CUR].MCI,3);
3:BEGIN
  S:=STRR(DMCI[CUR].LENGTH);
  EDITLINE(S,2);
  DMCI[CUR].LENGTH:=VALU(S);
  END;
4:YESNO(DMCI[CUR].YESNO);
5:YESNO(DMCI[CUR].MSG);
6:YESNO(DMCI[CUR].phone);
7:YESNO(DMCI[CUR].date);
8:BEGIN
  S:=DMCI[CUR].change;
  EDITLINE(S,25);
  DMCI[CUR].change:=S;
  END;

9:BEGIN
   INC(CUR);
   IF CUR=26 THEN CUR:=1;
  END;
10:BEGIN
   DEC(CUR);
   IF CUR=0 THEN CUR:=25;
   END;
  END;
mciinfo(cur);
UNTIL INT=11;
RESET(DMF);
WRITE(DMF,DMCI);
SETUPBAR;
display(1);
end;

PROCEDURE ADDAREA;
    var int:byte;
        S:STRING;
        SX:INTEGER;
BEGIN
display(1);
SETUPBAR;
FILLCHAR(DATAI,SIZEOF(DATAI),#0);
assign(datafile,config.data_dir+'dataarea.dat');
{$I-} RESET(datafile); {$I+}
if ioresult<>0 then begin
                    rewrite(datafile);
                    DATAI.areaname:='Misc Area';
                    datai.filename:='new';
                    datai.nondata:=false;
                    DATAI.access:='';
                    DATAI.addacs:='';
                    DATAI.listansi:='';
                    DATAI.showansi:='';
                    DATAI.sponsor:='';
                    DATAI.allowanon:=false;
                    datai.totalentry:='50';
                    DATAI.stormessage:=false;
                    write(datafile,DATAI);
                    reset(datafile);
                    end;
                    read(datafile,DATAI);

showinfo;
repeat
int:=PULLMENU(PM);
IF INT IN[1..13] THEN BEGIN
                      GOTOXY(19,3+INT);
                      CASE INT OF
                      1:EDITLINE(DATAI.areaNAME,20);
                      2:YESNO(DATAI.nondata);
                      3:EDITLINE(DATAI.FILENAME,8);
                      4:EDITLINE(DATAI.access,20);
                      5:EDITLINE(DATAI.addacs,20);
                      6:EDITLINE(DATAI.listansi,3);
                      7:EDITLINE(DATAI.showansi,8);
                      8:EDITLINE(DATAI.ADDANSI,8);
                      9:EDITLINE(DATAI.SPONSOR,30);
                      10:YESNO(DATAI.ALLOWANON);
                      11:YESNO(DATAI.STORMESSAGE);
                      12:EDITLINE(DATAI.totalentry,5);
                      END;
                      SEEK(datafile,FILEPOS(datafile)-1);
                      WRITE(datafile,DATAI);
                      END;

if int=13 then nextarea;
if int=14 then prevarea;
IF INT=15 THEN BEGIN
               SEEK(DATAFILE,FILESIZE(DATAFILE));
               FILLCHAR(DATAi,SIZEOF(DATAI),#0);
               DATAI.AREANAME:='New Area';
               write(datafile,datai);
               showinfo;
               END;
IF INT=16 THEN DELETEIT;
if int=17 then mciedit;
showinfo;
until int=18;
END;

begin
textattr:=7;
clrscr;
loadcfg;
addarea;
end.
