{  $LIST+, $DEBUG+, $BRAVE+, $LINESIZE:132, $PAGESIZE:80, $OCODE+   }
{  $ERRORS:50, $MATHCK+, $RANGECK+, $INITCK+, $INDEXCK+, $ENTRY+    }
{  $LINE+, $RUNTIME+, $SYMTAB+, $WARN+, $GOTO-     }
{  $TITLE:'Record Handler  ---  AEM$SCRATCH'             }
{  $MESSAGE:'PASCAL - COMPILATION OPTIONS SET'     }
{  $MESSAGE:'SYSTEM - COMPILATION BEGINS'          }

module file_aux_code;

const
   maxname =   20;
   maxstrg =   30;
   blank   =   ' ';

type
   s10         =   string(10);
   stindex     =   byte;
   idxrng      =   0..30;
   varstrng    =   lstring(maxname);
   fixstrng    =   string(maxname);
   maxstrng    =   string(maxstrg);
   maxlstrng   =   lstring(maxstrg);

   entrytype   =   record
       name    :   record
           lastname, firstname : fixstrng;
           midinit : char
       end;
       addr    :   record
           street  : maxstrng;
           city    : fixstrng;
           state   : string (2);
           zip     : string(5)
       end;
       phone   :   record
           number  : string(8);
           areacod : string(3)
       end;
       dob : string(8)
   end;

   nodeptr     =   ^node;
   node    = record
       entry :  entrytype;
       next : nodeptr
   end;

var [static,public]
   curtime, curdate : s10;

procedure cls; extern;
procedure time (var s: string); extern;
procedure date (var s: string); extern;
procedure locate (row, column : integer) ;extern;
procedure beep; extern;
procedure lookup (const key:entrytype;var current,previous:nodeptr;
                  const hol:nodeptr;var found : boolean);extern;
procedure keyboard (var destination : string; var length:idxrng; width:integer); extern;

procedure recdisp (const curdisp : nodeptr; const reccount : integer);

   var
    i : idxrng;
      recname : fixstrng;
   begin
       recname := curdisp^.entry.name.lastname;
       for i := 1 to 20 do
           if recname [i] in ['a'..'z'] then
               recname [i] := chr(ord(recname[i]) - 32);
       cls;
       locate (1,1);   time (curtime);  date (curdate);
       write (output, 'Page:  DISPLAY', null : 4, 'Primary key cannot be modified');
       locate (2,1); write (output, 'Time: ', curtime, null:3, 'Date: ', curdate);
       locate (4,1);    write (output, '*Current Record: ', recname);
       with curdisp^.entry do
           begin
               locate (6,1); write (output, 'First Name: ', name.firstname);
               locate (6,40); write (output, 'Middle Initial: ', name.midinit);
               locate (7,1); write (output, 'Last Name: ', name.lastname);
               locate (9,1); write (output, 'Address:');
               locate (11, 1); write (output, 'Street: ', addr.street);
               locate (12, 1); write (output, 'City: ', addr.city);
               locate (12,41); write (output, 'State: ', addr.state);
               locate (12,56); write (output, 'Zip code: ', addr.zip);
               locate (14,1); write (output, 'Area code: ', phone.areacod);
               locate (14, 17); write (output, 'Phone: ', phone.number);
               locate (16,1); write (output, 'Birthday: ', dob)
           end;
       locate (20,1); write (output, 'Last name cannot be modified');
       locate (22,1); write (output, 'Type the new value, or <RETURN> for no change');
   end;
procedure view (const hol : nodeptr);

var
   viewrec : entrytype;
   current,previous : nodeptr;
   found : boolean;
   length, i : idxrng;
begin
   cls;
   time (curtime);  date (curdate);
   locate (1,1); write (output, 'Time: ', curtime, null:3, 'Date: ', curdate);
   locate (4,1); write (output, 'Type LAST name of record to view -->');
   locate (4,38); for i := 1 to 20 do write (output, '.');
	locate (4,38);
   keyboard (viewrec.name.lastname, length, 20);  locate (4,38);
   for i := length + 1 to 20 do [ viewrec.name.lastname[i] := blank; write (output, blank) ];
   lookup (viewrec,current,previous,hol,found);
   if found then
       recdisp (current,01)
   else
       begin
           cls;
           locate (4,1); writeln;
           writeln (output, '*Requested record (', viewrec.name.lastname, ')  NOT found');
           writeln; writeln (output, 'Strike any key to proceed to primary options...');
           keyboard (viewrec.name.lastname,length,1);
           return
       end;
	locate (20,1); write (output, null: 70);
	locate (22,1); write (output, null: 70);
	locate (23,1); write (output, null: 60);
	locate (23,1); write (output, 'Strike any key to return to primary options');
	keyboard (viewrec.name.lastname,length,1)
