In general, the goal of these changes is to be more type-specific wherever
possible, reduce duplicated code, and avoid magic numbers. The biggest
individual change is to use Location triples of integers wherever possible
rather than three separate int variables. Another very helpful change for
understanding what is going on in the code is introducing the MarkState enum
for tracking the process of marking and unmarking blocks of cell.
The MarkState change was motivated by the issues with Ctrl-C,
and this commit, in fact,
resolves#28.
Because of the lack of a test harness, it is possible that a change of
this scope has created some bugs as well, but teapot was running OK for
me at the time of the commit. However, I don't know how good my coverage of
the changed code was -- I certainly did not save or load a Lotus 1-2-3 file!
In the end it turned out that the cause of the phantom values was
short-cutting in getvalue() when the contents of a cell were empty,
preventing the update of the internal cache of the value of the cell.
However, tracking this down (and getting the associated memory management
correct) necessitated implementing a debugging mode in which I could
dump the internal states of cells and print various other stuff to standard
output. It also involved understanding the meaning of various pointers in
the code, in the process of which I renamed some commonly used macros,
particularly the former SHEET(s,x,y,z) which was not returning a Sheet at
all but rather a pointer to a Cell. So this macro is now called CELL_AT. I
also replaced several very repeatedly used patterns of checking the validity
of locations and pointers with macros, now defined in sheet.h.
Therefore, unfortunately the (relatively small in the end) bugfix for this
major issue is entangled with numerous textual changes to the code made
in tracking it down.
Fixes#18.
Closes#19.