2 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
11 #include <l4/re/log-sys.h>
12 #include <l4/sys/kdebug.h>
13 #include <l4/cxx/minmax>
22 static Moe::Log *last_log = 0;
28 unsigned long size() const { return sizeof(_b); }
30 void printf(char const *fmt, ...);
31 __attribute__((format(printf, 2, 3)));
32 void outnstring(char const *str, unsigned long len);
35 void checknflush(int n);
39 bool fits(unsigned l) const { return (_p + l) < sizeof(_b); }
42 static void my_outnstring(char const *s, unsigned long len)
51 my_outnstring(_b, _p);
55 void Pbuf::checknflush(int n)
58 x = (char*)memchr(_b, '\n', _p + n);
62 int rem = n - (x - _b + 1 - _p);
66 memmove(_b, x + 1, rem);
73 void Pbuf::printf(char const *fmt, ...)
75 if (!fits(strlen(fmt) + 50))
80 n = vsnprintf(_b + _p, size() - _p, fmt, arg);
85 void Pbuf::outnstring(char const *str, unsigned long len)
89 memcpy(_b + _p, str, len);
94 Moe::Log::dispatch(l4_umword_t, L4::Ipc::Iostream &ios)
100 if (tag.label() != L4_PROTO_LOG)
101 return -L4_EBADPROTO;
105 // get opcode out of the message stream
108 // we only have one opcode
109 if (op != L4Re::Log_::Print)
112 char *msg = log_buffer;
113 unsigned long len_msg = sizeof(log_buffer);
117 ios >> L4::Ipc::Buf_cp_in<char>(msg, len_msg);
119 while (len_msg > 0 && msg[0])
122 ob.printf("\033[%s3%dm", (color() & 8) ? "01;" : "", (color() & 7));
124 ob.printf("\033[0m");
126 if (last_log != this)
131 ob.outnstring(_tag, cxx::min<unsigned long>(_l, Max_tag));
133 ob.outnstring(" ", Max_tag-_l);
142 for (i = 0; i < (long)len_msg; ++i)
143 if (msg[i] == '\n' || msg[i] == 0)
146 ob.outnstring(msg, i);
148 if (i < (long)len_msg && msg[i] == '\n')
151 ob.printf("\033[0m\n");
168 if (_in_line && color())
169 ob.printf("\033[0m");
177 Moe::Log::color_value(cxx::String const &col)
179 int c = 0, bright = 0;
186 case 'N': bright = 1; case 'n': c = 0; break;
187 case 'R': bright = 1; case 'r': c = 1; break;
188 case 'G': bright = 1; case 'g': c = 2; break;
189 case 'Y': bright = 1; case 'y': c = 3; break;
190 case 'B': bright = 1; case 'b': c = 4; break;
191 case 'M': bright = 1; case 'm': c = 5; break;
192 case 'C': bright = 1; case 'c': c = 6; break;
193 case 'W': bright = 1; case 'w': c = 7; break;
197 return (bright << 3) | c;