00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef HAVE_CONFIG_H
00034 #include "config.h"
00035 #endif
00036
00037 #include <string.h>
00038
00039 #include "rdd.h"
00040 #include "rdd_internals.h"
00041 #include "msgprinter.h"
00042
00043 typedef struct _RDD_STDIO_MSGPRINTER {
00044 FILE *stream;
00045 } RDD_STDIO_MSGPRINTER;
00046
00047 static void stdio_print(RDD_MSGPRINTER *printer,
00048 rdd_message_t type, int errcode, const char *msg);
00049 static int stdio_close(RDD_MSGPRINTER *printer, unsigned flags);
00050
00051 static RDD_MSGPRINTER_OPS stdio_ops = {
00052 stdio_print,
00053 stdio_close
00054 };
00055
00056 int
00057 rdd_mp_open_stdio_printer(RDD_MSGPRINTER **printer, FILE *stream)
00058 {
00059 RDD_STDIO_MSGPRINTER *stdio = 0;
00060 RDD_MSGPRINTER *p = 0;
00061 int rc = RDD_OK;
00062
00063 rc = rdd_mp_open_printer(&p, &stdio_ops, sizeof(RDD_STDIO_MSGPRINTER));
00064 if (rc != RDD_OK) {
00065 return rc;
00066 }
00067
00068 stdio = (RDD_STDIO_MSGPRINTER *) p->state;
00069 stdio->stream = stream;
00070
00071 *printer = p;
00072 return RDD_OK;
00073 }
00074
00075 static void
00076 stdio_print(RDD_MSGPRINTER *printer, rdd_message_t type, int errcode,
00077 const char *msg)
00078 {
00079 RDD_STDIO_MSGPRINTER *stdio = (RDD_STDIO_MSGPRINTER *) printer->state;
00080
00081 fprintf(stdio->stream, "%s\n", msg);
00082 }
00083
00084 static int
00085 stdio_close(RDD_MSGPRINTER *printer, unsigned flags)
00086 {
00087 RDD_STDIO_MSGPRINTER *stdio = (RDD_STDIO_MSGPRINTER *) printer->state;
00088
00089 memset(stdio, 0, sizeof *stdio);
00090 return RDD_OK;
00091 }