IMPLEMENTATION NOTES
********************

REPSTR string replace utility

Copyright (C) Laszlo Menczel (menczel@invitel.hu)

Most of the program code is straightforward. Command line and parameter file
parsing is based on the functions of the MUTIL library (see mutil.txt for a
detailed description). I describe here only those parts of the program wich
actually perform string replacements.

Each source file is processed in a line-by-line fashion. Three text buffers
are defined, two of them are used for storing the currently processed line,
while the third is used as an array of flags indicating regions of the input
line (comment regions) to be ignored when matching strings:

static char txtbuf[3][TEXT_BUF_LEN];
static int text_in = 0;
static int text_out = 1;

#define TEXT_IN  txtbuf[text_in]
#define TEXT_OUT txtbuf[text_out]
#define COMM_INF txtbuf[2]

The next line is read into the buffer TEXT_IN (which may be either the first
or the second text buffer, depending on previous operations). Then for each
string pair in the rule table, the following steps are repeated:

* If comments must be ignored, the line is first scanned for comment
delimiters. The third buffer (COMM_INF) is used as a flag array: for each
position in TEXT_IN which is inside a comment, the corresponding element of
COMM_INF is set to non-zero.

* The line is scanned to find the old string of the current string pair (but
positions marked as comment are skipped). The following array is used for
storing the result of string matching:

  static int match[TEXT_BUF_LEN / 2 + 1];

The length is set to TEXT_BUF_LEN / 2 since the minimum length of strings to
match is 2 (the '+ 1' is just paranoia :-) When a match is found, the current
element of 'match' is set to the position of match in TEXT_IN, and the match
array index is incremented.

* If any match was found in the previous step, the content of TEXT_IN is
copied to TEXT_OUT, any old string found in the previous step is replaced 'on
the fly'.

* If TEXT_IN was actually copied during the previous step, TEXT_IN and TEXT_OUT
are swapped.

