From 5da0354257cbf1ba49fd92be0ed572c2200fba3d Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 28 Jul 2012 17:32:30 +0200 Subject: [PATCH] Make logging defines reusable by Salamander without having to include general.h (full of dependencies which can't be met for standalone app) --- Makefile.ps3.salamander | 4 +- Makefile.wii | 8 ++-- console/logger/logger_override.h | 52 +++++++++++++++++++++++-- console/salamander/main.c | 23 +---------- general.h | 28 +------------ msvc/msvc-71/logger_override.h | 12 ++++++ retroarch_logger.h | 67 ++++++++++++++++++++++++++++++++ 7 files changed, 137 insertions(+), 57 deletions(-) create mode 100644 retroarch_logger.h diff --git a/Makefile.ps3.salamander b/Makefile.ps3.salamander index 751a82235a..e3acc41ba6 100644 --- a/Makefile.ps3.salamander +++ b/Makefile.ps3.salamander @@ -7,11 +7,11 @@ include $(CELL_MK_DIR)/sdk.makedef.mk STRIP = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-strip.exe -PPU_CFLAGS += -I. -D__CELLOS_LV2__ +PPU_CFLAGS += -I. -D__CELLOS_LV2__ -DIS_SALAMANDER PPU_SRCS = console/salamander/main.c file_path.c compat/compat.c conf/config_file.c ifeq ($(HAVE_LOGGER), 1) -PPU_CFLAGS += -DHAVE_LOGGER +PPU_CFLAGS += -DHAVE_LOGGER -Iconsole/logger PPU_SRCS += console/logger/logger.c endif diff --git a/Makefile.wii b/Makefile.wii index 4739e4dd0e..f5b0b0ddf5 100644 --- a/Makefile.wii +++ b/Makefile.wii @@ -31,13 +31,15 @@ OBJ = console/griffin/griffin.o console/font.bmpobj console/rzlib/rzlib.o ifeq ($(HAVE_LOGGER), 1) CFLAGS += -DHAVE_LOGGER CFLAGS += -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) -CFLAGS += -Iconsole/logger -CXXFLAGS += -Iconsole/logger -OBJ += console/logger/logger.o +CFLAGS += -Iconsole/logger +CXXFLAGS += -Iconsole/logger +OBJ += console/logger/logger.o endif ifeq ($(HAVE_FILE_LOGGER), 1) CFLAGS += -DHAVE_FILE_LOGGER +CFLAGS += -Iconsole/logger +CXXFLAGS += -Iconsole/logger endif CFLAGS += -std=gnu99 -DHAVE_DEFAULT_RETROPAD_INPUT -DRARCH_CONSOLE -DHAVE_CONFIGFILE=1 -DGEKKO -DHW_RVL -DHAVE_ZLIB -DHAVE_RARCH_MAIN_WRAP -DHAVE_GRIFFIN=1 -DPACKAGE_VERSION=\"0.9.6\" -Dmain=rarch_main -Wno-char-subscripts diff --git a/console/logger/logger_override.h b/console/logger/logger_override.h index 0cf84278ed..46601fd351 100644 --- a/console/logger/logger_override.h +++ b/console/logger/logger_override.h @@ -18,10 +18,26 @@ #define __RARCH_LOGGER_OVERRIDE_H #if defined(HAVE_LOGGER) -#include "console/logger/logger.h" +#include "logger.h" + +#ifdef IS_SALAMANDER #define RARCH_LOG(...) do { \ - if (g_extern.verbose) logger_send("RetroArch: " __VA_ARGS__); \ + logger_send("RetroArch Salamander: " __VA_ARGS__); \ +} while(0) + +#define RARCH_ERR(...) do { \ + logger_send("RetroArch Salamander [ERROR] :: " __VA_ARGS__); \ +} while(0) + +#define RARCH_WARN(...) do { \ + logger_send("RetroArch Salamander [WARN] :: " __VA_ARGS__); \ +} while(0) + +#else + +#define RARCH_LOG(...) do { \ + logger_send("RetroArch: " __VA_ARGS__); \ } while(0) #define RARCH_ERR(...) do { \ @@ -31,11 +47,39 @@ #define RARCH_WARN(...) do { \ logger_send("RetroArch [WARN] :: " __VA_ARGS__); \ } while(0) + +#endif + #elif defined(HAVE_FILE_LOGGER) extern FILE * log_fp; + +#ifdef IS_SALAMANDER + +#ifndef RARCH_LOG +#define RARCH_LOG(...) do { \ + fprintf(log_fp, "RetroArch Salamander: " __VA_ARGS__); \ + fflush(log_fp); \ + } while (0) +#endif + +#ifndef RARCH_ERR +#define RARCH_ERR(...) do { \ + fprintf(log_fp, "RetroArch Salamander [ERROR] :: " __VA_ARGS__); \ + fflush(log_fp); \ + } while (0) +#endif + +#ifndef RARCH_WARN +#define RARCH_WARN(...) do { \ + fprintf(log_fp, "RetroArch Salamander [WARN] :: " __VA_ARGS__); \ + fflush(log_fp); \ + } while (0) +#endif + +#else + #ifndef RARCH_LOG #define RARCH_LOG(...) do { \ - if (g_extern.verbose) \ fprintf(log_fp, "RetroArch: " __VA_ARGS__); \ fflush(log_fp); \ } while (0) @@ -58,3 +102,5 @@ extern FILE * log_fp; #endif #endif + +#endif diff --git a/console/salamander/main.c b/console/salamander/main.c index cfd179e603..294b7b3a83 100644 --- a/console/salamander/main.c +++ b/console/salamander/main.c @@ -44,28 +44,7 @@ #define PATH_MAX 512 #endif -#ifdef HAVE_LOGGER -#include "logger.h" -#define RARCH_LOG(...) logger_send("RetroArch Salamander: " __VA_ARGS__); -#define RARCH_ERR(...) logger_send("RetroArch Salamander [ERROR] :: " __VA_ARGS__); -#define RARCH_WARN(...) logger_send("RetroArch Salamander [WARN] :: " __VA_ARGS__); -#else -#define RARCH_LOG(...) do { \ - fprintf(stderr, "RetroArch Salamander: " __VA_ARGS__); \ - fflush(stderr); \ - } while (0) - -#define RARCH_ERR(...) do { \ - fprintf(stderr, "RetroArch Salamander [ERROR] :: " __VA_ARGS__); \ - fflush(stderr); \ - } while (0) - -#define RARCH_WARN(...) do { \ - fprintf(stderr, "RetroArch Salamander [WARN] :: " __VA_ARGS__); \ - fflush(stderr); \ - } while (0) -#endif - +#include "../../retroarch_logger.h" #include "../../file.h" #if defined(__CELLOS_LV2__) diff --git a/general.h b/general.h index 2eb5a77430..ec7c118a36 100644 --- a/general.h +++ b/general.h @@ -13,7 +13,6 @@ * If not, see . */ - #ifndef __RARCH_GENERAL_H #define __RARCH_GENERAL_H @@ -506,32 +505,7 @@ extern struct console_settings g_console; #endif ///////// -#if defined(RARCH_CONSOLE) && (defined(HAVE_LOGGER) || defined(HAVE_FILE_LOGGER) || defined(_XBOX1)) -#include -#else - -#ifndef RARCH_LOG -#define RARCH_LOG(...) do { \ - if (g_extern.verbose) \ - fprintf(stderr, "RetroArch: " __VA_ARGS__); \ - fflush(stderr); \ - } while (0) -#endif - -#ifndef RARCH_ERR -#define RARCH_ERR(...) do { \ - fprintf(stderr, "RetroArch [ERROR] :: " __VA_ARGS__); \ - fflush(stderr); \ - } while (0) -#endif - -#ifndef RARCH_WARN -#define RARCH_WARN(...) do { \ - fprintf(stderr, "RetroArch [WARN] :: " __VA_ARGS__); \ - fflush(stderr); \ - } while (0) -#endif -#endif +#include "retroarch_logger.h" #ifndef max #define max(a, b) ((a) > (b) ? (a) : (b)) diff --git a/msvc/msvc-71/logger_override.h b/msvc/msvc-71/logger_override.h index 71b716c496..a9999b8978 100644 --- a/msvc/msvc-71/logger_override.h +++ b/msvc/msvc-71/logger_override.h @@ -22,7 +22,11 @@ static inline void RARCH_LOG(const char *msg, ...) { char msg_new[1024], buffer[1024]; +#ifdef IS_SALAMANDER + snprintf(msg_new, sizeof(msg_new), "RetroArch Salamander: %s", msg); +#else snprintf(msg_new, sizeof(msg_new), "RetroArch: %s", msg); +#endif va_list ap; va_start(ap, msg); wvsprintf(buffer, msg_new, ap); @@ -33,7 +37,11 @@ static inline void RARCH_LOG(const char *msg, ...) static inline void RARCH_WARN(const char *msg, ...) { char msg_new[1024], buffer[1024]; +#ifdef IS_SALAMANDER + snprintf(msg_new, sizeof(msg_new), "RetroArch Salamander [WARN] :: %s", msg); +#else snprintf(msg_new, sizeof(msg_new), "RetroArch [WARN] :: %s", msg); +#endif va_list ap; va_start(ap, msg); wvsprintf(buffer, msg_new, ap); @@ -44,7 +52,11 @@ static inline void RARCH_WARN(const char *msg, ...) static inline void RARCH_ERR(const char *msg, ...) { char msg_new[1024], buffer[1024]; +#ifdef IS_SALAMANDER + snprintf(msg_new, sizeof(msg_new), "RetroArch Salamander [ERR] :: %s", msg); +#else snprintf(msg_new, sizeof(msg_new), "RetroArch [ERR] :: %s", msg); +#endif va_list ap; va_start(ap, msg); wvsprintf(buffer, msg_new, ap); diff --git a/retroarch_logger.h b/retroarch_logger.h new file mode 100644 index 0000000000..cbca98e8b0 --- /dev/null +++ b/retroarch_logger.h @@ -0,0 +1,67 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef __RARCH_LOGGER_H +#define __RARCH_LOGGER_H + +#if defined(RARCH_CONSOLE) && (defined(HAVE_LOGGER) || defined(HAVE_FILE_LOGGER) || defined(_XBOX1)) +#include +#else + +#ifndef RARCH_LOG +#ifdef IS_SALAMANDER +#define RARCH_LOG(...) do { \ + fprintf(stderr, "RetroArch Salamander: " __VA_ARGS__); \ + fflush(stderr); \ + } while (0) +#else +#define RARCH_LOG(...) do { \ + fprintf(stderr, "RetroArch: " __VA_ARGS__); \ + fflush(stderr); \ + } while (0) +#endif +#endif + +#ifndef RARCH_ERR +#ifdef IS_SALAMANDER +#define RARCH_ERR(...) do { \ + fprintf(stderr, "RetroArch Salamander [ERROR] :: " __VA_ARGS__); \ + fflush(stderr); \ + } while (0) +#else +#define RARCH_ERR(...) do { \ + fprintf(stderr, "RetroArch [ERROR] :: " __VA_ARGS__); \ + fflush(stderr); \ + } while (0) +#endif +#endif + +#ifndef RARCH_WARN +#ifdef IS_SALAMANDER +#define RARCH_WARN(...) do { \ + fprintf(stderr, "RetroArch Salamander [WARN] :: " __VA_ARGS__); \ + fflush(stderr); \ + } while (0) +#else +#define RARCH_WARN(...) do { \ + fprintf(stderr, "RetroArch [WARN] :: " __VA_ARGS__); \ + fflush(stderr); \ + } while (0) +#endif +#endif +#endif + +#endif