1 /* env.h (GLPK environment) */
2 
3 /***********************************************************************
4 *  This code is part of GLPK (GNU Linear Programming Kit).
5 *  Copyright (C) 2000-2017 Free Software Foundation, Inc.
6 *  Written by Andrew Makhorin <mao@gnu.org>.
7 *
8 *  GLPK is free software: you can redistribute it and/or modify it
9 *  under the terms of the GNU General Public License as published by
10 *  the Free Software Foundation, either version 3 of the License, or
11 *  (at your option) any later version.
12 *
13 *  GLPK is distributed in the hope that it will be useful, but WITHOUT
14 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 *  License for more details.
17 *
18 *  You should have received a copy of the GNU General Public License
19 *  along with GLPK. If not, see <http://www.gnu.org/licenses/>.
20 ***********************************************************************/
21 
22 #ifndef ENV_H
23 #define ENV_H
24 
25 #include "stdc.h"
26 
27 typedef struct ENV ENV;
28 typedef struct MBD MBD;
29 
30 #ifndef SIZE_T_MAX
31 #define SIZE_T_MAX (~(size_t)0)
32 #endif
33 /* largest value of size_t type */
34 
35 #define TBUF_SIZE 4096
36 /* terminal output buffer size, in bytes */
37 
38 #define EBUF_SIZE 1024
39 /* error message buffer size, in bytes */
40 
41 /* enable/disable flag: */
42 #define GLP_ON  1
43 #define GLP_OFF 0
44 
45 struct ENV
46 {     /* GLPK environment block */
47 #if 0 /* 14/I-2007 */
48       char version[7+1];
49       /* version string returned by the routine glp_version */
50 #endif
51       ENV *self;
52       /* pointer to this block to check its validity */
53       /*--------------------------------------------------------------*/
54       /* terminal output */
55       char *term_buf; /* char term_buf[TBUF_SIZE]; */
56       /* terminal output buffer */
57       int term_out;
58       /* flag to enable/disable terminal output */
59       int (*term_hook)(void *info, const char *s);
60       /* user-defined routine to intercept terminal output */
61       void *term_info;
62       /* transit pointer (cookie) passed to the routine term_hook */
63       FILE *tee_file;
64       /* output stream used to copy terminal output */
65       /*--------------------------------------------------------------*/
66       /* error handling */
67 #if 1 /* 07/XI-2015 */
68       int err_st;
69       /* error state flag; set on entry to glp_error */
70 #endif
71       const char *err_file;
72       /* value of the __FILE__ macro passed to glp_error */
73       int err_line;
74       /* value of the __LINE__ macro passed to glp_error */
75       void (*err_hook)(void *info);
76       /* user-defined routine to intercept abnormal termination */
77       void *err_info;
78       /* transit pointer (cookie) passed to the routine err_hook */
79       char *err_buf; /* char err_buf[EBUF_SIZE]; */
80       /* buffer to store error messages (used by I/O routines) */
81       /*--------------------------------------------------------------*/
82       /* dynamic memory allocation */
83       size_t mem_limit;
84       /* maximal amount of memory, in bytes, available for dynamic
85        * allocation */
86       MBD *mem_ptr;
87       /* pointer to the linked list of allocated memory blocks */
88       int mem_count;
89       /* total number of currently allocated memory blocks */
90       int mem_cpeak;
91       /* peak value of mem_count */
92       size_t mem_total;
93       /* total amount of currently allocated memory, in bytes; it is
94        * the sum of the size field over all memory block descriptors */
95       size_t mem_tpeak;
96       /* peak value of mem_total */
97 #if 1 /* 23/XI-2015 */
98       /*--------------------------------------------------------------*/
99       /* bignum module working area */
100       void *gmp_pool; /* DMP *gmp_pool; */
101       /* working memory pool */
102       int gmp_size;
103       /* size of working array */
104       unsigned short *gmp_work; /* ushort gmp_work[gmp_size]; */
105       /* working array */
106 #endif
107       /*--------------------------------------------------------------*/
108       /* dynamic linking support (optional) */
109       void *h_odbc;
110       /* handle to ODBC shared library */
111       void *h_mysql;
112       /* handle to MySQL shared library */
113 };
114 
115 struct MBD
116 {     /* memory block descriptor */
117       size_t size;
118       /* size of block, in bytes, including descriptor */
119       MBD *self;
120       /* pointer to this descriptor to check its validity */
121       MBD *prev;
122       /* pointer to previous memory block descriptor */
123       MBD *next;
124       /* pointer to next memory block descriptor */
125 };
126 
127 #define get_env_ptr _glp_get_env_ptr
128 ENV *get_env_ptr(void);
129 /* retrieve pointer to environment block */
130 
131 #define tls_set_ptr _glp_tls_set_ptr
132 void tls_set_ptr(void *ptr);
133 /* store global pointer in TLS */
134 
135 #define tls_get_ptr _glp_tls_get_ptr
136 void *tls_get_ptr(void);
137 /* retrieve global pointer from TLS */
138 
139 #define xputs glp_puts
140 void glp_puts(const char *s);
141 /* write string on terminal */
142 
143 #define xprintf glp_printf
144 void glp_printf(const char *fmt, ...);
145 /* write formatted output on terminal */
146 
147 #define xvprintf glp_vprintf
148 void glp_vprintf(const char *fmt, va_list arg);
149 /* write formatted output on terminal */
150 
151 int glp_term_out(int flag);
152 /* enable/disable terminal output */
153 
154 void glp_term_hook(int (*func)(void *info, const char *s), void *info);
155 /* install hook to intercept terminal output */
156 
157 int glp_open_tee(const char *fname);
158 /* start copying terminal output to text file */
159 
160 int glp_close_tee(void);
161 /* stop copying terminal output to text file */
162 
163 #ifndef GLP_ERRFUNC_DEFINED
164 #define GLP_ERRFUNC_DEFINED
165 typedef void (*glp_errfunc)(const char *fmt, ...);
166 #endif
167 
168 #define xerror glp_error_(__FILE__, __LINE__)
169 glp_errfunc glp_error_(const char *file, int line);
170 /* display fatal error message and terminate execution */
171 
172 #define xassert(expr) \
173       ((void)((expr) || (glp_assert_(#expr, __FILE__, __LINE__), 1)))
174 void glp_assert_(const char *expr, const char *file, int line);
175 /* check for logical condition */
176 
177 void glp_error_hook(void (*func)(void *info), void *info);
178 /* install hook to intercept abnormal termination */
179 
180 #define put_err_msg _glp_put_err_msg
181 void put_err_msg(const char *msg);
182 /* provide error message string */
183 
184 #define get_err_msg _glp_get_err_msg
185 const char *get_err_msg(void);
186 /* obtain error message string */
187 
188 #define xmalloc(size) glp_alloc(1, size)
189 /* allocate memory block (obsolete) */
190 
191 #define xcalloc(n, size) glp_alloc(n, size)
192 /* allocate memory block (obsolete) */
193 
194 #define xalloc(n, size) glp_alloc(n, size)
195 #define talloc(n, type) ((type *)glp_alloc(n, sizeof(type)))
196 void *glp_alloc(int n, int size);
197 /* allocate memory block */
198 
199 #define xrealloc(ptr, n, size) glp_realloc(ptr, n, size)
200 #define trealloc(ptr, n, type) ((type *)glp_realloc(ptr, n, \
201       sizeof(type)))
202 void *glp_realloc(void *ptr, int n, int size);
203 /* reallocate memory block */
204 
205 #define xfree(ptr) glp_free(ptr)
206 #define tfree(ptr) glp_free(ptr)
207 void glp_free(void *ptr);
208 /* free memory block */
209 
210 void glp_mem_limit(int limit);
211 /* set memory usage limit */
212 
213 void glp_mem_usage(int *count, int *cpeak, size_t *total,
214       size_t *tpeak);
215 /* get memory usage information */
216 
217 typedef struct glp_file glp_file;
218 /* sequential stream descriptor */
219 
220 #define glp_open _glp_open
221 glp_file *glp_open(const char *name, const char *mode);
222 /* open stream */
223 
224 #define glp_eof _glp_eof
225 int glp_eof(glp_file *f);
226 /* test end-of-file indicator */
227 
228 #define glp_ioerr _glp_ioerr
229 int glp_ioerr(glp_file *f);
230 /* test I/O error indicator */
231 
232 #define glp_read _glp_read
233 int glp_read(glp_file *f, void *buf, int nnn);
234 /* read data from stream */
235 
236 #define glp_getc _glp_getc
237 int glp_getc(glp_file *f);
238 /* read character from stream */
239 
240 #define glp_write _glp_write
241 int glp_write(glp_file *f, const void *buf, int nnn);
242 /* write data to stream */
243 
244 #define glp_format _glp_format
245 int glp_format(glp_file *f, const char *fmt, ...);
246 /* write formatted data to stream */
247 
248 #define glp_close _glp_close
249 int glp_close(glp_file *f);
250 /* close stream */
251 
252 #define xtime glp_time
253 double glp_time(void);
254 /* determine current universal time */
255 
256 #define xdifftime glp_difftime
257 double glp_difftime(double t1, double t0);
258 /* compute difference between two time values */
259 
260 #define xdlopen _glp_dlopen
261 void *xdlopen(const char *module);
262 /* open dynamically linked library */
263 
264 #define xdlsym _glp_dlsym
265 void *xdlsym(void *h, const char *symbol);
266 /* obtain address of symbol from dynamically linked library */
267 
268 #define xdlclose _glp_dlclose
269 void xdlclose(void *h);
270 /* close dynamically linked library */
271 
272 #endif
273 
274 /* eof */
275