add %s to cprintf for cons_puts

This commit is contained in:
rsc 2006-07-16 16:00:03 +00:00
parent b74f4b57ae
commit b75c11b20e
3 changed files with 23 additions and 1 deletions

View file

@ -105,7 +105,7 @@ printint(int xx, int base, int sgn)
} }
/* /*
* print to the console. only understands %d and %x. * print to the console. only understands %d, %x, %p, %s.
*/ */
void void
cprintf(char *fmt, ...) cprintf(char *fmt, ...)
@ -131,8 +131,19 @@ cprintf(char *fmt, ...)
} else if(c == 'x' || c == 'p'){ } else if(c == 'x' || c == 'p'){
printint(*ap, 16, 0); printint(*ap, 16, 0);
ap++; ap++;
} else if(c == 's'){
char *s = (char*)*ap;
ap++;
while(*s != 0){
real_cons_putc(*s);
s++;
}
} else if(c == '%'){ } else if(c == '%'){
real_cons_putc(c); real_cons_putc(c);
} else {
// Unknown % sequence. Print it to draw attention.
real_cons_putc('%');
real_cons_putc(c);
} }
state = 0; state = 0;
} }

10
ulib.c
View file

@ -16,3 +16,13 @@ puts1(char *s)
return i; return i;
} }
char*
strcpy(char *s, char *t)
{
char *os;
os = s;
while((*s++ = *t++) != 0)
;
return os;
}

1
user.h
View file

@ -13,3 +13,4 @@ int cons_puts(char*);
int puts(char*); int puts(char*);
int puts1(char*); int puts1(char*);
char* strcpy(char*, char*);