Author: chromatic
Date: Tue Dec 23 17:38:08 2008
New Revision: 34310
Modified:
trunk/compilers/imcc/debug.c
trunk/compilers/imcc/imc.h
trunk/compilers/imcc/parser_util.c
Log:
[IMCC] Made imcc_vfprintf() a thin wrapper around Parrot_vsprintf_c(). This
removes yet another sprintf() implementation.
Modified: trunk/compilers/imcc/debug.c
==============================================================================
--- trunk/compilers/imcc/debug.c (original)
+++ trunk/compilers/imcc/debug.c Tue Dec 23 17:38:08 2008
@@ -94,7 +94,7 @@
va_list ap;
va_start(ap, fmt);
- imcc_vfprintf(interp, stderr, fmt, ap);
+ imcc_vfprintf(interp, Parrot_io_STDERR(interp), fmt, ap);
va_end(ap);
Parrot_exit(interp, code);
}
@@ -120,7 +120,7 @@
va_start(ap, fmt);
fprintf(stderr, "error:imcc:");
- imcc_vfprintf(interp, stderr, fmt, ap);
+ imcc_vfprintf(interp, Parrot_io_STDERR(interp), fmt, ap);
va_end(ap);
IMCC_print_inc(interp);
Parrot_exit(interp, code);
@@ -146,7 +146,7 @@
return;
va_start(ap, fmt);
- imcc_vfprintf(interp, stderr, fmt, ap);
+ imcc_vfprintf(interp, Parrot_io_STDERR(interp), fmt, ap);
va_end(ap);
}
@@ -171,7 +171,7 @@
return;
va_start(ap, fmt);
- imcc_vfprintf(interp, stderr, fmt, ap);
+ imcc_vfprintf(interp, Parrot_io_STDERR(interp), fmt, ap);
va_end(ap);
}
@@ -194,7 +194,7 @@
if (!(level & IMCC_INFO(interp)->debug))
return;
va_start(ap, fmt);
- imcc_vfprintf(interp, stderr, fmt, ap);
+ imcc_vfprintf(interp, Parrot_io_STDERR(interp), fmt, ap);
va_end(ap);
}
Modified: trunk/compilers/imcc/imc.h
==============================================================================
--- trunk/compilers/imcc/imc.h (original)
+++ trunk/compilers/imcc/imc.h Tue Dec 23 17:38:08 2008
@@ -250,13 +250,12 @@
FUNC_MODIFIES(*error_message);
int imcc_vfprintf(PARROT_INTERP,
- ARGMOD(FILE *fd),
+ ARGMOD(PMC *io),
ARGIN(const char *format),
va_list ap)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
- __attribute__nonnull__(3)
- FUNC_MODIFIES(*fd);
+ __attribute__nonnull__(3);
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
Modified: trunk/compilers/imcc/parser_util.c
==============================================================================
--- trunk/compilers/imcc/parser_util.c (original)
+++ trunk/compilers/imcc/parser_util.c Tue Dec 23 17:38:08 2008
@@ -1201,113 +1201,17 @@
=item C<int imcc_vfprintf>
-TODO: Needs to be documented!!!
+Formats a given series of arguments per a given format string and prints it to
+the given Parrot IO PMC.
=cut
*/
int
-imcc_vfprintf(PARROT_INTERP, ARGMOD(FILE *fd), ARGIN(const char *format),
va_list ap)
+imcc_vfprintf(PARROT_INTERP, ARGIN(PMC *io), ARGIN(const char *format),
va_list ap)
{
- int len = 0;
- const char *fmt = format;
- char buf[128];
-
- for (;;) {
- const char *cp = fmt;
- int ch = 0;
- size_t n;
-
- for (n = 0; (ch = *fmt) && ch != '%'; fmt++, n++) {/*Empty body*/};
-
- /* print prev string */
- if (n) {
- fwrite(cp, 1, n, fd);
- len += n;
- continue;
- }
-
- /* finished? */
- if (!ch)
- break;
-
- /* ok, we have a format spec */
- /* % */
- ch = *++fmt;
-
- /* print it */
- if (ch == '%') {
- fwrite(fmt, 1, 1, fd);
- len += 1;
- ++fmt;
- continue;
- }
-
- /* look for end of format spec */
- for (; ch && strchr("diouxXeEfFgGcspI", ch) == NULL; ch = *++fmt)
- ;
-
- if (!ch) {
- /* no fatal here, else we get recursion */
- fprintf(stderr, "illegal format at %s\n", cp);
- exit(EXIT_FAILURE);
- }
-
- /* ok, we have a valid format char */
- ++fmt;
- switch (ch) {
- case 'd':
- case 'i':
- case 'o':
- case 'u':
- case 'x':
- case 'X':
- case 'p':
- case 'c':
- {
- const int _int = va_arg(ap, int);
- memcpy(buf, cp, n = (fmt - cp));
- buf[n] = '\0';
- len += fprintf(fd, buf, _int);
- }
- break;
- case 'e':
- case 'E':
- case 'f':
- case 'F':
- case 'g':
- case 'G':
- {
- const double _double = va_arg(ap, double);
- memcpy(buf, cp, n = (fmt - cp));
- buf[n] = '\0';
- len += fprintf(fd, buf, _double);
- }
- break;
- case 's':
- {
- const char * const _string = va_arg(ap, char *);
- memcpy(buf, cp, n = (fmt - cp));
- PARROT_ASSERT(n<128);
- buf[n] = '\0';
- len += fprintf(fd, buf, _string);
- }
- break;
- /* this is the reason for the whole mess */
- case 'I':
- {
- Instruction * const _ins = va_arg(ap, Instruction *);
- len += fprintf(fd, "%s ", _ins->opname);
- len += ins_print(interp, fd, _ins);
- }
- break;
- default:
- break;
- }
- }
-
- return len;
+ return Parrot_io_putps(interp, io, Parrot_vsprintf_c(interp, format, ap));
}
/* Utility functions */