diff --git a/xlhtml/Makefile.am b/xlhtml/Makefile.am index 677cdf9..1933372 100644 --- a/xlhtml/Makefile.am +++ b/xlhtml/Makefile.am @@ -9,10 +9,10 @@ man_MANS = xlhtml.1 bin_SCRIPTS = nsopen nsxlview bin_PROGRAMS = xlhtml 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 xlcdump_SOURCES = xlcdump.c -AM_CFLAGS = -Wall -Wshadow -Wcast-align -Wpointer-arith +AM_CFLAGS = -Wshadow -Wcast-align -Wpointer-arith doc: @echo Generating documentation... diff --git a/xlhtml/Makefile.in b/xlhtml/Makefile.in index db3de13..0fd02e5 100644 --- a/xlhtml/Makefile.in +++ b/xlhtml/Makefile.in @@ -83,10 +83,10 @@ man_MANS = xlhtml.1 bin_SCRIPTS = nsopen nsxlview bin_PROGRAMS = xlhtml 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 xlcdump_SOURCES = xlcdump.c -AM_CFLAGS = -Wall -Wshadow -Wcast-align -Wpointer-arith +AM_CFLAGS = -Wshadow -Wcast-align -Wpointer-arith mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../config.h CONFIG_CLEAN_FILES = @@ -97,7 +97,7 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I.. CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -xlhtml_OBJECTS = support.o xlhtml.o +xlhtml_OBJECTS = support.o xlhtml.o html.o ascii.o xml.o xlhtml_LDADD = $(LDADD) xlhtml_DEPENDENCIES = ../cole/libcole.a xlhtml_LDFLAGS = diff --git a/xlhtml/ascii.c b/xlhtml/ascii.c new file mode 100644 index 0000000..15d0205 --- /dev/null +++ b/xlhtml/ascii.c @@ -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 */ + } +} diff --git a/xlhtml/html.c b/xlhtml/html.c new file mode 100644 index 0000000..0915573 --- /dev/null +++ b/xlhtml/html.c @@ -0,0 +1,389 @@ + +#include "xlhtml.h" +#include + + + + +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("
"); + 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("

"); + OutputString(&ws_array[i]->ws_title); + printf("


"); + do_cr(); + } + else + { + printf("

(Unknown Page)


"); + do_cr(); + } + } + + /* Now dump the table */ + printf(""); + do_cr(); + printf(""); + do_cr(); + for (j=ws_array[i]->first_row; j<=ws_array[i]->biggest_row; j++) + { + update_default_alignment(i, j); + 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("\n"); + } + printf("

