Added patches that were uploaded to Chicago patch area.

This commit is contained in:
slidedraw 2002-10-11 01:40:57 +00:00
parent 358e24c07b
commit 4f2cdde40b
9 changed files with 691 additions and 348 deletions

View File

@ -1,3 +1,5 @@
/* /*
cole - A free C OLE library. cole - A free C OLE library.
Copyright 1998, 1999 Roberto Arturo Tena Sanchez Copyright 1998, 1999 Roberto Arturo Tena Sanchez
@ -20,8 +22,12 @@
Arturo Tena <arturo@directmail.org> Arturo Tena <arturo@directmail.org>
*/ */
#if !(defined( __BORLANDC__ ) || defined( __WIN32__ ))
#include "config.h" #include "config.h"
#include "cole.h" #include "cole.h"
#else
#include "cole.h.in"
#endif
#include "internal.h" #include "internal.h"
#include <stdlib.h> #include <stdlib.h>
@ -189,7 +195,7 @@ cole_umount (COLEFS *colefilesystem, COLERRNO *colerrno)
if (colerrno != NULL) *colerrno = COLE_ECLOSEFILE; if (colerrno != NULL) *colerrno = COLE_ECLOSEFILE;
ret = 1; ret = 1;
} }
#if defined(WIN32) #if defined(__WIN32__) || (__BORLANDC__)
if (remove (colefilesystem->sbfilename) && !ret) { if (remove (colefilesystem->sbfilename) && !ret) {
if (colerrno != NULL) *colerrno = COLE_EREMOVE; if (colerrno != NULL) *colerrno = COLE_EREMOVE;
ret = 1; 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, * Modify colerrno comment in the functions that call it,
* ie. cole_print_tree(). * ie. cole_print_tree().
*/ */
(void) cd; /*UNUSED*/
(void) colerrno; /*UNUSED*/
(*((long*)info))++; (*((long*)info))++;
return 0; 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, * Modify colerrno comment in the functions that call it,
* ie. cole_print_tree(). * ie. cole_print_tree().
*/ */
(void) cd; /*UNUSED*/
(void) colerrno; /*UNUSED*/
(*((long*)info))--; (*((long*)info))--;
return 0; return 0;
} }
@ -275,9 +275,6 @@ __cole_print_tree_inroot(COLEDIR *cd, void *info, COLERRNO *colerrno)
*/ */
char *entry_name; char *entry_name;
(void) info; /*UNUSED*/
(void) colerrno; /*UNUSED*/
printf ("DIR "); printf ("DIR ");
printf (" %7zu", cole_dir_getsize (cd)); printf (" %7zu", cole_dir_getsize (cd));
printf (" %08lx-%08lx %08lx-%08lx", printf (" %08lx-%08lx %08lx-%08lx",
@ -306,8 +303,6 @@ __cole_print_tree_indirentry(COLEDIRENT *cde, void *info, COLERRNO *colerrno)
long level; long level;
long i; long i;
(void) colerrno; /*UNUSED*/
level = *((long*)info); level = *((long*)info);
for (i = 0; i < level; i++) { for (i = 0; i < level; i++) {
if (i == level - 1) if (i == level - 1)
@ -412,8 +407,6 @@ cole_opendir_direntry (COLEDIRENT *coledirentry, COLERRNO *colerrno)
int int
cole_closedir (COLEDIR *coledir, COLERRNO *colerrno) cole_closedir (COLEDIR *coledir, COLERRNO *colerrno)
{ {
(void) colerrno; /*UNUSED*/
free (coledir); free (coledir);
return 0; return 0;
@ -601,7 +594,7 @@ cole_fopen (COLEFS *colefilesystem, char *filename, COLERRNO *colerrno)
_cole_fopen_action, colerrno)) { _cole_fopen_action, colerrno)) {
/* couldn't locate the filename */ /* couldn't locate the filename */
/* colerrno is set */ /* colerrno is set */
return NULL; return NULL;
} }
if (info.succ) if (info.succ)
@ -624,13 +617,15 @@ _cole_fopen_action (COLEDIRENT *cde, void *_info)
return; return;
} }
info->file = cole_fopen_direntry (cde, &info->colerrno); info->file = cole_fopen_direntry (cde, &info->colerrno);
if (info->file == NULL) { if (info->file == NULL) {
/* colerrno is set */ /* colerrno is set */
info->succ = 0; info->succ = 0;
return; return;
} }
info->succ = 1; info->succ = 1;
} }
@ -838,39 +833,46 @@ cole_fseek (COLEFILE *colefile, size_t delta, COLE_SEEK_FLAG direction,
case COLE_SEEK_SET: case COLE_SEEK_SET:
if (delta <= colefile->filesize) { if (delta <= colefile->filesize) {
colefile->pos = delta; colefile->pos = delta;
return 0;
} else { } else {
if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA; if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA;
return 1; return 1;
} }
break;
case COLE_SEEK_END: case COLE_SEEK_END:
if (delta <= colefile->filesize) { if (delta <= colefile->filesize) {
colefile->pos = colefile->filesize - delta; colefile->pos = colefile->filesize - delta;
return 0;
} else { } else {
if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA; if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA;
return 1; return 1;
} }
break;
case COLE_SEEK_BACKWARD: case COLE_SEEK_BACKWARD:
if (delta <= colefile->pos) { if (delta <= colefile->pos) {
colefile->pos = colefile->pos - delta; colefile->pos = colefile->pos - delta;
return 0;
} else { } else {
if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA; if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA;
return 1; return 1;
} }
break;
case COLE_SEEK_FORWARD: case COLE_SEEK_FORWARD:
if (delta <= colefile->filesize - colefile->pos) { if (delta <= colefile->filesize - colefile->pos) {
colefile->pos = colefile->pos + delta; colefile->pos = colefile->pos + delta;
return 0;
} else { } else {
if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA; if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA;
return 1; return 1;
} }
break;
default: default:
if (colerrno != NULL) *colerrno = COLE_EFSEEKFLAG; if (colerrno != NULL) *colerrno = COLE_EFSEEKFLAG;
return 1; 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 */ /* FIXME allow no absolute paths */
if (filename[0] != '/') { if (filename[0] != '/') {
if (colerrno != NULL) *colerrno = COLE_EBROKENFILENAME; if (colerrno != NULL) *colerrno = COLE_EBROKENFILENAME;
return 1; return 1;
} }
_info.action = action; _info.action = action;
@ -1145,8 +1147,6 @@ cole_locate_filename (COLEFS *colefilesystem, char *filename,
static int static int
__cole_locate_filename_visitdir (COLEDIR *cd, void *info) __cole_locate_filename_visitdir (COLEDIR *cd, void *info)
{ {
(void) cd; /*UNUSED*/
return ((struct __cole_locate_filenameinfo *)info)->visitdir; return ((struct __cole_locate_filenameinfo *)info)->visitdir;
} }

View File

@ -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. */ /* Define to empty if the keyword does not work. */
#undef const #undef const

View File

@ -9,5 +9,5 @@ man_MANS = ppthtml.1
bin_SCRIPTS = nspptview bin_SCRIPTS = nspptview
bin_PROGRAMS = ppthtml bin_PROGRAMS = ppthtml
LDADD = ../cole/libcole.a LDADD = ../cole/libcole.a
ppthtml_SOURCES = ppthtml.c ppthtml_SOURCES = ppthtml.c vector.c
#AM_CFLAGS = -Wall -Wshadow -Wcast-align -Wpointer-arith #AM_CFLAGS = -Wall -Wshadow -Wcast-align -Wpointer-arith

View File

@ -83,7 +83,7 @@ man_MANS = ppthtml.1
bin_SCRIPTS = nspptview bin_SCRIPTS = nspptview
bin_PROGRAMS = ppthtml bin_PROGRAMS = ppthtml
LDADD = ../cole/libcole.a LDADD = ../cole/libcole.a
ppthtml_SOURCES = ppthtml.c ppthtml_SOURCES = ppthtml.c vector.c
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../config.h CONFIG_HEADER = ../config.h
CONFIG_CLEAN_FILES = CONFIG_CLEAN_FILES =
@ -94,7 +94,7 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I..
CPPFLAGS = @CPPFLAGS@ CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@ LDFLAGS = @LDFLAGS@
LIBS = @LIBS@ LIBS = @LIBS@
ppthtml_OBJECTS = ppthtml.o ppthtml_OBJECTS = ppthtml.o vector.o
ppthtml_LDADD = $(LDADD) ppthtml_LDADD = $(LDADD)
ppthtml_DEPENDENCIES = ../cole/libcole.a ppthtml_DEPENDENCIES = ../cole/libcole.a
ppthtml_LDFLAGS = ppthtml_LDFLAGS =

View File

@ -17,23 +17,37 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 "config.h" /* Created by ./configure script */
#include "support.h" /* Needs to be before internal.h */ #include "support.h" /* Needs to be before internal.h */
#include "internal.h" /* Needs to be before cole */ #include "internal.h" /* Needs to be before cole */
#include "cole.h" #include "cole.h"
#if defined(WIN32) #else
#include <direct.h> /* _chdrive() */ #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 <dir.h>
#endif #endif
#include "vector.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> /* for strcpy() */ #include <string.h> /* For strcpy() */
#include <ctype.h> /* For isprint */ #include <ctype.h> /* For isprint */
#include <stdlib.h> /* For exitt() */ #include <stdlib.h> /* For exitt() */
#include <limits.h> /* For MAX_PATH */
#include "ppthtml.h" /* For SummaryInfo things*/
#define PRGNAME "pptHtml" #define PRGNAME "pptHtml"
#if defined(VERSION) #if !(defined( __WIN32__ ) || defined( __BORLANDC__ ))
#define PRGVER VERSION #define PRGVER VERSION
#else #else
#define PRGVER "0.4" #define PRGVER "0.4"
@ -45,6 +59,8 @@ static char FileName[2][32] = /* The section of the PowerPoint File we read */
"/PP40" /* Everything else ? */ "/PP40" /* Everything else ? */
}; };
#define BUFFER_SIZE 128
/* Function Prototypes */ /* Function Prototypes */
COLE_LOCATE_ACTION_FUNC dump_file; 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_unicode(unsigned char *, int);
static void print_utf8(unsigned short c); static void print_utf8(unsigned short c);
static void put_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 */ /* Global data */
static char filename[128]; static char filename[128];
@ -61,356 +81,628 @@ static int buf_idx=0;
static int output_this_container = 0; static int output_this_container = 0;
static int past_first_slide = 0; static int past_first_slide = 0;
static int last_container = 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 main (int argc, char **argv)
{ {
int f_ptr = 0; int f_ptr = 0;
COLEFS * cfs; COLEFS * cfs;
COLERRNO colerrno; COLEFILE * cf;
COLERRNO colerrno;
char buffer[BUFFER_SIZE];
size_t char_read;
size_t char_read_total;
if (argc < 2) gboolean ok;
{ OleSummary *si;
fprintf (stderr, "pptHtml - Outputs Power Point files as Html.\n"
"Usage: "PRGNAME" <FILE>\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);
}
}
while (cole_locate_filename (cfs, FileName[f_ptr], NULL, dump_file, &colerrno)) if (argc < 2)
{ {
if (f_ptr) fprintf (stderr, "pptHtml - Outputs Power Point files as Html.\n"
{ /* Two strikes...we're out! */ "Usage: "PRGNAME" <FILE>\n");
cole_perror (PRGNAME, colerrno); exit (1);
if (colerrno == COLE_EFILENOTFOUND) }
fprintf(stderr, "Section: PowerPoint Document\n"); else
break; {
} strncpy(filename, argv[1], 124);
else /* Don't do this... */ cfs = cole_mount (filename, &colerrno);
f_ptr++; if (cfs == NULL)
} {
cole_perror (PRGNAME, colerrno);
exit (1);
}
}
if (cole_umount (cfs, &colerrno))
{
cole_perror ("travel", colerrno);
exit (1);
}
return 0;
cf = cole_fopen (cfs, "/\005SummaryInformation", &colerrno);
if (!cf) {
printf("ERROR-No Summary Information available for this document\n");
cole_umount (cfs, NULL);
exit (1);
}
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) 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*/ 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); cf = cole_fopen_direntry(cde, &err);
/* Ouput Header */
printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n");
printf("<HTML><HEAD><TITLE>%s</TITLE>\n", title);
if(subject)
printf("<meta name=\"description\" content=\"%s\">\n", subject);
if(author)
printf("<meta name=\"author\" content=\"%s\">\n", author);
if(keywords)
printf("<meta name=\"keywords\" content=\"%s\">\n", keywords);
printf("</HEAD><BODY>\n");
/* Ouput Header */ /* Output body */
printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n"); while (cole_fread(cf, buf, 1, &err))
printf("<HTML><HEAD><TITLE>%s", filename);
printf("</TITLE></HEAD><BODY>\n");
/* Output body */
while (cole_fread(cf, buf, 1, &err))
{ {
if (count == 0) if (count == 0)
{ {
instance = buf[0]; instance = buf[0];
type = 0; type = 0;
length = 0; length = 0;
target = 80; /* ficticious number */ target = 80; /* ficticious number */
} }
else if (count == 1) else if (count == 1)
{ {
instance |= (buf[0]<<8); instance |= (buf[0]<<8);
version = instance &0x000F; version = instance &0x000F;
instance = (instance>>4); instance = (instance>>4);
} }
else if (count == 2) else if (count == 2)
type = (unsigned)buf[0]; type = (unsigned)buf[0];
else if (count == 3) else if (count == 3)
type |= (buf[0]<<8)&0x00000FFFL; type |= (buf[0]<<8)&0x00000FFFL;
else if (count == 4) else if (count == 4)
length = (unsigned)buf[0]; length = (unsigned)buf[0];
else if (count == 5) else if (count == 5)
length |= (buf[0]<<8); length |= (buf[0]<<8);
else if (count == 6) else if (count == 6)
length |= (buf[0]<<16); length |= (buf[0]<<16);
else if (count == 7) else if (count == 7)
{ {
length |= (buf[0]<<24); length |= (buf[0]<<24);
target = length; target = length;
if (version == 0x0F) if (version == 0x0F)
{ /* Do container level Processing */ { /* Do container level Processing */
container_processor(type); container_processor(type);
count = -1; count = -1;
} }
} }
if (count > 7) if (count > 7)
{ /* Here is where we want to process the data { /* Here is where we want to process the data
based on the Atom type... */ based on the Atom type... */
atom_processor(type, count-8, target-1, buf[0]); atom_processor(type, count-8, target-1, buf[0]);
} }
if (count == (target+7)) if (count == (target+7))
count = 0; count = 0;
else else
count++; count++;
} }
if (past_first_slide) if (past_first_slide)
printf("<HR>"); printf("<HR>");
printf("&nbsp;<br>\n"); printf("&nbsp;<br>\n");
/* Output Credit */ /* Output Credit */
printf("<hr><FONT SIZE=-1>Created with <a href=\"http://chicago.sf.net/xlhtml\">pptHtml</a></FONT><br>\n" ); printf("<hr><FONT SIZE=-1>Created with <a href=\"http://chicago.sf.net/xlhtml\">pptHtml</a></FONT><br>\n" );
/* Output Tail */ /* Output Tail */
printf("</BODY></HTML>\n"); printf("</BODY></HTML>\n");
cole_fclose(cf, &err); cole_fclose(cf, &err);
} }
static void container_processor(int type) static void container_processor(int type)
{ {
if (type == 0x03EE) if (type == 0x03EE)
{ {
if (past_first_slide) if (past_first_slide)
printf("<BR><HR><BR>\n"); printf("<BR><HR><BR>\n");
else else
past_first_slide = 1; past_first_slide = 1;
} }
switch (type) switch (type)
{ {
case 0x000D: case 0x000D:
if (last_container == 0x11) /* suppress notes info */ if (last_container == 0x11) /* suppress notes info */
output_this_container = 0; output_this_container = 0;
else else
output_this_container = 1; output_this_container = 1;
break; break;
case 0x0FF0: case 0x0FF0:
output_this_container = 1; output_this_container = 1;
break; break;
default: default:
/* printf("Cont:%x|\n", type); */ /* printf("Cont:%x|\n", type); */
output_this_container = 0; output_this_container = 0;
break; break;
} }
last_container = type; last_container = type;
} }
static void atom_processor(int type, int count, int buf_last, unsigned char data) static void atom_processor(int type, int count, int buf_last, unsigned char data)
{ {
if ((buf_idx >= WORK_SIZE)||(output_this_container == 0)) if ((buf_idx >= WORK_SIZE)||(output_this_container == 0))
return; return;
if (count == 0) if (count == 0)
{ {
memset(working_buffer, 0, WORK_SIZE); memset(working_buffer, 0, WORK_SIZE);
buf_idx = 0; buf_idx = 0;
} }
switch (type) switch (type)
{ {
case 0x0FA0: /* Text String in unicode */ case 0x0FA0: /* Text String in unicode */
working_buffer[buf_idx++] = data; working_buffer[buf_idx++] = data;
if (count == buf_last) if (count == buf_last)
{ {
/* printf("Atom:%x|\n", type); */ /* printf("Atom:%x|\n", type); */
/* working_buffer[buf_idx++] = 0; */ /* working_buffer[buf_idx++] = 0; */
/* printf("%s<BR>\n", working_buffer); */ /* printf("%s<BR>\n", working_buffer); */
print_unicode(working_buffer, buf_idx); print_unicode(working_buffer, buf_idx);
printf("<BR>\n"); printf("<BR>\n");
} }
break; break;
case 0x0FA8: /* Text String in ASCII */ case 0x0FA8: /* Text String in ASCII */
working_buffer[buf_idx++] = data; working_buffer[buf_idx++] = data;
if (count == buf_last) if (count == buf_last)
{ {
int i; int i;
/* working_buffer[buf_idx++] = 0; */ /* working_buffer[buf_idx++] = 0; */
/* printf("Atom:%x|\n", type); */ /* printf("Atom:%x|\n", type); */
for (i=0;i<buf_idx; i++) for (i=0;i<buf_idx; i++)
{ {
/* printf("%02X &nbsp;", (int)working_buffer[i]); */ /* Debug */ /* printf("%02X &nbsp;", (int)working_buffer[i]); */ /* Debug */
if (working_buffer[i] == 0x0D) if (working_buffer[i] == 0x0D)
printf("<BR>\n"); printf("<BR>\n");
else else
putchar(working_buffer[i]); putchar(working_buffer[i]);
} }
printf("<BR>\n"); printf("<BR>\n");
} }
break; break;
case 0x0FBA: /* CString - unicode... */ case 0x0FBA: /* CString - unicode... */
working_buffer[buf_idx++] = data; working_buffer[buf_idx++] = data;
if (count == buf_last) if (count == buf_last)
{ {
/* working_buffer[buf_idx++] = 0; */ /* working_buffer[buf_idx++] = 0; */
/* printf("%s<BR>\n", working_buffer); */ /* printf("%s<BR>\n", working_buffer); */
/* printf("Atom:%x|\n", type); */ /* printf("Atom:%x|\n", type); */
print_unicode(working_buffer, buf_idx); print_unicode(working_buffer, buf_idx);
printf("<BR>\n"); printf("<BR>\n");
} }
break; break;
default: default:
break; break;
} }
} }
static void print_unicode(unsigned char *ucs, int len) static void print_unicode(unsigned char *ucs, int len)
{ {
int i; int i;
for (i = 0; i < len; i += 2) for (i = 0; i < len; i += 2)
print_utf8(ucs[i] | (ucs[i+1] << 8)); print_utf8(ucs[i] | (ucs[i+1] << 8));
} }
static void OutputCharCorrected(unsigned char c) static void OutputCharCorrected(unsigned char c)
{ {
switch (c) switch (c)
{ /* Special char handlers here... */ { /* Special char handlers here... */
case '\r': case '\r':
printf("<BR>\n"); printf("<BR>\n");
break; break;
case 0x3C: case 0x3C:
printf("&lt;"); printf("&lt;");
break; break;
case 0x3E: case 0x3E:
printf("&gt;"); printf("&gt;");
break; break;
case 0x26: case 0x26:
printf("&amp;"); printf("&amp;");
break; break;
case 0x22: case 0x22:
printf("&quot;"); printf("&quot;");
break; break;
/* Also need to cover 128-159 since MS uses this area... */ /* Also need to cover 128-159 since MS uses this area... */
case 0x80: /* Euro Symbol */ case 0x80: /* Euro Symbol */
printf("&#8364;"); printf("&#8364;");
break; break;
case 0x82: /* baseline single quote */ case 0x82: /* baseline single quote */
printf("&#8218;"); printf("&#8218;");
break; break;
case 0x83: /* florin */ case 0x83: /* florin */
printf("&#402;"); printf("&#402;");
break; break;
case 0x84: /* baseline double quote */ case 0x84: /* baseline double quote */
printf("&#8222;"); printf("&#8222;");
break; break;
case 0x85: /* ellipsis */ case 0x85: /* ellipsis */
printf("&#8230;"); printf("&#8230;");
break; break;
case 0x86: /* dagger */ case 0x86: /* dagger */
printf("&#8224;"); printf("&#8224;");
break; break;
case 0x87: /* double dagger */ case 0x87: /* double dagger */
printf("&#8225;"); printf("&#8225;");
break; break;
case 0x88: /* circumflex accent */ case 0x88: /* circumflex accent */
printf("&#710;"); printf("&#710;");
break; break;
case 0x89: /* permile */ case 0x89: /* permile */
printf("&#8240;"); printf("&#8240;");
break; break;
case 0x8A: /* S Hacek */ case 0x8A: /* S Hacek */
printf("&#352;"); printf("&#352;");
break; break;
case 0x8B: /* left single guillemet */ case 0x8B: /* left single guillemet */
printf("&#8249;"); printf("&#8249;");
break; break;
case 0x8C: /* OE ligature */ case 0x8C: /* OE ligature */
printf("&#338;"); printf("&#338;");
break; break;
case 0x8E: /* #LATIN CAPITAL LETTER Z WITH CARON */ case 0x8E: /* #LATIN CAPITAL LETTER Z WITH CARON */
printf("&#381;"); printf("&#381;");
break; break;
case 0x91: /* left single quote ? */ case 0x91: /* left single quote ? */
printf("&#8216;"); printf("&#8216;");
break; break;
case 0x92: /* right single quote ? */ case 0x92: /* right single quote ? */
printf("&#8217;"); printf("&#8217;");
break; break;
case 0x93: /* left double quote */ case 0x93: /* left double quote */
printf("&#8220;"); printf("&#8220;");
break; break;
case 0x94: /* right double quote */ case 0x94: /* right double quote */
printf("&#8221;"); printf("&#8221;");
break; break;
case 0x95: /* bullet */ case 0x95: /* bullet */
printf("&#8226;"); printf("&#8226;");
break; break;
case 0x96: /* endash */ case 0x96: /* endash */
printf("&#8211;"); printf("&#8211;");
break; break;
case 0x97: /* emdash */ case 0x97: /* emdash */
printf("&#8212;"); printf("&#8212;");
break; break;
case 0x98: /* tilde accent */ case 0x98: /* tilde accent */
printf("&#732;"); printf("&#732;");
break; break;
case 0x99: /* trademark ligature */ case 0x99: /* trademark ligature */
printf("&#8482;"); printf("&#8482;");
break; break;
case 0x9A: /* s Haceks Hacek */ case 0x9A: /* s Haceks Hacek */
printf("&#353;"); printf("&#353;");
break; break;
case 0x9B: /* right single guillemet */ case 0x9B: /* right single guillemet */
printf("&#8250;"); printf("&#8250;");
break; break;
case 0x9C: /* oe ligature */ case 0x9C: /* oe ligature */
printf("&#339;"); printf("&#339;");
break; break;
case 0x9F: /* Y Dieresis */ case 0x9F: /* Y Dieresis */
printf("&#376;"); printf("&#376;");
break; break;
default: default:
putchar(c); putchar(c);
break; break;
} }
} }
static void print_utf8(unsigned short c) static void print_utf8(unsigned short c)
{ {
if (c == 0) if (c == 0)
return; return;
if (c < 0x80) if (c < 0x80)
OutputCharCorrected(c); OutputCharCorrected(c);
else if (c < 0x800) else if (c < 0x800)
{ {
putchar(0xC0 | (c >> 6)); putchar(0xC0 | (c >> 6));
put_utf8(c); put_utf8(c);
} }
else else
{ {
putchar(0xE0 | (c >> 12)); putchar(0xE0 | (c >> 12));
put_utf8(c >> 6); put_utf8(c >> 6);
put_utf8(c); put_utf8(c);
} }
} }
static void put_utf8(unsigned short 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;
}

