X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/5084155b97d2d79e695efcf0ed08c7e805ff6441..75263f25a1ce8e7b38ad4bd61a9a893723ec1db3:/mptypes.c diff --git a/mptypes.c b/mptypes.c index 8751e2e..f10ed7e 100644 --- a/mptypes.c +++ b/mptypes.c @@ -1,8 +1,49 @@ /* -*-c-*- * - * Program to find appropriate types for multiprecision integer stuff. + * $Id: mptypes.c,v 1.4 2000/10/08 12:05:24 mdw Exp $ + * + * Generate `mptypes.h' header file for current architecture + * + * (c) 1999 Straylight/Edgeware + */ + +/*----- Licensing notice --------------------------------------------------* + * + * This file is part of Catacomb. + * + * Catacomb is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * Catacomb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with Catacomb; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +/*----- Revision history --------------------------------------------------* + * + * $Log: mptypes.c,v $ + * Revision 1.4 2000/10/08 12:05:24 mdw + * Make later versions of GCC shut up about @long long@. + * + * Revision 1.3 1999/12/10 23:29:48 mdw + * Change header file guard names. + * + * Revision 1.2 1999/11/13 01:54:32 mdw + * Format source code properly ;-). Attach suffixes to the `max' + * constants. + * */ +/*----- Header files ------------------------------------------------------*/ + #define _GNU_SOURCE #include #include @@ -10,11 +51,19 @@ # include #endif +/*----- Data types --------------------------------------------------------*/ + /* --- Hack for GCC --- * * * WG14 in their infinite wisdom decided not to use the GCC constant name. */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 91) +# define EXT __extension__ +#else +# define EXT +#endif + #if defined(ULONG_LONG_MAX) && !defined(ULLONG_MAX) # define ULLONG_MAX ULONG_LONG_MAX #endif @@ -25,7 +74,7 @@ typedef uintmax_t umax; # define P_UMAX PRIuMAX #elif defined(ULLONG_MAX) - typedef unsigned long long umax; + __extension__ typedef unsigned long long umax; # define P_UMAX "%llu" #else typedef unsigned long umax; @@ -38,35 +87,38 @@ */ enum { - f_stdint + f_stdint = 1u, + f_ext = 2u }; struct itype { const char *name; + const char *suff; umax max; unsigned flags; unsigned bits; } tytab[] = { - { "unsigned int", UINT_MAX, 0 }, - { "unsigned short", USHRT_MAX, 0 }, - { "unsigned long", ULONG_MAX, 0 }, + { "unsigned int", "u", UINT_MAX, 0 }, + { "unsigned short", "u", USHRT_MAX, 0 }, + { "unsigned long", "ul", ULONG_MAX, 0 }, #ifdef ULLONG_MAX - { "unsigned long long", ULLONG_MAX, 0 }, + { "unsigned long long", "ull", EXT ULLONG_MAX, f_ext }, #endif #ifdef UINTMAX_MAX - { "uintmax_t", UINTMAX_MAX, f_stdint }, + { "uintmax_t", "u", UINTMAX_MAX, f_stdint }, #endif { 0, 0 }, }; typedef struct itype itype; -/* --- Main program --- */ +/*----- Main code ---------------------------------------------------------*/ int main(int argc, char *argv[]) { itype *i; itype *largest, *mpw, *mpd; + const static char *extstr = "CATACOMB_MPTYPES_EXTENSION "; /* --- Find the bitcounts --- */ @@ -116,8 +168,8 @@ int main(int argc, char *argv[]) * mptypes.h [generated]\n\ */\n\ \n\ -#ifndef MPTYPES_H\n\ -#define MPTYPES_H\n\ +#ifndef CATACOMB_MPTYPES_H\n\ +#define CATACOMB_MPTYPES_H\n\ "); if ((mpd->flags | mpw->flags) & f_stdint) { puts("\ @@ -126,19 +178,34 @@ int main(int argc, char *argv[]) #endif\n\ "); } + if ((mpd->flags | mpw->flags) & f_ext) { + printf("\ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 91)\n\ +# define %s __extension__\n\ +#else\n\ +# define %s\n\ +#endif\n\ +", extstr, extstr); + } printf("\ -typedef %s mpw;\n\ +%stypedef %s mpw;\n\ #define MPW_BITS %u\n\ -#define MPW_MAX " P_UMAX "\n\ +#define MPW_MAX %s" P_UMAX "%s\n\ \n\ -typedef %s mpd;\n\ +%stypedef %s mpd;\n\ #define MPD_BITS %u\n\ -#define MPD_MAX " P_UMAX "\n\ +#define MPD_MAX %s" P_UMAX "%s\n\ \n\ #endif\n\ ", - mpw->name, mpw->bits, mpw->max, - mpd->name, mpd->bits, mpd->max); + mpw->flags & f_ext ? extstr : "", mpw->name, + mpw->bits, + mpw->flags & f_ext ? extstr : "", mpw->max, mpw->suff, + mpd->flags & f_ext ? extstr : "", mpd->name, + mpd->bits, + mpd->flags & f_ext ? extstr : "", mpd->max, mpd->suff); return (0); } + +/*----- That's all, folks -------------------------------------------------*/