2019-07-22 20:32:33 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#ifdef ENABLE_UTF8
|
|
|
|
#include <ncursesw/curses.h>
|
|
|
|
#else
|
|
|
|
#include <curses.h>
|
|
|
|
#endif
|
|
|
|
#include <errno.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <signal.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>
|
2019-07-30 19:07:54 +00:00
|
|
|
extern char *strdup(const char* s);
|
2019-07-22 20:32:33 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#ifdef NEED_BCOPY
|
|
|
|
#define memmove(dst,src,len) bcopy(src,dst,len)
|
|
|
|
#endif
|
|
|
|
#ifdef OLD_REALLOC
|
|
|
|
#define realloc(s,l) myrealloc(s,l)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DMALLOC
|
|
|
|
#include "dmalloc.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include "complete.h"
|
|
|
|
#include "default.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "eval.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "sheet.h"
|
|
|
|
#include "utf8.h"
|
|
|
|
|
|
|
|
static Key wgetc(void);
|
|
|
|
|
|
|
|
/* redraw -- redraw whole screen */
|
|
|
|
static void redraw(void)
|
|
|
|
{
|
|
|
|
(void)touchwin(curscr);
|
|
|
|
(void)wrefresh(curscr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* do_attribute -- set cell attributes */
|
|
|
|
static int do_attribute(Sheet *cursheet)
|
|
|
|
{
|
|
|
|
int c;
|
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 *cc = curcell(cursheet);
|
2019-09-03 08:41:37 +00:00
|
|
|
Style sc = getstyle(cursheet, cursheet->cur);
|
2019-07-22 20:32:33 +00:00
|
|
|
do
|
|
|
|
{
|
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
|
|
|
MarkState ms = getmarkstate(cursheet);
|
|
|
|
const char* prompt = _("Block attribute");
|
2019-07-27 04:14:26 +00:00
|
|
|
if (ms == UNMARKED) prompt = _("Cell attribute");
|
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 *mainmenu[] =
|
|
|
|
{ _("jJ)ustify"), _("fF)loats"), _("tT)ypeface"),
|
|
|
|
_("mM)isc"), _("lL)abel"), _("kLock)"), NULL
|
|
|
|
};
|
2019-07-27 04:14:26 +00:00
|
|
|
c = line_menu(prompt, mainmenu, 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
|
|
|
/* There is a magic number "5" in the next line, presumably it represents
|
2019-07-27 04:14:26 +00:00
|
|
|
the selection of the lock attribute in the list of items above, in which
|
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
|
|
|
lock does indeed appear at index 5
|
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
|
|
|
if (ms == UNMARKED && c != 5 && locked(cc))
|
|
|
|
line_msg(_("Cell attribute:"), _("Cell is locked"));
|
2019-07-22 20:32:33 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (c)
|
|
|
|
{
|
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
|
|
|
case -2: case -1: c = KEY_CANCEL; break;
|
2019-07-22 20:32:33 +00:00
|
|
|
case 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
|
|
|
const char *justifymenu[] =
|
|
|
|
{ _("lL)eft"), _("rR)ight"), _("cC)entered"), NULL };
|
2019-09-03 08:41:37 +00:00
|
|
|
switch (c = line_menu(prompt, justifymenu, sc.adjust))
|
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
|
|
|
case -2: case -1: c = K_INVALID; break;
|
2019-07-22 20:32:33 +00:00
|
|
|
case 0: c = ADJUST_LEFT; break;
|
|
|
|
case 1: c = ADJUST_RIGHT; break;
|
|
|
|
case 2: c = ADJUST_CENTER; break;
|
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
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
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
const char *floatmenu[] =
|
|
|
|
{ _("dD)ecimal"), _("sS)cientific"), _("cC)ompact"),
|
|
|
|
_("hH)exact"), _("pP)recision"), NULL
|
|
|
|
};
|
2019-09-03 08:41:37 +00:00
|
|
|
switch (c = line_menu(prompt, floatmenu, sc.fform))
|
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
|
|
|
{
|
|
|
|
case -2: case -1: c = K_INVALID; break;
|
|
|
|
case 0: c = ADJUST_DECIMAL; break;
|
|
|
|
case 1: c = ADJUST_SCIENTIFIC; break;
|
|
|
|
case 2: c = ADJUST_COMPACT; break;
|
|
|
|
case 3: c = ADJUST_HEXACT; break;
|
|
|
|
case 4: c = ADJUST_PRECISION; break;
|
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
const char *typemenu[] =
|
2019-09-18 12:49:53 +00:00
|
|
|
{ _("bB)old"), _("dD)im"), _("uU)nderline"),
|
2019-08-29 06:19:08 +00:00
|
|
|
_("fF)oreground"), _("kBack)ground"), NULL };
|
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
|
|
|
switch (c = line_menu(prompt, typemenu, 0))
|
|
|
|
{
|
|
|
|
case -2: case -1: c = K_INVALID; break;
|
|
|
|
case 0: c = ADJUST_BOLD; break;
|
2019-09-18 12:49:53 +00:00
|
|
|
case 1: c = ADJUST_DIM; break;
|
|
|
|
case 2: c = ADJUST_UNDERLINE; break;
|
|
|
|
case 3: c = ADJUST_FOREGROUND; break;
|
|
|
|
case 4: c = ADJUST_BACKGROUND; 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
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
const char *miscmenu[] =
|
|
|
|
{ _("sS)hadow"), _("iI)gnore"),
|
|
|
|
_("oO)utput special characters"), NULL
|
|
|
|
};
|
|
|
|
switch (c = line_menu(prompt, miscmenu, 0))
|
|
|
|
{
|
|
|
|
case -2: case -1: c = K_INVALID; break;
|
|
|
|
case 0: c = ADJUST_SHADOW; break;
|
|
|
|
case 1: c = ADJUST_IGNORE; break;
|
|
|
|
case 2: c = ADJUST_TRANSPARENT; break;
|
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 4: c = ADJUST_LABEL; break;
|
|
|
|
case 5: c = ADJUST_LOCK; break;
|
2019-07-22 20:32:33 +00:00
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (c == K_INVALID);
|
|
|
|
if (c == KEY_CANCEL) c = K_INVALID;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* do_file -- file menu */
|
|
|
|
static int do_file(Sheet *cursheet)
|
|
|
|
{
|
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
|
|
|
int c = 0;
|
2019-09-05 07:24:24 +00:00
|
|
|
do {
|
|
|
|
const char *menu[] = { _("lL)oad"), _("sS)ave"), _("nN)ame"), NULL };
|
|
|
|
switch (c = line_menu(_("File:"), menu, 0)) {
|
|
|
|
case -2:
|
|
|
|
case -1: c = KEY_CANCEL; break;
|
|
|
|
case 0: c = K_LOADMENU; break;
|
|
|
|
case 1: c = K_SAVEMENU; break;
|
|
|
|
case 2: c = K_NAME; break;
|
|
|
|
default: assert(0);
|
|
|
|
}
|
2019-07-22 20:32:33 +00:00
|
|
|
} while (c == K_INVALID);
|
|
|
|
if (c == KEY_CANCEL) c = K_INVALID;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do_shell -- spawn a shell */
|
|
|
|
static int do_shell(void)
|
|
|
|
{
|
|
|
|
pid_t pid;
|
|
|
|
struct sigaction interrupt;
|
|
|
|
|
|
|
|
refresh();
|
2019-09-05 07:24:24 +00:00
|
|
|
interrupt.sa_flags = 0;
|
2019-07-22 20:32:33 +00:00
|
|
|
sigemptyset(&interrupt.sa_mask);
|
2019-09-05 07:24:24 +00:00
|
|
|
interrupt.sa_handler = SIG_IGN;
|
|
|
|
sigaction(SIGINT, &interrupt, (struct sigaction *)0);
|
|
|
|
sigaction(SIGQUIT, &interrupt, (struct sigaction *)0);
|
2019-07-22 20:32:33 +00:00
|
|
|
switch (pid=fork())
|
|
|
|
{
|
|
|
|
/* -1 */
|
|
|
|
case -1: line_msg(_("Spawn sub shell"),strerror(errno)); break;
|
|
|
|
|
|
|
|
/* 0 */
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
const char *shell;
|
|
|
|
|
|
|
|
if ((shell=getenv("SHELL"))==(const char*)0)
|
|
|
|
{
|
|
|
|
struct passwd *pwd;
|
|
|
|
|
|
|
|
if ((pwd=getpwuid(getuid()))==(struct passwd*)0)
|
|
|
|
{
|
|
|
|
shell="/bin/sh";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shell=pwd->pw_shell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line_msg((const char*)0,_("Sub shell started"));
|
|
|
|
move(LINES-1,0);
|
|
|
|
curs_set(1);
|
|
|
|
refresh();
|
|
|
|
reset_shell_mode();
|
|
|
|
puts("\n");
|
|
|
|
interrupt.sa_handler=SIG_DFL;
|
|
|
|
sigaction(SIGINT,&interrupt,(struct sigaction *)0);
|
|
|
|
sigaction(SIGQUIT,&interrupt,(struct sigaction *)0);
|
|
|
|
execl(shell,shell,(const char*)0);
|
|
|
|
exit(127);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default */
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
pid_t r;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
while ((r=wait(&status))!=-1 && r!=pid);
|
|
|
|
reset_prog_mode();
|
|
|
|
interrupt.sa_handler=SIG_DFL;
|
|
|
|
sigaction(SIGINT,&interrupt,(struct sigaction *)0);
|
|
|
|
sigaction(SIGQUIT,&interrupt,(struct sigaction *)0);
|
|
|
|
clear();
|
|
|
|
refresh();
|
|
|
|
curs_set(0);
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* do_block -- block menu */
|
|
|
|
static int do_block(Sheet *cursheet)
|
|
|
|
{
|
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
|
|
|
int c = 0;
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
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* block[] =
|
|
|
|
{ _("ecle)ar"), _("iI)nsert"), _("dD)elete"), _("mM)ove"),
|
|
|
|
_("cC)opy"), _("fF)ill"), _("sS)ort"), _("rMir)ror"), NULL
|
|
|
|
};
|
|
|
|
switch (c = line_menu(_("Block menu:"), block, 0))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
case -2:
|
|
|
|
case -1: c = KEY_CANCEL; break;
|
|
|
|
case 0: c = BLOCK_CLEAR; break;
|
|
|
|
case 1: c = BLOCK_INSERT; break;
|
|
|
|
case 2: c = BLOCK_DELETE; break;
|
|
|
|
case 3: c = BLOCK_MOVE; break;
|
|
|
|
case 4: c = BLOCK_COPY; break;
|
|
|
|
case 5: c = BLOCK_FILL; break;
|
|
|
|
case 6: c = BLOCK_SORT; break;
|
|
|
|
case 7: c = BLOCK_MIRROR; break;
|
|
|
|
}
|
|
|
|
} while (c == K_INVALID);
|
|
|
|
if (c == KEY_CANCEL) c = K_INVALID;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-08 19:39:40 +00:00
|
|
|
Key show_menu(Sheet *cursheet)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
int c = K_INVALID;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
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* menu[] =
|
2023-04-08 19:39:40 +00:00
|
|
|
{ _("aA)ttributes"), _("wW)idth"), _("hH)eight"), _("bB)lock"),
|
|
|
|
_("fF)ile"), _("gG)oto"), _("sS)hell"), _("vV)ersion"),
|
|
|
|
_("qQ)uit"), NULL
|
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
|
|
|
};
|
2019-07-22 20:32:33 +00:00
|
|
|
switch (c=line_menu(_("Main menu:"),menu,0))
|
|
|
|
{
|
|
|
|
case -2:
|
|
|
|
case -1: c = KEY_CANCEL; break;
|
|
|
|
case 0: c = do_attribute(cursheet); break;
|
|
|
|
case 1: c = K_COLWIDTH; break;
|
2023-04-08 19:39:40 +00:00
|
|
|
case 2: c = K_ROWHEIGHT; break;
|
|
|
|
case 3: c = do_block(cursheet); break;
|
|
|
|
case 4: c = do_file(cursheet); break;
|
|
|
|
case 5: c = K_GOTO; break;
|
|
|
|
case 6: do_shell(); c = KEY_CANCEL; break;
|
|
|
|
case 7: c = K_ABOUT; break;
|
|
|
|
case 8: c = K_QUIT; break;
|
2019-07-22 20:32:33 +00:00
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
} while (c == K_INVALID);
|
|
|
|
if (c == KEY_CANCEL) c = K_INVALID;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do_bg -- background teapot */
|
|
|
|
static void do_bg(void)
|
|
|
|
{
|
|
|
|
struct termios t;
|
|
|
|
|
|
|
|
if (tcgetattr(0,&t)==0 && t.c_cc[VSUSP]!=_POSIX_VDISABLE)
|
|
|
|
{
|
|
|
|
line_msg((const char*)0,_("Teapot stopped"));
|
|
|
|
move(LINES-1,0);
|
|
|
|
curs_set(1);
|
|
|
|
refresh();
|
|
|
|
reset_shell_mode();
|
|
|
|
puts("\n");
|
|
|
|
kill(getpid(),SIGSTOP);
|
|
|
|
clear();
|
|
|
|
refresh();
|
|
|
|
reset_prog_mode();
|
|
|
|
curs_set(0);
|
|
|
|
}
|
|
|
|
else line_msg((const char*)0,_("The susp character is undefined"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void display_main(Sheet *cursheet)
|
|
|
|
{
|
2023-04-08 19:39:40 +00:00
|
|
|
cursheet->maxx = (size_t)COLS;
|
|
|
|
cursheet->maxy = (size_t)(LINES-1);
|
2019-07-22 20:32:33 +00:00
|
|
|
|
2019-09-09 14:33:41 +00:00
|
|
|
Key k;
|
2019-07-22 20:32:33 +00:00
|
|
|
do
|
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
update(cursheet);
|
|
|
|
k = wgetc();
|
|
|
|
wmove(stdscr, LINES-1, 0);
|
2019-07-22 20:32:33 +00:00
|
|
|
wclrtoeol(stdscr);
|
|
|
|
switch ((int)k)
|
|
|
|
{
|
|
|
|
case KEY_SUSPEND:
|
|
|
|
case '\032': do_bg(); k = K_INVALID; break;
|
|
|
|
case '\014': redraw(); k = K_INVALID; break;
|
|
|
|
case KEY_F(0):
|
|
|
|
case KEY_F(10): k = show_menu(cursheet); break;
|
|
|
|
}
|
2019-09-03 08:41:37 +00:00
|
|
|
} while (k == K_INVALID || !do_sheetcmd(cursheet, k, 0)
|
|
|
|
|| !doanyway(cursheet,_("Sheet modified, leave anyway?")));
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 15:35:10 +00:00
|
|
|
#define CHANNEL_MAX 1000
|
|
|
|
|
2019-08-03 00:31:48 +00:00
|
|
|
typedef short CursesColor[3];
|
2019-09-05 07:24:24 +00:00
|
|
|
void display_init(Sheet *cursheet, bool imp_redraw)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
initscr();
|
2019-07-29 15:35:10 +00:00
|
|
|
start_color();
|
2019-08-03 16:42:32 +00:00
|
|
|
init_color(DefaultCN[BACKGROUND], CHANNEL_MAX, CHANNEL_MAX, CHANNEL_MAX);
|
|
|
|
assume_default_colors(COLOR_BLACK, DefaultCN[BACKGROUND]);
|
2019-07-29 15:35:10 +00:00
|
|
|
if (debug_level > 1)
|
|
|
|
printf("Terminal has colors: %d, #colors:%d, #pairs:%d",
|
|
|
|
has_colors(), COLORS, COLOR_PAIRS);
|
2019-07-22 20:32:33 +00:00
|
|
|
curs_set(0);
|
|
|
|
noecho();
|
|
|
|
raw();
|
|
|
|
nonl();
|
|
|
|
keypad(stdscr,TRUE);
|
|
|
|
clear();
|
|
|
|
refresh();
|
|
|
|
#ifdef HAVE_TYPEAHEAD
|
2019-09-05 07:24:24 +00:00
|
|
|
if (imp_redraw) typeahead(-1);
|
2019-07-22 20:32:33 +00:00
|
|
|
#endif
|
2019-08-03 00:31:48 +00:00
|
|
|
/* allocate and initialize the palette */
|
2019-09-05 07:24:24 +00:00
|
|
|
assert(COLORS > 0);
|
|
|
|
if ((size_t)COLORS < cursheet->max_colors) cursheet->max_colors = (size_t)COLORS;
|
2019-08-03 03:21:58 +00:00
|
|
|
cursheet->palette = (void *)malloc(cursheet->max_colors*sizeof(CursesColor));
|
|
|
|
memset(cursheet->palette, '\0', cursheet->max_colors*sizeof(CursesColor));
|
2019-08-03 00:31:48 +00:00
|
|
|
CursesColor *palt = (CursesColor *)(cursheet->palette);
|
2019-09-05 07:24:24 +00:00
|
|
|
for (ColorNum i = 0; i <= DefaultCN[BACKGROUND]; ++i)
|
2019-08-03 00:31:48 +00:00
|
|
|
(void)color_content(i, &(palt[i][0]), &(palt[i][1]), &(palt[i][2]));
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 15:35:10 +00:00
|
|
|
void display_end(Sheet* sheet)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
curs_set(1);
|
|
|
|
echo();
|
|
|
|
noraw();
|
|
|
|
refresh();
|
|
|
|
endwin();
|
2019-08-03 00:31:48 +00:00
|
|
|
free(sheet->palette);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
|
2019-07-27 04:14:26 +00:00
|
|
|
void redraw_cell(Sheet *sheet, const Location at )
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
update(sheet);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
|
2023-04-08 19:39:40 +00:00
|
|
|
static RowHgtT eff_height(Sheet *sheet, CoordT y) {
|
|
|
|
RowHgtT eff = rowheight(sheet, y, sheet->cur[Z]) / ROWHEIGHT_DENOMINATOR;
|
|
|
|
if (eff == 0) return 1;
|
|
|
|
return eff;
|
|
|
|
}
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* redraw_sheet -- draw a sheet with cell cursor */
|
|
|
|
void redraw_sheet(Sheet *sheet)
|
|
|
|
{
|
|
|
|
char pbuf[80];
|
|
|
|
char *buf=malloc(128);
|
|
|
|
size_t bufsz=128;
|
|
|
|
const char *label;
|
2019-07-27 04:14:26 +00:00
|
|
|
Location tmp;
|
|
|
|
Cell *cell;
|
|
|
|
MarkState ms;
|
2019-07-22 20:32:33 +00:00
|
|
|
char *err;
|
|
|
|
char moveonly;
|
|
|
|
|
2019-09-05 07:24:24 +00:00
|
|
|
assert(sheet != (Sheet*)0);
|
2019-07-27 04:14:26 +00:00
|
|
|
assert(IN_OCTANT(sheet->cur));
|
2019-09-05 07:24:24 +00:00
|
|
|
assert(sheet->offx >= 0);
|
|
|
|
assert(sheet->offy >= 0);
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
/* correct offsets to keep cursor visible */
|
2019-09-03 08:41:37 +00:00
|
|
|
while (shadowed(sheet, sheet->cur))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
--(sheet->cur[X]);
|
|
|
|
assert(sheet->cur[X] >= 0);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2023-04-08 19:39:40 +00:00
|
|
|
/* Calculate the nearest Y offset that will show the current row */
|
2019-07-27 04:14:26 +00:00
|
|
|
if (sheet->cur[Y] < sheet->offy) sheet->offy = sheet->cur[Y];
|
2023-04-08 19:39:40 +00:00
|
|
|
else {
|
|
|
|
size_t available = sheet->maxy - 2 - (header ? 1 : 0);
|
|
|
|
CoordT newoffy = sheet->cur[Y];
|
|
|
|
size_t needed = eff_height(sheet, newoffy);
|
|
|
|
while (needed < available && newoffy > 0) {
|
|
|
|
RowHgtT prevhgt = eff_height(sheet, newoffy - 1);
|
|
|
|
if (needed + prevhgt > available) break;
|
|
|
|
needed += prevhgt;
|
|
|
|
--newoffy;
|
|
|
|
}
|
|
|
|
if (newoffy > sheet->offy) sheet->offy = newoffy;
|
|
|
|
}
|
|
|
|
/* Calculate the nearest X offset that will show the current column */
|
2019-07-27 04:14:26 +00:00
|
|
|
if (sheet->cur[X] < sheet->offx) sheet->offx = sheet->cur[X];
|
2023-04-08 19:39:40 +00:00
|
|
|
else {
|
|
|
|
size_t width = header ? 4 : 0;
|
|
|
|
bool again;
|
|
|
|
size_t col;
|
|
|
|
do
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
again = false;
|
|
|
|
col = 0;
|
2023-04-08 19:39:40 +00:00
|
|
|
for (CoordT x = sheet->offx;
|
2019-09-05 07:24:24 +00:00
|
|
|
width <= (size_t)(sheet->maxx);
|
2019-07-27 04:14:26 +00:00
|
|
|
width += columnwidth(sheet, x, sheet->cur[Z]), ++x, ++col);
|
2019-07-22 20:32:33 +00:00
|
|
|
--col;
|
2019-07-27 04:14:26 +00:00
|
|
|
sheet->width = col;
|
|
|
|
if (sheet->cur[X] != sheet->offx)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
if (col==0) { ++sheet->offx; again = true; }
|
|
|
|
else if ((size_t)(sheet->cur[X] - sheet->offx) >= col) {
|
|
|
|
sheet->offx++; again = true;
|
2019-07-27 04:14:26 +00:00
|
|
|
}
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2023-04-08 19:39:40 +00:00
|
|
|
} while (again);
|
|
|
|
}
|
2019-07-22 20:32:33 +00:00
|
|
|
|
2019-09-05 07:24:24 +00:00
|
|
|
short curcp = 1;
|
2019-08-03 16:42:32 +00:00
|
|
|
init_pair(curcp, DefaultCN[FOREGROUND], COLOR_YELLOW);
|
2019-08-03 03:21:58 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
if (header) {
|
|
|
|
(void)wattron(stdscr,DEF_NUMBER);
|
|
|
|
/* draw x numbers */
|
2023-04-08 19:39:40 +00:00
|
|
|
for (size_t width=4; width < (size_t)(sheet->maxx); ++width)
|
2019-09-09 14:33:41 +00:00
|
|
|
mvwaddch(stdscr, (int)(sheet->oriy), (int)(sheet->orix + width),
|
2019-07-27 04:14:26 +00:00
|
|
|
(chtype)(unsigned char)' ');
|
2023-04-08 19:39:40 +00:00
|
|
|
ColWidT width = 4;
|
|
|
|
for (CoordT x = sheet->offx; width < sheet->maxx; ++x)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
short usecp = 0;
|
2019-08-03 03:21:58 +00:00
|
|
|
if (x == sheet->cur[X]) usecp = curcp;
|
2023-04-08 19:39:40 +00:00
|
|
|
ColWidT col = columnwidth(sheet, x, sheet->cur[Z]);
|
2019-07-22 20:32:33 +00:00
|
|
|
if (bufsz<(size_t)(col*UTF8SZ+1)) buf=realloc(buf,bufsz=(size_t)(col*UTF8SZ+1));
|
|
|
|
snprintf(buf,bufsz,"%d",x);
|
|
|
|
if (mbslen(buf)>col) {
|
|
|
|
buf[col-1]='$';
|
|
|
|
buf[col]='\0';
|
|
|
|
}
|
|
|
|
adjust(CENTER,buf,(size_t)col);
|
2019-09-05 07:24:24 +00:00
|
|
|
assert((size_t)sheet->maxx >= width);
|
|
|
|
if ((size_t)(sheet->maxx)-width < col)
|
|
|
|
buf[(size_t)(sheet->maxx)-width] = '\0';
|
2019-08-03 03:21:58 +00:00
|
|
|
wcolor_set(stdscr, usecp, NULL);
|
2019-09-09 14:33:41 +00:00
|
|
|
mvwaddstr(stdscr, (int)(sheet->oriy), (int)(sheet->orix+width), buf);
|
2023-04-08 19:39:40 +00:00
|
|
|
ColWidT used = strlen(buf);
|
|
|
|
while (used++ < col) waddch(stdscr, (chtype)(unsigned char)' ');
|
2019-08-03 03:21:58 +00:00
|
|
|
wcolor_set(stdscr, 0, NULL);
|
2023-04-08 19:39:40 +00:00
|
|
|
width += col;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* draw y numbers */
|
2023-04-08 19:39:40 +00:00
|
|
|
RowHgtT height = 1;
|
|
|
|
for (CoordT y = sheet->offy; height + 1 < sheet->maxy; ++y) {
|
2019-09-05 07:24:24 +00:00
|
|
|
short usecp = 0;
|
2023-04-08 19:39:40 +00:00
|
|
|
if (y == sheet->cur[Y]) usecp = curcp;
|
2019-08-03 03:21:58 +00:00
|
|
|
wcolor_set(stdscr, usecp, NULL);
|
2023-04-08 19:39:40 +00:00
|
|
|
(void)mvwprintw(stdscr, (int)(height+sheet->oriy), (int)sheet->orix,
|
|
|
|
"%-4d", y);
|
|
|
|
RowHgtT rows = eff_height(sheet, y);
|
|
|
|
for (RowHgtT extra = 1; extra < rows; ++extra) {
|
|
|
|
mvwaddstr(stdscr, (int)(height+extra+sheet->oriy), (int)sheet->orix,
|
|
|
|
" ");
|
|
|
|
}
|
2019-08-03 03:21:58 +00:00
|
|
|
wcolor_set(stdscr, 0, NULL);
|
2023-04-08 19:39:40 +00:00
|
|
|
height += eff_height(sheet, y);
|
2019-08-03 03:21:58 +00:00
|
|
|
}
|
2019-07-22 20:32:33 +00:00
|
|
|
(void)wattroff(stdscr,DEF_NUMBER);
|
|
|
|
|
|
|
|
/* draw z number */
|
2019-09-05 07:24:24 +00:00
|
|
|
(void)mvwprintw(stdscr, (CoordT)(sheet->oriy), (CoordT)(sheet->orix),
|
|
|
|
"%3d", sheet->cur[Z]);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2019-08-03 03:21:58 +00:00
|
|
|
++curcp;
|
2019-07-22 20:32:33 +00:00
|
|
|
/* draw elements */
|
2023-04-08 19:39:40 +00:00
|
|
|
RowHgtT height = header ? 1 : 0;
|
|
|
|
for (CoordT y = sheet->offy; height + 1 < sheet->maxy; ++y) {
|
|
|
|
RowHgtT rows = eff_height(sheet, y);
|
|
|
|
ColWidT width = header ? 4 : 0;
|
|
|
|
for (CoordT x = sheet->offx;
|
|
|
|
width < sheet->maxx;
|
2019-09-05 07:24:24 +00:00
|
|
|
width += columnwidth(sheet, x, sheet->cur[Z]), ++x)
|
2023-04-08 19:39:40 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
size_t size,realsize,fill, cutoff = 0;
|
|
|
|
int realx = x;
|
2019-09-03 08:41:37 +00:00
|
|
|
if (x == sheet->offx) {
|
|
|
|
Location fil;
|
|
|
|
fil[X] = realx;
|
2019-09-05 07:24:24 +00:00
|
|
|
fil[Y] = y - (header ? 1 : 0) + sheet->offy;
|
2019-09-03 08:41:37 +00:00
|
|
|
fil[Z] = sheet->cur[Z];
|
|
|
|
while (shadowed(sheet, fil)) {
|
|
|
|
--realx; fil[X] = realx;
|
|
|
|
cutoff += columnwidth(sheet, realx, sheet->cur[Z]);
|
|
|
|
}
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2023-04-08 19:39:40 +00:00
|
|
|
tmp[X] = realx; tmp[Y] = y;
|
2019-09-03 08:41:37 +00:00
|
|
|
tmp[Z] = sheet->cur[Z];
|
|
|
|
cell = safe_cell_at(sheet, tmp);
|
|
|
|
Style sc = getstyle(sheet, tmp);
|
2019-07-27 04:14:26 +00:00
|
|
|
if ((size = cellwidth(sheet, tmp)))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
if (bufsz < (size*UTF8SZ+1))
|
|
|
|
buf = realloc(buf, bufsz=(size*UTF8SZ+1));
|
2019-09-18 12:49:53 +00:00
|
|
|
size_t esize = size; char* ebuf = buf;
|
|
|
|
if (sc.italic) { esize -= 2; *buf = '*'; ebuf += 1; }
|
|
|
|
size_t spot = printvalue(ebuf, (esize*UTF8SZ + 1), esize, quote,
|
|
|
|
sc.fform, sc.precision, sheet, tmp);
|
|
|
|
if (sc.italic) { ebuf[spot++] = '*'; ebuf[spot] = '\0'; }
|
2019-09-03 08:41:37 +00:00
|
|
|
adjust(sc.adjust, buf, size);
|
2019-09-18 12:49:53 +00:00
|
|
|
assert(size >= cutoff);
|
2019-09-05 07:24:24 +00:00
|
|
|
if (width + size - cutoff >= (size_t)(sheet->maxx))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
*(buf + cutoff + (size_t)sheet->maxx - width) = '\0';
|
|
|
|
realsize = (size_t)(sheet->maxx) - width + cutoff;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2019-09-05 07:24:24 +00:00
|
|
|
else realsize = size;
|
2019-07-27 04:14:26 +00:00
|
|
|
ms = getmarkstate(sheet);
|
2019-09-05 07:24:24 +00:00
|
|
|
short usecp = 0;
|
2019-09-03 08:41:37 +00:00
|
|
|
ColorNum fg = sc.aspect[FOREGROUND];
|
|
|
|
if (fg == NO_COLOR_SET) fg = DefaultCN[FOREGROUND];
|
|
|
|
ColorNum bg = sc.aspect[BACKGROUND];
|
|
|
|
if (bg == NO_COLOR_SET) bg = DefaultCN[BACKGROUND];
|
2019-08-29 06:19:08 +00:00
|
|
|
while (usecp < curcp) {
|
2019-09-05 07:24:24 +00:00
|
|
|
short pfg, pbg;
|
2019-08-29 06:19:08 +00:00
|
|
|
pair_content(usecp, &pfg, &pbg);
|
|
|
|
if (fg == pfg && bg == pbg) break;
|
|
|
|
++usecp;
|
|
|
|
}
|
|
|
|
if (usecp == curcp) init_pair(curcp++, fg, bg);
|
|
|
|
wcolor_set(stdscr, usecp, NULL);
|
2019-09-18 12:49:53 +00:00
|
|
|
bool invert =
|
2019-07-27 04:14:26 +00:00
|
|
|
(ms != UNMARKED) && loc_in_box(tmp, sheet->mark1, sheet->mark2);
|
2023-04-08 19:39:40 +00:00
|
|
|
if (x == sheet->cur[X] && y == sheet->cur[Y])
|
2019-07-27 04:14:26 +00:00
|
|
|
invert = (ms == MARKING) ? true : !invert;
|
2019-07-22 20:32:33 +00:00
|
|
|
if (invert) (void)wattron(stdscr,DEF_CELLCURSOR);
|
2019-09-18 12:49:53 +00:00
|
|
|
if (sc.dim) wattron(stdscr, A_DIM);
|
|
|
|
if (sc.bold) wattron(stdscr, A_BOLD);
|
|
|
|
if (sc.underline) wattron(stdscr, A_UNDERLINE);
|
2023-04-08 19:39:40 +00:00
|
|
|
(void)mvwaddstr(stdscr, (int)(height + sheet->oriy),
|
|
|
|
(int)(width + sheet->orix),
|
2019-09-05 07:24:24 +00:00
|
|
|
buf+cutoff);
|
2019-07-27 04:14:26 +00:00
|
|
|
for (fill=mbslen(buf+cutoff); fill<realsize; ++fill)
|
|
|
|
(void)waddch(stdscr,(chtype)(unsigned char)' ');
|
2023-04-08 19:39:40 +00:00
|
|
|
for (RowHgtT extra = 1; extra < rows; ++extra) {
|
|
|
|
mvwaddstr(stdscr,
|
|
|
|
(int)(height + extra + sheet->oriy),
|
|
|
|
(int)(width + sheet->orix),
|
|
|
|
" ");
|
|
|
|
for (fill = 1; fill < realsize; ++fill)
|
|
|
|
(void)waddch(stdscr, (chtype)(unsigned char)' ');
|
|
|
|
}
|
2019-08-29 06:19:08 +00:00
|
|
|
wcolor_set(stdscr, 0, NULL);
|
2019-07-22 20:32:33 +00:00
|
|
|
wstandend(stdscr);
|
|
|
|
}
|
2023-04-08 19:39:40 +00:00
|
|
|
}
|
|
|
|
height += rows;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* draw contents of current element */
|
2019-09-05 07:24:24 +00:00
|
|
|
if (bufsz < (size_t)(sheet->maxx)*UTF8SZ + 1)
|
|
|
|
buf = realloc(buf, bufsz = (size_t)(sheet->maxx)*UTF8SZ + 1);
|
2019-07-27 04:14:26 +00:00
|
|
|
label = getlabel(curcell(sheet));
|
|
|
|
assert(label != (const char*)0);
|
|
|
|
moveonly = sheet->moveonly ? *_("V") : *_("E");
|
|
|
|
if (*label=='\0')
|
|
|
|
sprintf(pbuf, "%c @(%d,%d,%d)=", moveonly,
|
|
|
|
sheet->cur[X], sheet->cur[Y], sheet->cur[Z]);
|
|
|
|
else sprintf(pbuf, "%c @(%s)=", moveonly, label);
|
2019-07-22 20:32:33 +00:00
|
|
|
(void)strncpy(buf,pbuf,bufsz);
|
|
|
|
buf[bufsz-1] = 0;
|
2019-07-27 04:14:26 +00:00
|
|
|
if ((err=geterror(sheet,sheet->cur)) != (const char*)0)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
(void)strncpy(buf, err, bufsz);
|
|
|
|
free(err);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
cell = curcell(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
|
|
|
Token bc = gettok(cell, BASE_CONT);
|
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
|
|
|
printtok(buf+strlen(buf), bufsz-strlen(buf), 0, QUOTE_STRING,
|
2019-09-03 08:41:37 +00:00
|
|
|
FLT_COMPACT, -1, TRUNCATED_ERROR, &bc);
|
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 ic = gettok(cell, ITER_CONT);
|
2019-09-05 07:24:24 +00:00
|
|
|
if (ic.type != EMPTY && mbslen(buf) < (size_t)(sheet->maxx + 1 - 4))
|
2019-07-27 04:14:26 +00:00
|
|
|
{
|
|
|
|
strcat(buf," -> ");
|
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
|
|
|
printtok(buf+strlen(buf), bufsz-strlen(buf), 0, QUOTE_STRING,
|
2019-09-03 08:41:37 +00:00
|
|
|
FLT_COMPACT, -1, TRUNCATED_ERROR, &ic);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
2023-04-08 19:39:40 +00:00
|
|
|
*mbspos(buf, (int)sheet->maxx) = 0;
|
2019-09-09 14:33:41 +00:00
|
|
|
|
2023-04-08 19:39:40 +00:00
|
|
|
(void)mvwaddstr(stdscr, (int)(sheet->oriy + sheet->maxy) - 1,
|
2019-09-09 14:33:41 +00:00
|
|
|
(int)(sheet->orix), buf);
|
2023-04-08 19:39:40 +00:00
|
|
|
for (size_t col = mbslen(buf); col < sheet->maxx; ++col)
|
2019-09-05 07:24:24 +00:00
|
|
|
(void)waddch(stdscr, ' ');
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* line_file -- line editor function for file name entry */
|
|
|
|
const char *line_file(const char *file, const char *pattern, const char *title, int create)
|
|
|
|
{
|
|
|
|
static char buf[PATH_MAX] = "";
|
|
|
|
int rc;
|
|
|
|
size_t dummy1 = 0, dummy2 = 0;
|
|
|
|
|
|
|
|
if (file) strncpy(buf, file, sizeof(buf));
|
|
|
|
buf[sizeof(buf)-1] = 0;
|
|
|
|
rc = line_edit((Sheet*)0, buf, sizeof(buf), title, &dummy1, &dummy2);
|
|
|
|
if (rc < 0) return NULL;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* line_edit -- line editor function */
|
2019-09-05 07:24:24 +00:00
|
|
|
int line_edit(Sheet *sheet, char *buf, size_t size, const char *prompt,
|
|
|
|
size_t *x, size_t *offx)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
char *src, *dest;
|
|
|
|
|
2019-09-05 07:24:24 +00:00
|
|
|
assert(buf != NULL);
|
|
|
|
assert(prompt != NULL);
|
|
|
|
assert(x != (size_t*)0);
|
|
|
|
assert(offx != (size_t*)0);
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
(void)curs_set(1);
|
|
|
|
|
2019-09-05 07:24:24 +00:00
|
|
|
bool insert = true;
|
|
|
|
int mx = COLS;
|
|
|
|
CoordT promptlen = (CoordT)(mbslen(prompt)+1);
|
|
|
|
(void)mvwaddstr(stdscr,LINES-1,0,prompt); (void)waddch(stdscr,(chtype)(unsigned char)' ');
|
|
|
|
int c;
|
2019-07-22 20:32:33 +00:00
|
|
|
do {
|
2019-09-05 07:24:24 +00:00
|
|
|
/* correct offx so cursor stays visible */
|
|
|
|
if (*x < *offx) *offx = *x;
|
|
|
|
if ((CoordT)(*x - *offx) > (mx-promptlen-1))
|
|
|
|
*offx = *x - (size_t)mx + (size_t)promptlen + 1;
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
/* display buffer */
|
2019-09-05 07:24:24 +00:00
|
|
|
(void)wmove(stdscr, LINES-1, promptlen);
|
|
|
|
src = mbspos(buf, (int)(*offx));
|
|
|
|
dest = mbspos(buf, (int)(*offx) + COLS - promptlen);
|
|
|
|
int i = 0;
|
|
|
|
for (; *src && src < dest; ++i, ++src)
|
|
|
|
(void)waddch(stdscr, (chtype)(unsigned char)(*src));
|
|
|
|
if (i != mx) (void)wclrtoeol(stdscr);
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
/* show cursor */
|
2019-09-05 07:24:24 +00:00
|
|
|
(void)wmove(stdscr, LINES-1, (CoordT)(*x-*offx) + promptlen);
|
2019-07-22 20:32:33 +00:00
|
|
|
|
2019-09-05 07:24:24 +00:00
|
|
|
src = dest = mbspos(buf, (int)(*x));
|
|
|
|
c = wgetc();
|
|
|
|
if (sheet != (Sheet*)0 && sheet->moveonly) switch (c) {
|
2019-07-22 20:32:33 +00:00
|
|
|
/* ^o -- switch back to line editor */
|
|
|
|
case '\t':
|
|
|
|
case '\017': sheet->moveonly=0; break;
|
|
|
|
|
|
|
|
/* v -- insert value of current cell */
|
|
|
|
case 'v': {
|
|
|
|
char valbuf[1024];
|
|
|
|
|
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(valbuf, sizeof(valbuf), 0, QUOTE_STRING,
|
|
|
|
FLT_COMPACT, 0, sheet, sheet->cur);
|
2019-07-22 20:32:33 +00:00
|
|
|
if (strlen(buf)+strlen(valbuf) >= (size-1)) break;
|
|
|
|
(void)memmove(src+strlen(valbuf), src, strlen(src));
|
|
|
|
(void)memcpy(src, valbuf, strlen(valbuf));
|
|
|
|
(*x) += mbslen(valbuf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* p -- insert position of current cell */
|
|
|
|
case 'p': {
|
|
|
|
char valbuf[1024];
|
|
|
|
|
2019-07-27 04:14:26 +00:00
|
|
|
sprintf(valbuf, "(%d,%d,%d)",
|
|
|
|
sheet->cur[X], sheet->cur[Y], sheet->cur[Z]);
|
2019-07-22 20:32:33 +00:00
|
|
|
if (strlen(buf)+strlen(valbuf) >= (size-1)) break;
|
|
|
|
(void)memmove(src+strlen(valbuf), src, strlen(src));
|
|
|
|
(void)memcpy(src, valbuf, strlen(valbuf));
|
|
|
|
(*x) += mbslen(valbuf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default -- move around in sheet */
|
|
|
|
default:
|
|
|
|
(void)do_sheetcmd(sheet,c,1);
|
|
|
|
redraw_sheet(sheet);
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else switch (c) {
|
|
|
|
/* UP */
|
|
|
|
case K_UP: break;
|
|
|
|
|
|
|
|
/* LEFT */
|
|
|
|
case K_LEFT: if (*x > 0) (*x)--; break;
|
|
|
|
|
|
|
|
/* RIGHT */
|
|
|
|
case K_RIGHT: if (*x < mbslen(buf)) (*x)++; break;
|
|
|
|
|
|
|
|
/* BACKSPACE */
|
|
|
|
case K_BACKSPACE:
|
|
|
|
if (*x > 0) {
|
|
|
|
memmove(mbspos(src, -1), src, strlen(src)+1);
|
|
|
|
(*x)--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* C-i -- file name completion */
|
|
|
|
case '\t':
|
|
|
|
completefile(buf, src, size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* DC */
|
|
|
|
case K_DC:
|
|
|
|
src = mbspos(dest, 1);
|
|
|
|
if (*x < strlen(buf)) memmove(dest, src, strlen(src)+1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* HOME */
|
|
|
|
case K_HOME:
|
|
|
|
*x = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* END */
|
|
|
|
case K_END:
|
|
|
|
*x = mbslen(buf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* IC */
|
|
|
|
case KEY_IC:
|
2019-09-05 07:24:24 +00:00
|
|
|
insert = !insert;
|
2019-07-22 20:32:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* EIC */
|
|
|
|
case KEY_EIC:
|
2019-09-05 07:24:24 +00:00
|
|
|
insert = false;
|
2019-07-22 20:32:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* control t */
|
|
|
|
case '\024':
|
|
|
|
if (*x > 0) {
|
|
|
|
dest = mbspos(src, -1);
|
|
|
|
if (*x == mbslen(buf)) {
|
|
|
|
src = dest;
|
|
|
|
dest = mbspos(src, -1);
|
|
|
|
(*x)--;
|
|
|
|
}
|
2019-09-05 07:24:24 +00:00
|
|
|
char *end = mbspos(src, 1);
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
while (src != end) {
|
2019-09-09 14:33:41 +00:00
|
|
|
char k = *src;
|
|
|
|
memmove(dest+1, dest, (size_t)(src-dest));
|
|
|
|
*dest = k;
|
|
|
|
src++;
|
|
|
|
dest++;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
(*x)++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* control backslash */
|
|
|
|
case '\034': {
|
|
|
|
int level;
|
|
|
|
char open = 0, close = 0, dir = 1;
|
|
|
|
|
|
|
|
switch (*dest) {
|
2019-09-09 14:33:41 +00:00
|
|
|
case ')': dir = -1; /* FALL THROUGH */
|
2019-07-22 20:32:33 +00:00
|
|
|
case '(': open = '('; close = ')'; break;
|
2019-09-09 14:33:41 +00:00
|
|
|
case '}': dir = -1; /* FALL THROUGH */
|
2019-07-22 20:32:33 +00:00
|
|
|
case '{': open = '{'; close = '}'; break;
|
2019-09-09 14:33:41 +00:00
|
|
|
case ']': dir = -1; /* FALL THROUGH */
|
2019-07-22 20:32:33 +00:00
|
|
|
case '[': open = '['; close = ']'; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
level = dir;
|
|
|
|
while (*dest && level) {
|
|
|
|
dest += dir;
|
|
|
|
if (*dest == open) level--;
|
|
|
|
else if (*dest == close) level++;
|
|
|
|
}
|
|
|
|
if (!level) *x = mbslen(buf)-mbslen(dest);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DL */
|
|
|
|
case KEY_DL:
|
|
|
|
*src = '\0';
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* control o */
|
|
|
|
case '\017':
|
|
|
|
if (sheet!=(Sheet*)0) sheet->moveonly=1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* default */
|
2019-09-05 07:24:24 +00:00
|
|
|
default: {
|
|
|
|
if (((unsigned int)c) < ' ' || ((unsigned int)c) >= 256) break;
|
|
|
|
bool iscont = is_mbcont((unsigned char)c);
|
|
|
|
if (strlen(buf) >= (size-1)) {
|
|
|
|
if (iscont) {
|
|
|
|
dest = mbspos(src, -1);
|
|
|
|
memmove(dest, src, strlen(src)+1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (insert || iscont) memmove(src+1, src, strlen(src)+1);
|
|
|
|
else {
|
|
|
|
if (is_mbchar((unsigned char)(*src)))
|
|
|
|
memmove(src+1, mbspos(src, 1), strlen(mbspos(src, 1))+1);
|
|
|
|
if (!*src) *(src+1) = '\0';
|
|
|
|
}
|
|
|
|
*src = (char)c;
|
|
|
|
if (!iscont) (*x)++;
|
|
|
|
break;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
2019-09-05 07:24:24 +00:00
|
|
|
}
|
|
|
|
} while (c != K_ENTER && c != KEY_CANCEL
|
|
|
|
&& (c != K_UP || (sheet!=(Sheet*)0 && sheet->moveonly)));
|
2019-07-22 20:32:33 +00:00
|
|
|
|
2019-09-05 07:24:24 +00:00
|
|
|
if (sheet) sheet->moveonly = false;
|
2019-07-22 20:32:33 +00:00
|
|
|
(void)curs_set(0);
|
2019-09-05 07:24:24 +00:00
|
|
|
(void)wmove(stdscr, LINES-1, 0);
|
2019-07-22 20:32:33 +00:00
|
|
|
(void)wclrtoeol(stdscr);
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case KEY_CANCEL: return -1;
|
|
|
|
case K_UP: return -2;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* line_ok -- one line yes/no menu */
|
|
|
|
int line_ok(const char *prompt, int curx)
|
|
|
|
{
|
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
|
|
|
assert(curx == 0 || curx == 1);
|
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
|
|
|
const char* menu[] = { _("nN)o"), _("yY)es"), NULL };
|
2019-08-03 00:31:48 +00:00
|
|
|
return line_menu(prompt, menu, curx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* line_binary -- two choices with cancel */
|
|
|
|
int line_binary(const char *prompt, const char* op1, const char* op2, int curx)
|
|
|
|
{
|
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
|
|
|
assert(curx == 0 || curx == 1);
|
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
|
|
|
const char* menu[] = { _("cC)ancel"), op1, op2, NULL };
|
2019-08-03 00:31:48 +00:00
|
|
|
return line_menu(prompt, menu, curx+1) - 1;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* line_menu -- one line menu */
|
|
|
|
/* Notes */
|
|
|
|
/*
|
|
|
|
|
|
|
|
The choices are terminated by the last element having a (const char*)str
|
|
|
|
field. Each item can be chosen by tolower(*str) or by the key stored in
|
|
|
|
the c field. Use a space as first character of str, if you only want the
|
|
|
|
function key to work.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
int line_menu(const char *prompt, const char **choice, int curx)
|
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
|
|
|
assert(prompt != NULL);
|
|
|
|
assert(choice != (const char **)0);
|
|
|
|
assert(curx >= 0);
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
mvwaddstr(stdscr,LINES-1,0,prompt);
|
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 promptlen = mbslen(prompt);
|
|
|
|
int maxx = 0;
|
|
|
|
while (choice[maxx] != NULL) ++maxx;
|
|
|
|
int offx = 0;
|
2019-09-05 07:24:24 +00:00
|
|
|
int c;
|
2019-07-22 20:32:33 +00:00
|
|
|
do
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
int x;
|
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
|
|
|
(void)wmove(stdscr, LINES-1, (int)promptlen);
|
2019-07-22 20:32:33 +00:00
|
|
|
/* correct offset so choice is visible */
|
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 (curx <= offx) offx = curx;
|
2019-07-22 20:32:33 +00:00
|
|
|
else do
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
size_t width = promptlen;
|
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
|
|
|
x = offx;
|
2019-09-05 07:24:24 +00:00
|
|
|
while (x < maxx && width + mbslen(choice[x]+1) + 1 <= (size_t)COLS)
|
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
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
width += mbslen(choice[x]+1) + 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
|
|
|
++x;
|
|
|
|
}
|
2019-07-22 20:32:33 +00:00
|
|
|
--x;
|
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 (x < curx) ++offx;
|
|
|
|
} while (x < curx);
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
/* show visible choices */
|
2019-09-05 07:24:24 +00:00
|
|
|
size_t width = promptlen;
|
|
|
|
for (x = offx; x < maxx && width + mbslen(choice[x]+1) + 1 <= (size_t)COLS;
|
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
|
|
|
width += mbslen(choice[x]+1) + 1, ++x)
|
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
|
|
|
(void)waddch(stdscr, (chtype)(unsigned char)' ');
|
|
|
|
if (x == curx) (void)wattron(stdscr, DEF_MENU);
|
|
|
|
(void)waddstr(stdscr, (char*)(choice[x]+1));
|
|
|
|
if (x == curx) (void)wattroff(stdscr,DEF_MENU);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 07:24:24 +00:00
|
|
|
if (width < (size_t)COLS) (void)wclrtoeol(stdscr);
|
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
|
|
|
switch (c = wgetc())
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
/* KEY_LEFT -- move to previous item */
|
|
|
|
case K_BACKSPACE:
|
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
|
|
|
case K_LEFT: if (curx > 0) --curx; else curx = maxx-1; break;
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
/* Space, Tab, KEY_RIGHT -- move to next item */
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
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
|
|
|
case K_RIGHT: if (curx < (maxx-1)) ++curx; else curx = 0; break;
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
/* default -- search choice keys */
|
|
|
|
default:
|
|
|
|
{
|
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
|
|
|
for (int i = 0; i < maxx; ++i)
|
|
|
|
if (c < 256 && tolower(c) == choice[i][0])
|
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
|
|
|
c = K_ENTER;
|
|
|
|
curx = i;
|
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
|
|
|
while (c != K_ENTER && c != K_DOWN && c != KEY_CANCEL && c != K_UP);
|
|
|
|
(void)wmove(stdscr, LINES-1, 0);
|
2019-07-22 20:32:33 +00:00
|
|
|
(void)wclrtoeol(stdscr);
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case KEY_CANCEL: return -1;
|
|
|
|
case K_UP: return -2;
|
|
|
|
default: return curx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* line_msg -- one line message which will be cleared by someone else */
|
|
|
|
void line_msg(const char *prompt, const char *msg)
|
|
|
|
{
|
|
|
|
|
|
|
|
int width;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert(msg!=(const char*)0);
|
|
|
|
if (!*msg) msg = _("Use F0, F10 or / for menu");
|
|
|
|
|
|
|
|
if (!batch)
|
|
|
|
{
|
|
|
|
width=1;
|
|
|
|
mvwaddch(stdscr,LINES-1,0,(chtype)(unsigned char)'[');
|
|
|
|
if (prompt!=(const char*)0)
|
|
|
|
{
|
|
|
|
for (; width<COLS && *prompt!='\0'; ++width,++prompt) (void)waddch(stdscr,(chtype)(unsigned char)(*prompt));
|
|
|
|
if (width<COLS) { (void)waddch(stdscr,(chtype)(unsigned char)' '); ++width; }
|
|
|
|
}
|
|
|
|
for (; width<COLS && *msg!='\0'; ++width,++msg) (void)waddch(stdscr,(chtype)(unsigned char)(*msg));
|
|
|
|
if (width<COLS) (void)waddch(stdscr,(chtype)(unsigned char)']');
|
|
|
|
if (width+1<COLS) (void)wclrtoeol(stdscr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (prompt) fprintf(stderr,_("line %u: %s %s\n"),batchln,prompt,msg);
|
|
|
|
else fprintf(stderr,_("line %u: %s\n"),batchln,msg);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void show_text(const char *text)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *end, *stripped;
|
|
|
|
|
|
|
|
stripped = striphtml(text);
|
|
|
|
text = stripped-1;
|
|
|
|
|
|
|
|
while (text) {
|
|
|
|
(void)clear();
|
|
|
|
for (i = 0; i < LINES-2 && text; i++) {
|
|
|
|
end = strchr(++text, '\n');
|
|
|
|
if (*text == '\f') break;
|
|
|
|
if (end) *end = 0;
|
2019-09-05 07:24:24 +00:00
|
|
|
(void)move(i, (COLS - (CoordT)mbslen(text))/2);
|
2019-07-22 20:32:33 +00:00
|
|
|
(void)addstr(text);
|
|
|
|
text = end;
|
|
|
|
}
|
|
|
|
(void)move(i+1, (COLS-29)/2); (void)addstr(_("[ Press any key to continue ]"));
|
|
|
|
(void)refresh();
|
|
|
|
(void)getch();
|
|
|
|
}
|
|
|
|
|
|
|
|
free(stripped);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* keypressed -- get keypress, if there is one */
|
2019-09-03 08:41:37 +00:00
|
|
|
bool keypressed(void)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
2019-09-03 08:41:37 +00:00
|
|
|
(void)nodelay(stdscr, TRUE);
|
|
|
|
bool result = (getch() != ERR);
|
|
|
|
nodelay(stdscr, FALSE);
|
|
|
|
return result;
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* wgetc */
|
|
|
|
static Key wgetc(void)
|
|
|
|
{
|
2019-09-05 07:24:24 +00:00
|
|
|
int c;
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
doupdate();
|
|
|
|
refresh();
|
|
|
|
switch (c=wgetch(stdscr))
|
|
|
|
{
|
|
|
|
/* LEFT */
|
|
|
|
case KEY_LEFT:
|
|
|
|
case '\02': return K_LEFT;
|
|
|
|
|
|
|
|
/* RIGHT */
|
|
|
|
case KEY_RIGHT:
|
|
|
|
case '\06': return K_RIGHT;
|
|
|
|
|
|
|
|
/* UP */
|
|
|
|
case KEY_UP:
|
|
|
|
case '\020': return K_UP;
|
|
|
|
|
|
|
|
/* DOWN */
|
|
|
|
case KEY_DOWN:
|
|
|
|
case '\016': return K_DOWN;
|
|
|
|
|
|
|
|
/* BACKSPACE */
|
|
|
|
case KEY_BACKSPACE:
|
|
|
|
case '\010': return K_BACKSPACE;
|
|
|
|
|
|
|
|
/* DC */
|
|
|
|
case KEY_DC:
|
|
|
|
case '\04':
|
|
|
|
case '\177': return K_DC;
|
|
|
|
|
|
|
|
/* CANCEL */
|
|
|
|
case '\03':
|
|
|
|
case '\07': return KEY_CANCEL;
|
|
|
|
|
|
|
|
/* ENTER */
|
|
|
|
case KEY_ENTER:
|
|
|
|
case '\r':
|
|
|
|
case '\n': return K_ENTER;
|
|
|
|
|
|
|
|
/* HOME */
|
|
|
|
case KEY_HOME:
|
|
|
|
case '\01': return K_HOME;
|
|
|
|
|
|
|
|
/* END */
|
|
|
|
case KEY_END:
|
|
|
|
case '\05': return K_END;
|
|
|
|
|
|
|
|
/* DL */
|
|
|
|
case '\013': return KEY_DL;
|
|
|
|
|
|
|
|
/* NPAGE */
|
|
|
|
case KEY_NPAGE:
|
|
|
|
case '\026': return K_NPAGE;
|
|
|
|
|
|
|
|
/* PPAGE */
|
|
|
|
case KEY_PPAGE: return K_PPAGE;
|
|
|
|
|
|
|
|
/* Control Y, copy */
|
|
|
|
case '\031': return K_COPY;
|
|
|
|
|
|
|
|
/* Control R, recalculate sheet */
|
|
|
|
case '\022': return K_RECALC;
|
|
|
|
|
2023-04-09 05:35:05 +00:00
|
|
|
/* F8, F9 or Control S, clock sheet */
|
|
|
|
case KEY_F(8):
|
|
|
|
case KEY_F(9):
|
2019-07-22 20:32:33 +00:00
|
|
|
case '\023': return K_CLOCK;
|
|
|
|
|
|
|
|
/* Control X, get one more key */
|
|
|
|
case '\030':
|
|
|
|
{
|
|
|
|
switch (wgetch(stdscr))
|
|
|
|
{
|
|
|
|
/* C-x < -- BPAGE */
|
|
|
|
case KEY_PPAGE:
|
|
|
|
case '<': return K_BPAGE;
|
|
|
|
|
|
|
|
/* C-x > -- FPAGE */
|
|
|
|
case KEY_NPAGE:
|
|
|
|
case '>': return K_FPAGE;
|
|
|
|
|
|
|
|
/* C-x C-c -- QUIT */
|
|
|
|
case '\03': return K_QUIT;
|
|
|
|
|
|
|
|
/* C-x C-s -- SAVE */
|
|
|
|
case '\023': return K_SAVE;
|
|
|
|
|
|
|
|
/* C-x C-r -- LOAD */
|
|
|
|
case '\022': return K_LOAD;
|
|
|
|
|
|
|
|
/* default -- INVALID, general invalid value */
|
|
|
|
default: return K_INVALID;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ESC, get one more key */
|
|
|
|
case '\033':
|
|
|
|
{
|
|
|
|
switch (wgetch(stdscr))
|
|
|
|
{
|
|
|
|
/* M-v -- PPAGE */
|
|
|
|
case 'v': return K_PPAGE;
|
|
|
|
|
|
|
|
/* M-Enter -- MENTER */
|
|
|
|
case KEY_ENTER:
|
|
|
|
case '\r':
|
|
|
|
case '\n': return K_MENTER;
|
|
|
|
|
2019-09-03 08:41:37 +00:00
|
|
|
/* M-s -- edit style expression */
|
|
|
|
case 's': return K_EDIT_STYLE_EXPR;
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* M-z -- SAVEQUIT */
|
|
|
|
case 'z': return K_SAVEQUIT;
|
|
|
|
|
|
|
|
/* default -- INVALID, general invalid value */
|
|
|
|
default: return K_INVALID;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _("Load sheet file format:") */
|
|
|
|
case KEY_F(2): return K_LOADMENU;
|
|
|
|
|
|
|
|
/* _("Save sheet file format:") */
|
|
|
|
case KEY_F(3): return K_SAVEMENU;
|
|
|
|
|
|
|
|
/* default */
|
|
|
|
default: return c;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-09 14:33:41 +00:00
|
|
|
void find_helpfile(char *buf, size_t size, const char *argv0)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
strncpy(buf, HELPFILE, size);
|
|
|
|
buf[size-1] = 0;
|
|
|
|
}
|