]> git.ipfire.org Git - thirdparty/glibc.git/blame - stdio/printf.h
initial import
[thirdparty/glibc.git] / stdio / printf.h
CommitLineData
28f540f4
RM
1/* Copyright (C) 1991, 1992, 1993, 1995 Free Software Foundation, Inc.
2This file is part of the GNU C Library.
3
4The GNU C Library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Library General Public License as
6published by the Free Software Foundation; either version 2 of the
7License, or (at your option) any later version.
8
9The GNU C Library is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12Library General Public License for more details.
13
14You should have received a copy of the GNU Library General Public
15License along with the GNU C Library; see the file COPYING.LIB. If
16not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
17Cambridge, MA 02139, USA. */
18
19#ifndef _PRINTF_H
20
21#define _PRINTF_H 1
22#include <features.h>
23
24__BEGIN_DECLS
25
26#define __need_FILE
27#include <stdio.h>
28#define __need_size_t
29#include <stddef.h>
30
31#include <stdarg.h> /* Need va_list. */
32
33
34struct printf_info
35{
36 int prec; /* Precision. */
37 int width; /* Width. */
38 unsigned char spec; /* Format letter. */
39 unsigned int is_long_double:1;/* L flag. */
40 unsigned int is_short:1; /* h flag. */
41 unsigned int is_long:1; /* l flag. */
42 unsigned int alt:1; /* # flag. */
43 unsigned int space:1; /* Space flag. */
44 unsigned int left:1; /* - flag. */
45 unsigned int showsign:1; /* + flag. */
46 unsigned int group:1; /* ' flag. */
47 char pad; /* Padding character. */
48};
49
50
51/* Type of a printf specifier-handler function.
52 STREAM is the FILE on which to write output.
53 INFO gives information about the format specification.
54 Arguments can be read from ARGS.
55 The function should return the number of characters written,
56 or -1 for errors. */
57
58typedef int printf_function __P ((FILE * __stream,
59 __const struct printf_info * __info,
60 va_list * __args));
61typedef int printf_arginfo_function __P ((__const struct printf_info * __info,
62 size_t __n,
63 int *__argtypes));
64
65/* Register FUNC to be called to format SPEC specifiers.
66 ARGINFO, if not NULL, is a function used by `parse_printf_format'
67 to determine how many arguments a SPEC conversion requires,
68 and what their types are. */
69extern int register_printf_function __P ((int __spec, printf_function __func,
70 printf_arginfo_function __arginfo));
71
72/* Parse FMT, and fill in N elements of ARGTYPES with the
73 types needed for the conversions FMT specifies. Returns
74 the number of arguments required by FMT.
75
76 The ARGINFO function registered with a user-defined format is passed a
77 `struct printf_info' describing the format spec being parsed. A width
78 or precision of INT_MIN means a `*' was used to indicate that the
79 width/precision will come from an arg. The function should fill in the
80 array it is passed with the types of the arguments it wants, and return
81 the number of arguments it wants. */
82
83extern size_t parse_printf_format __P ((__const char *__fmt,
84 size_t __n,
85 int *__argtypes));
86
87/* Codes returned by `parse_printf_format' for basic types.
88
89 These values cover all the standard format specifications.
90 Users can add new values after PA_LAST for their own types. */
91
92enum
93{ /* C type: */
94 PA_INT, /* int */
95 PA_CHAR, /* int, cast to char */
96 PA_STRING, /* const char *, a '\0'-terminated string */
97 PA_POINTER, /* void * */
98 PA_FLOAT, /* float */
99 PA_DOUBLE, /* double */
100 PA_LAST
101};
102
103/* Flag bits that can be set in a type returned by `parse_printf_format'. */
104#define PA_FLAG_MASK 0xff00
105#define PA_FLAG_LONG_LONG (1 << 8)
106#define PA_FLAG_LONG_DOUBLE PA_FLAG_LONG_LONG
107#define PA_FLAG_LONG (1 << 9)
108#define PA_FLAG_SHORT (1 << 10)
109#define PA_FLAG_PTR (1 << 11)
110
111
112__END_DECLS
113
114#endif /* printf.h */