author | sandman <sandman> | 2002-04-13 00:47:20 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-04-13 00:47:20 (UTC) |
commit | 98a1e3f36567639344f12932b629e526a8783aa8 (patch) (unidiff) | |
tree | 0433d296857faceeafc54f7deabddb621f45a933 /noncore/unsupported/qpdf/goo | |
parent | 7e31b1fba119f69929d6744d7295555ff1727f4f (diff) | |
download | opie-98a1e3f36567639344f12932b629e526a8783aa8.zip opie-98a1e3f36567639344f12932b629e526a8783aa8.tar.gz opie-98a1e3f36567639344f12932b629e526a8783aa8.tar.bz2 |
CVS import of QPdf
Diffstat (limited to 'noncore/unsupported/qpdf/goo') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/goo/GHash.cc | 240 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/goo/GHash.h | 67 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/goo/GList.cc | 91 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/goo/GList.h | 89 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/goo/GString.cc | 231 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/goo/GString.h | 98 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/goo/gfile.h | 135 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/goo/gmem.h | 53 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/goo/gtypes.h | 29 |
9 files changed, 1033 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/goo/GHash.cc b/noncore/unsupported/qpdf/goo/GHash.cc new file mode 100644 index 0000000..9ef6bb1 --- a/dev/null +++ b/noncore/unsupported/qpdf/goo/GHash.cc | |||
@@ -0,0 +1,240 @@ | |||
1 | //======================================================================== | ||
2 | // | ||
3 | // GHash.cc | ||
4 | // | ||
5 | // Copyright 2001 Derek B. Noonburg | ||
6 | // | ||
7 | //======================================================================== | ||
8 | |||
9 | #ifdef __GNUC__ | ||
10 | #pragma implementation | ||
11 | #endif | ||
12 | |||
13 | #include <aconf.h> | ||
14 | #include "gmem.h" | ||
15 | #include "GString.h" | ||
16 | #include "GHash.h" | ||
17 | |||
18 | //------------------------------------------------------------------------ | ||
19 | |||
20 | struct GHashBucket { | ||
21 | GString *key; | ||
22 | void *val; | ||
23 | GHashBucket *next; | ||
24 | }; | ||
25 | |||
26 | struct GHashIter { | ||
27 | int h; | ||
28 | GHashBucket *p; | ||
29 | }; | ||
30 | |||
31 | //------------------------------------------------------------------------ | ||
32 | |||
33 | GHash::GHash(GBool deleteKeysA) { | ||
34 | int h; | ||
35 | |||
36 | deleteKeys = deleteKeysA; | ||
37 | size = 7; | ||
38 | tab = (GHashBucket **)gmalloc(size * sizeof(GHashBucket *)); | ||
39 | for (h = 0; h < size; ++h) { | ||
40 | tab[h] = NULL; | ||
41 | } | ||
42 | len = 0; | ||
43 | } | ||
44 | |||
45 | GHash::~GHash() { | ||
46 | GHashBucket *p; | ||
47 | int h; | ||
48 | |||
49 | for (h = 0; h < size; ++h) { | ||
50 | while (tab[h]) { | ||
51 | p = tab[h]; | ||
52 | tab[h] = p->next; | ||
53 | if (deleteKeys) { | ||
54 | delete p->key; | ||
55 | } | ||
56 | delete p; | ||
57 | } | ||
58 | } | ||
59 | gfree(tab); | ||
60 | } | ||
61 | |||
62 | void GHash::add(GString *key, void *val) { | ||
63 | GHashBucket **oldTab; | ||
64 | GHashBucket *p; | ||
65 | int oldSize, i, h; | ||
66 | |||
67 | // expand the table if necessary | ||
68 | if (len >= size) { | ||
69 | oldSize = size; | ||
70 | oldTab = tab; | ||
71 | size = 2*size + 1; | ||
72 | tab = (GHashBucket **)gmalloc(size * sizeof(GHashBucket *)); | ||
73 | for (h = 0; h < size; ++h) { | ||
74 | tab[h] = NULL; | ||
75 | } | ||
76 | for (i = 0; i < oldSize; ++i) { | ||
77 | while (oldTab[i]) { | ||
78 | p = oldTab[i]; | ||
79 | oldTab[i] = oldTab[i]->next; | ||
80 | h = hash(p->key); | ||
81 | p->next = tab[h]; | ||
82 | tab[h] = p; | ||
83 | } | ||
84 | } | ||
85 | gfree(oldTab); | ||
86 | } | ||
87 | |||
88 | // add the new symbol | ||
89 | p = new GHashBucket; | ||
90 | p->key = key; | ||
91 | p->val = val; | ||
92 | h = hash(key); | ||
93 | p->next = tab[h]; | ||
94 | tab[h] = p; | ||
95 | ++len; | ||
96 | } | ||
97 | |||
98 | void *GHash::lookup(GString *key) { | ||
99 | GHashBucket *p; | ||
100 | int h; | ||
101 | |||
102 | if (!(p = find(key, &h))) { | ||
103 | return NULL; | ||
104 | } | ||
105 | return p->val; | ||
106 | } | ||
107 | |||
108 | void *GHash::lookup(char *key) { | ||
109 | GHashBucket *p; | ||
110 | int h; | ||
111 | |||
112 | if (!(p = find(key, &h))) { | ||
113 | return NULL; | ||
114 | } | ||
115 | return p->val; | ||
116 | } | ||
117 | |||
118 | void *GHash::remove(GString *key) { | ||
119 | GHashBucket *p; | ||
120 | GHashBucket **q; | ||
121 | void *val; | ||
122 | int h; | ||
123 | |||
124 | if (!(p = find(key, &h))) { | ||
125 | return NULL; | ||
126 | } | ||
127 | q = &tab[h]; | ||
128 | while (*q != p) { | ||
129 | q = &((*q)->next); | ||
130 | } | ||
131 | *q = p->next; | ||
132 | if (deleteKeys) { | ||
133 | delete p->key; | ||
134 | } | ||
135 | val = p->val; | ||
136 | delete p; | ||
137 | --len; | ||
138 | return val; | ||
139 | } | ||
140 | |||
141 | void *GHash::remove(char *key) { | ||
142 | GHashBucket *p; | ||
143 | GHashBucket **q; | ||
144 | void *val; | ||
145 | int h; | ||
146 | |||
147 | if (!(p = find(key, &h))) { | ||
148 | return NULL; | ||
149 | } | ||
150 | q = &tab[h]; | ||
151 | while (*q != p) { | ||
152 | q = &((*q)->next); | ||
153 | } | ||
154 | *q = p->next; | ||
155 | if (deleteKeys) { | ||
156 | delete p->key; | ||
157 | } | ||
158 | val = p->val; | ||
159 | delete p; | ||
160 | --len; | ||
161 | return val; | ||
162 | } | ||
163 | |||
164 | void GHash::startIter(GHashIter **iter) { | ||
165 | *iter = new GHashIter; | ||
166 | (*iter)->h = -1; | ||
167 | (*iter)->p = NULL; | ||
168 | } | ||
169 | |||
170 | GBool GHash::getNext(GHashIter **iter, GString **key, void **val) { | ||
171 | if (!*iter) { | ||
172 | return gFalse; | ||
173 | } | ||
174 | if ((*iter)->p) { | ||
175 | (*iter)->p = (*iter)->p->next; | ||
176 | } | ||
177 | while (!(*iter)->p) { | ||
178 | if (++(*iter)->h == size) { | ||
179 | delete *iter; | ||
180 | *iter = NULL; | ||
181 | return gFalse; | ||
182 | } | ||
183 | (*iter)->p = tab[(*iter)->h]; | ||
184 | } | ||
185 | *key = (*iter)->p->key; | ||
186 | *val = (*iter)->p->val; | ||
187 | return gTrue; | ||
188 | } | ||
189 | |||
190 | void GHash::killIter(GHashIter **iter) { | ||
191 | delete *iter; | ||
192 | *iter = NULL; | ||
193 | } | ||
194 | |||
195 | GHashBucket *GHash::find(GString *key, int *h) { | ||
196 | GHashBucket *p; | ||
197 | |||
198 | *h = hash(key); | ||
199 | for (p = tab[*h]; p; p = p->next) { | ||
200 | if (!p->key->cmp(key)) { | ||
201 | return p; | ||
202 | } | ||
203 | } | ||
204 | return NULL; | ||
205 | } | ||
206 | |||
207 | GHashBucket *GHash::find(char *key, int *h) { | ||
208 | GHashBucket *p; | ||
209 | |||
210 | *h = hash(key); | ||
211 | for (p = tab[*h]; p; p = p->next) { | ||
212 | if (!p->key->cmp(key)) { | ||
213 | return p; | ||
214 | } | ||
215 | } | ||
216 | return NULL; | ||
217 | } | ||
218 | |||
219 | int GHash::hash(GString *key) { | ||
220 | char *p; | ||
221 | unsigned int h; | ||
222 | int i; | ||
223 | |||
224 | h = 0; | ||
225 | for (p = key->getCString(), i = 0; i < key->getLength(); ++p, ++i) { | ||
226 | h = 17 * h + (int)(*p & 0xff); | ||
227 | } | ||
228 | return (int)(h % size); | ||
229 | } | ||
230 | |||
231 | int GHash::hash(char *key) { | ||
232 | char *p; | ||
233 | unsigned int h; | ||
234 | |||
235 | h = 0; | ||
236 | for (p = key; *p; ++p) { | ||
237 | h = 17 * h + (int)(*p & 0xff); | ||
238 | } | ||
239 | return (int)(h % size); | ||
240 | } | ||
diff --git a/noncore/unsupported/qpdf/goo/GHash.h b/noncore/unsupported/qpdf/goo/GHash.h new file mode 100644 index 0000000..be1e573 --- a/dev/null +++ b/noncore/unsupported/qpdf/goo/GHash.h | |||
@@ -0,0 +1,67 @@ | |||
1 | //======================================================================== | ||
2 | // | ||
3 | // GHash.h | ||
4 | // | ||
5 | // Copyright 2001 Derek B. Noonburg | ||
6 | // | ||
7 | //======================================================================== | ||
8 | |||
9 | #ifndef GHASH_H | ||
10 | #define GHASH_H | ||
11 | |||
12 | #ifdef __GNUC__ | ||
13 | #pragma interface | ||
14 | #endif | ||
15 | |||
16 | #include "gtypes.h" | ||
17 | |||
18 | class GString; | ||
19 | struct GHashBucket; | ||
20 | struct GHashIter; | ||
21 | |||
22 | //------------------------------------------------------------------------ | ||
23 | |||
24 | class GHash { | ||
25 | public: | ||
26 | |||
27 | GHash(GBool deleteKeysA = gFalse); | ||
28 | ~GHash(); | ||
29 | void add(GString *key, void *val); | ||
30 | void *lookup(GString *key); | ||
31 | void *lookup(char *key); | ||
32 | void *remove(GString *key); | ||
33 | void *remove(char *key); | ||
34 | int getLength() { return len; } | ||
35 | void startIter(GHashIter **iter); | ||
36 | GBool getNext(GHashIter **iter, GString **key, void **val); | ||
37 | void killIter(GHashIter **iter); | ||
38 | |||
39 | private: | ||
40 | |||
41 | GHashBucket *find(GString *key, int *h); | ||
42 | GHashBucket *find(char *key, int *h); | ||
43 | int hash(GString *key); | ||
44 | int hash(char *key); | ||
45 | |||
46 | GBool deleteKeys; // set if key strings should be deleted | ||
47 | int size; // number of buckets | ||
48 | int len; // number of entries | ||
49 | GHashBucket **tab; | ||
50 | }; | ||
51 | |||
52 | #define deleteGHash(hash, T) \ | ||
53 | do { \ | ||
54 | GHash *_hash = (hash); \ | ||
55 | { \ | ||
56 | GHashIter *_iter; \ | ||
57 | GString *_key; \ | ||
58 | void *_p; \ | ||
59 | _hash->startIter(&_iter); \ | ||
60 | while (_hash->getNext(&_iter, &_key, &_p)) { \ | ||
61 | delete (T*)_p; \ | ||
62 | } \ | ||
63 | delete _hash; \ | ||
64 | } \ | ||
65 | } while(0) | ||
66 | |||
67 | #endif | ||
diff --git a/noncore/unsupported/qpdf/goo/GList.cc b/noncore/unsupported/qpdf/goo/GList.cc new file mode 100644 index 0000000..cfe0a25 --- a/dev/null +++ b/noncore/unsupported/qpdf/goo/GList.cc | |||
@@ -0,0 +1,91 @@ | |||
1 | //======================================================================== | ||
2 | // | ||
3 | // GList.cc | ||
4 | // | ||
5 | // Copyright 2001 Derek B. Noonburg | ||
6 | // | ||
7 | //======================================================================== | ||
8 | |||
9 | #ifdef __GNUC__ | ||
10 | #pragma implementation | ||
11 | #endif | ||
12 | |||
13 | #include <aconf.h> | ||
14 | #include <string.h> | ||
15 | #include "gmem.h" | ||
16 | #include "GList.h" | ||
17 | |||
18 | //------------------------------------------------------------------------ | ||
19 | // GList | ||
20 | //------------------------------------------------------------------------ | ||
21 | |||
22 | GList::GList() { | ||
23 | size = 8; | ||
24 | data = (void **)gmalloc(size * sizeof(void*)); | ||
25 | length = 0; | ||
26 | inc = 0; | ||
27 | } | ||
28 | |||
29 | GList::GList(int sizeA) { | ||
30 | size = sizeA; | ||
31 | data = (void **)gmalloc(size * sizeof(void*)); | ||
32 | length = 0; | ||
33 | inc = 0; | ||
34 | } | ||
35 | |||
36 | GList::~GList() { | ||
37 | gfree(data); | ||
38 | } | ||
39 | |||
40 | void GList::append(void *p) { | ||
41 | if (length >= size) { | ||
42 | expand(); | ||
43 | } | ||
44 | data[length++] = p; | ||
45 | } | ||
46 | |||
47 | void GList::append(GList *list) { | ||
48 | int i; | ||
49 | |||
50 | while (length + list->length > size) { | ||
51 | expand(); | ||
52 | } | ||
53 | for (i = 0; i < list->length; ++i) { | ||
54 | data[length++] = list->data[i]; | ||
55 | } | ||
56 | } | ||
57 | |||
58 | void GList::insert(int i, void *p) { | ||
59 | if (length >= size) { | ||
60 | expand(); | ||
61 | } | ||
62 | if (i < length) { | ||
63 | memmove(data+i+1, data+i, (length - i) * sizeof(void *)); | ||
64 | } | ||
65 | data[i] = p; | ||
66 | ++length; | ||
67 | } | ||
68 | |||
69 | void *GList::del(int i) { | ||
70 | void *p; | ||
71 | |||
72 | p = data[i]; | ||
73 | if (i < length - 1) { | ||
74 | memmove(data+i, data+i+1, (length - i - 1) * sizeof(void *)); | ||
75 | } | ||
76 | --length; | ||
77 | if (size - length >= ((inc > 0) ? inc : size/2)) { | ||
78 | shrink(); | ||
79 | } | ||
80 | return p; | ||
81 | } | ||
82 | |||
83 | void GList::expand() { | ||
84 | size += (inc > 0) ? inc : size; | ||
85 | data = (void **)grealloc(data, size * sizeof(void*)); | ||
86 | } | ||
87 | |||
88 | void GList::shrink() { | ||
89 | size -= (inc > 0) ? inc : size/2; | ||
90 | data = (void **)grealloc(data, size * sizeof(void*)); | ||
91 | } | ||
diff --git a/noncore/unsupported/qpdf/goo/GList.h b/noncore/unsupported/qpdf/goo/GList.h new file mode 100644 index 0000000..cc23731 --- a/dev/null +++ b/noncore/unsupported/qpdf/goo/GList.h | |||
@@ -0,0 +1,89 @@ | |||
1 | //======================================================================== | ||
2 | // | ||
3 | // GList.h | ||
4 | // | ||
5 | // Copyright 2001 Derek B. Noonburg | ||
6 | // | ||
7 | //======================================================================== | ||
8 | |||
9 | #ifndef GLIST_H | ||
10 | #define GLIST_H | ||
11 | |||
12 | #ifdef __GNUC__ | ||
13 | #pragma interface | ||
14 | #endif | ||
15 | |||
16 | #include "gtypes.h" | ||
17 | |||
18 | //------------------------------------------------------------------------ | ||
19 | // GList | ||
20 | //------------------------------------------------------------------------ | ||
21 | |||
22 | class GList { | ||
23 | public: | ||
24 | |||
25 | // Create an empty list. | ||
26 | GList(); | ||
27 | |||
28 | // Create an empty list with space for <size1> elements. | ||
29 | GList(int sizeA); | ||
30 | |||
31 | // Destructor - does not free pointed-to objects. | ||
32 | ~GList(); | ||
33 | |||
34 | //----- general | ||
35 | |||
36 | // Get the number of elements. | ||
37 | int getLength() { return length; } | ||
38 | |||
39 | //----- ordered list support | ||
40 | |||
41 | // Return the <i>th element. | ||
42 | // Assumes 0 <= i < length. | ||
43 | void *get(int i) { return data[i]; } | ||
44 | |||
45 | // Append an element to the end of the list. | ||
46 | void append(void *p); | ||
47 | |||
48 | // Append another list to the end of this one. | ||
49 | void append(GList *list); | ||
50 | |||
51 | // Insert an element at index <i>. | ||
52 | // Assumes 0 <= i <= length. | ||
53 | void insert(int i, void *p); | ||
54 | |||
55 | // Deletes and returns the element at index <i>. | ||
56 | // Assumes 0 <= i < length. | ||
57 | void *del(int i); | ||
58 | |||
59 | //----- control | ||
60 | |||
61 | // Set allocation increment to <inc>. If inc > 0, that many | ||
62 | // elements will be allocated every time the list is expanded. | ||
63 | // If inc <= 0, the list will be doubled in size. | ||
64 | void setAllocIncr(int incA) { inc = incA; } | ||
65 | |||
66 | private: | ||
67 | |||
68 | void expand(); | ||
69 | void shrink(); | ||
70 | |||
71 | void **data; // the list elements | ||
72 | int size; // size of data array | ||
73 | int length; // number of elements on list | ||
74 | int inc; // allocation increment | ||
75 | }; | ||
76 | |||
77 | #define deleteGList(list, T) \ | ||
78 | do { \ | ||
79 | GList *_list = (list); \ | ||
80 | { \ | ||
81 | int _i; \ | ||
82 | for (_i = 0; _i < _list->getLength(); ++_i) { \ | ||
83 | delete (T*)_list->get(_i); \ | ||
84 | } \ | ||
85 | delete _list; \ | ||
86 | } \ | ||
87 | } while (0) | ||
88 | |||
89 | #endif | ||
diff --git a/noncore/unsupported/qpdf/goo/GString.cc b/noncore/unsupported/qpdf/goo/GString.cc new file mode 100644 index 0000000..414c490 --- a/dev/null +++ b/noncore/unsupported/qpdf/goo/GString.cc | |||
@@ -0,0 +1,231 @@ | |||
1 | //======================================================================== | ||
2 | // | ||
3 | // GString.cc | ||
4 | // | ||
5 | // Simple variable-length string type. | ||
6 | // | ||
7 | // Copyright 1996 Derek B. Noonburg | ||
8 | // | ||
9 | //======================================================================== | ||
10 | |||
11 | #ifdef __GNUC__ | ||
12 | #pragma implementation | ||
13 | #endif | ||
14 | |||
15 | #include <aconf.h> | ||
16 | #include <stdlib.h> | ||
17 | #include <stddef.h> | ||
18 | #include <string.h> | ||
19 | #include <ctype.h> | ||
20 | #include "gtypes.h" | ||
21 | #include "GString.h" | ||
22 | |||
23 | static inline int size(int len) { | ||
24 | int delta; | ||
25 | |||
26 | delta = len < 256 ? 7 : 255; | ||
27 | return ((len + 1) + delta) & ~delta; | ||
28 | } | ||
29 | |||
30 | inline void GString::resize(int length1) { | ||
31 | char *s1; | ||
32 | |||
33 | if (!s) { | ||
34 | s = new char[size(length1)]; | ||
35 | } else if (size(length1) != size(length)) { | ||
36 | s1 = new char[size(length1)]; | ||
37 | memcpy(s1, s, length + 1); | ||
38 | delete[] s; | ||
39 | s = s1; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | GString::GString() { | ||
44 | s = NULL; | ||
45 | resize(length = 0); | ||
46 | s[0] = '\0'; | ||
47 | } | ||
48 | |||
49 | GString::GString(const char *sA) { | ||
50 | int n = strlen(sA); | ||
51 | |||
52 | s = NULL; | ||
53 | resize(length = n); | ||
54 | memcpy(s, sA, n + 1); | ||
55 | } | ||
56 | |||
57 | GString::GString(const char *sA, int lengthA) { | ||
58 | s = NULL; | ||
59 | resize(length = lengthA); | ||
60 | memcpy(s, sA, length * sizeof(char)); | ||
61 | s[length] = '\0'; | ||
62 | } | ||
63 | |||
64 | GString::GString(GString *str, int idx, int lengthA) { | ||
65 | s = NULL; | ||
66 | resize(length = lengthA); | ||
67 | memcpy(s, str->getCString() + idx, length); | ||
68 | s[length] = '\0'; | ||
69 | } | ||
70 | |||
71 | GString::GString(GString *str) { | ||
72 | s = NULL; | ||
73 | resize(length = str->getLength()); | ||
74 | memcpy(s, str->getCString(), length + 1); | ||
75 | } | ||
76 | |||
77 | GString::GString(GString *str1, GString *str2) { | ||
78 | int n1 = str1->getLength(); | ||
79 | int n2 = str2->getLength(); | ||
80 | |||
81 | s = NULL; | ||
82 | resize(length = n1 + n2); | ||
83 | memcpy(s, str1->getCString(), n1); | ||
84 | memcpy(s + n1, str2->getCString(), n2 + 1); | ||
85 | } | ||
86 | |||
87 | GString *GString::fromInt(int x) { | ||
88 | char buf[24]; // enough space for 64-bit ints plus a little extra | ||
89 | GBool neg; | ||
90 | Guint y; | ||
91 | int i; | ||
92 | |||
93 | i = 24; | ||
94 | if (x == 0) { | ||
95 | buf[--i] = '0'; | ||
96 | } else { | ||
97 | if ((neg = x < 0)) { | ||
98 | y = (Guint)-x; | ||
99 | } else { | ||
100 | y = (Guint)x; | ||
101 | } | ||
102 | while (i > 0 && y > 0) { | ||
103 | buf[--i] = '0' + y % 10; | ||
104 | y /= 10; | ||
105 | } | ||
106 | if (neg && i > 0) { | ||
107 | buf[--i] = '-'; | ||
108 | } | ||
109 | } | ||
110 | return new GString(buf + i, 24 - i); | ||
111 | } | ||
112 | |||
113 | GString::~GString() { | ||
114 | delete[] s; | ||
115 | } | ||
116 | |||
117 | GString *GString::clear() { | ||
118 | s[length = 0] = '\0'; | ||
119 | resize(0); | ||
120 | return this; | ||
121 | } | ||
122 | |||
123 | GString *GString::append(char c) { | ||
124 | resize(length + 1); | ||
125 | s[length++] = c; | ||
126 | s[length] = '\0'; | ||
127 | return this; | ||
128 | } | ||
129 | |||
130 | GString *GString::append(GString *str) { | ||
131 | int n = str->getLength(); | ||
132 | |||
133 | resize(length + n); | ||
134 | memcpy(s + length, str->getCString(), n + 1); | ||
135 | length += n; | ||
136 | return this; | ||
137 | } | ||
138 | |||
139 | GString *GString::append(const char *str) { | ||
140 | int n = strlen(str); | ||
141 | |||
142 | resize(length + n); | ||
143 | memcpy(s + length, str, n + 1); | ||
144 | length += n; | ||
145 | return this; | ||
146 | } | ||
147 | |||
148 | GString *GString::append(const char *str, int lengthA) { | ||
149 | resize(length + lengthA); | ||
150 | memcpy(s + length, str, lengthA); | ||
151 | length += lengthA; | ||
152 | s[length] = '\0'; | ||
153 | return this; | ||
154 | } | ||
155 | |||
156 | GString *GString::insert(int i, char c) { | ||
157 | int j; | ||
158 | |||
159 | resize(length + 1); | ||
160 | for (j = length + 1; j > i; --j) | ||
161 | s[j] = s[j-1]; | ||
162 | s[i] = c; | ||
163 | ++length; | ||
164 | return this; | ||
165 | } | ||
166 | |||
167 | GString *GString::insert(int i, GString *str) { | ||
168 | int n = str->getLength(); | ||
169 | int j; | ||
170 | |||
171 | resize(length + n); | ||
172 | for (j = length; j >= i; --j) | ||
173 | s[j+n] = s[j]; | ||
174 | memcpy(s+i, str->getCString(), n); | ||
175 | length += n; | ||
176 | return this; | ||
177 | } | ||
178 | |||
179 | GString *GString::insert(int i, const char *str) { | ||
180 | int n = strlen(str); | ||
181 | int j; | ||
182 | |||
183 | resize(length + n); | ||
184 | for (j = length; j >= i; --j) | ||
185 | s[j+n] = s[j]; | ||
186 | memcpy(s+i, str, n); | ||
187 | length += n; | ||
188 | return this; | ||
189 | } | ||
190 | |||
191 | GString *GString::insert(int i, const char *str, int lengthA) { | ||
192 | int j; | ||
193 | |||
194 | resize(length + lengthA); | ||
195 | for (j = length; j >= i; --j) | ||
196 | s[j+lengthA] = s[j]; | ||
197 | memcpy(s+i, str, lengthA); | ||
198 | length += lengthA; | ||
199 | return this; | ||
200 | } | ||
201 | |||
202 | GString *GString::del(int i, int n) { | ||
203 | int j; | ||
204 | |||
205 | if (n > 0) { | ||
206 | for (j = i; j <= length - n; ++j) | ||
207 | s[j] = s[j + n]; | ||
208 | resize(length -= n); | ||
209 | } | ||
210 | return this; | ||
211 | } | ||
212 | |||
213 | GString *GString::upperCase() { | ||
214 | int i; | ||
215 | |||
216 | for (i = 0; i < length; ++i) { | ||
217 | if (islower(s[i])) | ||
218 | s[i] = toupper(s[i]); | ||
219 | } | ||
220 | return this; | ||
221 | } | ||
222 | |||
223 | GString *GString::lowerCase() { | ||
224 | int i; | ||
225 | |||
226 | for (i = 0; i < length; ++i) { | ||
227 | if (isupper(s[i])) | ||
228 | s[i] = tolower(s[i]); | ||
229 | } | ||
230 | return this; | ||
231 | } | ||
diff --git a/noncore/unsupported/qpdf/goo/GString.h b/noncore/unsupported/qpdf/goo/GString.h new file mode 100644 index 0000000..3ced1c4 --- a/dev/null +++ b/noncore/unsupported/qpdf/goo/GString.h | |||
@@ -0,0 +1,98 @@ | |||
1 | //======================================================================== | ||
2 | // | ||
3 | // GString.h | ||
4 | // | ||
5 | // Simple variable-length string type. | ||
6 | // | ||
7 | // Copyright 1996 Derek B. Noonburg | ||
8 | // | ||
9 | //======================================================================== | ||
10 | |||
11 | #ifndef GSTRING_H | ||
12 | #define GSTRING_H | ||
13 | |||
14 | #ifdef __GNUC__ | ||
15 | #pragma interface | ||
16 | #endif | ||
17 | |||
18 | #include <string.h> | ||
19 | |||
20 | class GString { | ||
21 | public: | ||
22 | |||
23 | // Create an empty string. | ||
24 | GString(); | ||
25 | |||
26 | // Create a string from a C string. | ||
27 | GString(const char *sA); | ||
28 | |||
29 | // Create a string from <lengthA> chars at <sA>. This string | ||
30 | // can contain null characters. | ||
31 | GString(const char *sA, int lengthA); | ||
32 | |||
33 | // Create a string from <lengthA> chars at <idx> in <str>. | ||
34 | GString(GString *str, int idx, int lengthA); | ||
35 | |||
36 | // Copy a string. | ||
37 | GString(GString *str); | ||
38 | GString *copy() { return new GString(this); } | ||
39 | |||
40 | // Concatenate two strings. | ||
41 | GString(GString *str1, GString *str2); | ||
42 | |||
43 | // Convert an integer to a string. | ||
44 | static GString *fromInt(int x); | ||
45 | |||
46 | // Destructor. | ||
47 | ~GString(); | ||
48 | |||
49 | // Get length. | ||
50 | int getLength() { return length; } | ||
51 | |||
52 | // Get C string. | ||
53 | char *getCString() { return s; } | ||
54 | |||
55 | // Get <i>th character. | ||
56 | char getChar(int i) { return s[i]; } | ||
57 | |||
58 | // Change <i>th character. | ||
59 | void setChar(int i, char c) { s[i] = c; } | ||
60 | |||
61 | // Clear string to zero length. | ||
62 | GString *clear(); | ||
63 | |||
64 | // Append a character or string. | ||
65 | GString *append(char c); | ||
66 | GString *append(GString *str); | ||
67 | GString *append(const char *str); | ||
68 | GString *append(const char *str, int lengthA); | ||
69 | |||
70 | // Insert a character or string. | ||
71 | GString *insert(int i, char c); | ||
72 | GString *insert(int i, GString *str); | ||
73 | GString *insert(int i, const char *str); | ||
74 | GString *insert(int i, const char *str, int lengthA); | ||
75 | |||
76 | // Delete a character or range of characters. | ||
77 | GString *del(int i, int n = 1); | ||
78 | |||
79 | // Convert string to all-upper/all-lower case. | ||
80 | GString *upperCase(); | ||
81 | GString *lowerCase(); | ||
82 | |||
83 | // Compare two strings: -1:< 0:= +1:> | ||
84 | // These functions assume the strings do not contain null characters. | ||
85 | int cmp(GString *str) { return strcmp(s, str->getCString()); } | ||
86 | int cmpN(GString *str, int n) { return strncmp(s, str->getCString(), n); } | ||
87 | int cmp(const char *sA) { return strcmp(s, sA); } | ||
88 | int cmpN(const char *sA, int n) { return strncmp(s, sA, n); } | ||
89 | |||
90 | private: | ||
91 | |||
92 | int length; | ||
93 | char *s; | ||
94 | |||
95 | void resize(int length1); | ||
96 | }; | ||
97 | |||
98 | #endif | ||
diff --git a/noncore/unsupported/qpdf/goo/gfile.h b/noncore/unsupported/qpdf/goo/gfile.h new file mode 100644 index 0000000..16cbca0 --- a/dev/null +++ b/noncore/unsupported/qpdf/goo/gfile.h | |||
@@ -0,0 +1,135 @@ | |||
1 | //======================================================================== | ||
2 | // | ||
3 | // gfile.h | ||
4 | // | ||
5 | // Miscellaneous file and directory name manipulation. | ||
6 | // | ||
7 | // Copyright 1996 Derek B. Noonburg | ||
8 | // | ||
9 | //======================================================================== | ||
10 | |||
11 | #ifndef GFILE_H | ||
12 | #define GFILE_H | ||
13 | |||
14 | #include <stdio.h> | ||
15 | #include <stdlib.h> | ||
16 | #include <stddef.h> | ||
17 | #if defined(WIN32) | ||
18 | # include <sys/stat.h> | ||
19 | # ifdef FPTEX | ||
20 | # include <win32lib.h> | ||
21 | # else | ||
22 | # include <windows.h> | ||
23 | # endif | ||
24 | #elif defined(ACORN) | ||
25 | #elif defined(MACOS) | ||
26 | # include <ctime.h> | ||
27 | #else | ||
28 | # include <unistd.h> | ||
29 | # include <sys/types.h> | ||
30 | # ifdef VMS | ||
31 | # include "vms_dirent.h" | ||
32 | # elif HAVE_DIRENT_H | ||
33 | # include <dirent.h> | ||
34 | # define NAMLEN(d) strlen((d)->d_name) | ||
35 | # else | ||
36 | # define dirent direct | ||
37 | # define NAMLEN(d) (d)->d_namlen | ||
38 | # if HAVE_SYS_NDIR_H | ||
39 | # include <sys/ndir.h> | ||
40 | # endif | ||
41 | # if HAVE_SYS_DIR_H | ||
42 | # include <sys/dir.h> | ||
43 | # endif | ||
44 | # if HAVE_NDIR_H | ||
45 | # include <ndir.h> | ||
46 | # endif | ||
47 | # endif | ||
48 | #endif | ||
49 | #include "gtypes.h" | ||
50 | |||
51 | class GString; | ||
52 | |||
53 | //------------------------------------------------------------------------ | ||
54 | |||
55 | // Get home directory path. | ||
56 | extern GString *getHomeDir(); | ||
57 | |||
58 | // Get current directory. | ||
59 | extern GString *getCurrentDir(); | ||
60 | |||
61 | // Append a file name to a path string. <path> may be an empty | ||
62 | // string, denoting the current directory). Returns <path>. | ||
63 | extern GString *appendToPath(GString *path, char *fileName); | ||
64 | |||
65 | // Grab the path from the front of the file name. If there is no | ||
66 | // directory component in <fileName>, returns an empty string. | ||
67 | extern GString *grabPath(char *fileName); | ||
68 | |||
69 | // Is this an absolute path or file name? | ||
70 | extern GBool isAbsolutePath(char *path); | ||
71 | |||
72 | // Make this path absolute by prepending current directory (if path is | ||
73 | // relative) or prepending user's directory (if path starts with '~'). | ||
74 | extern GString *makePathAbsolute(GString *path); | ||
75 | |||
76 | // Get the modification time for <fileName>. Returns 0 if there is an | ||
77 | // error. | ||
78 | extern time_t getModTime(char *fileName); | ||
79 | |||
80 | // Create a temporary file and open it for writing. If <ext> is not | ||
81 | // NULL, it will be used as the file name extension. Returns both the | ||
82 | // name and the file pointer. For security reasons, all writing | ||
83 | // should be done to the returned file pointer; the file may be | ||
84 | // reopened later for reading, but not for writing. The <mode> string | ||
85 | // should be "w" or "wb". Returns true on success. | ||
86 | extern GBool openTempFile(GString **name, FILE **f, char *mode, char *ext); | ||
87 | |||
88 | // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line | ||
89 | // conventions. | ||
90 | extern char *getLine(char *buf, int size, FILE *f); | ||
91 | |||
92 | //------------------------------------------------------------------------ | ||
93 | // GDir and GDirEntry | ||
94 | //------------------------------------------------------------------------ | ||
95 | |||
96 | class GDirEntry { | ||
97 | public: | ||
98 | |||
99 | GDirEntry(char *dirPath, char *nameA, GBool doStat); | ||
100 | ~GDirEntry(); | ||
101 | GString *getName() { return name; } | ||
102 | GBool isDir() { return dir; } | ||
103 | |||
104 | private: | ||
105 | |||
106 | GString *name; // dir/file name | ||
107 | GBool dir; // is it a directory? | ||
108 | }; | ||
109 | |||
110 | class GDir { | ||
111 | public: | ||
112 | |||
113 | GDir(char *name, GBool doStatA = gTrue); | ||
114 | ~GDir(); | ||
115 | GDirEntry *getNextEntry(); | ||
116 | void rewind(); | ||
117 | |||
118 | private: | ||
119 | |||
120 | GString *path; // directory path | ||
121 | GBool doStat; // call stat() for each entry? | ||
122 | #if defined(WIN32) | ||
123 | WIN32_FIND_DATA ffd; | ||
124 | HANDLE hnd; | ||
125 | #elif defined(ACORN) | ||
126 | #elif defined(MACOS) | ||
127 | #else | ||
128 | DIR *dir; // the DIR structure from opendir() | ||
129 | #ifdef VMS | ||
130 | GBool needParent; // need to return an entry for [-] | ||
131 | #endif | ||
132 | #endif | ||
133 | }; | ||
134 | |||
135 | #endif | ||
diff --git a/noncore/unsupported/qpdf/goo/gmem.h b/noncore/unsupported/qpdf/goo/gmem.h new file mode 100644 index 0000000..7ab5ddb --- a/dev/null +++ b/noncore/unsupported/qpdf/goo/gmem.h | |||
@@ -0,0 +1,53 @@ | |||
1 | /* | ||
2 | * gmem.h | ||
3 | * | ||
4 | * Memory routines with out-of-memory checking. | ||
5 | * | ||
6 | * Copyright 1996 Derek B. Noonburg | ||
7 | */ | ||
8 | |||
9 | #ifndef GMEM_H | ||
10 | #define GMEM_H | ||
11 | |||
12 | #include <stdio.h> | ||
13 | |||
14 | #ifdef __cplusplus | ||
15 | extern "C" { | ||
16 | #endif | ||
17 | |||
18 | /* | ||
19 | * Same as malloc, but prints error message and exits if malloc() | ||
20 | * returns NULL. | ||
21 | */ | ||
22 | extern void *gmalloc(int size); | ||
23 | |||
24 | /* | ||
25 | * Same as realloc, but prints error message and exits if realloc() | ||
26 | * returns NULL. If <p> is NULL, calls malloc instead of realloc(). | ||
27 | */ | ||
28 | extern void *grealloc(void *p, int size); | ||
29 | |||
30 | /* | ||
31 | * Same as free, but checks for and ignores NULL pointers. | ||
32 | */ | ||
33 | extern void gfree(void *p); | ||
34 | |||
35 | #ifdef DEBUG_MEM | ||
36 | /* | ||
37 | * Report on unfreed memory. | ||
38 | */ | ||
39 | extern void gMemReport(FILE *f); | ||
40 | #else | ||
41 | #define gMemReport(f) | ||
42 | #endif | ||
43 | |||
44 | /* | ||
45 | * Allocate memory and copy a string into it. | ||
46 | */ | ||
47 | extern char *copyString(char *s); | ||
48 | |||
49 | #ifdef __cplusplus | ||
50 | } | ||
51 | #endif | ||
52 | |||
53 | #endif | ||
diff --git a/noncore/unsupported/qpdf/goo/gtypes.h b/noncore/unsupported/qpdf/goo/gtypes.h new file mode 100644 index 0000000..6593267 --- a/dev/null +++ b/noncore/unsupported/qpdf/goo/gtypes.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /* | ||
2 | * gtypes.h | ||
3 | * | ||
4 | * Some useful simple types. | ||
5 | * | ||
6 | * Copyright 1996 Derek B. Noonburg | ||
7 | */ | ||
8 | |||
9 | #ifndef GTYPES_H | ||
10 | #define GTYPES_H | ||
11 | |||
12 | /* | ||
13 | * These have stupid names to avoid conflicts with some (but not all) | ||
14 | * C++ compilers which define them. | ||
15 | */ | ||
16 | typedef int GBool; | ||
17 | #define gTrue 1 | ||
18 | #define gFalse 0 | ||
19 | |||
20 | /* | ||
21 | * These have stupid names to avoid conflicts with <sys/types.h>, | ||
22 | * which on various systems defines some random subset of these. | ||
23 | */ | ||
24 | typedef unsigned char Guchar; | ||
25 | typedef unsigned short Gushort; | ||
26 | typedef unsigned int Guint; | ||
27 | typedef unsigned long Gulong; | ||
28 | |||
29 | #endif | ||