Update all syscall
And add PutInt() and GetInt()
This commit is contained in:
parent
2b7c7ee780
commit
2a3198c949
7 changed files with 95 additions and 31 deletions
|
@ -37,22 +37,22 @@ int ConsoleDriver::GetChar()
|
|||
return ch;
|
||||
}
|
||||
|
||||
void ConsoleDriver::PutString(const char s[MAX_STRING_SIZE])
|
||||
void ConsoleDriver::PutString(const char s[])
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_STRING_SIZE; i++){
|
||||
if (*(s+i) =='\0'){
|
||||
return;
|
||||
}
|
||||
int i = 0;
|
||||
while (*(s+i) != '\0')
|
||||
{
|
||||
PutChar(*(s+i));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleDriver::GetString(char * s, int n)
|
||||
{
|
||||
int i;
|
||||
for ( i = 0; i < n - 1; i++){
|
||||
for ( i = 0; i < n; i++){
|
||||
char c = GetChar();
|
||||
DEBUG('s', "consoledriver->getstring keycode:%d, position:%d\n", (int)c, i);
|
||||
if ( c == '\0' || c == '\n' || c == EOF) {
|
||||
break;
|
||||
}
|
||||
|
@ -61,4 +61,22 @@ void ConsoleDriver::GetString(char * s, int n)
|
|||
*(s+i) = '\0';
|
||||
}
|
||||
|
||||
void ConsoleDriver::PutInt(int n)
|
||||
{
|
||||
char *buffer = new char[MAX_STRING_SIZE];
|
||||
snprintf(buffer,MAX_STRING_SIZE,"%d",n);
|
||||
DEBUG('s', "consoledriver->PutInt buffer:%s\n", buffer);
|
||||
PutString(buffer);
|
||||
delete [] buffer;
|
||||
}
|
||||
|
||||
int ConsoleDriver::GetInt()
|
||||
{
|
||||
int n;
|
||||
char *buffer = new char[MAX_STRING_SIZE];
|
||||
GetString(buffer,MAX_STRING_SIZE);
|
||||
sscanf(buffer, "%d", &n);
|
||||
delete [] buffer;
|
||||
return n;
|
||||
}
|
||||
#endif // CHANGED
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue