/farmR/src/glplib.h

https://code.google.com/p/javawfm/ · C Header · 379 lines · 193 code · 80 blank · 106 comment · 1 complexity · d3fe2597f3494f7e1ae1e534464b0bd0 MD5 · raw file

  1. /* glplib.h (low-level library routines) */
  2. /***********************************************************************
  3. * This code is part of GLPK (GNU Linear Programming Kit).
  4. *
  5. * Copyright (C) 2000,01,02,03,04,05,06,07,08,2009 Andrew Makhorin,
  6. * Department for Applied Informatics, Moscow Aviation Institute,
  7. * Moscow, Russia. All rights reserved. E-mail: <mao@mai2.rcnet.ru>.
  8. *
  9. * GLPK is free software: you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * GLPK is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  17. * License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
  21. ***********************************************************************/
  22. #ifndef _GLPLIB_H
  23. #define _GLPLIB_H
  24. #ifdef HAVE_CONFIG_H
  25. #include <config.h>
  26. #endif
  27. #include "glpstd.h"
  28. typedef struct { int lo, hi; } xlong_t;
  29. /* long integer data type */
  30. typedef struct { xlong_t quot, rem; } xldiv_t;
  31. /* result of long integer division */
  32. typedef struct LIBENV LIBENV;
  33. typedef struct LIBMEM LIBMEM;
  34. typedef struct XFILE XFILE;
  35. struct LIBENV
  36. { /* library environment block */
  37. char version[7+1];
  38. /* version string returned by the routine glp_version */
  39. /*--------------------------------------------------------------*/
  40. /* memory allocation */
  41. xlong_t mem_limit;
  42. /* maximal amount of memory (in bytes) available for dynamic
  43. allocation */
  44. LIBMEM *mem_ptr;
  45. /* pointer to the linked list of allocated memory blocks */
  46. int mem_count;
  47. /* total number of currently allocated memory blocks */
  48. int mem_cpeak;
  49. /* peak value of mem_count */
  50. xlong_t mem_total;
  51. /* total amount of currently allocated memory (in bytes; is the
  52. sum of the size field over all memory block descriptors) */
  53. xlong_t mem_tpeak;
  54. /* peak value of mem_total */
  55. /*--------------------------------------------------------------*/
  56. /* terminal output */
  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 passed to the routine term_hook */
  63. /*--------------------------------------------------------------*/
  64. /* input/output streams */
  65. char err_msg[1000+1];
  66. XFILE *file_ptr;
  67. /* pointer to the linked list of active stream descriptors */
  68. void *log_file; /* FILE *log_file; */
  69. /* output stream used to hardcopy all terminal output; NULL means
  70. no hardcopying */
  71. const char *err_file;
  72. int err_line;
  73. /*--------------------------------------------------------------*/
  74. /* standard time */
  75. xlong_t t_init, t_last;
  76. char c_init[sizeof(double)]; /* clock_t c_init; */
  77. /*--------------------------------------------------------------*/
  78. /* shared libraries */
  79. void *h_odbc; /* handle to ODBC shared library */
  80. void *h_mysql; /* handle to MySQL shared library */
  81. };
  82. #define LIB_MEM_FLAG 0x20101960
  83. /* memory block descriptor flag */
  84. struct LIBMEM
  85. { /* memory block descriptor */
  86. int flag;
  87. /* descriptor flag */
  88. int size;
  89. /* size of block (in bytes, including descriptor) */
  90. LIBMEM *prev;
  91. /* pointer to previous memory block descriptor */
  92. LIBMEM *next;
  93. /* pointer to next memory block descriptor */
  94. };
  95. struct XFILE
  96. { /* input/output stream descriptor */
  97. int type;
  98. /* stream handle type: */
  99. #define FH_FILE 0x11 /* FILE */
  100. #define FH_ZLIB 0x22 /* gzFile */
  101. void *fh;
  102. /* pointer to stream handle */
  103. XFILE *prev;
  104. /* pointer to previous stream descriptor */
  105. XFILE *next;
  106. /* pointer to next stream descriptor */
  107. };
  108. #define XEOF (-1)
  109. #define bigmul _glp_lib_bigmul
  110. void bigmul(int n, int m, unsigned short x[], unsigned short y[]);
  111. /* multiply unsigned integer numbers of arbitrary precision */
  112. #define bigdiv _glp_lib_bigdiv
  113. void bigdiv(int n, int m, unsigned short x[], unsigned short y[]);
  114. /* divide unsigned integer numbers of arbitrary precision */
  115. #define xlset _glp_lib_xlset
  116. xlong_t xlset(int x);
  117. /* expand integer to long integer */
  118. #define xlneg _glp_lib_xlneg
  119. xlong_t xlneg(xlong_t x);
  120. /* negate long integer */
  121. #define xladd _glp_lib_xladd
  122. xlong_t xladd(xlong_t x, xlong_t y);
  123. /* add long integers */
  124. #define xlsub _glp_lib_xlsub
  125. xlong_t xlsub(xlong_t x, xlong_t y);
  126. /* subtract long integers */
  127. #define xlcmp _glp_lib_xlcmp
  128. int xlcmp(xlong_t x, xlong_t y);
  129. /* compare long integers */
  130. #define xlmul _glp_lib_xlmul
  131. xlong_t xlmul(xlong_t x, xlong_t y);
  132. /* multiply long integers */
  133. #define xldiv _glp_lib_xldiv
  134. xldiv_t xldiv(xlong_t x, xlong_t y);
  135. /* divide long integers */
  136. #define xltod _glp_lib_xltod
  137. double xltod(xlong_t x);
  138. /* convert long integer to double */
  139. #define xltoa _glp_lib_xltoa
  140. char *xltoa(xlong_t x, char *s);
  141. /* convert long integer to character string */
  142. #define lib_set_ptr _glp_lib_set_ptr
  143. void lib_set_ptr(void *ptr);
  144. /* store global pointer in TLS */
  145. #define lib_get_ptr _glp_lib_get_ptr
  146. void *lib_get_ptr(void);
  147. /* retrieve global pointer from TLS */
  148. #define lib_init_env _glp_lib_init_env
  149. int lib_init_env(void);
  150. /* initialize library environment */
  151. #define lib_link_env _glp_lib_link_env
  152. LIBENV *lib_link_env(void);
  153. /* retrieve pointer to library environment block */
  154. #define lib_version _glp_lib_version
  155. const char *lib_version(void);
  156. /* determine library version */
  157. #define lib_free_env _glp_lib_free_env
  158. int lib_free_env(void);
  159. /* free library environment */
  160. #define xgetc _glp_lib_xgetc
  161. int xgetc(void);
  162. /* read character from the terminal */
  163. #define xputc _glp_lib_xputc
  164. void xputc(int c);
  165. /* write character to the terminal */
  166. #define xprintf _glp_lib_xprintf
  167. void xprintf(const char *fmt, ...);
  168. /* write formatted output to the terminal */
  169. #define xvprintf _glp_lib_xvprintf
  170. void xvprintf(const char *fmt, va_list arg);
  171. /* write formatted output to the terminal */
  172. #define lib_term_hook _glp_lib_term_hook
  173. void lib_term_hook(int (*func)(void *info, const char *s), void *info);
  174. /* install hook to intercept terminal output */
  175. #define lib_print_hook _glp_lib_print_hook
  176. void lib_print_hook(int (*func)(void *info, char *buf), void *info);
  177. /* (obsolete) */
  178. #if 0
  179. #define xerror _glp_lib_xerror
  180. void xerror(const char *fmt, ...);
  181. /* display error message and terminate execution */
  182. #else
  183. #define xerror lib_xerror1(__FILE__, __LINE__)
  184. typedef void (*xerror_t)(const char *fmt, ...);
  185. #define lib_xerror1 _glp_lib_xerror1
  186. xerror_t lib_xerror1(const char *file, int line);
  187. #define lib_xerror2 _glp_lib_xerror2
  188. void lib_xerror2(const char *fmt, ...);
  189. #endif
  190. #define lib_fault_hook _glp_lib_fault_hook
  191. void lib_fault_hook(int (*func)(void *info, char *buf), void *info);
  192. /* (obsolete) */
  193. #define xassert(expr) \
  194. ((void)((expr) || (lib_xassert(#expr, __FILE__, __LINE__), 1)))
  195. #define lib_xassert _glp_lib_xassert
  196. void lib_xassert(const char *expr, const char *file, int line);
  197. /* check for logical condition */
  198. #define xmalloc _glp_lib_xmalloc
  199. void *xmalloc(int size);
  200. /* allocate memory block */
  201. #define xcalloc _glp_lib_xcalloc
  202. void *xcalloc(int n, int size);
  203. /* allocate memory block */
  204. #define xfree _glp_lib_xfree
  205. void xfree(void *ptr);
  206. /* free memory block */
  207. #define lib_mem_limit _glp_lib_mem_limit
  208. void lib_mem_limit(xlong_t limit);
  209. /* set memory allocation limit */
  210. #define lib_mem_usage _glp_lib_mem_usage
  211. void lib_mem_usage(int *count, int *cpeak, xlong_t *total,
  212. xlong_t *tpeak);
  213. /* get memory usage information */
  214. #define lib_err_msg _glp_lib_err_msg
  215. void lib_err_msg(const char *msg);
  216. #define xerrmsg _glp_lib_xerrmsg
  217. const char *xerrmsg(void);
  218. #define xfopen _glp_lib_xfopen
  219. XFILE *xfopen(const char *fname, const char *mode);
  220. #define xferror _glp_lib_xferror
  221. int xferror(XFILE *file);
  222. #define xfeof _glp_lib_xfeof
  223. int xfeof(XFILE *file);
  224. #define xfgetc _glp_lib_xfgetc
  225. int xfgetc(XFILE *file);
  226. #define xfputc _glp_lib_xfputc
  227. int xfputc(int c, XFILE *file);
  228. #define xfflush _glp_lib_xfflush
  229. int xfflush(XFILE *fp);
  230. #define xfclose _glp_lib_xfclose
  231. int xfclose(XFILE *file);
  232. #define lib_doprnt _glp_lib_doprnt
  233. int lib_doprnt(int (*func)(void *info, int c), void *info, const char
  234. *fmt, va_list arg);
  235. /* perform formatted output (basic routine) */
  236. #define xfprintf _glp_lib_xfprintf
  237. int xfprintf(XFILE *file, const char *fmt, ...);
  238. #define lib_open_log _glp_lib_open_log
  239. int lib_open_log(const char *fname);
  240. /* open hardcopy file */
  241. #define lib_close_log _glp_lib_close_log
  242. int lib_close_log(void);
  243. /* close hardcopy file */
  244. #if 0
  245. #define xtime1 _glp_lib_xtime1
  246. glp_ulong xtime1(void);
  247. /* determine the current universal time */
  248. #endif
  249. #if 0
  250. #define xdifftime1 _glp_lib_xdifftime1
  251. double xdifftime1(glp_ulong t1, glp_ulong t0);
  252. /* compute the difference between two time values */
  253. #endif
  254. #define xtime _glp_lib_xtime
  255. xlong_t xtime(void);
  256. /* determine the current universal time */
  257. #define xdifftime _glp_lib_xdifftime
  258. double xdifftime(xlong_t t1, xlong_t t0);
  259. #define str2int _glp_lib_str2int
  260. int str2int(const char *str, int *val);
  261. /* convert character string to value of int type */
  262. #define str2num _glp_lib_str2num
  263. int str2num(const char *str, double *val);
  264. /* convert character string to value of double type */
  265. #define strspx _glp_lib_strspx
  266. char *strspx(char *str);
  267. /* remove all spaces from character string */
  268. #define strtrim _glp_lib_strtrim
  269. char *strtrim(char *str);
  270. /* remove trailing spaces from character string */
  271. #define strrev _glp_lib_strrev
  272. char *strrev(char *s);
  273. /* reverse character string */
  274. #define gcd _glp_lib_gcd
  275. int gcd(int x, int y);
  276. /* compute greatest common divisor of two integers */
  277. #define gcdn _glp_lib_gcdn
  278. int gcdn(int n, int x[]);
  279. /* compute greatest common divisor of n integers */
  280. #define round2n _glp_lib_round2n
  281. double round2n(double x);
  282. /* round floating-point number to nearest power of two */
  283. #define fp2rat _glp_lib_fp2rat
  284. int fp2rat(double x, double eps, double *p, double *q);
  285. /* convert floating-point number to rational number */
  286. #define jday _glp_lib_jday
  287. int jday(int d, int m, int y);
  288. /* convert calendar date to Julian day number */
  289. #define jdate _glp_lib_jdate
  290. int jdate(int j, int *d, int *m, int *y);
  291. /* convert Julian day number to calendar date */
  292. #define xdlopen _glp_xdlopen
  293. void *xdlopen(const char *module);
  294. #define xdlsym _glp_xdlsym
  295. void *xdlsym(void *h, const char *symbol);
  296. #define xdlclose _glp_xdlclose
  297. void xdlclose(void *h);
  298. #endif
  299. /* eof */