Fix commandCallHanler
parent
47948489ed
commit
250c2b868b
15
include/ui.h
15
include/ui.h
|
@ -9,10 +9,16 @@
|
||||||
|
|
||||||
#define MAX_COMMAND_LEN 200
|
#define MAX_COMMAND_LEN 200
|
||||||
|
|
||||||
|
void clearExtraInput()
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
while ((c = getchar()) != '\n' && c != EOF) {}
|
||||||
|
}
|
||||||
|
|
||||||
int getString(char* str, const int size)
|
int getString(char* str, const int size)
|
||||||
{
|
{
|
||||||
char* buf = (char*) malloc(size + 1);
|
char* buf = (char*) malloc(size + 1);
|
||||||
if (gets(buf) == NULL)
|
if (fgets(buf, size, stdin) == NULL)
|
||||||
{
|
{
|
||||||
return GETSTRING_ERR_RE;
|
return GETSTRING_ERR_RE;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +34,7 @@ int getString(char* str, const int size)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int commandCallHandler()
|
char* commandCallHandler()
|
||||||
{
|
{
|
||||||
char* command = (char*) malloc(MAX_COMMAND_LEN);
|
char* command = (char*) malloc(MAX_COMMAND_LEN);
|
||||||
char* buf = (char*) malloc(MAX_COMMAND_LEN);
|
char* buf = (char*) malloc(MAX_COMMAND_LEN);
|
||||||
|
@ -37,11 +43,12 @@ int commandCallHandler()
|
||||||
result = getString(command, MAX_COMMAND_LEN-1);
|
result = getString(command, MAX_COMMAND_LEN-1);
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
// Разбиваем на лексемы и обрабатываем команду
|
strcpy(buf, command);
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue