1 /* Macros to help writing output handlers.
2 Copyright (C) 1996 Markus Armbruster */
13 # define XP_ARG1 stream
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 XPF3R(fmt, a1, a2, a3) fprintf (stream, (fmt), (a1), (a2), (a3))
20 # define XPCR(p) (putc (*(p), stream) == EOF ? -1 : 1)
21 #else /* !USE_PRINTF */
24 # define XP_GETARG(type, index) va_arg (*ap, type)
25 # define XPMR(p,n) f (a, (p), (n))
26 # define XPR(p) f (a, (p), strlen((p)))
27 # define XPF1R(fmt, arg) xgprintf (f, a, (fmt), (arg))
28 # define XPF3R(fmt, a1, a2, a3) xgprintf (f, a, (fmt), (a1), (a2), (a3))
29 # define XPCR(p) XPMR (p, 1)
30 #endif /* !USE_PRINTF */
32 #define XP(p) XP_CHK (XPR ((p)))
33 #define XPM(p,n) XP_CHK (XPMR ((p), (n)))
34 #define XPSR(p) XPMR ((p), sizeof(p)-1)
35 #define XPS(p) XPM ((p), sizeof(p)-1)
36 #define XPF1(fmt, arg) XP_CHK (XPF1R ((fmt), (arg)))
37 #define XPC(c) XP_CHK (XPCR ((c)))
38 #define XP_CHK(expr) \
41 if (n < 0) return -1; else printed += n; \