Added copyright headers
[libfirm] / ir / common / xp_help.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/common/xp_help.h
4  * Purpose:     Macros to help writing output handlers.
5  * Author:      Markus Armbruster
6  * Modified by:
7  * Created:     1999 by getting from fiasco
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1996 Markus Armbruster
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13
14 #ifndef _XP_HELP_H
15 #define _XP_HELP_H
16
17 # ifdef HAVE_STRING_H
18 #  include <string.h>
19 # endif
20 #ifdef USE_PRINTF
21 # define XP_ARG1 stream
22 # define XP_ARGN args
23 # define XP_GETARG(type, index) (*(type *)args[index])
24 # define XPMR(p,n) fwrite ((p), 1, (n), stream)
25 # define XPR(p) fputs ((p), stream)
26 # define XPF1R(fmt, arg) fprintf (stream, (fmt), (arg))
27 # define XPF3R(fmt, a1, a2, a3) fprintf (stream, (fmt), (a1), (a2), (a3))
28 # define XPCR(p) (putc (*(p), stream) == EOF ? -1 : 1)
29 #else /* !USE_PRINTF */
30 # define XP_ARG1 f, a
31 # define XP_ARGN ap
32 # define XP_GETARG(type, index) va_arg (*ap, type)
33 # define XPMR(p,n) f (a, (p), (n))
34 # define XPR(p) f (a, (p), strlen((p)))
35 # define XPF1R(fmt, arg) xgprintf (f, a, (fmt), (arg))
36 # define XPF3R(fmt, a1, a2, a3) xgprintf (f, a, (fmt), (a1), (a2), (a3))
37 # define XPCR(p) XPMR (p, 1)
38 #endif /* !USE_PRINTF */
39
40 #define XP(p) XP_CHK (XPR ((p)))
41 #define XPM(p,n) XP_CHK (XPMR ((p), (n)))
42 #define XPSR(p) XPMR ((p), sizeof(p)-1)
43 #define XPS(p) XPM ((p), sizeof(p)-1)
44 #define XPF1(fmt, arg) XP_CHK (XPF1R ((fmt), (arg)))
45 #define XPC(c) XP_CHK (XPCR ((c)))
46 #define XP_CHK(expr)                            \
47   do {                                          \
48     int n = (expr);                             \
49     if (n < 0) return -1; else printed += n;    \
50   } while (0)
51
52 #endif