*** empty log message ***
[libfirm] / ir / common / xp_help.h
1 /* Macros to help writing output handlers.
2    Copyright (C) 1996 Markus Armbruster */
3
4 /* $Id$ */
5
6 #ifndef _XP_HELP_H
7 #define _XP_HELP_H
8
9 # ifdef HAVE_STRING_H
10 #  include <string.h>
11 # endif
12 #ifdef USE_PRINTF
13 # define XP_ARG1 stream
14 # define XP_ARGN args
15 # define XP_GETARG(type, index) (*(type *)args[index])
16 # define XPMR(p,n) fwrite ((p), 1, (n), stream)
17 # define XPR(p) fputs ((p), stream)
18 # define XPF1R(fmt, arg) fprintf (stream, (fmt), (arg))
19 # define XPCR(p) (putc (*(p), stream) == EOF ? -1 : 1)
20 #else /* !USE_PRINTF */
21 # define XP_ARG1 f, a
22 # define XP_ARGN ap
23 # define XP_GETARG(type, index) va_arg (*ap, type)
24 # define XPMR(p,n) f (a, (p), (n))
25 # define XPR(p) f (a, (p), strlen((p)))
26 # define XPF1R(fmt, arg) xgprintf (f, a, (fmt), (arg))
27 # define XPCR(p) XPMR (p, 1)
28 #endif /* !USE_PRINTF */
29
30 #define XP(p) XP_CHK (XPR ((p)))
31 #define XPM(p,n) XP_CHK (XPMR ((p), (n)))
32 #define XPSR(p) XPMR ((p), sizeof(p)-1)
33 #define XPS(p) XPM ((p), sizeof(p)-1)
34 #define XPF1(fmt, arg) XP_CHK (XPF1R ((fmt), (arg)))
35 #define XPC(c) XP_CHK (XPCR ((c)))
36 #define XP_CHK(expr)                            \
37   do {                                          \
38     int n = (expr);                             \
39     if (n < 0) return -1; else printed += n;    \
40   } while (0)
41
42 #endif