Add the identifying header
[kugel-rb.git] / apps / plugins / pdbox / PDa / src / s_print.c
blobc71dcb78451f45639cb3342699668c393b1eb5db
1 /* Copyright (c) 1997-1999 Miller Puckette.
2 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
3 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
5 #include "m_pd.h"
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <stdarg.h>
9 #include <string.h>
10 #include <errno.h>
12 #if defined(ROCKBOX) && defined (SIMULATOR)
13 /* Copied from stdio.h */
14 int printf (__const char *__restrict __format, ...);
15 int vprintf (__const char *__restrict __format, va_list __arg);
16 int vsprintf (char *__restrict __s,
17 __const char *__restrict __format,
18 va_list __arg);
19 int putchar (int __c);
20 #endif
22 void post(char *fmt, ...)
24 #ifdef ROCKBOX
25 #ifdef SIMULATOR
26 va_list ap;
27 va_start(ap, fmt);
28 vprintf(fmt, ap);
29 va_end(ap);
30 putchar('\n');
31 #else /* SIMULATOR */
32 (void) fmt;
33 #endif /* SIMULATOR */
34 #else /* ROCKBOX */
35 va_list ap;
36 t_int arg[8];
37 int i;
38 va_start(ap, fmt);
39 vfprintf(stderr, fmt, ap);
40 va_end(ap);
41 putc('\n', stderr);
42 #endif /* ROCKBOX */
45 void startpost(char *fmt, ...)
47 #ifdef ROCKBOX
48 #ifdef SIMULATOR
49 va_list ap;
50 t_int arg[8];
51 unsigned int i;
52 va_start(ap, fmt);
54 for (i = 0 ; i < 8; i++)
55 arg[i] = va_arg(ap, t_int);
57 va_end(ap);
58 printf(fmt, arg[0], arg[1], arg[2], arg[3],
59 arg[4], arg[5], arg[6], arg[7]);
60 #else /* SIMULATOR */
61 (void) fmt;
62 #endif /* SIMULATOR */
63 #else /* ROCKBOX */
64 va_list ap;
65 t_int arg[8];
66 int i;
67 va_start(ap, fmt);
69 for (i = 0 ; i < 8; i++) arg[i] = va_arg(ap, t_int);
70 va_end(ap);
71 fprintf(stderr, fmt, arg[0], arg[1], arg[2], arg[3],
72 arg[4], arg[5], arg[6], arg[7]);
73 #endif /* ROCKBOX */
76 void poststring(char *s)
78 #ifdef ROCKBOX
79 #ifdef SIMULATOR
80 printf(" %s", s);
81 #else /* SIMULATOR */
82 (void) s;
83 #endif /* SIMULATOR */
84 #else /* ROCKBOX */
85 fprintf(stderr, " %s", s);
86 #endif /* ROCKBOX */
89 void postatom(int argc, t_atom *argv)
91 int i;
92 for (i = 0; i < argc; i++)
94 char buf[80];
95 atom_string(argv+i, buf, 80);
96 poststring(buf);
100 void postfloat(float f)
102 t_atom a;
103 SETFLOAT(&a, f);
104 postatom(1, &a);
107 void endpost(void)
109 #ifdef ROCKBOX
110 #ifdef SIMULATOR
111 putchar('\n');
112 #endif /* SIMULATOR */
113 #else /* ROCKBOX */
114 fprintf(stderr, "\n");
115 #endif /* ROCKBOX */
118 void error(char *fmt, ...)
120 #ifdef ROCKBOX
121 #ifdef SIMULATOR
122 va_list ap;
123 va_start(ap, fmt);
124 printf("error: ");
125 vprintf(fmt, ap);
126 va_end(ap);
127 putchar('\n');
128 #else /* SIMULATOR */
129 (void) fmt;
130 #endif /* SIMULATOR */
131 #else /* ROCKBOX */
132 va_list ap;
133 t_int arg[8];
134 int i;
135 va_start(ap, fmt);
136 fprintf(stderr, "error: ");
137 vfprintf(stderr, fmt, ap);
138 va_end(ap);
139 putc('\n', stderr);
140 #endif /* ROCKBOX */
143 /* here's the good way to log errors -- keep a pointer to the
144 offending or offended object around so the user can search for it
145 later. */
147 static void *error_object;
148 static char error_string[256];
149 void canvas_finderror(void *object);
151 void pd_error(void *object, char *fmt, ...)
153 #ifdef ROCKBOX
154 #ifdef SIMULATOR
155 va_list ap;
156 static int saidit = 0;
158 va_start(ap, fmt);
159 vsprintf(error_string, fmt, ap);
160 va_end(ap);
161 printf("error: %s\n", error_string);
163 error_object = object;
164 if (!saidit)
166 post("... you might be able to track this down from the Find menu.");
167 saidit = 1;
169 #else /* SIMULATOR */
170 (void) object;
171 (void) fmt;
172 #endif /* SIMULATOR */
173 #else /* ROCKBOX */
174 va_list ap;
175 t_int arg[8];
176 int i;
177 static int saidit = 0;
178 va_start(ap, fmt);
179 vsprintf(error_string, fmt, ap);
180 va_end(ap);
181 fprintf(stderr, "error: %s\n", error_string);
182 error_object = object;
183 if (!saidit)
185 post("... you might be able to track this down from the Find menu.");
186 saidit = 1;
188 #endif /* ROCKBOX */
191 void glob_finderror(t_pd *dummy)
193 #ifdef ROCKBOX
194 (void) dummy;
195 #endif /* ROCKBOX */
196 if (!error_object)
197 post("no findable error yet.");
198 else
200 post("last trackable error:");
201 post("%s", error_string);
202 canvas_finderror(error_object);
206 void bug(char *fmt, ...)
208 #ifdef ROCKBOX
209 #ifdef SIMULATOR
210 va_list ap;
211 t_int arg[8];
212 unsigned int i;
214 va_start(ap, fmt);
215 for(i = 0; i < 8; i++)
216 arg[i] = va_arg(ap, t_int);
217 va_end(ap);
219 printf("Consistency check failed: ");
220 printf(fmt, arg[0], arg[1], arg[2], arg[3],
221 arg[4], arg[5], arg[6], arg[7]);
222 putchar('\n');
223 #else /* SIMULATOR */
224 (void) fmt;
225 #endif /* SIMULATOR */
226 #else /* ROCKBOX */
227 va_list ap;
228 t_int arg[8];
229 int i;
230 va_start(ap, fmt);
232 for (i = 0 ; i < 8; i++) arg[i] = va_arg(ap, t_int);
233 va_end(ap);
234 fprintf(stderr, "Consistency check failed: ");
235 fprintf(stderr, fmt, arg[0], arg[1], arg[2], arg[3],
236 arg[4], arg[5], arg[6], arg[7]);
237 putc('\n', stderr);
238 #endif /* ROCKBOX */
241 /* this isn't worked out yet. */
242 static char *errobject;
243 static char *errstring;
245 void sys_logerror(char *object, char *s)
247 errobject = object;
248 errstring = s;
251 void sys_unixerror(char *object)
253 #ifdef ROCKBOX
254 (void) object;
255 #else
256 errobject = object;
257 errstring = strerror(errno);
258 #endif /* ROCKBOX */
261 void sys_ouch(void)
263 if (*errobject) error("%s: %s", errobject, errstring);
264 else error("%s", errstring);