teapot-spreadsheet/src/common/sheet.h

140 lines
5.6 KiB
C
Raw Normal View History

#ifndef SHEET_H
#define SHEET_H
#include "cell.h"
#ifdef __cplusplus
extern "C" {
#endif
/* must be a prime */
#define LABEL_CACHE 29
#define ASCENDING 001
typedef size_t ColWidT;
typedef struct
{
Location soff;
CoordT sortkey; /* OR-ed value of the above constants */
} Sortkey;
struct Label
{
const char *label;
Location location;
struct Label *next;
};
typedef enum { MARK_CYCLE = 0, GET_MARK_CUR = 1, GET_MARK_ALL = 2,
MARKING = 3, MARKED = 4, UNMARKED = 5 } MarkState;
typedef struct
{
struct Label *labelcache[LABEL_CACHE];
Location cur;
Location mark1, mark2;
CoordT offx, offy;
Cell **sheet;
ColWidT *column;
size_t dim[HYPER];
size_t orix, oriy;
CoordT maxx, maxy;
size_t width;
char *name;
void *display;
size_t max_colors;
void *palette;
MarkState marking;
unsigned int changed:1;
unsigned int moveonly:1;
unsigned int clk:1;
} Sheet;
#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)))
#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))
#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])
#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])
#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)
extern Sheet *upd_sheet;
extern Location upd_l;
extern int max_eval;
void initialize_sheet(Sheet *sheet);
void resize(Sheet *sheet, CoordT x, CoordT y, CoordT z, bool *qextended);
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);
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);
Cell *curcell(Sheet *sheet);
void cachelabels(Sheet *sheet);
void freesheet(Sheet *sheet, int all);
void forceupdate(Sheet *sheet);
MarkState getmarkstate(Sheet *sheet);
void dump_current_cell(Sheet *sheet);
void freecellofsheet(Sheet *sheet, const Location at);
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);
Token evaluate_at(Token t, Sheet *sheet, const Location at);
void update(Sheet *sheet);
char *geterror(Sheet *sheet, const Location at);
size_t printvalue(char *s, size_t size, size_t chars, StringFormat sf,
FloatFormat ff, PrecisionLevel precision,
Sheet *sheet, const Location at);
Style getstyle(Sheet *sheet, const Location at);
bool shadowed(Sheet *sheet, const Location at);
bool transparent(Sheet *sheet, const Location at);
PrecisionLevel getprecision(Sheet *sheet, const Location at);
bool overridestyle(Sheet *sheet, const Location at, Style sty);
bool setadjust(Sheet *sheet, const Location at, Adjust adjust);
bool shadow(Sheet *sheet, const Location at, bool yep);
bool makedim(Sheet *sheet, const Location at, bool yep);
bool embolden(Sheet *sheet, const Location at, bool yep);
bool italicize(Sheet *sheet, const Location at, bool yep);
bool underline(Sheet *sheet, const Location at, bool yep);
bool setcolor(Sheet *sheet, const Location at, ColorAspect asp, ColorNum col);
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);
void clk(Sheet *sheet, const Location at);
bool setfltformat(Sheet *sheet, const Location at, FloatFormat ff);
bool setprecision(Sheet *sheet, const Location at, PrecisionLevel precision);
void setlabel(Sheet *sheet, const Location at, const char *buf, int update);
Token findlabel(Sheet *sheet, const char *label);
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);
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);
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);
#ifdef __cplusplus
}
#endif
#endif