libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 93c140984bcbc71ff75ec354f1e00678ec0a37cf
parent 0c0331bd3fe2e668c9820c714b11543790383c4d
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon, 16 Feb 2009 07:17:04 +0000

code clean up

Diffstat:
Msrc/plugins/pdf/Dict.cc | 8++++----
Msrc/plugins/pdf/Dict.h | 8++++----
Msrc/plugins/pdf/Error.cc | 2+-
Msrc/plugins/pdf/Error.h | 2+-
Msrc/plugins/pdf/Function.cc | 2+-
Msrc/plugins/pdf/Object.cc | 71++---------------------------------------------------------------------
Msrc/plugins/pdf/Object.h | 31+++++++++++++++----------------
Msrc/plugins/pdf/Page.cc | 2+-
Msrc/plugins/pdf/Page.h | 2+-
Msrc/plugins/pdf/Params.cc | 3++-
Msrc/plugins/pdf/Params.h | 3++-
Msrc/plugins/pdf/Stream.cc | 18+++++++++---------
Msrc/plugins/pdf/Stream.h | 26+++++++++++++-------------
Msrc/plugins/pdf/gfile.cc | 2+-
Msrc/plugins/pdf/gfile.h | 2+-
Msrc/plugins/pdf/pdfextractor.cc | 12++++++------
16 files changed, 64 insertions(+), 130 deletions(-)

