-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
andresmmera
committed
Aug 17, 2016
1 parent
9649e76
commit 5a84d97
Showing
3 changed files
with
196 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* logging.c - logging facility class implementation | ||
* | ||
* Copyright (C) 2003, 2004, 2005 Stefan Jahn <stefan@lkcc.org> | ||
* | ||
* This 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, or (at your option) | ||
* any later version. | ||
* | ||
* This software 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 package; see the file COPYING. If not, write to | ||
* the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
* | ||
* $Id$ | ||
* | ||
*/ | ||
|
||
#if HAVE_CONFIG_H | ||
# include <config.h> | ||
#endif | ||
|
||
|
||
#include <stdlib.h> | ||
#include <stdarg.h> | ||
|
||
#include "logging.h" | ||
|
||
/* This function prints the given messages format and the appropriate | ||
arguments to a FILE stream depending on the given log level. */ | ||
void logprint (int level, const char * format, ...) { | ||
FILE * f; | ||
va_list args; | ||
|
||
f = level == LOG_STATUS ? file_status : file_error; | ||
if (f != NULL) { | ||
va_start (args, format); | ||
vfprintf (f, format, args); | ||
va_end (args); | ||
fflush (f); | ||
} | ||
} | ||
|
||
/* Initialization of the logging interface. */ | ||
void loginit (void) { | ||
file_error = file_status = stderr; | ||
} | ||
|
||
/* Both of the log level dependent FILE streams. */ | ||
FILE * file_status = NULL; | ||
FILE * file_error = NULL; | ||
|
||
/* Last number of '*' in the progress bar. */ | ||
int progressbar_last = 0; | ||
|
||
/* Print a tiny progress-bar depending on the arguments. */ | ||
void logprogressbar (nr_double_t current, nr_double_t final, int points) { | ||
int i; | ||
if (progressbar_enable) { | ||
if (((int) (current * 100 / final)) == progressbar_last && current) | ||
return; | ||
progressbar_last = (int) (current * 100 / final); | ||
if (progressbar_gui) { | ||
logprint (LOG_STATUS, "\t%02d\r", progressbar_last); | ||
} | ||
else { | ||
logprint (LOG_STATUS, "["); | ||
for (i = 0; i < (current * points / final); i++) | ||
logprint (LOG_STATUS, "*"); | ||
for (; i < points; i++) logprint (LOG_STATUS, " "); | ||
logprint (LOG_STATUS, "] %.2f%% \r", | ||
(double) (current * 100.0 / final)); | ||
} | ||
} | ||
} | ||
|
||
/* If non-zero then progress bars are painted... */ | ||
int progressbar_enable = 0; | ||
|
||
/* If non-zero then progress bars are painted for the GUI. */ | ||
int progressbar_gui = 0; | ||
|
||
/* Clears up the progress bar if requested. */ | ||
void logprogressclear (int points) { | ||
int i; | ||
progressbar_last = 0; | ||
if (progressbar_enable && !progressbar_gui) { | ||
for (i = 0; i < points + 15; i++) logprint (LOG_STATUS, " "); | ||
logprint (LOG_STATUS, "\r"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* logging.h - logging facility class definitions | ||
* | ||
* Copyright (C) 2003, 2005 Stefan Jahn <stefan@lkcc.org> | ||
* | ||
* This 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, or (at your option) | ||
* any later version. | ||
* | ||
* This software 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 package; see the file COPYING. If not, write to | ||
* the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
* | ||
* $Id$ | ||
* | ||
*/ | ||
|
||
#ifndef __LOGGING_H__ | ||
#define __LOGGING_H__ | ||
|
||
#define LOG_ERROR 0 | ||
#define LOG_STATUS 1 | ||
#include <stdio.h> | ||
__BEGIN_DECLS | ||
|
||
void logprint (int, const char *, ...); | ||
void loginit (void); | ||
void logprogressbar (nr_double_t, nr_double_t, int); | ||
void logprogressclear (int); | ||
extern FILE * file_status; | ||
extern FILE * file_error; | ||
extern int progressbar_enable; | ||
extern int progressbar_gui; | ||
|
||
__END_DECLS | ||
|
||
#endif /* __LOGGING_H__ */ |