1 /* glpenv.h (GLPK environment) */
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
7 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <mao@gnu.org>.
11 * GLPK is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************/
31 typedef struct ENV ENV;
32 typedef struct MEM MEM;
33 typedef struct XFILE XFILE;
35 #define ENV_MAGIC 0x454E5631
36 /* environment block magic value */
38 #define TERM_BUF_SIZE 4096
39 /* terminal output buffer size, in bytes */
41 #define IOERR_MSG_SIZE 1024
42 /* i/o error message buffer size, in bytes */
44 #define MEM_MAGIC 0x4D454D31
45 /* memory block descriptor magic value */
48 { /* environment block */
50 /* magic value used for debugging */
52 /* version string returned by the routine glp_version */
53 /*--------------------------------------------------------------*/
55 char *term_buf; /* char term_buf[TERM_BUF_SIZE]; */
56 /* terminal output buffer */
58 /* flag to enable/disable terminal output */
59 int (*term_hook)(void *info, const char *s);
60 /* user-defined routine to intercept terminal output */
62 /* transit pointer (cookie) passed to the routine term_hook */
64 /* output stream used to copy terminal output */
65 /*--------------------------------------------------------------*/
68 /* value of the __FILE__ macro passed to glp_error */
70 /* value of the __LINE__ macro passed to glp_error */
71 void (*err_hook)(void *info);
72 /* user-defined routine to intercept abnormal termination */
74 /* transit pointer (cookie) passed to the routine err_hook */
75 /*--------------------------------------------------------------*/
76 /* memory allocation */
78 /* maximal amount of memory (in bytes) available for dynamic
81 /* pointer to the linked list of allocated memory blocks */
83 /* total number of currently allocated memory blocks */
85 /* peak value of mem_count */
87 /* total amount of currently allocated memory (in bytes; is the
88 sum of the size field over all memory block descriptors) */
90 /* peak value of mem_total */
91 /*--------------------------------------------------------------*/
92 /* stream input/output */
94 /* pointer to the linked list of active stream descriptors */
95 char *ioerr_msg; /* char ioerr_msg[IOERR_MSG_SIZE]; */
96 /* input/output error message buffer */
97 /*--------------------------------------------------------------*/
98 /* shared libraries support */
100 /* handle to ODBC shared library */
102 /* handle to MySQL shared library */
106 { /* memory block descriptor */
108 /* descriptor flag */
110 /* size of block (in bytes, including descriptor) */
112 /* pointer to previous memory block descriptor */
114 /* pointer to next memory block descriptor */
118 { /* input/output stream descriptor */
120 /* stream handle type: */
121 #define FH_FILE 0x11 /* FILE */
122 #define FH_ZLIB 0x22 /* gzFile */
124 /* pointer to stream handle */
126 /* pointer to previous stream descriptor */
128 /* pointer to next stream descriptor */
133 #define get_env_ptr _glp_get_env_ptr
134 ENV *get_env_ptr(void);
135 /* retrieve pointer to environment block */
137 #define tls_set_ptr _glp_tls_set_ptr
138 void tls_set_ptr(void *ptr);
139 /* store global pointer in TLS */
141 #define tls_get_ptr _glp_tls_get_ptr
142 void *tls_get_ptr(void);
143 /* retrieve global pointer from TLS */
145 #define xprintf glp_printf
146 void glp_printf(const char *fmt, ...);
147 /* write formatted output to the terminal */
149 #define xvprintf glp_vprintf
150 void glp_vprintf(const char *fmt, va_list arg);
151 /* write formatted output to the terminal */
153 #ifndef GLP_ERROR_DEFINED
154 #define GLP_ERROR_DEFINED
155 typedef void (*_glp_error)(const char *fmt, ...);
158 #define xerror glp_error_(__FILE__, __LINE__)
159 _glp_error glp_error_(const char *file, int line);
160 /* display error message and terminate execution */
162 #define xassert(expr) \
163 ((void)((expr) || (glp_assert_(#expr, __FILE__, __LINE__), 1)))
164 void glp_assert_(const char *expr, const char *file, int line);
165 /* check for logical condition */
167 #define xmalloc glp_malloc
168 void *glp_malloc(int size);
169 /* allocate memory block */
171 #define xcalloc glp_calloc
172 void *glp_calloc(int n, int size);
173 /* allocate memory block */
175 #define xfree glp_free
176 void glp_free(void *ptr);
177 /* free memory block */
179 #define xtime glp_time
180 glp_long glp_time(void);
181 /* determine current universal time */
183 #define xdifftime glp_difftime
184 double glp_difftime(glp_long t1, glp_long t0);
185 /* compute difference between two time values, in seconds */
187 #define lib_err_msg _glp_lib_err_msg
188 void lib_err_msg(const char *msg);
190 #define xerrmsg _glp_lib_xerrmsg
191 const char *xerrmsg(void);
193 #define xfopen _glp_lib_xfopen
194 XFILE *xfopen(const char *fname, const char *mode);
196 #define xferror _glp_lib_xferror
197 int xferror(XFILE *file);
199 #define xfeof _glp_lib_xfeof
200 int xfeof(XFILE *file);
202 #define xfgetc _glp_lib_xfgetc
203 int xfgetc(XFILE *file);
205 #define xfputc _glp_lib_xfputc
206 int xfputc(int c, XFILE *file);
208 #define xfflush _glp_lib_xfflush
209 int xfflush(XFILE *fp);
211 #define xfclose _glp_lib_xfclose
212 int xfclose(XFILE *file);
214 #define xfprintf _glp_lib_xfprintf
215 int xfprintf(XFILE *file, const char *fmt, ...);
217 #define xdlopen _glp_xdlopen
218 void *xdlopen(const char *module);
220 #define xdlsym _glp_xdlsym
221 void *xdlsym(void *h, const char *symbol);
223 #define xdlclose _glp_xdlclose
224 void xdlclose(void *h);