diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 54c2b99a6..b1adaeca2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,6 +45,7 @@ add_library(aseprite-library gfxmode.cpp job.cpp launcher.cpp + log.cpp recent_files.cpp resource_finder.cpp ui_context.cpp diff --git a/src/app.cpp b/src/app.cpp index 88d38733d..ab013f1d5 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -46,6 +46,7 @@ #include "core/modules.h" #include "file/file.h" #include "intl/intl.h" +#include "log.h" #include "modules/editors.h" #include "modules/gfx.h" #include "modules/gui.h" diff --git a/src/core/core.cpp b/src/core/core.cpp index 8956871c0..0cd268432 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -18,27 +18,7 @@ #include "config.h" -#include -#include -#include -#include -#include -#include - -#include "jinete/jbase.h" - #include "core/core.h" -#include "resource_finder.h" - -/* DOS and Windows needs "log" files (because their poor stderr support) */ -#if defined ALLEGRO_DOS || defined ALLEGRO_WINDOWS -# define NEED_LOG -#endif - -/* in DOS, print in stderr is like print in the video screen */ -#if defined ALLEGRO_DOS -# define NO_STDERR -#endif /** * Current running mode of ASE. @@ -47,67 +27,6 @@ */ int ase_mode = 0; -#ifdef NEED_LOG -/* log file info */ -static std::string log_filename; -static FILE *log_fileptr = NULL; -#endif - -LoggerModule::LoggerModule() -{ - PRINTF("Logger module: starting\n"); - -#ifdef NEED_LOG - ResourceFinder rf; - rf.findInBinDir("aseprite.log"); - log_filename = rf.first(); -#endif - - PRINTF("Logger module: started\n"); -} - -LoggerModule::~LoggerModule() -{ - PRINTF("Logger module: shutting down (this is the last line)\n"); - -#ifdef NEED_LOG - if (log_fileptr) { - fclose(log_fileptr); - log_fileptr = NULL; - } -#endif -} - -void verbose_printf(const char *format, ...) -{ - if (!(ase_mode & MODE_VERBOSE)) - return; - -#ifdef NEED_LOG - if (!log_fileptr) - if (log_filename.size() > 0) - log_fileptr = fopen(log_filename.c_str(), "w"); - - if (log_fileptr) -#endif - { - va_list ap; - va_start(ap, format); - -#ifndef NO_STDERR - vfprintf(stderr, format, ap); - fflush(stderr); -#endif - -#ifdef NEED_LOG - vfprintf(log_fileptr, format, ap); - fflush(log_fileptr); -#endif - - va_end(ap); - } -} - /** * Returns true if the application is running in interactive mode (GUI). * diff --git a/src/core/core.h b/src/core/core.h index f4c569ec7..5f3efc741 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -19,8 +19,6 @@ #ifndef CORE_CORE_H_INCLUDED #define CORE_CORE_H_INCLUDED -#include "jinete/jbase.h" - enum { MODE_VERBOSE = 1, /* verbose mode status */ MODE_BATCH = 2, /* batch mode */ @@ -29,14 +27,6 @@ enum { extern int ase_mode; -class LoggerModule -{ -public: - LoggerModule(); - ~LoggerModule(); -}; - -void verbose_printf(const char *format, ...); bool is_interactive(); #endif diff --git a/src/log.cpp b/src/log.cpp new file mode 100644 index 000000000..d245a6a0f --- /dev/null +++ b/src/log.cpp @@ -0,0 +1,103 @@ +/* ASE - Allegro Sprite Editor + * Copyright (C) 2001-2010 David Capello + * + * This program 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 Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include + +#include "jinete/jbase.h" + +#include "core/core.h" +#include "log.h" +#include "resource_finder.h" + +/* DOS and Windows needs "log" files (because their poor stderr support) */ +#if defined ALLEGRO_DOS || defined ALLEGRO_WINDOWS +# define NEED_LOG +#endif + +/* in DOS, print in stderr is like print in the video screen */ +#if defined ALLEGRO_DOS +# define NO_STDERR +#endif + +#ifdef NEED_LOG +/* log file info */ +static std::string log_filename; +static FILE *log_fileptr = NULL; +#endif + +LoggerModule::LoggerModule() +{ + PRINTF("Logger module: starting\n"); + +#ifdef NEED_LOG + ResourceFinder rf; + rf.findInBinDir("aseprite.log"); + log_filename = rf.first(); +#endif + + PRINTF("Logger module: started\n"); +} + +LoggerModule::~LoggerModule() +{ + PRINTF("Logger module: shutting down (this is the last line)\n"); + +#ifdef NEED_LOG + if (log_fileptr) { + fclose(log_fileptr); + log_fileptr = NULL; + } +#endif +} + +void verbose_printf(const char *format, ...) +{ + if (!(ase_mode & MODE_VERBOSE)) + return; + +#ifdef NEED_LOG + if (!log_fileptr) + if (log_filename.size() > 0) + log_fileptr = fopen(log_filename.c_str(), "w"); + + if (log_fileptr) +#endif + { + va_list ap; + va_start(ap, format); + +#ifndef NO_STDERR + vfprintf(stderr, format, ap); + fflush(stderr); +#endif + +#ifdef NEED_LOG + vfprintf(log_fileptr, format, ap); + fflush(log_fileptr); +#endif + + va_end(ap); + } +} diff --git a/src/log.h b/src/log.h new file mode 100644 index 000000000..2c008913f --- /dev/null +++ b/src/log.h @@ -0,0 +1,31 @@ +/* ASE - Allegro Sprite Editor + * Copyright (C) 2001-2010 David Capello + * + * This program 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 Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef LOG_H_INCLUDED +#define LOG_H_INCLUDED + +class LoggerModule +{ +public: + LoggerModule(); + ~LoggerModule(); +}; + +void verbose_printf(const char* format, ...); + +#endif