From 5ea8b4348c46ddb6332cbb083aec201efc267242 Mon Sep 17 00:00:00 2001 From: Brian Pow Date: Thu, 15 Feb 2018 23:32:08 +0800 Subject: [PATCH 1/2] add PrintAndLogEx() --- client/ui.c | 19 +++++++++++++++++++ client/ui.h | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/client/ui.c b/client/ui.c index 56101cd80..d0ed5d11e 100644 --- a/client/ui.c +++ b/client/ui.c @@ -22,6 +22,25 @@ bool showDemod = true; pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER; static char *logfilename = "proxmark3.log"; +void PrintAndLogEx(logLevel_t level, char *filename, int lineno, char *func, char *fmt, ...) { + char buffer[MAX_PRINT_BUFFER] = {0}; + int size; + static char *prefix[5]; + prefix[0]=""; + prefix[1]=" [+] "; + prefix[2]=" [!] "; + prefix[3]=" [!!] "; + prefix[4]=" [#] "; + size=strlen(prefix[level]); + strncpy(buffer, prefix[level], MAX_PRINT_BUFFER); + + va_list args; + va_start(args,fmt); + vsprintf(buffer + size,fmt, args); + va_end(args); + PrintAndLog(buffer); +} + void PrintAndLog(char *fmt, ...) { char *saved_line; int saved_point; diff --git a/client/ui.h b/client/ui.h index 5c50b55db..6d554d3fc 100644 --- a/client/ui.h +++ b/client/ui.h @@ -28,11 +28,15 @@ #ifndef M_PI #define M_PI 3.14159265358979323846264338327 #endif +#define MAX_PRINT_BUFFER 2048 +typedef enum logLevel {NORMAL, INFO, WARNING, ERR, DEBUG} logLevel_t; + void ShowGui(void); void HideGraphWindow(void); void ShowGraphWindow(void); void RepaintGraphWindow(void); extern void PrintAndLog(char *fmt, ...); +void PrintAndLogEx(logLevel_t level, char *filename, int lineno, char *func, char *fmt, ...); extern void SetLogFilename(char *fn); extern double CursorScaleFactor; From 68fddf00ce30f8b993278db0c6d6d6bb7c811af9 Mon Sep 17 00:00:00 2001 From: Brian Pow Date: Wed, 21 Feb 2018 14:10:44 +0800 Subject: [PATCH 2/2] simplify PrintAndLogEx() --- client/ui.c | 14 +++++--------- client/ui.h | 4 ++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/client/ui.c b/client/ui.c index d0ed5d11e..31529a63f 100644 --- a/client/ui.c +++ b/client/ui.c @@ -22,21 +22,17 @@ bool showDemod = true; pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER; static char *logfilename = "proxmark3.log"; -void PrintAndLogEx(logLevel_t level, char *filename, int lineno, char *func, char *fmt, ...) { +void PrintAndLogEx(logLevel_t level, char *fmt, ...) { char buffer[MAX_PRINT_BUFFER] = {0}; int size; - static char *prefix[5]; - prefix[0]=""; - prefix[1]=" [+] "; - prefix[2]=" [!] "; - prefix[3]=" [!!] "; - prefix[4]=" [#] "; + static char *prefix[7] = { "", "[+] ", "[=] ", "[-] ", "[!] ", "[!!] ", "[#] "}; + size=strlen(prefix[level]); - strncpy(buffer, prefix[level], MAX_PRINT_BUFFER); + strncpy(buffer, prefix[level], sizeof buffer); va_list args; va_start(args,fmt); - vsprintf(buffer + size,fmt, args); + vsnprintf(buffer + size, sizeof(buffer) - size, fmt, args); va_end(args); PrintAndLog(buffer); } diff --git a/client/ui.h b/client/ui.h index 6d554d3fc..83669d1d1 100644 --- a/client/ui.h +++ b/client/ui.h @@ -29,14 +29,14 @@ #define M_PI 3.14159265358979323846264338327 #endif #define MAX_PRINT_BUFFER 2048 -typedef enum logLevel {NORMAL, INFO, WARNING, ERR, DEBUG} logLevel_t; +typedef enum logLevel {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG} logLevel_t; void ShowGui(void); void HideGraphWindow(void); void ShowGraphWindow(void); void RepaintGraphWindow(void); extern void PrintAndLog(char *fmt, ...); -void PrintAndLogEx(logLevel_t level, char *filename, int lineno, char *func, char *fmt, ...); +void PrintAndLogEx(logLevel_t level, char *fmt, ...); extern void SetLogFilename(char *fn); extern double CursorScaleFactor;