From 1fd361a1ea06e44286c213ca1f814f49306fdc43 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 19 Aug 2006 03:12:28 +0000 Subject: Create Subversion repository git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- buildtools/typegen.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 buildtools/typegen.c (limited to 'buildtools/typegen.c') diff --git a/buildtools/typegen.c b/buildtools/typegen.c new file mode 100644 index 00000000..5b32af28 --- /dev/null +++ b/buildtools/typegen.c @@ -0,0 +1,113 @@ +/*---------------------------------------------------------------------------- + typegen +------------------------------------------------------------------------------ + This is a program to create an inttypes.h file for use in building + Netpbm. Ordinarily we use the inttypes.h that comes with the C library + or C compiler, specified by Single Unix Specification. When that isn't + available there is usually some other system header file we should use. + But when there isn't any system header file to define the needed types, + the file we generate is better than nothing. + + The main problem with the inttypes.h we generate is that when we + figure out which type is a 32 bit integer, we aren't necessarily using + the same compile environment as what will actually get used to build + Netpbm, and thus the one where our inttypes.h will be used. + + Right now, it simply generates either + + typedef int int32_t; + + or + + typedef long int32_t; + + based on which type, int, or long, is 32 bits. + + We also include the uint32_t and int_fast32_t typedefs. + + We also include the multiple inclusion guard ifdef. +-----------------------------------------------------------------------------*/ +#include +#include +#include + + + +static void +createTypedefForUint32_t(void) { + + if (sizeof(unsigned int) == 4) + printf("typedef unsigned int uint32_t;\n"); + else if (sizeof(unsigned long) == 4) + printf("typedef unsigned long uint32_t;\n"); + else { + fprintf(stderr, "Cannot find a 32 bit unsigned integer type!\n"); + exit(1); + } +} + + + +static void +createTypedefForUintFast32_t(void) { + + if (sizeof(unsigned int) == 4) + printf("typedef unsigned int uint_fast32_t;\n"); + else if (sizeof(unsigned long) == 4) + printf("typedef unsigned long uint_fast32_t;\n"); + else { + fprintf(stderr, "Cannot find a 32 bit unsigned integer type!\n"); + exit(1); + } +} + + + +static void +createTypedefForInt32_t(void) { + + if (sizeof(signed int) == 4) + printf("typedef signed int int32_t;\n"); + else if (sizeof(signed long) == 4) + printf("typedef signed long int32_t;\n"); + else { + fprintf(stderr, "Cannot find a 32 bit signed integer type!\n"); + exit(1); + } +} + + + +static void +createTypedefForIntFast32_t(void) { + + if (sizeof(signed int) == 4) + printf("typedef signed int int_fast32_t;\n"); + else if (sizeof(signed long) == 4) + printf("typedef signed long int_fast32_t;\n"); + else { + fprintf(stderr, "Cannot find a 32 bit signed integer type!\n"); + exit(1); + } +} + + + +int +main(int argc, char **argv) { + + printf("/* This was generated by the program 'typegen' */\n"); + + + printf("#ifndef INTTYPES_H_NETPBM\n"); + printf("#define INTTYPES_H_NETPBM\n"); + + createTypedefForUint32_t(); + createTypedefForInt32_t(); + createTypedefForIntFast32_t(); + createTypedefForUintFast32_t(); + + printf("#endif\n"); + + return 0; +} -- cgit 1.4.1