end; {procedure}
procedure getdata (var newrecord : entrytype);

label
   1, 2;
var
   length, i : idxrng;
   tempstring : maxstrng;
   index : integer;
   reply :char;

   procedure pad (var s : string; curlen, maxlen : idxrng);
   var index : idxrng;
   begin   { pad }
       if curlen < maxlen then
           for index := curlen+1 to maxlen do
               s [index] := blank
   end;  {pad}
begin   {insert information into record and exit back to primary}
1: cls;
   time (curtime);  date (curdate);
   locate (2,1);
   write (output, 'Time: ',curtime, '   Date: ', curdate);
   locate (1,1);   write ('Add Record:');
   locate (1,23);  write ('Data Entry:');
   locate (1,70);  write ('*NEW*');
   locate (3,1);
   for index := 1 to 79 do write ('-');
   locate (5,1);   write ('Last Name:');
   locate (5,12);  for i := 1 to 20 do write ('.');
   locate (5,40);  write ('Middle Initial:');
   locate (5,56);  write ('.');
   locate (7,1);   write ('First Name:');
   locate (7,13);  for i := 1 to 20 do write ('.');
   locate (7,40);  write ('D.O.B.:');
   locate (7,48);  write ('../../..');
   locate (9,1);   write ('Street:');
   locate (9,9);   for i := 1 to 30 do write ('.');
   locate (11,1);  write ('City:');
   locate (11,7);  for i := 1 to 20 do write ('.');
   locate (11,33); write ('State:');
   locate (11,41); write ('..');
   locate (11,46); write ('Zip Code:');
   locate (11,56); write ('.....');
   locate (13,1);  write ('Phone:');
   locate (13,09);  write ('...-....');
   locate (13,21); write ('Area Code:');
   locate (13,32); write ('(...)');
{now get the actual data items input with keyboard}
   with newrecord do
       begin
           locate (5,12);
           keyboard (name.lastname, length, 20);
           pad (name.lastname,length,20);
           beep;
           for i := length+1 to 20 do write (output,blank);
           locate (5,56);  keyboard (name.midinit,length,1);
           beep;
           locate (7,13);
           keyboard (name.firstname, length, 20);
           pad (name.firstname,length,20);
           beep;
           for i := length+1 to 20 do write (output, blank);
           locate (7,48);
           keyboard (dob, length, 08);
           pad (dob,length,08);
           beep;
           for i := length+1 to 10 do write(output, blank);
           locate (9,9);
           keyboard (addr.street, length, 30);
           pad (addr.street,length,30);
           beep;
           for i := length+1 to 30 do write (output,blank);
           locate (11,7);
           keyboard (addr.city, length, 20);
           pad (addr.city,length,20);
           beep;
           for i := length+1 to 20 do write (output, blank);
           locate (11,41);
           keyboard (addr.state, length, 02);
           pad (addr.state,length,02);
           beep;
           for i := length+1 to 2 do write (output, blank);
           locate (11, 56);
           keyboard (addr.zip, length, 5);
           pad (addr.zip,length,5);
           beep;
           for i := length+1 to 5 do write (output, blank);
           locate (13,09);
           keyboard (phone.number, length, 8);
           pad(phone.number,length,8);
           beep;
           for i := length+1 to 8 do write (output, blank);
           locate (13,33);
           keyboard (phone.areacod, length, 3);
           pad(phone.areacod,length,3);
           for i := length+1 to 3 do write (output, blank);
           beep
       end;
2: locate (22,1);     write (null : 60);
   locate (20,1);
   write (output, 'Is this record correct?  ');
   keyboard (reply,length,1);
   if (reply = 'N') or (reply = 'n') then
       goto 1
   else
      if (reply = 'y') or (reply = 'Y') then
           return     {go back to caller}
   else      {reply was bad}
       begin
           locate (22,1);
           write (output, '*Bad reply -- restart - key <ENTER>');
           keyboard (reply, i, 1);
           goto 2
       end
end;  {procedure for data entry}
end.  {module}