diff --git a/src/plugins/pdf/Dict.cc b/src/plugins/pdf/Dict.cc @@ -54,7 +54,7 @@ void Dict::add(char *key, Object *val) { ++length; } -inline DictEntry *Dict::find(char *key) { +inline DictEntry *Dict::find(const char *key) { int i; for (i = 0; i < length; ++i) { @@ -64,19 +64,19 @@ inline DictEntry *Dict::find(char *key) { return NULL; } -GBool Dict::is(char *type) { +GBool Dict::is(const char *type) { DictEntry *e; return (e = find("Type")) && e->val.isName(type); } -Object *Dict::lookup(char *key, Object *obj) { +Object *Dict::lookup(const char *key, Object *obj) { DictEntry *e; return (e = find(key)) ? e->val.fetch(xref, obj) : obj->initNull(); } -Object *Dict::lookupNF(char *key, Object *obj) { +Object *Dict::lookupNF(const char *key, Object *obj) { DictEntry *e; return (e = find(key)) ? e->val.copy(obj) : obj->initNull(); diff --git a/src/plugins/pdf/Dict.h b/src/plugins/pdf/Dict.h @@ -46,12 +46,12 @@ public: void add(char *key, Object *val); // Check if dictionary is of specified type. - GBool is(char *type); + GBool is(const char *type); // Look up an entry and return the value. Returns a null object // if <key> is not in the dictionary. - Object *lookup(char *key, Object *obj); - Object *lookupNF(char *key, Object *obj); + Object *lookup(const char *key, Object *obj); + Object *lookupNF(const char *key, Object *obj); // Iterative accessors. char *getKey(int i); @@ -71,7 +71,7 @@ private: int length; // number of entries in dictionary int ref; // reference count - DictEntry *find(char *key); + DictEntry *find(const char *key); }; #endif diff --git a/src/plugins/pdf/Error.cc b/src/plugins/pdf/Error.cc @@ -17,5 +17,5 @@ #include <stdarg.h> #include "Error.h" -void error(int pos, char *msg, ...) { +void error(int pos, const char *msg, ...) { } diff --git a/src/plugins/pdf/Error.h b/src/plugins/pdf/Error.h @@ -18,6 +18,6 @@ #include <stdio.h> #include "config.h" -extern void error(int pos, char *msg, ...); +extern void error(int pos, const char *msg, ...); #endif diff --git a/src/plugins/pdf/Function.cc b/src/plugins/pdf/Function.cc @@ -719,7 +719,7 @@ enum PSOp { // Note: 'if' and 'ifelse' are parsed separately. // The rest are listed here in alphabetical order. // The index in this table is equivalent to the entry in PSOp. -char *psOpNames[] = { +const char *psOpNames[] = { "abs", "add", "and", diff --git a/src/plugins/pdf/Object.cc b/src/plugins/pdf/Object.cc @@ -24,7 +24,7 @@ // Object //------------------------------------------------------------------------ -char *objTypeNames[numObjTypes] = { +const char *objTypeNames[numObjTypes] = { "boolean", "integer", "real", @@ -141,77 +141,10 @@ void Object::free() { type = objNone; } -char *Object::getTypeName() { +const char *Object::getTypeName() { return objTypeNames[type]; } -void Object::print(FILE *f) { - Object obj; - int i; - - switch (type) { - case objBool: - fprintf(f, "%s", booln ? "true" : "false"); - break; - case objInt: - fprintf(f, "%d", intg); - break; - case objReal: - fprintf(f, "%g", real); - break; - case objString: - fprintf(f, "("); - fwrite(string->getCString(), 1, string->getLength(), stdout); - fprintf(f, ")"); - break; - case objName: - fprintf(f, "/%s", name); - break; - case objNull: - fprintf(f, "null"); - break; - case objArray: - fprintf(f, "["); - for (i = 0; i < arrayGetLength(); ++i) { - if (i > 0) - fprintf(f, " "); - arrayGetNF(i, &obj); - obj.print(f); - obj.free(); - } - fprintf(f, "]"); - break; - case objDict: - fprintf(f, "<<"); - for (i = 0; i < dictGetLength(); ++i) { - fprintf(f, " /%s ", dictGetKey(i)); - dictGetValNF(i, &obj); - obj.print(f); - obj.free(); - } - fprintf(f, " >>"); - break; - case objStream: - fprintf(f, "<stream>"); - break; - case objRef: - fprintf(f, "%d %d R", ref.num, ref.gen); - break; - case objCmd: - fprintf(f, "%s", cmd); - break; - case objError: - fprintf(f, "<error>"); - break; - case objEOF: - fprintf(f, "<EOF>"); - break; - case objNone: - fprintf(f, "<none>"); - break; - } -} - void Object::memCheck(FILE *f) { #ifdef DEBUG_MEM int i; diff --git a/src/plugins/pdf/Object.h b/src/plugins/pdf/Object.h @@ -136,11 +136,11 @@ public: GBool isNone() { return type == objNone; } // Special type checking. - GBool isName(char *nameA) + GBool isName(const char *nameA) { return type == objName && !strcmp(name, nameA); } - GBool isDict(char *dictType); - GBool isStream(char *dictType); - GBool isCmd(char *cmdA) + GBool isDict(const char *dictType); + GBool isStream(const char *dictType); + GBool isCmd(const char *cmdA) { return type == objCmd && !strcmp(cmd, cmdA); } // Accessors. NB: these assume object is of correct type. @@ -167,15 +167,15 @@ public: // Dict accessors. int dictGetLength(); void dictAdd(char *key, Object *val); - GBool dictIs(char *dictType); - Object *dictLookup(char *key, Object *obj); - Object *dictLookupNF(char *key, Object *obj); + GBool dictIs(const char *dictType); + Object *dictLookup(const char *key, Object *obj); + Object *dictLookupNF(const char *key, Object *obj); char *dictGetKey(int i); Object *dictGetVal(int i, Object *obj); Object *dictGetValNF(int i, Object *obj); // Stream accessors. - GBool streamIs(char *dictType); + GBool streamIs(const char *dictType); void streamReset(); void streamClose(); int streamGetChar(); @@ -186,8 +186,7 @@ public: Dict *streamGetDict(); // Output. - char *getTypeName(); - void print(FILE *f = stdout); + const char *getTypeName(); // Memory testing. static void memCheck(FILE *f); @@ -244,16 +243,16 @@ inline int Object::dictGetLength() inline void Object::dictAdd(char *key, Object *val) { if (type == objDict) dict->add(key, val); } -inline GBool Object::dictIs(char *dictType) +inline GBool Object::dictIs(const char *dictType) { return (type == objDict) && dict->is(dictType); } -inline GBool Object::isDict(char *dictType) +inline GBool Object::isDict(const char *dictType) { return (type == objDict) && dictIs(dictType); } -inline Object *Object::dictLookup(char *key, Object *obj) +inline Object *Object::dictLookup(const char *key, Object *obj) { if (type != objDict) return obj->initNull(); return dict->lookup(key, obj); } -inline Object *Object::dictLookupNF(char *key, Object *obj) +inline Object *Object::dictLookupNF(const char *key, Object *obj) { if (type != objDict) return obj->initNull(); return dict->lookupNF(key, obj); } inline char *Object::dictGetKey(int i) @@ -271,10 +270,10 @@ inline Object *Object::dictGetValNF(int i, Object *obj) #include "Stream.h" -inline GBool Object::streamIs(char *dictType) +inline GBool Object::streamIs(const char *dictType) { return (type == objStream) && stream->getDict()->is(dictType); } -inline GBool Object::isStream(char *dictType) +inline GBool Object::isStream(const char *dictType) { return (type == objStream) && streamIs(dictType); } inline void Object::streamReset() diff --git a/src/plugins/pdf/Page.cc b/src/plugins/pdf/Page.cc @@ -124,7 +124,7 @@ PageAttrs::~PageAttrs() { resources.free(); } -GBool PageAttrs::readBox(Dict *dict, char *key, PDFRectangle *box) { +GBool PageAttrs::readBox(Dict *dict, const char *key, PDFRectangle *box) { PDFRectangle tmp; Object obj1, obj2; GBool ok; diff --git a/src/plugins/pdf/Page.h b/src/plugins/pdf/Page.h @@ -78,7 +78,7 @@ public: private: - GBool readBox(Dict *dict, char *key, PDFRectangle *box); + GBool readBox(Dict *dict, const char *key, PDFRectangle *box); PDFRectangle mediaBox; PDFRectangle cropBox; diff --git a/src/plugins/pdf/Params.cc b/src/plugins/pdf/Params.cc @@ -19,7 +19,8 @@ static int fontPathLen, fontPathSize; DevFontMapEntry *devFontMap = NULL; static int devFontMapLen, devFontMapSize; -void initParams(char *userConfigFile, char *sysConfigFile) { +void initParams(const char *userConfigFile, + const char *sysConfigFile) { GString *fileName; FILE *f; char buf[256]; diff --git a/src/plugins/pdf/Params.h b/src/plugins/pdf/Params.h @@ -31,7 +31,8 @@ extern DevFontMapEntry *devFontMap; // <userConfigFile> exists, read it; else if <sysConfigFile> exists, // read it. <userConfigFile> is relative to the user's home // directory; <sysConfigFile> should be an absolute path. -extern void initParams(char *userConfigFile, char *sysConfigFile); +extern void initParams(const char *userConfigFile, + const char *sysConfigFile); // Free memory used for font path and font map. extern void freeParams(); diff --git a/src/plugins/pdf/Stream.cc b/src/plugins/pdf/Stream.cc @@ -85,7 +85,7 @@ char *Stream::getLine(char *buf, int size) { return buf; } -GString *Stream::getPSFilter(int psLevel, char *indent) { +GString *Stream::getPSFilter(int psLevel, const char *indent) { return new GString(); } @@ -930,7 +930,7 @@ int ASCIIHexStream::lookChar() { return buf; } -GString *ASCIIHexStream::getPSFilter(int psLevel, char *indent) { +GString *ASCIIHexStream::getPSFilter(int psLevel, const char *indent) { GString *s; if (psLevel < 2) { @@ -1011,7 +1011,7 @@ int ASCII85Stream::lookChar() { return b[index]; } -GString *ASCII85Stream::getPSFilter(int psLevel, char *indent) { +GString *ASCII85Stream::getPSFilter(int psLevel, const char *indent) { GString *s; if (psLevel < 2) { @@ -1197,7 +1197,7 @@ int LZWStream::getCode() { return code; } -GString *LZWStream::getPSFilter(int psLevel, char *indent) { +GString *LZWStream::getPSFilter(int psLevel, const char *indent) { GString *s; if (psLevel < 2 || pred) { @@ -1234,7 +1234,7 @@ void RunLengthStream::reset() { eof = gFalse; } -GString *RunLengthStream::getPSFilter(int psLevel, char *indent) { +GString *RunLengthStream::getPSFilter(int psLevel, const char *indent) { GString *s; if (psLevel < 2) { @@ -2388,7 +2388,7 @@ short CCITTFaxStream::lookBits(int n) { #endif -GString *CCITTFaxStream::getPSFilter(int psLevel, char *indent) { +GString *CCITTFaxStream::getPSFilter(int psLevel, const char *indent) { GString *s; char s1[50]; @@ -3829,7 +3829,7 @@ int DCTStream::read16() { return (c1 << 8) + c2; } -GString *DCTStream::getPSFilter(int psLevel, char *indent) { +GString *DCTStream::getPSFilter(int psLevel, const char *indent) { GString *s; if (psLevel < 2) { @@ -4026,7 +4026,7 @@ int FlateStream::getRawChar() { return c; } -GString *FlateStream::getPSFilter(int psLevel, char *indent) { +GString *FlateStream::getPSFilter(int psLevel, const char *indent) { GString *s; if (psLevel < 3 || pred) { @@ -4455,7 +4455,7 @@ void ASCIIHexEncoder::reset() { } GBool ASCIIHexEncoder::fillBuf() { - static char *hex = "0123456789abcdef"; + static const char *hex = "0123456789abcdef"; int c; if (eof) { diff --git a/src/plugins/pdf/Stream.h b/src/plugins/pdf/Stream.h @@ -88,7 +88,7 @@ public: virtual void setPos(Guint pos, int dir = 0) = 0; // Get PostScript command for the filter(s). - virtual GString *getPSFilter(int psLevel, char *indent); + virtual GString *getPSFilter(int psLevel, const char *indent); // Does this stream type potentially contain non-printable chars? virtual GBool isBinary(GBool last = gTrue) = 0; @@ -382,7 +382,7 @@ public: virtual int getChar() { int c = lookChar(); buf = EOF; return c; } virtual int lookChar(); - virtual GString *getPSFilter(int psLevel, char *indent); + virtual GString *getPSFilter(int psLevel, const char *indent); virtual GBool isBinary(GBool last = gTrue); private: @@ -405,7 +405,7 @@ public: virtual int getChar() { int ch = lookChar(); ++index; return ch; } virtual int lookChar(); - virtual GString *getPSFilter(int psLevel, char *indent); + virtual GString *getPSFilter(int psLevel, const char *indent); virtual GBool isBinary(GBool last = gTrue); private: @@ -431,7 +431,7 @@ public: virtual int getChar(); virtual int lookChar(); virtual int getRawChar(); - virtual GString *getPSFilter(int psLevel, char *indent); + virtual GString *getPSFilter(int psLevel, const char *indent); virtual GBool isBinary(GBool last = gTrue); private: @@ -475,7 +475,7 @@ public: { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); } virtual int lookChar() { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); } - virtual GString *getPSFilter(int psLevel, char *indent); + virtual GString *getPSFilter(int psLevel, const char *indent); virtual GBool isBinary(GBool last = gTrue); private: @@ -506,7 +506,7 @@ public: virtual int getChar() { int c = lookChar(); buf = EOF; return c; } virtual int lookChar(); - virtual GString *getPSFilter(int psLevel, char *indent); + virtual GString *getPSFilter(int psLevel, const char *indent); virtual GBool isBinary(GBool last = gTrue); private: @@ -578,7 +578,7 @@ public: virtual void reset(); virtual int getChar(); virtual int lookChar(); - virtual GString *getPSFilter(int psLevel, char *indent); + virtual GString *getPSFilter(int psLevel, const char *indent); virtual GBool isBinary(GBool last = gTrue); Stream *getRawStream() { return str; } @@ -679,7 +679,7 @@ public: virtual int getChar(); virtual int lookChar(); virtual int getRawChar(); - virtual GString *getPSFilter(int psLevel, char *indent); + virtual GString *getPSFilter(int psLevel, const char *indent); virtual GBool isBinary(GBool last = gTrue); private: @@ -728,7 +728,7 @@ public: virtual void reset() {} virtual int getChar() { return EOF; } virtual int lookChar() { return EOF; } - virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; } + virtual GString *getPSFilter(int psLevel, const char *indent) { return NULL; } virtual GBool isBinary(GBool last = gTrue) { return gFalse; } }; @@ -745,7 +745,7 @@ public: virtual void reset(); virtual int getChar(); virtual int lookChar(); - virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; } + virtual GString *getPSFilter(int psLevel, const char *indent) { return NULL; } virtual GBool isBinary(GBool last = gTrue); virtual GBool isEncoder() { return gTrue; } @@ -770,7 +770,7 @@ public: { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); } virtual int lookChar() { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); } - virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; } + virtual GString *getPSFilter(int psLevel, const char *indent) { return NULL; } virtual GBool isBinary(GBool last = gTrue) { return gFalse; } virtual GBool isEncoder() { return gTrue; } @@ -800,7 +800,7 @@ public: { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); } virtual int lookChar() { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); } - virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; } + virtual GString *getPSFilter(int psLevel, const char *indent) { return NULL; } virtual GBool isBinary(GBool last = gTrue) { return gFalse; } virtual GBool isEncoder() { return gTrue; } @@ -830,7 +830,7 @@ public: { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); } virtual int lookChar() { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); } - virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; } + virtual GString *getPSFilter(int psLevel, const char *indent) { return NULL; } virtual GBool isBinary(GBool last = gTrue) { return gTrue; } virtual GBool isEncoder() { return gTrue; } diff --git a/src/plugins/pdf/gfile.cc b/src/plugins/pdf/gfile.cc @@ -75,7 +75,7 @@ GString *getCurrentDir() { return new GString(); } -GString *appendToPath(GString *path, char *fileName) { +GString *appendToPath(GString *path, const char *fileName) { #if defined(WIN32) //---------- Win32 ---------- GString *tmp; diff --git a/src/plugins/pdf/gfile.h b/src/plugins/pdf/gfile.h @@ -33,7 +33,7 @@ extern GString *getCurrentDir(); // Append a file name to a path string. <path> may be an empty // string, denoting the current directory). Returns <path>. -extern GString *appendToPath(GString *path, char *fileName); +extern GString *appendToPath(GString *path, const char *fileName); // Grab the path from the front of the file name. If there is no // directory component in <fileName>, returns an empty string. diff --git a/src/plugins/pdf/pdfextractor.cc b/src/plugins/pdf/pdfextractor.cc @@ -60,12 +60,12 @@ extern "C" { static struct EXTRACTOR_Keywords * printInfoString(Dict *infoDict, - char *key, + const char *key, EXTRACTOR_KeywordType type, struct EXTRACTOR_Keywords * next) { Object obj; GString *s1; - char * s; + const char * s; if (infoDict->lookup(key, &obj)->isString()) { s1 = obj.getString(); @@ -74,12 +74,12 @@ extern "C" { (((unsigned char)s[1]) & 0xff) == 0xff) { char * result; - result = EXTRACTOR_common_convert_to_utf8((const char*) &s[2], s1->getLength() - 2, "UTF-16BE"); + result = EXTRACTOR_common_convert_to_utf8(&s[2], s1->getLength() - 2, "UTF-16BE"); next = addKeyword(type, result, next); } else { - unsigned int len = (NULL == s) ? 0 : strlen(s); + size_t len = strlen(s); while(0 < len) { /* @@ -119,7 +119,7 @@ extern "C" { } static struct EXTRACTOR_Keywords * printInfoDate(Dict *infoDict, - char *key, + const char *key, EXTRACTOR_KeywordType type, struct EXTRACTOR_Keywords * next) { Object obj; @@ -154,7 +154,7 @@ extern "C" { /* which mime-types should not be subjected to the PDF extractor? (no use trying!) */ - static char * blacklist[] = { + static const char * blacklist[] = { "image/jpeg", "image/gif", "image/png",