From ae25085d7ecf0ae117b141181989d78c3cd3e365 Mon Sep 17 00:00:00 2001 From: henyxia Date: Mon, 2 Mar 2015 17:09:23 +0100 Subject: [PATCH] Output function done README fixed Makefile adapted --- Makefile | 13 ++++++------- README.md | 2 +- main.c | 15 ++++----------- printx.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ printx.h | 15 +++++++++++++++ 5 files changed, 76 insertions(+), 19 deletions(-) create mode 100644 printx.c create mode 100644 printx.h diff --git a/Makefile b/Makefile index dc48b2d..5c5ef71 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,10 @@ -CC= gcc -CC_FLAGS=-c -Wall -Werror -g -CC_LIBS=$(NFC_PROXMARK_LIB) -INCLUDES=-I../nfc_proxmark3_driver +CC=gcc +CC_FLAGS=-c -Wall -Werror +CC_LIBS= +INCLUDES= -SOURCES=main.c +SOURCES=main.c printx.c OBJECTS=$(SOURCES:.c=.o) -NFC_PROXMARK_LIB=-L../nfc_proxmark3_driver -lnfcproxmark3driver OUTPUT=tweekd all: $(SOURCES) $(OUTPUT) @@ -14,7 +13,7 @@ $(OUTPUT): $(OBJECTS) $(CC) $(OBJECTS) $(CC_LIBS) -o $@ %.o: %.c - $(CC) -c $(INCLUDES) $(CC_FLAGS) $< -o $@ + $(CC) $(INCLUDES) $(CC_FLAGS) $< -o $@ clear: rm -f $(OUTPUT) $(OBJECTS) diff --git a/README.md b/README.md index d33e7f4..d6c1f6a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # tweekd -Tweekd is a projet of an automated coffee dispenser +Tweekd is a project of an automated coffee dispenser diff --git a/main.c b/main.c index 055149e..b283e26 100644 --- a/main.c +++ b/main.c @@ -1,17 +1,10 @@ #include -#include -#include +#include "printx.h" int main(void) { - printf("Tweekd starting\n"); - if(initializeProxmark() != 0) - { - printf("Initialization failed\n"); - return 1; - } - printf("[NFC]\t: HW version\n"); - proxVersion(); - stopProxmark(); + initLog(); + printx(INFO, "Tweekd starting\n"); + closeLog(); return 0; } diff --git a/printx.c b/printx.c new file mode 100644 index 0000000..8185dd9 --- /dev/null +++ b/printx.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +#include +#include "printx.h" + +#define FILENAME_LENGTH 24 +#define S_RESET "\33[0m" +#define MAX_BUFFER 128 + +FILE* logfile = NULL; +char s_color[4][12] = {"\x1b[01;31m", "\x1b[01;33m", "\x1b[01;32m", "\x1b[01;36m"}; + +bool initLog() +{ + char filename[FILENAME_LENGTH]; + time_t now = time(NULL); + + strftime(filename, FILENAME_LENGTH, "log/%F-%T:%d", localtime(&now)); + strcat(filename, ".log"); + + logfile = fopen(filename, "w"); + if(logfile == NULL) + { + printf("Unable to open the log file\n"); + return false; + } + + return true; +} + +void closeLog() +{ + fclose(logfile); +} + +void printx(severity s, char* str, ...) +{ + char buffer[MAX_BUFFER]; + va_list arglist; + va_start(arglist, str); + vsprintf(buffer, str, arglist); + fprintf(logfile, buffer); + printf(s_color[s]); + printf(buffer); + printf(S_RESET); + va_end(arglist); +} diff --git a/printx.h b/printx.h new file mode 100644 index 0000000..bb9ac69 --- /dev/null +++ b/printx.h @@ -0,0 +1,15 @@ +#ifndef __PRINTX_H__ +#define __PRINTX_H__ + +#include + +typedef enum +{ + ERROR, WARNING, INFO, DEBUG +}severity; + +bool initLog(); +void printx(severity, char*, ...); +void closeLog(); + +#endif -- libgit2 0.21.2