alpar@1: /* glpenv.h (GLPK environment) */ alpar@1: alpar@1: /*********************************************************************** alpar@1: * This code is part of GLPK (GNU Linear Programming Kit). alpar@1: * alpar@1: * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, alpar@1: * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, alpar@1: * Moscow Aviation Institute, Moscow, Russia. All rights reserved. alpar@1: * E-mail: . alpar@1: * alpar@1: * GLPK is free software: you can redistribute it and/or modify it alpar@1: * under the terms of the GNU General Public License as published by alpar@1: * the Free Software Foundation, either version 3 of the License, or alpar@1: * (at your option) any later version. alpar@1: * alpar@1: * GLPK is distributed in the hope that it will be useful, but WITHOUT alpar@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY alpar@1: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public alpar@1: * License for more details. alpar@1: * alpar@1: * You should have received a copy of the GNU General Public License alpar@1: * along with GLPK. If not, see . alpar@1: ***********************************************************************/ alpar@1: alpar@1: #ifndef GLPENV_H alpar@1: #define GLPENV_H alpar@1: alpar@1: #include "glpstd.h" alpar@1: #include "glplib.h" alpar@1: alpar@1: typedef struct ENV ENV; alpar@1: typedef struct MEM MEM; alpar@1: typedef struct XFILE XFILE; alpar@1: alpar@1: #define ENV_MAGIC 0x454E5631 alpar@1: /* environment block magic value */ alpar@1: alpar@1: #define TERM_BUF_SIZE 4096 alpar@1: /* terminal output buffer size, in bytes */ alpar@1: alpar@1: #define IOERR_MSG_SIZE 1024 alpar@1: /* i/o error message buffer size, in bytes */ alpar@1: alpar@1: #define MEM_MAGIC 0x4D454D31 alpar@1: /* memory block descriptor magic value */ alpar@1: alpar@1: struct ENV alpar@1: { /* environment block */ alpar@1: int magic; alpar@1: /* magic value used for debugging */ alpar@1: char version[7+1]; alpar@1: /* version string returned by the routine glp_version */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* terminal output */ alpar@1: char *term_buf; /* char term_buf[TERM_BUF_SIZE]; */ alpar@1: /* terminal output buffer */ alpar@1: int term_out; alpar@1: /* flag to enable/disable terminal output */ alpar@1: int (*term_hook)(void *info, const char *s); alpar@1: /* user-defined routine to intercept terminal output */ alpar@1: void *term_info; alpar@1: /* transit pointer (cookie) passed to the routine term_hook */ alpar@1: FILE *tee_file; alpar@1: /* output stream used to copy terminal output */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* error handling */ alpar@1: const char *err_file; alpar@1: /* value of the __FILE__ macro passed to glp_error */ alpar@1: int err_line; alpar@1: /* value of the __LINE__ macro passed to glp_error */ alpar@1: void (*err_hook)(void *info); alpar@1: /* user-defined routine to intercept abnormal termination */ alpar@1: void *err_info; alpar@1: /* transit pointer (cookie) passed to the routine err_hook */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* memory allocation */ alpar@1: glp_long mem_limit; alpar@1: /* maximal amount of memory (in bytes) available for dynamic alpar@1: allocation */ alpar@1: MEM *mem_ptr; alpar@1: /* pointer to the linked list of allocated memory blocks */ alpar@1: int mem_count; alpar@1: /* total number of currently allocated memory blocks */ alpar@1: int mem_cpeak; alpar@1: /* peak value of mem_count */ alpar@1: glp_long mem_total; alpar@1: /* total amount of currently allocated memory (in bytes; is the alpar@1: sum of the size field over all memory block descriptors) */ alpar@1: glp_long mem_tpeak; alpar@1: /* peak value of mem_total */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* stream input/output */ alpar@1: XFILE *file_ptr; alpar@1: /* pointer to the linked list of active stream descriptors */ alpar@1: char *ioerr_msg; /* char ioerr_msg[IOERR_MSG_SIZE]; */ alpar@1: /* input/output error message buffer */ alpar@1: /*--------------------------------------------------------------*/ alpar@1: /* shared libraries support */ alpar@1: void *h_odbc; alpar@1: /* handle to ODBC shared library */ alpar@1: void *h_mysql; alpar@1: /* handle to MySQL shared library */ alpar@1: }; alpar@1: alpar@1: struct MEM alpar@1: { /* memory block descriptor */ alpar@1: int flag; alpar@1: /* descriptor flag */ alpar@1: int size; alpar@1: /* size of block (in bytes, including descriptor) */ alpar@1: MEM *prev; alpar@1: /* pointer to previous memory block descriptor */ alpar@1: MEM *next; alpar@1: /* pointer to next memory block descriptor */ alpar@1: }; alpar@1: alpar@1: struct XFILE alpar@1: { /* input/output stream descriptor */ alpar@1: int type; alpar@1: /* stream handle type: */ alpar@1: #define FH_FILE 0x11 /* FILE */ alpar@1: #define FH_ZLIB 0x22 /* gzFile */ alpar@1: void *fh; alpar@1: /* pointer to stream handle */ alpar@1: XFILE *prev; alpar@1: /* pointer to previous stream descriptor */ alpar@1: XFILE *next; alpar@1: /* pointer to next stream descriptor */ alpar@1: }; alpar@1: alpar@1: #define XEOF (-1) alpar@1: alpar@1: #define get_env_ptr _glp_get_env_ptr alpar@1: ENV *get_env_ptr(void); alpar@1: /* retrieve pointer to environment block */ alpar@1: alpar@1: #define tls_set_ptr _glp_tls_set_ptr alpar@1: void tls_set_ptr(void *ptr); alpar@1: /* store global pointer in TLS */ alpar@1: alpar@1: #define tls_get_ptr _glp_tls_get_ptr alpar@1: void *tls_get_ptr(void); alpar@1: /* retrieve global pointer from TLS */ alpar@1: alpar@1: #define xprintf glp_printf alpar@1: void glp_printf(const char *fmt, ...); alpar@1: /* write formatted output to the terminal */ alpar@1: alpar@1: #define xvprintf glp_vprintf alpar@1: void glp_vprintf(const char *fmt, va_list arg); alpar@1: /* write formatted output to the terminal */ alpar@1: alpar@1: #ifndef GLP_ERROR_DEFINED alpar@1: #define GLP_ERROR_DEFINED alpar@1: typedef void (*_glp_error)(const char *fmt, ...); alpar@1: #endif alpar@1: alpar@1: #define xerror glp_error_(__FILE__, __LINE__) alpar@1: _glp_error glp_error_(const char *file, int line); alpar@1: /* display error message and terminate execution */ alpar@1: alpar@1: #define xassert(expr) \ alpar@1: ((void)((expr) || (glp_assert_(#expr, __FILE__, __LINE__), 1))) alpar@1: void glp_assert_(const char *expr, const char *file, int line); alpar@1: /* check for logical condition */ alpar@1: alpar@1: #define xmalloc glp_malloc alpar@1: void *glp_malloc(int size); alpar@1: /* allocate memory block */ alpar@1: alpar@1: #define xcalloc glp_calloc alpar@1: void *glp_calloc(int n, int size); alpar@1: /* allocate memory block */ alpar@1: alpar@1: #define xfree glp_free alpar@1: void glp_free(void *ptr); alpar@1: /* free memory block */ alpar@1: alpar@1: #define xtime glp_time alpar@1: glp_long glp_time(void); alpar@1: /* determine current universal time */ alpar@1: alpar@1: #define xdifftime glp_difftime alpar@1: double glp_difftime(glp_long t1, glp_long t0); alpar@1: /* compute difference between two time values, in seconds */ alpar@1: alpar@1: #define lib_err_msg _glp_lib_err_msg alpar@1: void lib_err_msg(const char *msg); alpar@1: alpar@1: #define xerrmsg _glp_lib_xerrmsg alpar@1: const char *xerrmsg(void); alpar@1: alpar@1: #define xfopen _glp_lib_xfopen alpar@1: XFILE *xfopen(const char *fname, const char *mode); alpar@1: alpar@1: #define xferror _glp_lib_xferror alpar@1: int xferror(XFILE *file); alpar@1: alpar@1: #define xfeof _glp_lib_xfeof alpar@1: int xfeof(XFILE *file); alpar@1: alpar@1: #define xfgetc _glp_lib_xfgetc alpar@1: int xfgetc(XFILE *file); alpar@1: alpar@1: #define xfputc _glp_lib_xfputc alpar@1: int xfputc(int c, XFILE *file); alpar@1: alpar@1: #define xfflush _glp_lib_xfflush alpar@1: int xfflush(XFILE *fp); alpar@1: alpar@1: #define xfclose _glp_lib_xfclose alpar@1: int xfclose(XFILE *file); alpar@1: alpar@1: #define xfprintf _glp_lib_xfprintf alpar@1: int xfprintf(XFILE *file, const char *fmt, ...); alpar@1: alpar@1: #define xdlopen _glp_xdlopen alpar@1: void *xdlopen(const char *module); alpar@1: alpar@1: #define xdlsym _glp_xdlsym alpar@1: void *xdlsym(void *h, const char *symbol); alpar@1: alpar@1: #define xdlclose _glp_xdlclose alpar@1: void xdlclose(void *h); alpar@1: alpar@1: #endif alpar@1: alpar@1: /* eof */