unit dataarea;
interface
procedure randompick(n:integer);
function  loadit(n:integer):boolean;
procedure runadd(n:byte);
procedure runadd2(n:byte);
procedure runit(n:byte);
implementation

uses crt,io,genstr,records,userstuf,filehandle,protcomm;

    type strec=record
               str:string[80];
               yn:boolean;
               end;

    type mciarr=array[1..25] of datamci;
         strarr=array[1..25] of strec;
    var
    datai:datarec;
    dmci:mciarr;
    mci:mcis;

procedure randompick(n:integer);
var x:integer;
    dataenter:file;
    r:strarr;
begin
loadit(n);
nassign(dataenter,config.data_dir+datai.filename+'.ent');
randomize;
x:=random(filesize(dataenter));
nseek(dataenter,x);
nread(dataenter,r,sizeof(r));
for x:=1 to 25 do begin
                  mci[x].str:=r[x].str;
                  end;
printfile(Config.Textfile_Dir+datai.listansi+'ran.ans',mci,false);
nclose(dataenter);
end;

function loadit(n:integer):boolean;
    var
    datafile:file;{ of datarec;}
    dmf:file; {of mciarr;}
    x:integer;
begin
fillchar(datai,sizeof(datai),#0);
assign(datafile,config.data_dir+'dataarea.dat');
{$i-} reset(datafile,1); {$i+}
if ioresult<>0 then begin
                    loadit:=false;
                    exit;
                    end;
nseek(datafile,(sizeof(datai)*(n-1)));
nread(datafile,datai,sizeof(datai));
nclose(datafile);
nassign(dmf,config.data_dir+datai.filename+'.mci');
nread(dmf,dmci,sizeof(dmci));
nclose(dmf);
fillchar(mci,sizeof(mci),#0);
for x:=1 to 25 do begin
                  mci[x].mci:=dmci[x].mci;
                  mci[x].str:='';
                  mci[x].yesno:=dmci[x].yesno;
{                 mci[x].yesnoresult:=dmci[x].yesnoresult;}
                  mci[x].phone:=dmci[x].phone;
                  mci[x].date:=dmci[x].date;
                  mci[x].lng:=dmci[x].length;
                  end;
end;

procedure runadd(n:byte);
var x:integer;
    dataenter:file{ strarr};
    r:strarr;
    userx:longint;
begin
if loadit(n)=false then exit;
nassign(dataenter,config.data_dir+datai.filename+'.ent');
printfile(Config.Textfile_Dir+datai.addansi+'.ans',mci,TRUE);
for x:=1 to 25 do begin
                  r[x].str:=mci[x].str;
                  r[x].yn:= mci[x].yesnoresult;
                  end;
if filesize(dataenter) div sizeof(r)>=valu(datai.totalentry) then
rewrite(dataenter,1);
nseek(dataenter,filesize(dataenter));
nwrite(dataenter,r,sizeof(R));
nclose(dataenter);
end;

procedure runadd2(n:byte);
var x:integer;
    dataenter:file;{ of strarr;}
    r:strarr;
    userx:longint;
    keys:array[1..30] of char;
    y,z:integer;
    c:char;
procedure updateit;
var x:integer;
begin
for x:=1 to 25 do begin
      if dmci[x].change='USERNAME'  THEN mci[x].str:=user.alias;
      if dmci[x].change='REALNAME'  THEN mci[x].str:=user.realname;
      if dmci[x].change='PHONE'     THEN mci[x].str:=user.phone;
      if dmci[x].change='PASSWORD'  THEN mci[x].str:=user.password;
      if dmci[x].change='MAINLEV'   THEN mci[x].str:=strr(user.mainlev);
      if dmci[x].change='FILELEV'   THEN mci[x].str:=strr(user.filelev);
      if dmci[x].change='FLAGS'     THEN mci[x].str:=user.flags;
      if dmci[x].change='USERNOTE'  THEN mci[x].str:=user.usernote;
      if dmci[x].change='SYSOPNOTE' THEN mci[x].str:=user.Sysopnote;
      if dmci[x].change='ADDRESS'   THEN mci[x].str:=user.ADDRESS;
      if dmci[x].change='LOCATION'  THEN mci[x].str:=user.location;
      if dmci[x].change='ZIP'       THEN mci[x].str:=user.zipcode;
      if dmci[x].change='SCRLN'     THEN mci[x].str:=strr(user.scrln);
      if dmci[x].change='YESNOBAR'  THEN begin
                                         mci[x].yesno:=true;
                                         mci[x].yesnoresult:=user.yesno;
                                         MCI[X].STR:=YN(USER.YESNO);
                                         end;
      if dmci[x].change='PAUSE'     THEN begin
                                         mci[x].yesno:=true;
                                         mci[x].yesnoresult:=user.PAUSE;
                                         MCI[X].STR:=YN(USER.PAUSE);
                                         end;
      if dmci[x].change='EXPERT'    THEN begin
                                         mci[x].yesno:=true;
                                         mci[x].yesnoresult:=user.xpermode;
                                         MCI[X].STR:=YN(USER.XPERMODE);
                                         end;
      if dmci[x].change='HOTKEY'    THEN begin
                                         mci[x].yesno:=true;
                                         mci[x].yesnoresult:=user.hotkey;
                                         MCI[X].STR:=YN(USER.hotkey);
                                         end;
      if dmci[x].change='AUTOSIG'    THEN begin
                                         mci[x].yesno:=true;
                                         mci[x].yesnoresult:=user.AUTOSIG;
                                         MCI[X].STR:=YN(USER.AUTOSIG);
                                         end;
      if dmci[x].change='PROMPTIT'    THEN begin
                                         MCI[X].STR:=STRR(USER.PROMPT);
                                         MCI[X].ACTION:=NEXTPROMPT;
                                         MCI[X].USEPROC:=TRUE;
                                         end;
                   end;

mci[30].mci:='~**';
end;

begin
if loadit(n)=false then exit;

if datai.nondata=false then
nassign(dataenter,config.data_dir+datai.filename+'.ent');

{ Load Userinfo into DataArea Stuff }
updateit;

printfile(Config.Textfile_Dir+datai.addansi+'.ans',mci,false);

for x:=1 to 25 do begin
                  r[x].str:=mci[x].str;
                  r[x].yn:= mci[x].yesnoresult;
                  end;

for x:=1 to 25 do keys[x]:=mci[x].mci[3];

repeat
goxy(mci[30].x,mci[30].y);
c:=sreadkey;
AnsiColor(mci[30].Back shl 4 + mci[30].Fore);
print(c);
for x:=1 to 25 do
if UPCASE(c)=keys[x] then
          begin
          AnsiColor(mci[x].Back shl 4 + mci[x].Fore);
          goxy(mci[x].x,mci[x].y);
          if mci[X].phone=true then sphoneinput(mci[X].str) else
          if mci[X].DATE =true then sdateinput(mci[X].str) else
          if mci[x].yesno=true then
          BEGIN
          MCI[X].YESNORESULT:=YNCHANGE(MCI[X].YESNORESULT);
          print(yn(mci[x].yesnoresult));
          END else
          if mci[x].useproc=true then begin
          mci[x].action;
          updateit;
          printfile(Config.Textfile_Dir+datai.addansi+'.ans',mci,false)
          end
          else
          editline(mci[X].str);
          end;
until (c=#27) OR ((Not Carrier) AND (Not Localon)) or (hungup) or (loggedoff);;

for x:=1 to 25 do begin
      userx:=finduser(user.alias,false);
      if dmci[x].change='USERNAME'  THEN user.alias:=mci[x].str;
      if dmci[x].change='REALNAME'  THEN user.realname:=mci[x].str;
      if dmci[x].change='PHONE'     THEN user.phone:=mci[x].str;
      if dmci[x].change='PASSWORD'  THEN user.password:=mci[x].str;
      if dmci[x].change='MAINLEV'   THEN user.mainlev:=valu(mci[x].str);
      if dmci[x].change='FILELEV'   THEN user.filelev:=valu(mci[x].str);
      if dmci[x].change='FLAGS'     THEN user.flags:=mci[x].str;
      if dmci[x].change='USERNOTE'  THEN user.usernote:=mci[x].str;
      if dmci[x].change='SYSOPNOTE' THEN user.Sysopnote:=mci[x].str;
      if dmci[x].change='ADDRESS'   THEN user.ADDRESS:=mci[x].str;
      if dmci[x].change='LOCATION'  THEN user.location:=mci[x].str;
      if dmci[x].change='ZIP'       THEN user.ZIPCODE:=mci[x].str;
      if dmci[x].change='YESNOBAR'  THEN user.yesno:=mci[x].yesnoresult;
      if dmci[x].change='EXPERT'    THEN user.xpermode:=mci[x].yesnoresult;
      if dmci[x].change='PAUSE'     THEN user.PAUSE:=mci[x].yesnoresult;
      if dmci[x].change='HOTKEY'    THEN user.hotkey:=mci[x].yesnoresult;
      if dmci[x].change='AUTOSIG'   THEN user.autosig:=mci[x].yesnoresult;
      IF DMCI[X].CHANGE='SCRLN'     THEN user.scrln:=valu(mci[x].str);
      writeuserInfo(userx);
                end;
IF DATAI.nondata=false then
begin
nseek(dataenter,filesize(dataenter));
nwrite(dataenter,r,sizeof(r));
nclose(dataenter);
end;
end;

procedure runit(n:byte);
var x:integer;
    dataenter:file{ of strarr};
    r:strarr;

begin
if loadit(n)=false then exit;
{datai.filename:=;}
nassign(dataenter,config.data_dir+datai.filename+'.ent'); {then
                    begin
                    printfile(Config.Textfile_Dir+datai.listansi+'.top',mci,false);
                    printfile(Config.Textfile_Dir+datai.listansi+'.bot',mci,false);
                    exit;
                    end;}
printfile(Config.Textfile_Dir+datai.listansi+'.top',mci,false);
repeat
nread(dataenter,r,sizeof(r));
for x:=1 to 25 do begin
                  mci[x].str:=r[x].str;
                  mci[x].yesnoresult:=r[x].yn;
                  end;
printfile(Config.Textfile_Dir+datai.listansi+'.mid',mci,false);
until eof(dataenter);
printfile(Config.Textfile_Dir+datai.listansi+'.bot',mci,false);
nclose(dataenter);
end;

begin
end.