Made major progress in modularizing code.
This commit is contained in:
parent
1411d6a7e0
commit
10e32cf3e9
@ -9,10 +9,10 @@ man_MANS = xlhtml.1
|
|||||||
bin_SCRIPTS = nsopen nsxlview
|
bin_SCRIPTS = nsopen nsxlview
|
||||||
bin_PROGRAMS = xlhtml
|
bin_PROGRAMS = xlhtml
|
||||||
LDADD = ../cole/libcole.a
|
LDADD = ../cole/libcole.a
|
||||||
xlhtml_SOURCES = support.c xlhtml.c
|
xlhtml_SOURCES = support.c xlhtml.c html.c ascii.c xml.c
|
||||||
xldump_SOURCES = xldump.c
|
xldump_SOURCES = xldump.c
|
||||||
xlcdump_SOURCES = xlcdump.c
|
xlcdump_SOURCES = xlcdump.c
|
||||||
AM_CFLAGS = -Wall -Wshadow -Wcast-align -Wpointer-arith
|
AM_CFLAGS = -Wshadow -Wcast-align -Wpointer-arith
|
||||||
|
|
||||||
doc:
|
doc:
|
||||||
@echo Generating documentation...
|
@echo Generating documentation...
|
||||||
|
@ -83,10 +83,10 @@ man_MANS = xlhtml.1
|
|||||||
bin_SCRIPTS = nsopen nsxlview
|
bin_SCRIPTS = nsopen nsxlview
|
||||||
bin_PROGRAMS = xlhtml
|
bin_PROGRAMS = xlhtml
|
||||||
LDADD = ../cole/libcole.a
|
LDADD = ../cole/libcole.a
|
||||||
xlhtml_SOURCES = support.c xlhtml.c
|
xlhtml_SOURCES = support.c xlhtml.c html.c ascii.c xml.c
|
||||||
xldump_SOURCES = xldump.c
|
xldump_SOURCES = xldump.c
|
||||||
xlcdump_SOURCES = xlcdump.c
|
xlcdump_SOURCES = xlcdump.c
|
||||||
AM_CFLAGS = -Wall -Wshadow -Wcast-align -Wpointer-arith
|
AM_CFLAGS = -Wshadow -Wcast-align -Wpointer-arith
|
||||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||||
CONFIG_HEADER = ../config.h
|
CONFIG_HEADER = ../config.h
|
||||||
CONFIG_CLEAN_FILES =
|
CONFIG_CLEAN_FILES =
|
||||||
@ -97,7 +97,7 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I..
|
|||||||
CPPFLAGS = @CPPFLAGS@
|
CPPFLAGS = @CPPFLAGS@
|
||||||
LDFLAGS = @LDFLAGS@
|
LDFLAGS = @LDFLAGS@
|
||||||
LIBS = @LIBS@
|
LIBS = @LIBS@
|
||||||
xlhtml_OBJECTS = support.o xlhtml.o
|
xlhtml_OBJECTS = support.o xlhtml.o html.o ascii.o xml.o
|
||||||
xlhtml_LDADD = $(LDADD)
|
xlhtml_LDADD = $(LDADD)
|
||||||
xlhtml_DEPENDENCIES = ../cole/libcole.a
|
xlhtml_DEPENDENCIES = ../cole/libcole.a
|
||||||
xlhtml_LDFLAGS =
|
xlhtml_LDFLAGS =
|
||||||
|
129
xlhtml/ascii.c
Normal file
129
xlhtml/ascii.c
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
|
||||||
|
#include "xlhtml.h"
|
||||||
|
|
||||||
|
extern void SetupExtraction(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern void do_cr(void);
|
||||||
|
extern int center_tables;
|
||||||
|
extern int ws_array;
|
||||||
|
extern int first_sheet;
|
||||||
|
extern int last_sheet;
|
||||||
|
extern uni_string default_font;
|
||||||
|
extern void trim_sheet_edges(unsigned int);
|
||||||
|
extern int next_ws_title;
|
||||||
|
extern void update_default_font(unsigned int);
|
||||||
|
extern void OutputString(uni_string * );
|
||||||
|
extern int default_fontsize;
|
||||||
|
extern char *default_alignment;
|
||||||
|
extern int aggressive;
|
||||||
|
extern char *lastUpdated;
|
||||||
|
extern int file_version;
|
||||||
|
extern int NoFormat;
|
||||||
|
extern int notAccurate;
|
||||||
|
extern int formula_warnings;
|
||||||
|
extern int NoHeaders;
|
||||||
|
extern int NotImplemented;
|
||||||
|
extern int Unsupported;
|
||||||
|
extern int MaxWorksheetsExceeded;
|
||||||
|
extern int MaxRowExceeded;
|
||||||
|
extern int MaxColExceeded;
|
||||||
|
extern int MaxStringsExceeded;
|
||||||
|
extern int MaxFontsExceeded;
|
||||||
|
extern int MaxPalExceeded;
|
||||||
|
extern int MaxXFExceeded;
|
||||||
|
extern int MaxFormatsExceeded;
|
||||||
|
extern char colorTab[MAX_COLORS];
|
||||||
|
extern char *default_text_color;
|
||||||
|
extern char *default_background_color;
|
||||||
|
extern char *default_image;
|
||||||
|
extern char filename[256];
|
||||||
|
extern int UnicodeStrings;
|
||||||
|
extern int CodePage;
|
||||||
|
extern char *title;
|
||||||
|
extern void update_default_alignment(unsigned int, int);
|
||||||
|
extern void output_cell( cell *, int);
|
||||||
|
extern uni_string author;
|
||||||
|
extern int null_string(U8 *);
|
||||||
|
extern int Csv;
|
||||||
|
extern int xf_array;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void OutputPartialTableAscii(void)
|
||||||
|
{
|
||||||
|
int i, j, k;
|
||||||
|
|
||||||
|
SetupExtraction();
|
||||||
|
|
||||||
|
/* Here's where we dump the Html Page out */
|
||||||
|
for (i=first_sheet; i<=last_sheet; i++) /* For each worksheet */
|
||||||
|
{
|
||||||
|
if (ws_array[i] == 0)
|
||||||
|
continue;
|
||||||
|
if ((ws_array[i]->biggest_row == -1)||(ws_array[i]->biggest_col == -1))
|
||||||
|
continue;
|
||||||
|
if (ws_array[i]->c_array == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Now dump the table */
|
||||||
|
for (j=ws_array[i]->first_row; j<=ws_array[i]->biggest_row; j++)
|
||||||
|
{
|
||||||
|
for (k=ws_array[i]->first_col; k<=ws_array[i]->biggest_col; k++)
|
||||||
|
{
|
||||||
|
int safe, numeric=0;
|
||||||
|
cell *c = ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k]; /* This stuff happens for each cell... */
|
||||||
|
|
||||||
|
if (c)
|
||||||
|
{
|
||||||
|
numeric = IsCellNumeric(c);
|
||||||
|
if (!numeric && Csv)
|
||||||
|
printf("\"");
|
||||||
|
safe = IsCellSafe(c);
|
||||||
|
|
||||||
|
if (c->ustr.str)
|
||||||
|
{
|
||||||
|
if (safe)
|
||||||
|
output_formatted_data(&(c->ustr), xf_array[c->xfmt]->fmt_idx, numeric, IsCellFormula(c));
|
||||||
|
else
|
||||||
|
OutputString(&(c->ustr));
|
||||||
|
}
|
||||||
|
else if (!Csv)
|
||||||
|
printf(" "); /* Empty cell... */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ /* Empty cell... */
|
||||||
|
if (!Csv)
|
||||||
|
printf(" ");
|
||||||
|
else
|
||||||
|
printf("\"");
|
||||||
|
}
|
||||||
|
if (ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k]) /* Honor Column spanning ? */
|
||||||
|
{
|
||||||
|
if (ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k]->colspan != 0)
|
||||||
|
k += ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k]->colspan-1;
|
||||||
|
}
|
||||||
|
if (!numeric && Csv)
|
||||||
|
printf("\"");
|
||||||
|
|
||||||
|
if (Csv && (k < ws_array[i]->biggest_col))
|
||||||
|
{ /* big cheat here: quoting everything! */
|
||||||
|
putchar(','); /* Csv Cell Separator */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (( !Csv )&&( k != ws_array[i]->biggest_col ))
|
||||||
|
putchar('\t'); /* Ascii Cell Separator */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Csv)
|
||||||
|
printf("\r\n");
|
||||||
|
else
|
||||||
|
putchar(0x0A); /* Row Separator */
|
||||||
|
}
|
||||||
|
if (!Csv)
|
||||||
|
printf("\n\n"); /* End of Table 2 LF-CR */
|
||||||
|
}
|
||||||
|
}
|
389
xlhtml/html.c
Normal file
389
xlhtml/html.c
Normal file
@ -0,0 +1,389 @@
|
|||||||
|
|
||||||
|
#include "xlhtml.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern void do_cr(void);
|
||||||
|
extern int center_tables;
|
||||||
|
extern int first_sheet;
|
||||||
|
extern int last_sheet;
|
||||||
|
extern uni_string default_font;
|
||||||
|
extern void trim_sheet_edges(unsigned int);
|
||||||
|
extern int next_ws_title;
|
||||||
|
extern void SetupExtraction(void);
|
||||||
|
extern void update_default_font(unsigned int);
|
||||||
|
extern void OutputString(uni_string * );
|
||||||
|
extern int default_fontsize;
|
||||||
|
extern char *default_alignment;
|
||||||
|
extern int aggressive;
|
||||||
|
extern char *lastUpdated;
|
||||||
|
extern int file_version;
|
||||||
|
extern int NoFormat;
|
||||||
|
extern int notAccurate;
|
||||||
|
extern int formula_warnings;
|
||||||
|
extern int NoHeaders;
|
||||||
|
extern int NotImplemented;
|
||||||
|
extern int Unsupported;
|
||||||
|
extern int MaxWorksheetsExceeded;
|
||||||
|
extern int MaxRowExceeded;
|
||||||
|
extern int MaxColExceeded;
|
||||||
|
extern int MaxStringsExceeded;
|
||||||
|
extern int MaxFontsExceeded;
|
||||||
|
extern int MaxPalExceeded;
|
||||||
|
extern int MaxXFExceeded;
|
||||||
|
extern int MaxFormatsExceeded;
|
||||||
|
extern char colorTab[MAX_COLORS];
|
||||||
|
extern char *default_text_color;
|
||||||
|
extern char *default_background_color;
|
||||||
|
extern char *default_image;
|
||||||
|
extern char filename[256];
|
||||||
|
extern int UnicodeStrings;
|
||||||
|
extern int CodePage;
|
||||||
|
extern char *title;
|
||||||
|
extern void update_default_alignment(unsigned int, int);
|
||||||
|
extern void output_cell( cell *, int);
|
||||||
|
extern uni_string author;
|
||||||
|
extern int null_string(U8 *);
|
||||||
|
extern unsigned int next_font;
|
||||||
|
|
||||||
|
void output_header(void);
|
||||||
|
void output_footer(void);
|
||||||
|
|
||||||
|
void OutputTableHTML(void)
|
||||||
|
{
|
||||||
|
int i, j, k;
|
||||||
|
|
||||||
|
void output_header();
|
||||||
|
if (center_tables)
|
||||||
|
{
|
||||||
|
printf("<CENTER>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
|
||||||
|
SetupExtraction();
|
||||||
|
|
||||||
|
/* Here's where we dump the Html Page out */
|
||||||
|
for (i=first_sheet; i<=last_sheet; i++) /* For each worksheet */
|
||||||
|
{
|
||||||
|
update_default_font(i);
|
||||||
|
if (ws_array[i] == 0)
|
||||||
|
continue;
|
||||||
|
if ((ws_array[i]->biggest_row == -1)||(ws_array[i]->biggest_col == -1))
|
||||||
|
continue;
|
||||||
|
if (ws_array[i]->c_array == 0)
|
||||||
|
continue;
|
||||||
|
trim_sheet_edges(i);
|
||||||
|
|
||||||
|
/* Print its name */
|
||||||
|
if (next_ws_title > 0)
|
||||||
|
{
|
||||||
|
if (ws_array[i]->ws_title.str)
|
||||||
|
{
|
||||||
|
printf("<H1><CENTER>");
|
||||||
|
OutputString(&ws_array[i]->ws_title);
|
||||||
|
printf("</CENTER></H1><br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("<H1><CENTER>(Unknown Page)</CENTER></H1><br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now dump the table */
|
||||||
|
printf("<FONT FACE=\"");
|
||||||
|
OutputString(&default_font);
|
||||||
|
if (default_fontsize != 3)
|
||||||
|
printf("\" SIZE=\"%d", default_fontsize);
|
||||||
|
printf("\">");
|
||||||
|
do_cr();
|
||||||
|
printf("<TABLE BORDER=\"1\" CELLSPACING=\"2\">");
|
||||||
|
do_cr();
|
||||||
|
for (j=ws_array[i]->first_row; j<=ws_array[i]->biggest_row; j++)
|
||||||
|
{
|
||||||
|
update_default_alignment(i, j);
|
||||||
|
printf("<TR");
|
||||||
|
if (null_string((U8 *)default_alignment))
|
||||||
|
printf(">");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (strcmp(default_alignment, "left") != 0)
|
||||||
|
printf(" ALIGN=\"%s\"", default_alignment);
|
||||||
|
if (!aggressive)
|
||||||
|
printf(" VALIGN=\"bottom\">\n");
|
||||||
|
else
|
||||||
|
printf(">");
|
||||||
|
}
|
||||||
|
for (k=ws_array[i]->first_col; k<=ws_array[i]->biggest_col; k++)
|
||||||
|
{
|
||||||
|
output_cell(ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k],0); /* This stuff happens for each cell... */
|
||||||
|
if (ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k])
|
||||||
|
{
|
||||||
|
if (ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k]->colspan != 0)
|
||||||
|
k += ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k]->colspan-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!aggressive)
|
||||||
|
printf("</TR>\n");
|
||||||
|
}
|
||||||
|
printf("</table></FONT><HR>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (center_tables)
|
||||||
|
{
|
||||||
|
printf("</CENTER>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print the author's name in itallics... */
|
||||||
|
if (author.str)
|
||||||
|
{
|
||||||
|
printf("<FONT SIZE=-1><I>Spreadsheet's Author: ");
|
||||||
|
OutputString(&author);
|
||||||
|
printf("</I></FONT><br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print when & how the file was last updated. */
|
||||||
|
printf("<FONT SIZE=-1><I>Last Updated ");
|
||||||
|
if (lastUpdated)
|
||||||
|
printf("%s ", lastUpdated);
|
||||||
|
switch (file_version)
|
||||||
|
{
|
||||||
|
case EXCEL95:
|
||||||
|
printf("with Excel 5.0 or 95");
|
||||||
|
break;
|
||||||
|
case EXCEL97:
|
||||||
|
printf("with Excel 97");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("with Excel ????");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf("</I></FONT><br>");
|
||||||
|
do_cr();
|
||||||
|
|
||||||
|
/* Next print Disclaimers... */
|
||||||
|
if (NoFormat)
|
||||||
|
{
|
||||||
|
printf("<br>* This cell's format is not supported.<br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
if ((notAccurate)&&(formula_warnings))
|
||||||
|
{
|
||||||
|
printf("<br>** This cell's data may not be accurate.<br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
if (NotImplemented)
|
||||||
|
{
|
||||||
|
printf("<br>*** This cell's data type will be supported in the future.<br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
if (Unsupported)
|
||||||
|
{
|
||||||
|
printf("<br>**** This cell's type is unsupported.<br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now out exceeded capacity warnings... */
|
||||||
|
if (MaxWorksheetsExceeded || MaxRowExceeded || MaxColExceeded || MaxStringsExceeded ||
|
||||||
|
MaxFontsExceeded || MaxPalExceeded || MaxXFExceeded || MaxFormatsExceeded )
|
||||||
|
printf("<FONT COLOR=\"%s\">", colorTab[0x0A]);
|
||||||
|
if (MaxWorksheetsExceeded)
|
||||||
|
{
|
||||||
|
printf("The Maximum Number of Worksheets was exceeded, you might want to increase it.<br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
if (MaxRowExceeded)
|
||||||
|
{
|
||||||
|
printf("The Maximum Number of Rows was exceeded, you might want to increase it.<br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
if (MaxColExceeded)
|
||||||
|
{
|
||||||
|
printf("The Maximum Number of Columns was exceeded, you might want to increase it.<br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
if (MaxStringsExceeded)
|
||||||
|
{
|
||||||
|
printf("The Maximum Number of Strings was exceeded, you might want to increase it.<br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
if (MaxFontsExceeded)
|
||||||
|
{
|
||||||
|
printf("The Maximum Number of Fonts was exceeded, you might want to increase it.<br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
if (MaxPalExceeded)
|
||||||
|
{
|
||||||
|
printf("The Maximum Number of Color Palettes was exceeded, you might want to increase it.<br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
if (MaxXFExceeded)
|
||||||
|
{
|
||||||
|
printf("The Maximum Number of Extended Formats was exceeded, you might want to increase it.<br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
if (MaxFormatsExceeded)
|
||||||
|
{
|
||||||
|
printf("The Maximum Number of Formats was exceeded, you might want to increase it.<br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
if (MaxWorksheetsExceeded || MaxRowExceeded || MaxColExceeded || MaxStringsExceeded ||
|
||||||
|
MaxFontsExceeded || MaxPalExceeded || MaxXFExceeded || MaxFormatsExceeded )
|
||||||
|
printf("</FONT>");
|
||||||
|
|
||||||
|
printf(" <br>");
|
||||||
|
do_cr();
|
||||||
|
|
||||||
|
/* Output Credit */
|
||||||
|
printf("<hr><FONT SIZE=-1>Created with <a href=\"http://chicago.sf.net/xlhtml\">xlhtml %s</a></FONT><br>", VERSION);
|
||||||
|
do_cr();
|
||||||
|
|
||||||
|
/* Output Tail */
|
||||||
|
output_footer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void output_header(void)
|
||||||
|
{ /* Ouput Header */
|
||||||
|
if (NoHeaders)
|
||||||
|
return;
|
||||||
|
if (!aggressive)
|
||||||
|
{
|
||||||
|
printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML Transitional//EN\"");
|
||||||
|
do_cr();
|
||||||
|
printf("\"http://www.w3.org/TR/REC-html40/loose.dtd\">");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
printf("<HTML><HEAD>");
|
||||||
|
do_cr();
|
||||||
|
printf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=");
|
||||||
|
if ((UnicodeStrings <= 1)&&CodePage&&(CodePage != 1252))
|
||||||
|
printf("windows-%d\">", CodePage);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (UnicodeStrings)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
printf("iso-8859-1\">"); /* Latin-1 */
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
printf("windows-1252\">"); /* Microsoft */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("utf-8\">"); /* Unicode */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
do_cr();
|
||||||
|
|
||||||
|
if (!aggressive)
|
||||||
|
{
|
||||||
|
printf("<meta name=\"GENERATOR\" content=\"xlhtml\">");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
printf("<TITLE>");
|
||||||
|
if (title)
|
||||||
|
printf("%s", title);
|
||||||
|
else
|
||||||
|
printf("%s", filename);
|
||||||
|
printf("</TITLE>");
|
||||||
|
do_cr();
|
||||||
|
printf("</HEAD>");
|
||||||
|
do_cr();
|
||||||
|
do_cr();
|
||||||
|
printf("<BODY TEXT=\"#%s\" BGCOLOR=\"#%s\"",
|
||||||
|
default_text_color, default_background_color);
|
||||||
|
if (default_image)
|
||||||
|
printf("BACKGROUND=\"%s\"", default_image);
|
||||||
|
printf("><br>");
|
||||||
|
do_cr();
|
||||||
|
}
|
||||||
|
|
||||||
|
void output_footer(void)
|
||||||
|
{
|
||||||
|
if (NoHeaders)
|
||||||
|
return;
|
||||||
|
printf("</BODY></HTML>");
|
||||||
|
do_cr();
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void output_start_html_attr(html_attr *h, unsigned int fnt_idx, int do_underlines)
|
||||||
|
{
|
||||||
|
if (fnt_idx < next_font)
|
||||||
|
{
|
||||||
|
if (((font_array[fnt_idx]->underline&0x0023) > 0)&&(do_underlines))
|
||||||
|
{
|
||||||
|
printf("<U>");
|
||||||
|
h->uflag = 1;
|
||||||
|
}
|
||||||
|
if (font_array[fnt_idx]->bold >= 0x02BC)
|
||||||
|
{
|
||||||
|
h->bflag = 1;
|
||||||
|
printf("<B>");
|
||||||
|
}
|
||||||
|
if (font_array[fnt_idx]->attr & 0x0002)
|
||||||
|
{
|
||||||
|
h->iflag = 1;
|
||||||
|
printf("<I>");
|
||||||
|
}
|
||||||
|
if (font_array[fnt_idx]->attr & 0x0008)
|
||||||
|
{
|
||||||
|
h->sflag = 1;
|
||||||
|
printf("<S>");
|
||||||
|
}
|
||||||
|
if ((font_array[fnt_idx]->super & 0x0003) == 0x0001)
|
||||||
|
{
|
||||||
|
h->spflag = 1;
|
||||||
|
printf("<SUP>");
|
||||||
|
}
|
||||||
|
else if ((font_array[fnt_idx]->super & 0x0003) == 0x0002)
|
||||||
|
{
|
||||||
|
h->sbflag = 1;
|
||||||
|
printf("<SUB>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void output_end_html_attr(html_attr *h)
|
||||||
|
{
|
||||||
|
if (h->sbflag)
|
||||||
|
{
|
||||||
|
printf("</SUB>");
|
||||||
|
h->sbflag = 0;
|
||||||
|
}
|
||||||
|
else if (h->spflag)
|
||||||
|
{
|
||||||
|
printf("</SUP>");
|
||||||
|
h->spflag = 0;
|
||||||
|
}
|
||||||
|
if (h->sflag)
|
||||||
|
{
|
||||||
|
printf("</S>");
|
||||||
|
h->sflag = 0;
|
||||||
|
}
|
||||||
|
if (h->iflag)
|
||||||
|
{
|
||||||
|
printf("</I>");
|
||||||
|
h->iflag = 0;
|
||||||
|
}
|
||||||
|
if (h->bflag)
|
||||||
|
{
|
||||||
|
printf("</B>");
|
||||||
|
h->bflag = 0;
|
||||||
|
}
|
||||||
|
if (h->uflag)
|
||||||
|
{
|
||||||
|
if (h->uflag == 1)
|
||||||
|
printf("</U>");
|
||||||
|
else
|
||||||
|
printf("</A>");
|
||||||
|
h->uflag = 0;
|
||||||
|
}
|
||||||
|
}
|
147
xlhtml/support.c
147
xlhtml/support.c
@ -2,9 +2,10 @@
|
|||||||
/* Various support functions for xlhtml. */
|
/* Various support functions for xlhtml. */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "support.h"
|
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
#include <time.h>
|
||||||
|
#include "../cole/cole.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
void print_version(void)
|
void print_version(void)
|
||||||
{
|
{
|
||||||
@ -63,3 +64,145 @@ S32 getLong(U8 *ptr)
|
|||||||
|
|
||||||
return (S32)(*(ptr+3)<<24)+(*(ptr+2)<<16)+(*(ptr+1)<<8)+*ptr;
|
return (S32)(*(ptr+3)<<24)+(*(ptr+2)<<16)+(*(ptr+1)<<8)+*ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef WORDS_BIGENDIAN /* Defined in <config.h> */
|
||||||
|
/*! Little Endian - 0x86 family */
|
||||||
|
void getDouble(U8 *ptr, F64 *d)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
F64 dd;
|
||||||
|
U8 *t = (U8 *)ⅆ
|
||||||
|
|
||||||
|
for (i=0; i<sizeof(F64); i++)
|
||||||
|
*(t+i) = *(ptr+i);
|
||||||
|
|
||||||
|
*d = (F64)dd;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/*! Big Endian version - UltraSparc's, etc. */
|
||||||
|
void getDouble (U8 *ptr, F64 *d)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
F64 dd;
|
||||||
|
U8 *t = (U8 *)ⅆ
|
||||||
|
|
||||||
|
for (i=0; i<sizeof(F64); i++)
|
||||||
|
*(t+i) = *(ptr+sizeof(F64) - 1 - i);
|
||||||
|
|
||||||
|
*d = (F64)dd;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int null_string(U8 *str)
|
||||||
|
{ /* FIXME: This function may not be unicode safe */
|
||||||
|
U8 *ptr;
|
||||||
|
if ((str == NULL)||(*str == 0))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
ptr = str;
|
||||||
|
while (*ptr != 0)
|
||||||
|
{
|
||||||
|
if (*ptr++ != ' ')
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FracToTime(U8 *cnum, int *hr, int *minut, int *sec, int *msec)
|
||||||
|
{
|
||||||
|
int Hr, Min, Sec, Msec;
|
||||||
|
F64 fnum, tHr, tMin, tSec, tMsec;
|
||||||
|
|
||||||
|
if (msec)
|
||||||
|
fnum = atof((char *)&cnum[0])+(0.05 / 86400.0); /* Round off to 1/10th seconds */
|
||||||
|
else if (sec)
|
||||||
|
fnum = atof((char *)&cnum[0])+(0.5 / 86400.0); /* Round off to seconds */
|
||||||
|
else
|
||||||
|
fnum = atof((char *)&cnum[0])+(30 / 86400.0); /* Round off to minutes */
|
||||||
|
tHr = 24.0 * fnum;
|
||||||
|
Hr = (int)tHr;
|
||||||
|
tMin = (tHr - (F64)Hr) * 60.0;
|
||||||
|
Min = (int)tMin;
|
||||||
|
tSec = (tMin - (F64)Min) * 60.0;
|
||||||
|
Sec = (int)tSec;
|
||||||
|
tMsec = (tSec - (F64)Sec) * 10.0;
|
||||||
|
Msec = (int)tMsec;
|
||||||
|
|
||||||
|
Hr = Hr%24; /* Fix roll-overs */
|
||||||
|
if (hr)
|
||||||
|
*hr = Hr;
|
||||||
|
if (minut)
|
||||||
|
*minut = Min;
|
||||||
|
if (sec)
|
||||||
|
*sec = Sec;
|
||||||
|
if (msec)
|
||||||
|
*msec = Msec;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void NumToDate(long num, int *year, int *month, int *day)
|
||||||
|
{
|
||||||
|
const int ldays[]={31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
|
const int ndays[]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
|
|
||||||
|
extern int DatesR1904;
|
||||||
|
|
||||||
|
int t, i, y = 0;
|
||||||
|
|
||||||
|
num = num%36525L; /* Trim century */
|
||||||
|
while (num > (((y%4) == 0) ? 366 : 365))
|
||||||
|
num -= ((y++%4) == 0) ? 366 : 365;
|
||||||
|
|
||||||
|
*year = y;
|
||||||
|
t = num;
|
||||||
|
if (DatesR1904)
|
||||||
|
*year += 4; /* Adjust for McIntosh... */
|
||||||
|
if ((*year%4) == 0)
|
||||||
|
{ /* Leap Year */
|
||||||
|
for (i=0; i<12; i++)
|
||||||
|
{
|
||||||
|
if (t <= ldays[i])
|
||||||
|
break;
|
||||||
|
t -= ldays[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i=0; i<12; i++)
|
||||||
|
{
|
||||||
|
if (t <= ndays[i])
|
||||||
|
break;
|
||||||
|
t -= ndays[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Some fixups... */
|
||||||
|
*month = 1+i;
|
||||||
|
if (t == 0)
|
||||||
|
t = 1;
|
||||||
|
*day = t;
|
||||||
|
*year = *year % 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* noaliasdub macro avoids trouble from gcc -O2 type-based alias analysis */
|
||||||
|
typedef S32 swords[2];
|
||||||
|
#define noaliasdub(type,ptr) \
|
||||||
|
(((union{swords sw; F64 dub;} *)(ptr))->sw)
|
||||||
|
|
||||||
|
#ifndef WORDS_BIGENDIAN /*! Defined in <config.h> */
|
||||||
|
/*! Little Endian - 0x86 family */
|
||||||
|
void RKtoDouble(S32 n, F64 *d)
|
||||||
|
{
|
||||||
|
noaliasdub(swords,d)[0] = 0;
|
||||||
|
noaliasdub(swords,d)[1] = n << 2;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/*! Big Endian version - UltraSparc's, etc. */
|
||||||
|
void RKtoDouble(S32 n, F64 *d)
|
||||||
|
{
|
||||||
|
U8 *ptr = (U8 *)&n;
|
||||||
|
|
||||||
|
noaliasdub(swords,d)[1] = 0;
|
||||||
|
noaliasdub(swords,d)[0] =
|
||||||
|
((*(ptr+0)<<24)+(*(ptr+1)<<16)+(*(ptr+2)<<8)+(*(ptr+3))) << 2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
1012
xlhtml/xlhtml.c
1012
xlhtml/xlhtml.c
File diff suppressed because it is too large
Load Diff
@ -22,7 +22,7 @@
|
|||||||
/* Used by packed string array Opcode: 0xFC */
|
/* Used by packed string array Opcode: 0xFC */
|
||||||
#define HARD_MAX_ROWS_97 0x7FFE /*!< Used in add_wb_array to prevent OOM */
|
#define HARD_MAX_ROWS_97 0x7FFE /*!< Used in add_wb_array to prevent OOM */
|
||||||
#define HARD_MAX_ROWS_95 0x3FFF /*!< Used in add_wb_array to prevent OOM */
|
#define HARD_MAX_ROWS_95 0x3FFF /*!< Used in add_wb_array to prevent OOM */
|
||||||
#define HARD_MAX_COLS 256 /*!< Used in add_wb_array to prevent OOM */
|
#define HARD_MAX_COLS 256 /*!< Used in add_wb_array to prevent OOM */
|
||||||
|
|
||||||
U16 HARD_MAX_ROWS = HARD_MAX_ROWS_97;
|
U16 HARD_MAX_ROWS = HARD_MAX_ROWS_97;
|
||||||
/**********************************
|
/**********************************
|
||||||
@ -73,6 +73,7 @@ typedef struct /*!< This encapsulates some information about each worksheet */
|
|||||||
uni_string ws_title;
|
uni_string ws_title;
|
||||||
cell **c_array;
|
cell **c_array;
|
||||||
U16 spanned;
|
U16 spanned;
|
||||||
|
int ws_array;
|
||||||
}work_sheet;
|
}work_sheet;
|
||||||
|
|
||||||
typedef struct /*!< This is everything we need to know about fonts */
|
typedef struct /*!< This is everything we need to know about fonts */
|
||||||
@ -116,9 +117,4 @@ typedef struct /*!< HTML Attribute */
|
|||||||
int spflag; /*!< Superscript */
|
int spflag; /*!< Superscript */
|
||||||
}html_attr;
|
}html_attr;
|
||||||
|
|
||||||
static char SectionName[2][12] = /* The section of the Excel Stream where the workbooks are kept */
|
|
||||||
{
|
|
||||||
"/Workbook", /*!< Excel 97 & 2000 */
|
|
||||||
"/Book" /*!< Everything else ? */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
187
xlhtml/xml.c
Normal file
187
xlhtml/xml.c
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
|
||||||
|
#include "xlhtml.h"
|
||||||
|
|
||||||
|
extern void do_cr(void);
|
||||||
|
extern int center_tables;
|
||||||
|
extern int ws_array;
|
||||||
|
extern int first_sheet;
|
||||||
|
extern int last_sheet;
|
||||||
|
extern uni_string default_font;
|
||||||
|
extern void trim_sheet_edges(unsigned int);
|
||||||
|
extern int next_ws_title;
|
||||||
|
extern void SetupExtraction(void);
|
||||||
|
extern void update_default_font(unsigned int);
|
||||||
|
extern void OutputString(uni_string * );
|
||||||
|
extern int default_fontsize;
|
||||||
|
extern char *default_alignment;
|
||||||
|
extern int aggressive;
|
||||||
|
extern char *lastUpdated;
|
||||||
|
extern int file_version;
|
||||||
|
extern int NoFormat;
|
||||||
|
extern int notAccurate;
|
||||||
|
extern int formula_warnings;
|
||||||
|
extern int NoHeaders;
|
||||||
|
extern int NotImplemented;
|
||||||
|
extern int Unsupported;
|
||||||
|
extern int MaxWorksheetsExceeded;
|
||||||
|
extern int MaxRowExceeded;
|
||||||
|
extern int MaxColExceeded;
|
||||||
|
extern int MaxStringsExceeded;
|
||||||
|
extern int MaxFontsExceeded;
|
||||||
|
extern int MaxPalExceeded;
|
||||||
|
extern int MaxXFExceeded;
|
||||||
|
extern int MaxFormatsExceeded;
|
||||||
|
extern char colorTab[MAX_COLORS];
|
||||||
|
extern char *default_text_color;
|
||||||
|
extern char *default_background_color;
|
||||||
|
extern char *default_image;
|
||||||
|
extern char filename[256];
|
||||||
|
extern int UnicodeStrings;
|
||||||
|
extern int CodePage;
|
||||||
|
extern char *title;
|
||||||
|
extern void update_default_alignment(unsigned int, int);
|
||||||
|
extern void output_cell( cell *, int);
|
||||||
|
extern uni_string author;
|
||||||
|
extern int null_string(U8 *);
|
||||||
|
|
||||||
|
|
||||||
|
void OutputTableXML(void)
|
||||||
|
{
|
||||||
|
int i, j, k;
|
||||||
|
|
||||||
|
printf( "<?xml version=\"1.0\" encoding=\"" );
|
||||||
|
switch (UnicodeStrings)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
printf("iso-8859-1\" ?>\n"); /* Latin-1 */
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
printf("windows-1252\"?>\n"); /* Microsoft */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("utf-8\"?>\n"); /* Unicode */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetupExtraction();
|
||||||
|
|
||||||
|
printf( "<excel_workbook>\n" );
|
||||||
|
printf( "\t<sheets>\n" );
|
||||||
|
|
||||||
|
/* Here's where we dump the Html Page out */
|
||||||
|
for (i=first_sheet; i<=last_sheet; i++) /* For each worksheet */
|
||||||
|
{
|
||||||
|
trim_sheet_edges(i);
|
||||||
|
update_default_font(i);
|
||||||
|
if (ws_array[i] == 0)
|
||||||
|
continue;
|
||||||
|
if ((ws_array[i]->biggest_row == -1)||(ws_array[i]->biggest_col == -1))
|
||||||
|
continue;
|
||||||
|
if (ws_array[i]->c_array == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
printf( "\t\t<sheet>\n" );
|
||||||
|
printf( "\t\t\t<page>%d</page>\n", i );
|
||||||
|
|
||||||
|
/* Print its name */
|
||||||
|
if (next_ws_title > 0)
|
||||||
|
{
|
||||||
|
if (ws_array[i]->ws_title.str)
|
||||||
|
{
|
||||||
|
printf("\t\t\t<pagetitle>");
|
||||||
|
OutputString(&ws_array[i]->ws_title);
|
||||||
|
printf("</pagetitle>\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf("\t\t\t<pagetitle>(Unknown Page)</pagetitle>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf( "\t\t\t<firstrow>%ld</firstrow>\n", ws_array[i]->first_row );
|
||||||
|
printf( "\t\t\t<lastrow>%ld</lastrow>\n", ws_array[i]->biggest_row );
|
||||||
|
printf( "\t\t\t<firstcol>%d</firstcol>\n", ws_array[i]->first_col );
|
||||||
|
printf( "\t\t\t<lastcol>%d</lastcol>\n", ws_array[i]->biggest_col );
|
||||||
|
printf( "\t\t\t<rows>\n" );
|
||||||
|
|
||||||
|
for (j=ws_array[i]->first_row; j<=ws_array[i]->biggest_row; j++)
|
||||||
|
{
|
||||||
|
update_default_alignment(i, j);
|
||||||
|
printf("\t\t\t\t<row>\n");
|
||||||
|
for (k=ws_array[i]->first_col; k<=ws_array[i]->biggest_col; k++)
|
||||||
|
{
|
||||||
|
printf("\t\t\t\t\t<cell row=\"%d\" col=\"%d\">", j, k );
|
||||||
|
output_cell(ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k], 1); /* This stuff happens for each cell... */
|
||||||
|
printf("</cell>\n" );
|
||||||
|
if (ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k])
|
||||||
|
{
|
||||||
|
if (ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k]->colspan != 0)
|
||||||
|
k += ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k]->colspan-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("</row>\n");
|
||||||
|
}
|
||||||
|
printf( "\t\t\t</rows>\n" );
|
||||||
|
printf("\t\t</sheet>\n");
|
||||||
|
}
|
||||||
|
printf( "\t</sheets>\n" );
|
||||||
|
|
||||||
|
/* Print the author's name in itallics... */
|
||||||
|
if (author.str)
|
||||||
|
{
|
||||||
|
printf("\t<author>");
|
||||||
|
OutputString(&author);
|
||||||
|
printf("</author>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Print when & how the file was last updated. */
|
||||||
|
if (lastUpdated)
|
||||||
|
printf("\t<lastwrite>%s</lastwrite>", lastUpdated);
|
||||||
|
printf( "\t<excelversion>" );
|
||||||
|
switch (file_version)
|
||||||
|
{
|
||||||
|
case EXCEL95:
|
||||||
|
printf("using Excel 5.0 or 95");
|
||||||
|
break;
|
||||||
|
case EXCEL97:
|
||||||
|
printf("using Excel 97/2000");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("using Excel ????");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf("</excelversion>\n");
|
||||||
|
|
||||||
|
/* Next print Disclaimers... */
|
||||||
|
if (NoFormat)
|
||||||
|
printf("\t<noformat>%d</noformat>\n", NoFormat );
|
||||||
|
if ((notAccurate)&&(formula_warnings))
|
||||||
|
printf("\t<accuracy>%d</accuracy>\n", notAccurate );
|
||||||
|
if (NotImplemented)
|
||||||
|
printf("\t<notimplemented>%d</notimplemented>\n", NotImplemented );
|
||||||
|
if (Unsupported)
|
||||||
|
printf("\t<unsupported>%d</unsupported>\n", Unsupported );
|
||||||
|
|
||||||
|
/* Now out exceeded capacity warnings... */
|
||||||
|
if (MaxWorksheetsExceeded)
|
||||||
|
printf("\t<MaxWorksheetsExceeded>The Maximum Number of Worksheets were exceeded, you might want to increase it.</MaxWorksheetsExceeded>\n ");
|
||||||
|
if (MaxRowExceeded)
|
||||||
|
printf("\t<MaxRowExceeded>The Maximum Number of Rows were exceeded, you might want to increase it.</MaxRowExceeded>\n ");
|
||||||
|
if (MaxColExceeded)
|
||||||
|
printf("\t<MaxColExceeded>The Maximum Number of Columns were exceeded, you might want to increase it.</MaxColExceeded>\n");
|
||||||
|
if (MaxStringsExceeded)
|
||||||
|
printf("\t<MaxStringsExceeded>The Maximum Number of Strings were exceeded, you might want to increase it.</MaxStringsExceeded>\n");
|
||||||
|
if (MaxFontsExceeded)
|
||||||
|
printf("\t<MaxFontsExceeded>The Maximum Number of Fonts were exceeded, you might want to increase it.</MaxFontsExceeded>\n");
|
||||||
|
if (MaxPalExceeded)
|
||||||
|
printf("\t<MaxPalExceeded>The Maximum Number of Color Palettes were exceeded, you might want to increase it.</MaxPalExceeded>\n");
|
||||||
|
if (MaxXFExceeded)
|
||||||
|
printf("\t<MaxXFExceeded>The Maximum Number of Extended Formats were exceeded, you might want to increase it.</MaxXFExceeded>\n");
|
||||||
|
if (MaxFormatsExceeded)
|
||||||
|
printf("\t<MaxFormatsExceeded>The Maximum Number of Formats were exceeded, you might want to increase it.</MaxFormatsExceeded>\n");
|
||||||
|
|
||||||
|
/* Output Credit */
|
||||||
|
printf("\t<tool>Created with xlhtml %s</tool>\n", VERSION);
|
||||||
|
printf("\t<toollink>http://chicago.sf.net/xlhtml/</toollink>\n");
|
||||||
|
printf( "</excel_workbook>\n" );
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user