Blame lib/printf-args.h

Packit 8f70b4
/* Decomposed printf argument list.
Packit 8f70b4
   Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2018 Free Software
Packit 8f70b4
   Foundation, Inc.
Packit 8f70b4
Packit 8f70b4
   This program is free software; you can redistribute it and/or modify
Packit 8f70b4
   it under the terms of the GNU General Public License as published by
Packit 8f70b4
   the Free Software Foundation; either version 3, or (at your option)
Packit 8f70b4
   any later version.
Packit 8f70b4
Packit 8f70b4
   This program is distributed in the hope that it will be useful,
Packit 8f70b4
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8f70b4
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8f70b4
   GNU General Public License for more details.
Packit 8f70b4
Packit 8f70b4
   You should have received a copy of the GNU General Public License along
Packit 8f70b4
   with this program; if not, see <https://www.gnu.org/licenses/>.  */
Packit 8f70b4
Packit 8f70b4
#ifndef _PRINTF_ARGS_H
Packit 8f70b4
#define _PRINTF_ARGS_H
Packit 8f70b4
Packit 8f70b4
/* This file can be parametrized with the following macros:
Packit 8f70b4
     ENABLE_UNISTDIO    Set to 1 to enable the unistdio extensions.
Packit 8f70b4
     PRINTF_FETCHARGS   Name of the function to be declared.
Packit 8f70b4
     STATIC             Set to 'static' to declare the function static.  */
