Commit 0892511b authored by Christophe Devriese's avatar Christophe Devriese
Browse files

Added lots and lots of const goodness

svn path=/trunk/kdegraphics/kpdf/; revision=254561
parent 03d825b1
......@@ -19,7 +19,7 @@
//------------------------------------------------------------------------
struct GHashBucket {
GString *key;
const GString *key;
void *val;
GHashBucket *next;
};
......@@ -96,7 +96,7 @@ void GHash::add(GString *key, void *val) {
++len;
}
void *GHash::lookup(GString *key) {
void *GHash::lookup(const GString *key) {
GHashBucket *p;
int h;
......@@ -106,7 +106,7 @@ void *GHash::lookup(GString *key) {
return p->val;
}
void *GHash::lookup(char *key) {
void *GHash::lookup(const char *key) {
GHashBucket *p;
int h;
......@@ -116,7 +116,7 @@ void *GHash::lookup(char *key) {
return p->val;
}
void *GHash::remove(GString *key) {
void *GHash::remove(const GString *key) {
GHashBucket *p;
GHashBucket **q;
void *val;
......@@ -139,7 +139,7 @@ void *GHash::remove(GString *key) {
return val;
}
void *GHash::remove(char *key) {
void *GHash::remove(const char *key) {
GHashBucket *p;
GHashBucket **q;
void *val;
......@@ -168,7 +168,7 @@ void GHash::startIter(GHashIter **iter) {
(*iter)->p = NULL;
}
GBool GHash::getNext(GHashIter **iter, GString **key, void **val) {
GBool GHash::getNext(GHashIter **iter, const GString **key, void **val) {
if (!*iter) {
return gFalse;
}
......@@ -193,7 +193,7 @@ void GHash::killIter(GHashIter **iter) {
*iter = NULL;
}
GHashBucket *GHash::find(GString *key, int *h) {
GHashBucket *GHash::find(const GString *key, int *h) {
GHashBucket *p;
*h = hash(key);
......@@ -205,7 +205,7 @@ GHashBucket *GHash::find(GString *key, int *h) {
return NULL;
}
GHashBucket *GHash::find(char *key, int *h) {
GHashBucket *GHash::find(const char *key, int *h) {
GHashBucket *p;
*h = hash(key);
......@@ -217,8 +217,8 @@ GHashBucket *GHash::find(char *key, int *h) {
return NULL;
}
int GHash::hash(GString *key) {
char *p;
int GHash::hash(const GString *key) {
const char *p;
unsigned int h;
int i;
......@@ -229,8 +229,8 @@ int GHash::hash(GString *key) {
return (int)(h % size);
}
int GHash::hash(char *key) {
char *p;
int GHash::hash(const char *key) {
const char *p;
unsigned int h;
h = 0;
......
......@@ -29,21 +29,24 @@ public:
GHash(GBool deleteKeysA = gFalse);
~GHash();
void add(GString *key, void *val);
void *lookup(GString *key);
void *lookup(char *key);
void *remove(GString *key);
void *remove(char *key);
void *lookup(const GString *key);
void *lookup(const char *key);
void *remove(const GString *key);
void *remove(const char *key);
int getLength() { return len; }
void startIter(GHashIter **iter);
GBool getNext(GHashIter **iter, GString **key, void **val);
GBool getNext(GHashIter **iter, const GString **key, void **val);
GBool getNext(GHashIter **iter, GString ** key, void ** val) {
return getNext(iter, const_cast<GString **> (key), val);
}
void killIter(GHashIter **iter);
private:
GHashBucket *find(GString *key, int *h);
GHashBucket *find(char *key, int *h);
int hash(GString *key);
int hash(char *key);
GHashBucket *find(const GString *key, int *h);
GHashBucket *find(const char *key, int *h);
int hash(const GString *key);
int hash(const char *key);
GBool deleteKeys; // set if key strings should be deleted
int size; // number of buckets
......
......@@ -49,10 +49,11 @@ public:
~GString();
// Get length.
int getLength() { return length; }
int getLength() const { return length; }
// Get C string.
char *getCString() { return s; }
const char *getCString() const { return s; }
char *getCString() { return s; }
// Get <i>th character.
char getChar(int i) { return s[i]; }
......@@ -84,10 +85,10 @@ public:
// Compare two strings: -1:< 0:= +1:>
// These functions assume the strings do not contain null characters.
int cmp(GString *str) { return strcmp(s, str->getCString()); }
int cmpN(GString *str, int n) { return strncmp(s, str->getCString(), n); }
int cmp(const char *sA) { return strcmp(s, sA); }
int cmpN(const char *sA, int n) { return strncmp(s, sA, n); }
int cmp(const GString *str) const { return strcmp(s, str->getCString()); }
int cmpN(const GString *str, int n) const { return strncmp(s, str->getCString(), n); }
int cmp(const char *sA) const { return strcmp(s, sA); }
int cmpN(const char *sA, int n) const { return strncmp(s, sA, n); }
private:
......
......@@ -108,7 +108,7 @@ GString *getCurrentDir() {
return new GString();
}
GString *appendToPath(GString *path, char *fileName) {
GString *appendToPath(GString *path, const char *fileName) {
#if defined(VMS)
//---------- VMS ----------
//~ this should handle everything necessary for file
......@@ -487,7 +487,7 @@ GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
int fd;
if (ext) {
#if HAVE_MKSTEMPS
#ifdef HAVE_MKSTEMPS
if ((s = getenv("TMPDIR"))) {
*name = new GString(s);
} else {
......
......@@ -60,7 +60,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.
......
......@@ -195,7 +195,7 @@ void gMemReport(FILE *f) {
}
#endif
char *copyString(char *s) {
char *copyString(const char *s) {
char *s1;
s1 = (char *)gmalloc(strlen(s) + 1);
......
......@@ -44,7 +44,7 @@ extern void gMemReport(FILE *f);
/*
* Allocate memory and copy a string into it.
*/
extern char *copyString(char *s);
extern char *copyString(const char *s);
#ifdef __cplusplus
}
......
......@@ -9,7 +9,7 @@
#ifndef COMPACTFONTINFO_H
#define COMPACTFONTINFO_H
static char *type1CStdStrings[391] = {
static const char *type1CStdStrings[391] = {
".notdef",
"space",
"exclam",
......
......@@ -21,8 +21,8 @@ static void md5(Guchar *msg, int msgLen, Guchar *digest);
static Guchar passwordPad[32] = {
0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41,
0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08,
0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80,
0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08,
0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80,
0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a
};
......@@ -125,7 +125,7 @@ GBool Decrypt::makeFileKey(int encVersion, int encRevision, int keyLength,
permissions, fileID, userPassword, fileKey);
}
GBool Decrypt::makeFileKey2(int encVersion, int encRevision, int keyLength,
GBool Decrypt::makeFileKey2(int /* encVersion */, int encRevision, int keyLength,
GString *ownerKey, GString *userKey,
int permissions, GString *fileID,
GString *userPassword, Guchar *fileKey) {
......
......@@ -34,13 +34,13 @@ Dict::~Dict() {
int i;
for (i = 0; i < length; ++i) {
gfree(entries[i].key);
gfree((void *) entries[i].key);
entries[i].val.free();
}
gfree(entries);
}
void Dict::add(char *key, Object *val) {
void Dict::add(const char *key, Object *val) {
if (length + 1 > size) {
size += 8;
entries = (DictEntry *)grealloc(entries, size * sizeof(DictEntry));
......@@ -50,7 +50,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) {
......@@ -60,25 +60,25 @@ 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();
}
char *Dict::getKey(int i) {
const char *Dict::getKey(int i) {
return entries[i].key;
}
......
......@@ -22,7 +22,7 @@
//------------------------------------------------------------------------
struct DictEntry {
char *key;
const char *key;
Object val;
};
......@@ -43,18 +43,18 @@ public:
int getLength() { return length; }
// Add an entry. NB: does not copy key.
void add(char *key, Object *val);
void add(const 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);
const char *getKey(int i);
Object *getVal(int i, Object *obj);
Object *getValNF(int i, Object *obj);
......@@ -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
......@@ -7,9 +7,9 @@
//========================================================================
static struct {
char *name;
char *xlfd;
char *encoding;
const char *name;
const char *xlfd;
const char *encoding;
} displayFontTab[] = {
{"Courier", "-*-courier-medium-r-normal-*-%s-*-*-*-*-*-iso8859-1", "Latin1"},
{"Courier-Bold", "-*-courier-bold-r-normal-*-%s-*-*-*-*-*-iso8859-1", "Latin1"},
......@@ -25,5 +25,5 @@ static struct {
{"Times-Italic", "-*-times-medium-i-normal-*-%s-*-*-*-*-*-iso8859-1", "Latin1"},
{"Times-Roman", "-*-times-medium-r-normal-*-%s-*-*-*-*-*-iso8859-1", "Latin1"},
{"ZapfDingbats", "-*-zapfdingbats-medium-r-normal-*-%s-*-*-*-*-*-*-*", "ZapfDingbats"},
{NULL}
{NULL, NULL, NULL}
};
......@@ -18,7 +18,7 @@
#include "GlobalParams.h"
#include "Error.h"
void CDECL error(int pos, char *msg, ...) {
void CDECL error(int pos, const char *msg, ...) {
va_list args;
// NB: this can be called before the globalParams object is created
......
......@@ -18,6 +18,6 @@
#include <stdio.h>
#include "config.h"
extern void CDECL error(int pos, char *msg, ...);
extern void CDECL error(int pos, const char *msg, ...);
#endif
......@@ -636,7 +636,7 @@ void Type1CFontFile::convertToType1(FontFileOutputFunc outputFuncA,
}
}
void Type1CFontFile::convertToCIDType0(char *psName,
void Type1CFontFile::convertToCIDType0(const char *psName,
FontFileOutputFunc outputFuncA,
void *outputStreamA) {
Type1CTopDict dict;
......@@ -954,7 +954,7 @@ void Type1CFontFile::convertToCIDType0(char *psName,
err0:;
}
void Type1CFontFile::convertToType0(char *psName,
void Type1CFontFile::convertToType0(const char *psName,
FontFileOutputFunc outputFuncA,
void *outputStreamA) {
Type1CTopDict dict;
......@@ -1532,7 +1532,7 @@ Gushort *Type1CFontFile::readCharset(int charset, int nGlyphs) {
return glyphNames;
}
void Type1CFontFile::eexecWrite(char *s) {
void Type1CFontFile::eexecWrite(const char *s) {
Guchar *p;
Guchar x;
......@@ -1549,7 +1549,7 @@ void Type1CFontFile::eexecWrite(char *s) {
}
}
void Type1CFontFile::eexecCvtGlyph(char *glyphName, int pos, int n) {
void Type1CFontFile::eexecCvtGlyph(const char *glyphName, int pos, int n) {
char eBuf[256];
cvtGlyph(pos, n, gTrue);
......@@ -2273,7 +2273,7 @@ void Type1CFontFile::eexecWriteCharstring(Guchar *s, int n) {
}
}
void Type1CFontFile::getDeltaInt(char *buf, char *key, double *opA,
void Type1CFontFile::getDeltaInt(char *buf, const char *key, double *opA,
int n) {
int x, i;
......@@ -2288,7 +2288,7 @@ void Type1CFontFile::getDeltaInt(char *buf, char *key, double *opA,
sprintf(buf, "] def\n");
}
void Type1CFontFile::getDeltaReal(char *buf, char *key, double *opA,
void Type1CFontFile::getDeltaReal(char *buf, const char *key, double *opA,
int n) {
double x;
int i;
......@@ -2536,7 +2536,7 @@ struct TTFontTableHdr {
};
struct T42Table {
char *tag; // 4-byte tag
const char *tag; // 4-byte tag
GBool required; // required by the TrueType spec?
};
......@@ -2562,7 +2562,7 @@ static T42Table t42Tables[nT42Tables] = {
// Glyph names in some arbitrary standard that Apple uses for their
// TrueType fonts.
static char *macGlyphNames[258] = {
static const char *macGlyphNames[258] = {
".notdef",
"null",
"CR",
......@@ -3067,7 +3067,7 @@ char **TrueTypeFontFile::getEncoding() {
return encoding;
}
void TrueTypeFontFile::convertToType42(char *name, char **encodingA,
void TrueTypeFontFile::convertToType42(const char *name, char **encodingA,
CharCodeToUnicode *toUnicode,
GBool pdfFontHasEncoding,
GBool pdfFontIsSymbolic,
......@@ -3101,7 +3101,7 @@ void TrueTypeFontFile::convertToType42(char *name, char **encodingA,
(*outputFunc)(outputStream, "FontName currentdict end definefont pop\n", 40);
}
void TrueTypeFontFile::convertToCIDType2(char *name, Gushort *cidMap,
void TrueTypeFontFile::convertToCIDType2(const char *name, Gushort *cidMap,
int nCIDs,
FontFileOutputFunc outputFunc,
void *outputStream) {
......@@ -3209,7 +3209,7 @@ void TrueTypeFontFile::convertToCIDType2(char *name, Gushort *cidMap,
56);
}
void TrueTypeFontFile::convertToType0(char *name, Gushort *cidMap,
void TrueTypeFontFile::convertToType0(const char *name, Gushort *cidMap,
int nCIDs,
FontFileOutputFunc outputFunc,
void *outputStream) {
......@@ -3345,7 +3345,7 @@ double TrueTypeFontFile::getFixed(int pos) {
return (double)x + (double)y / 65536;
}
int TrueTypeFontFile::seekTable(char *tag) {
int TrueTypeFontFile::seekTable(const char *tag) {
int i;
for (i = 0; i < nTables; ++i) {
......@@ -3356,7 +3356,7 @@ int TrueTypeFontFile::seekTable(char *tag) {
return -1;
}
int TrueTypeFontFile::seekTableIdx(char *tag) {
int TrueTypeFontFile::seekTableIdx(const char *tag) {
int i;
for (i = 0; i < nTables; ++i) {
......@@ -3373,7 +3373,7 @@ int TrueTypeFontFile::seekTableIdx(char *tag) {
void TrueTypeFontFile::cvtEncoding(char **encodingA, GBool pdfFontHasEncoding,
FontFileOutputFunc outputFunc,
void *outputStream) {
char *name;
const char *name;
char buf[64];
int i;
......@@ -4171,7 +4171,7 @@ void TrueTypeFontFile::writeTTF(FILE *out) {
}
}
}
gfree(tableDir);
gfree(newTableHdrs);
if (unsortedLoca) {
......
......@@ -24,7 +24,7 @@ class CharCodeToUnicode;
//------------------------------------------------------------------------
typedef void (*FontFileOutputFunc)(void *stream, char *data, int len);
typedef void (*FontFileOutputFunc)(void *stream, const char *data, int len);
//------------------------------------------------------------------------
// FontFile
......@@ -87,13 +87,13 @@ public:
// Convert to a Type 0 CIDFont, suitable for embedding in a
// PostScript file. The name will be used as the PostScript font
// name.
void convertToCIDType0(char *psName,
void convertToCIDType0(const char *psName,
FontFileOutputFunc outputFuncA, void *outputStreamA);
// Convert to a Type 0 (but non-CID) composite font, suitable for
// embedding in a PostScript file. The name will be used as the
// PostScript font name.
void convertToType0(char *psName,
void convertToType0(const char *psName,
FontFileOutputFunc outputFuncA, void *outputStreamA);
private:
......@@ -103,16 +103,16 @@ private:
void readPrivateDict(Type1CPrivateDict *privateDict,
int offset, int size);
Gushort *readCharset(int charset, int nGlyphs);
void eexecWrite(char *s);
void eexecCvtGlyph(char *glyphName, int pos, int n);
void eexecWrite(const char *s);
void eexecCvtGlyph(const char *glyphName, int pos, int n);
void cvtGlyph(int pos, int n, GBool top);
void cvtGlyphWidth(GBool useOp);
void eexecDumpNum(double x, GBool fpA);
void eexecDumpOp1(int opA);
void eexecDumpOp2(int opA);
void eexecWriteCharstring(Guchar *s, int n);
void getDeltaInt(char *buf, char *key, double *opA, int n);
void getDeltaReal(char *buf, char *key, double *opA, int n);
void getDeltaInt(char *buf, const char *key, double *opA, int n);
void getDeltaReal(char *buf, const char *key, double *opA, int n);
int getIndexLen(int indexPos);
int getIndexValPos(int indexPos, int i, int *valLen);
int getIndexEnd(int indexPos);
......@@ -175,7 +175,7 @@ public:
// don't need to depend on the 'name' table in the font). The
// encoding is needed because the PDF Font object can modify the
// encoding.
void convertToType42(char *name, char **encodingA,
void convertToType42(const char *name, char **encodingA,
CharCodeToUnicode *toUnicode,
GBool pdfFontHasEncoding,
GBool pdfFontIsSymbolic,
......@@ -185,14 +185,14 @@ public:
// PostScript file. The name will be used as the PostScript font
// name (so we don't need to depend on the 'name' table in the
// font).
void convertToCIDType2(char *name, Gushort *cidMap, int nCIDs,
void convertToCIDType2(const char *name, Gushort *cidMap, int nCIDs,
FontFileOutputFunc outputFunc, void *outputStream);
// Convert to a Type 0 (but non-CID) composite font, suitable for
// embedding in a PostScript file. The name will be used as the
// PostScript font name (so we don't need to depend on the 'name'
// table in the font).
void convertToType0(char *name, Gushort *cidMap, int nCIDs,
void convertToType0(const char *name, Gushort *cidMap, int nCIDs,
FontFileOutputFunc outputFunc, void *outputStream);
// Write a TTF file, filling in any missing tables that are required
......@@ -220,8 +220,8 @@ private:
int getShort(int pos);
Guint getULong(int pos);
double getFixed(int pos);
int seekTable(char *tag);
int seekTableIdx(char *tag);
int seekTable(const char *tag);
int seekTableIdx(const char *tag);
void cvtEncoding(char **encodingA, GBool pdfFontHasEncoding,
FontFileOutputFunc outputFunc, void *outputStream);
void cvtCharStrings(char **encodingA, CharCodeToUnicode *toUnicode,
......
......@@ -410,7 +410,7 @@ void SampledFunction::transform(double *in, double *out) {
// ExponentialFunction
//------------------------------------------------------------------------
ExponentialFunction::ExponentialFunction(Object *funcObj, Dict *dict) {
ExponentialFunction::ExponentialFunction(Object * /* funcObj */, Dict *dict) {
Object obj1, obj2;
int i;
......@@ -529,7 +529,7 @@ void ExponentialFunction::transform(double *in, double *out) {
// StitchingFunction
//------------------------------------------------------------------------
StitchingFunction::StitchingFunction(Object *funcObj, Dict *dict) {
StitchingFunction::StitchingFunction(Object * /* funcObj */, Dict *dict) {
Object obj1, obj2;
int i;
......
......@@ -671,17 +671,17 @@ int Gfx::getPos() {
// graphics state operators
//------------------------------------------------------------------------
void Gfx::opSave(Object args[], int numArgs) {
void Gfx::opSave(Object * /* args */, int /* numArgs */) {
out->saveState(state);
state = state->save();
}
void Gfx::opRestore(Object args[], int numArgs) {
void Gfx::opRestore(Object * /* args */, int /* numArgs */) {
state = state->restore();
out->restoreState(state);
}
void Gfx::opConcat(Object args[], int numArgs) {
void Gfx::opConcat(Object args[], int /* numArgs */) {
state->concatCTM(args[0].getNum(), args[1].getNum(),
args[2].getNum(), args[3].getNum(),
args[4].getNum(), args[5].getNum());
......@@ -691,7 +691,7 @@ void Gfx::opConcat(Object args[], int numArgs) {
fontChanged = gTrue;
}
void Gfx::opSetDash(Object args[], int numArgs) {
void Gfx::opSetDash(Object args[], int /* numArgs */) {
Array *