ref: b9d1e45dc2ee18fe0935e174499779f5b2505028
parent: 63beb9c3beb1b0a0ab3579ab8e7b17b02c0f76f9
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Mon Jul 8 09:40:15 EDT 2002
Work around stdint.h portability problems. If the C99 header isn't available, look for uint32_t in a few other likely headers. Also try and discover appropriate sizes and use our own typedefs if no useful header is found. All this goes into a new generated header file 'config_types.h'. We abuse autogen.sh to create the template so it doesn't clutter cvs for non-autotools builds. Include config.h and config_types.h into every file that includes jbig2_priv.h so ensure the types are defined. git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@112 ded80894-8fb9-0310-811b-c03f3676ab4d
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,7 +1,7 @@
#!/bin/sh
# Run this to set up the build system: configure, makefiles, etc.
-# $Id: autogen.sh,v 1.1 2002/05/08 00:59:20 giles Exp $
+# $Id: autogen.sh,v 1.2 2002/07/08 13:40:15 giles Exp $
package="jbig2dec"
AUTOMAKE_FLAGS="--foreign $AUTOMAKE_FLAGS"
@@ -23,11 +23,37 @@
echo " aclocal $ACLOCAL_FLAGS"
aclocal $ACLOCAL_FLAGS
+
echo " autoheader"
autoheader
+
+echo " creating config_types.h.in"
+cat >config_types.h.in <<EOF
+/*
+ generated header with missing types for the
+ jbig2dec program and library. include this
+ after config.h, within the HAVE_CONFIG_H
+ ifdef
+*/
+
+#ifndef HAVE_STDINT_H
+# ifdef JBIG2_REPLACE_STDINT_H
+# include <@JBIG2_STDINT_H@>
+# else
+ typedef unsigned @JBIG2_INT32_T@ uint32_t;
+ typedef unsigned @JBIG2_INT16_T@ uint16_t;
+ typedef unsigned @JBIG2_INT8_T@ uint8_t;
+ typedef signed @JBIG2_INT32_T@ int32_t;
+ typedef signed @JBIG2_INT16_T@ int16_t;
+ typedef signed @JBIG2_INT8_T@ int8_t;
+# endif /* JBIG2_REPLACE_STDINT */
+#endif /* HAVE_STDINT_H */
+EOF
+
echo " automake --add-missing $AUTOMAKE_FLAGS"
automake --add-missing $AUTOMAKE_FLAGS
echo " running autoconf"
+
autoconf
if test -z "$*"; then
--- a/configure.ac
+++ b/configure.ac
@@ -10,7 +10,7 @@
AM_INIT_AUTOMAKE([$package], [$version])
AM_CONFIG_HEADER(config.h)
-AC_REVISION([$Revision: 1.3 $])
+AC_REVISION([$Revision: 1.4 $])
# Checks for programs.
AC_PROG_CC
@@ -18,16 +18,87 @@
# Checks for libraries.
AC_CHECK_LIB([png], [png_check_sig], [
+ AC_CHECK_HEADER([png.h], [
+ AC_CHECK_LIB([z], [deflate], [
AC_DEFINE(HAVE_LIBPNG, 1, [Define if libpng is available (-lpng)])
- LIBS="$LIBS -lpng"
+ LIBS="$LIBS -lpng -lz"
LIBOBJS="$LIBOBJS jbig2_image_png.o"
- AC_CHECK_LIB([z], [deflate])
+ ])
+ ])
])
# Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS([libintl.h stddef.h stdint.h stdlib.h string.h strings.h unistd.h])
+AC_CHECK_HEADERS([libintl.h stddef.h unistd.h strings.h])
+dnl We assume the fixed-size types from stdint.h. If that header is are not available,
+dnl look for the same types in a few other headers. We also attempt to define them
+dnl ourselves, but only use those is the native versions aren't available.
+dnl The substitutions happen in a file config_types.h, whose template is
+dnl created by autogen.sh
+stdint_types_in="no_replacement_found"
+stdint_types_discovered="yes"
+AC_CHECK_SIZEOF(char)
+AC_CHECK_SIZEOF(short)
+AC_CHECK_SIZEOF(int)
+AC_CHECK_SIZEOF(long)
+if test $ac_cv_sizeof_char = 1; then
+ AC_MSG_RESULT([can define int8_t as char])
+ int8_type="char"
+else
+ stdint_types_discovered="no"
+fi
+if test $ac_cv_sizeof_short = 2; then
+ AC_MSG_RESULT([can define int16_t as short])
+ int16_type="short"
+elif test $ac_cv_sizeof_char = 2; then
+ AC_MSG_RESULT([can define int16_t as char])
+ int16_type="char"
+elif test $ac_cv_sizeof_int = 2; then
+ AC_MSG_RESULT([can define int16_t as int])
+ int16_type="char"
+else
+ stdint_types_discovered="no"
+fi
+if test $ac_cv_sizeof_int = 4; then
+ AC_MSG_RESULT([can define int32_t as int])
+ int32_type="int"
+elif test $ac_cv_sizeof_long = 4; then
+ AC_MSG_RESULT([can define int32_t as long])
+ int32_type="long"
+elif test $ac_cv_sizeof_short = 4; then
+ AC_MSG_RESULT([can define int32_t as short])
+ int32_type="short"
+else
+ stdint_types_discovered="no"
+fi
+AC_CHECK_HEADER([stdint.h])
+if test "x$ac_cv_header_stdint_h" != "xyes"; then
+ for include in sys/types.h inttypes.h sys/inttypes.h sys/int_types.h ; do
+ AC_MSG_CHECKING([for uint32_t in $include])
+ AC_TRY_COMPILE([#include <$include>], [uint32_t canary;], [
+ AC_MSG_RESULT([yes])
+ stdint_types_in="$include"
+ break;
+ ], AC_MSG_RESULT([no])
+ )
+ done
+ if test "x$stding_types_in" != "xno_replacement_found"; then
+ AC_MSG_RESULT([Adding $stdint_types_in to config header for stdint types])
+ AC_DEFINE([JBIG2_REPLACE_STDINT_H],,
+ [set by configure if an alternate header with the stdint.h types is found])
+ elif test "x$stdint_types_discovered" = "xno"; then
+ AC_MSG_ERROR([
+Unable to find suitable definitions of the stdint.h types (uint32_t and friends)
+You will have to define these yourself in a separate header
+ ])
+ fi
+fi
+AC_SUBST(JBIG2_INT32_T, [$int32_type])
+AC_SUBST(JBIG2_INT16_T, [$int16_type])
+AC_SUBST(JBIG2_INT8_T, [$int8_type])
+AC_SUBST(JBIG2_STDINT_H, [$stdint_types_in])
+
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
@@ -45,5 +116,5 @@
# generate output
AC_SUBST(LIBOJBS)
-AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([Makefile config_types.h])
AC_OUTPUT
--- a/jbig2.c
+++ b/jbig2.c
@@ -8,13 +8,20 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2.c,v 1.12 2002/07/04 16:33:44 giles Exp $
+ $Id: jbig2.c,v 1.13 2002/07/08 13:40:15 giles Exp $
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
#include <stdint.h>
+#endif
+
+#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-#include <stdio.h>
#include "jbig2.h"
#include "jbig2_priv.h"
--- a/jbig2_arith.c
+++ b/jbig2_arith.c
@@ -8,12 +8,19 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_arith.c,v 1.8 2002/06/05 00:15:57 raph Exp $
+ $Id: jbig2_arith.c,v 1.9 2002/07/08 13:40:15 giles Exp $
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
-#include <stdint.h>
#include "jbig2.h"
#include "jbig2_priv.h"
--- a/jbig2_arith_iaid.c
+++ b/jbig2_arith_iaid.c
@@ -1,12 +1,19 @@
/* Annex A.3 */
-#ifdef VERBOSE
-#include <stdio.h> /* for debug printing only */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
#include <stddef.h>
-#include <stdint.h>
#include <string.h> /* memset() */
+
+#ifdef VERBOSE
+#include <stdio.h> /* for debug printing only */
+#endif
#include "jbig2.h"
#include "jbig2_priv.h"
--- a/jbig2_arith_int.c
+++ b/jbig2_arith_int.c
@@ -1,7 +1,14 @@
/* Annex A */
-#include <stddef.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
#include <stdint.h>
+#endif
+
+#include <stddef.h>
#include <string.h> /* memset() */
#include "jbig2.h"
--- a/jbig2_generic.c
+++ b/jbig2_generic.c
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_generic.c,v 1.10 2002/07/04 13:34:29 giles Exp $
+ $Id: jbig2_generic.c,v 1.11 2002/07/08 13:40:15 giles Exp $
*/
/**
@@ -15,7 +15,14 @@
* Generic region handlers.
**/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
#include <stdint.h>
+#endif
+
#include <stddef.h>
#include <string.h> /* memcpy(), memset() */
@@ -22,6 +29,7 @@
#ifdef OUTPUT_PBM
#include <stdio.h>
#endif
+
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
--- a/jbig2_huffman.c
+++ b/jbig2_huffman.c
@@ -8,11 +8,19 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_huffman.c,v 1.8 2002/06/15 16:02:53 giles Exp $
+ $Id: jbig2_huffman.c,v 1.9 2002/07/08 13:40:15 giles Exp $
*/
/* Huffman table decoding procedures
-- See Annex B of the JBIG2 draft spec */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
#include <stdlib.h>
--- a/jbig2_image.c
+++ b/jbig2_image.c
@@ -8,12 +8,19 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_image.c,v 1.16 2002/07/04 13:34:29 giles Exp $
+ $Id: jbig2_image.c,v 1.17 2002/07/08 13:40:15 giles Exp $
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
-#include <stdint.h>
#include <string.h> /* memcpy() */
#include "jbig2.h"
--- a/jbig2_image_png.c
+++ b/jbig2_image_png.c
@@ -8,8 +8,16 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_image_png.c,v 1.3 2002/07/03 00:30:20 giles Exp $
+ $Id: jbig2_image_png.c,v 1.4 2002/07/08 13:40:15 giles Exp $
*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
--- a/jbig2_mmr.c
+++ b/jbig2_mmr.c
@@ -2,7 +2,14 @@
in Ghostscript.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
#include <stdint.h>
+#endif
+
#include <stddef.h>
#include <stdio.h>
--- a/jbig2_page.c
+++ b/jbig2_page.c
@@ -8,8 +8,16 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_page.c,v 1.9 2002/07/07 20:38:26 giles Exp $
+ $Id: jbig2_page.c,v 1.10 2002/07/08 13:40:15 giles Exp $
*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
#include <stdlib.h>
--- a/jbig2_segment.c
+++ b/jbig2_segment.c
@@ -8,11 +8,18 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_segment.c,v 1.13 2002/07/07 20:38:26 giles Exp $
+ $Id: jbig2_segment.c,v 1.14 2002/07/08 13:40:15 giles Exp $
*/
-#include <stdlib.h> /* size_t */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "config_types.h"
+#endif
+#ifdef HAVE_STDINT_H
#include <stdint.h>
+#endif
+
+#include <stddef.h> /* size_t */
#include "jbig2.h"
#include "jbig2_priv.h"
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -8,18 +8,21 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_symbol_dict.c,v 1.14 2002/07/04 13:34:29 giles Exp $
+ $Id: jbig2_symbol_dict.c,v 1.15 2002/07/08 13:40:15 giles Exp $
symbol dictionary segment decode and support
*/
-#include <stddef.h>
-#include <stdint.h>
-#include <string.h> /* memset() */
-
#ifdef HAVE_CONFIG_H
#include "config.h"
+#include "config_types.h"
#endif
+#if HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+#include <stddef.h>
+#include <string.h> /* memset() */
#include "jbig2.h"
#include "jbig2_priv.h"
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -8,18 +8,20 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_text.c,v 1.11 2002/07/07 20:38:26 giles Exp $
+ $Id: jbig2_text.c,v 1.12 2002/07/08 13:40:15 giles Exp $
*/
-#include <stddef.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h> /* memset() */
-
#ifdef HAVE_CONFIG_H
#include "config.h"
+#include "config_types.h"
#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#include <stddef.h>
+#include <string.h> /* memset() */
+
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_arith.h"
@@ -144,9 +146,7 @@
} else {
code = jbig2_arith_int_decode(IADT, as, &STRIPT);
}
-#ifdef DEBUG
- fprintf(stderr, "decoded stript value %d (scale to %d)\n", STRIPT, -STRIPT*params->SBSTRIPS);
-#endif
+
/* 6.4.5 (2) */
STRIPT *= -(params->SBSTRIPS);
FIRSTS = 0;
@@ -162,9 +162,7 @@
}
DT *= params->SBSTRIPS;
STRIPT += DT;
-#ifdef DEBUG
- fprintf(stderr, "decoded DT = %d, STRIPT = %d\n", DT, STRIPT);
-#endif
+
first_symbol = TRUE;
/* 6.4.5 (3c) - decode symbols in strip */
for (;;) {
@@ -179,9 +177,7 @@
FIRSTS += DFS;
CURS = FIRSTS;
first_symbol = FALSE;
-#ifdef DEBUG
- fprintf(stderr, "decoded DFS = %d (first symbol) CURS = %d\n", DFS, CURS);
-#endif
+
} else {
/* (3c.ii / 6.4.8) */
if (params->SBHUFF) {
@@ -190,15 +186,9 @@
code = jbig2_arith_int_decode(IADS, as, &IDS);
}
if (code) {
-#ifdef DEBUG
- fprintf(stderr, "Symbol instance S coordinate OOB: End of Strip\n");
-#endif
break;
}
CURS += IDS + params->SBDSOFFSET;
-#ifdef DEBUG
- fprintf(stderr, "decoded IDS = %d, CURS = %d\n", IDS, CURS);
-#endif
}
/* (3c.iii / 6.4.9) */
@@ -210,9 +200,7 @@
code = jbig2_arith_int_decode(IAIT, as, &CURT);
}
T = STRIPT + CURT;
-#ifdef DEBUG
- fprintf(stderr, "decoded CURT = %d, STRIPT = %d, T = %d\n", CURT, STRIPT, T);
-#endif
+
/* (3b.iv / 6.4.10) decode the symbol id */
if (params->SBHUFF) {
/* todo */
@@ -223,9 +211,7 @@
return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
"symbol id out of range! (%d/%d)", ID, max_id);
}
-#ifdef DEBUG
- fprintf(stderr, "decoded symbol id = %d (code = %d)\n", ID, code);
-#endif
+
/* (3c.v) look up the symbol bitmap IB */
{
int id = ID;
--- a/jbig2dec.c
+++ b/jbig2dec.c
@@ -8,17 +8,21 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2dec.c,v 1.26 2002/07/04 16:33:44 giles Exp $
+ $Id: jbig2dec.c,v 1.27 2002/07/08 13:40:15 giles Exp $
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-
#ifdef HAVE_CONFIG_H
#include "config.h"
+#include "config_types.h"
#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+#include <stdio.h>
+# include <stdlib.h>
+# include <stddef.h>
+# include <string.h>
#ifdef HAVE_GETOPT_H
# include <getopt.h>