root/Whitix/trunk/kernel/print.c

Revision 1914, 2.0 KB (checked in by mwhitworth, 3 years ago)

Export KeVaPrint as a symbol.

Line 
1/*  This file is part of Whitix.
2 *
3 *  Whitix is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  Whitix is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with Whitix; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 */
18
19#include <config.h>
20#include <module.h>
21#include <stdarg.h>
22#include <string.h>
23#include <typedefs.h>
24
25#include <i386/ioports.h>
26
27/* Defines */
28#define CONSOLE_OUT_LEN         256
29
30static void (*ConsoleOutput)(char* message, int length) = NULL;
31
32void KeSetOutput(void (*newOutput)(char*, int))
33{
34        ConsoleOutput=newOutput;
35}
36
37SYMBOL_EXPORT(KeSetOutput);
38
39int logLevelUnknown=1;
40int currLogLevel=-1;
41
42void KeVaPrint(const char* message, VaList args)
43{
44        char buf[CONSOLE_OUT_LEN];
45        char outputBuf[CONSOLE_OUT_LEN];
46        char* start;
47        int length=0;
48       
49        length = vsnprintf(buf, CONSOLE_OUT_LEN, message, args);
50       
51        if (!length)
52                return;
53               
54        length = 0;
55
56        for (start=buf; *start; start++)
57        {
58                if (logLevelUnknown)
59                {
60                        /* Parse the beginning of the message to find out the log level. */
61                        if (*start == '<')
62                        {
63                                currLogLevel=*(start+1)-'0';
64
65                                /* Skip past the closing > */
66                                start+=3;
67                        }else
68                                currLogLevel=1;
69
70                        logLevelUnknown=0;
71                }
72
73                if (currLogLevel <= KERN_LOG_LEVEL)
74                        outputBuf[length++]=*start;
75
76                if (*start == '\n')
77                        logLevelUnknown=1;
78        }
79
80        outputBuf[length]='\0';
81
82        ConsoleOutput(outputBuf, length);
83}
84
85SYMBOL_EXPORT(KeVaPrint);
86
87void KePrint(const char* message, ...)
88{
89        VaList args;
90       
91        VaStart(args, message);
92        KeVaPrint(message, args);
93        VaEnd(args);
94}
95
96SYMBOL_EXPORT(KePrint);
Note: See TracBrowser for help on using the browser.