diff --git a/seriell/Makefile b/seriell/Makefile index 4a0e201..7ff4fa2 100644 --- a/seriell/Makefile +++ b/seriell/Makefile @@ -16,26 +16,32 @@ all: $(BIN_NAME) $(BIN_NAME): main.o config.o input.o process.o write.o - $(LD) $(DEBUG) -L/usr/lib/pgsql -lpq $(LDFLAS) $(BIN_NAME) main.o input.o process.o write.o config.o + $(LD) $(DEBUG) $(NOLOG) -L/usr/lib/pgsql -lpq $(LDFLAS) $(BIN_NAME) main.o input.o process.o write.o config.o main.o: main.c main.h definitions.h config.h input.h - $(CC) $(DEBUG) -c main.c + $(CC) $(DEBUG) $(NOLOG) $(CFLAGS) main.c config.o: config.c config.h definitions.h - $(CC) $(DEBUG) -c config.c + $(CC) $(DEBUG) $(NOLOG) $(CFLAGS) config.c input.o: input.c input.h main.h config.h definitions.h process.h - $(CC) $(DEBUG) -c input.c + $(CC) $(DEBUG) $(NOLOG) $(CFLAGS) input.c process.o: process.c process.h main.h config.h definitions.h write.h - $(CC) $(DEBUG) -c process.c + $(CC) $(DEBUG) $(NOLOG) $(CFLAGS) process.c write.o: write.c write.h main.h definitions.h - $(CC) $(DEBUG) -I/usr/include/postgresql -o write.o -c write.c + $(CC) $(DEBUG) $(NOLOG) -I/usr/include/postgresql $(CFLAGS) write.c +# Programm mit debug-ausgabe bauen debug: $(MAKE) all DEBUG=-DDEBUG +# Programm ohne Log-ausgabe bauen +nolog: + $(MAKE) all NOLOG=-DNO_LOGING + +# Aufräumnen (alle Object-Files löschen) cleanup: echo "Räume auf...entferne:" echo " " *.o diff --git a/seriell/config.c b/seriell/config.c index 723826d..471949d 100644 --- a/seriell/config.c +++ b/seriell/config.c @@ -47,10 +47,12 @@ static int flag_handler(int *, int , const char *); static const struct config_keyword keywords[] = { /* keyword handler variable address default */ {"interface", read_str, &(global_opts.device), DEFAULT_SERIAL_PORT}, + #ifndef NO_LOGING {"log_data", read_log_data_flag, &(global_opts.flags), "no"}, {"log_error", read_log_error_flag, &(global_opts.flags), "no"}, {"data_file", read_str, &(global_opts.data_log), DEFAULT_DATA_FILE}, {"error_file", read_str, &(global_opts.error_log), DEFAULT_ERROR_FILE}, + #endif {"foreground", read_foreground_flag, &(global_opts.flags), "no"}, {"verbose", read_verbose_flag, &(global_opts.flags), "no"}, {"pg_host", read_str, &(global_opts.pg_host), DEFAULT_PG_HOST}, @@ -74,6 +76,7 @@ static int read_str(const char *line, void *arg){ /* Die 4 Funktionen reichen jeweils nur die Daten an den * flag_handler durch und teilen diesem noch das Flag * mit, was er setzen soll (oder nicht) */ +#ifndef NO_LOGING static read_log_data_flag(const char *line, void *arg){ return flag_handler(arg, LOG_DATA_FLAG, line); } @@ -81,6 +84,7 @@ static read_log_data_flag(const char *line, void *arg){ static read_log_error_flag(const char *line, void *arg){ return flag_handler(arg, LOG_ERROR_FLAG, line); } +#endif static read_foreground_flag(const char *line, void *arg){ return flag_handler(arg, FOREGROUND_FLAG, line); diff --git a/seriell/definitions.h b/seriell/definitions.h index b0e55ee..159b51d 100644 --- a/seriell/definitions.h +++ b/seriell/definitions.h @@ -60,10 +60,12 @@ /* Parameter-Flags ----------------------------------------------------- */ -#define LOG_ERROR_FLAG 0x01 -#define LOG_DATA_FLAG 0x02 -#define FOREGROUND_FLAG 0x04 -#define VERBOSE_FLAG 0x08 +#define FOREGROUND_FLAG 0x01 +#define VERBOSE_FLAG 0x02 +#ifndef NO_LOGING + #define LOG_ERROR_FLAG 0x04 + #define LOG_DATA_FLAG 0x08 +#endif /* Puffergrößen -------------------------------------------------------- */ diff --git a/seriell/main.c b/seriell/main.c index 51337ea..916005a 100644 --- a/seriell/main.c +++ b/seriell/main.c @@ -163,10 +163,12 @@ static void background(){ static void merge_options(w_opts *priv){ if((*priv).device != NULL) global_opts.device = (*priv).device; + #ifndef NO_LOGING if((*priv).data_log != NULL) global_opts.data_log = (*priv).data_log; if((*priv).error_log != NULL) global_opts.error_log = (*priv).error_log; + #endif global_opts.flags |= (*priv).flags; } diff --git a/seriell/write.c b/seriell/write.c index 1ca8cec..fd4d306 100644 --- a/seriell/write.c +++ b/seriell/write.c @@ -126,8 +126,10 @@ static int pg_connect(){ } if(PQstatus(connection) != CONNECTION_OK){ DEBUGOUT2("\nFehler beim Aufbau der Datenbankverbindung\n%s\n", PQerrorMessage(connection)); + #ifndef NO_LOGING snprintf(get_error_buffer(), ERR_BUFFERSIZE, "Fehler beim Aufbau der Datenbankverbindung: %s", PQerrorMessage(connection)); log_error(get_error_buffer()); + #endif return 0; } DEBUGOUT1("\nDatenbankverbindung erfolgreich hergestellt\n"); @@ -141,8 +143,10 @@ static void pg_insert(char *query){ res = PQexec(connection, query); if(!res || PQresultStatus(res) != PGRES_COMMAND_OK){ DEBUGOUT2("Fehler beim INSERT: %s\n", query); + #ifndef NO_LOGING snprintf(get_error_buffer(), ERR_BUFFERSIZE, "Fehler beim INSERT: %s", query); log_error(get_error_buffer()); + #endif } else { DEBUGOUT2("Query: '%s' ausgeführt\n", query); }