mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-02 21:54:10 +08:00
PrintAndLogEx supports multi-line messages
This commit is contained in:
parent
bba3e3f35a
commit
d8f0863a2a
1 changed files with 27 additions and 12 deletions
39
client/ui.c
39
client/ui.c
|
@ -29,34 +29,49 @@ void PrintAndLogEx(logLevel_t level, char *fmt, ...) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char buffer[MAX_PRINT_BUFFER] = {0};
|
char buffer[MAX_PRINT_BUFFER] = {0};
|
||||||
|
char buffer2[MAX_PRINT_BUFFER] = {0};
|
||||||
|
char prefix[20] = {0};
|
||||||
|
char *token = NULL;
|
||||||
int size = 0;
|
int size = 0;
|
||||||
// {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG}
|
// {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG}
|
||||||
static char *prefix[7] = { "", "[+] ", "[=] ", "[-] ", "[!] ", "[!!] ", "[#] "};
|
static char *prefixes[7] = { "", "[+] ", "[=] ", "[-] ", "[!] ", "[!!] ", "[#] "};
|
||||||
|
|
||||||
switch( level ) {
|
switch( level ) {
|
||||||
case FAILED:
|
case FAILED:
|
||||||
size = strlen( _RED_([-] ) );
|
strncpy(prefix,_RED_([-] ), sizeof(prefix)-1);
|
||||||
strncpy(buffer,_RED_([-] ), size);
|
|
||||||
break;
|
break;
|
||||||
case DEBUG:
|
case DEBUG:
|
||||||
size = strlen( _BLUE_([#] ) );
|
strncpy(prefix,_BLUE_([#] ), sizeof(prefix)-1);
|
||||||
strncpy(buffer,_BLUE_([#] ), size);
|
|
||||||
break;
|
break;
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
size = strlen( _GREEN_([+] ) );
|
strncpy(prefix,_GREEN_([+] ), sizeof(prefix)-1);
|
||||||
strncpy(buffer,_GREEN_([+] ), size);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
size = strlen(prefix[level]);
|
strncpy(prefix, prefixes[level], sizeof(buffer)-1);
|
||||||
strncpy(buffer, prefix[level], sizeof buffer);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args,fmt);
|
va_start(args, fmt);
|
||||||
vsnprintf(buffer + size, sizeof(buffer) - size, fmt, args);
|
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
PrintAndLog(buffer);
|
|
||||||
|
if(strchr(buffer, '\n'))
|
||||||
|
{
|
||||||
|
token = strtok(buffer,"\n");
|
||||||
|
while (token != NULL)
|
||||||
|
{
|
||||||
|
size=strlen(buffer2);
|
||||||
|
if(strlen(token))
|
||||||
|
snprintf(buffer2+size, sizeof(buffer2)-size, "%s%s\n", prefix, token);
|
||||||
|
else
|
||||||
|
snprintf(buffer2+size, sizeof(buffer2)-size, "\n");
|
||||||
|
token = strtok(NULL, "\n");
|
||||||
|
}
|
||||||
|
PrintAndLog(buffer2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
PrintAndLog(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintAndLog(char *fmt, ...) {
|
void PrintAndLog(char *fmt, ...) {
|
||||||
|
|
Loading…
Reference in a new issue