My Project
0.0.16
QUCS Mapping
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
DownLoad
QUCS-src
qucs-0.0.16
qucs-core
src
logging.c
Go to the documentation of this file.
1
/*
2
* logging.c - logging facility class implementation
3
*
4
* Copyright (C) 2003, 2004, 2005 Stefan Jahn <stefan@lkcc.org>
5
*
6
* This is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
9
* any later version.
10
*
11
* This software is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this package; see the file COPYING. If not, write to
18
* the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19
* Boston, MA 02110-1301, USA.
20
*
21
* $Id: logging.c 1825 2011-03-11 20:42:14Z ela $
22
*
23
*/
24
25
#if HAVE_CONFIG_H
26
# include <config.h>
27
#endif
28
29
#include <stdio.h>
30
#include <stdlib.h>
31
#include <stdarg.h>
32
33
#include "
logging.h
"
34
35
/* This function prints the given messages format and the appropriate
36
arguments to a FILE stream depending on the given log level. */
37
void
logprint
(
int
level,
const
char
* format, ...) {
38
FILE * f;
39
va_list args;
40
41
f = level ==
LOG_STATUS
?
file_status
:
file_error
;
42
if
(f != NULL) {
43
va_start (args, format);
44
vfprintf (f, format, args);
45
va_end (args);
46
fflush (f);
47
}
48
}
49
50
/* Initialization of the logging interface. */
51
void
loginit
(
void
) {
52
file_error
=
file_status
= stderr;
53
}
54
55
/* Both of the log level dependent FILE streams. */
56
FILE *
file_status
= NULL;
57
FILE *
file_error
= NULL;
58
59
/* Last number of '*' in the progress bar. */
60
int
progressbar_last
= 0;
61
62
/* Print a tiny progress-bar depending on the arguments. */
63
void
logprogressbar
(nr_double_t current, nr_double_t
final
,
int
points) {
64
int
i
;
65
if
(
progressbar_enable
) {
66
if
(((
int
) (current * 100 /
final
)) ==
progressbar_last
&& current)
67
return
;
68
progressbar_last
= (int) (current * 100 /
final
);
69
if
(
progressbar_gui
) {
70
logprint
(
LOG_STATUS
,
"\t%02d\r"
,
progressbar_last
);
71
}
72
else
{
73
logprint
(
LOG_STATUS
,
"["
);
74
for
(i = 0; i < (current * points /
final
); i++)
75
logprint
(
LOG_STATUS
,
"*"
);
76
for
(; i < points; i++)
logprint
(
LOG_STATUS
,
" "
);
77
logprint
(
LOG_STATUS
,
"] %.2f%% \r"
,
78
(
double
) (current * 100.0 /
final
));
79
}
80
}
81
}
82
83
/* If non-zero then progress bars are painted... */
84
int
progressbar_enable
= 0;
85
86
/* If non-zero then progress bars are painted for the GUI. */
87
int
progressbar_gui
= 0;
88
89
/* Clears up the progress bar if requested. */
90
void
logprogressclear
(
int
points) {
91
int
i
;
92
progressbar_last
= 0;
93
if
(
progressbar_enable
&& !
progressbar_gui
) {
94
for
(i = 0; i < points + 15; i++)
logprint
(
LOG_STATUS
,
" "
);
95
logprint
(
LOG_STATUS
,
"\r"
);
96
}
97
}
Generated on Tue Dec 25 2012 14:30:34 for My Project by
1.8.2