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 20:32:18 (GMT)
committer Martin Kretzschmar <mkretzschmar@src.gnome.org>2002-09-18 20:32:18 (GMT)
commit7aac8dc8533347e21311b15186e0af82f1b22fd6 (patch)
tree02650bb02c8a1d8468c22f50ff151885d233016b /pdf/goo
parentd99fb4f4acd14fcdbda968abd907547dcc7af40c (diff)
Synched with Xpdf 0.92
this adds "decryption" support testing this code after six weeks immediately gives me segfaults (image drawing) :-O must have fixed that later without knowing :-O
Diffstat (limited to 'pdf/goo')
-rw-r--r--pdf/goo/.cvsignore1
-rw-r--r--pdf/goo/GString.cc35
-rw-r--r--pdf/goo/GString.h15
-rw-r--r--pdf/goo/gfile.cc138
-rw-r--r--pdf/goo/gfile.h29
-rw-r--r--pdf/goo/gmempp.cc14
-rw-r--r--pdf/goo/vms_make.com82
7 files changed, 270 insertions, 44 deletions
diff --git a/pdf/goo/.cvsignore b/pdf/goo/.cvsignore
index e995588..e7315c7 100644
--- a/pdf/goo/.cvsignore
+++ b/pdf/goo/.cvsignore
@@ -1,3 +1,4 @@
.deps
Makefile
Makefile.in
+semantic.cache
diff --git a/pdf/goo/GString.cc b/pdf/goo/GString.cc
index 6225932..7b8f271 100644
--- a/pdf/goo/GString.cc
+++ b/pdf/goo/GString.cc
@@ -16,6 +16,7 @@
#include <stddef.h>
#include <string.h>
#include <ctype.h>
+#include "gtypes.h"
#include "GString.h"
static inline int size(int len) {
@@ -75,6 +76,32 @@ GString::GString(GString *str1, GString *str2) {
memcpy(s + n1, str2->getCString(), n2 + 1);
}
+GString *GString::fromInt(int x) {
+ char buf[24]; // enough space for 64-bit ints plus a little extra
+ GBool neg;
+ Guint y;
+ int i;
+
+ i = 24;
+ if (x == 0) {
+ buf[--i] = '0';
+ } else {
+ if ((neg = x < 0)) {
+ y = (Guint)-x;
+ } else {
+ y = (Guint)x;
+ }
+ while (i > 0 && y > 0) {
+ buf[--i] = '0' + y % 10;
+ y /= 10;
+ }
+ if (neg && i > 0) {
+ buf[--i] = '-';
+ }
+ }
+ return new GString(buf + i, 24 - i);
+}
+
GString::~GString() {
delete[] s;
}
@@ -101,7 +128,7 @@ GString *GString::append(GString *str) {
return this;
}
-GString *GString::append(char *str) {
+GString *GString::append(const char *str) {
int n = strlen(str);
resize(length + n);
@@ -110,7 +137,7 @@ GString *GString::append(char *str) {
return this;
}
-GString *GString::append(char *str, int length1) {
+GString *GString::append(const char *str, int length1) {
resize(length + length1);
memcpy(s + length, str, length1);
length += length1;
@@ -141,7 +168,7 @@ GString *GString::insert(int i, GString *str) {
return this;
}
-GString *GString::insert(int i, char *str) {
+GString *GString::insert(int i, const char *str) {
int n = strlen(str);
int j;
@@ -153,7 +180,7 @@ GString *GString::insert(int i, char *str) {
return this;
}
-GString *GString::insert(int i, char *str, int length1) {
+GString *GString::insert(int i, const char *str, int length1) {
int j;
resize(length + length1);
diff --git a/pdf/goo/GString.h b/pdf/goo/GString.h
index 6fa24a6..4c3b95f 100644
--- a/pdf/goo/GString.h
+++ b/pdf/goo/GString.h
@@ -37,6 +37,9 @@ public:
// Concatenate two strings.
GString(GString *str1, GString *str2);
+ // Convert an integer to a string.
+ static GString *fromInt(int x);
+
// Destructor.
~GString();
@@ -58,14 +61,14 @@ public:
// Append a character or string.
GString *append(char c);
GString *append(GString *str);
- GString *append(char *str);
- GString *append(char *str, int length1);
+ GString *append(const char *str);
+ GString *append(const char *str, int length1);
// Insert a character or string.
GString *insert(int i, char c);
GString *insert(int i, GString *str);
- GString *insert(int i, char *str);
- GString *insert(int i, char *str, int length1);
+ GString *insert(int i, const char *str);
+ GString *insert(int i, const char *str, int length1);
// Delete a character or range of characters.
GString *del(int i, int n = 1);
@@ -78,8 +81,8 @@ public:
// 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(char *s1) { return strcmp(s, s1); }
- int cmpN(char *s1, int n) { return strncmp(s, s1, n); }
+ int cmp(const char *s1) { return strcmp(s, s1); }
+ int cmpN(const char *s1, int n) { return strncmp(s, s1, n); }
private:
diff --git a/pdf/goo/gfile.cc b/pdf/goo/gfile.cc
index b57d9c8..25fa1c9 100644
--- a/pdf/goo/gfile.cc
+++ b/pdf/goo/gfile.cc
@@ -10,18 +10,20 @@
extern "C" {
#ifdef WIN32
-# include <sys/stat.h>
# ifndef _MSC_VER
# include <kpathsea/win32lib.h>
# endif
#else // !WIN32
-# ifndef ACORN
+# if defined(MACOS)
+# include <sys/stat.h>
+# elif !defined(ACORN)
# include <sys/types.h>
# include <sys/stat.h>
+# include <fcntl.h>
# endif
# include <limits.h>
# include <string.h>
-# if !defined(VMS) && !defined(ACORN)
+# if !defined(VMS) && !defined(ACORN) && !defined(MACOS)
# include <pwd.h>
# endif
# if defined(VMS) && (__DECCXX_VER < 50200000)
@@ -60,6 +62,10 @@ GString *getHomeDir() {
//---------- RISCOS ----------
return new GString("@");
+#elif defined(MACOS)
+ //---------- MacOS ----------
+ return new GString(":");
+
#else
//---------- Unix ----------
char *s;
@@ -91,6 +97,8 @@ GString *getCurrentDir() {
if (GetCurrentDirectory(sizeof(buf), buf))
#elif defined(ACORN)
if (strcpy(buf, "@"))
+#elif defined(MACOS)
+ if (strcpy(buf, ":"))
#else
if (getcwd(buf, sizeof(buf)))
#endif
@@ -171,6 +179,23 @@ GString *appendToPath(GString *path, char *fileName) {
}
return path;
+#elif defined(MACOS)
+ //---------- MacOS ----------
+ 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;
@@ -278,6 +303,14 @@ GString *grabPath(char *fileName) {
return new GString(fileName, p - fileName);
return new GString();
+#elif defined(MACOS)
+ //---------- MacOS ----------
+ char *p;
+
+ if ((p = strrchr(fileName, ':')))
+ return new GString(fileName, p - fileName);
+ return new GString();
+
#else
//---------- Unix ----------
char *p;
@@ -302,6 +335,10 @@ GBool isAbsolutePath(char *path) {
//---------- RISCOS ----------
return path[0] == '$';
+#elif defined(MACOS)
+ //---------- MacOS ----------
+ return path[0] != ':';
+
#else
//---------- Unix ----------
return path[0] == '/';
@@ -315,15 +352,7 @@ GString *makePathAbsolute(GString *path) {
if (!isAbsolutePath(path->getCString())) {
if (getcwd(buf, sizeof(buf))) {
- if (path->getChar(0) == '[') {
- if (path->getChar(1) != '.')
- path->insert(0, '.');
- path->insert(0, buf);
- } else {
- path->insert(0, '[');
- path->insert(1, ']');
- path->insert(1, buf);
- }
+ path->insert(0, buf);
}
}
return path;
@@ -347,6 +376,11 @@ GString *makePathAbsolute(GString *path) {
path->insert(0, '@');
return path;
+#elif defined(MACOS)
+ //---------- MacOS ----------
+ path->del(0, 1);
+ return path;
+
#else
//---------- Unix and OS/2+EMX ----------
struct passwd *pw;
@@ -393,6 +427,82 @@ GString *makePathAbsolute(GString *path) {
#endif
}
+time_t getModTime(char *fileName) {
+#ifdef WIN32
+ //~ should implement this, but it's (currently) only used in xpdf
+ return 0;
+#else
+ struct stat statBuf;
+
+ if (stat(fileName, &statBuf)) {
+ return 0;
+ }
+ return statBuf.st_mtime;
+#endif
+}
+
+GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
+#if defined(VMS) || defined(__EMX__) || defined(WIN32) || defined(ACORN) || defined(MACOS)
+ //---------- non-Unix ----------
+ char *s;
+
+ // There is a security hole here: an attacker can create a symlink
+ // with this file name after the tmpnam call and before the fopen
+ // call. I will happily accept fixes to this function for non-Unix
+ // OSs.
+ if (!(s = tmpnam(NULL))) {
+ return gFalse;
+ }
+ *name = new GString(s);
+ if (ext) {
+ (*name)->append(ext);
+ }
+ if (!(*f = fopen((*name)->getCString(), mode))) {
+ delete (*name);
+ return gFalse;
+ }
+ return gTrue;
+#else
+ //---------- Unix ----------
+ char *s, *p;
+ int fd;
+
+ if (ext) {
+ if (!(s = tmpnam(NULL))) {
+ return gFalse;
+ }
+ *name = new GString(s);
+ s = (*name)->getCString();
+ if ((p = strrchr(s, '.'))) {
+ (*name)->del(p - s, (*name)->getLength() - (p - s));
+ }
+ (*name)->append(ext);
+ fd = open((*name)->getCString(), O_WRONLY | O_CREAT | O_EXCL, 0600);
+ } else {
+#if HAVE_MKSTEMP
+ if ((s = getenv("TMPDIR"))) {
+ *name = new GString(s);
+ } else {
+ *name = new GString("/tmp");
+ }
+ (*name)->append("/XXXXXX");
+ fd = mkstemp((*name)->getCString());
+#else // HAVE_MKSTEMP
+ if (!(s = tmpnam(NULL))) {
+ return gFalse;
+ }
+ *name = new GString(s);
+ fd = open((*name)->getCString(), O_WRONLY | O_CREAT | O_EXCL, 0600);
+#endif // HAVE_MKSTEMP
+ }
+ if (fd < 0 || !(*f = fdopen(fd, mode))) {
+ delete *name;
+ return gFalse;
+ }
+ return gTrue;
+#endif
+}
+
//------------------------------------------------------------------------
// GDir and GDirEntry
//------------------------------------------------------------------------
@@ -447,6 +557,7 @@ GDir::GDir(char *name, GBool doStat1) {
hnd = FindFirstFile(tmp->getCString(), &ffd);
delete tmp;
#elif defined(ACORN)
+#elif defined(MACOS)
#else
dir = opendir(name);
#ifdef VMS
@@ -463,6 +574,7 @@ GDir::~GDir() {
hnd = NULL;
}
#elif defined(ACORN)
+#elif defined(MACOS)
#else
if (dir)
closedir(dir);
@@ -481,6 +593,7 @@ GDirEntry *GDir::getNextEntry() {
hnd = NULL;
}
#elif defined(ACORN)
+#elif defined(MACOS)
#else
if (dir) {
#ifdef VMS
@@ -512,6 +625,7 @@ void GDir::rewind() {
tmp->append("/*.*");
hnd = FindFirstFile(tmp->getCString(), &ffd);
#elif defined(ACORN)
+#elif defined(MACOS)
#else
if (dir)
rewinddir(dir);
diff --git a/pdf/goo/gfile.h b/pdf/goo/gfile.h
index bb4dbe0..38b9998 100644
--- a/pdf/goo/gfile.h
+++ b/pdf/goo/gfile.h
@@ -11,16 +11,20 @@
#ifndef GFILE_H
#define GFILE_H
-extern "C" {
+#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
+extern "C" {
#if defined(WIN32)
-# ifdef _MSC_VER
-# include <windows.h>
+# include <sys/stat.h>
+# ifdef FPTEX
+# include <win32lib.h>
# else
-# include <kpathsea/win32lib.h>
+# include <windows.h>
# endif
#elif defined(ACORN)
+#elif defined(MACOS)
+# include <ctime.h>
#else
# include <unistd.h>
# include <sys/types.h>
@@ -28,10 +32,10 @@ extern "C" {
# include "vms_dirent.h"
# elif HAVE_DIRENT_H
# include <dirent.h>
-# define NAMLEN(dirent) strlen((dirent)->d_name)
+# define NAMLEN(d) strlen((d)->d_name)
# else
# define dirent direct
-# define NAMLEN(dirent) (dirent)->d_namlen
+# define NAMLEN(d) (d)->d_namlen
# if HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
@@ -71,6 +75,18 @@ extern GBool isAbsolutePath(char *path);
// relative) or prepending user's directory (if path starts with '~').
GString *makePathAbsolute(GString *path);
+// Get the modification time for <fileName>. Returns 0 if there is an
+// error.
+time_t getModTime(char *fileName);
+
+// Create a temporary file and open it for writing. If <ext> is not
+// NULL, it will be used as the file name extension. Returns both the
+// name and the file pointer. For security reasons, all writing
+// should be done to the returned file pointer; the file may be
+// reopened later for reading, but not for writing. The <mode> string
+// should be "w" or "wb". Returns true on success.
+GBool openTempFile(GString **name, FILE **f, char *mode, char *ext);
+
//------------------------------------------------------------------------
// GDir and GDirEntry
//------------------------------------------------------------------------
@@ -105,6 +121,7 @@ private:
WIN32_FIND_DATA ffd;
HANDLE hnd;
#elif defined(ACORN)
+#elif defined(MACOS)
#else
DIR *dir; // the DIR structure from opendir()
#ifdef VMS
diff --git a/pdf/goo/gmempp.cc b/pdf/goo/gmempp.cc
index 41dd441..6eb6494 100644
--- a/pdf/goo/gmempp.cc
+++ b/pdf/goo/gmempp.cc
@@ -11,13 +11,21 @@
#include "gmem.h"
#ifdef DEBUG_MEM
-void *operator new(long size) {
+
+void *operator new(size_t size) {
+ return gmalloc((int)size);
+}
+
+void *operator new[](size_t size) {
return gmalloc((int)size);
}
-#endif
-#ifdef DEBUG_MEM
void operator delete(void *p) {
gfree(p);
}
+
+void operator delete[](void *p) {
+ gfree(p);
+}
+
#endif
diff --git a/pdf/goo/vms_make.com b/pdf/goo/vms_make.com
index 88b6458..454c1ff 100644
--- a/pdf/goo/vms_make.com
+++ b/pdf/goo/vms_make.com
@@ -2,25 +2,81 @@ $!========================================================================
$!
$! Goo library compile script for VMS.
$!
+$! Written by Patrick Moreau, Martin P.J. Zinser.
+$!
$! Copyright 1996 Derek B. Noonburg
$!
$!========================================================================
$!
-$ GOO_OBJS = "GString.obj,gmempp.obj,gfile.obj,gmem.obj,parseargs.obj" + -
- ",vms_directory.obj,vms_unix_times.obj"
+$ GOO_CXXOBJS = "GString.obj,gmempp.obj,gfile.obj"
+$ GOO_CCOBJS = "gmem.obj,parseargs.obj,vms_directory.obj,vms_unix_times.obj"
+$!
$ if f$extract(1,3,f$getsyi("Version")) .lts. "7.0"
$ then
-$ GOO_OBJS = GOO_OBJS + ",vms_unlink.obj"
-$ CCOMP vms_unlink.c
+$ GOO_CCOBJS = GOO_CCOBJS + ",vms_unlink.obj"
$ endif
$!
-$ CXXCOMP GString.cc
-$ CXXCOMP gmempp.cc
-$ CXXCOMP gfile.cc
-$ CCOMP gmem.c
-$ CCOMP parseargs.c
-$ CCOMP vms_directory.c
-$ CCOMP vms_unix_times.c
+$ i = 0
+$ j = 0
+$COMPILE_CXX_LOOP:
+$ file = f$element(i, ",",GOO_CXXOBJS)
+$ if file .eqs. "," then goto COMPILE_CC_LOOP
+$ i = i + 1
+$ name = f$parse(file,,,"NAME")
+$ call make 'file "CXXCOMP ''name'.cc" -
+ 'name'.cc
+$ goto COMPILE_CXX_LOOP
+$!
+$COMPILE_CC_LOOP:
+$ file = f$element(j, ",",GOO_CCOBJS)
+$ if file .eqs. "," then goto COMPILE_END
+$ j = j + 1
+$ name = f$parse(file,,,"NAME")
+$ call make 'file "CCOMP ''name'.c" -
+ 'name'.c
+$ goto COMPILE_CC_LOOP
+$!
+$COMPILE_END:
+$ call make libgoo.olb "lib/cre libgoo.olb ''GOO_CXXOBJS',''GOO_CCOBJS'" *.obj
+$!
+$ exit
$!
-$ lib/cre libgoo.olb
-$ lib libgoo 'GOO_OBJS
+$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
+$ V = 'F$Verify(0)
+$! P1 = What we are trying to make
+$! P2 = Command to make it
+$! P3 - P8 What it depends on
+$
+$ If F$Search(P1) .Eqs. "" Then Goto Makeit
+$ Time = F$CvTime(F$File(P1,"RDT"))
+$arg=3
+$Loop:
+$ Argument = P'arg
+$ If Argument .Eqs. "" Then Goto Exit
+$ El=0
+$Loop2:
+$ File = F$Element(El," ",Argument)
+$ If File .Eqs. " " Then Goto Endl
+$ AFile = ""
+$Loop3:
+$ OFile = AFile
+$ AFile = F$Search(File)
+$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
+$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
+$ Goto Loop3
+$NextEL:
+$ El = El + 1
+$ Goto Loop2
+$EndL:
+$ arg=arg+1
+$ If arg .Le. 8 Then Goto Loop
+$ Goto Exit
+$
+$Makeit:
+$ VV=F$VERIFY(0)
+$ write sys$output P2
+$ 'P2
+$ VV='F$Verify(VV)
+$Exit:
+$ If V Then Set Verify
+$ENDSUBROUTINE