View File

@ -83,6 +83,27 @@ void OutputTableHTML(void)
do_cr(); do_cr();
printf("<TABLE BORDER=\"1\" CELLSPACING=\"2\">"); printf("<TABLE BORDER=\"1\" CELLSPACING=\"2\">");
do_cr(); do_cr();
if (TableHeaders)
{
printf("<TR><TH></TH>");
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("<TH>%s%s",col_hdr,(aggressive ? "" : "</TH>"));
}
printf("</TR>\n");
}
for (j=ws_array[i]->first_row; j<=ws_array[i]->biggest_row; j++) for (j=ws_array[i]->first_row; j<=ws_array[i]->biggest_row; j++)
{ {
update_default_alignment(i, j); update_default_alignment(i, j);
@ -98,6 +119,8 @@ void OutputTableHTML(void)
else else
printf(">"); printf(">");
} }
if (TableHeaders)
printf("<TH>%d%s",j+1,(aggressive ? "" : "</TH>"));
for (k=ws_array[i]->first_col; k<=ws_array[i]->biggest_col; k++) 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... */ output_cell(ws_array[i]->c_array[(j*ws_array[i]->max_cols)+k],0); /* This stuff happens for each cell... */

View File

@ -89,6 +89,20 @@ S32 getLong(U8 *ptr)
} }
#ifndef WORDS_BIGENDIAN /* Defined in <config.h> */ #ifndef WORDS_BIGENDIAN /* Defined in <config.h> */
#ifdef __arm__
/* cross-endian doubles in little endian ARM */
void getDouble(U8 *ptr, F64 *d)
{
size_t i;
F64 dd;
U8 *t = (U8 *)&dd;
for (i=0; i<sizeof(F64); i++)
*(t+i) = *(ptr+(i^4));
*d = (F64)dd;
}
#else
/*! Little Endian - 0x86 family */ /*! Little Endian - 0x86 family */
void getDouble(U8 *ptr, F64 *d) void getDouble(U8 *ptr, F64 *d)
{ {
@ -101,6 +115,7 @@ void getDouble(U8 *ptr, F64 *d)
*d = (F64)dd; *d = (F64)dd;
} }
#endif
#else #else
/*! Big Endian version - UltraSparc's, etc. */ /*! Big Endian version - UltraSparc's, etc. */
void getDouble (U8 *ptr, F64 *d) void getDouble (U8 *ptr, F64 *d)
@ -210,12 +225,21 @@ typedef S32 swords[2];
(((union{swords sw; F64 dub;} *)(ptr))->sw) (((union{swords sw; F64 dub;} *)(ptr))->sw)
#ifndef WORDS_BIGENDIAN /*! Defined in <config.h> */ #ifndef WORDS_BIGENDIAN /*! Defined in <config.h> */
#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 */ /*! Little Endian - 0x86 family */
void RKtoDouble(S32 n, F64 *d) void RKtoDouble(S32 n, F64 *d)
{ {
noaliasdub(swords,d)[0] = 0; noaliasdub(swords,d)[0] = 0;
noaliasdub(swords,d)[1] = n << 2; noaliasdub(swords,d)[1] = n << 2;
} }
#endif
#else #else
/*! Big Endian version - UltraSparc's, etc. */ /*! Big Endian version - UltraSparc's, etc. */
void RKtoDouble(S32 n, F64 *d) void RKtoDouble(S32 n, F64 *d)