"); + do_cr(); + } + + if (center_tables) + { + printf("
"); + do_cr(); + } + + /* Print the author's name in itallics... */ + if (author.str) + { + printf("Spreadsheet's Author: "); + OutputString(&author); + printf("
"); + do_cr(); + } + + /* Print when & how the file was last updated. */ + printf("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("
"); + do_cr(); + + /* Next print Disclaimers... */ + if (NoFormat) + { + printf("
* This cell's format is not supported.
"); + do_cr(); + } + if ((notAccurate)&&(formula_warnings)) + { + printf("
** This cell's data may not be accurate.
"); + do_cr(); + } + if (NotImplemented) + { + printf("
*** This cell's data type will be supported in the future.
"); + do_cr(); + } + if (Unsupported) + { + printf("
**** This cell's type is unsupported.
"); + do_cr(); + } + + /* Now out exceeded capacity warnings... */ + if (MaxWorksheetsExceeded || MaxRowExceeded || MaxColExceeded || MaxStringsExceeded || + MaxFontsExceeded || MaxPalExceeded || MaxXFExceeded || MaxFormatsExceeded ) + printf("", colorTab[0x0A]); + if (MaxWorksheetsExceeded) + { + printf("The Maximum Number of Worksheets was exceeded, you might want to increase it.
"); + do_cr(); + } + if (MaxRowExceeded) + { + printf("The Maximum Number of Rows was exceeded, you might want to increase it.
"); + do_cr(); + } + if (MaxColExceeded) + { + printf("The Maximum Number of Columns was exceeded, you might want to increase it.
"); + do_cr(); + } + if (MaxStringsExceeded) + { + printf("The Maximum Number of Strings was exceeded, you might want to increase it.
"); + do_cr(); + } + if (MaxFontsExceeded) + { + printf("The Maximum Number of Fonts was exceeded, you might want to increase it.
"); + do_cr(); + } + if (MaxPalExceeded) + { + printf("The Maximum Number of Color Palettes was exceeded, you might want to increase it.
"); + do_cr(); + } + if (MaxXFExceeded) + { + printf("The Maximum Number of Extended Formats was exceeded, you might want to increase it.
"); + do_cr(); + } + if (MaxFormatsExceeded) + { + printf("The Maximum Number of Formats was exceeded, you might want to increase it.
"); + do_cr(); + } + if (MaxWorksheetsExceeded || MaxRowExceeded || MaxColExceeded || MaxStringsExceeded || + MaxFontsExceeded || MaxPalExceeded || MaxXFExceeded || MaxFormatsExceeded ) + printf("
"); + + printf(" 
"); + do_cr(); + + /* Output Credit */ + printf("
Created with xlhtml %s
", VERSION); + do_cr(); + + /* Output Tail */ + output_footer(); +} + +void output_header(void) +{ /* Ouput Header */ + if (NoHeaders) + return; + if (!aggressive) + { + printf(""); + do_cr(); + } + printf(""); + do_cr(); + printf("", 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(""); + do_cr(); + } + printf(""); + if (title) + printf("%s", title); + else + printf("%s", filename); + printf(""); + do_cr(); + printf(""); + do_cr(); + do_cr(); + printf("
"); + do_cr(); +} + +void output_footer(void) +{ + if (NoHeaders) + return; + printf(""); + 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(""); + h->uflag = 1; + } + if (font_array[fnt_idx]->bold >= 0x02BC) + { + h->bflag = 1; + printf(""); + } + if (font_array[fnt_idx]->attr & 0x0002) + { + h->iflag = 1; + printf(""); + } + if (font_array[fnt_idx]->attr & 0x0008) + { + h->sflag = 1; + printf(""); + } + if ((font_array[fnt_idx]->super & 0x0003) == 0x0001) + { + h->spflag = 1; + printf(""); + } + else if ((font_array[fnt_idx]->super & 0x0003) == 0x0002) + { + h->sbflag = 1; + printf(""); + } + } +} + +void output_end_html_attr(html_attr *h) +{ + if (h->sbflag) + { + printf(""); + h->sbflag = 0; + } + else if (h->spflag) + { + printf(""); + h->spflag = 0; + } + if (h->sflag) + { + printf(""); + h->sflag = 0; + } + if (h->iflag) + { + printf(""); + h->iflag = 0; + } + if (h->bflag) + { + printf(""); + h->bflag = 0; + } + if (h->uflag) + { + if (h->uflag == 1) + printf(""); + else + printf(""); + h->uflag = 0; + } +} diff --git a/xlhtml/support.c b/xlhtml/support.c index 4f16f49..1417591 100644 --- a/xlhtml/support.c +++ b/xlhtml/support.c @@ -2,9 +2,10 @@ /* Various support functions for xlhtml. */ #include -#include "support.h" #include "version.h" - +#include +#include "../cole/cole.h" +#include void print_version(void) { @@ -63,3 +64,145 @@ S32 getLong(U8 *ptr) return (S32)(*(ptr+3)<<24)+(*(ptr+2)<<16)+(*(ptr+1)<<8)+*ptr; } + +#ifndef WORDS_BIGENDIAN /* Defined in */ +/*! Little Endian - 0x86 family */ +void getDouble(U8 *ptr, F64 *d) +{ + size_t i; + F64 dd; + U8 *t = (U8 *)ⅆ + + for (i=0; i (((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 */ +/*! 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 diff --git a/xlhtml/xlhtml.c b/xlhtml/xlhtml.c index e18941f..4374a11 100644 --- a/xlhtml/xlhtml.c +++ b/xlhtml/xlhtml.c @@ -29,11 +29,16 @@ +static char SectionName[2][12] = /* The section of the Excel Stream where the workbooks are kept */ +{ + "/Workbook", /*!< Excel 97 & 2000 */ + "/Book" /*!< Everything else ? */ +}; -static int numCustomColors = 0; -static U8 **customColors = 0; -static char colorTab[MAX_COLORS][8] = +int numCustomColors = 0; +U8 **customColors = 0; +char colorTab[MAX_COLORS][8] = { "000000", /* FIXME: Need to find these first 8 colors! */ "FFFFFF", @@ -102,152 +107,154 @@ static char colorTab[MAX_COLORS][8] = "FFFFFF" /* 0x40 */ }; +int DatesR1904 = 0; /*!< Flag that the dates are based on McIntosh Dates system */ + /* FIXME: Support major languages here...not just English */ -static const char month_abbr[12][5] = { "Jan", "Feb", "Mar", "Apr", "May", "June", +const char month_abbr[12][5] = { "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec" }; -static const int ndays[]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; -static const int ldays[]={31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; -/************************************************************************** -* Functions and data are declared static to prevent name collisions. -***************************************************************************/ /* Function Prototypes */ + +/* These functions are in support.c */ extern void print_version(void); extern void display_usage(void); +extern void do_cr(void); +extern void OutputTableHTML(void); +extern S32 getLong(U8 *); +extern U16 getShort(U8 *); +extern void getDouble(U8 *, F64 *); +extern int null_string(U8 *); +extern void FracToTime(U8 *, int *, int *, int *, int *); +extern void NumToDate(long, int *, int *, int *); +extern void RKtoDouble(S32, F64 *); + +/* This function is in xml.c */ +extern void OutputTableXML(void); + +/* This function is in ascii.c */ +void OutputPartialTableAscii(void); + +/* These functions are in html.c */ +extern void output_start_html_attr(html_attr *h, unsigned int, int); +extern void output_end_html_attr(html_attr *h); COLE_LOCATE_ACTION_FUNC scan_file; -void OutputPartialTableAscii(void); -static void OutputTableHTML(void); -static void OutputTableXML(void); - -extern void do_cr(void); -static void main_line_processor(U16, U16, U32, U16, U8); -static void SetupExtraction(void); -static void output_header(void); -static void output_footer(void); -extern U16 getShort(U8 *); -extern S32 getLong(U8 *); -static void getDouble(U8 *, F64 *); -static void RKtoDouble(S32, F64 *); -static void decodeBoolErr(U16, U16, char *); -static int IsCellNumeric(cell *); -static int IsCellSafe(cell *); -static int IsCellFormula(cell *); -static void output_cell(cell *, int); -static void output_formatted_data(uni_string *, U16, int, int); -static void PrintFloatComma(char *, int, F64); -static void print_as_fraction(F64, int); -static void NumToDate(long, int *, int *, int *); -static void FracToTime(U8 *, int *, int *, int *, int *); -static void trim_sheet_edges(unsigned int); -static void update_default_font(unsigned int); -static void incr_f_cnt(uni_string *); -static int get_default_font(void); -static void update_default_alignment(unsigned int, int); -static int null_string(U8 *); -static void OutputString(uni_string *); -static void OutputCharCorrected(U8); -static void update_crun_info(U16 *loc, U16 *fnt_idx, U16 crun_cnt, U8 *fmt_run); -static void put_utf8(U16); -static void print_utf8(U16); -static void uni_string_clear(uni_string *); -static int uni_string_comp(uni_string *, uni_string *); -static void output_start_html_attr(html_attr *h, unsigned int, int); -static void output_end_html_attr(html_attr *h); -static void html_flag_init(html_attr *h); -static void output_start_font_attribute(html_attr *h, U16 fnt_idx); +void main_line_processor(U16, U16, U32, U16, U8); +void SetupExtraction(void); +void decodeBoolErr(U16, U16, char *); +int IsCellNumeric(cell *); +int IsCellSafe(cell *); +int IsCellFormula(cell *); +void output_cell(cell *, int); +void output_formatted_data(uni_string *, U16, int, int); +void PrintFloatComma(char *, int, F64); +void print_as_fraction(F64, int); +void trim_sheet_edges(unsigned int); +void update_default_font(unsigned int); +void incr_f_cnt(uni_string *); +int get_default_font(void); +void update_default_alignment(unsigned int, int); +void OutputString(uni_string *); +void OutputCharCorrected(U8); +void update_crun_info(U16 *loc, U16 *fnt_idx, U16 crun_cnt, U8 *fmt_run); +void put_utf8(U16); +void print_utf8(U16); +void uni_string_clear(uni_string *); +int uni_string_comp(uni_string *, uni_string *); +void html_flag_init(html_attr *h); +void output_start_font_attribute(html_attr *h, U16 fnt_idx); /* The array update functions */ -static int ws_init(int); -static int add_more_worksheet_ptrs(void); -static int resize_c_array(work_sheet *, U32, U16); -static void add_wb_array(U16, U16, U16, U16, U8, U8 *, U16, U16, U8 *); -static void update_cell_xf(U16, U16, U16); -static void update_cell_hyperlink(U16 r, U16 c, U8 *hyperlink, int len, U16 type); -static void add_str_array(U8, U8 *, U16, U8 *, U8); -static void add_font(U16, U16, U16, U16, U16, U8, U16, U8 *, U16); -static void add_ws_title(U16, U8 *, U16); -static void add_xf_array(U16 fnt_idx, U16 fmt_idx, U16 gen, U16 align, - U16 indent, U16 b_style, U16 b_l_color, U32 b_t_color, U16 cell_color); +int ws_init(int); +int add_more_worksheet_ptrs(void); +int resize_c_array(work_sheet *, U32, U16); +void add_wb_array(U16, U16, U16, U16, U8, U8 *, U16, U16, U8 *); +void update_cell_xf(U16, U16, U16); +void update_cell_hyperlink(U16 r, U16 c, U8 *hyperlink, int len, U16 type); +void add_str_array(U8, U8 *, U16, U8 *, U8); +void add_font(U16, U16, U16, U16, U16, U8, U16, U8 *, U16); +void add_ws_title(U16, U8 *, U16); +void add_xf_array(U16 fnt_idx, U16 fmt_idx, U16 gen, U16 align, +U16 indent, U16 b_style, U16 b_l_color, U32 b_t_color, U16 cell_color); /* Global data */ -static char filename[256]; -static int file_version = 0; -static U32 next_string=0; -static unsigned int next_font=0, next_ws_title=0, next_xf=0; -static U8 working_buffer[WBUFF_SIZE]; -static unsigned int bufidx, buflast; /*!< Needed for working buffer */ -static U8 grbit=0; /*!< Needed by the SST Opcode FC */ -static U16 crun=0, cch=0; /*!< Needed by the SST Opcode FC */ -static U32 extrst=0; /*!< Needed by the SST Opcode FC */ -static U16 nonascii = 0; /*!< Needed by the SST Opcode FC */ -static int sheet_count=-2; /*!< Number of worksheets found */ -static U16 last_opcode = -1; /*!< Used for the continue command */ -static unsigned int cont_grbit=0, cont_str_array=0; -static uni_string default_font; /*!< Font for table */ -static int default_fontsize = 3; /*!< Default font size for table */ -static char *default_alignment = 0; /*!< Alignment for table */ -static int first_sheet = 0; /*!< First worksheet to display */ -static int last_sheet = WORKSHEETS_INCR-1; /*!< The last worksheet to display */ -static S16 xp=0, xr1=-1, xr2=-1, xc1=-1, xc2=-1; /*!< Extraction info... */ -static int currency_symbol = '$'; /*!< What to use for currency */ -static U16 str_formula_row = 0; /*!< Data holders for string formulas */ -static U16 str_formula_col = 0; /*!< Data holders for string formulas */ -static U16 str_formula_format = 0; /*!< Data holders for string formulas */ +char filename[256]; +int file_version = 0; +U32 next_string=0; +unsigned int next_font=0, next_ws_title=0, next_xf=0; +U8 working_buffer[WBUFF_SIZE]; +unsigned int bufidx, buflast; /*!< Needed for working buffer */ +U8 grbit=0; /*!< Needed by the SST Opcode FC */ +U16 crun=0, cch=0; /*!< Needed by the SST Opcode FC */ +U32 extrst=0; /*!< Needed by the SST Opcode FC */ +U16 nonascii = 0; /*!< Needed by the SST Opcode FC */ +int sheet_count=-2; /*!< Number of worksheets found */ +U16 last_opcode = -1; /*!< Used for the continue command */ +unsigned int cont_grbit=0, cont_str_array=0; +uni_string default_font; /*!< Font for table */ +int default_fontsize = 3; /*!< Default font size for table */ +char *default_alignment = 0; /*!< Alignment for table */ +int first_sheet = 0; /*!< First worksheet to display */ +int last_sheet = WORKSHEETS_INCR-1; /*!< The last worksheet to display */ +S16 xp=0, xr1=-1, xr2=-1, xc1=-1, xc2=-1; /*!< Extraction info... */ +int currency_symbol = '$'; /*!< What to use for currency */ +U16 str_formula_row = 0; /*!< Data holders for string formulas */ +U16 str_formula_col = 0; /*!< Data holders for string formulas */ +U16 str_formula_format = 0; /*!< Data holders for string formulas */ /* Limits */ -static unsigned int max_fonts = FONTS_INCR; -static unsigned int max_xformats = XFORMATS_INCR; -static unsigned long max_strings = STRINGS_INCR; -static unsigned int max_worksheets = WORKSHEETS_INCR; +unsigned int max_fonts = FONTS_INCR; +unsigned int max_xformats = XFORMATS_INCR; +unsigned long max_strings = STRINGS_INCR; +unsigned int max_worksheets = WORKSHEETS_INCR; + /* Global arrays */ -static xf_attr **xf_array; -static work_sheet **ws_array; -static uni_string **str_array; -static font_attr **font_array; -static fnt_cnt *f_cnt; -static int fnt_size_cnt[7]; /*!< Html has only 7 sizes... */ -static uni_string author; -static char *title = 0; -static char *lastUpdated = 0; +xf_attr **xf_array; +work_sheet **ws_array; +uni_string **str_array; +font_attr **font_array; +fnt_cnt *f_cnt; +int fnt_size_cnt[7]; /*!< Html has only 7 sizes... */ +uni_string author; +char *title = 0; +char *lastUpdated = 0; /* Command Line flags */ -static int use_colors = 1; /*!< Whether or not to use colors in output */ +int use_colors = 1; /*!< Whether or not to use colors in output */ int aggressive = 0; /*!< Aggressive html optimization */ -static int formula_warnings = 1; /*!< Whether or not to suppress formula warnings */ -static int center_tables = 0; /*!< Whether or not to center justify tables or leave it left */ -static int trim_edges = 0; /*!< Whether or not to trim the edges of columns or rows */ -static char *default_text_color = "000000"; -static char *default_background_color="FFFFFF"; -static char *default_image=NULL; /*!< Point to background image */ -static int Ascii = 0; /*!< Whether or not to out ascii instaed of html */ -static int Csv = 0; /*!< Whether or not to out csv instaed of html */ -static int OutputXML = 0; /*!< Output as xml */ -static int DumpPage = 0; /*!< Dump page count & max cols & rows */ -static int Xtract = 0; /*!< Extract a range on a page. */ -static int MultiByte = 0; /*!< Output as multibyte */ -static int NoHeaders = 0; /*!< Dont output html header */ +int formula_warnings = 1; /*!< Whether or not to suppress formula warnings */ +int center_tables = 0; /*!< Whether or not to center justify tables or leave it left */ +int trim_edges = 0; /*!< Whether or not to trim the edges of columns or rows */ +char *default_text_color = "000000"; +char *default_background_color="FFFFFF"; +char *default_image=NULL; /*!< Point to background image */ +int Ascii = 0; /*!< Whether or not to out ascii instaed of html */ +int Csv = 0; /*!< Whether or not to out csv instaed of html */ +int OutputXML = 0; /*!< Output as xml */ +int DumpPage = 0; /*!< Dump page count & max cols & rows */ +int Xtract = 0; /*!< Extract a range on a page. */ +int MultiByte = 0; /*!< Output as multibyte */ +int NoHeaders = 0; /*!< Dont output html header */ /* Some Global Flags */ -static int notAccurate = 0; /*!< Flag used to indicate that stale data was used */ -static int NoFormat = 0; /*!< Flag used to indicated unimplemented format */ -static int NotImplemented = 0; /*!< Flag to print unimplemented cell type message */ -static int Unsupported = 0; /*!< Flag to print unsupported cell type message */ -static int DatesR1904 = 0; /*!< Flag that the dates are based on McIntosh Dates system */ -static int MaxPalExceeded = 0; -static int MaxXFExceeded = 0; -static int MaxFormatsExceeded = 0; -static int MaxColExceeded = 0; -static int MaxRowExceeded = 0; -static int MaxWorksheetsExceeded = 0; -static int MaxStringsExceeded = 0; -static int MaxFontsExceeded = 0; -static int UnicodeStrings = 0; /*!< 0==ASCII, 1==windows-1252, 2==uft-8 */ -static int CodePage = 0; /*!< Micosoft CodePage as specified in the Excel file. */ +int notAccurate = 0; /*!< Flag used to indicate that stale data was used */ +int NoFormat = 0; /*!< Flag used to indicated unimplemented format */ +int NotImplemented = 0; /*!< Flag to print unimplemented cell type message */ +int Unsupported = 0; /*!< Flag to print unsupported cell type message */ +int MaxPalExceeded = 0; +int MaxXFExceeded = 0; +int MaxFormatsExceeded = 0; +int MaxColExceeded = 0; +int MaxRowExceeded = 0; +int MaxWorksheetsExceeded = 0; +int MaxStringsExceeded = 0; +int MaxFontsExceeded = 0; +int UnicodeStrings = 0; /*!< 0==ASCII, 1==windows-1252, 2==uft-8 */ +int CodePage = 0; /*!< Micosoft CodePage as specified in the Excel file. */ @@ -390,7 +397,7 @@ int main (int argc, char **argv) aggressive = 0; /* Init arrays... */ - ws_array = (work_sheet **)malloc(max_worksheets * sizeof(work_sheet*)); + ws_array = (work_sheet **)malloc(max_worksheets * sizeof(work_sheet *)); for (i=0; i<(int)max_worksheets; i++) ws_array[i] = 0; @@ -483,8 +490,13 @@ int main (int argc, char **argv) } } } + + free(xf_array); free(font_array); free(f_cnt); + free(str_array); + free(ws_array); + for (i=0; i<(int)max_worksheets; i++) { if (ws_array[i]) @@ -515,8 +527,6 @@ int main (int argc, char **argv) } } - free(str_array); - free(ws_array); for (i=0; i<(int)max_xformats; i++) { @@ -641,346 +651,9 @@ void scan_file(COLEDIRENT *cde, void *_info) -static void OutputTableHTML(void) -{ - int i, j, k; - output_header(); - if (center_tables) - { - printf("
"); - 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("

"); - OutputString(&ws_array[i]->ws_title); - printf("


"); - do_cr(); - } - else - { - printf("

(Unknown Page)


"); - do_cr(); - } - } - - /* Now dump the table */ - printf(""); - do_cr(); - printf(""); - do_cr(); - for (j=ws_array[i]->first_row; j<=ws_array[i]->biggest_row; j++) - { - update_default_alignment(i, j); - 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("\n"); - } - printf("

"); - do_cr(); - } - - if (center_tables) - { - printf("
"); - do_cr(); - } - - /* Print the author's name in itallics... */ - if (author.str) - { - printf("Spreadsheet's Author: "); - OutputString(&author); - printf("
"); - do_cr(); - } - - /* Print when & how the file was last updated. */ - printf("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("
"); - do_cr(); - - /* Next print Disclaimers... */ - if (NoFormat) - { - printf("
* This cell's format is not supported.
"); - do_cr(); - } - if ((notAccurate)&&(formula_warnings)) - { - printf("
** This cell's data may not be accurate.
"); - do_cr(); - } - if (NotImplemented) - { - printf("
*** This cell's data type will be supported in the future.
"); - do_cr(); - } - if (Unsupported) - { - printf("
**** This cell's type is unsupported.
"); - do_cr(); - } - - /* Now out exceeded capacity warnings... */ - if (MaxWorksheetsExceeded || MaxRowExceeded || MaxColExceeded || MaxStringsExceeded || - MaxFontsExceeded || MaxPalExceeded || MaxXFExceeded || MaxFormatsExceeded ) - printf("", colorTab[0x0A]); - if (MaxWorksheetsExceeded) - { - printf("The Maximum Number of Worksheets was exceeded, you might want to increase it.
"); - do_cr(); - } - if (MaxRowExceeded) - { - printf("The Maximum Number of Rows was exceeded, you might want to increase it.
"); - do_cr(); - } - if (MaxColExceeded) - { - printf("The Maximum Number of Columns was exceeded, you might want to increase it.
"); - do_cr(); - } - if (MaxStringsExceeded) - { - printf("The Maximum Number of Strings was exceeded, you might want to increase it.
"); - do_cr(); - } - if (MaxFontsExceeded) - { - printf("The Maximum Number of Fonts was exceeded, you might want to increase it.
"); - do_cr(); - } - if (MaxPalExceeded) - { - printf("The Maximum Number of Color Palettes was exceeded, you might want to increase it.
"); - do_cr(); - } - if (MaxXFExceeded) - { - printf("The Maximum Number of Extended Formats was exceeded, you might want to increase it.
"); - do_cr(); - } - if (MaxFormatsExceeded) - { - printf("The Maximum Number of Formats was exceeded, you might want to increase it.
"); - do_cr(); - } - if (MaxWorksheetsExceeded || MaxRowExceeded || MaxColExceeded || MaxStringsExceeded || - MaxFontsExceeded || MaxPalExceeded || MaxXFExceeded || MaxFormatsExceeded ) - printf("
"); - - printf(" 
"); - do_cr(); - - /* Output Credit */ - printf("
Created with xlhtml %s
", VERSION); - do_cr(); - - /* Output Tail */ - output_footer(); -} - -static void OutputTableXML(void) -{ - int i, j, k; - - printf( "\n"); /* Latin-1 */ - break; - case 1: - printf("windows-1252\"?>\n"); /* Microsoft */ - break; - default: - printf("utf-8\"?>\n"); /* Unicode */ - break; - } - - SetupExtraction(); - - printf( "\n" ); - printf( "\t\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\n" ); - printf( "\t\t\t%d\n", i ); - - /* Print its name */ - if (next_ws_title > 0) - { - if (ws_array[i]->ws_title.str) - { - printf("\t\t\t"); - OutputString(&ws_array[i]->ws_title); - printf("\n"); - } - else - printf("\t\t\t(Unknown Page)\n"); - } - - printf( "\t\t\t%ld\n", ws_array[i]->first_row ); - printf( "\t\t\t%ld\n", ws_array[i]->biggest_row ); - printf( "\t\t\t%d\n", ws_array[i]->first_col ); - printf( "\t\t\t%d\n", ws_array[i]->biggest_col ); - printf( "\t\t\t\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\n"); - for (k=ws_array[i]->first_col; k<=ws_array[i]->biggest_col; k++) - { - printf("\t\t\t\t\t", j, k ); - output_cell(ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k], 1); /* This stuff happens for each cell... */ - printf("\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("\n"); - } - printf( "\t\t\t\n" ); - printf("\t\t\n"); - } - printf( "\t\n" ); - - /* Print the author's name in itallics... */ - if (author.str) - { - printf("\t"); - OutputString(&author); - printf("\n"); - } - - /* Print when & how the file was last updated. */ - if (lastUpdated) - printf("\t%s", lastUpdated); - printf( "\t" ); - 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("\n"); - - /* Next print Disclaimers... */ - if (NoFormat) - printf("\t%d\n", NoFormat ); - if ((notAccurate)&&(formula_warnings)) - printf("\t%d\n", notAccurate ); - if (NotImplemented) - printf("\t%d\n", NotImplemented ); - if (Unsupported) - printf("\t%d\n", Unsupported ); - - /* Now out exceeded capacity warnings... */ - if (MaxWorksheetsExceeded) - printf("\tThe Maximum Number of Worksheets were exceeded, you might want to increase it.\n "); - if (MaxRowExceeded) - printf("\tThe Maximum Number of Rows were exceeded, you might want to increase it.\n "); - if (MaxColExceeded) - printf("\tThe Maximum Number of Columns were exceeded, you might want to increase it.\n"); - if (MaxStringsExceeded) - printf("\tThe Maximum Number of Strings were exceeded, you might want to increase it.\n"); - if (MaxFontsExceeded) - printf("\tThe Maximum Number of Fonts were exceeded, you might want to increase it.\n"); - if (MaxPalExceeded) - printf("\tThe Maximum Number of Color Palettes were exceeded, you might want to increase it.\n"); - if (MaxXFExceeded) - printf("\tThe Maximum Number of Extended Formats were exceeded, you might want to increase it.\n"); - if (MaxFormatsExceeded) - printf("\tThe Maximum Number of Formats were exceeded, you might want to increase it.\n"); - - /* Output Credit */ - printf("\tCreated with xlhtml %s\n", VERSION); - printf("\thttp://chicago.sf.net/xlhtml/\n"); - printf( "\n" ); -} - -static void SetupExtraction(void) +void SetupExtraction(void) { if (Xtract) { /* Revise the page settings... */ @@ -1051,70 +724,6 @@ static void SetupExtraction(void) } } -static void output_header(void) -{ /* Ouput Header */ - if (NoHeaders) - return; - if (!aggressive) - { - printf(""); - do_cr(); - } - printf(""); - do_cr(); - printf("", 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(""); - do_cr(); - } - printf(""); - if (title) - printf("%s", title); - else - printf("%s", filename); - printf(""); - do_cr(); - printf(""); - do_cr(); - do_cr(); - printf("
"); - do_cr(); -} - -static void output_footer(void) -{ - if (NoHeaders) - return; - printf(""); - do_cr(); - fflush(stdout); -} /*!****************************************************************** * \param count the absolute count in the record @@ -1122,7 +731,7 @@ static void output_footer(void) * \param bufidx the index into the working buffer * \param buflast the expected length of the working buffer ********************************************************************/ -static void main_line_processor(U16 opcode, U16 version, U32 count, U16 last, U8 data) +void main_line_processor(U16 opcode, U16 version, U32 count, U16 last, U8 data) { U16 cont_opcode = 0; @@ -2183,60 +1792,11 @@ static void main_line_processor(U16 opcode, U16 version, U32 count, U16 last, U8 -#ifndef WORDS_BIGENDIAN /* Defined in */ -/*! Little Endian - 0x86 family */ -static void getDouble(U8 *ptr, F64 *d) -{ - size_t i; - F64 dd; - U8 *t = (U8 *)ⅆ - for (i=0; isw) - -#ifndef WORDS_BIGENDIAN /*! Defined in */ -/*! Little Endian - 0x86 family */ -static void RKtoDouble(S32 n, F64 *d) -{ - noaliasdub(swords,d)[0] = 0; - noaliasdub(swords,d)[1] = n << 2; -} -#else -/*! Big Endian version - UltraSparc's, etc. */ -static 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 /*! returns 1 on error, 0 on success */ -static int ws_init(int i) +int ws_init(int i) { U32 j; U16 k; @@ -2268,7 +1828,7 @@ static int ws_init(int i) } /*! returns 1 on error, 0 on success */ -static int add_more_worksheet_ptrs(void) +int add_more_worksheet_ptrs(void) { work_sheet **tws_array; int pages; @@ -2303,7 +1863,7 @@ static int add_more_worksheet_ptrs(void) return 0; } -static int resize_c_array(work_sheet *ws, U32 new_rows, U16 new_cols) +int resize_c_array(work_sheet *ws, U32 new_rows, U16 new_cols) { cell **tc_array; if (ws == 0) @@ -2334,7 +1894,7 @@ static int resize_c_array(work_sheet *ws, U32 new_rows, U16 new_cols) return 0; } -static void add_wb_array(U16 r, U16 c, U16 xf, U16 type, U8 uni, +void add_wb_array(U16 r, U16 c, U16 xf, U16 type, U8 uni, U8 *str, U16 len, U16 crun_cnt, U8 *fmt_run) { work_sheet *ws; @@ -2485,7 +2045,7 @@ static void add_wb_array(U16 r, U16 c, U16 xf, U16 type, U8 uni, } } -static void update_cell_xf(U16 r, U16 c, U16 xf) +void update_cell_xf(U16 r, U16 c, U16 xf) { work_sheet *ws; @@ -2557,7 +2117,7 @@ static void update_cell_xf(U16 r, U16 c, U16 xf) } */ } -static void update_cell_hyperlink(U16 r, U16 c, U8 *hyperlink, int len, U16 uni) +void update_cell_hyperlink(U16 r, U16 c, U8 *hyperlink, int len, U16 uni) { work_sheet *ws; @@ -2628,7 +2188,7 @@ static void update_cell_hyperlink(U16 r, U16 c, U8 *hyperlink, int len, U16 uni) } */ } -static void add_str_array(U8 uni, U8 *str, U16 len, U8 *fmt_run, U8 crun_cnt) +void add_str_array(U8 uni, U8 *str, U16 len, U8 *fmt_run, U8 crun_cnt) { if ((str == 0)||(len == 0)) @@ -2700,7 +2260,7 @@ static void add_str_array(U8 uni, U8 *str, U16 len, U8 *fmt_run, U8 crun_cnt) next_string++; } -static void add_font(U16 size, U16 attr, U16 c_idx, U16 bold, U16 super, U8 underline, +void add_font(U16 size, U16 attr, U16 c_idx, U16 bold, U16 super, U8 underline, U16 uni, U8 *n, U16 len) { if (n == 0) @@ -2776,7 +2336,7 @@ static void add_font(U16 size, U16 attr, U16 c_idx, U16 bold, U16 super, U8 unde next_font++; } -static void add_ws_title(U16 uni, U8 *n, U16 len) +void add_ws_title(U16 uni, U8 *n, U16 len) { if (n == 0) return; @@ -2808,7 +2368,7 @@ static void add_ws_title(U16 uni, U8 *n, U16 len) next_ws_title++; } -static void add_xf_array(U16 fnt_idx, U16 fmt_idx, U16 gen, U16 align, +void add_xf_array(U16 fnt_idx, U16 fmt_idx, U16 gen, U16 align, U16 indent, U16 b_style, U16 b_l_color, U32 b_t_color, U16 cell_color) { if (next_xf >= max_xformats) @@ -2853,7 +2413,7 @@ static void add_xf_array(U16 fnt_idx, U16 fmt_idx, U16 gen, U16 align, } } -static void decodeBoolErr(U16 value, U16 flag, char *str) +void decodeBoolErr(U16 value, U16 flag, char *str) { if (str == 0) return; @@ -2897,7 +2457,7 @@ static void decodeBoolErr(U16 value, U16 flag, char *str) } } -static int IsCellNumeric(cell *c) +int IsCellNumeric(cell *c) { int ret_val = 0; @@ -2922,7 +2482,7 @@ static int IsCellNumeric(cell *c) /*! \retval 0 not safe at all. \retval 1 extended format is OK \retval 2 Fonts OK */ -static int IsCellSafe(cell *c) +int IsCellSafe(cell *c) { int safe = 0; @@ -2941,7 +2501,7 @@ static int IsCellSafe(cell *c) return safe; } -static int IsCellFormula(cell *c) +int IsCellFormula(cell *c) { if ((c->type > 0x0100)||(c->type == 0x0006)) return 1; @@ -2949,7 +2509,7 @@ static int IsCellFormula(cell *c) return 0; } -static void output_cell(cell *c, int xml) +void output_cell(cell *c, int xml) { html_attr h; @@ -3165,7 +2725,7 @@ static void output_cell(cell *c, int xml) printf( xml ? "" : "\n"); } -static void output_formatted_data(uni_string *u, U16 idx, int numeric, int formula) +void output_formatted_data(uni_string *u, U16 idx, int numeric, int formula) { if ((idx < max_xformats)&&(u->str)) { @@ -3479,76 +3039,9 @@ static void output_formatted_data(uni_string *u, U16 idx, int numeric, int formu OutputString(u); } -static void NumToDate(long num, int *year, int *month, int *day) -{ - 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; -} - -static 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; -} - -static void PrintFloatComma(char *fformat, int is_currency, F64 d) +void PrintFloatComma(char *fformat, int is_currency, F64 d) { int len, int_len, dec_len; char *ptr2, buf[64]; @@ -3637,7 +3130,7 @@ static void PrintFloatComma(char *fformat, int is_currency, F64 d) } } -static void print_as_fraction(F64 d, int digits) +void print_as_fraction(F64 d, int digits) { F64 i, j, w, r, closest=1.0, lim = 9.0; int ci=1, cj=1; @@ -3678,7 +3171,7 @@ static void print_as_fraction(F64 d, int digits) printf("%d/%d", ci, cj); } -static void trim_sheet_edges(unsigned int sheet) +void trim_sheet_edges(unsigned int sheet) { cell *ce; int not_done = 1; @@ -3800,7 +3293,7 @@ static void trim_sheet_edges(unsigned int sheet) *! Figures out the best font & alignment for the current table. * Also sets the default_font and default_alignment. ****************/ -static void update_default_font(unsigned int sheet) +void update_default_font(unsigned int sheet) { cell *ce; int r, c, f; @@ -3917,7 +3410,7 @@ static void update_default_font(unsigned int sheet) } } -static void incr_f_cnt(uni_string *name) +void incr_f_cnt(uni_string *name) { int i; @@ -3951,7 +3444,7 @@ static void incr_f_cnt(uni_string *name) } } -static int get_default_font(void) +int get_default_font(void) { int i, m = -1; @@ -3969,7 +3462,7 @@ static int get_default_font(void) return m; } -static void update_default_alignment(unsigned int sheet, int row) +void update_default_alignment(unsigned int sheet, int row) { int i, left = 0, center = 0, right = 0; cell *c; @@ -4035,22 +3528,8 @@ static void update_default_alignment(unsigned int sheet, int row) default_alignment = "left"; } -static 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; -} - -static void OutputString(uni_string *u) +void OutputString(uni_string *u) { unsigned int i; @@ -4169,7 +3648,7 @@ static void OutputString(uni_string *u) } } -static void OutputCharCorrected(U8 c) +void OutputCharCorrected(U8 c) { if (MultiByte && (c & 0x80)) { @@ -4296,7 +3775,7 @@ static void OutputCharCorrected(U8 c) } } -static void update_crun_info(U16 *loc, U16 *fmt_idx, U16 crun_cnt, U8 *fmt_run) +void update_crun_info(U16 *loc, U16 *fmt_idx, U16 crun_cnt, U8 *fmt_run) { U16 tloc, tfmt_idx; U16 offset = (U16)(crun_cnt*4); @@ -4307,12 +3786,12 @@ static void update_crun_info(U16 *loc, U16 *fmt_idx, U16 crun_cnt, U8 *fmt_run) *fmt_idx = tfmt_idx; } -static void put_utf8(U16 c) +void put_utf8(U16 c) { putchar((int)0x0080 | (c & 0x003F)); } -static void print_utf8(U16 c) +void print_utf8(U16 c) { if (c < 0x80) OutputCharCorrected(c); @@ -4329,7 +3808,7 @@ static void print_utf8(U16 c) } } -static void uni_string_clear(uni_string *str) +void uni_string_clear(uni_string *str) { if (str == 0) return; @@ -4341,7 +3820,7 @@ static void uni_string_clear(uni_string *str) str->crun_cnt = 0; } -static int uni_string_comp(uni_string *s1, uni_string *s2) +int uni_string_comp(uni_string *s1, uni_string *s2) { if ((s1 == 0)||(s2 == 0)) return -1; @@ -4354,81 +3833,9 @@ static int uni_string_comp(uni_string *s1, uni_string *s2) return -1; } -static 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(""); - h->uflag = 1; - } - if (font_array[fnt_idx]->bold >= 0x02BC) - { - h->bflag = 1; - printf(""); - } - if (font_array[fnt_idx]->attr & 0x0002) - { - h->iflag = 1; - printf(""); - } - if (font_array[fnt_idx]->attr & 0x0008) - { - h->sflag = 1; - printf(""); - } - if ((font_array[fnt_idx]->super & 0x0003) == 0x0001) - { - h->spflag = 1; - printf(""); - } - else if ((font_array[fnt_idx]->super & 0x0003) == 0x0002) - { - h->sbflag = 1; - printf(""); - } - } -} -static void output_end_html_attr(html_attr *h) -{ - if (h->sbflag) - { - printf(""); - h->sbflag = 0; - } - else if (h->spflag) - { - printf(""); - h->spflag = 0; - } - if (h->sflag) - { - printf(""); - h->sflag = 0; - } - if (h->iflag) - { - printf(""); - h->iflag = 0; - } - if (h->bflag) - { - printf(""); - h->bflag = 0; - } - if (h->uflag) - { - if (h->uflag == 1) - printf(""); - else - printf(""); - h->uflag = 0; - } -} -static void html_flag_init(html_attr *h) +void html_flag_init(html_attr *h) { h->fflag = 0; h->bflag = 0; @@ -4439,7 +3846,7 @@ static void html_flag_init(html_attr *h) h->spflag = 0; } -static void output_start_font_attribute(html_attr *h, U16 fnt_idx) +void output_start_font_attribute(html_attr *h, U16 fnt_idx) { if (uni_string_comp(&default_font, &(font_array[fnt_idx]->name)) != 0) { @@ -4506,79 +3913,4 @@ static void output_start_font_attribute(html_attr *h, U16 fnt_idx) printf(">"); } -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 */ - } -} diff --git a/xlhtml/xlhtml.h b/xlhtml/xlhtml.h index 9d3585b..0871fb2 100644 --- a/xlhtml/xlhtml.h +++ b/xlhtml/xlhtml.h @@ -22,7 +22,7 @@ /* 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_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; /********************************** @@ -73,6 +73,7 @@ typedef struct /*!< This encapsulates some information about each worksheet */ uni_string ws_title; cell **c_array; U16 spanned; + int ws_array; }work_sheet; typedef struct /*!< This is everything we need to know about fonts */ @@ -116,9 +117,4 @@ typedef struct /*!< HTML Attribute */ int spflag; /*!< Superscript */ }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 ? */ -}; diff --git a/xlhtml/xml.c b/xlhtml/xml.c new file mode 100644 index 0000000..9994a91 --- /dev/null +++ b/xlhtml/xml.c @@ -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( "\n"); /* Latin-1 */ + break; + case 1: + printf("windows-1252\"?>\n"); /* Microsoft */ + break; + default: + printf("utf-8\"?>\n"); /* Unicode */ + break; + } + + SetupExtraction(); + + printf( "\n" ); + printf( "\t\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\n" ); + printf( "\t\t\t%d\n", i ); + + /* Print its name */ + if (next_ws_title > 0) + { + if (ws_array[i]->ws_title.str) + { + printf("\t\t\t"); + OutputString(&ws_array[i]->ws_title); + printf("\n"); + } + else + printf("\t\t\t(Unknown Page)\n"); + } + + printf( "\t\t\t%ld\n", ws_array[i]->first_row ); + printf( "\t\t\t%ld\n", ws_array[i]->biggest_row ); + printf( "\t\t\t%d\n", ws_array[i]->first_col ); + printf( "\t\t\t%d\n", ws_array[i]->biggest_col ); + printf( "\t\t\t\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\n"); + for (k=ws_array[i]->first_col; k<=ws_array[i]->biggest_col; k++) + { + printf("\t\t\t\t\t", j, k ); + output_cell(ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k], 1); /* This stuff happens for each cell... */ + printf("\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("\n"); + } + printf( "\t\t\t\n" ); + printf("\t\t\n"); + } + printf( "\t\n" ); + + /* Print the author's name in itallics... */ + if (author.str) + { + printf("\t"); + OutputString(&author); + printf("\n"); + } + + /* Print when & how the file was last updated. */ + if (lastUpdated) + printf("\t%s", lastUpdated); + printf( "\t" ); + 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("\n"); + + /* Next print Disclaimers... */ + if (NoFormat) + printf("\t%d\n", NoFormat ); + if ((notAccurate)&&(formula_warnings)) + printf("\t%d\n", notAccurate ); + if (NotImplemented) + printf("\t%d\n", NotImplemented ); + if (Unsupported) + printf("\t%d\n", Unsupported ); + + /* Now out exceeded capacity warnings... */ + if (MaxWorksheetsExceeded) + printf("\tThe Maximum Number of Worksheets were exceeded, you might want to increase it.\n "); + if (MaxRowExceeded) + printf("\tThe Maximum Number of Rows were exceeded, you might want to increase it.\n "); + if (MaxColExceeded) + printf("\tThe Maximum Number of Columns were exceeded, you might want to increase it.\n"); + if (MaxStringsExceeded) + printf("\tThe Maximum Number of Strings were exceeded, you might want to increase it.\n"); + if (MaxFontsExceeded) + printf("\tThe Maximum Number of Fonts were exceeded, you might want to increase it.\n"); + if (MaxPalExceeded) + printf("\tThe Maximum Number of Color Palettes were exceeded, you might want to increase it.\n"); + if (MaxXFExceeded) + printf("\tThe Maximum Number of Extended Formats were exceeded, you might want to increase it.\n"); + if (MaxFormatsExceeded) + printf("\tThe Maximum Number of Formats were exceeded, you might want to increase it.\n"); + + /* Output Credit */ + printf("\tCreated with xlhtml %s\n", VERSION); + printf("\thttp://chicago.sf.net/xlhtml/\n"); + printf( "\n" ); +}