2
* Copyright (c) 2003, 2006 Matteo Frigo
3
* Copyright (c) 2003, 2006 Massachusetts Institute of Technology
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
/* $Id: print.c,v 1.30 2006-01-05 03:04:27 stevenj Exp $ */
30
static void myputs(printer *p, const char *s)
37
static void newline(printer *p)
42
for (i = 0; i < p->indent; ++i)
46
static const char *digits = "0123456789abcdef";
48
static void putint(printer *p, INT i)
59
*f++ = digits[i % 10];
68
static void putulong(printer *p, unsigned long i, int base, int width)
74
*f++ = digits[i % base];
78
while (width > f - buf) {
88
static void vprint(printer *p, const char *format, va_list ap)
90
const char *s = format;
100
md5uint x = va_arg(ap, md5uint);
101
putulong(p, (unsigned long)(0xffffffffUL & x),
106
int x = va_arg(ap, int);
111
char *x = va_arg(ap, char *);
119
int x = va_arg(ap, int);
124
ival = va_arg(ap, INT);
128
/* print optional vector length */
129
ival = va_arg(ap, INT);
137
/* integer option. Usage: %oNAME= */
138
ival = va_arg(ap, INT);
141
while ((c = *s++) != '=')
151
unsigned x = va_arg(ap, unsigned);
152
putulong(p, (unsigned long)x, 10, 0);
156
unsigned x = va_arg(ap, unsigned);
157
putulong(p, (unsigned long)x, 16, 0);
161
/* newline, augment indent level */
162
p->indent += p->indent_incr;
167
/* decrement indent level */
168
p->indent -= p->indent_incr;
171
case 'p': { /* note difference from C's %p */
173
plan *x = va_arg(ap, plan *);
182
problem *x = va_arg(ap, problem *);
191
tensor *x = va_arg(ap, tensor *);
193
X(tensor_print)(x, p);
199
A(0 /* unknown format */);
218
static void print(printer *p, const char *format, ...)
221
va_start(ap, format);
222
vprint(p, format, ap);
226
printer *X(mkprinter)(size_t size,
227
void (*putchr)(printer *p, char c),
228
void (*cleanup)(printer *p))
230
printer *s = (printer *)MALLOC(size, OTHER);
234
s->cleanup = cleanup;
240
void X(printer_destroy)(printer *p)