From b3b0f8f43aa31bdf8146efd0a0d07a570fddf734 Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Tue, 17 Oct 2006 19:11:29 +0000 Subject: [PATCH] Implemented option -b in catppt fixses debian bug 383576 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=383576 --- src/catppt.c | 11 +++++++---- src/pptparse.c | 30 +++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/catppt.c b/src/catppt.c index 31c8120..c90580c 100644 --- a/src/catppt.c +++ b/src/catppt.c @@ -2,7 +2,7 @@ * @file ppt2text.c * @author Alex Ott * @date 23 äÅË 2004 - * Version: $Id: catppt.c,v 1.1 2006-02-24 17:44:06 vitus Exp $ + * Version: $Id: catppt.c,v 1.2 2006-10-17 19:11:29 vitus Exp $ * Copyright: Alex Ott * * @brief main module for text extracting from .ppt @@ -34,10 +34,10 @@ * */ void help (void) { - printf("Usage:\n ppt2text [-lV] [-b string] [-s charset] [-d charset] files\n"); + printf("Usage:\n catppt [-lV] [-b string] [-s charset] [-d charset] files\n"); } - +extern char *slide_separator; char *input_buffer, *output_buffer; /** @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) { check_charset(&dest_csname,dest_csname); - while ((c=getopt(argc,argv,"Vls:d:p:"))!=-1) { + while ((c=getopt(argc,argv,"Vls:d:b:"))!=-1) { switch(c) { case 'l': list_charsets(); exit(0); @@ -81,6 +81,9 @@ int main(int argc, char *argv[]) { case 'd': check_charset(&dest_csname,optarg); break; + case 'b': + slide_separator = strdup(optarg); + break; case 'V': printf("Catdoc Version %s\n",CATDOC_VERSION); exit(0); default: diff --git a/src/pptparse.c b/src/pptparse.c index e74c93a..c5ebe03 100644 --- a/src/pptparse.c +++ b/src/pptparse.c @@ -2,7 +2,7 @@ * @file pptparse.c * @author Alex Ott * @date 23 äÅË 2004 - * Version: $Id: pptparse.c,v 1.1 2006-02-24 17:44:06 vitus Exp $ + * Version: $Id: pptparse.c,v 1.2 2006-10-17 19:11:29 vitus Exp $ * Copyright: Alex Ott * * @brief .ppt parsing routines @@ -21,12 +21,15 @@ #include "catdoc.h" #include "ppttypes.h" +char *slide_separator = "\f"; + static void process_item (int rectype, long reclen, FILE* input); #if !defined(min) #define min(x,y) ((x) < (y) ? (x) : (y)) #endif +static void start_text_out(void); /** * @@ -34,12 +37,21 @@ static void process_item (int rectype, long reclen, FILE* input); * @param input * @param filename */ + +enum {START_FILE,START_SLIDE,TEXTOUT,END_FILE} slide_state ; + +static void start_text_out(void) { + if (slide_state == START_SLIDE) { + fputs(slide_separator,stdout); + } + slide_state = TEXTOUT; +} void do_ppt(FILE *input,char *filename) { int itemsread=1; int rectype; long reclen; unsigned char recbuf[8]; - + slide_state = START_FILE; while(itemsread) { itemsread = catdoc_read(recbuf, 1, 8, input); /* fprintf(stderr,"itemsread=%d: ",itemsread); */ @@ -73,11 +85,16 @@ void do_ppt(FILE *input,char *filename) { static void process_item (int rectype, long reclen, FILE* input) { int i=0, u; static char buf[2]; - +/* fprintf(stderr,"Processing record %d length %d\n",rectype,reclen); + * */ switch(rectype) { case DOCUMENT_END: /* fprintf(stderr,"End of document, ended at %ld\n",catdoc_tell(input)); */ catdoc_seek(input, reclen, SEEK_CUR); + if (slide_state == TEXTOUT) { + fputs(slide_separator,stdout); + slide_state = END_FILE; + } break; case DOCUMENT: @@ -92,7 +109,6 @@ static void process_item (int rectype, long reclen, FILE* input) { case SLIDE: /* fprintf(stderr,"Slide, reclen=%ld\n", reclen); */ -/* fputs("---------------------------------------\n",stderr); */ break; case SLIDE_ATOM: @@ -133,6 +149,7 @@ static void process_item (int rectype, long reclen, FILE* input) { case TEXT_BYTES_ATOM: { /* fprintf(stderr,"TextBytes, reclen=%ld\n", reclen); */ + start_text_out(); for(i=0; i < reclen; i++) { catdoc_read(buf,1,1,input); if((unsigned char)*buf!=0x0d) @@ -149,6 +166,7 @@ static void process_item (int rectype, long reclen, FILE* input) { long text_len; /* fprintf(stderr,"CString, reclen=%ld\n", reclen); */ + start_text_out(); text_len=reclen/2; for(i=0; i < text_len; i++) { catdoc_read(buf,2,1,input); @@ -247,7 +265,9 @@ static void process_item (int rectype, long reclen, FILE* input) { break; case SLIDE_PERSIST_ATOM: -/* fprintf(stderr,"SlidePersistAtom, reclen=%ld\n", reclen); */ + if (slide_state != START_FILE) { + slide_state = START_SLIDE; + } catdoc_seek(input, reclen, SEEK_CUR); break; -- 2.39.5