2019-07-22 20:32:33 +00:00
|
|
|
#ifndef SHEET_H
|
|
|
|
#define SHEET_H
|
|
|
|
|
2019-07-27 07:00:03 +00:00
|
|
|
#include "cell.h"
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* must be a prime */
|
|
|
|
#define LABEL_CACHE 29
|
|
|
|
|
|
|
|
#define ASCENDING 001
|
|
|
|
|
2019-09-05 07:24:24 +00:00
|
|
|
typedef size_t ColWidT;
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
Location soff;
|
|
|
|
CoordT sortkey; /* OR-ed value of the above constants */
|
2019-07-22 20:32:33 +00:00
|
|
|
} Sortkey;
|
|
|
|
|
|
|
|
struct Label
|
|
|
|
{
|
|
|
|
const char *label;
|
2019-07-27 04:14:26 +00:00
|
|
|
Location location;
|
2019-07-22 20:32:33 +00:00
|
|
|
struct Label *next;
|
|
|
|
};
|
|
|
|
|
2019-07-27 07:00:03 +00:00
|
|
|
typedef enum { MARK_CYCLE = 0, GET_MARK_CUR = 1, GET_MARK_ALL = 2,
|
|
|
|
MARKING = 3, MARKED = 4, UNMARKED = 5 } MarkState;
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
struct Label *labelcache[LABEL_CACHE];
|
2019-07-27 04:14:26 +00:00
|
|
|
Location cur;
|
|
|
|
Location mark1, mark2;
|
2019-09-05 07:24:24 +00:00
|
|
|
CoordT offx, offy;
|
2019-07-22 20:32:33 +00:00
|
|
|
Cell **sheet;
|
2019-09-05 07:24:24 +00:00
|
|
|
ColWidT *column;
|
|
|
|
size_t dim[HYPER];
|
|
|
|
size_t orix, oriy;
|
|
|
|
CoordT maxx, maxy;
|
|
|
|
size_t width;
|
2019-07-22 20:32:33 +00:00
|
|
|
char *name;
|
2019-07-29 15:35:10 +00:00
|
|
|
void *display;
|
2019-09-05 07:24:24 +00:00
|
|
|
size_t max_colors;
|
2019-07-29 15:35:10 +00:00
|
|
|
void *palette;
|
|
|
|
MarkState marking;
|
2019-07-22 20:32:33 +00:00
|
|
|
unsigned int changed:1;
|
|
|
|
unsigned int moveonly:1;
|
|
|
|
unsigned int clk:1;
|
|
|
|
} Sheet;
|
|
|
|
|
2019-09-05 07:24:24 +00:00
|
|
|
#define LOC_WITHINC(s,x,y,z) ((size_t)x<(s)->dim[X] && (size_t)y<(s)->dim[Y] && (size_t)z<(s)->dim[Z])
|
|
|
|
#define LOC_WITHIN(s,l) LOCATION_LT((size_t)l,(s)->dim)
|
|
|
|
#define CELL_ATC(s,x,y,z) (*((s)->sheet + ((size_t)(z))*(s)->dim[Y]*(s)->dim[X] + ((size_t)(y))*(s)->dim[X] + (x)))
|
2019-07-27 04:14:26 +00:00
|
|
|
#define CELL_AT(s,l) (CELL_ATC(s,l[X],l[Y],l[Z]))
|
|
|
|
#define CELL_IS_NULLC(s,x,y,z) (CELL_ATC(s,x,y,z) == NULLCELL)
|
|
|
|
#define CELL_IS_NULL(s,l) (CELL_AT(s,l) == NULLCELL)
|
|
|
|
#define CELL_IS_GOODC(s,x,y,z) (LOC_WITHINC(s,x,y,z) && !CELL_IS_NULLC(s,x,y,z))
|
|
|
|
#define CELL_IS_GOOD(s,l) (LOC_WITHIN(s,l) && !CELL_IS_NULL(s,l))
|
2019-09-05 07:24:24 +00:00
|
|
|
#define ALL_COORDS_IN_SHEETC(s,x,y,z) z=0; (size_t)(z)<(s)->dim[Z]; ++z) for (y=0; (size_t)(y)<(s)->dim[Y]; ++y) for (x=0; (size_t)(x)<(s)->dim[X]; ++x
|
|
|
|
#define ALL_LOCS_IN_SHEET(s,l) ALL_COORDS_IN_SHEETC(s,l[X],l[Y],l[Z])
|
2019-07-27 04:14:26 +00:00
|
|
|
#define ALL_LOCS_IN_REGION(s,l) l[Z]=(s)->mark1[Z]; l[Z]<=(s)->mark2[Z]; ++(l[Z])) for (l[Y]=(s)->mark1[Y]; l[Y]<=(s)->mark2[Y]; ++(l[Y])) for (l[X]=(s)->mark1[X]; l[X]<=(s)->mark2[X]; ++(l[X])
|
2019-09-05 07:24:24 +00:00
|
|
|
#define ALL_CELLS_IN_SHEET(s,i,c) i=0,c=*((s)->sheet); i<(s)->dim[X]*(s)->dim[Y]*(s)->dim[Z]; ++i, c=*((s)->sheet+i)
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
extern Sheet *upd_sheet;
|
2019-07-27 04:14:26 +00:00
|
|
|
extern Location upd_l;
|
2019-07-22 20:32:33 +00:00
|
|
|
extern int max_eval;
|
|
|
|
|
2019-07-27 04:14:26 +00:00
|
|
|
void initialize_sheet(Sheet *sheet);
|
2019-09-05 07:24:24 +00:00
|
|
|
void resize(Sheet *sheet, CoordT x, CoordT y, CoordT z, bool *qextended);
|
Make tpa the default file format for Teapot
There turned out to be one blocking technical issue for full adpotion of
tpa format, and that was the fact that the printed representation of
floating values inside the tpa file might not reproduce the same double
when read. This change therefore introduces the "hexact" floating point
format, based on the the %La format string, which produces a hex
representation with exact round trips. While working on this, it was
convenient to add a new representation "compact" which is basically the
shorter of decimal and scientific representations, without trailing zeros.
This is now the default float format, but of course one can select decimal
or scientific formats to restore prior appearance. However, full-precision
compact format is now the (only) format for editing cell contents, as it
is accurate and efficient. Of course you can enter floating point values
in any format you like when typing in a formula.
The addition of several new floating point options overloaded the menus
in terminal teapot, so this change also revamps those menus slightly,
including eliminating the unused MenuChoice struct, and just specifying menus
with an array of strings.
Closes #63.
2019-08-24 16:58:46 +00:00
|
|
|
Cell *initcellofsheet(Sheet *sheet, const Location at, bool *qnew);
|
Streamline internals of teapot
The primary change is to add a “funcall” token, so that an entire expression
can be encapsulated as a single token. This change is used to allow a cell to
include simply a selection of appropriate semantic tokens. I.e., the content
and iterative content are now each a single token like the value and the
result value. Token vectors are used only as intermediate results in scanning
and parsing.
Not this means the cells are now in effect storing parse trees, so
computation should be slightly faster and future extensions (like #56) should
be facilitated.
This commit also takes the opportunity while internals are being altered to
add another token to a cell for future use for computed attributes, cf #22,
and to change the internal numerical values from double and ints to long
doubles and long longs. However, the change attempts to encapsulate that
choice so it would be easy to change back or change to another representation.
Note that these changes break savexdr(), as the internal binary format of
a cell is now different. Rather than reimplement it, it is deprecated as
the world does not need another binary spreadsheet format. Hence, the
ascii format for teapot spreadsheets becomes the primary file format.
Loading of old xdr files is still supported for backward compatibility.
Closes #59.
Also along the way, various other slight fixes and enhancements crept in,
a partial but probably not exhaustive list of which follows:
Fixes #31.
Further revisions and improvements to documentation.
Make the approximate comparison of floating point values scale more
accurately with the size of the doubles being compared.
Further extensions of absolute and relative cell addressing.
Addition of (circle constant) tau function/constant.
Modified string conversion to simply use internal printing routines, and
to take "scientific" and "decimal" keywords.
Allowed n() function to take a list of values, or just a single location
defaulting to the current location.
Added floor, ceil, trunc, and round functions, and allowed them to be
keywords controlling the int() integer conversion function as well.
Allowed substr() to drop its last argument to go to the end of the string.
Provided an enum of built-in functions to preserve legacy function
identifiers, allowing the large table inside func.c to be reorganized
in a clearer fashion.
Added additional annotation of properties of the built-in functions,
including precedence.
All operators are now also accessible as built-in functions.
Made precedence of unary - lower than ^ to match python.
Avoided inadvertently using FLTK @symbol abbreviations for formulas with
"@" in them.
2019-08-23 19:12:06 +00:00
|
|
|
void copycelltosheet(const Cell *fromcell, Sheet *sheet2,
|
|
|
|
const Location to, LabelHandling lh);
|
2019-07-27 04:14:26 +00:00
|
|
|
Cell *safe_cell_at(Sheet *sheet, const Location at);
|
Streamline internals of teapot
The primary change is to add a “funcall” token, so that an entire expression
can be encapsulated as a single token. This change is used to allow a cell to
include simply a selection of appropriate semantic tokens. I.e., the content
and iterative content are now each a single token like the value and the
result value. Token vectors are used only as intermediate results in scanning
and parsing.
Not this means the cells are now in effect storing parse trees, so
computation should be slightly faster and future extensions (like #56) should
be facilitated.
This commit also takes the opportunity while internals are being altered to
add another token to a cell for future use for computed attributes, cf #22,
and to change the internal numerical values from double and ints to long
doubles and long longs. However, the change attempts to encapsulate that
choice so it would be easy to change back or change to another representation.
Note that these changes break savexdr(), as the internal binary format of
a cell is now different. Rather than reimplement it, it is deprecated as
the world does not need another binary spreadsheet format. Hence, the
ascii format for teapot spreadsheets becomes the primary file format.
Loading of old xdr files is still supported for backward compatibility.
Closes #59.
Also along the way, various other slight fixes and enhancements crept in,
a partial but probably not exhaustive list of which follows:
Fixes #31.
Further revisions and improvements to documentation.
Make the approximate comparison of floating point values scale more
accurately with the size of the doubles being compared.
Further extensions of absolute and relative cell addressing.
Addition of (circle constant) tau function/constant.
Modified string conversion to simply use internal printing routines, and
to take "scientific" and "decimal" keywords.
Allowed n() function to take a list of values, or just a single location
defaulting to the current location.
Added floor, ceil, trunc, and round functions, and allowed them to be
keywords controlling the int() integer conversion function as well.
Allowed substr() to drop its last argument to go to the end of the string.
Provided an enum of built-in functions to preserve legacy function
identifiers, allowing the large table inside func.c to be reorganized
in a clearer fashion.
Added additional annotation of properties of the built-in functions,
including precedence.
All operators are now also accessible as built-in functions.
Made precedence of unary - lower than ^ to match python.
Avoided inadvertently using FLTK @symbol abbreviations for formulas with
"@" in them.
2019-08-23 19:12:06 +00:00
|
|
|
Cell *safe_cell_atc(Sheet *sheet, int x, int y, int z);
|
2019-07-27 04:14:26 +00:00
|
|
|
Cell *curcell(Sheet *sheet);
|
2019-07-22 20:32:33 +00:00
|
|
|
void cachelabels(Sheet *sheet);
|
|
|
|
void freesheet(Sheet *sheet, int all);
|
|
|
|
void forceupdate(Sheet *sheet);
|
2019-07-27 04:14:26 +00:00
|
|
|
MarkState getmarkstate(Sheet *sheet);
|
Prevent phantom values when clocking, resetting, and clocking again
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.
2019-07-24 17:47:39 +00:00
|
|
|
void dump_current_cell(Sheet *sheet);
|
2019-07-27 07:00:03 +00:00
|
|
|
void freecellofsheet(Sheet *sheet, const Location at);
|
2019-09-05 07:24:24 +00:00
|
|
|
ColWidT columnwidth(Sheet *sheet, CoordT x, CoordT z);
|
|
|
|
bool setwidth(Sheet *sheet, CoordT x, CoordT z, ColWidT width);
|
|
|
|
ColWidT cellwidth(Sheet *sheet, const Location at);
|
Streamline internals of teapot
The primary change is to add a “funcall” token, so that an entire expression
can be encapsulated as a single token. This change is used to allow a cell to
include simply a selection of appropriate semantic tokens. I.e., the content
and iterative content are now each a single token like the value and the
result value. Token vectors are used only as intermediate results in scanning
and parsing.
Not this means the cells are now in effect storing parse trees, so
computation should be slightly faster and future extensions (like #56) should
be facilitated.
This commit also takes the opportunity while internals are being altered to
add another token to a cell for future use for computed attributes, cf #22,
and to change the internal numerical values from double and ints to long
doubles and long longs. However, the change attempts to encapsulate that
choice so it would be easy to change back or change to another representation.
Note that these changes break savexdr(), as the internal binary format of
a cell is now different. Rather than reimplement it, it is deprecated as
the world does not need another binary spreadsheet format. Hence, the
ascii format for teapot spreadsheets becomes the primary file format.
Loading of old xdr files is still supported for backward compatibility.
Closes #59.
Also along the way, various other slight fixes and enhancements crept in,
a partial but probably not exhaustive list of which follows:
Fixes #31.
Further revisions and improvements to documentation.
Make the approximate comparison of floating point values scale more
accurately with the size of the doubles being compared.
Further extensions of absolute and relative cell addressing.
Addition of (circle constant) tau function/constant.
Modified string conversion to simply use internal printing routines, and
to take "scientific" and "decimal" keywords.
Allowed n() function to take a list of values, or just a single location
defaulting to the current location.
Added floor, ceil, trunc, and round functions, and allowed them to be
keywords controlling the int() integer conversion function as well.
Allowed substr() to drop its last argument to go to the end of the string.
Provided an enum of built-in functions to preserve legacy function
identifiers, allowing the large table inside func.c to be reorganized
in a clearer fashion.
Added additional annotation of properties of the built-in functions,
including precedence.
All operators are now also accessible as built-in functions.
Made precedence of unary - lower than ^ to match python.
Avoided inadvertently using FLTK @symbol abbreviations for formulas with
"@" in them.
2019-08-23 19:12:06 +00:00
|
|
|
void puttok(Sheet *sheet, const Location at, Token t, TokVariety v);
|
|
|
|
Token recompvalue(Sheet *sheet, const Location at);
|
2019-08-28 19:40:50 +00:00
|
|
|
Token evaluate_at(Token t, Sheet *sheet, const Location at);
|
2019-07-22 20:32:33 +00:00
|
|
|
void update(Sheet *sheet);
|
2019-07-27 04:14:26 +00:00
|
|
|
char *geterror(Sheet *sheet, const Location at);
|
2019-09-03 08:41:37 +00:00
|
|
|
size_t printvalue(char *s, size_t size, size_t chars, StringFormat sf,
|
2019-09-05 07:24:24 +00:00
|
|
|
FloatFormat ff, PrecisionLevel precision,
|
|
|
|
Sheet *sheet, const Location at);
|
2019-09-03 08:41:37 +00:00
|
|
|
Style getstyle(Sheet *sheet, const Location at);
|
|
|
|
Adjust getadjust(Sheet *sheet, const Location at);
|
|
|
|
bool shadowed(Sheet *sheet, const Location at);
|
|
|
|
bool isbold(Sheet *sheet, const Location at);
|
|
|
|
bool underlined(Sheet *sheet, const Location at);
|
|
|
|
ColorNum getcolor(Sheet *sheet, const Location at, ColorAspect aspect);
|
|
|
|
bool transparent(Sheet *sheet, const Location at);
|
|
|
|
FloatFormat getfltformat(Sheet *sheet, const Location at);
|
|
|
|
PrecisionLevel getprecision(Sheet *sheet, const Location at);
|
|
|
|
bool overridestyle(Sheet *sheet, const Location at, Style sty);
|
Make tpa the default file format for Teapot
There turned out to be one blocking technical issue for full adpotion of
tpa format, and that was the fact that the printed representation of
floating values inside the tpa file might not reproduce the same double
when read. This change therefore introduces the "hexact" floating point
format, based on the the %La format string, which produces a hex
representation with exact round trips. While working on this, it was
convenient to add a new representation "compact" which is basically the
shorter of decimal and scientific representations, without trailing zeros.
This is now the default float format, but of course one can select decimal
or scientific formats to restore prior appearance. However, full-precision
compact format is now the (only) format for editing cell contents, as it
is accurate and efficient. Of course you can enter floating point values
in any format you like when typing in a formula.
The addition of several new floating point options overloaded the menus
in terminal teapot, so this change also revamps those menus slightly,
including eliminating the unused MenuChoice struct, and just specifying menus
with an array of strings.
Closes #63.
2019-08-24 16:58:46 +00:00
|
|
|
bool setadjust(Sheet *sheet, const Location at, Adjust adjust);
|
|
|
|
bool shadow(Sheet *sheet, const Location at, bool yep);
|
|
|
|
bool bold(Sheet *sheet, const Location at, bool yep);
|
|
|
|
bool underline(Sheet *sheet, const Location at, bool yep);
|
2019-08-29 06:19:08 +00:00
|
|
|
bool setcolor(Sheet *sheet, const Location at, ColorAspect asp, ColorNum col);
|
Make tpa the default file format for Teapot
There turned out to be one blocking technical issue for full adpotion of
tpa format, and that was the fact that the printed representation of
floating values inside the tpa file might not reproduce the same double
when read. This change therefore introduces the "hexact" floating point
format, based on the the %La format string, which produces a hex
representation with exact round trips. While working on this, it was
convenient to add a new representation "compact" which is basically the
shorter of decimal and scientific representations, without trailing zeros.
This is now the default float format, but of course one can select decimal
or scientific formats to restore prior appearance. However, full-precision
compact format is now the (only) format for editing cell contents, as it
is accurate and efficient. Of course you can enter floating point values
in any format you like when typing in a formula.
The addition of several new floating point options overloaded the menus
in terminal teapot, so this change also revamps those menus slightly,
including eliminating the unused MenuChoice struct, and just specifying menus
with an array of strings.
Closes #63.
2019-08-24 16:58:46 +00:00
|
|
|
bool lockcell(Sheet *sheet, const Location at, bool yep);
|
|
|
|
bool maketrans(Sheet *sheet, const Location at, bool yep);
|
|
|
|
bool igncell(Sheet *sheet, const Location at, bool yep);
|
2019-07-27 04:14:26 +00:00
|
|
|
void clk(Sheet *sheet, const Location at);
|
Make tpa the default file format for Teapot
There turned out to be one blocking technical issue for full adpotion of
tpa format, and that was the fact that the printed representation of
floating values inside the tpa file might not reproduce the same double
when read. This change therefore introduces the "hexact" floating point
format, based on the the %La format string, which produces a hex
representation with exact round trips. While working on this, it was
convenient to add a new representation "compact" which is basically the
shorter of decimal and scientific representations, without trailing zeros.
This is now the default float format, but of course one can select decimal
or scientific formats to restore prior appearance. However, full-precision
compact format is now the (only) format for editing cell contents, as it
is accurate and efficient. Of course you can enter floating point values
in any format you like when typing in a formula.
The addition of several new floating point options overloaded the menus
in terminal teapot, so this change also revamps those menus slightly,
including eliminating the unused MenuChoice struct, and just specifying menus
with an array of strings.
Closes #63.
2019-08-24 16:58:46 +00:00
|
|
|
bool setfltformat(Sheet *sheet, const Location at, FloatFormat ff);
|
2019-09-03 08:41:37 +00:00
|
|
|
bool setprecision(Sheet *sheet, const Location at, PrecisionLevel precision);
|
2019-07-27 04:14:26 +00:00
|
|
|
void setlabel(Sheet *sheet, const Location at, const char *buf, int update);
|
2019-07-22 20:32:33 +00:00
|
|
|
Token findlabel(Sheet *sheet, const char *label);
|
2019-07-27 04:14:26 +00:00
|
|
|
void relabel(Sheet* sheet, const Location at,
|
|
|
|
const char *oldlabel, const char *newlabel);
|
|
|
|
|
|
|
|
const char *savetbl(Sheet *sheet, const char *name, int body, const Location beg, const Location end, unsigned int *count);
|
|
|
|
const char *savetext(Sheet *sheet, const char *name, const Location beg, const Location end, unsigned int *count);
|
|
|
|
const char *savecsv(Sheet *sheet, const char *name, char sep, const Location beg, const Location end, unsigned int *count);
|
2019-07-22 20:32:33 +00:00
|
|
|
const char *saveport(Sheet *sheet, const char *name, unsigned int *count);
|
|
|
|
const char *loadport(Sheet *sheet, const char *name);
|
|
|
|
const char *loadcsv(Sheet *sheet, const char *name);
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-09-05 07:24:24 +00:00
|
|
|
void insertcube(Sheet *sh, const Location beg, const Location end, Dimensions dm);
|
|
|
|
void deletecube(Sheet *sh, const Location beg, const Location end, Dimensions dm);
|
|
|
|
void moveblock(Sheet *sheet, const Location beg, const Location end,
|
|
|
|
const Location dest, int copy);
|
|
|
|
const char *sortblock(Sheet *sheet, const Location beg, const Location end,
|
|
|
|
Dimensions dm, Sortkey *sk, size_t sklen);
|
|
|
|
void mirrorblock(Sheet *sh, const Location beg, const Location end, Dimensions dm);
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|