2019-07-22 20:32:33 +00:00
|
|
|
/* #includes */ /*{{{C}}}*//*{{{*/
|
|
|
|
#ifndef NO_POSIX_SOURCE
|
|
|
|
#undef _POSIX_SOURCE
|
|
|
|
#define _POSIX_SOURCE 1
|
|
|
|
#undef _POSIX_C_SOURCE
|
|
|
|
#define _POSIX_C_SOURCE 2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DMALLOC
|
|
|
|
#include "dmalloc.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "latex.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "misc.h"
|
|
|
|
/*}}}*/
|
|
|
|
|
|
|
|
/* savelatex -- save as LaTeX table */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
const char *savelatex(Sheet *sheet, const char *name, int body,
|
|
|
|
const Location beg, const Location end,
|
|
|
|
unsigned int *count)
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
/* variables */ /*{{{*/
|
|
|
|
FILE *fp=(FILE*)0; /* cause runtime error */
|
2019-07-27 04:14:26 +00:00
|
|
|
Location w;
|
2019-07-22 20:32:33 +00:00
|
|
|
char buf[1024];
|
|
|
|
char num[20];
|
|
|
|
char fullname[PATH_MAX];
|
2019-07-27 04:14:26 +00:00
|
|
|
Cell *cell;
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
/* asserts */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
assert(sheet != (Sheet*)0);
|
|
|
|
assert(name != (const char*)0);
|
2019-07-22 20:32:33 +00:00
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
*count=0;
|
2019-07-27 04:14:26 +00:00
|
|
|
w[X] = beg[X];
|
|
|
|
for (w[Z]=beg[Z]; w[Z]<=end[Z]; ++(w[Z]))
|
|
|
|
for (w[Y]=beg[Y]; w[Y]<=end[Y]; ++(w[Y]))
|
|
|
|
if (shadowed(CELL_AT(sheet,w))) return _("Shadowed cells in first column");
|
2019-07-22 20:32:33 +00:00
|
|
|
if (!body && (fp=fopen(name,"w"))==(FILE*)0) return strerror(errno);
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[Z]=beg[Z]; w[Z]<=end[Z]; ++(w[Z]))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
if (body)
|
|
|
|
/* open new file */ /*{{{*/
|
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
sprintf(num, ".%d", w[Z]);
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
fullname[sizeof(fullname)-strlen(num)-1]='\0';
|
|
|
|
(void)strncpy(fullname,name,sizeof(fullname)-strlen(num)-1);
|
|
|
|
fullname[sizeof(fullname)-1]='\0';
|
|
|
|
(void)strncat(fullname,num,sizeof(fullname)-strlen(num)-1);
|
|
|
|
fullname[sizeof(fullname)-1]='\0';
|
|
|
|
if ((fp=fopen(fullname,"w"))==(FILE*)0) return strerror(errno);
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
else
|
|
|
|
/* print header */ /*{{{*/
|
2019-07-27 04:14:26 +00:00
|
|
|
if (w[Z] == beg[Z])
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
if (fputs_close("\\documentclass{article}\n\\usepackage{longtable}\n\\begin{document}\n\\setlongtables\n\\vfill\n",fp)==EOF) return strerror(errno);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fputs_close("\\clearpage\n\\vfill\n",fp)==EOF) return strerror(errno);
|
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
|
|
|
|
/* print bogus format */ /*{{{*/
|
|
|
|
fprintf(fp,"\\begin{longtable}{");
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[X]=beg[X]; w[X]<=end[X]; ++(w[X])) if (fputc_close('l',fp)==EOF) return strerror(errno);
|
2019-07-22 20:32:33 +00:00
|
|
|
fprintf(fp,"}\n");
|
|
|
|
/*}}}*/
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[Y]=beg[Y]; w[Y]<=end[Y]; ++(w[Y]))
|
2019-07-22 20:32:33 +00:00
|
|
|
/* print contents */ /*{{{*/
|
|
|
|
{
|
2019-07-27 04:14:26 +00:00
|
|
|
for (w[X]=beg[X]; w[X]<=end[X]; )
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
int multicols;
|
|
|
|
char *bufp;
|
|
|
|
|
2019-07-27 04:14:26 +00:00
|
|
|
if (w[X]>beg[X] && fputc_close('&',fp)==EOF) return strerror(errno);
|
|
|
|
for (multicols = w[X]+1; multicols<sheet->dimx && SHADOWEDC(sheet,multicols,w[Y],w[Z]); ++multicols);
|
|
|
|
multicols = multicols - w[X];
|
2019-07-22 20:32:33 +00:00
|
|
|
fprintf(fp,"\\multicolumn{%d}{",multicols);
|
2019-07-27 04:14:26 +00:00
|
|
|
cell = CELL_AT(sheet, w);
|
|
|
|
switch (getadjust(cell))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
case LEFT: if (fputc_close('l',fp)==EOF) return strerror(errno); break;
|
|
|
|
case RIGHT: if (fputc_close('r',fp)==EOF) return strerror(errno); break;
|
|
|
|
case CENTER: if (fputc_close('c',fp)==EOF) return strerror(errno); break;
|
|
|
|
default: assert(0);
|
|
|
|
}
|
Make tpa the default file format for Teapot
There turned out to be one blocking technical issue for full adpotion of
tpa format, and that was the fact that the printed representation of
floating values inside the tpa file might not reproduce the same double
when read. This change therefore introduces the "hexact" floating point
format, based on the the %La format string, which produces a hex
representation with exact round trips. While working on this, it was
convenient to add a new representation "compact" which is basically the
shorter of decimal and scientific representations, without trailing zeros.
This is now the default float format, but of course one can select decimal
or scientific formats to restore prior appearance. However, full-precision
compact format is now the (only) format for editing cell contents, as it
is accurate and efficient. Of course you can enter floating point values
in any format you like when typing in a formula.
The addition of several new floating point options overloaded the menus
in terminal teapot, so this change also revamps those menus slightly,
including eliminating the unused MenuChoice struct, and just specifying menus
with an array of strings.
Closes #63.
2019-08-24 16:58:46 +00:00
|
|
|
printvalue(buf, sizeof(buf), 0, DIRECT_STRING, getfltformat(cell),
|
2019-07-27 04:14:26 +00:00
|
|
|
getprecision(cell), sheet, w);
|
2019-07-22 20:32:33 +00:00
|
|
|
if (fputs_close("}{",fp)==EOF) return strerror(errno);
|
2019-07-27 04:14:26 +00:00
|
|
|
if (transparent(cell))
|
2019-07-22 20:32:33 +00:00
|
|
|
{
|
|
|
|
if (fputs_close(buf,fp)==EOF) return strerror(errno);
|
|
|
|
}
|
|
|
|
else for (bufp=buf; *bufp; ++bufp) switch (*bufp)
|
|
|
|
{
|
|
|
|
case '%':
|
|
|
|
case '$':
|
|
|
|
case '&':
|
|
|
|
case '#':
|
|
|
|
case '_':
|
|
|
|
case '{':
|
|
|
|
case '}':
|
|
|
|
case '~':
|
|
|
|
case '^': if (fputc_close('\\',fp)==EOF || fputc_close(*bufp,fp)==EOF) return strerror(errno); break;
|
|
|
|
case '\\': if (fputs_close("\\backslash ",fp)==EOF) return strerror(errno); break;
|
|
|
|
default: if (fputc_close(*bufp,fp)==EOF) return strerror(errno);
|
|
|
|
}
|
|
|
|
if (fputc_close('}',fp)==EOF) return strerror(errno);
|
2019-07-27 04:14:26 +00:00
|
|
|
w[X] += multicols;
|
2019-07-22 20:32:33 +00:00
|
|
|
++*count;
|
|
|
|
}
|
2019-07-27 04:14:26 +00:00
|
|
|
if (fputs_close(w[Y]<end[Y] ? "\\\\\n" : "\n\\end{longtable}\n",fp)==EOF) return strerror(errno);
|
2019-07-22 20:32:33 +00:00
|
|
|
}
|
|
|
|
/*}}}*/
|
|
|
|
if (body)
|
|
|
|
{
|
|
|
|
if (fclose(fp)==EOF) return strerror(errno);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fputs_close("\\vfill\n",fp)==EOF) return strerror(errno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!body)
|
|
|
|
{
|
|
|
|
if (fputs_close("\\end{document}\n",fp)==EOF) return strerror(errno);
|
|
|
|
if (fclose(fp)==EOF) return strerror(errno);
|
|
|
|
}
|
|
|
|
return (const char*)0;
|
|
|
|
}
|
|
|
|
/*}}}*/
|