The documentation follows:

The program has some large main parts:

    1) One part scans the options and their arguments from the command line.

    2) One part reads text input which not should be changed before
    the folding and writes the text to standard output.

    3) One part does the actual folding and inserts text from
    the '-i' flag. This part also cuts the words if they are too
    long and puts a '-' at the end of the cut word.

    4) One part reads input text which not should be changed after
    the folding, and writes the text to standard output.

Variables with names 'got_blabla' and 'index_blabla' refer to
the different flags the program can receive. The program doesn't
use getopts(3) and therefore has a more rigid option format
in the shell. But it's easier to handle errors this way.

The '-i' and '-D' options are handled as special cases by mfold.
Any input file is also handled as a special case by mfold.
Remaining options are handled in one separate switch construct.

The text which is to be folded is read into an internal two
dimensional 'page' buffer. This buffer has the width of one column
and the length of all the lines in ALL columns on one page. The buffer
is named 'cur_page' and is a global variable.

The folding is done in a 'while ( 1 )' loop. The first thing done
in this loop is a large 'if' statement, about 44 lines long. This
'if' statement checks if a word is larger than the line length and then
cuts the word, saves some characters in some temporary variables, named
'in_2' and 'in_3'. This construction can handle 2 (two) character
long lines. Then some newline handling is done, see the '-n'
option in the manual to understand the source easier. An 'if'
statement checks if the next character is a blank space or not a
blank space. If it is a space, the word in 'cur_word' is written to
the output, and if it's not, the character is put into 'cur_word'.
When encountering an EOF, mfold exits the 'while ( 1 )' loop.

The output is not sent to standard output directly. Instead a
function 'putcolu' is used. 'putcolu' writes to the internal
page buffer 'cur_page'. When 'cur_page' is full, the function
'flush_page' writes 'cur_page to the output. But if the '-d'
flag is used the output is written to 'putrev' instead, where
the function 'flushrev' flushes the internal reverse script
one line buffer. When the '-r' flag is set, the function
'fill_sp' fills blank space until every line is right justified.

There are some more help functions, but they are very simple
and should be understood without explanation... :-) ?


Bug reports, ideas, or patches could be sent to;
Peter Smidt   smidt@cd.chalmers.se    or
Peter Smidt   smidt@fy.chalmers.se

/Maaniker
