"Fossies" - the Fresh Open Source Software Archive 
Member "FunctionCheck-3.2.0/src/libfc/fc_ressources.c" (26 May 2012, 5467 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 #include "fc_ressources.h"
21 #include <string.h>
22
23 /* switch for getenv (if not defined) */
24 #ifndef FC_NO_GETENV
25 #define FC_GETENV(n) getenv(n)
26 #else
27 #define FC_GETENV(n) NULL
28 #endif
29
30 /* switch for setenv (if not defined) */
31 #ifndef FC_NO_SETENV
32 #define FC_SETENV(n,v,o) setenv((n),(v),(o))
33 #else
34 #define FC_SETENV(n,v,o) {} /*empty command */
35 #endif
36
37 /* switch for unsetenv (if not defined) */
38 #ifndef FC_NO_UNSETENV
39 #define FC_UNSETENV(n) unsetenv(n)
40 #else
41 #define FC_UNSETENV(n) {} /*empty command */
42 #endif
43
44 /* get env. variable 'var' and convert in integer */
45 int fc_get_env_integer(char *var, int *nb)
46 {
47 char *tmp;
48
49 if ((tmp = FC_GETENV(var)) == NULL)
50 return (0);
51
52 sscanf(tmp, "%d", nb);
53 return (1);
54 }
55
56 /* get env. variable 'var' and convert in bool */
57 int fc_get_env_bool(char *var)
58 {
59 if (FC_GETENV(var) == NULL)
60 return (0);
61
62 return (1);
63 }
64
65 /* get env. variable 'var' and convert in float */
66 int fc_get_env_float(char *var, float *nb)
67 {
68 char *tmp;
69
70 if ((tmp = FC_GETENV(var)) == NULL)
71 return (0);
72
73 sscanf(tmp, "%f", nb);
74 return (1);
75 }
76
77 /* get env. variable 'var' and convert in char* (must be pre-allocated) */
78 int fc_get_env_char(char *var, char *nb)
79 {
80 char *tmp;
81
82 if ((tmp = FC_GETENV(var)) == NULL)
83 return (0);
84
85 nb[0] = '\0';
86 strcat(nb, tmp);
87 return (1);
88 }
89
90 /** read env. variables and set values in corresponding
91 variables. If not set, variables are unchanged **/
92 int fc_read_env(int *fc_buffer_size,
93 int *fc_stack_size,
94 int *fc_function_size,
95 int *fc_graph_size,
96 int *fc_memory_size,
97 char*fc_dump_path,
98 char*fc_dump_name,
99 char*fc_time_mode,
100 int *fc_verbose_mode,
101 int *fc_use_pid,
102 int *fc_no_fork,
103 int *fc_no_thread,
104 int *fc_debug,
105 int *give_help,
106 int *use_memory,
107 int *memory_stack)
108 {
109 /* no verbose */
110 if (fc_get_env_bool("FC_QUIET"))
111 *fc_verbose_mode = 0;
112
113 /* help */
114 if (fc_get_env_bool("FC_HELP"))
115 *give_help = 1;
116
117 /* memory profiling */
118 if (fc_get_env_bool("FC_MEMORY"))
119 *use_memory = 1;
120
121 /* the size of the buffer (for communications) */
122 fc_get_env_integer("FC_MEMORY_STACK", memory_stack);
123
124 /* the size of the buffer (for communications) */
125 fc_get_env_integer("FC_BUFFER_SIZE", fc_buffer_size);
126
127 /* the size of the stack */
128 fc_get_env_integer("FC_STACK_SIZE", fc_stack_size);
129
130 /* the size of the function list */
131 fc_get_env_integer("FC_FUNCTION_SIZE", fc_function_size);
132
133 /* the size of the function list */
134 fc_get_env_integer("FC_GRAPH_SIZE", fc_graph_size);
135
136 /* the size of the memory-entry list */
137 fc_get_env_integer("FC_MEMORY_SIZE", fc_memory_size);
138
139 /* the time unit to use */
140 fc_get_env_char("FC_TIME_MODE", fc_time_mode);
141
142 /* the base name of the dump file */
143 fc_get_env_char("FC_DUMP_NAME", fc_dump_name);
144
145 /* the path for each output files */
146 fc_get_env_char("FC_DUMP_PATH", fc_dump_path);
147
148 /* no forks */
149 if (fc_get_env_bool("FC_NO_FORK"))
150 *fc_no_fork = 1;
151
152 /* allow threads */
153 if (fc_get_env_bool("FC_ALLOW_THREAD"))
154 *fc_no_thread = 0;
155
156 /* use PID for dump file name (for multiple profiles) */
157 if (fc_get_env_bool("FC_USE_PID"))
158 *fc_use_pid = 1;
159
160 /* switch to debug mode */
161 if (fc_get_env_bool("FC_DEBUG"))
162 *fc_debug = 1;
163
164 /* disable messages */
165 if (fc_get_env_bool("FC_NO_VERBOSE"))
166 *fc_verbose_mode = 0;
167
168 return (1);
169 }
170
171 /** read ressources file (if exist) and set env. variables
172 with corresponding values (to be done before fc_read_env) **/
173 int fc_read_ressources()
174 {
175 char *s;
176 FILE *f;
177 char temp[1024];
178 char keyw[1024], val[1024];
179
180 if ((f = fopen("./.functioncheckrc", "r")) == NULL)
181 return 0;
182
183 while (1)
184 {
185 /* read a line from file */
186 s = fgets(temp, 1023, f);
187 /* EOF: stop */
188 if (s == NULL || feof(f))
189 break;
190 /* get VARIABLE VALUE pair */
191 sscanf(temp, "%s%s", keyw, val);
192 /* check if the VARIABLE is a FC_ one */
193 if (strncmp(keyw, "FC_", 3) == 0)
194 {
195 /* set this value as an env. variable */
196 if (strcmp(val, "!") == 0)
197 {/* special case: unset the variable */
198 FC_UNSETENV(keyw);
199 }
200 else
201 {
202 FC_SETENV(keyw, val, 1);
203 }
204 }
205 }
206
207 fclose(f);
208 return 1;
209 }