diff --git a/cole/cole.c b/cole/cole.c index 72a6ba2..e4a85d3 100644 --- a/cole/cole.c +++ b/cole/cole.c @@ -1,3 +1,5 @@ + + /* cole - A free C OLE library. Copyright 1998, 1999 Roberto Arturo Tena Sanchez @@ -20,8 +22,12 @@ Arturo Tena */ +#if !(defined( __BORLANDC__ ) || defined( __WIN32__ )) #include "config.h" #include "cole.h" +#else +#include "cole.h.in" +#endif #include "internal.h" #include @@ -189,7 +195,7 @@ cole_umount (COLEFS *colefilesystem, COLERRNO *colerrno) if (colerrno != NULL) *colerrno = COLE_ECLOSEFILE; ret = 1; } -#if defined(WIN32) +#if defined(__WIN32__) || (__BORLANDC__) if (remove (colefilesystem->sbfilename) && !ret) { if (colerrno != NULL) *colerrno = COLE_EREMOVE; ret = 1; @@ -243,9 +249,6 @@ __cole_print_tree_indir(COLEDIR *cd, void *info, COLERRNO *colerrno) * Modify colerrno comment in the functions that call it, * ie. cole_print_tree(). */ - (void) cd; /*UNUSED*/ - (void) colerrno; /*UNUSED*/ - (*((long*)info))++; return 0; } @@ -258,9 +261,6 @@ __cole_print_tree_outdir(COLEDIR *cd, void *info, COLERRNO *colerrno) * Modify colerrno comment in the functions that call it, * ie. cole_print_tree(). */ - (void) cd; /*UNUSED*/ - (void) colerrno; /*UNUSED*/ - (*((long*)info))--; return 0; } @@ -275,9 +275,6 @@ __cole_print_tree_inroot(COLEDIR *cd, void *info, COLERRNO *colerrno) */ char *entry_name; - (void) info; /*UNUSED*/ - (void) colerrno; /*UNUSED*/ - printf ("DIR "); printf (" %7zu", cole_dir_getsize (cd)); printf (" %08lx-%08lx %08lx-%08lx", @@ -306,8 +303,6 @@ __cole_print_tree_indirentry(COLEDIRENT *cde, void *info, COLERRNO *colerrno) long level; long i; - (void) colerrno; /*UNUSED*/ - level = *((long*)info); for (i = 0; i < level; i++) { if (i == level - 1) @@ -412,8 +407,6 @@ cole_opendir_direntry (COLEDIRENT *coledirentry, COLERRNO *colerrno) int cole_closedir (COLEDIR *coledir, COLERRNO *colerrno) { - (void) colerrno; /*UNUSED*/ - free (coledir); return 0; @@ -601,7 +594,7 @@ cole_fopen (COLEFS *colefilesystem, char *filename, COLERRNO *colerrno) _cole_fopen_action, colerrno)) { /* couldn't locate the filename */ /* colerrno is set */ - return NULL; + return NULL; } if (info.succ) @@ -624,13 +617,15 @@ _cole_fopen_action (COLEDIRENT *cde, void *_info) return; } + + info->file = cole_fopen_direntry (cde, &info->colerrno); + if (info->file == NULL) { /* colerrno is set */ info->succ = 0; return; } - info->succ = 1; } @@ -838,39 +833,46 @@ cole_fseek (COLEFILE *colefile, size_t delta, COLE_SEEK_FLAG direction, case COLE_SEEK_SET: if (delta <= colefile->filesize) { colefile->pos = delta; - return 0; + } else { if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA; return 1; } + break; case COLE_SEEK_END: if (delta <= colefile->filesize) { colefile->pos = colefile->filesize - delta; - return 0; + } else { if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA; return 1; } + break; case COLE_SEEK_BACKWARD: if (delta <= colefile->pos) { colefile->pos = colefile->pos - delta; - return 0; + } else { if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA; return 1; } + break; case COLE_SEEK_FORWARD: if (delta <= colefile->filesize - colefile->pos) { colefile->pos = colefile->pos + delta; - return 0; + } else { if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA; return 1; } + + break; default: if (colerrno != NULL) *colerrno = COLE_EFSEEKFLAG; return 1; } + + fseek(colefile->file,colefile->pos,SEEK_SET); } @@ -1117,8 +1119,8 @@ cole_locate_filename (COLEFS *colefilesystem, char *filename, /* FIXME allow no absolute paths */ if (filename[0] != '/') { - if (colerrno != NULL) *colerrno = COLE_EBROKENFILENAME; - return 1; + if (colerrno != NULL) *colerrno = COLE_EBROKENFILENAME; + return 1; } _info.action = action; @@ -1145,8 +1147,6 @@ cole_locate_filename (COLEFS *colefilesystem, char *filename, static int __cole_locate_filename_visitdir (COLEDIR *cd, void *info) { - (void) cd; /*UNUSED*/ - return ((struct __cole_locate_filenameinfo *)info)->visitdir; } diff --git a/config.h.in b/config.h.in index 8b62303..ad5f29d 100644 --- a/config.h.in +++ b/config.h.in @@ -1,4 +1,4 @@ -/* config.h.in. Generated automatically from configure.in by autoheader. */ +/* config.h.in. Generated automatically from configure.in by autoheader 2.13. */ /* Define to empty if the keyword does not work. */ #undef const diff --git a/ppthtml/Makefile.am b/ppthtml/Makefile.am index 9be3fa7..d6e8544 100644 --- a/ppthtml/Makefile.am +++ b/ppthtml/Makefile.am @@ -7,7 +7,7 @@ INCLUDES = -I../cole noinst_PROGRAMS = pptdump man_MANS = ppthtml.1 bin_SCRIPTS = nspptview -bin_PROGRAMS = ppthtml +bin_PROGRAMS = ppthtml LDADD = ../cole/libcole.a -ppthtml_SOURCES = ppthtml.c +ppthtml_SOURCES = ppthtml.c vector.c #AM_CFLAGS = -Wall -Wshadow -Wcast-align -Wpointer-arith diff --git a/ppthtml/Makefile.in b/ppthtml/Makefile.in index a8c3aba..b15fe97 100644 --- a/ppthtml/Makefile.in +++ b/ppthtml/Makefile.in @@ -81,9 +81,9 @@ INCLUDES = -I../cole noinst_PROGRAMS = pptdump man_MANS = ppthtml.1 bin_SCRIPTS = nspptview -bin_PROGRAMS = ppthtml +bin_PROGRAMS = ppthtml LDADD = ../cole/libcole.a -ppthtml_SOURCES = ppthtml.c +ppthtml_SOURCES = ppthtml.c vector.c mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../config.h CONFIG_CLEAN_FILES = @@ -94,7 +94,7 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I.. CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -ppthtml_OBJECTS = ppthtml.o +ppthtml_OBJECTS = ppthtml.o vector.o ppthtml_LDADD = $(LDADD) ppthtml_DEPENDENCIES = ../cole/libcole.a ppthtml_LDFLAGS = diff --git a/ppthtml/ppthtml.c b/ppthtml/ppthtml.c index 611f9af..e3163d2 100644 --- a/ppthtml/ppthtml.c +++ b/ppthtml/ppthtml.c @@ -17,23 +17,37 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* The code used to extract title, author, subject and keywords was based + on original code from libcole2 written by + + Michael Meeks (michael@helixcode.com) + Arturo Tena (arturo@directmail.org) +*/ + +#if !(defined( __BORLANDC__ ) || defined( __WIN32__ )) #include "config.h" /* Created by ./configure script */ #include "support.h" /* Needs to be before internal.h */ #include "internal.h" /* Needs to be before cole */ #include "cole.h" -#if defined(WIN32) -#include /* _chdrive() */ +#else +#include "config.h.in" /* Created by ./configure script */ +#include "support.h" /* Needs to be before internal.h */ +#include "internal.h" /* Needs to be before cole */ +#include "cole.h.in" +#include #endif - +#include "vector.h" #include -#include /* for strcpy() */ +#include /* For strcpy() */ #include /* For isprint */ -#include /* For exitt() */ +#include /* For exitt() */ +#include /* For MAX_PATH */ +#include "ppthtml.h" /* For SummaryInfo things*/ #define PRGNAME "pptHtml" -#if defined(VERSION) +#if !(defined( __WIN32__ ) || defined( __BORLANDC__ )) #define PRGVER VERSION #else #define PRGVER "0.4" @@ -45,6 +59,8 @@ static char FileName[2][32] = /* The section of the PowerPoint File we read */ "/PP40" /* Everything else ? */ }; +#define BUFFER_SIZE 128 + /* Function Prototypes */ COLE_LOCATE_ACTION_FUNC dump_file; @@ -53,6 +69,10 @@ static void atom_processor(int, int, int, unsigned char); static void print_unicode(unsigned char *, int); static void print_utf8(unsigned short c); static void put_utf8(unsigned short c); +static OleSummary *summary_open_stream(COLEFILE *cf, const PropertySetID psid); +static void close_summary(OleSummary *si); +static gboolean read_items(OleSummary *si, PropertySetID ps_id); +static char *summary_get_string (OleSummary *si,OleSummaryPID id,gboolean *available); /* Global data */ static char filename[128]; @@ -61,356 +81,628 @@ static int buf_idx=0; static int output_this_container = 0; static int past_first_slide = 0; static int last_container = 0; +static char *title; +static char *author; +static char *subject; +static char *keywords; int main (int argc, char **argv) { - int f_ptr = 0; - COLEFS * cfs; - COLERRNO colerrno; + int f_ptr = 0; + COLEFS * cfs; + COLEFILE * cf; + COLERRNO colerrno; + char buffer[BUFFER_SIZE]; + size_t char_read; + size_t char_read_total; - if (argc < 2) - { - fprintf (stderr, "pptHtml - Outputs Power Point files as Html.\n" - "Usage: "PRGNAME" \n"); - exit (1); - } - else - { - strncpy(filename, argv[1], 124); -#if 1 && defined(WIN32) - if( 0 != filename[0] && ':' == filename[1] ) - { - _chdrive(tolower((unsigned char)filename[0]) - 'a' + 1); - /* cut the drive from the filename */ - memmove(filename,filename+2,strlen(filename+2)+1); - } -#endif - cfs = cole_mount (filename, &colerrno); - if (cfs == NULL) - { - cole_perror (PRGNAME, colerrno); - exit (1); - } - } + gboolean ok; + OleSummary *si; + + if (argc < 2) + { + fprintf (stderr, "pptHtml - Outputs Power Point files as Html.\n" + "Usage: "PRGNAME" \n"); + exit (1); + } + else + { + strncpy(filename, argv[1], 124); + cfs = cole_mount (filename, &colerrno); + if (cfs == NULL) + { + cole_perror (PRGNAME, colerrno); + exit (1); + } + } - while (cole_locate_filename (cfs, FileName[f_ptr], NULL, dump_file, &colerrno)) - { - if (f_ptr) - { /* Two strikes...we're out! */ - cole_perror (PRGNAME, colerrno); - if (colerrno == COLE_EFILENOTFOUND) - fprintf(stderr, "Section: PowerPoint Document\n"); - break; - } - else /* Don't do this... */ - f_ptr++; - } - if (cole_umount (cfs, &colerrno)) - { - cole_perror ("travel", colerrno); - exit (1); - } + + + cf = cole_fopen (cfs, "/\005SummaryInformation", &colerrno); + + if (!cf) { + printf("ERROR-No Summary Information available for this document\n"); + cole_umount (cfs, NULL); + exit (1); + } - return 0; + si = summary_open_stream(cf, OLE_PS_SUMMARY_INFO); + if (!si) { + printf ("Could not open SummaryInformation\n"); + exit(1); + } + + title = summary_get_string(si, OLE_SUMMARY_TITLE, &ok); + /* if (ok) */ + /* printf ("The title is %s\n", title); */ + /* else */ + /* printf ("no title found\n"); */ + + subject = summary_get_string (si, OLE_SUMMARY_SUBJECT, &ok); + /* if (ok) */ + /* printf ("The subject is %s\n", subject); */ + /* else */ + /* printf ("no subject found\n"); */ + + + author =summary_get_string (si, OLE_SUMMARY_AUTHOR, &ok); + /* if (ok) */ + /* printf ("The author is %s\n", author); */ + /* else */ + /* printf ("no author found\n"); */ + + + keywords = summary_get_string (si, OLE_SUMMARY_KEYWORDS, &ok); + /* if (ok) */ + /* printf ("The keywords are %s\n", keywords); */ + /* else */ + /* printf ("no keywords found\n"); */ + + cole_fclose (cf, &colerrno); + + + while (cole_locate_filename (cfs, FileName[f_ptr], NULL, dump_file, &colerrno)) + { + if (f_ptr) + { /* Two strikes...we're out! */ + cole_perror (PRGNAME, colerrno); + if (colerrno == COLE_EFILENOTFOUND) + fprintf(stderr, "Section: PowerPoint Document\n"); + break; + } + else /* Don't do this... */ + f_ptr++; + } + + free (title); + free (subject); + free (author); + free (keywords); + + if (cole_umount (cfs, &colerrno)) + { + cole_perror ("travel", colerrno); + exit (1); + } + + return 0; } - void dump_file(COLEDIRENT *cde, void *_info) { - unsigned long version=0, instance=0, type=0, length=0, target=0, count=0; - unsigned char buf[16]; - COLEFILE *cf; - COLERRNO err; - - (void) _info; /*UNUSED*/ - - cf = cole_fopen_direntry(cde, &err); - -/* Ouput Header */ - printf("\n"); - printf("%s", filename); - printf("\n"); - -/* Output body */ - while (cole_fread(cf, buf, 1, &err)) + + unsigned long version=0, instance=0, type=0, length=0, target=0, count=0; + unsigned char buf[16]; + COLEFILE *cf; + COLERRNO err; + + cf = cole_fopen_direntry(cde, &err); + /* Ouput Header */ + printf("\n"); + printf("%s\n", title); + if(subject) + printf("\n", subject); + if(author) + printf("\n", author); + if(keywords) + printf("\n", keywords); + printf("\n"); + + /* Output body */ + while (cole_fread(cf, buf, 1, &err)) { - if (count == 0) - { - instance = buf[0]; - type = 0; - length = 0; - target = 80; /* ficticious number */ - } - else if (count == 1) - { - instance |= (buf[0]<<8); - version = instance &0x000F; - instance = (instance>>4); - } - else if (count == 2) - type = (unsigned)buf[0]; - else if (count == 3) - type |= (buf[0]<<8)&0x00000FFFL; - else if (count == 4) - length = (unsigned)buf[0]; - else if (count == 5) - length |= (buf[0]<<8); - else if (count == 6) - length |= (buf[0]<<16); - else if (count == 7) - { - length |= (buf[0]<<24); - target = length; - if (version == 0x0F) - { /* Do container level Processing */ - container_processor(type); - count = -1; + if (count == 0) + { + instance = buf[0]; + type = 0; + length = 0; + target = 80; /* ficticious number */ + } + else if (count == 1) + { + instance |= (buf[0]<<8); + version = instance &0x000F; + instance = (instance>>4); + } + else if (count == 2) + type = (unsigned)buf[0]; + else if (count == 3) + type |= (buf[0]<<8)&0x00000FFFL; + else if (count == 4) + length = (unsigned)buf[0]; + else if (count == 5) + length |= (buf[0]<<8); + else if (count == 6) + length |= (buf[0]<<16); + else if (count == 7) + { + length |= (buf[0]<<24); + target = length; + if (version == 0x0F) + { /* Do container level Processing */ + container_processor(type); + count = -1; } - } - if (count > 7) - { /* Here is where we want to process the data - based on the Atom type... */ - atom_processor(type, count-8, target-1, buf[0]); - } - if (count == (target+7)) + } + if (count > 7) + { /* Here is where we want to process the data + based on the Atom type... */ + atom_processor(type, count-8, target-1, buf[0]); + } + if (count == (target+7)) count = 0; - else - count++; + else + count++; } - - if (past_first_slide) - printf("
"); - - printf(" 
\n"); - - /* Output Credit */ - printf("
Created with pptHtml
\n" ); - - /* Output Tail */ - printf("\n"); - cole_fclose(cf, &err); + + if (past_first_slide) + printf("
"); + + printf(" 
\n"); + + /* Output Credit */ + printf("
Created with pptHtml
\n" ); + + /* Output Tail */ + printf("\n"); + cole_fclose(cf, &err); } static void container_processor(int type) { - if (type == 0x03EE) - { - if (past_first_slide) - printf("


