{$C-}
Program Index;

type  Str255 = string[255];
      str39  = string[39];

      dataptr = ^strdata;

      strdata = record
                pg : integer;
                data : str39;
                end;
      soc     = set of char;

const
      word_mark   = $0b;   {^K}
      Phrase_mark = $10;   {^P}
      Word_len    =  39;
      LastCol     =  40;
      Page_len    : integer = 66;
      Def_LMargin : integer =  8;
      Def_RMargin : integer = 72;
      Def_TMargin : integer =  3;
      Def_BMargin : integer = 8;
      endd        = 2500;

var
      strptr      : array [1..endd] of dataptr;

      c           : char;
      Char_count : real;
      Word_count,
      Line_count,
      This_line,
      entries,
      This_page,
      Read_page,
      Page_size,
      Lmargin,
      RMargin,
      End_of_Primary_List  : integer;

      Found_index,
      PAS_file,
      pass2,
      Search_twice,
      Word_Found   : boolean;

      F1,F2,F3    : text;
      InName        : string[14];

var   Current_Page,
      Current_line,
      Total_line,
      x,y,z           : integer;
      Trailer        : string[$7F] absolute $80;
      line            : string[255];

      ch              : char;

{.pa}
{$I index.doc}
{.pa}
{$I INDEX.1  }
{.pa}
{$I INDEX.2  }
{.pa}
{$I INDEX.3  }
{.pa}
begin
Search_Twice := false;
Found_index := false;
PAS_file := false;
clrscr;
gotoxy (1,4);
write ('Enter file to be INDEXED <              >');
if length(Trailer) <> 0 then
    begin
    delete (trailer,1,1);
    gotoxy (27,4); write (trailer);
    end;
repeat
    gotoxy (27,4);
    if length(trailer) > 0 then
        InName := Trailer
      else
        readln (InName);
    Trailer := '';
    if length(InName) <> 0 then
        begin
        x := bdos($19);      { get loged drive           }
        bdos ($0D,$00);      { reset disk system         }
        bdos ($0E,x);        { Select logged drive again }
        Assign (F1,InName);
        {$I-}  reset (F1);   {$I+}
        end;
    until (ioresult = 0) or (length(InName) = 0);
if length(InName) = 0 then exit;

assign (F2,root(InName)+'.$$$');
{$I-}  rewrite (F2);  {$I+}
if ioresult <> 0 then
    begin
    writeln (' Trouble opening output file');
    exit;
    end;
writeln;
if pos('.PAS',StrUpper(InName)) <>0 then
    begin
    gotoxy (1,6);
    write ('Condenced print (Y/N)  < >');
    repeat
        ch := ^@;
        gotoxy (25,6);
        if keypressed then
            read (kbd,ch);
        ch := upcase(ch);
        if ch <> ^@ then
            write (ch);
        until ch in ['Y','N',^[];
    if Ch = ^[ then exit;
    if ch = 'Y' then
        begin
        Def_LMargin :=  11;
        Def_RMargin := 102;
        Def_TMargin :=   6;
        Def_BMargin :=  12;
        Page_len    :=  88;
        PAS_file     := true;
        Search_Twice := True;
        end;
    end;
writeln;

{.pa}
{  Now read file looking for marked words }

writeln;
writeln (' reading input file ');

index;
cleanup;
sort;
writeln (' Writing Index to disk');
dump;

Close (F2);
Close (F1);
assign (F3,root(InName) + '.BAK');
{$I-}  erase (F3);  {$I+}
if ioresult = 0 then
    close (F3);

rename (F1,root(InName) + '.BAK');
assign (F2,root(InName)+'.$$$');
rename (F2,InName);
end.


..Index
 
.pa
.FI index11.IDX
 
root(InName) + '.BAK');
assign (F2,root(InName)+'.$$$');
rename (F2,InName);
end.


..In