Compiling for szadb

Lets have a closer look at the C program below. Its stated purpose is to replace, if possible, runs of white space with tabs. The width of a tab is fixed and equal to a constant TABSTOP. If a text line is getting too long then substitutions are abandoned and remaining characters are copied without modifications.


unexpand.c


This program has actually two bugs. See if you can find them just examinig the source.

Here is how szadb can help. Compile source as follows (these commands are for Sozobon C)

cc -t -O -o unexpand.tos unexpand.c
Flag -O is not necessary but with this particular compiler you will probably find a disassembled code easier to follow. You may test the compiled executable on its own source.
unexpand.tos <unexpand.c >output
In the first moment the program appears to work, but a closer examination of the output reveals that the indentation is not exactly right. Moreover, some lines start with a blank, followed by a tab, which is not really what was intended. There are also other problems. Check yourself. The likely suspect will be an array tabs of tabstops filled by a function settab().