Blame lib/printf-args.h

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