Code: Select all
retnum *= -1;
kprintf("%d", (signed long)-62);
Here is the kprintf code:
Code: Select all
void kprintf(const char *str, ...)
{
va_list listptr;
va_start(listptr, str);
short is_percent = 0;
short colour_changed = 0;
register int i = 0;
for(; i < strlen(str); i++)
{
if(str[i] == '%')
{
is_percent = 1;
continue;
}
if(is_percent)
{
switch(str[i])
{
case '%':
//Gotta print % itself
putch('%');
break;
case 'i':
putnum(va_arg(listptr, int));
break;
case 'd':
putnum(va_arg(listptr, long));
break;
case 'c':
putch((char)va_arg(listptr, int));
break;
case 'x':
puthex(va_arg(listptr, unsigned int));
break;
case 's':
puts(va_arg(listptr, char*));
break;
case 'u':
putunum(va_arg(listptr, unsigned long));
break;
case 'f':
putfloat(va_arg(listptr, double));
break;
case '~':
//Start messy if-else...
if(str[i + 1] == 'B' && str[i + 2] == 'L' && str[i + 3] == 'A')
{
set_text_colour(BLACK);
colour_changed = 1;
}
else if(str[i + 1] == 'B' && str[i + 2] == 'L' && str[i + 3] == 'U')
{
set_text_colour(BLUE);
colour_changed = 1;
}
else if(str[i + 1] == 'G' && str[i + 2] == 'R' && str[i + 3] == 'E')
{
set_text_colour(BLUE);
colour_changed = 1;
}
else if(str[i + 1] == 'C' && str[i + 2] == 'Y' && str[i + 3] == 'A')
{
set_text_colour(CYAN);
colour_changed = 1;
}
else if(str[i + 1] == 'R' && str[i + 2] == 'E' && str[i + 3] == 'D')
{
set_text_colour(RED);
colour_changed = 1;
}
else if(str[i + 1] == 'M' && str[i + 2] == 'A' && str[i + 3] == 'G')
{
set_text_colour(MAGENTA);
colour_changed = 1;
}
else if(str[i + 1] == 'B' && str[i + 2] == 'R' && str[i + 3] == 'O')
{
set_text_colour(BROWN);
colour_changed = 1;
}
else if(str[i + 1] == 'L' && str[i + 2] == 'G' && str[i + 3] == 'Y')
{
set_text_colour(LIGHTGREY);
colour_changed = 1;
}
else if(str[i + 1] == 'D' && str[i + 2] == 'G' && str[i + 3] == 'Y')
{
set_text_colour(DARKGREY);
colour_changed = 1;
}
else if(str[i + 1] == 'L' && str[i + 2] == 'B' && str[i + 3] == 'U')
{
set_text_colour(LIGHTBLUE);
colour_changed = 1;
}
else if(str[i + 1] == 'L' && str[i + 2] == 'G' && str[i + 3] == 'E')
{
set_text_colour(LIGHTGREEN);
colour_changed = 1;
}
else if(str[i + 1] == 'L' && str[i + 2] == 'C' && str[i + 3] == 'Y')
{
set_text_colour(LIGHTCYAN);
colour_changed = 1;
}
else if(str[i + 1] == 'L' && str[i + 2] == 'R' && str[i + 3] == 'E')
{
set_text_colour(LIGHTRED);
colour_changed = 1;
}
else if(str[i + 1] == 'L' && str[i + 2] == 'M' && str[i + 3] == 'A')
{
set_text_colour(LIGHTMAGENTA);
colour_changed = 1;
}
else if(str[i + 1] == 'L' && str[i + 2] == 'B' && str[i + 3] == 'R')
{
set_text_colour(LIGHTBROWN);
colour_changed = 1;
}
else if(str[i + 1] == 'W' && str[i + 2] == 'H' && str[i + 3] == 'I')
{
set_text_colour(WHITE);
colour_changed = 1;
}
else
{
putchar(str[i]);
break;
}
i += 3;
break;
//Precision format handling
default:
if(is_number(str[i]) || str[i] == '.')
{
int tmp = i;
while(is_number(str[tmp]) || str[tmp] == '.')
{
tmp++;
}
char tm[3] = { str[i], str[i + 1] };
switch(str[tmp])
{
case 'i':
case 'd':
putnum_precision(va_arg(listptr, int), atoi(tm));
return;
case 'u':
putunum_precision(va_arg(listptr, unsigned long), atoi(tm));
return;
case 'x':
puthex_precision(va_arg(listptr, unsigned int), atoi(tm));
return;
}
short precision = 0;
tmp = i;
while(str[tmp] != '.')
{
tmp++;
if(is_letter(str[tmp]))
{
precision = 10;
break;
}
}
tmp++;
char t[3] = "";
if(!is_letter(str[tmp]))
{
t[0] = str[tmp];
}
else if(is_letter(str[tmp]))
{
precision = 10;
goto print;
}
if(!is_letter(str[tmp + 1]))
{
t[1] = str[tmp + 1];
}
precision = atoi(t);
print:
if(is_letter(str[tmp + 1]))
{
tmp--;
}
switch(str[tmp + 2])
{
case 'f':
putfloat_precision(va_arg(listptr, double), precision);
break;
}
i = tmp + 3;
}
break;
}
is_percent = 0;
}
else
{
putch(str[i]);
}
}
if(colour_changed)
{
set_text_colour(WHITE);
}
va_end(listptr);
}
What's wrong?
Thanks.