~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to extern/fftw/kernel/print.c

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2003, 2006 Matteo Frigo
 
3
 * Copyright (c) 2003, 2006 Massachusetts Institute of Technology
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 *
 
19
 */
 
20
 
 
21
/* $Id: print.c,v 1.30 2006-01-05 03:04:27 stevenj Exp $ */
 
22
 
 
23
#include "ifftw.h"
 
24
#include <stddef.h>
 
25
#include <stdarg.h>
 
26
#include <stdio.h>
 
27
 
 
28
#define BSZ 64
 
29
 
 
30
static void myputs(printer *p, const char *s)
 
31
{
 
32
     char c;
 
33
     while ((c = *s++))
 
34
          p->putchr(p, c);
 
35
}
 
36
 
 
37
static void newline(printer *p)
 
38
{
 
39
     int i;
 
40
 
 
41
     p->putchr(p, '\n');
 
42
     for (i = 0; i < p->indent; ++i)
 
43
          p->putchr(p, ' ');
 
44
}
 
45
 
 
46
static const char *digits = "0123456789abcdef";
 
47
 
 
48
static void putint(printer *p, INT i)
 
49
{
 
50
     char buf[BSZ];
 
51
     char *f = buf;
 
52
 
 
53
     if (i < 0) {
 
54
          p->putchr(p, '-');
 
55
          i = -i;
 
56
     }
 
57
     
 
58
     do {
 
59
          *f++ = digits[i % 10];
 
60
          i /= 10;
 
61
     } while (i);
 
62
     
 
63
     do {
 
64
          p->putchr(p, *--f);
 
65
     } while (f != buf);
 
66
}
 
67
 
 
68
static void putulong(printer *p, unsigned long i, int base, int width)
 
69
{
 
70
     char buf[BSZ];
 
71
     char *f = buf;
 
72
 
 
73
     do {
 
74
          *f++ = digits[i % base];
 
75
          i /= base;
 
76
     } while (i);
 
77
 
 
78
     while (width > f - buf) {
 
79
          p->putchr(p, '0');
 
80
          --width;
 
81
     }
 
82
 
 
83
     do {
 
84
          p->putchr(p, *--f);
 
85
     } while (f != buf);
 
86
}
 
87
 
 
88
static void vprint(printer *p, const char *format, va_list ap)
 
89
{
 
90
     const char *s = format;
 
91
     char c;
 
92
     INT ival;
 
93
 
 
94
     while ((c = *s++)) {
 
95
          switch (c) {
 
96
              case '%':
 
97
                   switch ((c = *s++)) {
 
98
                       case 'M': {
 
99
                            /* md5 value */
 
100
                            md5uint x = va_arg(ap, md5uint);
 
101
                            putulong(p, (unsigned long)(0xffffffffUL & x),
 
102
                                     16, 8);
 
103
                            break;
 
104
                       }
 
105
                       case 'c': {
 
106
                            int x = va_arg(ap, int);
 
107
                            p->putchr(p, x);
 
108
                            break;
 
109
                       }
 
110
                       case 's': {
 
111
                            char *x = va_arg(ap, char *);
 
112
                            if (x)
 
113
                                 myputs(p, x);
 
114
                            else
 
115
                                 goto putnull;
 
116
                            break;
 
117
                       }
 
118
                       case 'd': {
 
119
                            int x = va_arg(ap, int);
 
120
                            ival = (INT)x;
 
121
                            goto putival;
 
122
                       }
 
123
                       case 'D': {
 
124
                            ival = va_arg(ap, INT);
 
125
                            goto putival;
 
126
                       }
 
127
                       case 'v': {
 
128
                            /* print optional vector length */
 
129
                            ival = va_arg(ap, INT);
 
130
                            if (ival > 1) {
 
131
                                 myputs(p, "-x");
 
132
                                 goto putival;
 
133
                            }
 
134
                            break;
 
135
                       }
 
136
                       case 'o': {
 
137
                            /* integer option.  Usage: %oNAME= */
 
138
                            ival = va_arg(ap, INT);
 
139
                            if (ival)
 
140
                                 p->putchr(p, '/');
 
141
                            while ((c = *s++) != '=')
 
142
                                 if (ival)
 
143
                                      p->putchr(p, c);
 
144
                            if (ival) {
 
145
                                 p->putchr(p, '=');
 
146
                                 goto putival;
 
147
                            }
 
148
                            break;
 
149
                       }
 
150
                       case 'u': {
 
151
                            unsigned x = va_arg(ap, unsigned);
 
152
                            putulong(p, (unsigned long)x, 10, 0);
 
153
                            break;
 
154
                       }
 
155
                       case 'x': {
 
156
                            unsigned x = va_arg(ap, unsigned);
 
157
                            putulong(p, (unsigned long)x, 16, 0);
 
158
                            break;
 
159
                       }
 
160
                       case '(': {
 
161
                            /* newline, augment indent level */
 
162
                            p->indent += p->indent_incr;
 
163
                            newline(p);
 
164
                            break;
 
165
                       }
 
166
                       case ')': {
 
167
                            /* decrement indent level */
 
168
                            p->indent -= p->indent_incr;
 
169
                            break;
 
170
                       }
 
171
                       case 'p': {  /* note difference from C's %p */
 
172
                            /* print plan */
 
173
                            plan *x = va_arg(ap, plan *);
 
174
                            if (x) 
 
175
                                 x->adt->print(x, p);
 
176
                            else 
 
177
                                 goto putnull;
 
178
                            break;
 
179
                       }
 
180
                       case 'P': {
 
181
                            /* print problem */
 
182
                            problem *x = va_arg(ap, problem *);
 
183
                            if (x)
 
184
                                 x->adt->print(x, p);
 
185
                            else
 
186
                                 goto putnull;
 
187
                            break;
 
188
                       }
 
189
                       case 'T': {
 
190
                            /* print tensor */
 
191
                            tensor *x = va_arg(ap, tensor *);
 
192
                            if (x)
 
193
                                 X(tensor_print)(x, p);
 
194
                            else
 
195
                                 goto putnull;
 
196
                            break;
 
197
                       }
 
198
                       default:
 
199
                            A(0 /* unknown format */);
 
200
                            break;
 
201
 
 
202
                   putnull:
 
203
                            myputs(p, "(null)");
 
204
                            break;
 
205
 
 
206
                   putival:
 
207
                            putint(p, ival);
 
208
                            break;
 
209
                   }
 
210
                   break;
 
211
              default:
 
212
                   p->putchr(p, c);
 
213
                   break;
 
214
          }
 
215
     }
 
216
}
 
217
 
 
218
static void print(printer *p, const char *format, ...)
 
219
{
 
220
     va_list ap;
 
221
     va_start(ap, format);
 
222
     vprint(p, format, ap);
 
223
     va_end(ap);
 
224
}
 
225
 
 
226
printer *X(mkprinter)(size_t size, 
 
227
                      void (*putchr)(printer *p, char c),
 
228
                      void (*cleanup)(printer *p))
 
229
{
 
230
     printer *s = (printer *)MALLOC(size, OTHER);
 
231
     s->print = print;
 
232
     s->vprint = vprint;
 
233
     s->putchr = putchr;
 
234
     s->cleanup = cleanup;
 
235
     s->indent = 0;
 
236
     s->indent_incr = 2;
 
237
     return s;
 
238
}
 
239
 
 
240
void X(printer_destroy)(printer *p)
 
241
{
 
242
     if (p->cleanup)
 
243
          p->cleanup(p);
 
244
     X(ifree)(p);
 
245
}