"Fossies" - the Fresh Open Source Software Archive 
Member "FunctionCheck-3.2.0/src/share/fc_tools.c" (26 May 2012, 3878 Bytes) of package /linux/privat/old/FunctionCheck-3.2.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*
2 * FunctionCheck profiler
3 * (C) Copyright 2000-2012 Yannick Perret
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 /* fc_tools: various tools for the lib part of functioncheck
21 in particular for outputs
22 */
23
24 /** includes **/
25 #include "fc_tools.h"
26 #include "fc_global.h"
27 #include <string.h>
28
29 /** table of strings for errors **/
30 char *fc_error_str[] = {
31 "OK", "'exec*' error", "'fork' error", "memory error",
32 "'pipe' error", "reading error", "writing error",
33 "'close' error", "thread error", "time error",
34 "undefined error",
35 "bad arguments", "hash table error", "stack error",
36 "fopen error", "bad header", "unexpected end of file",
37 "overflow error",
38 };
39
40 char *fc_error_ndef = "bad error number";
41
42 /** the FILE where to write messages/errors (default: stderr) **/
43 FILE *fc_message_stream = NULL;
44
45 /* switch for the stream */
46 #define FC_STREAM (fc_message_stream==NULL?stderr:fc_message_stream)
47
48 /** the name used for functioncheck itself (in messages) **/
49 char *fc_lib_name = "FCHECK";
50
51 /** flag to forbid messages **/
52 int fc_allow_messages = 1;
53
54 /** flag for verbose mode (debug) **/
55 int fc_allow_debug = 0;
56
57 /* flag to validate the debug */
58 #ifndef FC_NO_DEBUG
59 int fc_allow_debug_hard = 1;
60 #else
61 int fc_allow_debug_hard = 0;
62 #endif
63
64 /** functions **/
65
66 /** strings for exit status **/
67 char *fc_strerror(int err)
68 {
69 if ((err < FC_ERR_FIRST) || (err > FC_ERR_LAST))
70 return (fc_error_ndef);
71 return (fc_error_str[err]);
72 }
73
74 /* set the message stream */
75 void fc_set_message_stream(FILE*f)
76 {
77 fc_message_stream = f;
78 }
79
80 /* set the message name */
81 void fc_set_message_name(char *name)
82 {
83 char *tmp; /* sorry, old name is not deleted */
84
85 tmp = strdup(name);
86
87 if (tmp != NULL)
88 fc_lib_name = tmp;
89 }
90
91 /* mode==true: allow messages */
92 void fc_set_message_mode(int mode)
93 {
94 fc_allow_messages = mode;
95 }
96
97 /* set debug mode */
98 void fc_set_debug_mode(int mode)
99 {
100 fc_allow_debug = mode;
101 }
102
103 /* write a message */
104 void fc_message(char *format, ...)
105 {
106 va_list args;
107 char buffer[1024];
108
109 if (fc_allow_messages)
110 {
111 va_start(args, format);
112 fprintf(FC_STREAM, "%s: ", fc_lib_name);
113 vsnprintf(buffer, 1023, format, args);
114 fprintf(FC_STREAM, "%s", buffer);
115 fprintf(FC_STREAM, "\n");
116 va_end(args);
117 }
118 }
119
120 /* write a debug message */
121 void fc_rdebug(char *format, ...)
122 {
123 va_list args;
124 char buffer[1024];
125
126 if (!fc_allow_debug)
127 return;
128
129 if (fc_allow_messages)
130 {
131 va_start(args, format);
132 fprintf(FC_STREAM, "%s:DEBUG: ", fc_lib_name);
133 vsnprintf(buffer, 1023, format, args);
134 fprintf(FC_STREAM, "%s", buffer);
135 fprintf(FC_STREAM, "\n");
136 va_end(args);
137 }
138 }
139
140 void fc_message_fatal(int ret, char *format, ...)
141 {
142 va_list args;
143 char buffer[1024];
144
145 if (fc_allow_messages)
146 {
147 va_start(args, format);
148 fprintf(FC_STREAM, "%s: ", fc_lib_name);
149 vsnprintf(buffer, 1023, format, args);
150 fprintf(FC_STREAM, "%s", buffer);
151 fprintf(FC_STREAM, "\n");
152 va_end(args);
153 /* exit with return code */
154 fprintf(FC_STREAM, "FATAL (%d)!\n", ret);
155 }
156 exit(ret);
157 }