View File

@ -211,6 +211,7 @@ int DumpPage = 0; /*!< Dump page count & max cols & rows */
int Xtract = 0; /*!< Extract a range on a page. */ int Xtract = 0; /*!< Extract a range on a page. */
int MultiByte = 0; /*!< Output as multibyte */ int MultiByte = 0; /*!< Output as multibyte */
int NoHeaders = 0; /*!< Don't output html header */ int NoHeaders = 0; /*!< Don't output html header */
int TableHeaders = 0; /*!< Output row/column headers */
/* Some Global Flags */ /* Some Global Flags */
@ -299,6 +300,8 @@ int main (int argc, char **argv)
print_version(); print_version();
else if(strcmp(argv[i], "-nh") == 0 ) else if(strcmp(argv[i], "-nh") == 0 )
NoHeaders = 1; NoHeaders = 1;
else if(strcmp(argv[i], "-th") == 0 )
TableHeaders = 1;
else if (strncmp(argv[i], "-xc:", 4) == 0) else if (strncmp(argv[i], "-xc:", 4) == 0)
{ {
int d1, d2; int d1, d2;

View File

@ -152,6 +152,7 @@ extern char *default_image;
extern int aggressive; extern int aggressive;
extern int center_tables; extern int center_tables;
extern int NoHeaders; extern int NoHeaders;
extern int TableHeaders;
extern int formula_warnings; extern int formula_warnings;
extern int Csv; extern int Csv;
extern xf_attr **xf_array; extern xf_attr **xf_array;