2019-07-22 20:32:33 +00:00
|
|
|
/* #includes */ /*{{{C}}}*//*{{{*/
|
|
|
|
#ifdef DMALLOC
|
|
|
|
#include "dmalloc.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
2019-07-27 04:14:26 +00:00
|
|
|
#include <stdbool.h>
|
2019-07-22 20:32:33 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "csv.h"
|
|
|
|
#include "default.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "eval.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "scanner.h"
|
|
|
|
#include "sheet.h"
|
|
|
|
#include "utf8.h"
|
|
|
|
#include "xdr.h"
|
|
|
|
|
|
|
|
/*}}}*/
|
|
|
|
/* #defines */ /*{{{*/
|
|
|
|
#define HASH(x,s) \
|
|
|
|
{ \
|
|
|
|
const unsigned char *S=(const unsigned char*)s; \
|
|
|
|
\
|
|
|
|
x=0; \
|
|
|
|
while (*S) { x=(x<<5)+((x>>27)^*S); ++S; } \
|
|
|
|
x%=LABEL_CACHE; \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*}}}*/
|
|
|
|
|
|
|
|
/* variables */ /*{{{*/
|
2019-09-03 08:41:37 +00:00
|
|
|
static bool upd_clock; /* evaluate clocked expressions */
|
2019-07-22 20:32:33 +00:00
|
|
|
/* Used during evaluation of a cell to specify the currently updated cell */
|
|
|
|
Sheet *upd_sheet;
|
2019-07-27 04:14:26 +00:00
|
|
|
Location upd_l;
|
2019-07-22 20:32:33 +00:00
|
|
|
int max_eval;
|
|
|
|
/*}}}*/
|
|
|
|
|
2019-07-27 07:00:03 +00:00
|
|
|
/* copycelltosheet -- copy a cell into a sheet*/ /*{{{*/
|
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)
|
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
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
assert(sheet2 != (Sheet*)0);
|
2019-07-27 08:08:42 +00:00
|
|
|
Cell *tocell = safe_cell_at(sheet2, to);
|
|
|
|
if (fromcell == tocell) return;
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-27 07:00:03 +00:00
|
|
|
freecellofsheet(sheet2, to);
|
2019-07-27 04:14:26 +00:00
|
|
|
if (fromcell != NULLCELL)
|
|
|
|
/* copy first cell to second */ /*{{{*/
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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
|
|
|
sheet2->changed = true;
|
|
|
|
Cell *alsotocell = initcellofsheet(sheet2, to, NULL);
|
2019-07-27 08:08:42 +00:00
|
|
|
assert(tocell == NULLCELL || tocell == alsotocell);
|
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
|
|
|
copycell(alsotocell, fromcell, lh);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2019-07-27 04:14:26 +00:00
|
|
|
/*}}}*/
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
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
|
|
|
/* dump_cell -- write internal contents of cell to standard out */ /*{{{*/
|
|
|
|
static void dump_cell(Sheet *sheet, int x, int y, int z)
|
|
|
|
{
|
|
|
|
Cell* c;
|
|
|
|
char buf[2048];
|
|
|
|
|
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
if (x < 0 || y < 0 || z < 0)
|
|
|
|
{
|
|
|
|
printf("TEADUMP: Requested cell &(%d,%d,%d) has negative coordinates.\n",
|
|
|
|
x, y, z);
|
|
|
|
return;
|
|
|
|
}
|
2019-07-27 04:14:26 +00:00
|
|
|
if (!LOC_WITHINC(sheet, x, y, z))
|
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
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
printf("TEADUMP: Requested cell &(%d,%d,%d) outside sheet dims %zu,%zu,%zu.\n",
|
|
|
|
x, y, z, sheet->dim[X], sheet->dim[Y], sheet->dim[Z]);
|
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
|
|
|
return;
|
|
|
|
}
|
2019-07-27 04:14:26 +00:00
|
|
|
c = CELL_ATC(sheet, x, y, z);
|
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
|
|
|
if (c == NULLCELL)
|
|
|
|
{
|
|
|
|
printf("TEADUMP: Cell at &(%d,%d,%d) is empty.\n", x, y, z);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("TEADUMP of &(%d,%d,%d):\n", x, y, z);
|
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
|
|
|
for (TokVariety tv = BASE_CONT; tv < CONTINGENT; ++tv)
|
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
printf(" %s: (%s)", TokVariety_Name[tv], Type_Name[c->tok[tv].type]);
|
|
|
|
printtok(buf, sizeof(buf), 0, QUOTE_STRING, FLT_COMPACT, -1,
|
|
|
|
VERBOSE_ERROR, c->tok + tv);
|
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
|
|
|
printf("%s.\n", buf);
|
|
|
|
}
|
|
|
|
if (c->label == NULL) printf("\n No label.\n");
|
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
|
|
|
else printf("\n Label: %s.\n", c->label);
|
2019-09-03 08:41:37 +00:00
|
|
|
if (c->updated) printf(" updated ");
|
|
|
|
if (c->locked) printf(" locked ");
|
|
|
|
if (c->ignored) printf(" ignored ");
|
2023-04-30 16:19:12 +00:00
|
|
|
if (c->use_iter_cont) printf(" use_iter_cont ");
|
|
|
|
if (c->clock_resolving) printf(" clock_resolving ");
|
|
|
|
if (c->clock_requested) printf(" clock_requested ");
|
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
|
|
|
printf("\n\n");
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
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
|
|
|
/* dump_current_cell -- dump_cell of the current_cell */ /*{{{*/
|
|
|
|
void dump_current_cell(Sheet *sheet)
|
|
|
|
{
|
|
|
|
assert(sheet != (Sheet *)0);
|
2019-07-27 04:14:26 +00:00
|
|
|
dump_cell(sheet, sheet->cur[X], sheet->cur[Y], sheet->cur[Z]);
|
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
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* swapblock -- swap two non-overlapping blocks of cells */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
static void swapblock(Sheet *sheet1, Location l1, Sheet *sheet2, Location l2,
|
|
|
|
Location dist)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
assert(sheet1 != (Sheet*)0);
|
|
|
|
assert(sheet2 != (Sheet*)0);
|
|
|
|
resize(sheet1, l1[X]+dist[X]-1, l1[Y]+dist[Y]-1, l1[Z]+dist[Z]-1, NULL);
|
|
|
|
resize(sheet2, l2[X]+dist[X]-1, l2[Y]+dist[Y]-1, l2[Z]+dist[Z]-1, NULL);
|
|
|
|
Location off;
|
|
|
|
for (off[Z] = 0; off[Z] < dist[Z]; off[Z]++)
|
|
|
|
for (off[Y] = 0; off[Y] < dist[Y]; off[Y]++)
|
|
|
|
for (off[X] = 0; off[X] < dist[X]; off[X]++)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
Location a; LOCATION_GETS(a,l1); LOCATION_ADD(a,off);
|
|
|
|
Cell *t = CELL_AT(sheet1, a);
|
|
|
|
Location b; LOCATION_GETS(b,l2); LOCATION_ADD(b,off);
|
|
|
|
CELL_AT(sheet1,a) = CELL_AT(sheet2,b);
|
|
|
|
CELL_AT(sheet2,b) = t;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
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
|
|
|
sheet1->changed = true;
|
|
|
|
sheet2->changed = true;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
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
|
|
|
|
|
|
|
/* signum -- -1 if < 0, 0 if 0, 1 if > 0 */
|
|
|
|
static int signum(int x) {
|
|
|
|
return (x > 0) - (x < 0);
|
|
|
|
}
|
|
|
|
/* cmpflt -- -1 if <, 0 if =, 1 if > */
|
|
|
|
static int cmpflt(FltT x, FltT y) {
|
|
|
|
return (x > y) - (x < y);
|
|
|
|
}
|
|
|
|
/* cmpflint -- -1 if <, 0 if =, 1 if > */
|
|
|
|
static int cmpflint(FltT x, IntT y) {
|
|
|
|
return (x > y) - (x < y);
|
|
|
|
}
|
|
|
|
/* cmpint -- -1 if <, 0 if =, 1 if > */
|
|
|
|
static int cmpint(IntT x, IntT y) {
|
|
|
|
return (x > y) - (x < y);
|
|
|
|
}
|
|
|
|
/* cmpintfl -- -1 if <, 0 if =, 1 if > */
|
|
|
|
static int cmpintfl(IntT x, FltT y) {
|
|
|
|
return (x > y) - (x < y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define NOT_COMPARABLE 2
|
2019-07-22 20:32:33 +00:00
|
|
|
/* cmpcell -- compare to cells with given order flags */ /*{{{*/
|
|
|
|
/* Notes */ /*{{{*/
|
|
|
|
/*
|
|
|
|
Compare the _values_ of two cells. The result is -1 if first is smaller
|
|
|
|
than second, 0 if they are equal and 1 if the first is bigger than the
|
|
|
|
second. A result of 2 means they are not comparable.
|
|
|
|
*/
|
|
|
|
/*}}}*/
|
2019-09-05 07:24:24 +00:00
|
|
|
static int cmpcell(Sheet *sheet1, const Location l1,
|
|
|
|
Sheet *sheet2, const Location l2, int sortkey)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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
|
|
|
int ascending = (sortkey & ASCENDING) ? 1 : -1;
|
2019-09-05 07:24:24 +00:00
|
|
|
Token leftval = gettok(safe_cell_at(sheet1, l1), CURR_VAL);
|
|
|
|
Token rightval = gettok(safe_cell_at(sheet2, l2), CURR_VAL);
|
2019-07-22 20:32:33 +00:00
|
|
|
/* empty cells are smaller than any non-empty cell */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
if (leftval.type == EMPTY) {
|
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
|
|
|
if (rightval.type == EMPTY) return 0;
|
|
|
|
else return -ascending;
|
2019-09-05 07:24:24 +00:00
|
|
|
}
|
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
|
|
|
if (rightval.type == EMPTY) return ascending;
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
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
|
|
|
switch (leftval.type)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
/* STRING */ /*{{{*/
|
|
|
|
case STRING:
|
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
|
|
|
if (rightval.type == STRING)
|
|
|
|
return signum(strcmp(leftval.u.string, rightval.u.string)) * ascending;
|
|
|
|
return NOT_COMPARABLE;
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
|
|
|
/* FLOAT */ /*{{{*/
|
|
|
|
case FLOAT:
|
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
|
|
|
if (rightval.type == FLOAT)
|
|
|
|
return cmpflt(leftval.u.flt, rightval.u.flt)*ascending;
|
|
|
|
if (rightval.type == INT)
|
|
|
|
return cmpflint(leftval.u.flt, rightval.u.integer)*ascending;
|
|
|
|
return NOT_COMPARABLE;
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
|
|
|
/* INT */ /*{{{*/
|
|
|
|
case INT:
|
|
|
|
{
|
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
|
|
|
if (rightval.type == INT)
|
|
|
|
return cmpint(leftval.u.integer, rightval.u.integer)*ascending;
|
|
|
|
if (rightval.type == FLOAT)
|
|
|
|
return cmpintfl(leftval.u.integer, rightval.u.flt)*ascending;
|
|
|
|
return NOT_COMPARABLE;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
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
|
|
|
default: return NOT_COMPARABLE;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
|
2019-07-27 04:14:26 +00:00
|
|
|
/* initialize_sheet -- fill in fields of a newly allocated Sheet */ /*{{{*/
|
|
|
|
void initialize_sheet(Sheet *sheet) {
|
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
OLOCATION(sheet->cur);
|
|
|
|
sheet->offx = sheet->offy = 0;
|
2019-09-05 07:24:24 +00:00
|
|
|
sheet->dim[X] = sheet->dim[Y] = sheet->dim[Z] = 0;
|
2019-07-27 04:14:26 +00:00
|
|
|
sheet->sheet = (Cell**)0;
|
2019-09-05 07:24:24 +00:00
|
|
|
sheet->column = (ColWidT*)0;
|
2023-04-09 05:41:50 +00:00
|
|
|
sheet->rowhts = (RowHgtT*)0;
|
2019-07-27 04:14:26 +00:00
|
|
|
sheet->orix = sheet->oriy = 0;
|
|
|
|
sheet->maxx = sheet->maxy = 0;
|
|
|
|
sheet->name = (char*)0;
|
|
|
|
OLOCATION(sheet->mark1);
|
|
|
|
OLOCATION(sheet->mark2);
|
|
|
|
sheet->marking = UNMARKED;
|
|
|
|
sheet->changed = 0;
|
|
|
|
sheet->moveonly = 0;
|
|
|
|
sheet->clk = 0;
|
|
|
|
(void)memset(sheet->labelcache, 0, sizeof(sheet->labelcache));
|
2019-07-29 15:35:10 +00:00
|
|
|
sheet->max_colors = MAX_MAX_COLORS;
|
|
|
|
/* start display of this sheet */
|
|
|
|
if (!batch) {
|
|
|
|
display_init(sheet, always_redraw);
|
|
|
|
line_msg((const char*)0,"");
|
|
|
|
}
|
2019-07-27 04:14:26 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* resize -- check if sheet needs to be resized in any dimension */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
void resize(Sheet *sheet, CoordT x, CoordT y, CoordT z, bool *qextended)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
assert(x >= 0);
|
|
|
|
assert(y >= 0);
|
|
|
|
assert(z >= 0);
|
|
|
|
assert(sheet != (Sheet*)0);
|
2019-07-27 04:14:26 +00:00
|
|
|
|
|
|
|
if (!LOC_WITHINC(sheet,x,y,z))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
Sheet dummy;
|
2019-07-22 20:32:33 +00:00
|
|
|
|
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
|
|
|
sheet->changed = true;
|
|
|
|
if (qextended) *qextended = true;
|
2019-09-05 07:24:24 +00:00
|
|
|
dummy.dim[X] = ((size_t)x >= sheet->dim[X] ? (size_t)(x+1) : sheet->dim[X]);
|
|
|
|
dummy.dim[Y] = ((size_t)y >= sheet->dim[Y] ? (size_t)(y+1) : sheet->dim[Y]);
|
|
|
|
dummy.dim[Z] = ((size_t)z >= sheet->dim[Z] ? (size_t)(z+1) : sheet->dim[Z]);
|
2019-07-22 20:32:33 +00:00
|
|
|
/* allocate new sheet */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
dummy.sheet = malloc(dummy.dim[X]*dummy.dim[Y]*dummy.dim[Z]*sizeof(Cell*));
|
2019-07-27 04:14:26 +00:00
|
|
|
for (ALL_COORDS_IN_SHEETC(&dummy,x,y,z))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
if (LOC_WITHINC(sheet,x,y,z)) CELL_ATC(&dummy,x,y,z) = CELL_ATC(sheet,x,y,z);
|
|
|
|
else CELL_ATC(&dummy,x,y,z) = NULLCELL;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
if (sheet->sheet!=(Cell**)0) free(sheet->sheet);
|
2019-07-27 04:14:26 +00:00
|
|
|
sheet->sheet = dummy.sheet;
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
2023-04-09 05:41:50 +00:00
|
|
|
/* allocate new column widths and row heights */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
if ((size_t)x > sheet->dim[X] || (size_t)z >= sheet->dim[Z])
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
dummy.column = malloc(dummy.dim[X] * dummy.dim[Z] * sizeof(ColWidT));
|
|
|
|
for (x=0; (size_t)x < dummy.dim[X]; ++x)
|
|
|
|
for (z=0; (size_t)z < dummy.dim[Z]; ++z)
|
|
|
|
{
|
|
|
|
if ((size_t)x < sheet->dim[X] && (size_t)z < sheet->dim[Z])
|
|
|
|
*(dummy.column + ((size_t)x)*dummy.dim[Z] + (size_t)z)
|
2023-04-09 05:41:50 +00:00
|
|
|
= *(sheet->column + ((size_t)x)*sheet->dim[Z] + (size_t)z);
|
2019-09-05 07:24:24 +00:00
|
|
|
else
|
|
|
|
*(dummy.column + ((size_t)x)*dummy.dim[Z] + (size_t)z)
|
|
|
|
= DEF_COLUMNWIDTH;
|
|
|
|
}
|
|
|
|
if (sheet->column != (ColWidT*)0) free(sheet->column);
|
2019-07-27 04:14:26 +00:00
|
|
|
sheet->column = dummy.column;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2023-04-09 05:41:50 +00:00
|
|
|
if ((size_t)(y) > sheet->dim[Y] || (size_t)z > sheet->dim[Z])
|
|
|
|
{
|
|
|
|
dummy.rowhts = malloc(dummy.dim[Y] * dummy.dim[Z] * sizeof(RowHgtT));
|
|
|
|
for (y=0; (size_t)y < dummy.dim[Y]; ++y)
|
|
|
|
for (z=0; (size_t)z < dummy.dim[Z]; ++z)
|
|
|
|
{
|
|
|
|
RowHgtT *dumht = dummy.rowhts + ((size_t)y)*dummy.dim[Z] + (size_t)z;
|
|
|
|
if ((size_t)y < sheet->dim[Y] && (size_t)z < sheet->dim[Z])
|
|
|
|
*dumht = *(sheet->rowhts + ((size_t)y)*sheet->dim[Z] + (size_t)z);
|
|
|
|
else
|
|
|
|
*dumht = DEF_ROWHEIGHT;
|
|
|
|
}
|
|
|
|
if (sheet->rowhts != (RowHgtT*)0) free(sheet->rowhts);
|
|
|
|
sheet->rowhts = dummy.rowhts;
|
|
|
|
}
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
2019-09-05 07:24:24 +00:00
|
|
|
for (Dimensions dd = X; dd < HYPER; ++dd) sheet->dim[dd] = dummy.dim[dd];
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-27 07:00:03 +00:00
|
|
|
/* initcellofsheet -- initialise new cell, if it does not exist yet */ /*{{{*/
|
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)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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
|
|
|
Cell *nc;
|
|
|
|
|
2019-07-27 04:14:26 +00:00
|
|
|
assert(IN_OCTANT(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
|
|
|
resize(sheet, at[X], at[Y], at[Z], qnew);
|
2019-07-27 04:14:26 +00:00
|
|
|
nc = CELL_AT(sheet,at);
|
|
|
|
if (nc == NULLCELL)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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
|
|
|
sheet->changed = true;
|
|
|
|
if (qnew) *qnew = true;
|
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
|
|
|
nc = malloc(sizeof(Cell));
|
2019-07-27 04:14:26 +00:00
|
|
|
CELL_AT(sheet,at) = nc;
|
2019-07-27 07:00:03 +00:00
|
|
|
initcellcontents(nc);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2019-07-27 04:14:26 +00:00
|
|
|
return nc;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
|
|
|
/* safe_cell_at -- returns pointer to the cell at the given location,
|
|
|
|
even in the face of various edge conditions.
|
|
|
|
*/
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (sheet == (Sheet*)0) return NULLCELL;
|
|
|
|
if (sheet->sheet == (Cell **)0) return NULLCELL;
|
|
|
|
if (!LOC_WITHINC(sheet,x,y,z)) return NULLCELL;
|
|
|
|
return CELL_ATC(sheet,x,y,z);
|
|
|
|
}
|
|
|
|
/* safe_cell_at -- returns pointer to the cell at the given location,
|
|
|
|
even in the face of various edge conditions.
|
|
|
|
*/
|
|
|
|
|
2019-07-27 04:14:26 +00:00
|
|
|
Cell *safe_cell_at(Sheet *sheet, const Location at)
|
|
|
|
{
|
|
|
|
if (sheet == (Sheet*)0) return NULLCELL;
|
|
|
|
if (sheet->sheet == (Cell **)0) return NULLCELL;
|
|
|
|
if (!LOC_WITHIN(sheet, at)) return NULLCELL;
|
|
|
|
return CELL_AT(sheet, at);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* curcell -- return pointer to the current cell */ /*{{{*/
|
|
|
|
Cell *curcell(Sheet *sheet)
|
|
|
|
{
|
|
|
|
return safe_cell_at(sheet, sheet->cur);
|
|
|
|
}
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* cachelabels -- create new label cache */ /*{{{*/
|
|
|
|
void cachelabels(Sheet *sheet)
|
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
int i;
|
|
|
|
Location w;
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
if (sheet==(Sheet*)0) return;
|
|
|
|
for (i=0; i<LABEL_CACHE; ++i) /* free bucket */ /*{{{*/
|
|
|
|
{
|
|
|
|
struct Label *run;
|
|
|
|
|
|
|
|
for (run=sheet->labelcache[i]; run!=(struct Label*)0;)
|
|
|
|
{
|
|
|
|
struct Label *runnext;
|
|
|
|
|
|
|
|
runnext=run->next;
|
|
|
|
free(run);
|
|
|
|
run=runnext;
|
|
|
|
}
|
|
|
|
sheet->labelcache[i]=(struct Label*)0;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
for (ALL_LOCS_IN_SHEET(sheet,w))
|
2019-07-22 20:32:33 +00:00
|
|
|
/* cache all labels */ /*{{{*/
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
const char *l = getlabel(CELL_AT(sheet,w));
|
2019-07-22 20:32:33 +00:00
|
|
|
if (*l)
|
|
|
|
{
|
|
|
|
unsigned long hx;
|
|
|
|
struct Label **run;
|
|
|
|
|
|
|
|
HASH(hx,l);
|
|
|
|
for (run=&sheet->labelcache[(unsigned int)hx]; *run!=(struct Label*)0 && strcmp(l,(*run)->label); run=&((*run)->next));
|
|
|
|
if (*run==(struct Label*)0)
|
|
|
|
{
|
|
|
|
*run=malloc(sizeof(struct Label));
|
|
|
|
(*run)->next=(struct Label*)0;
|
|
|
|
(*run)->label=l;
|
2019-07-27 04:14:26 +00:00
|
|
|
LOCATION_GETS((*run)->location,w);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/* else we have a duplicate label, which _can_ happen under */
|
|
|
|
/* unfortunate conditions. Don't tell anybody. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
/* freesheet -- free all cells of an entire spread sheet */ /*{{{*/
|
|
|
|
void freesheet(Sheet *sheet, int all)
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
sheet->changed = FALSE;
|
2019-07-27 04:14:26 +00:00
|
|
|
Location w;
|
2019-09-05 07:24:24 +00:00
|
|
|
for (ALL_LOCS_IN_SHEET(sheet,w)) freecellofsheet(sheet,w);
|
2019-07-22 20:32:33 +00:00
|
|
|
if (all)
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
for (int i=0; i < LABEL_CACHE; ++i) /* free all buckets */ /*{{{*/
|
|
|
|
for (struct Label *run = sheet->labelcache[i]; run != (struct Label*)0;) {
|
|
|
|
struct Label *runnext = run->next;
|
2019-07-22 20:32:33 +00:00
|
|
|
free(run);
|
2019-09-05 07:24:24 +00:00
|
|
|
run = runnext;
|
|
|
|
} /*}}}*/
|
2019-07-22 20:32:33 +00:00
|
|
|
if (sheet->sheet) free(sheet->sheet);
|
|
|
|
if (sheet->column) free(sheet->column);
|
2023-04-09 05:41:50 +00:00
|
|
|
if (sheet->rowhts) free(sheet->rowhts);
|
2019-07-22 20:32:33 +00:00
|
|
|
if (sheet->name) free(sheet->name);
|
2019-09-05 07:24:24 +00:00
|
|
|
if (!batch) display_end(sheet);
|
|
|
|
} else {
|
|
|
|
for (size_t x = 0; x < sheet->dim[X]; ++x)
|
|
|
|
for (size_t z = 0; z < sheet->dim[Z]; ++z)
|
|
|
|
*(sheet->column + x*sheet->dim[Z] + z) = DEF_COLUMNWIDTH;
|
2023-04-09 05:41:50 +00:00
|
|
|
for (size_t y = 0; y < sheet->dim[y]; ++y)
|
|
|
|
for (size_t z = 0; z < sheet->dim[Z]; ++z)
|
|
|
|
*(sheet->rowhts + y*sheet->dim[Z] + z) = DEF_ROWHEIGHT;
|
2019-07-22 20:32:33 +00:00
|
|
|
cachelabels(sheet);
|
|
|
|
forceupdate(sheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-09-05 07:24:24 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* forceupdate -- clear all clock and update flags */ /*{{{*/
|
|
|
|
void forceupdate(Sheet *sheet)
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
assert(sheet != (Sheet*)0);
|
2019-07-28 03:54:16 +00:00
|
|
|
if (sheet->sheet == (Cell **)0) return;
|
2019-09-05 07:24:24 +00:00
|
|
|
size_t i; Cell *cell;
|
2019-07-27 04:14:26 +00:00
|
|
|
for (ALL_CELLS_IN_SHEET(sheet,i,cell))
|
2019-09-03 08:41:37 +00:00
|
|
|
if (cell != NULLCELL) {
|
2023-04-30 16:19:12 +00:00
|
|
|
cell->updated = cell->use_iter_cont = cell->clock_resolving = cell->clock_requested = false;
|
2019-09-03 08:41:37 +00:00
|
|
|
tfree(&(cell->tok[STYLE_VAL]));
|
|
|
|
}
|
2019-07-22 20:32:33 +00:00
|
|
|
update(sheet);
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-27 07:00:03 +00:00
|
|
|
/* freecellofsheet -- free one cell */ /*{{{*/
|
|
|
|
void freecellofsheet(Sheet *sheet, const Location at)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
if (sheet->sheet != (Cell**)0 && CELL_IS_GOOD(sheet,at))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 07:00:03 +00:00
|
|
|
Cell *c = CELL_AT(sheet,at);
|
|
|
|
freecellcontents(c);
|
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
|
|
|
free(c);
|
2019-07-27 04:14:26 +00:00
|
|
|
CELL_AT(sheet,at) = NULLCELL;
|
|
|
|
sheet->changed = 1;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* columnwidth -- get width of column */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
ColWidT columnwidth(Sheet *sheet, CoordT x, CoordT z)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
assert(sheet!=(Sheet*)0);
|
2019-09-05 07:24:24 +00:00
|
|
|
if ((size_t)x < sheet->dim[X] && (size_t)z < sheet->dim[Z])
|
|
|
|
return (*(sheet->column + ((size_t)x)*sheet->dim[Z] + (size_t)z));
|
2019-07-22 20:32:33 +00:00
|
|
|
else return DEF_COLUMNWIDTH;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
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
|
|
|
|
2023-04-09 05:41:50 +00:00
|
|
|
/* rowheight -- get height of row */ /*{{{*/
|
|
|
|
ColWidT rowheight(Sheet *sheet, CoordT y, CoordT z)
|
|
|
|
{
|
|
|
|
assert(sheet!=(Sheet*)0);
|
|
|
|
if ((size_t)y < sheet->dim[Y] && (size_t)z < sheet->dim[Z])
|
|
|
|
return (*(sheet->rowhts + ((size_t)y)*sheet->dim[Z] + (size_t)z));
|
|
|
|
else return DEF_ROWHEIGHT;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* setwidth -- set width of column */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
bool setwidth(Sheet *sheet, CoordT x, CoordT z, ColWidT width)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
assert(sheet != (Sheet*)0);
|
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 isbigger = false;
|
|
|
|
resize(sheet, x, 1, z, &isbigger);
|
|
|
|
if (isbigger) sheet->changed = true;
|
2019-09-05 07:24:24 +00:00
|
|
|
ColWidT *storage = sheet->column + (size_t)x*sheet->dim[Z] + (size_t)z;
|
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
|
|
|
if (*storage != width) {
|
|
|
|
*storage = width;
|
|
|
|
sheet->changed = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return isbigger;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
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
|
|
|
|
2023-04-09 05:41:50 +00:00
|
|
|
|
|
|
|
/* setheight -- set height of row */ /*{{{*/
|
|
|
|
bool setheight(Sheet *sheet, CoordT y, CoordT z, RowHgtT height)
|
|
|
|
{
|
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
bool isbigger = false;
|
|
|
|
resize(sheet, 1, y, z, &isbigger);
|
|
|
|
if (isbigger) sheet->changed = true;
|
|
|
|
RowHgtT *storage = sheet->rowhts + (size_t)y*sheet->dim[Z] + (size_t)z;
|
|
|
|
if (*storage != height) {
|
|
|
|
*storage = height;
|
|
|
|
sheet->changed = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return isbigger;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* cellwidth -- get width of a cell */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
ColWidT cellwidth(Sheet *sheet, const Location at)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
if (shadowed(sheet,at)) return 0;
|
|
|
|
Location near; LOCATION_GETS(near,at);
|
2019-09-05 07:24:24 +00:00
|
|
|
ColWidT width = columnwidth(sheet,at[X],at[Z]);
|
2019-09-03 08:41:37 +00:00
|
|
|
for (near[X]++; shadowed(sheet,near);
|
|
|
|
width += columnwidth(sheet,near[X]++,near[Z]));
|
2019-07-22 20:32:33 +00:00
|
|
|
return width;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2023-04-09 05:41:50 +00:00
|
|
|
|
|
|
|
/* cellheight -- get height of a cell */ /*{{{*/
|
|
|
|
RowHgtT cellheight(Sheet *sheet, const Location at)
|
|
|
|
{
|
|
|
|
/* At the moment this is trivial because there is no vertical
|
|
|
|
"shadowing". Probably rather than implementing that more
|
|
|
|
general cell merging would be a preferable way to go
|
|
|
|
*/
|
|
|
|
return rowheight(sheet, at[Y], at[Z]);
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* putcont -- assign new contents */ /*{{{*/
|
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)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
Cell *cell;
|
|
|
|
|
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
sheet->changed = 1;
|
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, at, NULL);
|
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
|
|
|
tfree(&(cell->tok[v]));
|
|
|
|
cell->tok[v] = t;
|
2019-07-27 04:14:26 +00:00
|
|
|
redraw_cell(sheet, at);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
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
|
|
|
/* recompvalue -- get tcopy()ed value */ /*{{{*/
|
|
|
|
Token recompvalue(Sheet *sheet, const Location at)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
/* variables */ /*{{{*/
|
|
|
|
Token result;
|
2019-07-27 04:14:26 +00:00
|
|
|
Cell* cell;
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
|
|
|
|
|
|
|
assert(sheet!=(Sheet*)0);
|
2019-07-27 04:14:26 +00:00
|
|
|
if (!IN_OCTANT(at))
|
2019-07-22 20:32:33 +00:00
|
|
|
/* return error */ /*{{{*/
|
|
|
|
{
|
|
|
|
result.type=EEK;
|
2019-07-30 19:07:54 +00:00
|
|
|
char *templ = _("Attempt to access cell at (%d,%d,%d) with negative index");
|
|
|
|
result.u.err = malloc(strlen(templ)+32);
|
|
|
|
sprintf(result.u.err, templ, at[X], at[Y], at[Z]);
|
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
|
|
|
return result;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
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
|
|
|
result.type = EMPTY;
|
|
|
|
/* Can always short-circuit an out-of-bounds or empty cell */
|
2019-07-27 04:14:26 +00:00
|
|
|
if (!CELL_IS_GOOD(sheet,at)) return result;
|
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
|
|
|
/* only short-circuit on empty contents of a good cell if we are NOT
|
|
|
|
depending on this call to update the current value
|
|
|
|
*/
|
2019-07-27 04:14:26 +00:00
|
|
|
cell = CELL_AT(sheet, 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
|
|
|
if (!upd_clock && gettok(cell, CONTINGENT).type == EMPTY) return result;
|
2019-07-22 20:32:33 +00:00
|
|
|
/* update value of this cell if needed and return it */ /*{{{*/
|
2019-09-03 08:41:37 +00:00
|
|
|
bool orig_upd_clock = upd_clock;
|
2019-07-27 04:14:26 +00:00
|
|
|
if (cell->ignored)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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
|
|
|
tfree(cell->tok + CURR_VAL);
|
2019-09-03 08:41:37 +00:00
|
|
|
cell->updated = true;
|
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
|
|
|
}
|
2019-09-03 08:41:37 +00:00
|
|
|
else if (cell->updated == false)
|
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
|
|
|
{
|
|
|
|
/* variables */ /*{{{*/
|
|
|
|
Sheet *old_sheet;
|
2019-07-27 04:14:26 +00:00
|
|
|
Location old_l;
|
|
|
|
int old_max_eval;
|
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
|
|
|
Token oldvalue;
|
|
|
|
/*}}}*/
|
2019-07-22 20:32:33 +00:00
|
|
|
|
2019-07-27 04:14:26 +00:00
|
|
|
old_sheet = upd_sheet;
|
|
|
|
LOCATION_GETS(old_l, upd_l);
|
|
|
|
old_max_eval = max_eval;
|
|
|
|
upd_sheet = sheet;
|
|
|
|
LOCATION_GETS(upd_l, at);
|
|
|
|
max_eval = MAX_EVALNEST;
|
2023-04-30 16:19:12 +00:00
|
|
|
if (!(cell->clock_resolving))
|
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
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
cell->updated = true;
|
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
|
|
|
oldvalue = gettok(cell, CURR_VAL);
|
2019-09-03 08:41:37 +00:00
|
|
|
upd_clock = false;
|
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->tok[CURR_VAL] = evaltoken(gettok(cell, CONTINGENT), FULL);
|
2019-07-22 20:32:33 +00:00
|
|
|
tfree(&oldvalue);
|
|
|
|
}
|
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
|
|
|
else if (upd_clock)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
cell->updated = true;
|
|
|
|
upd_clock = false;
|
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
|
|
|
oldvalue = gettok(cell, RES_VAL);
|
|
|
|
cell->tok[RES_VAL] = evaltoken(gettok(cell, CONTINGENT), FULL);
|
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
|
|
|
tfree(&oldvalue);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2019-07-27 04:14:26 +00:00
|
|
|
upd_sheet = old_sheet;
|
|
|
|
LOCATION_GETS(upd_l, old_l);
|
|
|
|
max_eval = old_max_eval;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2023-04-30 16:19:12 +00:00
|
|
|
/* When upd_clock was true on entry, the result is going to be thrown
|
|
|
|
away in any case, so don't bother doing the copy.
|
|
|
|
*/
|
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
|
|
|
if (!orig_upd_clock) result = tcopy(cell->tok[CURR_VAL]);
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-08-28 19:40:50 +00:00
|
|
|
/* evaluate_at -- evaluate a token in a sheet at a location */ /*{{{*/
|
|
|
|
Token evaluate_at(Token t, Sheet *sheet, const Location at)
|
|
|
|
{
|
|
|
|
assert(sheet != (Sheet *)0);
|
|
|
|
Sheet *oldsheet = upd_sheet;
|
|
|
|
upd_sheet = sheet;
|
|
|
|
Location old_l;
|
|
|
|
LOCATION_GETS(old_l, upd_l);
|
|
|
|
LOCATION_GETS(upd_l, at);
|
|
|
|
Token result = evaltoken(t, FULL);
|
|
|
|
LOCATION_GETS(upd_l, old_l);
|
|
|
|
upd_sheet = oldsheet;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* update -- update all cells that need it */ /*{{{*/
|
|
|
|
void update(Sheet *sheet)
|
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
assert(sheet != (Sheet*)0);
|
2019-09-03 08:41:37 +00:00
|
|
|
int iterating = 0;
|
|
|
|
bool kp = false;
|
|
|
|
for (sheet->clk = true; sheet->sheet && sheet->clk && !kp; kp = keypressed())
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
sheet->clk = 0;
|
2019-09-03 08:41:37 +00:00
|
|
|
if (iterating == 1)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2023-04-30 16:19:12 +00:00
|
|
|
line_msg(NULL, _("Recalculation running, press Escape to abort it"));
|
2019-07-22 20:32:33 +00:00
|
|
|
++iterating;
|
|
|
|
}
|
2019-09-03 08:41:37 +00:00
|
|
|
else if (iterating == 0) ++iterating;
|
|
|
|
Cell *cell;
|
2019-09-05 07:24:24 +00:00
|
|
|
size_t i;
|
2019-07-27 04:14:26 +00:00
|
|
|
for (ALL_CELLS_IN_SHEET(sheet,i,cell))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2023-04-30 16:19:12 +00:00
|
|
|
if (cell && cell->clock_requested)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
cell->updated = false;
|
2023-04-30 16:19:12 +00:00
|
|
|
cell->use_iter_cont = true;
|
|
|
|
cell->clock_resolving = true;
|
|
|
|
cell->clock_requested = false;
|
2019-09-03 08:41:37 +00:00
|
|
|
tfree(&(cell->tok[STYLE_VAL]));
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-03 08:41:37 +00:00
|
|
|
Location w;
|
2019-07-27 04:14:26 +00:00
|
|
|
for (ALL_LOCS_IN_SHEET(sheet,w))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
upd_clock = true;
|
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
|
|
|
recompvalue(sheet, w);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2023-04-30 16:19:12 +00:00
|
|
|
bool current_changed = false;
|
2019-07-27 04:14:26 +00:00
|
|
|
for (ALL_CELLS_IN_SHEET(sheet,i,cell))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2023-04-30 16:19:12 +00:00
|
|
|
if (cell && cell->clock_resolving)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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
|
|
|
tfree(&(cell->tok[CURR_VAL]));
|
|
|
|
cell->tok[CURR_VAL] = cell->tok[RES_VAL];;
|
2023-04-30 16:19:12 +00:00
|
|
|
cell->tok[RES_VAL].type = EMPTY;
|
|
|
|
current_changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (current_changed) {
|
|
|
|
/* Recompute all of the non-clocked cells so that they get the values
|
|
|
|
of the newly-changed clocked cells
|
|
|
|
*/
|
|
|
|
for (ALL_CELLS_IN_SHEET(sheet, i, cell)) {
|
|
|
|
if (cell) {
|
|
|
|
if (cell->clock_resolving) {
|
|
|
|
cell->clock_resolving = false;
|
|
|
|
} else {
|
|
|
|
cell->updated = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (ALL_LOCS_IN_SHEET(sheet, w)) {
|
|
|
|
upd_clock = true;
|
|
|
|
recompvalue(sheet, w);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-03 08:41:37 +00:00
|
|
|
upd_clock = false;
|
|
|
|
}
|
|
|
|
if (iterating == 2)
|
|
|
|
line_msg(NULL, kp ? _("Calculation aborted") : _("Calculation finished"));
|
|
|
|
sheet->clk = false;
|
2019-07-22 20:32:33 +00:00
|
|
|
redraw_sheet(sheet);
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-09-03 08:41:37 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* geterror -- get malloc()ed error string */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
char *geterror(Sheet *sheet, const Location at)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
Token v;
|
|
|
|
|
|
|
|
assert(sheet!=(Sheet*)0);
|
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
|
|
|
if ((v = recompvalue(sheet,at)).type != EEK)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
tfree(&v);
|
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
|
|
|
return NULL;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
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
|
|
|
else return (v.u.err);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* printvalue -- get ASCII representation of value */ /*{{{*/
|
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-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
assert(sheet != (Sheet*)0);
|
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
|
|
|
Token t = recompvalue(sheet, at);
|
2019-09-03 08:41:37 +00:00
|
|
|
size_t retval =
|
|
|
|
printtok(s, size, chars, sf, ff, precision, TRUNCATED_ERROR, &t);
|
2019-07-22 20:32:33 +00:00
|
|
|
tfree(&t);
|
2019-09-03 08:41:37 +00:00
|
|
|
return retval;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-09-03 08:41:37 +00:00
|
|
|
/* getstyle -- get the current style token */
|
|
|
|
Style getstyle(Sheet *sheet, const Location at)
|
|
|
|
{
|
|
|
|
Token res;
|
|
|
|
res.type = STYLE;
|
|
|
|
clearstyle(&(res.u.style));
|
|
|
|
res.u.style.fform = DEF_FLOATFORM;
|
|
|
|
res.u.style.precision = def_precision;
|
|
|
|
if (!IN_OCTANT(at) || !CELL_IS_GOOD(sheet, at)) {
|
|
|
|
res.u.style.adjust = LEFT; return res.u.style;
|
|
|
|
}
|
|
|
|
Cell *cell = CELL_AT(sheet, at);
|
2019-09-09 14:33:41 +00:00
|
|
|
if (!(cell->updated)) recompvalue(sheet, at);
|
2019-09-03 08:41:37 +00:00
|
|
|
assert(cell->updated);
|
|
|
|
if (cell->tok[STYLE_VAL].type == STYLE) return cell->tok[STYLE_VAL].u.style;
|
|
|
|
Sheet *old_up_sh = upd_sheet;
|
|
|
|
Location old_upd_l; LOCATION_GETS(old_upd_l, upd_l);
|
|
|
|
upd_sheet = sheet;
|
|
|
|
LOCATION_GETS(upd_l, at);
|
|
|
|
Token tsty = evaltoken(cell->tok[STYLE_CONT], FULL);
|
|
|
|
LOCATION_GETS(upd_l, old_upd_l);
|
|
|
|
upd_sheet = old_up_sh;
|
|
|
|
Style sty;
|
|
|
|
switch (tsty.type) {
|
|
|
|
case STYLE: sty = tsty.u.style; break;
|
|
|
|
case EMPTY: sty = res.u.style; break;
|
|
|
|
default: {
|
|
|
|
char buf[4096];
|
2019-09-09 14:33:41 +00:00
|
|
|
const char *msg = _("Produced non-style value at &(%d,%d,%d) '");
|
|
|
|
sprintf(buf, msg, at[X], at[Y], at[Z]);
|
|
|
|
printtok(buf+strlen(buf), sizeof(buf)-strlen(buf)-1, 0, QUOTE_STRING,
|
2019-09-03 08:41:37 +00:00
|
|
|
FLT_COMPACT, -1, VERBOSE_ERROR, &tsty);
|
2019-09-09 14:33:41 +00:00
|
|
|
strcat(buf, "'");
|
2019-09-03 08:41:37 +00:00
|
|
|
line_msg(_("Cell style expr:"), msg);
|
|
|
|
sty = res.u.style;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sty.adjust == AUTOADJUST)
|
|
|
|
sty.adjust = TOKISNUM(cell->tok[CURR_VAL]) ? RIGHT : LEFT;
|
|
|
|
if (sty.fform == FLT_NO_FORMAT) sty.fform = DEF_FLOATFORM;
|
|
|
|
if (sty.precision == NO_PRECISION) sty.precision = def_precision;
|
|
|
|
cell->tok[STYLE_VAL].type = STYLE;
|
|
|
|
cell->tok[STYLE_VAL].u.style = sty;
|
|
|
|
return sty;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* shadowed -- is cell shadowed? */
|
|
|
|
bool shadowed(Sheet *sheet, const Location at)
|
|
|
|
{
|
|
|
|
return getstyle(sheet, at).shadowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* transparent -- is cell transparent? */
|
|
|
|
bool transparent(Sheet *sheet, const Location at)
|
|
|
|
{
|
|
|
|
return getstyle(sheet, at).transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* getprecision -- get cell precision */
|
|
|
|
PrecisionLevel getprecision(Sheet *sheet, const Location at)
|
|
|
|
{
|
|
|
|
return getstyle(sheet, at).precision;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* overridestyle -- coerce the style of a cell to match sty */
|
|
|
|
bool overridestyle(Sheet *sheet, const Location at, Style sty) {
|
|
|
|
Style esty;
|
|
|
|
clearstyle(&esty);
|
|
|
|
if (style_equal(sty, esty)) return false;
|
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
bool isnew = false;
|
|
|
|
Cell* thecell = initcellofsheet(sheet, at, &isnew);
|
|
|
|
if (isnew) sheet->changed = true;
|
|
|
|
Token stok = gettok(thecell, STYLE_CONT);
|
|
|
|
switch (stok.type) {
|
|
|
|
case EMPTY:
|
|
|
|
thecell->tok[STYLE_CONT].type = STYLE;
|
|
|
|
thecell->tok[STYLE_CONT].u.style = sty;
|
|
|
|
tfree(&(thecell->tok[STYLE_VAL]));
|
|
|
|
return true;
|
|
|
|
case STYLE: {
|
|
|
|
Token tsty; tsty.type = STYLE; tsty.u.style = sty;
|
|
|
|
thecell->tok[STYLE_CONT] = tadd(tsty, stok);
|
2019-09-09 14:33:41 +00:00
|
|
|
if (style_equal(stok.u.style, thecell->tok[STYLE_CONT].u.style))
|
|
|
|
return false;
|
2019-09-03 08:41:37 +00:00
|
|
|
tfree(&(thecell->tok[STYLE_VAL]));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
/* Create an expression that adds the prior expression to this style */
|
|
|
|
Token tsty; tsty.type = STYLE; tsty.u.style = sty;
|
|
|
|
Token fsty; fsty.type = FUNCALL;
|
|
|
|
fsty.u.funcall.fident = FUNC_PLUS_SYMBOL;
|
|
|
|
fsty.u.funcall.argc = 2;
|
2019-09-05 07:24:24 +00:00
|
|
|
fsty.u.funcall.argv = malloc(2*sizeof(Token));
|
2019-09-03 08:41:37 +00:00
|
|
|
fsty.u.funcall.argv[0] = tsty;
|
|
|
|
fsty.u.funcall.argv[1] = stok;
|
|
|
|
thecell->tok[STYLE_CONT] = fsty;
|
|
|
|
tfree(&(thecell->tok[STYLE_VAL]));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The cell field setters used to all have nearly identical code, so: */
|
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
|
|
|
|
|
|
|
#define DEFSETTER(funcname,argtype,field) bool\
|
|
|
|
funcname(Sheet *sheet, const Location at, argtype arg)\
|
|
|
|
{\
|
|
|
|
assert(sheet != (Sheet*)0);\
|
|
|
|
bool isnew = false;\
|
|
|
|
Cell* thecell = initcellofsheet(sheet, at, &isnew);\
|
|
|
|
if (isnew) sheet->changed = true;\
|
|
|
|
if (thecell->field != arg) {\
|
|
|
|
thecell->field = arg;\
|
|
|
|
sheet->changed = true;\
|
|
|
|
return true;\
|
|
|
|
}\
|
|
|
|
return isnew;\
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2019-07-27 04:14:26 +00:00
|
|
|
|
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
|
|
|
DEFSETTER(lockcell, bool, locked);
|
|
|
|
DEFSETTER(igncell, bool, ignored);
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-09-03 08:41:37 +00:00
|
|
|
#define DEFSTYVAL(funcname,argtype,field) bool\
|
|
|
|
funcname(Sheet *sheet, const Location at, argtype arg)\
|
|
|
|
{\
|
|
|
|
Style nsty; clearstyle(&nsty);\
|
|
|
|
nsty.field = arg;\
|
|
|
|
return overridestyle(sheet, at, nsty);\
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFSTYVAL(setadjust, Adjust, adjust);
|
|
|
|
DEFSTYVAL(setfltformat, FloatFormat, fform);
|
|
|
|
DEFSTYVAL(setprecision, PrecisionLevel, precision);
|
|
|
|
|
|
|
|
#define DEFSTYFLAG(funcname,field) bool\
|
|
|
|
funcname(Sheet *sheet, const Location at, bool arg)\
|
|
|
|
{\
|
|
|
|
Style nsty; clearstyle(&nsty);\
|
|
|
|
nsty.field = arg;\
|
|
|
|
nsty.field##_set = true;\
|
|
|
|
return overridestyle(sheet, at, nsty);\
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFSTYFLAG(shadow, shadowed);
|
2019-09-18 12:49:53 +00:00
|
|
|
DEFSTYFLAG(makedim, dim);
|
|
|
|
DEFSTYFLAG(embolden, bold);
|
|
|
|
DEFSTYFLAG(italicize, italic);
|
2019-09-03 08:41:37 +00:00
|
|
|
DEFSTYFLAG(underline, underline);
|
|
|
|
DEFSTYFLAG(maketrans, transparent);
|
|
|
|
|
|
|
|
/* setcolor -- force the color of a cell to be as specified */
|
2019-08-29 06:19:08 +00:00
|
|
|
bool setcolor(Sheet *sheet, const Location at, ColorAspect asp, ColorNum col)
|
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
Style nsty; clearstyle(&nsty);
|
|
|
|
nsty.aspect[asp] = col;
|
|
|
|
return overridestyle(sheet, at, nsty);
|
2019-08-29 06:19:08 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* clk -- clock cell */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
void clk(Sheet *sheet, const Location at)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
assert(IN_OCTANT(at));
|
2023-04-30 16:19:12 +00:00
|
|
|
assert(LOC_WITHIN(sheet, at));
|
|
|
|
Cell* toclock = CELL_AT(sheet, at);
|
|
|
|
if (iterable(toclock))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2023-04-30 16:19:12 +00:00
|
|
|
toclock->clock_requested = true;
|
2019-09-03 08:41:37 +00:00
|
|
|
sheet->clk = true;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
|
|
|
/* getmarkstate -- find out where in the marking cycle the sheet is */ /*{{{*/
|
|
|
|
MarkState getmarkstate(Sheet *sheet) {
|
|
|
|
if (sheet == (Sheet*)0) return MARK_CYCLE;
|
|
|
|
return sheet->marking;
|
|
|
|
}
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* setlabel -- set cell label */ /*{{{*/
|
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
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
Cell *cell;
|
|
|
|
|
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
sheet->changed = 1;
|
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, at, NULL);
|
2019-07-27 04:14:26 +00:00
|
|
|
if (cell->label != (char*)0) free(cell->label);
|
|
|
|
if (*buf == '\0') cell->label = (char*)0;
|
|
|
|
else cell->label = strcpy(malloc(strlen(buf)+1), buf);
|
2019-07-22 20:32:33 +00:00
|
|
|
if (update)
|
|
|
|
{
|
|
|
|
cachelabels(sheet);
|
|
|
|
forceupdate(sheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* findlabel -- return cell location for a given label */ /*{{{*/
|
|
|
|
Token findlabel(Sheet *sheet, const char *label)
|
|
|
|
{
|
|
|
|
/* variables */ /*{{{*/
|
|
|
|
Token result;
|
|
|
|
unsigned long hx;
|
|
|
|
struct Label *run;
|
|
|
|
/*}}}*/
|
|
|
|
|
|
|
|
assert(sheet!=(Sheet*)0);
|
|
|
|
/*
|
|
|
|
if (sheet==(Sheet*)0) run=(struct Label*)0;
|
|
|
|
else
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
HASH(hx,label);
|
|
|
|
for (run=sheet->labelcache[(unsigned int)hx]; run!=(struct Label*)0 && strcmp(label,run->label); run=run->next);
|
|
|
|
}
|
|
|
|
if (run)
|
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
result.type = LOCATION;
|
|
|
|
LOCATION_GETS(result.u.location, run->location);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
result.type = EEK;
|
2019-07-30 19:07:54 +00:00
|
|
|
char *pref = _("No such label: ");
|
|
|
|
result.u.err = malloc(strlen(pref) + strlen(label) + 1);
|
|
|
|
strcpy(result.u.err, pref);
|
|
|
|
strcat(result.u.err, label);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
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
|
|
|
/* search and replace for labels in a token */
|
|
|
|
|
|
|
|
static void relabel_token(Token *tok, const char *oldl, const char *newl)
|
|
|
|
{
|
|
|
|
switch (tok->type)
|
|
|
|
{
|
|
|
|
case LIDENT:
|
|
|
|
if (strcmp(tok->u.lident, oldl) == 0)
|
|
|
|
{
|
|
|
|
tfree(tok);
|
|
|
|
tok->type = LIDENT;
|
|
|
|
tok->u.lident = strdup(newl);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FUNCALL:
|
|
|
|
for (int ai = 0; ai < tok->u.funcall.argc; ++ai)
|
|
|
|
relabel_token((tok->u.funcall.argv) + ai, oldl, newl);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* relabel -- search and replace for labels */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
void relabel(Sheet *sheet, const Location at,
|
|
|
|
const char *oldlabel, const char *newlabel)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
/* asserts */ /*{{{*/
|
|
|
|
assert(oldlabel!=(const char*)0);
|
|
|
|
assert(newlabel!=(const char*)0);
|
|
|
|
/*}}}*/
|
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
|
|
|
|
2019-07-27 04:14:26 +00:00
|
|
|
if (!LOC_WITHIN(sheet, at)) return;
|
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 *cell = CELL_AT(sheet, at);
|
2019-07-27 04:14:26 +00:00
|
|
|
if (cell != NULLCELL)
|
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
|
|
|
for (TokVariety v = BASE_CONT; v <= MAX_PERSIST_TV; ++v)
|
|
|
|
relabel_token(cell->tok + v, oldlabel, newlabel);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* savetbl -- save as tbl tyble */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
const char *savetbl(Sheet *sheet, const char *name, int body,
|
|
|
|
const Location beg, const Location end,
|
|
|
|
unsigned int *count)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
/* variables */ /*{{{*/
|
|
|
|
FILE *fp=(FILE*)0; /* cause run time error */
|
2019-07-27 04:14:26 +00:00
|
|
|
Location w;
|
2019-07-22 20:32:33 +00:00
|
|
|
char buf[1024];
|
|
|
|
char num[20];
|
|
|
|
char fullname[PATH_MAX];
|
|
|
|
/*}}}*/
|
|
|
|
|
|
|
|
/* asserts */ /*{{{*/
|
|
|
|
assert(sheet!=(Sheet*)0);
|
|
|
|
assert(name!=(const char*)0);
|
|
|
|
/*}}}*/
|
|
|
|
*count=0;
|
2019-07-27 04:14:26 +00:00
|
|
|
w[X] = beg[X];
|
|
|
|
for (w[Z]=beg[Z]; w[Z]<=end[Z]; ++(w[Z]))
|
|
|
|
for (w[Y]=beg[Y]; w[Y]<=end[Y]; ++(w[Y]))
|
2019-09-03 08:41:37 +00:00
|
|
|
if (shadowed(sheet,w)) return _("Shadowed cells in first column");
|
2019-07-22 20:32:33 +00:00
|
|
|
if (!body && (fp=fopen(name,"w"))==(FILE*)0) return strerror(errno);
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[Z]=beg[Z]; w[Z]<=end[Z]; ++(w[Z]))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
if (body)
|
|
|
|
/* open new file */ /*{{{*/
|
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
sprintf(num, ".%d", w[Z]);
|
2019-07-22 20:32:33 +00:00
|
|
|
fullname[sizeof(fullname)-strlen(num)-1]='\0';
|
|
|
|
(void)strncpy(fullname,name,sizeof(fullname)-strlen(num)-1);
|
|
|
|
fullname[sizeof(fullname)-1]='\0';
|
|
|
|
(void)strncat(fullname,num,sizeof(fullname)-strlen(num)-1);
|
|
|
|
fullname[sizeof(fullname)-1]='\0';
|
|
|
|
if ((fp=fopen(fullname,"w"))==(FILE*)0) return strerror(errno);
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
else if (fputs_close(".TS\n",fp)==EOF) return strerror(errno);
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[Y]=beg[Y]; w[Y]<=end[Y]; ++(w[Y]))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
/* print format */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
if (w[Y] > beg[Y] && fputs_close(".T&\n",fp)==EOF) return strerror(errno);
|
|
|
|
for (w[X]=beg[X]; w[X]<=end[X]; ++(w[X]))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
if (w[X] > beg [X] && fputc_close(' ',fp)==EOF) return strerror(errno);
|
2019-09-03 08:41:37 +00:00
|
|
|
Style sw = getstyle(sheet,w);
|
|
|
|
if (sw.shadowed && fputc_close('s',fp)==EOF) return strerror(errno);
|
|
|
|
if (sw.bold && fputc_close('b',fp)==EOF) return strerror(errno);
|
2019-09-18 12:49:53 +00:00
|
|
|
/* FIXME: troff for italic/dim? */
|
2019-09-03 08:41:37 +00:00
|
|
|
if (sw.underline && fputc_close('u',fp)==EOF) return strerror(errno);
|
|
|
|
switch (sw.adjust)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
case LEFT: if (fputc_close('l',fp)==EOF) return strerror(errno); break;
|
|
|
|
case RIGHT: if (fputc_close('r',fp)==EOF) return strerror(errno); break;
|
|
|
|
case CENTER: if (fputc_close('c',fp)==EOF) return strerror(errno); break;
|
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fputs_close(".\n",fp)==EOF) return strerror(errno);
|
|
|
|
/*}}}*/
|
|
|
|
/* print contents */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[X]=beg[X]; w[X]<=end[X]; ++(w[X]))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
Cell *cw = CELL_AT(sheet,w);
|
|
|
|
Style sw = getstyle(sheet,w);
|
|
|
|
if (!sw.shadowed)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
if (w[X] > beg[X] && fputc_close('\t',fp)==EOF) return strerror(errno);
|
|
|
|
if (cw != NULLCELL)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
printvalue(buf, sizeof(buf), 0, DIRECT_STRING, sw.fform,
|
|
|
|
sw.precision, sheet, w);
|
|
|
|
if (sw.transparent)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
if (fputs_close(buf,fp)==EOF) return strerror(errno);
|
|
|
|
}
|
2019-09-03 08:41:37 +00:00
|
|
|
else for (char *bufp = buf; *bufp; ++bufp) switch (*bufp)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
case '\\':
|
|
|
|
{
|
|
|
|
if (fputc_close('\\',fp)==EOF || fputc_close('e',fp)==EOF) return strerror(errno);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '_':
|
|
|
|
{
|
|
|
|
if (fputc_close('\\',fp)==EOF || fputc_close('&',fp)==EOF || fputc_close('_',fp)==EOF) return strerror(errno);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '.':
|
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
if (w[X] == beg[X] && bufp==buf && (fputc_close('\\',fp)==EOF || fputc_close('&',fp)==EOF)) return strerror(errno);
|
2019-07-22 20:32:33 +00:00
|
|
|
if (fputc_close('.',fp)==EOF) return strerror(errno);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '\'':
|
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
if (w[X] == beg[X] && bufp==buf && (fputc_close('\\',fp)==EOF || fputc_close('&',fp)==EOF)) return strerror(errno);
|
2019-07-22 20:32:33 +00:00
|
|
|
if (fputc_close('\'',fp)==EOF) return strerror(errno);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '-':
|
|
|
|
{
|
|
|
|
if (*(bufp+1)=='-')
|
|
|
|
{
|
|
|
|
if (fputc_close('-',fp)==EOF) return strerror(errno);
|
|
|
|
else ++bufp;
|
|
|
|
}
|
|
|
|
else if (fputs_close("\\-",fp)==EOF) return strerror(errno);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: if (fputc_close(*bufp,fp)==EOF) return strerror(errno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fputc_close('\n',fp)==EOF) return strerror(errno);
|
|
|
|
/*}}}*/
|
|
|
|
++*count;
|
|
|
|
}
|
|
|
|
if (!body)
|
|
|
|
{
|
|
|
|
if (fputs_close(".TE\n",fp)==EOF) return strerror(errno);
|
2019-07-27 04:14:26 +00:00
|
|
|
if (w[Z] < end[Z] && fputs_close(".bp\n",fp)==EOF) return strerror(errno);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
if (body && fclose(fp)==EOF) return strerror(errno);
|
|
|
|
}
|
|
|
|
if (!body && fclose(fp)==EOF) return strerror(errno);
|
|
|
|
return (const char*)0;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
/* savetext -- save as text */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
const char *savetext(Sheet *sheet, const char *name,
|
|
|
|
const Location beg, const Location end,
|
|
|
|
unsigned int *count)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
/* asserts */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
assert(name != (const char*)0);
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
2019-09-03 08:41:37 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
*count=0;
|
2019-09-03 08:41:37 +00:00
|
|
|
Location w;
|
2019-07-27 04:14:26 +00:00
|
|
|
w[X] = beg[X];
|
|
|
|
for (w[Z]=beg[Z]; w[Z]<=end[Z]; ++(w[Z]))
|
|
|
|
for (w[Y]=beg[Y]; w[Y]<=end[Y]; ++(w[Y]))
|
2019-09-03 08:41:37 +00:00
|
|
|
if (shadowed(sheet,w)) return _("Shadowed cells in first column");
|
|
|
|
FILE *fp;
|
2019-07-22 20:32:33 +00:00
|
|
|
if ((fp=fopen(name,"w"))==(FILE*)0) return strerror(errno);
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[Z]=beg[Z]; w[Z]<=end[Z]; ++(w[Z]))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[Y]=beg[Y]; w[Y]<=end[Y]; ++(w[Y]))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
size_t size,fill;
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[X]=beg[X]; w[X]<=end[X]; ++(w[X]))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
size = cellwidth(sheet,w);
|
2019-09-03 08:41:37 +00:00
|
|
|
Cell *cw = CELL_AT(sheet,w);
|
2019-07-27 04:14:26 +00:00
|
|
|
if (cw != NULLCELL)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
char *buf = malloc(size*UTF8SZ+1);
|
|
|
|
Style sw = getstyle(sheet,w);
|
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
|
|
|
printvalue(buf, size*UTF8SZ + 1, size, DIRECT_STRING,
|
2019-09-03 08:41:37 +00:00
|
|
|
sw.fform, sw.precision, sheet, w);
|
|
|
|
adjust(sw.adjust, buf, size);
|
2019-07-22 20:32:33 +00:00
|
|
|
if (fputs_close(buf,fp)==EOF)
|
|
|
|
{
|
|
|
|
free(buf);
|
|
|
|
return strerror(errno);
|
|
|
|
}
|
|
|
|
for (fill=strlen(buf); fill<size; ++fill) if (fputc_close(' ',fp)==EOF)
|
|
|
|
{
|
|
|
|
free(buf);
|
|
|
|
return strerror(errno);
|
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (fill=0; fill<size; ++fill) if (fputc_close(' ',fp)==EOF) return strerror(errno);
|
|
|
|
}
|
|
|
|
++*count;
|
|
|
|
}
|
|
|
|
if (fputc_close('\n',fp)==EOF) return strerror(errno);
|
|
|
|
}
|
2019-07-27 04:14:26 +00:00
|
|
|
if (w[Z] < end[Z] && fputs_close("\f",fp)==EOF) return strerror(errno);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
if (fclose(fp)==EOF) return strerror(errno);
|
|
|
|
return (const char*)0;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* savecsv -- save as CSV */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
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
|
|
|
{
|
|
|
|
/* asserts */ /*{{{*/
|
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
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
assert(name != (const char*)0);
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
2019-09-03 08:41:37 +00:00
|
|
|
|
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
|
|
|
*count = 0;
|
2019-09-03 08:41:37 +00:00
|
|
|
Location w;
|
2019-07-27 04:14:26 +00:00
|
|
|
w[X] = beg[X];
|
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
|
|
|
for (w[Z] = beg[Z]; w[Z] <= end[Z]; ++(w[Z]))
|
|
|
|
for (w[Y] = beg[Y]; w[Y] <= end[Y]; ++(w[Y]))
|
2019-09-03 08:41:37 +00:00
|
|
|
if (shadowed(sheet,w)) return _("Shadowed cells in first column");
|
|
|
|
FILE *fp;
|
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
|
|
|
if ((fp = fopen(name,"w")) == (FILE*)0) return strerror(errno);
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[Z]=beg[Z]; w[Z]<=end[Z]; ++(w[Z]))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[Y]=beg[Y]; w[Y]<=end[Y]; ++(w[Y]))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[X]=beg[X]; w[X]<=end[X]; ++(w[X]))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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
|
|
|
if (w[X] > beg[X])
|
|
|
|
if (fputc_close(sep,fp) == EOF) return strerror(errno);
|
|
|
|
Cell *cw = CELL_AT(sheet,w);
|
2019-07-27 04:14:26 +00:00
|
|
|
if (cw != NULLCELL)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-09 14:33:41 +00:00
|
|
|
static const size_t bufchar = 511;
|
|
|
|
static const size_t bufsz = bufchar*UTF8SZ + 1;
|
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
|
|
|
char *buf = malloc(bufsz);
|
2019-09-03 08:41:37 +00:00
|
|
|
Style sw = getstyle(sheet, w);
|
|
|
|
printvalue(buf, bufsz, bufchar, DIRECT_STRING, sw.fform,
|
|
|
|
sw.precision, sheet, w);
|
|
|
|
bool needquote = !(sw.transparent)
|
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
|
|
|
&& (strlen(buf) != strcspn(buf, "\",\n\r"));
|
|
|
|
if (needquote && fputc_close('"',fp) == EOF)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
free(buf);
|
|
|
|
return strerror(errno);
|
|
|
|
}
|
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
|
|
|
for (const char *s = buf; *s; ++s)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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
|
|
|
if (fputc_close(*s,fp) == EOF
|
|
|
|
|| (*s=='"' && needquote && fputc_close(*s,fp) == EOF))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
free(buf);
|
|
|
|
return strerror(errno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(buf);
|
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
|
|
|
if (needquote && fputc_close('"', fp) == EOF) return strerror(errno);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
++*count;
|
|
|
|
}
|
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
|
|
|
if (fputc_close('\n', fp) == EOF) return strerror(errno);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
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
|
|
|
if (w[Z] < end[Z] && fputc_close('\f', fp) == EOF) return strerror(errno);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
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
|
|
|
if (fclose(fp) == EOF) return strerror(errno);
|
2019-07-22 20:32:33 +00:00
|
|
|
return (const char*)0;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
|
|
|
static const char *saveport_contentleader[] =
|
2019-09-03 08:41:37 +00:00
|
|
|
{ [BASE_CONT] = ":", [ITER_CONT] = "\\\n", [STYLE_CONT] = "\\\n"
|
2019-07-27 04:14:26 +00:00
|
|
|
};
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* saveport -- save as portable text */ /*{{{*/
|
|
|
|
const char *saveport(Sheet *sheet, const char *name, unsigned int *count)
|
|
|
|
{
|
|
|
|
/* variables */ /*{{{*/
|
|
|
|
FILE *fp;
|
|
|
|
/*}}}*/
|
|
|
|
|
|
|
|
/* asserts */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
assert(name != (const char*)0);
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
*count = 0;
|
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
|
|
|
if ((fp = fopen(name,"w")) == (FILE*)0) return strerror(errno);
|
2019-07-22 20:32:33 +00:00
|
|
|
fprintf(fp,"# This is a work sheet generated with teapot %s.\n",VERSION);
|
2019-09-05 07:24:24 +00:00
|
|
|
for (CoordT z = (CoordT)(sheet->dim[Z] - 1); z >= 0; --z)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
for (CoordT y = (CoordT)(sheet->dim[Y] - 1); y >= 0; --y)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
for (CoordT x = (CoordT)(sheet->dim[X] - 1); x >= 0; --x)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
if (y == 0 && columnwidth(sheet,x,z) != DEF_COLUMNWIDTH)
|
2019-09-05 07:24:24 +00:00
|
|
|
fprintf(fp,"W%d %d %zu\n", x, z, columnwidth(sheet,x,z));
|
2023-04-09 05:41:50 +00:00
|
|
|
if (x == 0 && rowheight(sheet, y, z) != DEF_ROWHEIGHT)
|
|
|
|
fprintf(fp, "Y%d %d %zu\n", y, z, rowheight(sheet, y, z));
|
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 *cell = CELL_ATC(sheet,x,y,z);
|
2019-07-27 04:14:26 +00:00
|
|
|
if (cell != NULLCELL)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
fprintf(fp,"C%d %d %d ",x,y,z);
|
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
|
|
|
if (cell->label) fprintf(fp, "L%s ", cell->label);
|
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
|
|
|
if (cell->locked) fprintf(fp, "K ");
|
|
|
|
if (cell->ignored) fprintf(fp, "I ");
|
|
|
|
TokVariety lastv = MAX_PERSIST_TV;
|
|
|
|
while (lastv > BASE_CONT && cell->tok[lastv].type == EMPTY) --lastv;
|
|
|
|
for (TokVariety v = BASE_CONT; v <= lastv; ++v)
|
|
|
|
{
|
|
|
|
if (v == BASE_CONT && cell->tok[v].type == EMPTY) continue;
|
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
|
|
|
static const size_t bl = 4096;
|
|
|
|
char buf[bl];
|
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
|
|
|
if (fputs_close(saveport_contentleader[v], fp) == EOF)
|
|
|
|
return strerror(errno);
|
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
|
|
|
size_t used = printtok(buf, bl, 0, QUOTE_STRING, FLT_HEXACT,
|
|
|
|
-1, RESTORE_ERROR, cell->tok + v);
|
|
|
|
if (used > bl - 3) return _("Internal buffer overrun in saveport");
|
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
|
|
|
if (fputs_close(buf, fp) == EOF) return strerror(errno);
|
|
|
|
}
|
|
|
|
if (fputc_close('\n', fp) == EOF) return strerror(errno);
|
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
|
|
|
++(*count);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-27 04:14:26 +00:00
|
|
|
if (fclose(fp) == EOF) return strerror(errno);
|
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
|
|
|
sheet->changed = false;
|
2019-07-22 20:32:33 +00:00
|
|
|
return (const char*)0;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* loadport -- load from portable text */ /*{{{*/
|
|
|
|
const char *loadport(Sheet *sheet, const char *name)
|
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
Cell loaded;
|
2019-08-28 06:30:02 +00:00
|
|
|
FILE *fp;
|
2019-07-27 04:14:26 +00:00
|
|
|
if ((fp=fopen(name,"r")) == (FILE*)0) return strerror(errno);
|
|
|
|
freesheet(sheet, 0);
|
2019-08-28 06:30:02 +00:00
|
|
|
|
|
|
|
static char errbuf[80];
|
|
|
|
const char *err = NULL;
|
|
|
|
int line = 1;
|
|
|
|
char buf[4096];
|
|
|
|
while (fgets(buf, sizeof(buf), fp) != NULL)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
/* remove nl */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
size_t width = strlen(buf);
|
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
|
|
|
if (width > 0 && buf[width-1] == '\n') buf[--width] = '\0';
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
2023-04-09 05:41:50 +00:00
|
|
|
bool is_height = false;
|
2019-07-22 20:32:33 +00:00
|
|
|
switch (buf[0])
|
|
|
|
{
|
|
|
|
/* C -- parse cell */ /*{{{*/
|
|
|
|
case 'C':
|
|
|
|
{
|
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
|
|
|
TokVariety rv = BASE_CONT, nextrv = BASE_CONT;
|
2019-08-28 06:30:02 +00:00
|
|
|
Location loc;
|
|
|
|
|
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
|
|
|
if (width > 0 && buf[width-1]=='\\') { buf[--width]='\0'; ++nextrv; }
|
2019-07-27 07:00:03 +00:00
|
|
|
initcellcontents(&loaded);
|
2019-07-22 20:32:33 +00:00
|
|
|
/* parse x y and z */ /*{{{*/
|
2019-08-28 06:30:02 +00:00
|
|
|
const char *os = buf + 1;
|
|
|
|
char *ns = buf + 1;
|
2019-09-05 07:24:24 +00:00
|
|
|
loc[X] = (CoordT)strtol(os, &ns, 0);
|
|
|
|
if (os == ns)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
sprintf(errbuf, _("Parse error for x position in line %d"), line);
|
|
|
|
err = errbuf;
|
2019-07-22 20:32:33 +00:00
|
|
|
goto eek;
|
|
|
|
}
|
2019-09-05 07:24:24 +00:00
|
|
|
while (*ns == ' ') ++ns;
|
|
|
|
os = ns;
|
|
|
|
loc[Y] = (CoordT)strtol(os, &ns, 0);
|
|
|
|
if (os == ns)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
sprintf(errbuf, _("Parse error for y position in line %d"), line);
|
|
|
|
err = errbuf;
|
2019-07-22 20:32:33 +00:00
|
|
|
goto eek;
|
|
|
|
}
|
2019-09-05 07:24:24 +00:00
|
|
|
while (*ns == ' ') ++ns;
|
2019-07-22 20:32:33 +00:00
|
|
|
os=ns;
|
2019-09-05 07:24:24 +00:00
|
|
|
loc[Z] = (CoordT)strtol(os, &ns, 0);
|
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
|
|
|
if (os == ns)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
sprintf(errbuf, _("Parse error for z position in line %d"), line);
|
|
|
|
err = errbuf;
|
2019-07-22 20:32:33 +00:00
|
|
|
goto eek;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
/* parse optional attributes */ /*{{{*/
|
2019-09-03 08:41:37 +00:00
|
|
|
cleartoken(&(loaded.tok[STYLE_CONT]));
|
2019-07-22 20:32:33 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
while (*ns==' ') ++ns;
|
|
|
|
switch (*ns)
|
|
|
|
{
|
|
|
|
/* A -- adjustment */ /*{{{*/
|
|
|
|
case 'A':
|
|
|
|
{
|
|
|
|
++ns;
|
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
|
|
|
const char *found = strchr(Adjust_Char, *ns);
|
|
|
|
if (found != NULL)
|
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
loaded.tok[STYLE_CONT].type = STYLE;
|
|
|
|
loaded.tok[STYLE_CONT].u.style.adjust =
|
|
|
|
(Adjust)(found - Adjust_Char);
|
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
|
|
|
++ns;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sprintf(errbuf, _("Parse error for adjustment in line %d"), line);
|
|
|
|
err = errbuf;
|
|
|
|
goto eek;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
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
|
|
|
/* F -- float format */ /*{{{*/
|
|
|
|
case 'F':
|
|
|
|
{
|
|
|
|
++ns;
|
|
|
|
const char* found = strchr(FloatFormat_Char, *ns);
|
|
|
|
if (found != NULL)
|
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
loaded.tok[STYLE_CONT].type = STYLE;
|
|
|
|
loaded.tok[STYLE_CONT].u.style.fform =
|
|
|
|
(FloatFormat)(found - FloatFormat_Char);
|
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
|
|
|
++ns;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sprintf(errbuf,
|
|
|
|
_("Parse error for float format in line %d"), line);
|
|
|
|
err = errbuf;
|
|
|
|
goto eek;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-22 20:32:33 +00:00
|
|
|
/* L -- label */ /*{{{*/
|
|
|
|
case 'L':
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
char lbuf[1024];
|
|
|
|
char *p = lbuf;
|
2019-07-22 20:32:33 +00:00
|
|
|
++ns;
|
2019-09-05 07:24:24 +00:00
|
|
|
while (*ns && *ns!=' ') { *p = *ns; ++p; ++ns; }
|
|
|
|
*p = '\0';
|
|
|
|
loaded.label = strdup(lbuf);
|
2019-07-22 20:32:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
/* P -- precision */ /*{{{*/
|
|
|
|
case 'P':
|
|
|
|
{
|
|
|
|
os=++ns;
|
2019-09-03 08:41:37 +00:00
|
|
|
loaded.tok[STYLE_CONT].type = STYLE;
|
2019-09-05 07:24:24 +00:00
|
|
|
loaded.tok[STYLE_CONT].u.style.precision =
|
|
|
|
(PrecisionLevel)strtol(os, &ns, 0);
|
|
|
|
if (os == ns)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
sprintf(errbuf, _("Parse error for precision in line %d"), line);
|
|
|
|
err = errbuf;
|
2019-07-22 20:32:33 +00:00
|
|
|
goto eek;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
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
|
|
|
/* H -- hue (colors) */ /*{{{*/
|
|
|
|
case 'H':
|
|
|
|
{
|
|
|
|
os = ++ns;
|
2019-09-05 07:24:24 +00:00
|
|
|
size_t na = (size_t)strtol(os, &ns, 0);
|
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
|
|
|
if (os == ns || na > NUM_COLOR_ASPECTS)
|
|
|
|
{
|
|
|
|
sprintf(errbuf, _("Parse error for number of hues in line %d"),
|
|
|
|
line);
|
|
|
|
err = errbuf;
|
|
|
|
goto eek;
|
|
|
|
}
|
2019-09-03 08:41:37 +00:00
|
|
|
loaded.tok[STYLE_CONT].type = STYLE;
|
2019-09-05 07:24:24 +00:00
|
|
|
for (unsigned int a = 0; a < na; ++a)
|
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
|
|
|
{
|
|
|
|
while (*ns && (*ns == ' ')) { ++ns; }
|
|
|
|
os = ns;
|
2019-09-05 07:24:24 +00:00
|
|
|
loaded.tok[STYLE_CONT].u.style.aspect[a] =
|
|
|
|
(ColorNum)strtol(os, &ns, 0);
|
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
|
|
|
if (os == ns)
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
sprintf(errbuf, _("Parse error in hue %ud on line %d"),
|
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
|
|
|
a, line);
|
|
|
|
err = errbuf;
|
|
|
|
goto eek;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-22 20:32:33 +00:00
|
|
|
/* S -- shadowed */ /*{{{*/
|
|
|
|
case 'S':
|
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
if (loc[X]==0)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
sprintf(errbuf,_("Trying to shadow cell (%d,%d,%d) in line %d"),
|
|
|
|
loc[X],loc[Y],loc[Z],line);
|
2019-07-22 20:32:33 +00:00
|
|
|
err=errbuf;
|
|
|
|
goto eek;
|
|
|
|
}
|
|
|
|
++ns;
|
2019-09-03 08:41:37 +00:00
|
|
|
loaded.tok[STYLE_CONT].type = STYLE;
|
|
|
|
loaded.tok[STYLE_CONT].u.style.shadowed = true;
|
|
|
|
loaded.tok[STYLE_CONT].u.style.shadowed_set = true;
|
2019-07-22 20:32:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
/* U -- underline */ /*{{{*/
|
|
|
|
case 'U':
|
|
|
|
{
|
|
|
|
++ns;
|
2019-09-03 08:41:37 +00:00
|
|
|
loaded.tok[STYLE_CONT].type = STYLE;
|
|
|
|
loaded.tok[STYLE_CONT].u.style.underline = true;
|
|
|
|
loaded.tok[STYLE_CONT].u.style.underline_set = true;
|
2019-07-22 20:32:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
/* B -- bold */ /*{{{*/
|
|
|
|
case 'B':
|
|
|
|
{
|
|
|
|
++ns;
|
2019-09-03 08:41:37 +00:00
|
|
|
loaded.tok[STYLE_CONT].type = STYLE;
|
|
|
|
loaded.tok[STYLE_CONT].u.style.bold = true;
|
|
|
|
loaded.tok[STYLE_CONT].u.style.bold_set = true;
|
2019-07-22 20:32:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
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
|
|
|
/* E -- scientific, for backward compatibility */ /*{{{*/
|
2019-07-22 20:32:33 +00:00
|
|
|
case 'E':
|
|
|
|
{
|
|
|
|
++ns;
|
2019-09-03 08:41:37 +00:00
|
|
|
loaded.tok[STYLE_CONT].type = STYLE;
|
|
|
|
loaded.tok[STYLE_CONT].u.style.fform = FLT_SCIENTIFIC;
|
2019-07-22 20:32:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
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
|
|
|
/* K (formerly C) -- locked */ /*{{{*/
|
|
|
|
case 'C':
|
|
|
|
case 'K':
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
++ns;
|
2019-07-27 04:14:26 +00:00
|
|
|
loaded.locked=1;
|
2019-07-22 20:32:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
/* T -- transparent */ /*{{{*/
|
|
|
|
case 'T':
|
|
|
|
{
|
|
|
|
++ns;
|
2019-09-03 08:41:37 +00:00
|
|
|
loaded.tok[STYLE_CONT].type = STYLE;
|
|
|
|
loaded.tok[STYLE_CONT].u.style.transparent = true;
|
|
|
|
loaded.tok[STYLE_CONT].u.style.transparent_set = true;
|
2019-07-22 20:32:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
/* I -- ignored */ /*{{{*/
|
|
|
|
case 'I':
|
|
|
|
{
|
|
|
|
++ns;
|
2019-07-27 04:14:26 +00:00
|
|
|
loaded.ignored=1;
|
2019-07-22 20:32:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
/* : \0 -- do nothing */ /*{{{*/
|
|
|
|
case ':':
|
|
|
|
case '\0': break;
|
|
|
|
/*}}}*/
|
|
|
|
/* default -- error */ /*{{{*/
|
|
|
|
default: sprintf(errbuf,_("Invalid option %c in line %d"),*ns,line); err=errbuf; goto eek;
|
|
|
|
/*}}}*/
|
|
|
|
}
|
|
|
|
} while (*ns!=':' && *ns!='\0');
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
if (*ns) ++ns;
|
|
|
|
/* convert remaining string(s) into token sequence */ /*{{{*/
|
|
|
|
while (true)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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
|
|
|
Token **t = scan(&ns);
|
|
|
|
if (t == EMPTY_TVEC)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
sprintf(errbuf,_("Expression syntax error in line %d"),line);
|
|
|
|
err=errbuf;
|
|
|
|
goto eek;
|
|
|
|
}
|
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
|
|
|
Token pt = eval_safe(t, LITERAL);
|
|
|
|
tvecfree(t);
|
|
|
|
if (pt.type == EEK)
|
|
|
|
{
|
|
|
|
sprintf(errbuf, _("Parse error in line %d: %s"),
|
|
|
|
line, pt.u.err);
|
|
|
|
err = errbuf;
|
|
|
|
tfree(&pt);
|
|
|
|
goto eek;
|
|
|
|
}
|
|
|
|
loaded.tok[rv] = pt;
|
|
|
|
if (nextrv == rv) break;
|
|
|
|
rv = nextrv;
|
2019-07-27 04:14:26 +00:00
|
|
|
if (fgets(buf, sizeof(buf), fp) == (char*)0) break;
|
|
|
|
++line;
|
|
|
|
width = strlen(buf);
|
2019-09-03 08:41:37 +00:00
|
|
|
if (width > 0 && buf[width-1] == '\n') buf[--width] = '\0';
|
2019-07-27 04:14:26 +00:00
|
|
|
/* More content? */
|
2019-09-03 08:41:37 +00:00
|
|
|
if (width > 0 && buf[width-1] == '\\') {
|
|
|
|
buf[--width] = '\0';
|
|
|
|
++nextrv;
|
|
|
|
}
|
2019-07-27 04:14:26 +00:00
|
|
|
ns = buf;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
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
|
|
|
copycelltosheet(&loaded, sheet, loc, PRESERVE_LABEL);
|
2019-07-22 20:32:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2023-04-09 05:41:50 +00:00
|
|
|
/* Y -- row height */
|
|
|
|
case 'Y':
|
|
|
|
is_height = true;
|
|
|
|
/* FALL THROUGH */
|
2019-07-22 20:32:33 +00:00
|
|
|
/* W -- column width */ /*{{{*/
|
|
|
|
case 'W':
|
|
|
|
{
|
2023-04-09 05:41:50 +00:00
|
|
|
/* parse x/y and z */ /*{{{*/
|
2019-08-28 06:30:02 +00:00
|
|
|
const char *os = buf+1;
|
|
|
|
char *ns = buf+1;
|
2023-04-09 05:41:50 +00:00
|
|
|
CoordT cxy = (CoordT)strtol(os, &ns, 0);
|
2019-09-05 07:24:24 +00:00
|
|
|
if (os == ns)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2023-04-09 05:41:50 +00:00
|
|
|
sprintf(errbuf, _("Parse error for %c position in line %d"),
|
|
|
|
is_height ? 'y' : 'x', line);
|
2019-09-05 07:24:24 +00:00
|
|
|
err = errbuf;
|
2019-07-22 20:32:33 +00:00
|
|
|
goto eek;
|
|
|
|
}
|
2019-09-05 07:24:24 +00:00
|
|
|
while (*ns == ' ') ++ns;
|
|
|
|
os = ns;
|
|
|
|
CoordT cz = (CoordT)strtol(os, &ns, 0);
|
|
|
|
if (os == ns)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
sprintf(errbuf, _("Parse error for z position in line %d"), line);
|
|
|
|
err = errbuf;
|
2019-07-22 20:32:33 +00:00
|
|
|
goto eek;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2023-04-09 05:41:50 +00:00
|
|
|
/* parse width/height */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
while (*ns == ' ') ++ns;
|
|
|
|
os = ns;
|
2023-04-09 05:41:50 +00:00
|
|
|
long extent = strtol(os, &ns, 0);
|
2019-09-05 07:24:24 +00:00
|
|
|
if (os == ns)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
sprintf(errbuf, _("Parse error for width in line %d"), line);
|
|
|
|
err = errbuf;
|
2019-07-22 20:32:33 +00:00
|
|
|
goto eek;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2023-04-09 05:41:50 +00:00
|
|
|
if (is_height) setheight(sheet, cxy, cz, (RowHgtT)extent);
|
|
|
|
else setwidth(sheet, cxy, cz, (ColWidT)extent);
|
2019-07-22 20:32:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
/* # -- comment */ /*{{{*/
|
|
|
|
case '#': break;
|
|
|
|
/*}}}*/
|
|
|
|
/* default -- error */ /*{{{*/
|
|
|
|
default:
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
sprintf(errbuf, _("Unknown tag %c in line %d"), buf[0], line);
|
|
|
|
err = errbuf;
|
2019-07-22 20:32:33 +00:00
|
|
|
goto eek;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
}
|
|
|
|
++line;
|
|
|
|
}
|
|
|
|
eek:
|
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
|
|
|
if (fclose(fp) == EOF) {
|
|
|
|
if (err == (const char*)0) err=strerror(errno);
|
|
|
|
} else {
|
|
|
|
sheet->changed = false;
|
|
|
|
}
|
2019-07-22 20:32:33 +00:00
|
|
|
cachelabels(sheet);
|
|
|
|
forceupdate(sheet);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* loadcsv -- load/merge CSVs */ /*{{{*/
|
|
|
|
const char *loadcsv(Sheet *sheet, const char *name)
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
bool separator = false;
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
FILE *fp;
|
2019-09-05 07:24:24 +00:00
|
|
|
if ((fp = fopen(name,"r")) == (FILE*)0) return strerror(errno);
|
|
|
|
const char *err = NULL;
|
|
|
|
Location where; LOCATION_GETS(where, sheet->cur);
|
2019-07-22 20:32:33 +00:00
|
|
|
char ln[4096];
|
2019-07-27 04:14:26 +00:00
|
|
|
for (; fgets(ln,sizeof(ln),fp); ++(where[Y]))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
const char *cend;
|
|
|
|
|
|
|
|
if (!separator) { /* FIXME: find a better way to autodetect */
|
|
|
|
int ccnt = 0, scnt = 0;
|
|
|
|
char *pos = ln;
|
|
|
|
while ((pos = strchr(pos, ','))) pos++, ccnt++;
|
|
|
|
pos = ln;
|
|
|
|
while ((pos = strchr(pos, ';'))) pos++, scnt++;
|
2019-09-05 07:24:24 +00:00
|
|
|
if (ccnt || scnt) separator = true;
|
2019-07-22 20:32:33 +00:00
|
|
|
csv_setopt(scnt > ccnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
s=cend=ln;
|
2019-07-27 04:14:26 +00:00
|
|
|
where[X] = sheet->cur[X];
|
2019-07-22 20:32:33 +00:00
|
|
|
do
|
|
|
|
{
|
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
|
|
|
Token t;
|
|
|
|
t.type = EMPTY;
|
|
|
|
|
2019-09-05 07:24:24 +00:00
|
|
|
IntT lvalue = csv_long(s, &cend);
|
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
|
|
|
if (s != cend) /* ok, it is a integer */ /*{{{*/
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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
|
|
|
t.type = INT;
|
|
|
|
t.u.integer = lvalue;
|
|
|
|
puttok(sheet, where, t, BASE_CONT);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
else
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
FltT value = csv_double(s, &cend);
|
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
|
|
|
if (s != cend) /* ok, it is a double */ /*{{{*/
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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
|
|
|
t.type = FLOAT;
|
|
|
|
t.u.flt = value;
|
|
|
|
puttok(sheet, where, t, BASE_CONT);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
else
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
const char *str = csv_string(s, &cend);
|
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
|
|
|
if (s != cend) /* ok, it is a string */ /*{{{*/
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
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
|
|
|
t.type = STRING;
|
|
|
|
t.u.string = strdup(str);
|
|
|
|
puttok(sheet, where, t, BASE_CONT);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
else
|
|
|
|
{
|
|
|
|
csv_separator(s,&cend);
|
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
|
|
|
while (s == cend && *s && *s!='\n')
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
err=_("unknown values ignored");
|
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
|
|
|
csv_separator(++s, &cend);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/* else it is nothing, which does not need to be stored :) */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
} while (s != cend ? s = cend, ++(where[X]), 1 : 0);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* insertcube -- insert a block */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
void insertcube(Sheet *sh, const Location beg, const Location end, Dimensions dm)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
Location start; LOCATION_GETS(start,end);
|
|
|
|
Location fini; LOCATION_GETS(fini,beg);
|
|
|
|
start[dm] = (CoordT)(sh->dim[dm]) + end[dm] - beg[dm];
|
|
|
|
fini[dm] = end[dm]+1;
|
|
|
|
Location w;
|
|
|
|
for (w[Z] = start[Z]; w[Z] >= fini[Z]; w[Z]--)
|
|
|
|
for (w[Y] = start[Y]; w[Y] >= fini[Y]; w[Y]--)
|
2019-09-09 14:33:41 +00:00
|
|
|
for (w[X] = start[X]; w[X] >= fini[X]; w[X]--)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
resize(sh, w[X], w[Y], w[Z], NULL);
|
|
|
|
Location from; LOCATION_GETS(from,w);
|
|
|
|
from[dm] -= end[dm]-beg[dm]+1;
|
|
|
|
CELL_AT(sh,w) = CELL_AT(sh,from);
|
|
|
|
CELL_AT(sh,from) = NULLCELL;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2019-09-05 07:24:24 +00:00
|
|
|
sh->changed = true;
|
|
|
|
cachelabels(sh);
|
|
|
|
forceupdate(sh);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* deletecube -- delete a block */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
void deletecube(Sheet *sh, const Location beg, const Location end, Dimensions dm)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
Location w;
|
2019-07-22 20:32:33 +00:00
|
|
|
/* free cells in marked block */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
for (w[Z] = beg[Z]; w[Z] <= end[Z]; w[Z]++)
|
|
|
|
for (w[Y] = beg[Y]; w[Y] <= end[Y]; w[Y]++)
|
|
|
|
for (w[X] = beg[X]; w[X] <= end[X]; w[X]++)
|
|
|
|
freecellofsheet(sh, w);
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
2019-09-05 07:24:24 +00:00
|
|
|
Location fini; LOCATION_GETS(fini, end);
|
|
|
|
fini[dm] = (CoordT)(sh->dim[dm]) - (end[dm]-beg[dm]+1);
|
|
|
|
for (w[Z] = beg[Z]; w[Z] <= fini[Z]; w[Z]++)
|
|
|
|
for (w[Y] = beg[Y]; w[Y] <= fini[Y]; w[Y]++)
|
|
|
|
for (w[X] = beg[X]; w[X] <= fini[X]; w[X]++)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
Location fm; LOCATION_GETS(fm, w);
|
|
|
|
fm[dm] += end[dm]-beg[dm]+1;
|
|
|
|
if (LOC_WITHIN(sh,fm)) {
|
|
|
|
CELL_AT(sh,w) = CELL_AT(sh,fm); CELL_AT(sh,fm) = NULLCELL;
|
|
|
|
}
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2019-09-05 07:24:24 +00:00
|
|
|
sh->changed = true;
|
|
|
|
cachelabels(sh);
|
|
|
|
forceupdate(sh);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* moveblock -- move a block */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
void moveblock(Sheet *sheet, const Location beg, const Location end,
|
|
|
|
const Location dest, int copy)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
/* variables */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
Location wid, dir, fm, to, get, go;
|
|
|
|
Dimensions dim;
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
|
|
|
|
2019-07-27 04:14:26 +00:00
|
|
|
if (SAME_LOC(beg, dest)) return;
|
|
|
|
LOCATION_GETS(wid, end);
|
|
|
|
LOCATION_SUB(wid, beg);
|
|
|
|
for (dim = X; dim < HYPER; ++dim) {
|
|
|
|
if (dest[dim] > beg[dim])
|
|
|
|
{ dir[dim] = -1; fm[dim] = wid[dim]; to[dim] = beg[dim]-1; }
|
|
|
|
else
|
|
|
|
{ dir[dim] = 1; fm[dim] = 0; to[dim] = beg[dim]+wid[dim]+1; }
|
|
|
|
}
|
|
|
|
for (get[Z] = beg[Z]+fm[Z], go[Z] = dest[Z]+fm[Z];
|
|
|
|
get[Z] != to[Z]; get[Z] += dir[Z], go[Z] += dir[Z])
|
|
|
|
for (get[Y] = beg[Y]+fm[Y], go[Y] = dest[Y]+fm[Y];
|
|
|
|
get[Y] != to[Y]; get[Y] += dir[Y], go[Y] += dir[Y])
|
|
|
|
for (get[X] = beg[X]+fm[X], go[X] = dest[X]+fm[X];
|
|
|
|
get[X] != to[X]; get[X] += dir[X], go[X] += dir[X])
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 07:00:03 +00:00
|
|
|
if (!LOC_WITHIN(sheet, get)) freecellofsheet(sheet, go);
|
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
|
|
|
else if (copy)
|
|
|
|
copycelltosheet(CELL_AT(sheet, get), sheet, go, ALTER_LABEL);
|
2019-07-22 20:32:33 +00:00
|
|
|
else
|
|
|
|
{
|
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
|
|
|
resize(sheet, go[X], go[Y], go[Z], NULL);
|
2019-07-27 04:14:26 +00:00
|
|
|
CELL_AT(sheet, go) = CELL_AT(sheet, get);
|
|
|
|
CELL_AT(sheet, get) = NULLCELL;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
sheet->changed = TRUE;
|
2019-07-22 20:32:33 +00:00
|
|
|
cachelabels(sheet);
|
|
|
|
forceupdate(sheet);
|
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* sortblock -- sort a block */ /*{{{*/
|
|
|
|
/* Notes */ /*{{{*/
|
|
|
|
/*
|
|
|
|
The idea is to sort a block of cells in one direction by swapping the
|
|
|
|
planes which are canonical to the sort key vectors. An example is to
|
|
|
|
sort a two dimensional block line-wise with one column as sort key.
|
|
|
|
You can have multiple sort keys which all have the same direction and
|
|
|
|
you can sort a cube plane-wise.
|
|
|
|
*/
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
const char *sortblock(Sheet *sheet, const Location beg, const Location end,
|
2019-09-05 07:24:24 +00:00
|
|
|
Dimensions dm, Sortkey *sk, size_t sklen)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
assert(sklen > 0);
|
2019-07-22 20:32:33 +00:00
|
|
|
|
2019-09-05 07:24:24 +00:00
|
|
|
Location wbeg, wend;
|
|
|
|
LOCATION_GETS(wbeg, beg);
|
|
|
|
LOCATION_GETS(wend, end);
|
|
|
|
|
|
|
|
poscorners(wbeg, wend);
|
|
|
|
|
|
|
|
Location dist; LOCATION_GETS(dist, wend);
|
|
|
|
LOCATION_SUB(dist, wbeg);
|
|
|
|
Location one = {1, 1, 1};
|
|
|
|
LOCATION_ADD(dist, one);
|
|
|
|
|
|
|
|
Location inc; OLOCATION(inc);
|
|
|
|
inc[dm] = 1; wend[dm]--; dist[dm] = 1;
|
|
|
|
|
|
|
|
bool norel = false;
|
|
|
|
bool work;
|
2019-07-22 20:32:33 +00:00
|
|
|
do
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
work = false;
|
|
|
|
Location w;
|
|
|
|
for (LOCATION_GETS(w,wbeg); LOCATION_LEQ(w,wend); LOCATION_ADD(w,inc)) {
|
|
|
|
int r = -3;
|
|
|
|
for (size_t i = 0; i < sklen; ++i)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
Location here, there;
|
|
|
|
LOCATION_GETS(here, w);
|
|
|
|
LOCATION_ADD(here, sk[i].soff);
|
|
|
|
LOCATION_GETS(there, here);
|
|
|
|
LOCATION_ADD(there, inc);
|
|
|
|
r = cmpcell(sheet, here, sheet, there, sk[i].sortkey);
|
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
|
|
|
if (r == NOT_COMPARABLE) norel = true;
|
2019-09-05 07:24:24 +00:00
|
|
|
else if (r == -1 || r == 1) break;
|
|
|
|
else assert(r == 0);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2019-09-05 07:24:24 +00:00
|
|
|
if (r == 1)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
Location la; LOCATION_GETS(la,wbeg); la[dm] = w[dm];
|
|
|
|
Location lb; LOCATION_GETS(lb,wbeg); lb[dm] = w[dm]+inc[dm];
|
|
|
|
swapblock(sheet, la, sheet, lb, dist);
|
|
|
|
work = true;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-05 07:24:24 +00:00
|
|
|
LOCATION_SUB(wend, inc);
|
2019-07-22 20:32:33 +00:00
|
|
|
} while (work);
|
|
|
|
cachelabels(sheet);
|
|
|
|
forceupdate(sheet);
|
2019-09-03 08:41:37 +00:00
|
|
|
sheet->changed = true;
|
2019-07-22 20:32:33 +00:00
|
|
|
if (norel) return _("uncomparable elements");
|
2019-09-05 07:24:24 +00:00
|
|
|
else return NULL;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* mirrorblock -- mirror a block */ /*{{{*/
|
2019-09-05 07:24:24 +00:00
|
|
|
void mirrorblock(Sheet *sh, const Location beg, const Location end, Dimensions dm)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
Location dist; LOCATION_GETS(dist, end); LOCATION_SUB(dist, beg);
|
|
|
|
Location one = {1, 1, 1}; LOCATION_ADD(dist, one);
|
|
|
|
for (CoordT c = 0; c < (end[dm]-beg[dm]+1)/2; ++c) {
|
|
|
|
Location la; LOCATION_GETS(la, beg); la[dm] += c;
|
|
|
|
Location lb; LOCATION_GETS(lb, end); lb[dm] -= c;
|
|
|
|
swapblock(sh, la, sh, lb, dist);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2019-09-05 07:24:24 +00:00
|
|
|
sh->changed = true;
|
|
|
|
cachelabels(sh);
|
|
|
|
forceupdate(sh);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|