Back to index

glibc  2.9
printf.h
Go to the documentation of this file.
00001 /* Copyright (C) 1991-1993,1995-1999,2000,2001,2006
00002        Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef       _PRINTF_H
00021 
00022 #define       _PRINTF_H     1
00023 #include <features.h>
00024 
00025 __BEGIN_DECLS
00026 
00027 #define       __need_FILE
00028 #include <stdio.h>
00029 #define       __need_size_t
00030 #define __need_wchar_t
00031 #include <stddef.h>
00032 
00033 
00034 struct printf_info
00035 {
00036   int prec;                 /* Precision.  */
00037   int width;                /* Width.  */
00038   wchar_t spec;                    /* Format letter.  */
00039   unsigned int is_long_double:1;/* L flag.  */
00040   unsigned int is_short:1;  /* h flag.  */
00041   unsigned int is_long:1;   /* l flag.  */
00042   unsigned int alt:1;              /* # flag.  */
00043   unsigned int space:1;            /* Space flag.  */
00044   unsigned int left:1;             /* - flag.  */
00045   unsigned int showsign:1;  /* + flag.  */
00046   unsigned int group:1;            /* ' flag.  */
00047   unsigned int extra:1;            /* For special use.  */
00048   unsigned int is_char:1;   /* hh flag.  */
00049   unsigned int wide:1;             /* Nonzero for wide character streams.  */
00050   unsigned int i18n:1;             /* I flag.  */
00051   wchar_t pad;                     /* Padding character.  */
00052 };
00053 
00054 
00055 /* Type of a printf specifier-handler function.
00056    STREAM is the FILE on which to write output.
00057    INFO gives information about the format specification.
00058    ARGS is a vector of pointers to the argument data;
00059    the number of pointers will be the number returned
00060    by the associated arginfo function for the same INFO.
00061 
00062    The function should return the number of characters written,
00063    or -1 for errors.  */
00064 
00065 typedef int printf_function (FILE *__stream,
00066                           __const struct printf_info *__info,
00067                           __const void *__const *__args);
00068 
00069 /* Type of a printf specifier-arginfo function.
00070    INFO gives information about the format specification.
00071    N, ARGTYPES, and return value are as for parse_printf_format.  */
00072 
00073 typedef int printf_arginfo_function (__const struct printf_info *__info,
00074                                  size_t __n, int *__argtypes);
00075 
00076 
00077 /* Register FUNC to be called to format SPEC specifiers; ARGINFO must be
00078    specified to determine how many arguments a SPEC conversion requires and
00079    what their types are.  */
00080 
00081 extern int register_printf_function (int __spec, printf_function __func,
00082                                  printf_arginfo_function __arginfo);
00083 
00084 
00085 /* Parse FMT, and fill in N elements of ARGTYPES with the
00086    types needed for the conversions FMT specifies.  Returns
00087    the number of arguments required by FMT.
00088 
00089    The ARGINFO function registered with a user-defined format is passed a
00090    `struct printf_info' describing the format spec being parsed.  A width
00091    or precision of INT_MIN means a `*' was used to indicate that the
00092    width/precision will come from an arg.  The function should fill in the
00093    array it is passed with the types of the arguments it wants, and return
00094    the number of arguments it wants.  */
00095 
00096 extern size_t parse_printf_format (__const char *__restrict __fmt, size_t __n,
00097                                int *__restrict __argtypes) __THROW;
00098 
00099 
00100 /* Codes returned by `parse_printf_format' for basic types.
00101 
00102    These values cover all the standard format specifications.
00103    Users can add new values after PA_LAST for their own types.  */
00104 
00105 enum
00106 {                           /* C type: */
00107   PA_INT,                   /* int */
00108   PA_CHAR,                  /* int, cast to char */
00109   PA_WCHAR,                 /* wide char */
00110   PA_STRING,                /* const char *, a '\0'-terminated string */
00111   PA_WSTRING,               /* const wchar_t *, wide character string */
00112   PA_POINTER,               /* void * */
00113   PA_FLOAT,                 /* float */
00114   PA_DOUBLE,                /* double */
00115   PA_LAST
00116 };
00117 
00118 /* Flag bits that can be set in a type returned by `parse_printf_format'.  */
00119 #define       PA_FLAG_MASK         0xff00
00120 #define       PA_FLAG_LONG_LONG    (1 << 8)
00121 #define       PA_FLAG_LONG_DOUBLE  PA_FLAG_LONG_LONG
00122 #define       PA_FLAG_LONG         (1 << 9)
00123 #define       PA_FLAG_SHORT        (1 << 10)
00124 #define       PA_FLAG_PTR          (1 << 11)
00125 
00126 
00127 
00128 /* Function which can be registered as `printf'-handlers.  */
00129 
00130 /* Print floating point value using using abbreviations for the orders
00131    of magnitude used for numbers ('k' for kilo, 'm' for mega etc).  If
00132    the format specifier is a uppercase character powers of 1000 are
00133    used.  Otherwise powers of 1024.  */
00134 extern int printf_size (FILE *__restrict __fp,
00135                      __const struct printf_info *__info,
00136                      __const void *__const *__restrict __args) __THROW;
00137 
00138 /* This is the appropriate argument information function for `printf_size'.  */
00139 extern int printf_size_info (__const struct printf_info *__restrict
00140                           __info, size_t __n, int *__restrict __argtypes)
00141      __THROW;
00142 
00143 #ifdef __LDBL_COMPAT
00144 # include <bits/printf-ldbl.h>
00145 #endif
00146 
00147 __END_DECLS
00148 
00149 #endif /* printf.h  */