{==============================================================}
{			IXTEXT.PAS			       }
{Copyright (C) 1986 David E. Cortesi--see notice in IXMAIN.PAS.}
{ This include file contains declarations and code related to  }
{ reading and writing a pascal text file (straight ascii file) }
{ more in the manner of C than Pascal.	The input function     }
{ returns a CR character instead of the eoln condition, and    }
{ a ^Z when eof() appears.				       }
{   In addition, the input file de-tabifies the data, on the   }
{ expectation that it might have been worked over by an editor }
{ that compresses blanks to tabs.			       }
{							       }
{ History:						       }
{ initial writing 6/2/86				       }
{==============================================================}

var
	inpfile,	{ INDEX.DAT when program starts }
	outfile : text; { INDEX.DAT written when program ends }
	pushed : nchar; { pushed-back byte (damn borland) }
	column : integer; { current column in input }
	blanks : integer; { number of blanks to make from tab }

{------ open the input file, return true if there is one ------}
function initinp: boolean;
begin {$I- check own I/O results }
    assign(inpfile,'INDEX.INP');
    reset(inpfile);
    pushed := null;
    column := 0;
    blanks := 0;
    if (0 = IOresult) then initinp := not eof(inpfile)
    else initinp := false
end; {$I+ back to compiler checks on I/O }

{------ push back one byte of input, and damn Borland for -----}
{------ making this necessary by leaving out get/put i/o ------}
procedure pushinch(n:nchar);
begin pushed := n end;

{------ return the next byte from the text file inpfile -------}
function nextinch : nchar;
var c : char; n : nchar;
begin
    if (pushed <> null) then begin
	n := pushed;
	pushed := null
    end
    else if eof(inpfile) then n := asciieof
    else if eoln(inpfile) then begin
	readln(inpfile);
	n := asciicr;
	column := 0;
	blanks := 0
    end
    else if (blanks > 0) then begin
	n := asciiblank;
	blanks := blanks - 1;
    end
    else begin
	read(inpfile,c);
	n := ord(c);
	if (n <> asciitab) then column := column + 1
	else begin
	    blanks := 7 - (column mod 8);
	    column := column + blanks;
	    n := asciiblank
	end
    end;
    nextinch := n
end;

{------ open the output file ----------------------------------}
procedure initout;
begin
    assign(outfile,'INDEX.OUT');
    rewrite(outfile);
end;
{------ write a byte to the output - this is ONLY output ------}
procedure nextout(n:nchar);
begin
    if	    (n = asciicr) then writeln(outfile)
    else if (n = asciieof) then close(outfile)
    else write(outfile,chr(n))
end;
{------ write an integer without a leading blank --------------}
procedure intwrite(x : integer);
const
    czero = 48;
    powten : array[1..4] of integer = (10,100,1000,10000);
var
    k, p : integer;
    d : nchar;
    z : boolean;
begin
    if (x < 0) then begin
	nextout(ord('-'));
	x := abs(x)
    end;
    z := false;
    { n.b. integer division is VERY slow in 8-bit turbo }
    { yes, slower than 5 adds and 5 subtracts }
    for k := 4 downto 1 do begin
	p := powten[k];
	d := czero;
	while (x >= p) do begin
	    d := d + 1;
	    x := x - p
	end;
	if (d > czero) then z := true;
	if (z) then nextout(d)
    end;
    nextout(czero+x)
end;
 + 1;
	    x := x - p
	end;
	if (d > czero) then z := true;
	if (z) t