+ cleaning up code base
[qpalma.git] / dyn_prog / io.cpp
1 #include "io.h"
2 #include "common.h"
3
4 #include <stdio.h>
5 #include <stdarg.h>
6 #include <ctype.h>
7
8 FILE* CIO::target=stdout;
9
10 CIO::CIO()
11 {
12 }
13
14 void CIO::message(EMessageType prio, const CHAR *fmt, ... )
15 {
16 check_target();
17 print_message_prio(prio, target);
18 va_list list;
19 va_start(list,fmt);
20 vfprintf(target,fmt,list);
21 va_end(list);
22 fflush(target);
23 }
24
25 void CIO::buffered_message(EMessageType prio, const CHAR *fmt, ... )
26 {
27 check_target();
28 print_message_prio(prio, target);
29 va_list list;
30 va_start(list,fmt);
31 vfprintf(target,fmt,list);
32 va_end(list);
33 }
34
35 CHAR* CIO::skip_spaces(CHAR* str)
36 {
37 INT i=0;
38
39 if (str)
40 {
41 for (i=0; isspace(str[i]); i++);
42
43 return &str[i];
44 }
45 else
46 return str;
47 }
48
49 void CIO::set_target(FILE* t)
50 {
51 target=t;
52 }
53
54 void CIO::check_target()
55 {
56 if (!target)
57 target=stdout;
58 }
59
60 void CIO::print_message_prio(EMessageType prio, FILE* target)
61 {
62 switch (prio)
63 {
64 case M_DEBUG:
65 fprintf(target, "[DEBUG] ");
66 break;
67 case M_PROGRESS:
68 fprintf(target, "[PROGRESS] ");
69 break;
70 case M_INFO:
71 //fprintf(target, "[INFO] ");
72 break;
73 case M_NOTICE:
74 fprintf(target, "[NOTICE] ");
75 break;
76 case M_WARN:
77 fprintf(target, "[WARN] ");
78 break;
79 case M_ERROR:
80 fprintf(target, "[ERROR] ");
81 break;
82 case M_CRITICAL:
83 fprintf(target, "[CRITICAL] ");
84 break;
85 case M_ALERT:
86 fprintf(target, "[ALERT] ");
87 break;
88 case M_EMERGENCY:
89 fprintf(target, "[EMERGENCY] ");
90 break;
91 case M_MESSAGEONLY:
92 break;
93 default:
94 break;
95 }
96 }