Skip to content

Commit

Permalink
Added logging.c(/h)
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmmera committed Aug 17, 2016
1 parent 9649e76 commit 5a84d97
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 1 deletion.
56 changes: 55 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,58 @@ Debug
CMakeScripts
*.cxx_parameters
shadow

/qucs-core/build-aux/ar-lib
/qucs-core/build-aux/compile
/qucs-core/build-aux/test-driver
/qucs-core/build-aux/ylwrap
/qucs-core/src/components/verilog/DLS_1ton.cpp
/qucs-core/src/components/verilog/DLS_nto1.cpp
/qucs-core/src/components/verilog/EKV26MOS.cpp
/qucs-core/src/components/verilog/MESFET.cpp
/qucs-core/src/components/verilog/andor4x2.cpp
/qucs-core/src/components/verilog/andor4x3.cpp
/qucs-core/src/components/verilog/andor4x4.cpp
/qucs-core/src/components/verilog/binarytogrey4bit.cpp
/qucs-core/src/components/verilog/comp_1bit.cpp
/qucs-core/src/components/verilog/comp_2bit.cpp
/qucs-core/src/components/verilog/comp_4bit.cpp
/qucs-core/src/components/verilog/constants.vams
/qucs-core/src/components/verilog/dff_SR.cpp
/qucs-core/src/components/verilog/disciplines.vams
/qucs-core/src/components/verilog/dmux2to4.cpp
/qucs-core/src/components/verilog/dmux3to8.cpp
/qucs-core/src/components/verilog/dmux4to16.cpp
/qucs-core/src/components/verilog/fa1b.cpp
/qucs-core/src/components/verilog/fa2b.cpp
/qucs-core/src/components/verilog/gatedDlatch.cpp
/qucs-core/src/components/verilog/greytobinary4bit.cpp
/qucs-core/src/components/verilog/ha1b.cpp
/qucs-core/src/components/verilog/hpribin4bit.cpp
/qucs-core/src/components/verilog/jkff_SR.cpp
/qucs-core/src/components/verilog/log_amp.cpp
/qucs-core/src/components/verilog/logic_0.cpp
/qucs-core/src/components/verilog/logic_1.cpp
/qucs-core/src/components/verilog/mod_amp.cpp
/qucs-core/src/components/verilog/mux2to1.cpp
/qucs-core/src/components/verilog/mux4to1.cpp
/qucs-core/src/components/verilog/mux8to1.cpp
/qucs-core/src/components/verilog/nigbt.cpp
/qucs-core/src/components/verilog/pad2bit.cpp
/qucs-core/src/components/verilog/pad3bit.cpp
/qucs-core/src/components/verilog/pad4bit.cpp
/qucs-core/src/components/verilog/photodiode.cpp
/qucs-core/src/components/verilog/phototransistor.cpp
/qucs-core/src/components/verilog/potentiometer.cpp
/qucs-core/src/components/verilog/tff_SR.cpp
/qucs-core/src/components/verilog/vcresistor.cpp
/qucs-core/src/converter/parse_spice.hpp
/qucs-core/src/converter/parse_vcd.hpp
/qucs-core/src/parse_citi.hpp
/qucs-core/src/parse_csv.hpp
/qucs-core/src/parse_dataset.hpp
/qucs-core/src/parse_mdl.hpp
/qucs-core/src/parse_netlist.hpp
/qucs-core/src/parse_touchstone.hpp
/qucs-core/src/parse_zvr.hpp
/qucs/ar-lib
/compile
97 changes: 97 additions & 0 deletions qucs-core/src/logging.c
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");
}
}
44 changes: 44 additions & 0 deletions qucs-core/src/logging.h
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__ */

0 comments on commit 5a84d97

Please sign in to comment.