Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pdf/goo
diff options
context:
space:
mode:
authorMartin Kretzschmar <mkretzschmar@src.gnome.org>2002-09-18 18:58:15 (GMT)
committer Martin Kretzschmar <mkretzschmar@src.gnome.org>2002-09-18 18:58:15 (GMT)
commitd99fb4f4acd14fcdbda968abd907547dcc7af40c (patch)
treebbd52b808b583073e6d1d7c1043158fe8fd6fe4c /pdf/goo
parent28626f3d3c9aacc49c6f79353e7fcb2e49360b02 (diff)
Completely synched with Xpdf 0.90
doc changes (version numbers), typo fixes
Diffstat (limited to 'pdf/goo')
-rw-r--r--pdf/goo/GString.cc4
-rw-r--r--pdf/goo/GString.h4
-rw-r--r--pdf/goo/gfile.cc157
-rw-r--r--pdf/goo/gfile.h20
-rw-r--r--pdf/goo/gmem.c43
5 files changed, 162 insertions, 66 deletions
diff --git a/pdf/goo/GString.cc b/pdf/goo/GString.cc
index e089091..6225932 100644
--- a/pdf/goo/GString.cc
+++ b/pdf/goo/GString.cc
@@ -44,7 +44,7 @@ GString::GString() {
s[0] = '\0';
}
-GString::GString(char *s1) {
+GString::GString(const char *s1) {
int n = strlen(s1);
s = NULL;
@@ -52,7 +52,7 @@ GString::GString(char *s1) {
memcpy(s, s1, n + 1);
}
-GString::GString(char *s1, int length1) {
+GString::GString(const char *s1, int length1) {
s = NULL;
resize(length = length1);
memcpy(s, s1, length * sizeof(char));
diff --git a/pdf/goo/GString.h b/pdf/goo/GString.h
index 904f425..6fa24a6 100644
--- a/pdf/goo/GString.h
+++ b/pdf/goo/GString.h
@@ -24,11 +24,11 @@ public:
GString();
// Create a string from a C string.
- GString(char *s1);
+ GString(const char *s1);
// Create a string from <length1> chars at <s1>. This string
// can contain null characters.
- GString (char *s1, int length1);
+ GString (const char *s1, int length1);
// Copy a string.
GString(GString *str);
diff --git a/pdf/goo/gfile.cc b/pdf/goo/gfile.cc
index f6aac95..b57d9c8 100644
--- a/pdf/goo/gfile.cc
+++ b/pdf/goo/gfile.cc
@@ -8,22 +8,27 @@
//
//========================================================================
-#ifdef WIN32
extern "C" {
-#include <sys/stat.h>
-#include <kpathsea/win32lib.h>
-}
+#ifdef WIN32
+# include <sys/stat.h>
+# ifndef _MSC_VER
+# include <kpathsea/win32lib.h>
+# endif
#else // !WIN32
-#include <sys/stat.h>
-#include <limits.h>
-#include <string.h>
-#ifndef VMS
-#include <pwd.h>
-#endif
+# ifndef ACORN
+# include <sys/types.h>
+# include <sys/stat.h>
+# endif
+# include <limits.h>
+# include <string.h>
+# if !defined(VMS) && !defined(ACORN)
+# include <pwd.h>
+# endif
+# if defined(VMS) && (__DECCXX_VER < 50200000)
+# include <unixlib.h>
+# endif
#endif // WIN32
-#if defined(VMS) && (__DECCXX_VER < 50200000)
-#include <unixlib.h>
-#endif
+}
#include "GString.h"
#include "gfile.h"
@@ -51,6 +56,10 @@ GString *getHomeDir() {
ret = new GString(".");
return ret;
+#elif defined(ACORN)
+ //---------- RISCOS ----------
+ return new GString("@");
+
#else
//---------- Unix ----------
char *s;
@@ -77,14 +86,16 @@ GString *getCurrentDir() {
char buf[PATH_MAX+1];
#if defined(__EMX__)
- if (!_getcwd2(buf, sizeof(buf)))
+ if (_getcwd2(buf, sizeof(buf)))
#elif defined(WIN32)
- if (!GetCurrentDirectory(sizeof(buf), buf))
+ if (GetCurrentDirectory(sizeof(buf), buf))
+#elif defined(ACORN)
+ if (strcpy(buf, "@"))
#else
- if (!getcwd(buf, sizeof(buf)))
+ if (getcwd(buf, sizeof(buf)))
#endif
- return new GString();
- return new GString(buf);
+ return new GString(buf);
+ return new GString();
}
GString *appendToPath(GString *path, char *fileName) {
@@ -143,8 +154,25 @@ GString *appendToPath(GString *path, char *fileName) {
path->append(buf);
return path;
-#else
- //---------- Unix and OS/2+EMX ----------
+#elif defined(ACORN)
+ //---------- RISCOS ----------
+ char *p;
+ int i;
+
+ path->append(".");
+ i = path->getLength();
+ path->append(fileName);
+ for (p = path->getCString() + i; *p; ++p) {
+ if (*p == '/') {
+ *p = '.';
+ } else if (*p == '.') {
+ *p = '/';
+ }
+ }
+ return path;
+
+#elif defined(__EMX__)
+ //---------- OS/2+EMX ----------
int i;
// appending "." does nothing
@@ -154,51 +182,65 @@ GString *appendToPath(GString *path, char *fileName) {
// appending ".." goes up one directory
if (!strcmp(fileName, "..")) {
for (i = path->getLength() - 2; i >= 0; --i) {
-#ifdef __EMX__
if (path->getChar(i) == '/' || path->getChar(i) == '\\' ||
path->getChar(i) == ':')
-#else
- if (path->getChar(i) == '/')
-#endif
break;
}
if (i <= 0) {
-#ifdef __EMX__
- if (path->getChar[0] == '/' || path->getChar[0] == '\\') {
+ if (path->getChar(0) == '/' || path->getChar(0) == '\\') {
path->del(1, path->getLength() - 1);
- } else if (path->getLength() >= 2 && path->getChar[1] == ':') {
+ } else if (path->getLength() >= 2 && path->getChar(1) == ':') {
path->del(2, path->getLength() - 2);
} else {
path->clear();
path->append("..");
}
+ } else {
+ if (path->getChar(i-1) == ':')
+ ++i;
+ path->del(i, path->getLength() - i);
+ }
+ return path;
+ }
+
+ // otherwise, append "/" and new path component
+ if (path->getLength() > 0 &&
+ path->getChar(path->getLength() - 1) != '/' &&
+ path->getChar(path->getLength() - 1) != '\\')
+ path->append('/');
+ path->append(fileName);
+ return path;
+
#else
+ //---------- Unix ----------
+ int i;
+
+ // appending "." does nothing
+ if (!strcmp(fileName, "."))
+ return path;
+
+ // appending ".." goes up one directory
+ if (!strcmp(fileName, "..")) {
+ for (i = path->getLength() - 2; i >= 0; --i) {
+ if (path->getChar(i) == '/')
+ break;
+ }
+ if (i <= 0) {
if (path->getChar(0) == '/') {
path->del(1, path->getLength() - 1);
} else {
path->clear();
path->append("..");
}
-#endif
} else {
-#ifdef __EMX__
- if (path->getChar(i) == ':')
- ++i;
-#endif
path->del(i, path->getLength() - i);
}
return path;
}
// otherwise, append "/" and new path component
-#ifdef __EMX__
- if (path->getLength() > 0 &&
- path->getChar(path->getLength() - 1) != '/' &&
- path->getChar(path->getLength() - 1) != '\\')
-#else
if (path->getLength() > 0 &&
path->getChar(path->getLength() - 1) != '/')
-#endif
path->append('/');
path->append(fileName);
return path;
@@ -228,6 +270,14 @@ GString *grabPath(char *fileName) {
return new GString(fileName, p + 1 - fileName);
return new GString();
+#elif defined(ACORN)
+ //---------- RISCOS ----------
+ char *p;
+
+ if ((p = strrchr(fileName, '.')))
+ return new GString(fileName, p - fileName);
+ return new GString();
+
#else
//---------- Unix ----------
char *p;
@@ -248,6 +298,10 @@ GBool isAbsolutePath(char *path) {
//---------- OS/2+EMX and Win32 ----------
return path[0] == '/' || path[0] == '\\' || path[1] == ':';
+#elif defined(ACORN)
+ //---------- RISCOS ----------
+ return path[0] == '$';
+
#else
//---------- Unix ----------
return path[0] == '/';
@@ -274,7 +328,7 @@ GString *makePathAbsolute(GString *path) {
}
return path;
-#elif WIN32
+#elif defined(WIN32)
//---------- Win32 ----------
char buf[_MAX_PATH];
char *fp;
@@ -288,6 +342,11 @@ GString *makePathAbsolute(GString *path) {
path->append(buf);
return path;
+#elif defined(ACORN)
+ //---------- RISCOS ----------
+ path->insert(0, '@');
+ return path;
+
#else
//---------- Unix and OS/2+EMX ----------
struct passwd *pw;
@@ -324,7 +383,9 @@ GString *makePathAbsolute(GString *path) {
}
} else if (!isAbsolutePath(path->getCString())) {
if (getcwd(buf, sizeof(buf))) {
+#ifndef __EMX__
path->insert(0, '/');
+#endif
path->insert(0, buf);
}
}
@@ -339,9 +400,10 @@ GString *makePathAbsolute(GString *path) {
GDirEntry::GDirEntry(char *dirPath, char *name1, GBool doStat) {
#ifdef VMS
char *p;
-#elif WIN32
+#elif defined(WIN32)
int fa;
GString *s;
+#elif defined(ACORN)
#else
struct stat st;
GString *s;
@@ -354,6 +416,7 @@ GDirEntry::GDirEntry(char *dirPath, char *name1, GBool doStat) {
if (!strcmp(name1, "-") ||
((p = strrchr(name1, '.')) && !strncmp(p, ".DIR;", 5)))
dir = gTrue;
+#elif defined(ACORN)
#else
s = new GString(dirPath);
appendToPath(s, name1);
@@ -376,28 +439,30 @@ GDirEntry::~GDirEntry() {
GDir::GDir(char *name, GBool doStat1) {
path = new GString(name);
doStat = doStat1;
-#ifdef WIN32
+#if defined(WIN32)
GString *tmp;
tmp = path->copy();
tmp->append("/*.*");
hnd = FindFirstFile(tmp->getCString(), &ffd);
delete tmp;
+#elif defined(ACORN)
#else
dir = opendir(name);
-#endif
#ifdef VMS
needParent = strchr(name, '[') != NULL;
#endif
+#endif
}
GDir::~GDir() {
delete path;
-#ifdef WIN32
+#if defined(WIN32)
if (hnd) {
FindClose(hnd);
hnd = NULL;
}
+#elif defined(ACORN)
#else
if (dir)
closedir(dir);
@@ -409,12 +474,13 @@ GDirEntry *GDir::getNextEntry() {
GDirEntry *e;
e = NULL;
-#ifdef WIN32
+#if defined(WIN32)
e = new GDirEntry(path->getCString(), ffd.cFileName, doStat);
if (hnd && !FindNextFile(hnd, &ffd)) {
FindClose(hnd);
hnd = NULL;
}
+#elif defined(ACORN)
#else
if (dir) {
#ifdef VMS
@@ -445,11 +511,12 @@ void GDir::rewind() {
tmp = path->copy();
tmp->append("/*.*");
hnd = FindFirstFile(tmp->getCString(), &ffd);
+#elif defined(ACORN)
#else
if (dir)
rewinddir(dir);
-#endif
#ifdef VMS
needParent = strchr(path->getCString(), '[') != NULL;
#endif
+#endif
}
diff --git a/pdf/goo/gfile.h b/pdf/goo/gfile.h
index f1923cd..bb4dbe0 100644
--- a/pdf/goo/gfile.h
+++ b/pdf/goo/gfile.h
@@ -11,10 +11,16 @@
#ifndef GFILE_H
#define GFILE_H
+extern "C" {
#include <stdlib.h>
#include <stddef.h>
-#ifdef WIN32
-# include <kpathsea/win32lib.h>
+#if defined(WIN32)
+# ifdef _MSC_VER
+# include <windows.h>
+# else
+# include <kpathsea/win32lib.h>
+# endif
+#elif defined(ACORN)
#else
# include <unistd.h>
# include <sys/types.h>
@@ -37,6 +43,7 @@
# endif
# endif
#endif
+}
#include "gtypes.h"
class GString;
@@ -94,14 +101,15 @@ private:
GString *path; // directory path
GBool doStat; // call stat() for each entry?
-#ifdef VMS
- GBool needParent; // need to return an entry for [-]
-#endif
-#ifdef WIN32
+#if defined(WIN32)
WIN32_FIND_DATA ffd;
HANDLE hnd;
+#elif defined(ACORN)
#else
DIR *dir; // the DIR structure from opendir()
+#ifdef VMS
+ GBool needParent; // need to return an entry for [-]
+#endif
#endif
};
diff --git a/pdf/goo/gmem.c b/pdf/goo/gmem.c
index 4ae5481..cac386b 100644
--- a/pdf/goo/gmem.c
+++ b/pdf/goo/gmem.c
@@ -13,6 +13,7 @@
#include "gmem.h"
#ifdef DEBUG_MEM
+
typedef struct _GMemHdr {
int size;
int index;
@@ -26,24 +27,38 @@ typedef struct _GMemHdr {
#define gMemDeadVal 0xdeadbeefdeadbeef
#else
#define gMemDeadVal 0xdeadbeef
+#endif
/* round data size so trailer will be aligned */
#define gMemDataSize(size) \
((((size) + gMemTrlSize - 1) / gMemTrlSize) * gMemTrlSize)
-#endif
+#define gMemNLists 64
+#define gMemListShift 4
+#define gMemListMask (gMemNLists - 1)
+static GMemHdr *gMemList[gMemNLists] = {
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+};
-static GMemHdr *gMemList = NULL;
static int gMemIndex = 0;
static int gMemAlloc = 0;
-#endif
+
+#endif /* DEBUG_MEM */
void *gmalloc(int size) {
-#if DEBUG_MEM
+#ifdef DEBUG_MEM
int size1;
char *mem;
GMemHdr *hdr;
void *data;
+ int lst;
long *trl, *p;
if (size == 0)
@@ -58,8 +73,9 @@ void *gmalloc(int size) {
trl = (long *)(mem + gMemHdrSize + size1);
hdr->size = size;
hdr->index = gMemIndex++;
- hdr->next = gMemList;
- gMemList = hdr;
+ lst = ((int)hdr >> gMemListShift) & gMemListMask;
+ hdr->next = gMemList[lst];
+ gMemList[lst] = hdr;
++gMemAlloc;
for (p = (long *)data; p <= trl; ++p)
*p = gMemDeadVal;
@@ -78,7 +94,7 @@ void *gmalloc(int size) {
}
void *grealloc(void *p, int size) {
-#if DEBUG_MEM
+#ifdef DEBUG_MEM
GMemHdr *hdr;
void *q;
int oldSize;
@@ -123,11 +139,13 @@ void gfree(void *p) {
int size;
GMemHdr *hdr;
GMemHdr *prevHdr, *q;
+ int lst;
long *trl, *clr;
if (p) {
hdr = (GMemHdr *)((char *)p - gMemHdrSize);
- for (prevHdr = NULL, q = gMemList; q; prevHdr = q, q = q->next) {
+ lst = ((int)hdr >> gMemListShift) & gMemListMask;
+ for (prevHdr = NULL, q = gMemList[lst]; q; prevHdr = q, q = q->next) {
if (q == hdr)
break;
}
@@ -135,7 +153,7 @@ void gfree(void *p) {
if (prevHdr)
prevHdr->next = hdr->next;
else
- gMemList = hdr->next;
+ gMemList[lst] = hdr->next;
--gMemAlloc;
size = gMemDataSize(hdr->size);
trl = (long *)((char *)hdr + gMemHdrSize + size);
@@ -159,14 +177,17 @@ void gfree(void *p) {
#ifdef DEBUG_MEM
void gMemReport(FILE *f) {
GMemHdr *p;
+ int lst;
fprintf(f, "%d memory allocations in all\n", gMemIndex);
if (gMemAlloc > 0) {
fprintf(f, "%d memory blocks left allocated:\n", gMemAlloc);
fprintf(f, " index size\n");
fprintf(f, "-------- --------\n");
- for (p = gMemList; p; p = p->next)
- fprintf(f, "%8d %8d\n", p->index, p->size);
+ for (lst = 0; lst < gMemNLists; ++lst) {
+ for (p = gMemList[lst]; p; p = p->next)
+ fprintf(f, "%8d %8d\n", p->index, p->size);
+ }
} else {
fprintf(f, "No memory blocks left allocated\n");
}