Tiberiu Chibici
caa7718af9
==================================================== Mainly changed: HAL.FSs + Updated 'mount' call in floppy driver, now done after controller is initialized + Added 'detect' function for FAT file systems + Implemented 'initdr' driver, however still bugged + Improved logger
123 lines
2.3 KiB
C
123 lines
2.3 KiB
C
/*
|
|
* logger.c
|
|
*
|
|
* Created on: Sep 2, 2011
|
|
* Author: Tiberiu
|
|
*/
|
|
#include <debugio.h>
|
|
#include <stdlib.h>
|
|
|
|
string LogAllowedDevices[] = {
|
|
"drivers",
|
|
//"floppy",
|
|
"hal",
|
|
"fat",
|
|
"initrd",
|
|
"system",
|
|
"vfs",
|
|
//"mem",
|
|
"console",
|
|
0x0,
|
|
0x0
|
|
};
|
|
|
|
|
|
extern uint8 ConsoleDefaultColor;
|
|
extern void _write_char(char c);
|
|
extern void _write_string (string s);
|
|
|
|
int32 LogWrite (uint8 error, string device, string format, ...)
|
|
{
|
|
if (!format || !*format || !device || !*device) return 0;
|
|
|
|
// Print logged information
|
|
va_list args;
|
|
va_start (args, format);
|
|
uint32 i, len = strlen(format);
|
|
uint8 temp_color = ConsoleDefaultColor;
|
|
|
|
// Check if device is allowed. Errors are allowed
|
|
uint8 allowed = error;
|
|
for (i = 0; LogAllowedDevices[i] != 0 && !allowed; i++)
|
|
if (strcasecmp(device, LogAllowedDevices[i]) == 0) allowed = 1;
|
|
|
|
if (allowed)
|
|
{
|
|
ConsoleDefaultColor = (error) ? Color(ColorRed, ColorWhite) : (1 + (i % 15)) ;
|
|
_write_char('[');
|
|
_write_string(device);
|
|
_write_char(']');
|
|
|
|
ConsoleDefaultColor = temp_color;
|
|
_write_char(' ');
|
|
}
|
|
|
|
for (i = 0; i < len; i++)
|
|
if (format[i] != '%' && allowed) _write_char(format[i]);
|
|
else
|
|
{
|
|
++i;
|
|
switch (format[i]) {
|
|
// Character
|
|
case 'c': {
|
|
char c = va_arg (args, char);
|
|
if (allowed) _write_char(c);
|
|
break;
|
|
}
|
|
|
|
// String
|
|
case 's': {
|
|
int32* c = (int32*) va_arg (args, string);
|
|
if (allowed) _write_string((string)c);
|
|
break;
|
|
}
|
|
|
|
// Integers
|
|
case 'd':
|
|
case 'i': {
|
|
int32 c = va_arg(args, int32); char temp[32];
|
|
if (allowed) {
|
|
ConvertIntToString(temp, c, 10);
|
|
_write_string(temp);
|
|
}
|
|
break;
|
|
}
|
|
|
|
// Integers - hex
|
|
case 'X':
|
|
case 'x': {
|
|
int32 c = va_arg(args, int32); char temp[32];
|
|
if (allowed) {
|
|
ConvertUIntToString(temp, c, 16);
|
|
_write_string(temp);
|
|
}
|
|
break;
|
|
}
|
|
|
|
// Integers - unsigned
|
|
case 'u': {
|
|
int32 c = va_arg(args, uint32); char temp[32];
|
|
if (allowed) {
|
|
ConvertUIntToString (temp, c, 10);
|
|
_write_string(temp);
|
|
}
|
|
break;
|
|
}
|
|
|
|
// Colors
|
|
case '#': {
|
|
uint8 c = va_arg(args, uint8);
|
|
ConsoleDefaultColor = c;
|
|
break; }
|
|
|
|
default: va_end(args); return 1;
|
|
};
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
ConsoleDefaultColor = 0x7;
|
|
ConsoleCursorUpdateHardware();
|
|
return i;
|
|
}
|