| Library Reference
           
 
 
#include "source.h"
SrcBufPtr SrcBuffer;
char *SRCFILE;
char *TEXTSTART;
void initBuf(char *name, int f);
void refillBuf(char *p);
int finlBuf();
 
The source module has been designed to allow rapid access to the
characters of a text file.
A text file is a sequence of lines,
each terminated by a newline character.
There is no limit on the length of a line.
The source module guarantees that if the first character of a line is in
memory then all of the characters of that line, including the terminating
newline character, are in contiguous memory locations.
The newline terminating the last line in memory is followed by an ASCII NUL
character, and thus the sequence of lines constitutes a C string.
NUL characters are not allowed within the text file.
 
To use the module, first call initBuf, with a file name and descriptor.
The file must be opened for reading (byopen(2)prior to the call.
Upon return,SrcBufferpoints to a new text buffer,SRCFILEis the symbolic name of the input file,
andTEXTSTARTpoints to the first character of the first line of the
input file.
(If the input file is empty thenTEXTSTARTpoints to an ASCII NUL
character.) 
SRCFILEandTEXTSTARTare components of the text buffer;TEXTSTARTmay be arbitrarily altered by any client of the source
module.
Normally,TEXTSTARTis used to describe the position reached by the
client in processing the buffer's text.
Because it is a component of the text buffer, there is no need to save and
restore it when another text buffer is created by a subsequent invocation
ofinitBuf. 
All source module operations take place on the text buffer pointed to by
SrcBuffer, and bothSRCFILEandTEXTSTARTuseSrcBufferto access the text buffer.
A client of the source module may manage a number of text buffers
simultaneously by saving and restoringSrcBuffer. 
When a client has processed all of the information in a text buffer,
additional information can be obtained from the file by invoking
refillBufwith a pointer to the text in the buffer.
At least one line of text will be added to the text pointed to by the
argument ofrefillBuf, and upon returnTEXTSTARTpoints to
the first character of the augmented text.
The content of the memory pointed to by the argument ofrefillBufis undefined.
(If there is no more information in the file then the string pointed
to by the argument ofrefillBufis not augmented.
Upon returnTEXTSTARTpoints to the first character of that string
and the content of the memory pointed to by the argument ofrefillBufis undefined.) 
Invocation of finlBuffrees all storage for the text buffer pointed
to bySrcBuffer.
Upon return,SrcBuffercontains a null pointer and the value offinlBufis the descriptor of the file associated with the buffer.
The file itself has not been closed. 
 
 
           
 |