Packit 8f70b4
Packit 8f70b4
/* Default parameters.  */
Packit 8f70b4
#ifndef PRINTF_FETCHARGS
Packit 8f70b4
# define PRINTF_FETCHARGS printf_fetchargs
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
/* Get size_t.  */
Packit 8f70b4
#include <stddef.h>
Packit 8f70b4
Packit 8f70b4
/* Get wchar_t.  */
Packit 8f70b4
#if HAVE_WCHAR_T
Packit 8f70b4
# include <stddef.h>
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
/* Get wint_t.  */
Packit 8f70b4
#if HAVE_WINT_T
Packit 8f70b4
# include <wchar.h>
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
/* Get va_list.  */
Packit 8f70b4
#include <stdarg.h>
Packit 8f70b4
Packit 8f70b4
Packit 8f70b4
/* Argument types */
Packit 8f70b4
typedef enum
Packit 8f70b4
{
Packit 8f70b4
  TYPE_NONE,
Packit 8f70b4
  TYPE_SCHAR,
Packit 8f70b4
  TYPE_UCHAR,
Packit 8f70b4
  TYPE_SHORT,
Packit 8f70b4
  TYPE_USHORT,
Packit 8f70b4
  TYPE_INT,
Packit 8f70b4
  TYPE_UINT,
Packit 8f70b4
  TYPE_LONGINT,
Packit 8f70b4
  TYPE_ULONGINT,
Packit 8f70b4
#if HAVE_LONG_LONG_INT
Packit 8f70b4
  TYPE_LONGLONGINT,
Packit 8f70b4
  TYPE_ULONGLONGINT,
Packit 8f70b4
#endif
Packit 8f70b4
  TYPE_DOUBLE,
Packit 8f70b4
  TYPE_LONGDOUBLE,
Packit 8f70b4
  TYPE_CHAR,
Packit 8f70b4
#if HAVE_WINT_T
Packit 8f70b4
  TYPE_WIDE_CHAR,
Packit 8f70b4
#endif
Packit 8f70b4
  TYPE_STRING,
Packit 8f70b4
#if HAVE_WCHAR_T
Packit 8f70b4
  TYPE_WIDE_STRING,
Packit 8f70b4
#endif
Packit 8f70b4
  TYPE_POINTER,
Packit 8f70b4
  TYPE_COUNT_SCHAR_POINTER,
Packit 8f70b4
  TYPE_COUNT_SHORT_POINTER,
Packit 8f70b4
  TYPE_COUNT_INT_POINTER,
Packit 8f70b4
  TYPE_COUNT_LONGINT_POINTER
Packit 8f70b4
#if HAVE_LONG_LONG_INT
Packit 8f70b4
, TYPE_COUNT_LONGLONGINT_POINTER
Packit 8f70b4
#endif
Packit 8f70b4
#if ENABLE_UNISTDIO
Packit 8f70b4
  /* The unistdio extensions.  */
Packit 8f70b4
, TYPE_U8_STRING
Packit 8f70b4
, TYPE_U16_STRING
Packit 8f70b4
, TYPE_U32_STRING
Packit 8f70b4
#endif
Packit 8f70b4
} arg_type;
Packit 8f70b4
Packit 8f70b4
/* Polymorphic argument */
Packit 8f70b4
typedef struct
Packit 8f70b4
{
Packit 8f70b4
  arg_type type;
Packit 8f70b4
  union
Packit 8f70b4
  {
Packit 8f70b4
    signed char                 a_schar;
Packit 8f70b4
    unsigned char               a_uchar;
Packit 8f70b4
    short                       a_short;
Packit 8f70b4
    unsigned short              a_ushort;
Packit 8f70b4
    int                         a_int;
Packit 8f70b4
    unsigned int                a_uint;
Packit 8f70b4
    long int                    a_longint;
Packit 8f70b4
    unsigned long int           a_ulongint;
Packit 8f70b4
#if HAVE_LONG_LONG_INT
Packit 8f70b4
    long long int               a_longlongint;
Packit 8f70b4
    unsigned long long int      a_ulonglongint;
Packit 8f70b4
#endif
Packit 8f70b4
    float                       a_float;
Packit 8f70b4
    double                      a_double;
Packit 8f70b4
    long double                 a_longdouble;
Packit 8f70b4
    int                         a_char;
Packit 8f70b4
#if HAVE_WINT_T
Packit 8f70b4
    wint_t                      a_wide_char;
Packit 8f70b4
#endif
Packit 8f70b4
    const char*                 a_string;
Packit 8f70b4
#if HAVE_WCHAR_T
Packit 8f70b4
    const wchar_t*              a_wide_string;
Packit 8f70b4
#endif
Packit 8f70b4
    void*                       a_pointer;
Packit 8f70b4
    signed char *               a_count_schar_pointer;
Packit 8f70b4
    short *                     a_count_short_pointer;
Packit 8f70b4
    int *                       a_count_int_pointer;
Packit 8f70b4
    long int *                  a_count_longint_pointer;
Packit 8f70b4
#if HAVE_LONG_LONG_INT
Packit 8f70b4
    long long int *             a_count_longlongint_pointer;
Packit 8f70b4
#endif
Packit 8f70b4
#if ENABLE_UNISTDIO
Packit 8f70b4
    /* The unistdio extensions.  */
Packit 8f70b4
    const uint8_t *             a_u8_string;
Packit 8f70b4
    const uint16_t *            a_u16_string;
Packit 8f70b4
    const uint32_t *            a_u32_string;
Packit 8f70b4
#endif
Packit 8f70b4
  }
Packit 8f70b4
  a;
Packit 8f70b4
}
Packit 8f70b4
argument;
Packit 8f70b4
Packit 8f70b4
/* Number of directly allocated arguments (no malloc() needed).  */
Packit 8f70b4
#define N_DIRECT_ALLOC_ARGUMENTS 7
Packit 8f70b4
Packit 8f70b4
typedef struct
Packit 8f70b4
{
Packit 8f70b4
  size_t count;
Packit 8f70b4
  argument *arg;
Packit 8f70b4
  argument direct_alloc_arg[N_DIRECT_ALLOC_ARGUMENTS];
Packit 8f70b4
}
Packit 8f70b4
arguments;
Packit 8f70b4
Packit 8f70b4
Packit 8f70b4
/* Fetch the arguments, putting them into a. */
Packit 8f70b4
#ifdef STATIC
Packit 8f70b4
STATIC
Packit 8f70b4
#else
Packit 8f70b4
extern
Packit 8f70b4
#endif
Packit 8f70b4
int PRINTF_FETCHARGS (va_list args, arguments *a);
Packit 8f70b4
Packit 8f70b4
#endif /* _PRINTF_ARGS_H */