* docs/pmc.pod:
[parrot.git] / src / warnings.c
blobc3f2988217ecf8af09aa18d83937a04fa0713870
1 /*
2 Copyright (C) 2001-2003, The Perl Foundation.
3 $Id$
5 =head1 NAME
7 src/warnings.c - Warning and error reporting
9 =head1 DESCRIPTION
11 Parrot C<STRING> and C string versions of a function to print warning/error
12 messages.
14 =over 4
16 =cut
20 #include "parrot/parrot.h"
22 #include <stdarg.h>
23 #include <assert.h>
27 =item C<void
28 print_pbc_location(Parrot_Interp interpreter)>
30 Prints the bytecode location of the warning or error to C<PIO_STDERR>.
32 =cut
36 void
37 print_pbc_location(Parrot_Interp interpreter)
39 Interp * const tracer =
40 interpreter->debugger ?
41 interpreter->debugger : interpreter;
42 PIO_eprintf(tracer, "%Ss\n",
43 Parrot_Context_infostr(interpreter,
44 CONTEXT(interpreter->ctx)));
49 =item C<static INTVAL
50 print_warning(Interp *interpreter, STRING *msg)>
52 Prints the warning message and the bytecode location.
54 =cut
58 static INTVAL
59 print_warning(Interp *interpreter, STRING *msg)
62 if (!msg)
63 PIO_puts(interpreter, PIO_STDERR(interpreter), "Unknown warning\n");
64 else {
65 PIO_putps(interpreter, PIO_STDERR(interpreter), msg);
66 if (string_ord(interpreter, msg, -1) != '\n')
67 PIO_eprintf(interpreter, "%c", '\n');
69 print_pbc_location(interpreter);
70 return 1;
75 =back
77 =head2 Parrot Warnings Interface
79 =over
81 =item C<INTVAL
82 Parrot_warn(Interp *interpreter, INTVAL warnclass,
83 const char *message, ...)>
85 The Parrot C string warning/error reporter.
87 Returns 2 on error, 1 on success.
89 C<message, ..> can be a C<Parrot_vsprintf_c()> format with arguments.
91 =cut
95 INTVAL
96 Parrot_warn(Interp *interpreter, INTVAL warnclass,
97 const char *message, ...)
99 STRING *targ;
101 va_list args;
103 assert(interpreter);
104 if (!PARROT_WARNINGS_test(interpreter, warnclass))
105 return 2;
107 va_start(args, message);
108 targ = Parrot_vsprintf_c(interpreter, message, args);
109 va_end(args);
110 return print_warning(interpreter, targ);
116 =item C<INTVAL
117 Parrot_warn_s(Interp *interpreter, INTVAL warnclass,
118 STRING *message, ...)>
120 The Parrot C<STRING> warning/error reporter.
122 Returns 2 on error, 1 on success.
124 C<message, ..> can be a C<Parrot_vsprintf_s()> format with arguments.
126 =cut
130 INTVAL
131 Parrot_warn_s(Interp *interpreter, INTVAL warnclass,
132 STRING *message, ...)
134 STRING *targ;
136 va_list args;
138 if (!interpreter || !PARROT_WARNINGS_test(interpreter, warnclass))
139 return 2;
141 va_start(args, message);
142 targ = Parrot_vsprintf_s(interpreter, message, args);
143 va_end(args);
145 return print_warning(interpreter, targ);
150 =back
152 =head1 SEE ALSO
154 F<include/parrot/warnings.h>.
156 =cut
162 * Local variables:
163 * c-file-style: "parrot"
164 * End:
165 * vim: expandtab shiftwidth=4: