diff options
author | Nils Durner <durner@gnunet.org> | 2008-11-16 12:22:53 +0000 |
---|---|---|
committer | Nils Durner <durner@gnunet.org> | 2008-11-16 12:22:53 +0000 |
commit | 55335c192b31803e5a4dd5af32257affc8d4ce82 (patch) | |
tree | d3317d19fe35b165914d3bd426e48d2c9e584d50 /src/plugins | |
parent | 4165fa67f097952be76d735ff32b1c1588d572d6 (diff) | |
download | libextractor-55335c192b31803e5a4dd5af32257affc8d4ce82.tar.gz libextractor-55335c192b31803e5a4dd5af32257affc8d4ce82.zip |
move source from libpack and libconvert to new dynamic library libextractor_common
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Makefile-plugins.am | 2 | ||||
-rw-r--r-- | src/plugins/Makefile.am | 45 | ||||
-rw-r--r-- | src/plugins/applefileextractor.c | 10 | ||||
-rw-r--r-- | src/plugins/convert.c | 66 | ||||
-rw-r--r-- | src/plugins/convert.h | 46 | ||||
-rw-r--r-- | src/plugins/convert_numeric.c | 631 | ||||
-rw-r--r-- | src/plugins/convert_numeric.h | 140 | ||||
-rw-r--r-- | src/plugins/elfextractor.c | 8 | ||||
-rw-r--r-- | src/plugins/filenameextractor.c | 2 | ||||
-rw-r--r-- | src/plugins/flvextractor.c | 116 | ||||
-rw-r--r-- | src/plugins/gifextractor.c | 4 | ||||
-rw-r--r-- | src/plugins/htmlextractor.c | 4 | ||||
-rw-r--r-- | src/plugins/id3v23extractor.c | 6 | ||||
-rw-r--r-- | src/plugins/id3v24extractor.c | 8 | ||||
-rw-r--r-- | src/plugins/id3v2extractor.c | 6 | ||||
-rw-r--r-- | src/plugins/mp3extractor.c | 28 | ||||
-rw-r--r-- | src/plugins/ole2/ole2extractor.c | 10 | ||||
-rw-r--r-- | src/plugins/pack.c | 516 | ||||
-rw-r--r-- | src/plugins/pack.h | 59 | ||||
-rw-r--r-- | src/plugins/pdf/pdfextractor.cc | 8 | ||||
-rw-r--r-- | src/plugins/pdfextractor.c | 4 | ||||
-rw-r--r-- | src/plugins/pngextractor.c | 4 | ||||
-rw-r--r-- | src/plugins/tiffextractor.c | 4 |
23 files changed, 125 insertions, 1602 deletions
diff --git a/src/plugins/Makefile-plugins.am b/src/plugins/Makefile-plugins.am index af0a425..9392798 100644 --- a/src/plugins/Makefile-plugins.am +++ b/src/plugins/Makefile-plugins.am | |||
@@ -1,4 +1,4 @@ | |||
1 | INCLUDES = -I$(top_srcdir)/src/include | 1 | INCLUDES = -I$(top_srcdir)/src/include -I$(top_srcdir)/src/common |
2 | 2 | ||
3 | # install plugins under: | 3 | # install plugins under: |
4 | plugindir = $(libdir)/@RPLUGINDIR@ | 4 | plugindir = $(libdir)/@RPLUGINDIR@ |
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index e0d47ec..dd884a8 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am | |||
@@ -142,11 +142,6 @@ libextractor_flac_la_LDFLAGS = \ | |||
142 | -lFLAC $(flacoggflag) $(PLUGINFLAGS) $(retaincommand) | 142 | -lFLAC $(flacoggflag) $(PLUGINFLAGS) $(retaincommand) |
143 | endif | 143 | endif |
144 | 144 | ||
145 | noinst_LTLIBRARIES = \ | ||
146 | libpack.la \ | ||
147 | libconvert.la \ | ||
148 | libconvert_numeric.la | ||
149 | |||
150 | if HAVE_ZLIB | 145 | if HAVE_ZLIB |
151 | libextractor_qt_la_LDFLAGS = \ | 146 | libextractor_qt_la_LDFLAGS = \ |
152 | $(PLUGINFLAGS) $(retaincommand) | 147 | $(PLUGINFLAGS) $(retaincommand) |
@@ -172,35 +167,35 @@ libextractor_pdf_la_SOURCES = \ | |||
172 | libextractor_pdf_la_LDFLAGS = \ | 167 | libextractor_pdf_la_LDFLAGS = \ |
173 | $(PLUGINFLAGS) $(retaincommand) | 168 | $(PLUGINFLAGS) $(retaincommand) |
174 | libextractor_pdf_la_LIBADD = \ | 169 | libextractor_pdf_la_LIBADD = \ |
175 | libconvert.la | 170 | $(top_builddir)/src/common/libextractor_common.la |
176 | 171 | ||
177 | libextractor_mp3_la_SOURCES = \ | 172 | libextractor_mp3_la_SOURCES = \ |
178 | mp3extractor.c | 173 | mp3extractor.c |
179 | libextractor_mp3_la_LDFLAGS = \ | 174 | libextractor_mp3_la_LDFLAGS = \ |
180 | $(PLUGINFLAGS) $(retaincommand) | 175 | $(PLUGINFLAGS) $(retaincommand) |
181 | libextractor_mp3_la_LIBADD = \ | 176 | libextractor_mp3_la_LIBADD = \ |
182 | libconvert.la | 177 | $(top_builddir)/src/common/libextractor_common.la |
183 | 178 | ||
184 | libextractor_id3v2_la_SOURCES = \ | 179 | libextractor_id3v2_la_SOURCES = \ |
185 | id3v2extractor.c | 180 | id3v2extractor.c |
186 | libextractor_id3v2_la_LDFLAGS = \ | 181 | libextractor_id3v2_la_LDFLAGS = \ |
187 | $(PLUGINFLAGS) $(retaincommand) | 182 | $(PLUGINFLAGS) $(retaincommand) |
188 | libextractor_id3v2_la_LIBADD = \ | 183 | libextractor_id3v2_la_LIBADD = \ |
189 | libconvert.la | 184 | $(top_builddir)/src/common/libextractor_common.la |
190 | 185 | ||
191 | libextractor_id3v23_la_SOURCES = \ | 186 | libextractor_id3v23_la_SOURCES = \ |
192 | id3v23extractor.c | 187 | id3v23extractor.c |
193 | libextractor_id3v23_la_LDFLAGS = \ | 188 | libextractor_id3v23_la_LDFLAGS = \ |
194 | $(PLUGINFLAGS) $(retaincommand) | 189 | $(PLUGINFLAGS) $(retaincommand) |
195 | libextractor_id3v23_la_LIBADD = \ | 190 | libextractor_id3v23_la_LIBADD = \ |
196 | libconvert.la | 191 | $(top_builddir)/src/common/libextractor_common.la |
197 | 192 | ||
198 | libextractor_id3v24_la_SOURCES = \ | 193 | libextractor_id3v24_la_SOURCES = \ |
199 | id3v24extractor.c | 194 | id3v24extractor.c |
200 | libextractor_id3v24_la_LDFLAGS = \ | 195 | libextractor_id3v24_la_LDFLAGS = \ |
201 | $(PLUGINFLAGS) $(retaincommand) | 196 | $(PLUGINFLAGS) $(retaincommand) |
202 | libextractor_id3v24_la_LIBADD = \ | 197 | libextractor_id3v24_la_LIBADD = \ |
203 | libconvert.la | 198 | $(top_builddir)/src/common/libextractor_common.la |
204 | 199 | ||
205 | libextractor_it_la_SOURCES = \ | 200 | libextractor_it_la_SOURCES = \ |
206 | itextractor.c | 201 | itextractor.c |
@@ -238,42 +233,28 @@ libextractor_gif_la_SOURCES = \ | |||
238 | libextractor_gif_la_LDFLAGS = \ | 233 | libextractor_gif_la_LDFLAGS = \ |
239 | $(PLUGINFLAGS) $(retaincommand) | 234 | $(PLUGINFLAGS) $(retaincommand) |
240 | libextractor_gif_la_LIBADD = \ | 235 | libextractor_gif_la_LIBADD = \ |
241 | libpack.la | 236 | $(top_builddir)/src/common/libextractor_common.la |
242 | 237 | ||
243 | libextractor_tiff_la_SOURCES = \ | 238 | libextractor_tiff_la_SOURCES = \ |
244 | tiffextractor.c | 239 | tiffextractor.c |
245 | libextractor_tiff_la_LDFLAGS = \ | 240 | libextractor_tiff_la_LDFLAGS = \ |
246 | $(PLUGINFLAGS) $(retaincommand) | 241 | $(PLUGINFLAGS) $(retaincommand) |
247 | libextractor_tiff_la_LIBADD = \ | 242 | libextractor_tiff_la_LIBADD = \ |
248 | libpack.la | 243 | $(top_builddir)/src/common/libextractor_common.la |
249 | 244 | ||
250 | libextractor_applefile_la_SOURCES = \ | 245 | libextractor_applefile_la_SOURCES = \ |
251 | applefileextractor.c | 246 | applefileextractor.c |
252 | libextractor_applefile_la_LDFLAGS = \ | 247 | libextractor_applefile_la_LDFLAGS = \ |
253 | $(PLUGINFLAGS) $(retaincommand) | 248 | $(PLUGINFLAGS) $(retaincommand) |
254 | libextractor_applefile_la_LIBADD = \ | 249 | libextractor_applefile_la_LIBADD = \ |
255 | libpack.la | 250 | $(top_builddir)/src/common/libextractor_common.la |
256 | 251 | ||
257 | libextractor_elf_la_SOURCES = \ | 252 | libextractor_elf_la_SOURCES = \ |
258 | elfextractor.c | 253 | elfextractor.c |
259 | libextractor_elf_la_LDFLAGS = \ | 254 | libextractor_elf_la_LDFLAGS = \ |
260 | $(PLUGINFLAGS) $(retaincommand) | 255 | $(PLUGINFLAGS) $(retaincommand) |
261 | libextractor_elf_la_LIBADD = \ | 256 | libextractor_elf_la_LIBADD = \ |
262 | libpack.la | 257 | $(top_builddir)/src/common/libextractor_common.la |
263 | |||
264 | libpack_la_SOURCES = \ | ||
265 | pack.c \ | ||
266 | pack.h | ||
267 | |||
268 | libconvert_la_SOURCES = \ | ||
269 | convert.c \ | ||
270 | convert.h | ||
271 | libconvert_la_LDFLAGS = \ | ||
272 | $(LIBICONV) | ||
273 | |||
274 | libconvert_numeric_la_SOURCES = \ | ||
275 | convert_numeric.c \ | ||
276 | convert_numeric.h | ||
277 | 258 | ||
278 | libextractor_zip_la_SOURCES = \ | 259 | libextractor_zip_la_SOURCES = \ |
279 | zipextractor.c | 260 | zipextractor.c |
@@ -292,14 +273,14 @@ libextractor_html_la_LDFLAGS = \ | |||
292 | $(PLUGINFLAGS) $(retaincommand) | 273 | $(PLUGINFLAGS) $(retaincommand) |
293 | libextractor_html_la_LIBADD = \ | 274 | libextractor_html_la_LIBADD = \ |
294 | $(top_builddir)/src/main/libextractor.la \ | 275 | $(top_builddir)/src/main/libextractor.la \ |
295 | libconvert.la | 276 | $(top_builddir)/src/common/libextractor_common.la |
296 | 277 | ||
297 | libextractor_flv_la_SOURCES = \ | 278 | libextractor_flv_la_SOURCES = \ |
298 | flvextractor.c | 279 | flvextractor.c |
299 | libextractor_flv_la_LDFLAGS = \ | 280 | libextractor_flv_la_LDFLAGS = \ |
300 | $(PLUGINFLAGS) $(retaincommand) | 281 | $(PLUGINFLAGS) $(retaincommand) |
301 | libextractor_flv_la_LIBADD = \ | 282 | libextractor_flv_la_LIBADD = \ |
302 | libconvert_numeric.la | 283 | $(top_builddir)/src/common/libextractor_common.la |
303 | 284 | ||
304 | libextractor_real_la_SOURCES = \ | 285 | libextractor_real_la_SOURCES = \ |
305 | realextractor.c | 286 | realextractor.c |
@@ -353,7 +334,7 @@ libextractor_png_la_LDFLAGS = \ | |||
353 | $(top_builddir)/src/main/libextractor.la \ | 334 | $(top_builddir)/src/main/libextractor.la \ |
354 | $(PLUGINFLAGS) $(retaincommand) | 335 | $(PLUGINFLAGS) $(retaincommand) |
355 | libextractor_png_la_LIBADD = \ | 336 | libextractor_png_la_LIBADD = \ |
356 | libconvert.la -lz | 337 | $(top_builddir)/src/common/libextractor_common.la -lz |
357 | endif | 338 | endif |
358 | 339 | ||
359 | libextractor_filename_la_SOURCES = \ | 340 | libextractor_filename_la_SOURCES = \ |
@@ -362,7 +343,7 @@ libextractor_filename_la_LDFLAGS = \ | |||
362 | $(PLUGINFLAGS) $(retaincommand) | 343 | $(PLUGINFLAGS) $(retaincommand) |
363 | libextractor_filename_la_LIBADD = \ | 344 | libextractor_filename_la_LIBADD = \ |
364 | $(top_builddir)/src/main/libextractor.la \ | 345 | $(top_builddir)/src/main/libextractor.la \ |
365 | libconvert.la | 346 | $(top_builddir)/src/common/libextractor_common.la |
366 | 347 | ||
367 | libextractor_sid_la_SOURCES = \ | 348 | libextractor_sid_la_SOURCES = \ |
368 | sidextractor.c | 349 | sidextractor.c |
diff --git a/src/plugins/applefileextractor.c b/src/plugins/applefileextractor.c index 995b5c1..33685ab 100644 --- a/src/plugins/applefileextractor.c +++ b/src/plugins/applefileextractor.c | |||
@@ -99,7 +99,7 @@ static int readApplefileHeader(const unsigned char *data, | |||
99 | if ((*offset + APPLEFILE_HEADER_SIZE) > size) | 99 | if ((*offset + APPLEFILE_HEADER_SIZE) > size) |
100 | return -1; | 100 | return -1; |
101 | 101 | ||
102 | cat_unpack(data + *offset, | 102 | EXTRACTOR_common_cat_unpack(data + *offset, |
103 | APPLEFILE_HEADER_SPEC, | 103 | APPLEFILE_HEADER_SPEC, |
104 | APPLEFILE_HEADER_FIELDS(hdr)); | 104 | APPLEFILE_HEADER_FIELDS(hdr)); |
105 | *offset += APPLEFILE_HEADER_SIZE; | 105 | *offset += APPLEFILE_HEADER_SIZE; |
@@ -114,8 +114,8 @@ static int readEntryDescriptor(const unsigned char *data, | |||
114 | if ((*offset + APPLEFILE_ENTRY_DESCRIPTOR_SIZE) > size) | 114 | if ((*offset + APPLEFILE_ENTRY_DESCRIPTOR_SIZE) > size) |
115 | return -1; | 115 | return -1; |
116 | 116 | ||
117 | cat_unpack(data + *offset, | 117 | EXTRACTOR_common_cat_unpack(data + *offset, |
118 | APPLEFILE_ENTRY_DESCRIPTOR_SPEC, | 118 | APPLEFILE_ENTRY_DESCRIPTOR_SPEC, |
119 | APPLEFILE_ENTRY_DESCRIPTOR_FIELDS(dsc)); | 119 | APPLEFILE_ENTRY_DESCRIPTOR_FIELDS(dsc)); |
120 | *offset += APPLEFILE_ENTRY_DESCRIPTOR_SIZE; | 120 | *offset += APPLEFILE_ENTRY_DESCRIPTOR_SIZE; |
121 | return 0; | 121 | return 0; |
@@ -137,7 +137,7 @@ libextractor_applefile_extract (const char *filename, | |||
137 | if (readApplefileHeader(data, &offset, size, &header) == -1) | 137 | if (readApplefileHeader(data, &offset, size, &header) == -1) |
138 | return prev; | 138 | return prev; |
139 | 139 | ||
140 | if ((memcmp(header.magic, APPLESINGLE_SIGNATURE, 4) != 0) && | 140 | if ((memcmp(header.magic, APPLESINGLE_SIGNATURE, 4) != 0) && |
141 | (memcmp(header.magic, APPLEDOUBLE_SIGNATURE, 4) != 0)) | 141 | (memcmp(header.magic, APPLEDOUBLE_SIGNATURE, 4) != 0)) |
142 | return prev; | 142 | return prev; |
143 | 143 | ||
@@ -175,7 +175,7 @@ libextractor_applefile_extract (const char *filename, | |||
175 | else | 175 | else |
176 | snprintf (s, 13, "%.2f %s", (double) dsc.length, _("Bytes")); | 176 | snprintf (s, 13, "%.2f %s", (double) dsc.length, _("Bytes")); |
177 | 177 | ||
178 | result = addKeyword(EXTRACTOR_FILE_SIZE, s, result); | 178 | result = addKeyword(EXTRACTOR_FILE_SIZE, s, result); |
179 | } | 179 | } |
180 | break; | 180 | break; |
181 | case AED_ID_REAL_NAME: | 181 | case AED_ID_REAL_NAME: |
diff --git a/src/plugins/convert.c b/src/plugins/convert.c deleted file mode 100644 index b416fa8..0000000 --- a/src/plugins/convert.c +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of libextractor. | ||
3 | (C) 2004 Vidyut Samanta and Christian Grothoff | ||
4 | |||
5 | libextractor is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libextractor is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libextractor; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | #include "platform.h" | ||
22 | #include "extractor.h" | ||
23 | #include "convert.h" | ||
24 | |||
25 | /** | ||
26 | * Convert the len characters long character sequence | ||
27 | * given in input that is in the given charset | ||
28 | * to UTF-8. | ||
29 | * @return the converted string (0-terminated), | ||
30 | * if conversion fails, a copy of the orignal | ||
31 | * string is returned. | ||
32 | */ | ||
33 | char * | ||
34 | convertToUtf8 (const char *input, size_t len, const char *charset) | ||
35 | { | ||
36 | size_t tmpSize; | ||
37 | size_t finSize; | ||
38 | char *tmp; | ||
39 | char *ret; | ||
40 | char *itmp; | ||
41 | const char *i; | ||
42 | iconv_t cd; | ||
43 | |||
44 | i = input; | ||
45 | cd = iconv_open ("UTF-8", charset); | ||
46 | if (cd == (iconv_t) - 1) | ||
47 | return strdup (i); | ||
48 | tmpSize = 3 * len + 4; | ||
49 | tmp = malloc (tmpSize); | ||
50 | itmp = tmp; | ||
51 | finSize = tmpSize; | ||
52 | if (iconv (cd, (char **) &input, &len, &itmp, &finSize) == (size_t) - 1) | ||
53 | { | ||
54 | iconv_close (cd); | ||
55 | free (tmp); | ||
56 | return strdup (i); | ||
57 | } | ||
58 | ret = malloc (tmpSize - finSize + 1); | ||
59 | memcpy (ret, tmp, tmpSize - finSize); | ||
60 | ret[tmpSize - finSize] = '\0'; | ||
61 | free (tmp); | ||
62 | iconv_close (cd); | ||
63 | return ret; | ||
64 | } | ||
65 | |||
66 | /* end of convert.c */ | ||
diff --git a/src/plugins/convert.h b/src/plugins/convert.h deleted file mode 100644 index 3bb4c06..0000000 --- a/src/plugins/convert.h +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of libextractor. | ||
3 | (C) 2004 Vidyut Samanta and Christian Grothoff | ||
4 | |||
5 | libextractor is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libextractor is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libextractor; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | #ifndef CONVERT_H | ||
22 | #define CONVERT_H | ||
23 | |||
24 | #include "platform.h" | ||
25 | #include "extractor.h" | ||
26 | |||
27 | #ifdef __cplusplus | ||
28 | extern "C" { | ||
29 | #endif | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Convert the len characters long character sequence | ||
34 | * given in input that is in the given charset | ||
35 | * to UTF-8. | ||
36 | * @return the converted string (0-terminated) | ||
37 | */ | ||
38 | char * convertToUtf8(const char * input, | ||
39 | size_t len, | ||
40 | const char * charset); | ||
41 | |||
42 | #ifdef __cplusplus | ||
43 | } | ||
44 | #endif | ||
45 | |||
46 | #endif | ||
diff --git a/src/plugins/convert_numeric.c b/src/plugins/convert_numeric.c deleted file mode 100644 index e41151a..0000000 --- a/src/plugins/convert_numeric.c +++ /dev/null | |||
@@ -1,631 +0,0 @@ | |||
1 | /* IEEE floating point support routines, for GDB, the GNU Debugger. | ||
2 | Copyright 1991, 1994, 1999, 2000, 2003, 2005, 2006 | ||
3 | Free Software Foundation, Inc. | ||
4 | |||
5 | This file is part of GDB. | ||
6 | |||
7 | This program is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation; either version 2 of the License, or | ||
10 | (at your option) any later version. | ||
11 | |||
12 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program; if not, write to the Free Software | ||
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
20 | |||
21 | /* This is needed to pick up the NAN macro on some systems. */ | ||
22 | /* #define _GNU_SOURCE */ | ||
23 | |||
24 | #ifdef HAVE_CONFIG_H | ||
25 | #include "config.h" | ||
26 | #endif | ||
27 | |||
28 | #include <math.h> | ||
29 | |||
30 | #ifdef HAVE_STRING_H | ||
31 | #include <string.h> | ||
32 | #endif | ||
33 | |||
34 | /* On some platforms, <float.h> provides DBL_QNAN. */ | ||
35 | #ifdef STDC_HEADERS | ||
36 | #include <float.h> | ||
37 | #endif | ||
38 | |||
39 | /*#include "ansidecl.h"*/ | ||
40 | /*#include "libiberty.h"*/ | ||
41 | #include "convert_numeric.h" | ||
42 | |||
43 | #ifndef INFINITY | ||
44 | #ifdef HUGE_VAL | ||
45 | #define INFINITY HUGE_VAL | ||
46 | #else | ||
47 | #define INFINITY (1.0 / 0.0) | ||
48 | #endif | ||
49 | #endif | ||
50 | |||
51 | #ifndef NAN | ||
52 | #ifdef DBL_QNAN | ||
53 | #define NAN DBL_QNAN | ||
54 | #else | ||
55 | #define NAN (0.0 / 0.0) | ||
56 | #endif | ||
57 | #endif | ||
58 | |||
59 | static unsigned long get_field (const unsigned char *, | ||
60 | enum floatformat_byteorders, | ||
61 | unsigned int, | ||
62 | unsigned int, | ||
63 | unsigned int); | ||
64 | static int floatformat_always_valid (const struct floatformat *fmt, | ||
65 | const void *from); | ||
66 | |||
67 | static int | ||
68 | floatformat_always_valid (const struct floatformat *fmt /*ATTRIBUTE_UNUSED*/, | ||
69 | const void *from /*ATTRIBUTE_UNUSED*/) | ||
70 | { | ||
71 | return 1; | ||
72 | } | ||
73 | |||
74 | /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not | ||
75 | going to bother with trying to muck around with whether it is defined in | ||
76 | a system header, what we do if not, etc. */ | ||
77 | #define FLOATFORMAT_CHAR_BIT 8 | ||
78 | |||
79 | /* floatformats for IEEE single and double, big and little endian. */ | ||
80 | const struct floatformat floatformat_ieee_single_big = | ||
81 | { | ||
82 | floatformat_big, 32, 0, 1, 8, 127, 255, 9, 23, | ||
83 | floatformat_intbit_no, | ||
84 | "floatformat_ieee_single_big", | ||
85 | floatformat_always_valid | ||
86 | }; | ||
87 | const struct floatformat floatformat_ieee_single_little = | ||
88 | { | ||
89 | floatformat_little, 32, 0, 1, 8, 127, 255, 9, 23, | ||
90 | floatformat_intbit_no, | ||
91 | "floatformat_ieee_single_little", | ||
92 | floatformat_always_valid | ||
93 | }; | ||
94 | const struct floatformat floatformat_ieee_double_big = | ||
95 | { | ||
96 | floatformat_big, 64, 0, 1, 11, 1023, 2047, 12, 52, | ||
97 | floatformat_intbit_no, | ||
98 | "floatformat_ieee_double_big", | ||
99 | floatformat_always_valid | ||
100 | }; | ||
101 | const struct floatformat floatformat_ieee_double_little = | ||
102 | { | ||
103 | floatformat_little, 64, 0, 1, 11, 1023, 2047, 12, 52, | ||
104 | floatformat_intbit_no, | ||
105 | "floatformat_ieee_double_little", | ||
106 | floatformat_always_valid | ||
107 | }; | ||
108 | |||
109 | /* floatformat for IEEE double, little endian byte order, with big endian word | ||
110 | ordering, as on the ARM. */ | ||
111 | |||
112 | const struct floatformat floatformat_ieee_double_littlebyte_bigword = | ||
113 | { | ||
114 | floatformat_littlebyte_bigword, 64, 0, 1, 11, 1023, 2047, 12, 52, | ||
115 | floatformat_intbit_no, | ||
116 | "floatformat_ieee_double_littlebyte_bigword", | ||
117 | floatformat_always_valid | ||
118 | }; | ||
119 | |||
120 | /* floatformat for VAX. Not quite IEEE, but close enough. */ | ||
121 | |||
122 | const struct floatformat floatformat_vax_f = | ||
123 | { | ||
124 | floatformat_vax, 32, 0, 1, 8, 129, 0, 9, 23, | ||
125 | floatformat_intbit_no, | ||
126 | "floatformat_vax_f", | ||
127 | floatformat_always_valid | ||
128 | }; | ||
129 | const struct floatformat floatformat_vax_d = | ||
130 | { | ||
131 | floatformat_vax, 64, 0, 1, 8, 129, 0, 9, 55, | ||
132 | floatformat_intbit_no, | ||
133 | "floatformat_vax_d", | ||
134 | floatformat_always_valid | ||
135 | }; | ||
136 | const struct floatformat floatformat_vax_g = | ||
137 | { | ||
138 | floatformat_vax, 64, 0, 1, 11, 1025, 0, 12, 52, | ||
139 | floatformat_intbit_no, | ||
140 | "floatformat_vax_g", | ||
141 | floatformat_always_valid | ||
142 | }; | ||
143 | |||
144 | static int floatformat_i387_ext_is_valid (const struct floatformat *fmt, | ||
145 | const void *from); | ||
146 | |||
147 | static int | ||
148 | floatformat_i387_ext_is_valid (const struct floatformat *fmt, const void *from) | ||
149 | { | ||
150 | /* In the i387 double-extended format, if the exponent is all ones, | ||
151 | then the integer bit must be set. If the exponent is neither 0 | ||
152 | nor ~0, the intbit must also be set. Only if the exponent is | ||
153 | zero can it be zero, and then it must be zero. */ | ||
154 | unsigned long exponent, int_bit; | ||
155 | const unsigned char *ufrom = (const unsigned char *) from; | ||
156 | |||
157 | exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize, | ||
158 | fmt->exp_start, fmt->exp_len); | ||
159 | int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize, | ||
160 | fmt->man_start, 1); | ||
161 | |||
162 | if ((exponent == 0) != (int_bit == 0)) | ||
163 | return 0; | ||
164 | else | ||
165 | return 1; | ||
166 | } | ||
167 | |||
168 | const struct floatformat floatformat_i387_ext = | ||
169 | { | ||
170 | floatformat_little, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64, | ||
171 | floatformat_intbit_yes, | ||
172 | "floatformat_i387_ext", | ||
173 | floatformat_i387_ext_is_valid | ||
174 | }; | ||
175 | const struct floatformat floatformat_m68881_ext = | ||
176 | { | ||
177 | /* Note that the bits from 16 to 31 are unused. */ | ||
178 | floatformat_big, 96, 0, 1, 15, 0x3fff, 0x7fff, 32, 64, | ||
179 | floatformat_intbit_yes, | ||
180 | "floatformat_m68881_ext", | ||
181 | floatformat_always_valid | ||
182 | }; | ||
183 | const struct floatformat floatformat_i960_ext = | ||
184 | { | ||
185 | /* Note that the bits from 0 to 15 are unused. */ | ||
186 | floatformat_little, 96, 16, 17, 15, 0x3fff, 0x7fff, 32, 64, | ||
187 | floatformat_intbit_yes, | ||
188 | "floatformat_i960_ext", | ||
189 | floatformat_always_valid | ||
190 | }; | ||
191 | const struct floatformat floatformat_m88110_ext = | ||
192 | { | ||
193 | floatformat_big, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64, | ||
194 | floatformat_intbit_yes, | ||
195 | "floatformat_m88110_ext", | ||
196 | floatformat_always_valid | ||
197 | }; | ||
198 | const struct floatformat floatformat_m88110_harris_ext = | ||
199 | { | ||
200 | /* Harris uses raw format 128 bytes long, but the number is just an ieee | ||
201 | double, and the last 64 bits are wasted. */ | ||
202 | floatformat_big,128, 0, 1, 11, 0x3ff, 0x7ff, 12, 52, | ||
203 | floatformat_intbit_no, | ||
204 | "floatformat_m88110_ext_harris", | ||
205 | floatformat_always_valid | ||
206 | }; | ||
207 | const struct floatformat floatformat_arm_ext_big = | ||
208 | { | ||
209 | /* Bits 1 to 16 are unused. */ | ||
210 | floatformat_big, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64, | ||
211 | floatformat_intbit_yes, | ||
212 | "floatformat_arm_ext_big", | ||
213 | floatformat_always_valid | ||
214 | }; | ||
215 | const struct floatformat floatformat_arm_ext_littlebyte_bigword = | ||
216 | { | ||
217 | /* Bits 1 to 16 are unused. */ | ||
218 | floatformat_littlebyte_bigword, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64, | ||
219 | floatformat_intbit_yes, | ||
220 | "floatformat_arm_ext_littlebyte_bigword", | ||
221 | floatformat_always_valid | ||
222 | }; | ||
223 | const struct floatformat floatformat_ia64_spill_big = | ||
224 | { | ||
225 | floatformat_big, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64, | ||
226 | floatformat_intbit_yes, | ||
227 | "floatformat_ia64_spill_big", | ||
228 | floatformat_always_valid | ||
229 | }; | ||
230 | const struct floatformat floatformat_ia64_spill_little = | ||
231 | { | ||
232 | floatformat_little, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64, | ||
233 | floatformat_intbit_yes, | ||
234 | "floatformat_ia64_spill_little", | ||
235 | floatformat_always_valid | ||
236 | }; | ||
237 | const struct floatformat floatformat_ia64_quad_big = | ||
238 | { | ||
239 | floatformat_big, 128, 0, 1, 15, 16383, 0x7fff, 16, 112, | ||
240 | floatformat_intbit_no, | ||
241 | "floatformat_ia64_quad_big", | ||
242 | floatformat_always_valid | ||
243 | }; | ||
244 | const struct floatformat floatformat_ia64_quad_little = | ||
245 | { | ||
246 | floatformat_little, 128, 0, 1, 15, 16383, 0x7fff, 16, 112, | ||
247 | floatformat_intbit_no, | ||
248 | "floatformat_ia64_quad_little", | ||
249 | floatformat_always_valid | ||
250 | }; | ||
251 | |||
252 | |||
253 | #ifndef min | ||
254 | #define min(a, b) ((a) < (b) ? (a) : (b)) | ||
255 | #endif | ||
256 | |||
257 | /* Extract a field which starts at START and is LEN bits long. DATA and | ||
258 | TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */ | ||
259 | static unsigned long | ||
260 | get_field (const unsigned char *data, enum floatformat_byteorders order, | ||
261 | unsigned int total_len, unsigned int start, unsigned int len) | ||
262 | { | ||
263 | unsigned long result = 0; | ||
264 | unsigned int cur_byte; | ||
265 | int lo_bit, hi_bit, cur_bitshift = 0; | ||
266 | int nextbyte = (order == floatformat_little) ? 1 : -1; | ||
267 | |||
268 | /* Start is in big-endian bit order! Fix that first. */ | ||
269 | start = total_len - (start + len); | ||
270 | |||
271 | /* Start at the least significant part of the field. */ | ||
272 | if (order == floatformat_little) | ||
273 | cur_byte = start / FLOATFORMAT_CHAR_BIT; | ||
274 | else | ||
275 | cur_byte = (total_len - start - 1) / FLOATFORMAT_CHAR_BIT; | ||
276 | |||
277 | lo_bit = start % FLOATFORMAT_CHAR_BIT; | ||
278 | hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT); | ||
279 | |||
280 | do | ||
281 | { | ||
282 | unsigned int shifted = *(data + cur_byte) >> lo_bit; | ||
283 | unsigned int bits = hi_bit - lo_bit; | ||
284 | unsigned int mask = (1 << bits) - 1; | ||
285 | result |= (shifted & mask) << cur_bitshift; | ||
286 | len -= bits; | ||
287 | cur_bitshift += bits; | ||
288 | cur_byte += nextbyte; | ||
289 | lo_bit = 0; | ||
290 | hi_bit = min (len, FLOATFORMAT_CHAR_BIT); | ||
291 | } | ||
292 | while (len != 0); | ||
293 | |||
294 | return result; | ||
295 | } | ||
296 | |||
297 | /* Convert from FMT to a double. | ||
298 | FROM is the address of the extended float. | ||
299 | Store the double in *TO. */ | ||
300 | |||
301 | void | ||
302 | floatformat_to_double (const struct floatformat *fmt, | ||
303 | const void *from, double *to) | ||
304 | { | ||
305 | const unsigned char *ufrom = (const unsigned char *) from; | ||
306 | double dto; | ||
307 | long exponent; | ||
308 | unsigned long mant; | ||
309 | unsigned int mant_bits, mant_off; | ||
310 | int mant_bits_left; | ||
311 | int special_exponent; /* It's a NaN, denorm or zero */ | ||
312 | |||
313 | exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize, | ||
314 | fmt->exp_start, fmt->exp_len); | ||
315 | |||
316 | /* If the exponent indicates a NaN, we don't have information to | ||
317 | decide what to do. So we handle it like IEEE, except that we | ||
318 | don't try to preserve the type of NaN. FIXME. */ | ||
319 | if ((unsigned long) exponent == fmt->exp_nan) | ||
320 | { | ||
321 | int nan; | ||
322 | |||
323 | mant_off = fmt->man_start; | ||
324 | mant_bits_left = fmt->man_len; | ||
325 | nan = 0; | ||
326 | while (mant_bits_left > 0) | ||
327 | { | ||
328 | mant_bits = min (mant_bits_left, 32); | ||
329 | |||
330 | if (get_field (ufrom, fmt->byteorder, fmt->totalsize, | ||
331 | mant_off, mant_bits) != 0) | ||
332 | { | ||
333 | /* This is a NaN. */ | ||
334 | nan = 1; | ||
335 | break; | ||
336 | } | ||
337 | |||
338 | mant_off += mant_bits; | ||
339 | mant_bits_left -= mant_bits; | ||
340 | } | ||
341 | |||
342 | /* On certain systems (such as GNU/Linux), the use of the | ||
343 | INFINITY macro below may generate a warning that can not be | ||
344 | silenced due to a bug in GCC (PR preprocessor/11931). The | ||
345 | preprocessor fails to recognise the __extension__ keyword in | ||
346 | conjunction with the GNU/C99 extension for hexadecimal | ||
347 | floating point constants and will issue a warning when | ||
348 | compiling with -pedantic. */ | ||
349 | if (nan) | ||
350 | dto = NAN; | ||
351 | else | ||
352 | dto = INFINITY; | ||
353 | |||
354 | if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1)) | ||
355 | dto = -dto; | ||
356 | |||
357 | *to = dto; | ||
358 | |||
359 | return; | ||
360 | } | ||
361 | |||
362 | mant_bits_left = fmt->man_len; | ||
363 | mant_off = fmt->man_start; | ||
364 | dto = 0.0; | ||
365 | |||
366 | special_exponent = exponent == 0 || (unsigned long) exponent == fmt->exp_nan; | ||
367 | |||
368 | /* Don't bias zero's, denorms or NaNs. */ | ||
369 | if (!special_exponent) | ||
370 | exponent -= fmt->exp_bias; | ||
371 | |||
372 | /* Build the result algebraically. Might go infinite, underflow, etc; | ||
373 | who cares. */ | ||
374 | |||
375 | /* If this format uses a hidden bit, explicitly add it in now. Otherwise, | ||
376 | increment the exponent by one to account for the integer bit. */ | ||
377 | |||
378 | if (!special_exponent) | ||
379 | { | ||
380 | if (fmt->intbit == floatformat_intbit_no) | ||
381 | dto = ldexp (1.0, exponent); | ||
382 | else | ||
383 | exponent++; | ||
384 | } | ||
385 | |||
386 | while (mant_bits_left > 0) | ||
387 | { | ||
388 | mant_bits = min (mant_bits_left, 32); | ||
389 | |||
390 | mant = get_field (ufrom, fmt->byteorder, fmt->totalsize, | ||
391 | mant_off, mant_bits); | ||
392 | |||
393 | /* Handle denormalized numbers. FIXME: What should we do for | ||
394 | non-IEEE formats? */ | ||
395 | if (special_exponent && exponent == 0 && mant != 0) | ||
396 | dto += ldexp ((double)mant, | ||
397 | (- fmt->exp_bias | ||
398 | - mant_bits | ||
399 | - (mant_off - fmt->man_start) | ||
400 | + 1)); | ||
401 | else | ||
402 | dto += ldexp ((double)mant, exponent - mant_bits); | ||
403 | if (exponent != 0) | ||
404 | exponent -= mant_bits; | ||
405 | mant_off += mant_bits; | ||
406 | mant_bits_left -= mant_bits; | ||
407 | } | ||
408 | |||
409 | /* Negate it if negative. */ | ||
410 | if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1)) | ||
411 | dto = -dto; | ||
412 | *to = dto; | ||
413 | } | ||
414 | |||
415 | static void put_field (unsigned char *, enum floatformat_byteorders, | ||
416 | unsigned int, | ||
417 | unsigned int, | ||
418 | unsigned int, | ||
419 | unsigned long); | ||
420 | |||
421 | /* Set a field which starts at START and is LEN bits long. DATA and | ||
422 | TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */ | ||
423 | static void | ||
424 | put_field (unsigned char *data, enum floatformat_byteorders order, | ||
425 | unsigned int total_len, unsigned int start, unsigned int len, | ||
426 | unsigned long stuff_to_put) | ||
427 | { | ||
428 | unsigned int cur_byte; | ||
429 | int lo_bit, hi_bit; | ||
430 | int nextbyte = (order == floatformat_little) ? 1 : -1; | ||
431 | |||
432 | /* Start is in big-endian bit order! Fix that first. */ | ||
433 | start = total_len - (start + len); | ||
434 | |||
435 | /* Start at the least significant part of the field. */ | ||
436 | if (order == floatformat_little) | ||
437 | cur_byte = start / FLOATFORMAT_CHAR_BIT; | ||
438 | else | ||
439 | cur_byte = (total_len - start - 1) / FLOATFORMAT_CHAR_BIT; | ||
440 | |||
441 | lo_bit = start % FLOATFORMAT_CHAR_BIT; | ||
442 | hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT); | ||
443 | |||
444 | do | ||
445 | { | ||
446 | unsigned char *byte_ptr = data + cur_byte; | ||
447 | unsigned int bits = hi_bit - lo_bit; | ||
448 | unsigned int mask = ((1 << bits) - 1) << lo_bit; | ||
449 | *byte_ptr = (*byte_ptr & ~mask) | ((stuff_to_put << lo_bit) & mask); | ||
450 | stuff_to_put >>= bits; | ||
451 | len -= bits; | ||
452 | cur_byte += nextbyte; | ||
453 | lo_bit = 0; | ||
454 | hi_bit = min (len, FLOATFORMAT_CHAR_BIT); | ||
455 | } | ||
456 | while (len != 0); | ||
457 | } | ||
458 | |||
459 | /* The converse: convert the double *FROM to an extended float | ||
460 | and store where TO points. Neither FROM nor TO have any alignment | ||
461 | restrictions. */ | ||
462 | |||
463 | void | ||
464 | floatformat_from_double (const struct floatformat *fmt, | ||
465 | const double *from, void *to) | ||
466 | { | ||
467 | double dfrom; | ||
468 | int exponent; | ||
469 | double mant; | ||
470 | unsigned int mant_bits, mant_off; | ||
471 | int mant_bits_left; | ||
472 | unsigned char *uto = (unsigned char *) to; | ||
473 | |||
474 | dfrom = *from; | ||
475 | memset (uto, 0, fmt->totalsize / FLOATFORMAT_CHAR_BIT); | ||
476 | |||
477 | /* If negative, set the sign bit. */ | ||
478 | if (dfrom < 0) | ||
479 | { | ||
480 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1); | ||
481 | dfrom = -dfrom; | ||
482 | } | ||
483 | |||
484 | if (dfrom == 0) | ||
485 | { | ||
486 | /* 0.0. */ | ||
487 | return; | ||
488 | } | ||
489 | |||
490 | if (dfrom != dfrom) | ||
491 | { | ||
492 | /* NaN. */ | ||
493 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, | ||
494 | fmt->exp_len, fmt->exp_nan); | ||
495 | /* Be sure it's not infinity, but NaN value is irrelevant. */ | ||
496 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start, | ||
497 | 32, 1); | ||
498 | return; | ||
499 | } | ||
500 | |||
501 | if (dfrom + dfrom == dfrom) | ||
502 | { | ||
503 | /* This can only happen for an infinite value (or zero, which we | ||
504 | already handled above). */ | ||
505 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, | ||
506 | fmt->exp_len, fmt->exp_nan); | ||
507 | return; | ||
508 | } | ||
509 | |||
510 | mant = frexp (dfrom, &exponent); | ||
511 | if (exponent + fmt->exp_bias - 1 > 0) | ||
512 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, | ||
513 | fmt->exp_len, exponent + fmt->exp_bias - 1); | ||
514 | else | ||
515 | { | ||
516 | /* Handle a denormalized number. FIXME: What should we do for | ||
517 | non-IEEE formats? */ | ||
518 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, | ||
519 | fmt->exp_len, 0); | ||
520 | mant = ldexp (mant, exponent + fmt->exp_bias - 1); | ||
521 | } | ||
522 | |||
523 | mant_bits_left = fmt->man_len; | ||
524 | mant_off = fmt->man_start; | ||
525 | while (mant_bits_left > 0) | ||
526 | { | ||
527 | unsigned long mant_long; | ||
528 | mant_bits = mant_bits_left < 32 ? mant_bits_left : 32; | ||
529 | |||
530 | mant *= 4294967296.0; | ||
531 | mant_long = (unsigned long)mant; | ||
532 | mant -= mant_long; | ||
533 | |||
534 | /* If the integer bit is implicit, and we are not creating a | ||
535 | denormalized number, then we need to discard it. */ | ||
536 | if ((unsigned int) mant_bits_left == fmt->man_len | ||
537 | && fmt->intbit == floatformat_intbit_no | ||
538 | && exponent + fmt->exp_bias - 1 > 0) | ||
539 | { | ||
540 | mant_long &= 0x7fffffff; | ||
541 | mant_bits -= 1; | ||
542 | } | ||
543 | else if (mant_bits < 32) | ||
544 | { | ||
545 | /* The bits we want are in the most significant MANT_BITS bits of | ||
546 | mant_long. Move them to the least significant. */ | ||
547 | mant_long >>= 32 - mant_bits; | ||
548 | } | ||
549 | |||
550 | put_field (uto, fmt->byteorder, fmt->totalsize, | ||
551 | mant_off, mant_bits, mant_long); | ||
552 | mant_off += mant_bits; | ||
553 | mant_bits_left -= mant_bits; | ||
554 | } | ||
555 | } | ||
556 | |||
557 | /* Return non-zero iff the data at FROM is a valid number in format FMT. */ | ||
558 | |||
559 | int | ||
560 | floatformat_is_valid (const struct floatformat *fmt, const void *from) | ||
561 | { | ||
562 | return fmt->is_valid (fmt, from); | ||
563 | } | ||
564 | |||
565 | |||
566 | #ifdef IEEE_DEBUG | ||
567 | |||
568 | #include <stdio.h> | ||
569 | |||
570 | /* This is to be run on a host which uses IEEE floating point. */ | ||
571 | |||
572 | void | ||
573 | ieee_test (double n) | ||
574 | { | ||
575 | double result; | ||
576 | |||
577 | floatformat_to_double (&floatformat_ieee_double_little, &n, &result); | ||
578 | if ((n != result && (! isnan (n) || ! isnan (result))) | ||
579 | || (n < 0 && result >= 0) | ||
580 | || (n >= 0 && result < 0)) | ||
581 | printf ("Differ(to): %.20g -> %.20g\n", n, result); | ||
582 | |||
583 | floatformat_from_double (&floatformat_ieee_double_little, &n, &result); | ||
584 | if ((n != result && (! isnan (n) || ! isnan (result))) | ||
585 | || (n < 0 && result >= 0) | ||
586 | || (n >= 0 && result < 0)) | ||
587 | printf ("Differ(from): %.20g -> %.20g\n", n, result); | ||
588 | |||
589 | #if 0 | ||
590 | { | ||
591 | char exten[16]; | ||
592 | |||
593 | floatformat_from_double (&floatformat_m68881_ext, &n, exten); | ||
594 | floatformat_to_double (&floatformat_m68881_ext, exten, &result); | ||
595 | if (n != result) | ||
596 | printf ("Differ(to+from): %.20g -> %.20g\n", n, result); | ||
597 | } | ||
598 | #endif | ||
599 | |||
600 | #if IEEE_DEBUG > 1 | ||
601 | /* This is to be run on a host which uses 68881 format. */ | ||
602 | { | ||
603 | long double ex = *(long double *)exten; | ||
604 | if (ex != n) | ||
605 | printf ("Differ(from vs. extended): %.20g\n", n); | ||
606 | } | ||
607 | #endif | ||
608 | } | ||
609 | |||
610 | int | ||
611 | main (void) | ||
612 | { | ||
613 | ieee_test (0.0); | ||
614 | ieee_test (0.5); | ||
615 | ieee_test (256.0); | ||
616 | ieee_test (0.12345); | ||
617 | ieee_test (234235.78907234); | ||
618 | ieee_test (-512.0); | ||
619 | ieee_test (-0.004321); | ||
620 | ieee_test (1.2E-70); | ||
621 | ieee_test (1.2E-316); | ||
622 | ieee_test (4.9406564584124654E-324); | ||
623 | ieee_test (- 4.9406564584124654E-324); | ||
624 | ieee_test (- 0.0); | ||
625 | ieee_test (- INFINITY); | ||
626 | ieee_test (- NAN); | ||
627 | ieee_test (INFINITY); | ||
628 | ieee_test (NAN); | ||
629 | return 0; | ||
630 | } | ||
631 | #endif | ||
diff --git a/src/plugins/convert_numeric.h b/src/plugins/convert_numeric.h deleted file mode 100644 index 6889fca..0000000 --- a/src/plugins/convert_numeric.h +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | /* IEEE floating point support declarations, for GDB, the GNU Debugger. | ||
2 | Copyright 1991, 1994, 1995, 1997, 2000, 2003, 2005 | ||
3 | Free Software Foundation, Inc. | ||
4 | |||
5 | This file is part of GDB. | ||
6 | |||
7 | This program is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation; either version 2 of the License, or | ||
10 | (at your option) any later version. | ||
11 | |||
12 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program; if not, write to the Free Software | ||
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
20 | |||
21 | #if !defined (FLOATFORMAT_H) | ||
22 | #define FLOATFORMAT_H 1 | ||
23 | |||
24 | /*#include "ansidecl.h"*/ | ||
25 | |||
26 | /* A floatformat consists of a sign bit, an exponent and a mantissa. Once the | ||
27 | bytes are concatenated according to the byteorder flag, then each of those | ||
28 | fields is contiguous. We number the bits with 0 being the most significant | ||
29 | (i.e. BITS_BIG_ENDIAN type numbering), and specify which bits each field | ||
30 | contains with the *_start and *_len fields. */ | ||
31 | |||
32 | /* What is the order of the bytes? */ | ||
33 | |||
34 | enum floatformat_byteorders { | ||
35 | /* Standard little endian byte order. | ||
36 | EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */ | ||
37 | floatformat_little, | ||
38 | |||
39 | /* Standard big endian byte order. | ||
40 | EX: 1.2345678e10 => 42 06 fe e0 c5 80 00 00 */ | ||
41 | floatformat_big, | ||
42 | |||
43 | /* Little endian byte order but big endian word order. | ||
44 | EX: 1.2345678e10 => e0 fe 06 42 00 00 80 c5 */ | ||
45 | floatformat_littlebyte_bigword, | ||
46 | |||
47 | /* VAX byte order. Little endian byte order with 16-bit words. The | ||
48 | following example is an illustration of the byte order only; VAX | ||
49 | doesn't have a fully IEEE compliant floating-point format. | ||
50 | EX: 1.2345678e10 => 80 c5 00 00 06 42 e0 fe */ | ||
51 | floatformat_vax | ||
52 | }; | ||
53 | |||
54 | enum floatformat_intbit { floatformat_intbit_yes, floatformat_intbit_no }; | ||
55 | |||
56 | struct floatformat | ||
57 | { | ||
58 | enum floatformat_byteorders byteorder; | ||
59 | unsigned int totalsize; /* Total size of number in bits */ | ||
60 | |||
61 | /* Sign bit is always one bit long. 1 means negative, 0 means positive. */ | ||
62 | unsigned int sign_start; | ||
63 | |||
64 | unsigned int exp_start; | ||
65 | unsigned int exp_len; | ||
66 | /* Bias added to a "true" exponent to form the biased exponent. It | ||
67 | is intentionally signed as, otherwize, -exp_bias can turn into a | ||
68 | very large number (e.g., given the exp_bias of 0x3fff and a 64 | ||
69 | bit long, the equation (long)(1 - exp_bias) evaluates to | ||
70 | 4294950914) instead of -16382). */ | ||
71 | int exp_bias; | ||
72 | /* Exponent value which indicates NaN. This is the actual value stored in | ||
73 | the float, not adjusted by the exp_bias. This usually consists of all | ||
74 | one bits. */ | ||
75 | unsigned int exp_nan; | ||
76 | |||
77 | unsigned int man_start; | ||
78 | unsigned int man_len; | ||
79 | |||
80 | /* Is the integer bit explicit or implicit? */ | ||
81 | enum floatformat_intbit intbit; | ||
82 | |||
83 | /* Internal name for debugging. */ | ||
84 | const char *name; | ||
85 | |||
86 | /* Validator method. */ | ||
87 | int (*is_valid) (const struct floatformat *fmt, const void *from); | ||
88 | }; | ||
89 | |||
90 | /* floatformats for IEEE single and double, big and little endian. */ | ||
91 | |||
92 | extern const struct floatformat floatformat_ieee_single_big; | ||
93 | extern const struct floatformat floatformat_ieee_single_little; | ||
94 | extern const struct floatformat floatformat_ieee_double_big; | ||
95 | extern const struct floatformat floatformat_ieee_double_little; | ||
96 | |||
97 | /* floatformat for ARM IEEE double, little endian bytes and big endian words */ | ||
98 | |||
99 | extern const struct floatformat floatformat_ieee_double_littlebyte_bigword; | ||
100 | |||
101 | /* floatformats for VAX. */ | ||
102 | |||
103 | extern const struct floatformat floatformat_vax_f; | ||
104 | extern const struct floatformat floatformat_vax_d; | ||
105 | extern const struct floatformat floatformat_vax_g; | ||
106 | |||
107 | /* floatformats for various extendeds. */ | ||
108 | |||
109 | extern const struct floatformat floatformat_i387_ext; | ||
110 | extern const struct floatformat floatformat_m68881_ext; | ||
111 | extern const struct floatformat floatformat_i960_ext; | ||
112 | extern const struct floatformat floatformat_m88110_ext; | ||
113 | extern const struct floatformat floatformat_m88110_harris_ext; | ||
114 | extern const struct floatformat floatformat_arm_ext_big; | ||
115 | extern const struct floatformat floatformat_arm_ext_littlebyte_bigword; | ||
116 | /* IA-64 Floating Point register spilt into memory. */ | ||
117 | extern const struct floatformat floatformat_ia64_spill_big; | ||
118 | extern const struct floatformat floatformat_ia64_spill_little; | ||
119 | extern const struct floatformat floatformat_ia64_quad_big; | ||
120 | extern const struct floatformat floatformat_ia64_quad_little; | ||
121 | |||
122 | /* Convert from FMT to a double. | ||
123 | FROM is the address of the extended float. | ||
124 | Store the double in *TO. */ | ||
125 | |||
126 | extern void | ||
127 | floatformat_to_double (const struct floatformat *, const void *, double *); | ||
128 | |||
129 | /* The converse: convert the double *FROM to FMT | ||
130 | and store where TO points. */ | ||
131 | |||
132 | extern void | ||
133 | floatformat_from_double (const struct floatformat *, const double *, void *); | ||
134 | |||
135 | /* Return non-zero iff the data at FROM is a valid number in format FMT. */ | ||
136 | |||
137 | extern int | ||
138 | floatformat_is_valid (const struct floatformat *fmt, const void *from); | ||
139 | |||
140 | #endif /* defined (FLOATFORMAT_H) */ | ||
diff --git a/src/plugins/elfextractor.c b/src/plugins/elfextractor.c index 535c435..d750de3 100644 --- a/src/plugins/elfextractor.c +++ b/src/plugins/elfextractor.c | |||
@@ -294,7 +294,7 @@ getSectionHdr (char *data, | |||
294 | if (ehdr->e_shnum <= idx) | 294 | if (ehdr->e_shnum <= idx) |
295 | return -1; | 295 | return -1; |
296 | 296 | ||
297 | cat_unpack (&data[ehdr->e_shoff + ehdr->e_shentsize * idx], | 297 | EXTRACTOR_common_cat_unpack (&data[ehdr->e_shoff + ehdr->e_shentsize * idx], |
298 | ELF_SECTION_SPECS[getByteorder (data[EI_CLASS])], | 298 | ELF_SECTION_SPECS[getByteorder (data[EI_CLASS])], |
299 | ELF_SECTION_FIELDS (ret)); | 299 | ELF_SECTION_FIELDS (ret)); |
300 | return 0; | 300 | return 0; |
@@ -312,7 +312,7 @@ getDynTag (char *data, | |||
312 | { | 312 | { |
313 | if ((off + osize > size) || ((idx + 1) * ELF_DYN_SIZE > osize)) | 313 | if ((off + osize > size) || ((idx + 1) * ELF_DYN_SIZE > osize)) |
314 | return -1; | 314 | return -1; |
315 | cat_unpack (&data[off + idx * ELF_DYN_SIZE], | 315 | EXTRACTOR_common_cat_unpack (&data[off + idx * ELF_DYN_SIZE], |
316 | ELF_DYN_SPECS[getByteorder (data[EI_CLASS])], | 316 | ELF_DYN_SPECS[getByteorder (data[EI_CLASS])], |
317 | ELF_DYN_FIELDS (ret)); | 317 | ELF_DYN_FIELDS (ret)); |
318 | return 0; | 318 | return 0; |
@@ -330,7 +330,7 @@ getProgramHdr (char *data, | |||
330 | if (ehdr->e_phnum <= idx) | 330 | if (ehdr->e_phnum <= idx) |
331 | return -1; | 331 | return -1; |
332 | 332 | ||
333 | cat_unpack (&data[ehdr->e_phoff + ehdr->e_phensize * idx], | 333 | EXTRACTOR_common_cat_unpack (&data[ehdr->e_phoff + ehdr->e_phensize * idx], |
334 | ELF_PHDR_SPECS[getByteorder (data[EI_CLASS])], | 334 | ELF_PHDR_SPECS[getByteorder (data[EI_CLASS])], |
335 | ELF_PHDR_FIELDS (ret)); | 335 | ELF_PHDR_FIELDS (ret)); |
336 | return 0; | 336 | return 0; |
@@ -353,7 +353,7 @@ getELFHdr (char *data, size_t size, Elf32_Ehdr * ehdr) | |||
353 | { | 353 | { |
354 | case ELFDATA2LSB: | 354 | case ELFDATA2LSB: |
355 | case ELFDATA2MSB: | 355 | case ELFDATA2MSB: |
356 | cat_unpack (&data[EI_NIDENT], | 356 | EXTRACTOR_common_cat_unpack (&data[EI_NIDENT], |
357 | ELF_HEADER_SPECS[getByteorder (data[EI_CLASS])], | 357 | ELF_HEADER_SPECS[getByteorder (data[EI_CLASS])], |
358 | ELF_HEADER_FIELDS (ehdr)); | 358 | ELF_HEADER_FIELDS (ehdr)); |
359 | break; | 359 | break; |
diff --git a/src/plugins/filenameextractor.c b/src/plugins/filenameextractor.c index ce3ad78..500f9b8 100644 --- a/src/plugins/filenameextractor.c +++ b/src/plugins/filenameextractor.c | |||
@@ -44,7 +44,7 @@ libextractor_filename_extract (const char *filename, | |||
44 | } | 44 | } |
45 | keyword = malloc (sizeof (EXTRACTOR_KeywordList)); | 45 | keyword = malloc (sizeof (EXTRACTOR_KeywordList)); |
46 | keyword->next = prev; | 46 | keyword->next = prev; |
47 | keyword->keyword = convertToUtf8 (filenameRoot, | 47 | keyword->keyword = EXTRACTOR_common_convert_to_utf8 (filenameRoot, |
48 | strlen (filenameRoot), | 48 | strlen (filenameRoot), |
49 | nl_langinfo (CODESET)); | 49 | nl_langinfo (CODESET)); |
50 | keyword->keywordType = EXTRACTOR_FILENAME; | 50 | keyword->keywordType = EXTRACTOR_FILENAME; |
diff --git a/src/plugins/flvextractor.c b/src/plugins/flvextractor.c index 60f7979..c22cce5 100644 --- a/src/plugins/flvextractor.c +++ b/src/plugins/flvextractor.c | |||
@@ -117,8 +117,8 @@ static inline double readDouble(const unsigned char **data) | |||
117 | const unsigned char *ptr = *data; | 117 | const unsigned char *ptr = *data; |
118 | double val; | 118 | double val; |
119 | 119 | ||
120 | floatformat_to_double(&floatformat_ieee_double_big, | 120 | EXTRACTOR_common_floatformat_to_double(&EXTRACTOR_common_floatformat_ieee_double_big, |
121 | (const void *)ptr, | 121 | (const void *)ptr, |
122 | &val); | 122 | &val); |
123 | ptr += 8; | 123 | ptr += 8; |
124 | *data = ptr; | 124 | *data = ptr; |
@@ -152,7 +152,7 @@ static int readASBoolean(const unsigned char **data, | |||
152 | { | 152 | { |
153 | const unsigned char *ptr = *data; | 153 | const unsigned char *ptr = *data; |
154 | int val; | 154 | int val; |
155 | 155 | ||
156 | if (*len < 1) | 156 | if (*len < 1) |
157 | return -1; | 157 | return -1; |
158 | 158 | ||
@@ -192,7 +192,7 @@ static int readASString(const unsigned char **data, | |||
192 | const unsigned char *ptr = *data; | 192 | const unsigned char *ptr = *data; |
193 | char *ret; | 193 | char *ret; |
194 | int slen; | 194 | int slen; |
195 | 195 | ||
196 | if (*len < 2) | 196 | if (*len < 2) |
197 | return -1; | 197 | return -1; |
198 | 198 | ||
@@ -214,9 +214,9 @@ static int readASString(const unsigned char **data, | |||
214 | return 0; | 214 | return 0; |
215 | } | 215 | } |
216 | 216 | ||
217 | static int parse_amf(const unsigned char **data, | 217 | static int parse_amf(const unsigned char **data, |
218 | size_t *len, | 218 | size_t *len, |
219 | AMFParserHandler *handler) | 219 | AMFParserHandler *handler) |
220 | { | 220 | { |
221 | const unsigned char *ptr = *data; | 221 | const unsigned char *ptr = *data; |
222 | unsigned char astype; | 222 | unsigned char astype; |
@@ -231,8 +231,8 @@ static int parse_amf(const unsigned char **data, | |||
231 | double val; | 231 | double val; |
232 | ret = readASNumber(&ptr, len, &val); | 232 | ret = readASNumber(&ptr, len, &val); |
233 | if (ret == 0) | 233 | if (ret == 0) |
234 | (*(handler->as_end_callback))(astype, | 234 | (*(handler->as_end_callback))(astype, |
235 | &val, | 235 | &val, |
236 | handler->userdata); | 236 | handler->userdata); |
237 | break; | 237 | break; |
238 | } | 238 | } |
@@ -241,8 +241,8 @@ static int parse_amf(const unsigned char **data, | |||
241 | int val; | 241 | int val; |
242 | ret = readASBoolean(&ptr, len, &val); | 242 | ret = readASBoolean(&ptr, len, &val); |
243 | if (ret == 0) | 243 | if (ret == 0) |
244 | (*(handler->as_end_callback))(astype, | 244 | (*(handler->as_end_callback))(astype, |
245 | &val, | 245 | &val, |
246 | handler->userdata); | 246 | handler->userdata); |
247 | break; | 247 | break; |
248 | } | 248 | } |
@@ -251,8 +251,8 @@ static int parse_amf(const unsigned char **data, | |||
251 | char *val; | 251 | char *val; |
252 | ret = readASString(&ptr, len, &val); | 252 | ret = readASString(&ptr, len, &val); |
253 | if (ret == 0) { | 253 | if (ret == 0) { |
254 | (*(handler->as_end_callback))(astype, | 254 | (*(handler->as_end_callback))(astype, |
255 | val, | 255 | val, |
256 | handler->userdata); | 256 | handler->userdata); |
257 | free(val); | 257 | free(val); |
258 | } | 258 | } |
@@ -267,8 +267,8 @@ static int parse_amf(const unsigned char **data, | |||
267 | tmp[0] = &millis; | 267 | tmp[0] = &millis; |
268 | tmp[1] = &tz; | 268 | tmp[1] = &tz; |
269 | if (ret == 0) | 269 | if (ret == 0) |
270 | (*(handler->as_end_callback))(astype, | 270 | (*(handler->as_end_callback))(astype, |
271 | &tmp, | 271 | &tmp, |
272 | handler->userdata); | 272 | handler->userdata); |
273 | break; | 273 | break; |
274 | } | 274 | } |
@@ -293,11 +293,11 @@ static int parse_amf(const unsigned char **data, | |||
293 | if (ret == -1) | 293 | if (ret == -1) |
294 | break; | 294 | break; |
295 | } | 295 | } |
296 | (*(handler->as_end_callback))(ASTYPE_ARRAY, | 296 | (*(handler->as_end_callback))(ASTYPE_ARRAY, |
297 | NULL, | 297 | NULL, |
298 | handler->userdata); | 298 | handler->userdata); |
299 | break; | 299 | break; |
300 | } | 300 | } |
301 | case ASTYPE_OBJECT: | 301 | case ASTYPE_OBJECT: |
302 | { | 302 | { |
303 | char *key; | 303 | char *key; |
@@ -306,7 +306,7 @@ static int parse_amf(const unsigned char **data, | |||
306 | ret = readASString(&ptr, len, &key); | 306 | ret = readASString(&ptr, len, &key); |
307 | if (ret == -1) | 307 | if (ret == -1) |
308 | break; | 308 | break; |
309 | (*(handler->as_key_callback))(key, | 309 | (*(handler->as_key_callback))(key, |
310 | handler->userdata); | 310 | handler->userdata); |
311 | free(key); | 311 | free(key); |
312 | type = *ptr; | 312 | type = *ptr; |
@@ -317,17 +317,17 @@ static int parse_amf(const unsigned char **data, | |||
317 | ret = readASString(&ptr, len, &key); | 317 | ret = readASString(&ptr, len, &key); |
318 | if (ret == -1) | 318 | if (ret == -1) |
319 | break; | 319 | break; |
320 | (*(handler->as_key_callback))(key, | 320 | (*(handler->as_key_callback))(key, |
321 | handler->userdata); | 321 | handler->userdata); |
322 | free(key); | 322 | free(key); |
323 | type = *ptr; | 323 | type = *ptr; |
324 | } | 324 | } |
325 | if (ret == 0) | 325 | if (ret == 0) |
326 | (*(handler->as_end_callback))(ASTYPE_OBJECT, | 326 | (*(handler->as_end_callback))(ASTYPE_OBJECT, |
327 | NULL, | 327 | NULL, |
328 | handler->userdata); | 328 | handler->userdata); |
329 | break; | 329 | break; |
330 | } | 330 | } |
331 | case ASTYPE_MIXEDARRAY: | 331 | case ASTYPE_MIXEDARRAY: |
332 | { | 332 | { |
333 | char *key; | 333 | char *key; |
@@ -343,7 +343,7 @@ static int parse_amf(const unsigned char **data, | |||
343 | ret = readASString(&ptr, len, &key); | 343 | ret = readASString(&ptr, len, &key); |
344 | if (ret == -1) | 344 | if (ret == -1) |
345 | break; | 345 | break; |
346 | (*(handler->as_key_callback))(key, | 346 | (*(handler->as_key_callback))(key, |
347 | handler->userdata); | 347 | handler->userdata); |
348 | free(key); | 348 | free(key); |
349 | type = *ptr; | 349 | type = *ptr; |
@@ -354,21 +354,21 @@ static int parse_amf(const unsigned char **data, | |||
354 | ret = readASString(&ptr, len, &key); | 354 | ret = readASString(&ptr, len, &key); |
355 | if (ret == -1) | 355 | if (ret == -1) |
356 | break; | 356 | break; |
357 | (*(handler->as_key_callback))(key, | 357 | (*(handler->as_key_callback))(key, |
358 | handler->userdata); | 358 | handler->userdata); |
359 | free(key); | 359 | free(key); |
360 | type = *ptr; | 360 | type = *ptr; |
361 | } | 361 | } |
362 | if (ret == 0) | 362 | if (ret == 0) |
363 | (*(handler->as_end_callback))(astype, | 363 | (*(handler->as_end_callback))(astype, |
364 | NULL, | 364 | NULL, |
365 | handler->userdata); | 365 | handler->userdata); |
366 | break; | 366 | break; |
367 | } | 367 | } |
368 | default: | 368 | default: |
369 | ret = -1; | 369 | ret = -1; |
370 | (*(handler->as_end_callback))(astype, | 370 | (*(handler->as_end_callback))(astype, |
371 | NULL, | 371 | NULL, |
372 | handler->userdata); | 372 | handler->userdata); |
373 | #if DEBUG | 373 | #if DEBUG |
374 | printf("parse_amf: Unknown type %02x", astype); | 374 | printf("parse_amf: Unknown type %02x", astype); |
@@ -647,11 +647,11 @@ static void handleASBegin(unsigned char type, void * userdata) | |||
647 | { | 647 | { |
648 | FLVMetaParserState *state = (FLVMetaParserState *)userdata; | 648 | FLVMetaParserState *state = (FLVMetaParserState *)userdata; |
649 | 649 | ||
650 | if (state->onMetaData && state->parsingDepth == 0 && | 650 | if (state->onMetaData && state->parsingDepth == 0 && |
651 | type != ASTYPE_MIXEDARRAY) | 651 | type != ASTYPE_MIXEDARRAY) |
652 | state->onMetaData = 0; | 652 | state->onMetaData = 0; |
653 | 653 | ||
654 | if (type == ASTYPE_ARRAY || type == ASTYPE_MIXEDARRAY || | 654 | if (type == ASTYPE_ARRAY || type == ASTYPE_MIXEDARRAY || |
655 | type == ASTYPE_OBJECT) | 655 | type == ASTYPE_OBJECT) |
656 | state->parsingDepth++; | 656 | state->parsingDepth++; |
657 | } | 657 | } |
@@ -665,13 +665,13 @@ static void handleASKey(char * key, void * userdata) | |||
665 | return; | 665 | return; |
666 | 666 | ||
667 | i = 0; | 667 | i = 0; |
668 | while ((key_to_extractor_map[i].key != NULL) && | 668 | while ((key_to_extractor_map[i].key != NULL) && |
669 | (strcasecmp(key, key_to_extractor_map[i].key) != 0)) | 669 | (strcasecmp(key, key_to_extractor_map[i].key) != 0)) |
670 | i++; | 670 | i++; |
671 | state->currentKeyType = key_to_extractor_map[i].type; | 671 | state->currentKeyType = key_to_extractor_map[i].type; |
672 | 672 | ||
673 | i = 0; | 673 | i = 0; |
674 | while ((key_to_attribute_map[i].key != NULL) && | 674 | while ((key_to_attribute_map[i].key != NULL) && |
675 | (strcasecmp(key, key_to_attribute_map[i].key) != 0)) | 675 | (strcasecmp(key, key_to_attribute_map[i].key) != 0)) |
676 | i++; | 676 | i++; |
677 | state->currentAttribute = key_to_attribute_map[i].attribute; | 677 | state->currentAttribute = key_to_attribute_map[i].attribute; |
@@ -681,7 +681,7 @@ static void handleASEnd(unsigned char type, void * value, void * userdata) | |||
681 | { | 681 | { |
682 | FLVMetaParserState *state = (FLVMetaParserState *)userdata; | 682 | FLVMetaParserState *state = (FLVMetaParserState *)userdata; |
683 | char *s; | 683 | char *s; |
684 | 684 | ||
685 | if ((state->parsingDepth == 0) && (type == ASTYPE_STRING)) { | 685 | if ((state->parsingDepth == 0) && (type == ASTYPE_STRING)) { |
686 | s = (char *)value; | 686 | s = (char *)value; |
687 | if (!strcmp(s, "onMetaData")) | 687 | if (!strcmp(s, "onMetaData")) |
@@ -692,8 +692,8 @@ static void handleASEnd(unsigned char type, void * value, void * userdata) | |||
692 | * right after a "onMetaData" STRING */ | 692 | * right after a "onMetaData" STRING */ |
693 | 693 | ||
694 | /* stream info related metadata */ | 694 | /* stream info related metadata */ |
695 | if (state->onMetaData && (state->parsingDepth == 1) && | 695 | if (state->onMetaData && (state->parsingDepth == 1) && |
696 | (state->currentAttribute != FLV_NONE) && | 696 | (state->currentAttribute != FLV_NONE) && |
697 | (type == ASTYPE_NUMBER)) | 697 | (type == ASTYPE_NUMBER)) |
698 | { | 698 | { |
699 | double n = *((double *)value); | 699 | double n = *((double *)value); |
@@ -711,10 +711,10 @@ static void handleASEnd(unsigned char type, void * value, void * userdata) | |||
711 | break; | 711 | break; |
712 | case FLV_FRAMERATE: | 712 | case FLV_FRAMERATE: |
713 | state->streamInfo->videoFrameRate = n; | 713 | state->streamInfo->videoFrameRate = n; |
714 | break; | 714 | break; |
715 | case FLV_VDATARATE: | 715 | case FLV_VDATARATE: |
716 | state->streamInfo->videoDataRate = n; | 716 | state->streamInfo->videoDataRate = n; |
717 | break; | 717 | break; |
718 | case FLV_ADATARATE: | 718 | case FLV_ADATARATE: |
719 | state->streamInfo->audioDataRate = n; | 719 | state->streamInfo->audioDataRate = n; |
720 | break; | 720 | break; |
@@ -729,8 +729,8 @@ static void handleASEnd(unsigned char type, void * value, void * userdata) | |||
729 | } | 729 | } |
730 | } | 730 | } |
731 | 731 | ||
732 | if (state->onMetaData && (state->parsingDepth == 1) && | 732 | if (state->onMetaData && (state->parsingDepth == 1) && |
733 | (state->currentAttribute == FLV_STEREO) && | 733 | (state->currentAttribute == FLV_STEREO) && |
734 | (type == ASTYPE_BOOLEAN)) | 734 | (type == ASTYPE_BOOLEAN)) |
735 | { | 735 | { |
736 | int n = *((int *)value); | 736 | int n = *((int *)value); |
@@ -739,7 +739,7 @@ static void handleASEnd(unsigned char type, void * value, void * userdata) | |||
739 | } | 739 | } |
740 | 740 | ||
741 | /* metadata that maps straight to extractor keys */ | 741 | /* metadata that maps straight to extractor keys */ |
742 | if (state->onMetaData && (state->parsingDepth == 1) && | 742 | if (state->onMetaData && (state->parsingDepth == 1) && |
743 | (state->currentKeyType != EXTRACTOR_UNKNOWN)) | 743 | (state->currentKeyType != EXTRACTOR_UNKNOWN)) |
744 | { | 744 | { |
745 | s = NULL; | 745 | s = NULL; |
@@ -779,22 +779,22 @@ static void handleASEnd(unsigned char type, void * value, void * userdata) | |||
779 | } | 779 | } |
780 | 780 | ||
781 | if (s != NULL) | 781 | if (s != NULL) |
782 | state->keywords = addKeyword (state->currentKeyType, | 782 | state->keywords = addKeyword (state->currentKeyType, |
783 | s, | 783 | s, |
784 | state->keywords); | 784 | state->keywords); |
785 | } | 785 | } |
786 | state->currentKeyType = EXTRACTOR_UNKNOWN; | 786 | state->currentKeyType = EXTRACTOR_UNKNOWN; |
787 | state->currentAttribute = FLV_NONE; | 787 | state->currentAttribute = FLV_NONE; |
788 | 788 | ||
789 | if (type == ASTYPE_ARRAY || type == ASTYPE_MIXEDARRAY || | 789 | if (type == ASTYPE_ARRAY || type == ASTYPE_MIXEDARRAY || |
790 | type == ASTYPE_OBJECT) | 790 | type == ASTYPE_OBJECT) |
791 | state->parsingDepth--; | 791 | state->parsingDepth--; |
792 | } | 792 | } |
793 | 793 | ||
794 | static struct EXTRACTOR_Keywords * | 794 | static struct EXTRACTOR_Keywords * |
795 | handleMetaBody(const unsigned char *data, size_t len, | 795 | handleMetaBody(const unsigned char *data, size_t len, |
796 | FLVStreamInfo *stinfo, | 796 | FLVStreamInfo *stinfo, |
797 | struct EXTRACTOR_Keywords *prev) | 797 | struct EXTRACTOR_Keywords *prev) |
798 | { | 798 | { |
799 | AMFParserHandler handler; | 799 | AMFParserHandler handler; |
800 | FLVMetaParserState pstate; | 800 | FLVMetaParserState pstate; |
@@ -843,9 +843,9 @@ static char *FLVAudioSampleRates[] = { | |||
843 | }; | 843 | }; |
844 | 844 | ||
845 | static struct EXTRACTOR_Keywords * | 845 | static struct EXTRACTOR_Keywords * |
846 | handleAudioBody(const unsigned char *data, size_t len, | 846 | handleAudioBody(const unsigned char *data, size_t len, |
847 | FLVStreamInfo *stinfo, | 847 | FLVStreamInfo *stinfo, |
848 | struct EXTRACTOR_Keywords *prev) | 848 | struct EXTRACTOR_Keywords *prev) |
849 | { | 849 | { |
850 | stinfo->audioChannels = *data & 0x01; | 850 | stinfo->audioChannels = *data & 0x01; |
851 | stinfo->audioSampleBits = (*data & 0x02) >> 1; | 851 | stinfo->audioSampleBits = (*data & 0x02) >> 1; |
@@ -878,9 +878,9 @@ static int sorenson_predefined_res[][2] = { | |||
878 | }; | 878 | }; |
879 | 879 | ||
880 | static struct EXTRACTOR_Keywords * | 880 | static struct EXTRACTOR_Keywords * |
881 | handleVideoBody(const unsigned char *data, size_t len, | 881 | handleVideoBody(const unsigned char *data, size_t len, |
882 | FLVStreamInfo *stinfo, | 882 | FLVStreamInfo *stinfo, |
883 | struct EXTRACTOR_Keywords *prev) | 883 | struct EXTRACTOR_Keywords *prev) |
884 | { | 884 | { |
885 | int codecId, frameType; | 885 | int codecId, frameType; |
886 | 886 | ||
@@ -938,7 +938,7 @@ handleVideoBody(const unsigned char *data, size_t len, | |||
938 | if (separated_coeff || !filter_header) { | 938 | if (separated_coeff || !filter_header) { |
939 | data += 2; | 939 | data += 2; |
940 | } | 940 | } |
941 | /* XXX encoded/displayed dimensions might vary, but which are the | 941 | /* XXX encoded/displayed dimensions might vary, but which are the |
942 | * right ones? */ | 942 | * right ones? */ |
943 | stinfo->videoWidth = (data[3]*16) - (dim_adj>>4); | 943 | stinfo->videoWidth = (data[3]*16) - (dim_adj>>4); |
944 | stinfo->videoHeight = (data[2]*16) - (dim_adj&0x0F); | 944 | stinfo->videoHeight = (data[2]*16) - (dim_adj&0x0F); |
@@ -968,7 +968,7 @@ static int readFLVTag(const unsigned char **data, | |||
968 | if ((ptr + header.bodyLength) > end) | 968 | if ((ptr + header.bodyLength) > end) |
969 | return -1; | 969 | return -1; |
970 | 970 | ||
971 | switch (header.type) | 971 | switch (header.type) |
972 | { | 972 | { |
973 | case FLV_TAG_TYPE_AUDIO: | 973 | case FLV_TAG_TYPE_AUDIO: |
974 | head = handleAudioBody(ptr, header.bodyLength, stinfo, head); | 974 | head = handleAudioBody(ptr, header.bodyLength, stinfo, head); |
@@ -984,7 +984,7 @@ static int readFLVTag(const unsigned char **data, | |||
984 | } | 984 | } |
985 | 985 | ||
986 | ptr += header.bodyLength; | 986 | ptr += header.bodyLength; |
987 | 987 | ||
988 | *list = head; | 988 | *list = head; |
989 | *data = ptr; | 989 | *data = ptr; |
990 | return 0; | 990 | return 0; |
@@ -1038,7 +1038,7 @@ static char * printVideoFormat(FLVStreamInfo *stinfo) | |||
1038 | n += snprintf(s+n, len-n, "%.4f kbps", stinfo->videoDataRate); | 1038 | n += snprintf(s+n, len-n, "%.4f kbps", stinfo->videoDataRate); |
1039 | } | 1039 | } |
1040 | 1040 | ||
1041 | if (n == 0) | 1041 | if (n == 0) |
1042 | return NULL; | 1042 | return NULL; |
1043 | return strdup(s); | 1043 | return strdup(s); |
1044 | } | 1044 | } |
@@ -1058,7 +1058,7 @@ static char * printAudioFormat(FLVStreamInfo *stinfo) | |||
1058 | if (n > 0) | 1058 | if (n > 0) |
1059 | n += snprintf(s+n, len-n, ", "); | 1059 | n += snprintf(s+n, len-n, ", "); |
1060 | if (n < len) | 1060 | if (n < len) |
1061 | n += snprintf(s+n, len-n, "%s", | 1061 | n += snprintf(s+n, len-n, "%s", |
1062 | FLVAudioSampleSizes[stinfo->audioSampleBits]); | 1062 | FLVAudioSampleSizes[stinfo->audioSampleBits]); |
1063 | } | 1063 | } |
1064 | 1064 | ||
@@ -1066,7 +1066,7 @@ static char * printAudioFormat(FLVStreamInfo *stinfo) | |||
1066 | if (n > 0) | 1066 | if (n > 0) |
1067 | n += snprintf(s+n, len-n, ", "); | 1067 | n += snprintf(s+n, len-n, ", "); |
1068 | if (n < len) | 1068 | if (n < len) |
1069 | n += snprintf(s+n, len-n, "%s", | 1069 | n += snprintf(s+n, len-n, "%s", |
1070 | FLVAudioChannels[stinfo->audioChannels]); | 1070 | FLVAudioChannels[stinfo->audioChannels]); |
1071 | } | 1071 | } |
1072 | 1072 | ||
@@ -1085,7 +1085,7 @@ static char * printAudioFormat(FLVStreamInfo *stinfo) | |||
1085 | n += snprintf(s+n, len-n, "%.4f kbps", stinfo->audioDataRate); | 1085 | n += snprintf(s+n, len-n, "%.4f kbps", stinfo->audioDataRate); |
1086 | } | 1086 | } |
1087 | 1087 | ||
1088 | if (n == 0) | 1088 | if (n == 0) |
1089 | return NULL; | 1089 | return NULL; |
1090 | return strdup(s); | 1090 | return strdup(s); |
1091 | } | 1091 | } |
diff --git a/src/plugins/gifextractor.c b/src/plugins/gifextractor.c index def9fed..27d9c21 100644 --- a/src/plugins/gifextractor.c +++ b/src/plugins/gifextractor.c | |||
@@ -201,7 +201,7 @@ libextractor_gif_extract (const char *filename, | |||
201 | 201 | ||
202 | if (size < GIF_HEADER_SIZE) | 202 | if (size < GIF_HEADER_SIZE) |
203 | return prev; | 203 | return prev; |
204 | cat_unpack (data, GIF_HEADER_SPEC, GIF_HEADER_FIELDS (&header)); | 204 | EXTRACTOR_common_cat_unpack (data, GIF_HEADER_SPEC, GIF_HEADER_FIELDS (&header)); |
205 | if (0 != strncmp (&header.gif[0], "GIF", 3)) | 205 | if (0 != strncmp (&header.gif[0], "GIF", 3)) |
206 | return prev; | 206 | return prev; |
207 | if (0 != strncmp (&header.version[0], "89a", 3)) | 207 | if (0 != strncmp (&header.version[0], "89a", 3)) |
@@ -222,7 +222,7 @@ libextractor_gif_extract (const char *filename, | |||
222 | { | 222 | { |
223 | case ',': /* image descriptor block */ | 223 | case ',': /* image descriptor block */ |
224 | PRINT ("skipping local color map %d\n", pos); | 224 | PRINT ("skipping local color map %d\n", pos); |
225 | cat_unpack (&data[pos], | 225 | EXTRACTOR_common_cat_unpack (&data[pos], |
226 | GIF_DESCRIPTOR_SPEC, GIF_DESCRIPTOR_FIELDS (&gd)); | 226 | GIF_DESCRIPTOR_SPEC, GIF_DESCRIPTOR_FIELDS (&gd)); |
227 | pos = skipLocalColorMap (data, pos, size, &gd); | 227 | pos = skipLocalColorMap (data, pos, size, &gd); |
228 | break; | 228 | break; |
diff --git a/src/plugins/htmlextractor.c b/src/plugins/htmlextractor.c index 397ac47..1dafb31 100644 --- a/src/plugins/htmlextractor.c +++ b/src/plugins/htmlextractor.c | |||
@@ -421,7 +421,7 @@ libextractor_html_extract (const char *filename, | |||
421 | if (tmp != NULL) | 421 | if (tmp != NULL) |
422 | { | 422 | { |
423 | prev = addKeyword (tagmap[i].type, | 423 | prev = addKeyword (tagmap[i].type, |
424 | convertToUtf8 (tmp, | 424 | EXTRACTOR_common_convert_to_utf8 (tmp, |
425 | strlen (tmp), charset), prev); | 425 | strlen (tmp), charset), prev); |
426 | free (tmp); | 426 | free (tmp); |
427 | } | 427 | } |
@@ -434,7 +434,7 @@ libextractor_html_extract (const char *filename, | |||
434 | t = tags; | 434 | t = tags; |
435 | if (tagMatch ("title", t->tagStart, t->tagEnd)) | 435 | if (tagMatch ("title", t->tagStart, t->tagEnd)) |
436 | prev = addKeyword (EXTRACTOR_TITLE, | 436 | prev = addKeyword (EXTRACTOR_TITLE, |
437 | convertToUtf8 (t->dataStart, | 437 | EXTRACTOR_common_convert_to_utf8 (t->dataStart, |
438 | t->dataEnd - t->dataStart, | 438 | t->dataEnd - t->dataStart, |
439 | charset), prev); | 439 | charset), prev); |
440 | tags = t->next; | 440 | tags = t->next; |
diff --git a/src/plugins/id3v23extractor.c b/src/plugins/id3v23extractor.c index e02b71d..4f066fe 100644 --- a/src/plugins/id3v23extractor.c +++ b/src/plugins/id3v23extractor.c | |||
@@ -184,17 +184,17 @@ libextractor_id3v23_extract (const char *filename, | |||
184 | switch (data[pos + 10]) | 184 | switch (data[pos + 10]) |
185 | { | 185 | { |
186 | case 0x00: | 186 | case 0x00: |
187 | word = convertToUtf8 ((const char *) &data[pos + 11], | 187 | word = EXTRACTOR_common_convert_to_utf8 ((const char *) &data[pos + 11], |
188 | csize, "ISO-8859-1"); | 188 | csize, "ISO-8859-1"); |
189 | break; | 189 | break; |
190 | case 0x01: | 190 | case 0x01: |
191 | word = convertToUtf8 ((const char *) &data[pos + 11], | 191 | word = EXTRACTOR_common_convert_to_utf8 ((const char *) &data[pos + 11], |
192 | csize, "UCS-2"); | 192 | csize, "UCS-2"); |
193 | break; | 193 | break; |
194 | default: | 194 | default: |
195 | /* bad encoding byte, | 195 | /* bad encoding byte, |
196 | try to convert from iso-8859-1 */ | 196 | try to convert from iso-8859-1 */ |
197 | word = convertToUtf8 ((const char *) &data[pos + 11], | 197 | word = EXTRACTOR_common_convert_to_utf8 ((const char *) &data[pos + 11], |
198 | csize, "ISO-8859-1"); | 198 | csize, "ISO-8859-1"); |
199 | break; | 199 | break; |
200 | } | 200 | } |
diff --git a/src/plugins/id3v24extractor.c b/src/plugins/id3v24extractor.c index aa35925..aec3031 100644 --- a/src/plugins/id3v24extractor.c +++ b/src/plugins/id3v24extractor.c | |||
@@ -184,15 +184,15 @@ libextractor_id3v24_extract (const char *filename, | |||
184 | switch (data[pos + 10]) | 184 | switch (data[pos + 10]) |
185 | { | 185 | { |
186 | case 0x00: | 186 | case 0x00: |
187 | word = convertToUtf8 ((const char *) &data[pos + 11], | 187 | word = EXTRACTOR_common_convert_to_utf8 ((const char *) &data[pos + 11], |
188 | csize, "ISO-8859-1"); | 188 | csize, "ISO-8859-1"); |
189 | break; | 189 | break; |
190 | case 0x01: | 190 | case 0x01: |
191 | word = convertToUtf8 ((const char *) &data[pos + 11], | 191 | word = EXTRACTOR_common_convert_to_utf8 ((const char *) &data[pos + 11], |
192 | csize, "UTF-16"); | 192 | csize, "UTF-16"); |
193 | break; | 193 | break; |
194 | case 0x02: | 194 | case 0x02: |
195 | word = convertToUtf8 ((const char *) &data[pos + 11], | 195 | word = EXTRACTOR_common_convert_to_utf8 ((const char *) &data[pos + 11], |
196 | csize, "UTF-16BE"); | 196 | csize, "UTF-16BE"); |
197 | break; | 197 | break; |
198 | case 0x03: | 198 | case 0x03: |
@@ -203,7 +203,7 @@ libextractor_id3v24_extract (const char *filename, | |||
203 | default: | 203 | default: |
204 | /* bad encoding byte, | 204 | /* bad encoding byte, |
205 | try to convert from iso-8859-1 */ | 205 | try to convert from iso-8859-1 */ |
206 | word = convertToUtf8 ((const char *) &data[pos + 11], | 206 | word = EXTRACTOR_common_convert_to_utf8 ((const char *) &data[pos + 11], |
207 | csize, "ISO-8859-1"); | 207 | csize, "ISO-8859-1"); |
208 | break; | 208 | break; |
209 | } | 209 | } |
diff --git a/src/plugins/id3v2extractor.c b/src/plugins/id3v2extractor.c index 562ca2d..00e353c 100644 --- a/src/plugins/id3v2extractor.c +++ b/src/plugins/id3v2extractor.c | |||
@@ -131,17 +131,17 @@ libextractor_id3v2_extract (const char *filename, | |||
131 | switch (data[pos + 6]) | 131 | switch (data[pos + 6]) |
132 | { | 132 | { |
133 | case 0x00: | 133 | case 0x00: |
134 | word = convertToUtf8 ((const char *) &data[pos + 7], | 134 | word = EXTRACTOR_common_convert_to_utf8 ((const char *) &data[pos + 7], |
135 | csize, "ISO-8859-1"); | 135 | csize, "ISO-8859-1"); |
136 | break; | 136 | break; |
137 | case 0x01: | 137 | case 0x01: |
138 | word = convertToUtf8 ((const char *) &data[pos + 7], | 138 | word = EXTRACTOR_common_convert_to_utf8 ((const char *) &data[pos + 7], |
139 | csize, "UCS-2"); | 139 | csize, "UCS-2"); |
140 | break; | 140 | break; |
141 | default: | 141 | default: |
142 | /* bad encoding byte, | 142 | /* bad encoding byte, |
143 | try to convert from iso-8859-1 */ | 143 | try to convert from iso-8859-1 */ |
144 | word = convertToUtf8 ((const char *) &data[pos + 7], | 144 | word = EXTRACTOR_common_convert_to_utf8 ((const char *) &data[pos + 7], |
145 | csize, "ISO-8859-1"); | 145 | csize, "ISO-8859-1"); |
146 | break; | 146 | break; |
147 | } | 147 | } |
diff --git a/src/plugins/mp3extractor.c b/src/plugins/mp3extractor.c index 201a332..b0b2d0c 100644 --- a/src/plugins/mp3extractor.c +++ b/src/plugins/mp3extractor.c | |||
@@ -290,19 +290,19 @@ get_id3 (const char *data, size_t size, id3tag * id3) | |||
290 | return INVALID_ID3; | 290 | return INVALID_ID3; |
291 | pos += 3; | 291 | pos += 3; |
292 | 292 | ||
293 | id3->title = convertToUtf8 (pos, 30, "ISO-8859-1"); | 293 | id3->title = EXTRACTOR_common_convert_to_utf8 (pos, 30, "ISO-8859-1"); |
294 | trim (id3->title); | 294 | trim (id3->title); |
295 | pos += 30; | 295 | pos += 30; |
296 | id3->artist = convertToUtf8 (pos, 30, "ISO-8859-1"); | 296 | id3->artist = EXTRACTOR_common_convert_to_utf8 (pos, 30, "ISO-8859-1"); |
297 | trim (id3->artist); | 297 | trim (id3->artist); |
298 | pos += 30; | 298 | pos += 30; |
299 | id3->album = convertToUtf8 (pos, 30, "ISO-8859-1"); | 299 | id3->album = EXTRACTOR_common_convert_to_utf8 (pos, 30, "ISO-8859-1"); |
300 | trim (id3->album); | 300 | trim (id3->album); |
301 | pos += 30; | 301 | pos += 30; |
302 | id3->year = convertToUtf8 (pos, 4, "ISO-8859-1"); | 302 | id3->year = EXTRACTOR_common_convert_to_utf8 (pos, 4, "ISO-8859-1"); |
303 | trim (id3->year); | 303 | trim (id3->year); |
304 | pos += 4; | 304 | pos += 4; |
305 | id3->comment = convertToUtf8 (pos, 30, "ISO-8859-1"); | 305 | id3->comment = EXTRACTOR_common_convert_to_utf8 (pos, 30, "ISO-8859-1"); |
306 | trim (id3->comment); | 306 | trim (id3->comment); |
307 | if ( (pos[28] == '\0') && | 307 | if ( (pos[28] == '\0') && |
308 | (pos[29] != '\0') ) | 308 | (pos[29] != '\0') ) |
@@ -419,14 +419,14 @@ mp3parse (const unsigned char *data, size_t size, struct EXTRACTOR_Keywords *pre | |||
419 | idx_num = (mpeg_ver - 1) * 3 + layer - 1; | 419 | idx_num = (mpeg_ver - 1) * 3 + layer - 1; |
420 | else | 420 | else |
421 | idx_num = 2 + layer; | 421 | idx_num = 2 + layer; |
422 | bitrate = 1000 * bitrate_table[(header >> MPA_BITRATE_SHIFT) & | 422 | bitrate = 1000 * bitrate_table[(header >> MPA_BITRATE_SHIFT) & |
423 | MPA_BITRATE_MASK][idx_num]; | 423 | MPA_BITRATE_MASK][idx_num]; |
424 | if (bitrate < 0) | 424 | if (bitrate < 0) |
425 | { | 425 | { |
426 | frames--; | 426 | frames--; |
427 | break; | 427 | break; |
428 | } /*error in header */ | 428 | } /*error in header */ |
429 | sample_rate = freq_table[(header >> MPA_FREQ_SHIFT) & | 429 | sample_rate = freq_table[(header >> MPA_FREQ_SHIFT) & |
430 | MPA_FREQ_MASK][mpeg_ver - 1]; | 430 | MPA_FREQ_MASK][mpeg_ver - 1]; |
431 | if (sample_rate < 0) | 431 | if (sample_rate < 0) |
432 | { | 432 | { |
@@ -468,17 +468,17 @@ mp3parse (const unsigned char *data, size_t size, struct EXTRACTOR_Keywords *pre | |||
468 | 468 | ||
469 | prev = addkword (prev, mpeg_versions[mpeg_ver-1], EXTRACTOR_RESOURCE_TYPE); | 469 | prev = addkword (prev, mpeg_versions[mpeg_ver-1], EXTRACTOR_RESOURCE_TYPE); |
470 | format = malloc (512); | 470 | format = malloc (512); |
471 | snprintf (format, 512, "%s %s audio, %d kbps (%s), %d Hz, %s, %s, %s", | 471 | snprintf (format, 512, "%s %s audio, %d kbps (%s), %d Hz, %s, %s, %s", |
472 | mpeg_versions[mpeg_ver-1], | 472 | mpeg_versions[mpeg_ver-1], |
473 | layer_names[layer-1], | 473 | layer_names[layer-1], |
474 | avg_bps, | 474 | avg_bps, |
475 | vbr_flag ? _("VBR") : _("CBR"), | 475 | vbr_flag ? _("VBR") : _("CBR"), |
476 | sample_rate, | 476 | sample_rate, |
477 | channel_modes[ch], | 477 | channel_modes[ch], |
478 | copyright_flag ? _("copyright") : _("no copyright"), | 478 | copyright_flag ? _("copyright") : _("no copyright"), |
479 | original_flag ? _("original") : _("copy") ); | 479 | original_flag ? _("original") : _("copy") ); |
480 | prev = addkword (prev, format, EXTRACTOR_FORMAT); | 480 | prev = addkword (prev, format, EXTRACTOR_FORMAT); |
481 | snprintf (format, 512, "%dm%02d", | 481 | snprintf (format, 512, "%dm%02d", |
482 | length / 60, length % 60); | 482 | length / 60, length % 60); |
483 | prev = addkword (prev, format, EXTRACTOR_DURATION); | 483 | prev = addkword (prev, format, EXTRACTOR_DURATION); |
484 | free (format); | 484 | free (format); |
@@ -522,7 +522,7 @@ libextractor_mp3_extract (const char *filename, | |||
522 | strlen (info.album) + 6); | 522 | strlen (info.album) + 6); |
523 | sprintf (word, "%s: %s (%s)", info.artist, info.title, info.album); | 523 | sprintf (word, "%s: %s (%s)", info.artist, info.title, info.album); |
524 | klist = addkword (klist, word, EXTRACTOR_DESCRIPTION); | 524 | klist = addkword (klist, word, EXTRACTOR_DESCRIPTION); |
525 | 525 | ||
526 | free (word); | 526 | free (word); |
527 | free (info.title); | 527 | free (info.title); |
528 | free (info.year); | 528 | free (info.year); |
diff --git a/src/plugins/ole2/ole2extractor.c b/src/plugins/ole2/ole2extractor.c index 6933986..b3ba87b 100644 --- a/src/plugins/ole2/ole2extractor.c +++ b/src/plugins/ole2/ole2extractor.c | |||
@@ -27,7 +27,7 @@ | |||
27 | 27 | ||
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "extractor.h" | 29 | #include "extractor.h" |
30 | #include "../convert.h" | 30 | #include "convert.h" |
31 | 31 | ||
32 | #include <glib-object.h> | 32 | #include <glib-object.h> |
33 | #include <string.h> | 33 | #include <string.h> |
@@ -394,14 +394,14 @@ history_extract(GsfInput * stream, | |||
394 | // there are n strings, so n/2 revisions (author & file) | 394 | // there are n strings, so n/2 revisions (author & file) |
395 | nRev = (lbuffer[2] + (lbuffer[3] << 8)) / 2; | 395 | nRev = (lbuffer[2] + (lbuffer[3] << 8)) / 2; |
396 | where = 6; | 396 | where = 6; |
397 | for (i=0; i < nRev; i++) { | 397 | for (i=0; i < nRev; i++) { |
398 | if (where >= lcbSttbSavedBy) | 398 | if (where >= lcbSttbSavedBy) |
399 | break; | 399 | break; |
400 | length = lbuffer[where++]; | 400 | length = lbuffer[where++]; |
401 | if ( (where + 2 * length + 2 >= lcbSttbSavedBy) || | 401 | if ( (where + 2 * length + 2 >= lcbSttbSavedBy) || |
402 | (where + 2 * length + 2 <= where) ) | 402 | (where + 2 * length + 2 <= where) ) |
403 | break; | 403 | break; |
404 | author = convertToUtf8((const char*) &lbuffer[where], | 404 | author = EXTRACTOR_common_convert_to_utf8((const char*) &lbuffer[where], |
405 | length * 2, | 405 | length * 2, |
406 | "UTF-16BE"); | 406 | "UTF-16BE"); |
407 | where += length * 2 + 1; | 407 | where += length * 2 + 1; |
@@ -411,9 +411,9 @@ history_extract(GsfInput * stream, | |||
411 | free(author); | 411 | free(author); |
412 | break; | 412 | break; |
413 | } | 413 | } |
414 | filename = convertToUtf8((const char*) &lbuffer[where], | 414 | filename = EXTRACTOR_common_convert_to_utf8((const char*) &lbuffer[where], |
415 | length * 2, | 415 | length * 2, |
416 | "UTF-16BE"); | 416 | "UTF-16BE"); |
417 | where += length * 2 + 1; | 417 | where += length * 2 + 1; |
418 | rbuf = malloc(strlen(author) + strlen(filename) + 512); | 418 | rbuf = malloc(strlen(author) + strlen(filename) + 512); |
419 | snprintf(rbuf, 512 + strlen(author) + strlen(filename), | 419 | snprintf(rbuf, 512 + strlen(author) + strlen(filename), |
diff --git a/src/plugins/pack.c b/src/plugins/pack.c deleted file mode 100644 index 8b3c3f5..0000000 --- a/src/plugins/pack.c +++ /dev/null | |||
@@ -1,516 +0,0 @@ | |||
1 | /* | ||
2 | Catlib Copyright Notice | ||
3 | |||
4 | The author of this software is Christopher Adam Telfer | ||
5 | Copyright (c) 1998, 1999, 2000, 2001, 2002 | ||
6 | by Christopher Adam Telfer. All Rights Reserved. | ||
7 | |||
8 | Permission to use, copy, modify, and distribute this software for any | ||
9 | purpose without fee is hereby granted, provided that the above copyright | ||
10 | notice, this paragraph, and the following two paragraphs appear in all | ||
11 | copies, modifications, and distributions. | ||
12 | |||
13 | IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | ||
14 | SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | ||
15 | ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | ||
16 | THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
17 | |||
18 | THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT | ||
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
20 | PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF | ||
21 | ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". THE AUTHOR HAS NO | ||
22 | OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR | ||
23 | MODIFICATIONS. | ||
24 | |||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "pack.h" | ||
29 | |||
30 | typedef unsigned char byte; | ||
31 | typedef unsigned short half; | ||
32 | typedef unsigned int word; | ||
33 | typedef signed char sbyte; | ||
34 | typedef signed short shalf; | ||
35 | typedef signed int sword; | ||
36 | |||
37 | |||
38 | /* | ||
39 | "bhwAcslPBHWCSL" | ||
40 | |||
41 | Small letters: do not convert (not implemented for arrays and P) | ||
42 | Captial letters: convert from network byte order to host byte order | ||
43 | |||
44 | b - byte | ||
45 | h - half-word | ||
46 | w - word | ||
47 | a - array (32-byte unsigned long + that many bytes) | ||
48 | c - signed 8 bit value | ||
49 | s - signed 16 bit value | ||
50 | l - signed 32 bit value | ||
51 | p - (unpack only) value is a pointer to a pointer. Generate the buffer | ||
52 | to hold the data. | ||
53 | |||
54 | prefixing with a number K means that the argument will be an array of K | ||
55 | of the arguments specified by the letter | ||
56 | */ | ||
57 | |||
58 | int | ||
59 | cat_pack (void *buf, const char *fmt, ...) | ||
60 | { | ||
61 | va_list ap; | ||
62 | word blen, val; | ||
63 | int npacked; | ||
64 | unsigned int nreps, i; | ||
65 | byte *bp, *bytep; | ||
66 | half *halfp; | ||
67 | word *wordp; | ||
68 | void *arr; | ||
69 | struct cat_bvec *cbvp; | ||
70 | char *cp; | ||
71 | |||
72 | va_start (ap, fmt); | ||
73 | |||
74 | npacked = 0; | ||
75 | bp = (byte *) buf; | ||
76 | |||
77 | while (*fmt) | ||
78 | { | ||
79 | nreps = 0; | ||
80 | |||
81 | if (isdigit (*fmt)) | ||
82 | { | ||
83 | /* We use cp instead of fmt to keep the 'const' qualifier of fmt */ | ||
84 | nreps = strtoul (fmt, &cp, 0); | ||
85 | fmt = cp; | ||
86 | } | ||
87 | |||
88 | switch (*fmt) | ||
89 | { | ||
90 | case 'B': | ||
91 | case 'b': | ||
92 | case 'C': | ||
93 | case 'c': | ||
94 | if (!nreps) | ||
95 | { | ||
96 | *bp++ = va_arg (ap, int); | ||
97 | npacked += 1; | ||
98 | } | ||
99 | else | ||
100 | { | ||
101 | bytep = va_arg (ap, byte *); | ||
102 | for (i = 0; i < nreps; ++i) | ||
103 | { | ||
104 | *bp++ = bytep[i]; | ||
105 | npacked += 1; | ||
106 | } | ||
107 | } | ||
108 | break; | ||
109 | |||
110 | case 'h': | ||
111 | case 's': | ||
112 | if (!nreps) | ||
113 | { | ||
114 | val = va_arg (ap, int); | ||
115 | *bp++ = val & 0xFF; | ||
116 | *bp++ = val >> 8; | ||
117 | npacked += 2; | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | halfp = va_arg (ap, half *); | ||
122 | for (i = 0; i < nreps; ++i) | ||
123 | { | ||
124 | val = halfp[i]; | ||
125 | *bp++ = val & 0xFF; | ||
126 | *bp++ = val >> 8; | ||
127 | npacked += 2; | ||
128 | } | ||
129 | } | ||
130 | break; | ||
131 | |||
132 | case 'H': | ||
133 | case 'S': | ||
134 | if (!nreps) | ||
135 | { | ||
136 | val = va_arg (ap, int); | ||
137 | *bp++ = val >> 8; | ||
138 | *bp++ = val & 0xFF; | ||
139 | npacked += 2; | ||
140 | } | ||
141 | else | ||
142 | { | ||
143 | halfp = va_arg (ap, half *); | ||
144 | for (i = 0; i < nreps; ++i) | ||
145 | { | ||
146 | val = halfp[i]; | ||
147 | *bp++ = val >> 8; | ||
148 | *bp++ = val & 0xFF; | ||
149 | npacked += 2; | ||
150 | } | ||
151 | } | ||
152 | break; | ||
153 | |||
154 | case 'l': | ||
155 | case 'w': | ||
156 | if (!nreps) | ||
157 | { | ||
158 | val = va_arg (ap, word); | ||
159 | *bp++ = val & 0xFF; | ||
160 | *bp++ = val >> 8; | ||
161 | *bp++ = val >> 16; | ||
162 | *bp++ = val >> 24; | ||
163 | npacked += 4; | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | wordp = va_arg (ap, word *); | ||
168 | for (i = 0; i < nreps; ++i) | ||
169 | { | ||
170 | val = wordp[i]; | ||
171 | *bp++ = val & 0xFF; | ||
172 | *bp++ = val >> 8; | ||
173 | *bp++ = val >> 16; | ||
174 | *bp++ = val >> 24; | ||
175 | npacked += 4; | ||
176 | } | ||
177 | } | ||
178 | break; | ||
179 | |||
180 | case 'L': | ||
181 | case 'W': | ||
182 | if (!nreps) | ||
183 | { | ||
184 | val = va_arg (ap, word); | ||
185 | *bp++ = val >> 24; | ||
186 | *bp++ = val >> 16; | ||
187 | *bp++ = val >> 8; | ||
188 | *bp++ = val & 0xFF; | ||
189 | npacked += 4; | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | wordp = va_arg (ap, word *); | ||
194 | for (i = 0; i < nreps; ++i) | ||
195 | { | ||
196 | val = wordp[i]; | ||
197 | *bp++ = val >> 24; | ||
198 | *bp++ = val >> 16; | ||
199 | *bp++ = val >> 8; | ||
200 | *bp++ = val & 0xFF; | ||
201 | npacked += 4; | ||
202 | } | ||
203 | } | ||
204 | break; | ||
205 | |||
206 | case 'A': | ||
207 | if (!nreps) | ||
208 | { | ||
209 | blen = va_arg (ap, word); | ||
210 | arr = va_arg (ap, void *); | ||
211 | *bp++ = blen >> 24; | ||
212 | *bp++ = blen >> 16; | ||
213 | *bp++ = blen >> 8; | ||
214 | *bp++ = blen & 0xFF; | ||
215 | memmove (bp, arr, blen); | ||
216 | bp += blen; | ||
217 | npacked += blen + 4; /* +4 for the 32 bits of length field */ | ||
218 | } | ||
219 | else | ||
220 | { | ||
221 | cbvp = va_arg (ap, struct cat_bvec *); | ||
222 | for (i = 0; i < nreps; ++i) | ||
223 | { | ||
224 | blen = cbvp[i].len; | ||
225 | arr = cbvp[i].data; | ||
226 | *bp++ = blen >> 24; | ||
227 | *bp++ = blen >> 16; | ||
228 | *bp++ = blen >> 8; | ||
229 | *bp++ = blen & 0xFF; | ||
230 | memmove (bp, arr, blen); | ||
231 | bp += blen; | ||
232 | npacked += blen + 4; /* see above */ | ||
233 | } | ||
234 | } | ||
235 | break; | ||
236 | |||
237 | default: | ||
238 | va_end (ap); | ||
239 | return -1; | ||
240 | } | ||
241 | ++fmt; | ||
242 | } | ||
243 | |||
244 | va_end (ap); | ||
245 | return npacked; | ||
246 | } | ||
247 | |||
248 | |||
249 | |||
250 | int | ||
251 | cat_unpack (const void *buf, const char *fmt, ...) | ||
252 | { | ||
253 | va_list ap; | ||
254 | word maxlen, len, *wordp; | ||
255 | void *arr; | ||
256 | byte *bp, *bytep, *newbuf; | ||
257 | half *halfp; | ||
258 | sbyte *sbytep; | ||
259 | shalf *shalfp; | ||
260 | sword *swordp; | ||
261 | int npacked; | ||
262 | unsigned int nreps, i, isnonprefixed = 1; /* used for 'a' types only */ | ||
263 | struct cat_bvec *cbvp; | ||
264 | char *cp; | ||
265 | |||
266 | bp = (byte *) buf; | ||
267 | npacked = 0; | ||
268 | |||
269 | va_start (ap, fmt); | ||
270 | |||
271 | while (*fmt) | ||
272 | { | ||
273 | nreps = 1; | ||
274 | |||
275 | if (isdigit (*fmt)) | ||
276 | { | ||
277 | /* We use cp instead of format to keep the 'const' qualifier of fmt */ | ||
278 | nreps = strtoul (fmt, &cp, 0); | ||
279 | fmt = cp; | ||
280 | if (*fmt == 'a') | ||
281 | isnonprefixed = 0; | ||
282 | } | ||
283 | |||
284 | switch (*fmt) | ||
285 | { | ||
286 | case 'B': | ||
287 | case 'b': | ||
288 | bytep = va_arg (ap, byte *); | ||
289 | for (i = 0; i < nreps; ++i) | ||
290 | { | ||
291 | *bytep = *bp++; | ||
292 | ++bytep; | ||
293 | npacked += 1; | ||
294 | } | ||
295 | break; | ||
296 | |||
297 | |||
298 | |||
299 | case 'h': | ||
300 | halfp = va_arg (ap, half *); | ||
301 | for (i = 0; i < nreps; ++i) | ||
302 | { | ||
303 | *halfp = *bp++; | ||
304 | *halfp |= *bp++ << 8; | ||
305 | ++halfp; | ||
306 | npacked += 2; | ||
307 | } | ||
308 | break; | ||
309 | |||
310 | case 'H': | ||
311 | halfp = va_arg (ap, half *); | ||
312 | for (i = 0; i < nreps; ++i) | ||
313 | { | ||
314 | *halfp = *bp++ << 8; | ||
315 | *halfp |= *bp++; | ||
316 | ++halfp; | ||
317 | npacked += 2; | ||
318 | } | ||
319 | break; | ||
320 | |||
321 | |||
322 | case 'w': | ||
323 | wordp = va_arg (ap, word *); | ||
324 | for (i = 0; i < nreps; ++i) | ||
325 | { | ||
326 | *wordp = *bp++; | ||
327 | *wordp |= *bp++ << 8; | ||
328 | *wordp |= *bp++ << 16; | ||
329 | *wordp |= *bp++ << 24; | ||
330 | ++wordp; | ||
331 | npacked += 4; | ||
332 | } | ||
333 | break; | ||
334 | |||
335 | case 'W': | ||
336 | wordp = va_arg (ap, word *); | ||
337 | for (i = 0; i < nreps; ++i) | ||
338 | { | ||
339 | *wordp = *bp++ << 24; | ||
340 | *wordp |= *bp++ << 16; | ||
341 | *wordp |= *bp++ << 8; | ||
342 | *wordp |= *bp++; | ||
343 | ++wordp; | ||
344 | npacked += 4; | ||
345 | } | ||
346 | break; | ||
347 | |||
348 | case 'A': | ||
349 | if (isnonprefixed) | ||
350 | { | ||
351 | maxlen = va_arg (ap, word); | ||
352 | arr = va_arg (ap, void *); | ||
353 | |||
354 | len = *bp++ << 24; | ||
355 | len |= *bp++ << 16; | ||
356 | len |= *bp++ << 8; | ||
357 | len |= *bp++; | ||
358 | |||
359 | if (len > maxlen) | ||
360 | { | ||
361 | va_end (ap); | ||
362 | return -1; | ||
363 | } | ||
364 | |||
365 | memmove (arr, bp, len); | ||
366 | bp += len; | ||
367 | |||
368 | npacked += len; | ||
369 | } | ||
370 | else | ||
371 | { | ||
372 | cbvp = va_arg (ap, struct cat_bvec *); | ||
373 | for (i = 0; i < nreps; ++i) | ||
374 | { | ||
375 | maxlen = cbvp->len; | ||
376 | arr = cbvp->data; | ||
377 | |||
378 | len = *bp++ << 24; | ||
379 | len |= *bp++ << 16; | ||
380 | len |= *bp++ << 8; | ||
381 | len |= *bp++; | ||
382 | |||
383 | if (len > maxlen) | ||
384 | return -1; | ||
385 | |||
386 | memmove (arr, bp, len); | ||
387 | cbvp->len = len; | ||
388 | bp += len; | ||
389 | |||
390 | ++cbvp; | ||
391 | npacked += len; | ||
392 | } | ||
393 | isnonprefixed = 1; | ||
394 | } | ||
395 | break; | ||
396 | |||
397 | case 'C': | ||
398 | case 'c': | ||
399 | sbytep = va_arg (ap, sbyte *); | ||
400 | for (i = 0; i < nreps; ++i) | ||
401 | { | ||
402 | *sbytep = *bp++; | ||
403 | |||
404 | if ((sizeof (sbyte) > 1) && (*sbytep & 0x80)) | ||
405 | *sbytep |= (~0) << ((sizeof (sbyte) - 1) * 8); | ||
406 | |||
407 | ++sbytep; | ||
408 | npacked += 1; | ||
409 | } | ||
410 | break; | ||
411 | |||
412 | |||
413 | case 's': | ||
414 | shalfp = va_arg (ap, shalf *); | ||
415 | for (i = 0; i < nreps; ++i) | ||
416 | { | ||
417 | *shalfp = *bp++; | ||
418 | *shalfp |= *bp++ << 8; | ||
419 | |||
420 | if ((sizeof (shalf) > 2) && (*shalfp & 0x8000)) | ||
421 | *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8); | ||
422 | |||
423 | ++shalfp; | ||
424 | npacked += 2; | ||
425 | } | ||
426 | break; | ||
427 | |||
428 | case 'S': | ||
429 | shalfp = va_arg (ap, shalf *); | ||
430 | for (i = 0; i < nreps; ++i) | ||
431 | { | ||
432 | *shalfp = *bp++ << 8; | ||
433 | *shalfp |= *bp++; | ||
434 | |||
435 | if ((sizeof (shalf) > 2) && (*shalfp & 0x8000)) | ||
436 | *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8); | ||
437 | |||
438 | ++shalfp; | ||
439 | npacked += 2; | ||
440 | } | ||
441 | break; | ||
442 | |||
443 | case 'l': | ||
444 | swordp = va_arg (ap, sword *); | ||
445 | for (i = 0; i < nreps; ++i) | ||
446 | { | ||
447 | *swordp = *bp++; | ||
448 | *swordp |= *bp++ << 8; | ||
449 | *swordp |= *bp++ << 16; | ||
450 | *swordp |= *bp++ << 24; | ||
451 | |||
452 | if ((sizeof (swordp) > 4) && (*swordp & 0x80000000)) | ||
453 | *swordp |= (~0) << ((sizeof (sword) - 4) * 8); | ||
454 | |||
455 | ++swordp; | ||
456 | npacked += 4; | ||
457 | } | ||
458 | break; | ||
459 | |||
460 | case 'L': | ||
461 | swordp = va_arg (ap, sword *); | ||
462 | for (i = 0; i < nreps; ++i) | ||
463 | { | ||
464 | *swordp = *bp++ << 24; | ||
465 | *swordp |= *bp++ << 16; | ||
466 | *swordp |= *bp++ << 8; | ||
467 | *swordp |= *bp++; | ||
468 | |||
469 | if ((sizeof (swordp) > 4) && (*swordp & 0x80000000)) | ||
470 | *swordp |= (~0) << ((sizeof (sword) - 4) * 8); | ||
471 | |||
472 | ++swordp; | ||
473 | npacked += 4; | ||
474 | } | ||
475 | break; | ||
476 | |||
477 | case 'P': | ||
478 | cbvp = va_arg (ap, struct cat_bvec *); | ||
479 | for (i = 0; i < nreps; ++i) | ||
480 | { | ||
481 | len = *bp++ << 24; | ||
482 | len |= *bp++ << 16; | ||
483 | len |= *bp++ << 8; | ||
484 | len |= *bp++; | ||
485 | |||
486 | newbuf = (byte *) malloc (len); | ||
487 | |||
488 | if (!newbuf) | ||
489 | { | ||
490 | int j; | ||
491 | for (j = 0; j < i; j++) | ||
492 | free (cbvp[i].data); | ||
493 | va_end (ap); | ||
494 | return -1; | ||
495 | } | ||
496 | |||
497 | memmove (newbuf, bp, len); | ||
498 | cbvp[i].data = newbuf; | ||
499 | cbvp[i].len = len; | ||
500 | |||
501 | bp += len; | ||
502 | npacked += len; | ||
503 | } | ||
504 | break; | ||
505 | |||
506 | default: | ||
507 | va_end (ap); | ||
508 | return -1; | ||
509 | } | ||
510 | |||
511 | ++fmt; | ||
512 | } | ||
513 | |||
514 | va_end (ap); | ||
515 | return 0; | ||
516 | } | ||
diff --git a/src/plugins/pack.h b/src/plugins/pack.h deleted file mode 100644 index 81824f2..0000000 --- a/src/plugins/pack.h +++ /dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | /* | ||
2 | Catlib Copyright Notice | ||
3 | |||
4 | The author of this software is Christopher Adam Telfer | ||
5 | Copyright (c) 1998, 1999, 2000, 2001, 2002 | ||
6 | by Christopher Adam Telfer. All Rights Reserved. | ||
7 | |||
8 | Permission to use, copy, modify, and distribute this software for any | ||
9 | purpose without fee is hereby granted, provided that the above copyright | ||
10 | notice, this paragraph, and the following two paragraphs appear in all | ||
11 | copies, modifications, and distributions. | ||
12 | |||
13 | IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | ||
14 | SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | ||
15 | ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | ||
16 | THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
17 | |||
18 | THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT | ||
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
20 | PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF | ||
21 | ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". THE AUTHOR HAS NO | ||
22 | OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR | ||
23 | MODIFICATIONS. | ||
24 | |||
25 | |||
26 | */ | ||
27 | |||
28 | #ifndef __CAT_PACK_H | ||
29 | #define __CAT_PACK_H | ||
30 | |||
31 | /* | ||
32 | "bhwAcslPBHWCSL" | ||
33 | |||
34 | Small letters: do not convert (not implemented for arrays and P) | ||
35 | Captial letters: convert from network byte order to host byte order | ||
36 | |||
37 | b - byte | ||
38 | h - half-word | ||
39 | w - word | ||
40 | a - array (32-byte unsigned long + that many bytes) | ||
41 | c - signed 8 bit value | ||
42 | s - signed 16 bit value | ||
43 | l - signed 32 bit value | ||
44 | p - (unpack only) value is a pointer to a pointer. Generate the buffer | ||
45 | to hold the data. | ||
46 | */ | ||
47 | |||
48 | int cat_pack(void * buf, const char *fmt, ... ); | ||
49 | |||
50 | int cat_unpack(const void * buf, const char *fmt, ... ); | ||
51 | |||
52 | struct cat_bvec { | ||
53 | unsigned long len; | ||
54 | void * data; | ||
55 | }; | ||
56 | |||
57 | #endif /* __CAT_PACK_H */ | ||
58 | |||
59 | |||
diff --git a/src/plugins/pdf/pdfextractor.cc b/src/plugins/pdf/pdfextractor.cc index 9ec37a8..01fe7c9 100644 --- a/src/plugins/pdf/pdfextractor.cc +++ b/src/plugins/pdf/pdfextractor.cc | |||
@@ -24,7 +24,7 @@ | |||
24 | 24 | ||
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "extractor.h" | 26 | #include "extractor.h" |
27 | #include "../convert.h" | 27 | #include "convert.h" |
28 | #include <math.h> | 28 | #include <math.h> |
29 | 29 | ||
30 | #include "parseargs.h" | 30 | #include "parseargs.h" |
@@ -74,7 +74,7 @@ extern "C" { | |||
74 | (((unsigned char)s[1]) & 0xff) == 0xff) { | 74 | (((unsigned char)s[1]) & 0xff) == 0xff) { |
75 | char * result; | 75 | char * result; |
76 | 76 | ||
77 | result = convertToUtf8((const char*) &s[2], s1->getLength() - 2, "UTF-16BE"); | 77 | result = EXTRACTOR_common_convert_to_utf8((const char*) &s[2], s1->getLength() - 2, "UTF-16BE"); |
78 | next = addKeyword(type, | 78 | next = addKeyword(type, |
79 | result, | 79 | result, |
80 | next); | 80 | next); |
@@ -108,7 +108,7 @@ extern "C" { | |||
108 | 108 | ||
109 | if (0 < len) { | 109 | if (0 < len) { |
110 | next = addKeyword(type, | 110 | next = addKeyword(type, |
111 | convertToUtf8(s, len, | 111 | EXTRACTOR_common_convert_to_utf8(s, len, |
112 | "ISO-8859-1"), | 112 | "ISO-8859-1"), |
113 | next); | 113 | next); |
114 | } | 114 | } |
@@ -135,7 +135,7 @@ extern "C" { | |||
135 | /* isUnicode */ | 135 | /* isUnicode */ |
136 | char * result; | 136 | char * result; |
137 | 137 | ||
138 | result = convertToUtf8((const char*)&s[2], s1->getLength() - 2, "UTF-16BE"); | 138 | result = EXTRACTOR_common_convert_to_utf8((const char*)&s[2], s1->getLength() - 2, "UTF-16BE"); |
139 | next = addKeyword(type, | 139 | next = addKeyword(type, |
140 | result, | 140 | result, |
141 | next); | 141 | next); |
diff --git a/src/plugins/pdfextractor.c b/src/plugins/pdfextractor.c index 0ab15d0..e31262d 100644 --- a/src/plugins/pdfextractor.c +++ b/src/plugins/pdfextractor.c | |||
@@ -206,11 +206,11 @@ charsetDecode (const unsigned char *in, size_t size) | |||
206 | /* TODO: extend glibc with | 206 | /* TODO: extend glibc with |
207 | character set that corresponds to | 207 | character set that corresponds to |
208 | Adobe's extended ISOLATIN1 encoding! */ | 208 | Adobe's extended ISOLATIN1 encoding! */ |
209 | return convertToUtf8 ((const char *) in, size, "CSISOLATIN1"); | 209 | return EXTRACTOR_common_convert_to_utf8 ((const char *) in, size, "CSISOLATIN1"); |
210 | } | 210 | } |
211 | else | 211 | else |
212 | { | 212 | { |
213 | return convertToUtf8 ((const char *) &in[2], size - 2, "UTF-16BE"); | 213 | return EXTRACTOR_common_convert_to_utf8 ((const char *) &in[2], size - 2, "UTF-16BE"); |
214 | } | 214 | } |
215 | } | 215 | } |
216 | 216 | ||
diff --git a/src/plugins/pngextractor.c b/src/plugins/pngextractor.c index ee3706b..991afa2 100644 --- a/src/plugins/pngextractor.c +++ b/src/plugins/pngextractor.c | |||
@@ -115,7 +115,7 @@ processtEXt (const char *data, | |||
115 | off = stnlen (data, length) + 1; | 115 | off = stnlen (data, length) + 1; |
116 | if (off >= length) | 116 | if (off >= length) |
117 | return prev; /* failed to find '\0' */ | 117 | return prev; /* failed to find '\0' */ |
118 | keyword = convertToUtf8 (&data[off], length - off, "ISO-8859-1"); | 118 | keyword = EXTRACTOR_common_convert_to_utf8 (&data[off], length - off, "ISO-8859-1"); |
119 | i = 0; | 119 | i = 0; |
120 | while (tagmap[i].name != NULL) | 120 | while (tagmap[i].name != NULL) |
121 | { | 121 | { |
@@ -275,7 +275,7 @@ processzTXt (const char *data, | |||
275 | if (ret != Z_BUF_ERROR) | 275 | if (ret != Z_BUF_ERROR) |
276 | return prev; /* unknown error, abort */ | 276 | return prev; /* unknown error, abort */ |
277 | } | 277 | } |
278 | keyword = convertToUtf8 (buf, bufLen, "ISO-8859-1"); | 278 | keyword = EXTRACTOR_common_convert_to_utf8 (buf, bufLen, "ISO-8859-1"); |
279 | free (buf); | 279 | free (buf); |
280 | i = 0; | 280 | i = 0; |
281 | while (tagmap[i].name != NULL) | 281 | while (tagmap[i].name != NULL) |
diff --git a/src/plugins/tiffextractor.c b/src/plugins/tiffextractor.c index f845c7f..a9d23da 100644 --- a/src/plugins/tiffextractor.c +++ b/src/plugins/tiffextractor.c | |||
@@ -129,7 +129,7 @@ libextractor_tiff_extract (char *filename, | |||
129 | #if __BYTE_ORDER == __BIG_ENDIAN | 129 | #if __BYTE_ORDER == __BIG_ENDIAN |
130 | byteOrder = 1 - byteOrder; | 130 | byteOrder = 1 - byteOrder; |
131 | #endif | 131 | #endif |
132 | cat_unpack (data, TIFF_HEADER_SPECS[byteOrder], TIFF_HEADER_FIELDS (&hdr)); | 132 | EXTRACTOR_common_cat_unpack (data, TIFF_HEADER_SPECS[byteOrder], TIFF_HEADER_FIELDS (&hdr)); |
133 | if (hdr.fourty_two != 42) | 133 | if (hdr.fourty_two != 42) |
134 | return prev; /* can not be tiff */ | 134 | return prev; /* can not be tiff */ |
135 | if (hdr.ifd_offset + 6 > size) | 135 | if (hdr.ifd_offset + 6 > size) |
@@ -159,7 +159,7 @@ libextractor_tiff_extract (char *filename, | |||
159 | DIRECTORY_ENTRY entry; | 159 | DIRECTORY_ENTRY entry; |
160 | off = current_ifd + 2 + DIRECTORY_ENTRY_SIZE * i; | 160 | off = current_ifd + 2 + DIRECTORY_ENTRY_SIZE * i; |
161 | 161 | ||
162 | cat_unpack (&data[off], | 162 | EXTRACTOR_common_cat_unpack (&data[off], |
163 | DIRECTORY_ENTRY_SPECS[byteOrder], | 163 | DIRECTORY_ENTRY_SPECS[byteOrder], |
164 | DIRECTORY_ENTRY_FIELDS (&entry)); | 164 | DIRECTORY_ENTRY_FIELDS (&entry)); |
165 | switch (entry.tag) | 165 | switch (entry.tag) |