\n"); - else - past_first_slide = 1; - } - switch (type) - { - case 0x000D: - if (last_container == 0x11) /* suppress notes info */ - output_this_container = 0; - else - output_this_container = 1; - break; - case 0x0FF0: - output_this_container = 1; - break; - default: -/* printf("Cont:%x|\n", type); */ - output_this_container = 0; - break; - } - last_container = type; + if (type == 0x03EE) + { + if (past_first_slide) + printf("


\n"); + else + past_first_slide = 1; + } + switch (type) + { + case 0x000D: + if (last_container == 0x11) /* suppress notes info */ + output_this_container = 0; + else + output_this_container = 1; + break; + case 0x0FF0: + output_this_container = 1; + break; + default: + /* printf("Cont:%x|\n", type); */ + output_this_container = 0; + break; + } + last_container = type; } static void atom_processor(int type, int count, int buf_last, unsigned char data) { - if ((buf_idx >= WORK_SIZE)||(output_this_container == 0)) - return; - - if (count == 0) - { - memset(working_buffer, 0, WORK_SIZE); - buf_idx = 0; - } - - switch (type) - { - case 0x0FA0: /* Text String in unicode */ - working_buffer[buf_idx++] = data; - if (count == buf_last) - { -/* printf("Atom:%x|\n", type); */ -/* working_buffer[buf_idx++] = 0; */ -/* printf("%s
\n", working_buffer); */ - print_unicode(working_buffer, buf_idx); - printf("
\n"); - } - break; - case 0x0FA8: /* Text String in ASCII */ - working_buffer[buf_idx++] = data; - if (count == buf_last) - { - int i; -/* working_buffer[buf_idx++] = 0; */ -/* printf("Atom:%x|\n", type); */ - for (i=0;i\n"); - else - putchar(working_buffer[i]); - } - printf("
\n"); - } - break; - case 0x0FBA: /* CString - unicode... */ - working_buffer[buf_idx++] = data; - if (count == buf_last) - { -/* working_buffer[buf_idx++] = 0; */ -/* printf("%s
\n", working_buffer); */ -/* printf("Atom:%x|\n", type); */ - print_unicode(working_buffer, buf_idx); - printf("
\n"); - } - break; - default: - break; - } + if ((buf_idx >= WORK_SIZE)||(output_this_container == 0)) + return; + + if (count == 0) + { + memset(working_buffer, 0, WORK_SIZE); + buf_idx = 0; + } + + switch (type) + { + case 0x0FA0: /* Text String in unicode */ + working_buffer[buf_idx++] = data; + if (count == buf_last) + { + /* printf("Atom:%x|\n", type); */ + /* working_buffer[buf_idx++] = 0; */ + /* printf("%s
\n", working_buffer); */ + print_unicode(working_buffer, buf_idx); + printf("
\n"); + } + break; + case 0x0FA8: /* Text String in ASCII */ + working_buffer[buf_idx++] = data; + if (count == buf_last) + { + int i; + /* working_buffer[buf_idx++] = 0; */ + /* printf("Atom:%x|\n", type); */ + for (i=0;i\n"); + else + putchar(working_buffer[i]); + } + printf("
\n"); + } + break; + case 0x0FBA: /* CString - unicode... */ + working_buffer[buf_idx++] = data; + if (count == buf_last) + { + /* working_buffer[buf_idx++] = 0; */ + /* printf("%s
\n", working_buffer); */ + /* printf("Atom:%x|\n", type); */ + print_unicode(working_buffer, buf_idx); + printf("
\n"); + } + break; + default: + break; + } } static void print_unicode(unsigned char *ucs, int len) { - int i; - for (i = 0; i < len; i += 2) - print_utf8(ucs[i] | (ucs[i+1] << 8)); + int i; + for (i = 0; i < len; i += 2) + print_utf8(ucs[i] | (ucs[i+1] << 8)); } static void OutputCharCorrected(unsigned char c) { - switch (c) - { /* Special char handlers here... */ - case '\r': - printf("
\n"); - break; - case 0x3C: - printf("<"); - break; - case 0x3E: - printf(">"); - break; - case 0x26: - printf("&"); - break; - case 0x22: - printf("""); - break; - /* Also need to cover 128-159 since MS uses this area... */ - case 0x80: /* Euro Symbol */ - printf("€"); - break; - case 0x82: /* baseline single quote */ - printf("‚"); - break; - case 0x83: /* florin */ - printf("ƒ"); - break; - case 0x84: /* baseline double quote */ - printf("„"); - break; - case 0x85: /* ellipsis */ - printf("…"); - break; - case 0x86: /* dagger */ - printf("†"); - break; - case 0x87: /* double dagger */ - printf("‡"); - break; - case 0x88: /* circumflex accent */ - printf("ˆ"); - break; - case 0x89: /* permile */ - printf("‰"); - break; - case 0x8A: /* S Hacek */ - printf("Š"); - break; - case 0x8B: /* left single guillemet */ - printf("‹"); - break; - case 0x8C: /* OE ligature */ - printf("Œ"); - break; - case 0x8E: /* #LATIN CAPITAL LETTER Z WITH CARON */ - printf("Ž"); - break; - case 0x91: /* left single quote ? */ - printf("‘"); - break; - case 0x92: /* right single quote ? */ - printf("’"); - break; - case 0x93: /* left double quote */ - printf("“"); - break; - case 0x94: /* right double quote */ - printf("”"); - break; - case 0x95: /* bullet */ - printf("•"); - break; - case 0x96: /* endash */ - printf("–"); - break; - case 0x97: /* emdash */ - printf("—"); - break; - case 0x98: /* tilde accent */ - printf("˜"); - break; - case 0x99: /* trademark ligature */ - printf("™"); - break; - case 0x9A: /* s Haceks Hacek */ - printf("š"); - break; - case 0x9B: /* right single guillemet */ - printf("›"); - break; - case 0x9C: /* oe ligature */ - printf("œ"); - break; - case 0x9F: /* Y Dieresis */ - printf("Ÿ"); - break; - default: - putchar(c); - break; - } + switch (c) + { /* Special char handlers here... */ + case '\r': + printf("
\n"); + break; + case 0x3C: + printf("<"); + break; + case 0x3E: + printf(">"); + break; + case 0x26: + printf("&"); + break; + case 0x22: + printf("""); + break; + /* Also need to cover 128-159 since MS uses this area... */ + case 0x80: /* Euro Symbol */ + printf("€"); + break; + case 0x82: /* baseline single quote */ + printf("‚"); + break; + case 0x83: /* florin */ + printf("ƒ"); + break; + case 0x84: /* baseline double quote */ + printf("„"); + break; + case 0x85: /* ellipsis */ + printf("…"); + break; + case 0x86: /* dagger */ + printf("†"); + break; + case 0x87: /* double dagger */ + printf("‡"); + break; + case 0x88: /* circumflex accent */ + printf("ˆ"); + break; + case 0x89: /* permile */ + printf("‰"); + break; + case 0x8A: /* S Hacek */ + printf("Š"); + break; + case 0x8B: /* left single guillemet */ + printf("‹"); + break; + case 0x8C: /* OE ligature */ + printf("Œ"); + break; + case 0x8E: /* #LATIN CAPITAL LETTER Z WITH CARON */ + printf("Ž"); + break; + case 0x91: /* left single quote ? */ + printf("‘"); + break; + case 0x92: /* right single quote ? */ + printf("’"); + break; + case 0x93: /* left double quote */ + printf("“"); + break; + case 0x94: /* right double quote */ + printf("”"); + break; + case 0x95: /* bullet */ + printf("•"); + break; + case 0x96: /* endash */ + printf("–"); + break; + case 0x97: /* emdash */ + printf("—"); + break; + case 0x98: /* tilde accent */ + printf("˜"); + break; + case 0x99: /* trademark ligature */ + printf("™"); + break; + case 0x9A: /* s Haceks Hacek */ + printf("š"); + break; + case 0x9B: /* right single guillemet */ + printf("›"); + break; + case 0x9C: /* oe ligature */ + printf("œ"); + break; + case 0x9F: /* Y Dieresis */ + printf("Ÿ"); + break; + default: + putchar(c); + break; + } } static void print_utf8(unsigned short c) { - if (c == 0) - return; - - if (c < 0x80) - OutputCharCorrected(c); - else if (c < 0x800) - { - putchar(0xC0 | (c >> 6)); - put_utf8(c); - } - else - { - putchar(0xE0 | (c >> 12)); - put_utf8(c >> 6); - put_utf8(c); - } + if (c == 0) + return; + + if (c < 0x80) + OutputCharCorrected(c); + else if (c < 0x800) + { + putchar(0xC0 | (c >> 6)); + put_utf8(c); + } + else + { + putchar(0xE0 | (c >> 12)); + put_utf8(c >> 6); + put_utf8(c); + } } static void put_utf8(unsigned short c) { - putchar(0x0080 | ((short)c & 0x003F)); + putchar(0x0080 | ((short)c & 0x003F)); } +OleSummary * +summary_open_stream (COLEFILE *cf, const PropertySetID psid) +{ + uint8_t data[64]; + uint16_t byte_order; + gboolean panic=FALSE; + uint32_t os_version; + OleSummary *si; + int i, sections; + COLERRNO colerrno; + + if (cf == NULL){ + printf("No cole file info available\n"); + return NULL; + } + + /* reading data */ + cole_fread (cf, data, 28, &colerrno); + + si = malloc(sizeof(OleSummary)); + si->sections = malloc(sizeof(ole_vector)); + si->items = malloc(sizeof(item_vector)); + + si->s = cf; + si->write_items = NULL; + si->read_mode = TRUE; + + byte_order = GET_UINT16(data); + if (byte_order != 0xfffe) + panic = TRUE; + + if (GET_UINT16 (data + 2) != 0) /* Format */ + panic = TRUE; + + os_version = GET_UINT32 (data + 4); + + for (i = 0; i < 16; i++) + si->class_id[i] = data[8 + i]; + + sections = GET_UINT32 (data + 24); + + if (panic) { + close_summary(si); + return NULL; + } + + create_ole_vector(si->sections); + + for (i = 0; i < sections; i++) { + OleSummarySection sect; + if (!cole_fread (cf, data, 16 + 4, &colerrno)){ + close_summary(si); + return NULL; + } + + if (psid == OLE_PS_SUMMARY_INFO) { + if (GET_UINT32 (data + 0) == sum_fmtid[0] && + GET_UINT32 (data + 4) == sum_fmtid[1] && + GET_UINT32 (data + 8) == sum_fmtid[2] && + GET_UINT32 (data + 12) == sum_fmtid[3]) { + si->ps_id = OLE_PS_SUMMARY_INFO; + sect.ps_id = OLE_PS_SUMMARY_INFO; + + } else { + close_summary(si); + return NULL; + } + + } + sect.offset = GET_UINT32 (data + 16); + append_ole(si->sections,sect); + } + + create_item_vector(si->items); + + for (i = 0; i < sections; i++) { + OleSummarySection st; + + st = ole_at(si->sections,i); + if (!read_items(si, st.ps_id)) { + printf("Serious error reading items\n"); + close_summary(si); + return NULL; + } + } + return si; +} + +void +close_summary(OleSummary *si) +{ + + if(si->sections) + free(si->sections); + destroy_ole_vector(si->sections); + si->sections = NULL; + + if(si->items) + free(si->items); + destroy_item_vector(si->items); + si->items=NULL; + + free(si); + +} + +gboolean +read_items (OleSummary *si, PropertySetID ps_id) +{ + int sect; + COLERRNO colerrno; + + for (sect = 0; sect < si->sections->index; sect++) { + OleSummarySection st; + uint8_t data[8]; + int i; + + st = ole_at(si->sections,sect); + + if (st.ps_id != ps_id) + continue; + + cole_fseek(si->s, st.offset, COLE_SEEK_SET, &colerrno); + if (!cole_fread (si->s, data, 8, &colerrno)) + return FALSE; + + st.bytes = GET_UINT32 (data); + st.props = GET_UINT32 (data + 4); + + if (st.props == 0) + continue; + + for (i = 0; i < st.props; i++) { + item_t item; + if (!cole_fread (si->s, data, 8, &colerrno)) + return FALSE; + + item.id = GET_UINT32 (data); + item.offset = GET_UINT32 (data + 4); + item.offset = item.offset + st.offset; + item.ps_id = ps_id; + append_item(si->items, item); + } + } + return TRUE; + +} + + + +/* Seeks to the correct place, and returns a handle or NULL on failure */ +static item_t * +seek_to_record (OleSummary *si, OleSummaryPID id) +{ + int i; + COLERRNO colerrno; + + for (i = 0; i < si->items->index; i++) { + item_t *item = &item_at(si->items,i); + if (item->id == SUMMARY_ID(id)) { + gboolean is_summary; + + is_summary = ((si->ps_id == OLE_PS_SUMMARY_INFO) && + (item->ps_id == OLE_PS_SUMMARY_INFO)); + + if (is_summary) { + cole_fseek(si->s, item->offset, COLE_SEEK_SET, &colerrno); + return item; + } + } + } + return NULL; +} + +char * +summary_get_string (OleSummary *si, OleSummaryPID id, gboolean *available) +{ + uint8_t data[8]; + uint32_t type, len; + char *ans; + item_t *item; + COLERRNO colerrno; + + *available = FALSE; + + if (!(item = seek_to_record (si, id))) + return NULL; + + if (!cole_fread(si->s, data, 8, &colerrno)) + return NULL; + + type = GET_UINT32 (data); + len = GET_UINT32 (data + 4); + + if (type != TYPE_STRING) { + printf("Summary string type mismatch\n"); + return NULL; + } + + ans = allocate_mem(char, len + 1); + + if (!cole_fread(si->s, ans, len,&colerrno)) { + free (ans); + return NULL; + } + + ans[len] = '\0'; + + *available = TRUE; + + return ans; +} + + + diff --git a/xlhtml/html.c b/xlhtml/html.c index 0510986..b13b8b8 100644 --- a/xlhtml/html.c +++ b/xlhtml/html.c @@ -83,6 +83,27 @@ void OutputTableHTML(void) do_cr(); printf(""); do_cr(); + if (TableHeaders) + { + printf(""); + for (k=ws_array[i]->first_col; k<=ws_array[i]->biggest_col; k++) + { + char col_hdr[3]; + if (k < 26) + { + col_hdr[0]='A' + (k % 26); + col_hdr[1]='\0'; + } + else + { + col_hdr[0]='A' - 1 + (k / 26); + col_hdr[1]='A' + (k % 26); + col_hdr[2]='\0'; + } + printf("")); + } + printf("\n"); + } for (j=ws_array[i]->first_row; j<=ws_array[i]->biggest_row; j++) { update_default_alignment(i, j); @@ -98,6 +119,8 @@ void OutputTableHTML(void) else printf(">"); } + if (TableHeaders) + 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... */ diff --git a/xlhtml/support.c b/xlhtml/support.c index 45565f5..9b377ab 100644 --- a/xlhtml/support.c +++ b/xlhtml/support.c @@ -89,6 +89,20 @@ S32 getLong(U8 *ptr) } #ifndef WORDS_BIGENDIAN /* Defined in */ +#ifdef __arm__ +/* cross-endian doubles in little endian ARM */ +void getDouble(U8 *ptr, F64 *d) +{ + size_t i; + F64 dd; + U8 *t = (U8 *)ⅆ + + for (i=0; isw) #ifndef WORDS_BIGENDIAN /*! Defined in */ +#ifdef __arm__ +/* cross-endian doubles in little endian ARM */ +void RKtoDouble(S32 n, F64 *d) +{ + noaliasdub(swords,d)[0] = n << 2; + noaliasdub(swords,d)[1] = 0; +} +#else /*! Little Endian - 0x86 family */ void RKtoDouble(S32 n, F64 *d) { noaliasdub(swords,d)[0] = 0; noaliasdub(swords,d)[1] = n << 2; } +#endif #else /*! Big Endian version - UltraSparc's, etc. */ void RKtoDouble(S32 n, F64 *d) diff --git a/xlhtml/xlhtml.c b/xlhtml/xlhtml.c index 2342a47..5d0b51f 100644 --- a/xlhtml/xlhtml.c +++ b/xlhtml/xlhtml.c @@ -211,6 +211,7 @@ 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; /*!< Don't output html header */ +int TableHeaders = 0; /*!< Output row/column headers */ /* Some Global Flags */ @@ -299,6 +300,8 @@ int main (int argc, char **argv) print_version(); else if(strcmp(argv[i], "-nh") == 0 ) NoHeaders = 1; + else if(strcmp(argv[i], "-th") == 0 ) + TableHeaders = 1; else if (strncmp(argv[i], "-xc:", 4) == 0) { int d1, d2; diff --git a/xlhtml/xlhtml.h b/xlhtml/xlhtml.h index 5965b34..43f612b 100644 --- a/xlhtml/xlhtml.h +++ b/xlhtml/xlhtml.h @@ -152,6 +152,7 @@ extern char *default_image; extern int aggressive; extern int center_tables; extern int NoHeaders; +extern int TableHeaders; extern int formula_warnings; extern int Csv; extern xf_attr **xf_array;
%s%s",col_hdr,(aggressive ? "" : "
%d%s",j+1,(aggressive ? "" : "