glpenv.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /* glpenv.h (GLPK environment) */
  2. /***********************************************************************
  3. * This code is part of GLPK (GNU Linear Programming Kit).
  4. *
  5. * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
  6. * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
  7. * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
  8. * E-mail: <mao@gnu.org>.
  9. *
  10. * GLPK is free software: you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * GLPK is distributed in the hope that it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  18. * License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
  22. ***********************************************************************/
  23. #ifndef GLPENV_H
  24. #define GLPENV_H
  25. #include "glpstd.h"
  26. #include "glplib.h"
  27. typedef struct ENV ENV;
  28. typedef struct MEM MEM;
  29. typedef struct XFILE XFILE;
  30. #define ENV_MAGIC 0x454E5631
  31. /* environment block magic value */
  32. #define TERM_BUF_SIZE 4096
  33. /* terminal output buffer size, in bytes */
  34. #define IOERR_MSG_SIZE 1024
  35. /* i/o error message buffer size, in bytes */
  36. #define MEM_MAGIC 0x4D454D31
  37. /* memory block descriptor magic value */
  38. struct ENV
  39. { /* environment block */
  40. int magic;
  41. /* magic value used for debugging */
  42. char version[7+1];
  43. /* version string returned by the routine glp_version */
  44. /*--------------------------------------------------------------*/
  45. /* terminal output */
  46. char *term_buf; /* char term_buf[TERM_BUF_SIZE]; */
  47. /* terminal output buffer */
  48. int term_out;
  49. /* flag to enable/disable terminal output */
  50. int (*term_hook)(void *info, const char *s);
  51. /* user-defined routine to intercept terminal output */
  52. void *term_info;
  53. /* transit pointer (cookie) passed to the routine term_hook */
  54. FILE *tee_file;
  55. /* output stream used to copy terminal output */
  56. /*--------------------------------------------------------------*/
  57. /* error handling */
  58. const char *err_file;
  59. /* value of the __FILE__ macro passed to glp_error */
  60. int err_line;
  61. /* value of the __LINE__ macro passed to glp_error */
  62. void (*err_hook)(void *info);
  63. /* user-defined routine to intercept abnormal termination */
  64. void *err_info;
  65. /* transit pointer (cookie) passed to the routine err_hook */
  66. /*--------------------------------------------------------------*/
  67. /* memory allocation */
  68. glp_long mem_limit;
  69. /* maximal amount of memory (in bytes) available for dynamic
  70. allocation */
  71. MEM *mem_ptr;
  72. /* pointer to the linked list of allocated memory blocks */
  73. int mem_count;
  74. /* total number of currently allocated memory blocks */
  75. int mem_cpeak;
  76. /* peak value of mem_count */
  77. glp_long mem_total;
  78. /* total amount of currently allocated memory (in bytes; is the
  79. sum of the size field over all memory block descriptors) */
  80. glp_long mem_tpeak;
  81. /* peak value of mem_total */
  82. /*--------------------------------------------------------------*/
  83. /* stream input/output */
  84. XFILE *file_ptr;
  85. /* pointer to the linked list of active stream descriptors */
  86. char *ioerr_msg; /* char ioerr_msg[IOERR_MSG_SIZE]; */
  87. /* input/output error message buffer */
  88. /*--------------------------------------------------------------*/
  89. /* shared libraries support */
  90. void *h_odbc;
  91. /* handle to ODBC shared library */
  92. void *h_mysql;
  93. /* handle to MySQL shared library */
  94. };
  95. struct MEM
  96. { /* memory block descriptor */
  97. int flag;
  98. /* descriptor flag */
  99. int size;
  100. /* size of block (in bytes, including descriptor) */
  101. MEM *prev;
  102. /* pointer to previous memory block descriptor */
  103. MEM *next;
  104. /* pointer to next memory block descriptor */
  105. };
  106. struct XFILE
  107. { /* input/output stream descriptor */
  108. int type;
  109. /* stream handle type: */
  110. #define FH_FILE 0x11 /* FILE */
  111. #define FH_ZLIB 0x22 /* gzFile */
  112. void *fh;
  113. /* pointer to stream handle */
  114. XFILE *prev;
  115. /* pointer to previous stream descriptor */
  116. XFILE *next;
  117. /* pointer to next stream descriptor */
  118. };
  119. #define XEOF (-1)
  120. #define get_env_ptr _glp_get_env_ptr
  121. ENV *get_env_ptr(void);
  122. /* retrieve pointer to environment block */
  123. #define tls_set_ptr _glp_tls_set_ptr
  124. void tls_set_ptr(void *ptr);
  125. /* store global pointer in TLS */
  126. #define tls_get_ptr _glp_tls_get_ptr
  127. void *tls_get_ptr(void);
  128. /* retrieve global pointer from TLS */
  129. #define xprintf glp_printf
  130. void glp_printf(const char *fmt, ...);
  131. /* write formatted output to the terminal */
  132. #define xvprintf glp_vprintf
  133. void glp_vprintf(const char *fmt, va_list arg);
  134. /* write formatted output to the terminal */
  135. #ifndef GLP_ERROR_DEFINED
  136. #define GLP_ERROR_DEFINED
  137. typedef void (*_glp_error)(const char *fmt, ...);
  138. #endif
  139. #define xerror glp_error_(__FILE__, __LINE__)
  140. _glp_error glp_error_(const char *file, int line);
  141. /* display error message and terminate execution */
  142. #define xassert(expr) \
  143. ((void)((expr) || (glp_assert_(#expr, __FILE__, __LINE__), 1)))
  144. void glp_assert_(const char *expr, const char *file, int line);
  145. /* check for logical condition */
  146. #define xmalloc glp_malloc
  147. void *glp_malloc(int size);
  148. /* allocate memory block */
  149. #define xcalloc glp_calloc
  150. void *glp_calloc(int n, int size);
  151. /* allocate memory block */
  152. #define xfree glp_free
  153. void glp_free(void *ptr);
  154. /* free memory block */
  155. #define xtime glp_time
  156. glp_long glp_time(void);
  157. /* determine current universal time */
  158. #define xdifftime glp_difftime
  159. double glp_difftime(glp_long t1, glp_long t0);
  160. /* compute difference between two time values, in seconds */
  161. #define lib_err_msg _glp_lib_err_msg
  162. void lib_err_msg(const char *msg);
  163. #define xerrmsg _glp_lib_xerrmsg
  164. const char *xerrmsg(void);
  165. #define xfopen _glp_lib_xfopen
  166. XFILE *xfopen(const char *fname, const char *mode);
  167. #define xferror _glp_lib_xferror
  168. int xferror(XFILE *file);
  169. #define xfeof _glp_lib_xfeof
  170. int xfeof(XFILE *file);
  171. #define xfgetc _glp_lib_xfgetc
  172. int xfgetc(XFILE *file);
  173. #define xfputc _glp_lib_xfputc
  174. int xfputc(int c, XFILE *file);
  175. #define xfflush _glp_lib_xfflush
  176. int xfflush(XFILE *fp);
  177. #define xfclose _glp_lib_xfclose
  178. int xfclose(XFILE *file);
  179. #define xfprintf _glp_lib_xfprintf
  180. int xfprintf(XFILE *file, const char *fmt, ...);
  181. #define xdlopen _glp_xdlopen
  182. void *xdlopen(const char *module);
  183. #define xdlsym _glp_xdlsym
  184. void *xdlsym(void *h, const char *symbol);
  185. #define xdlclose _glp_xdlclose
  186. void xdlclose(void *h);
  187. #endif
  188. /* eof */