/home/coin/DyLP-1.1.1/DyLP/src/DylpStdLib/dylib_std.h

Go to the documentation of this file.
00001 #ifndef _DYLIB_STD_H
00002 #define _DYLIB_STD_H
00003 
00004 /*
00005   This file is part of the support library  for the OsiDylp LP distribution.
00006 
00007         Copyright (C) 2005 Lou Hafer
00008 
00009         School of Computing Science
00010         Simon Fraser University
00011         Burnaby, B.C., V5A 1S6, Canada
00012         lou@cs.sfu.ca
00013 
00014   This program is free software; you can redistribute it and/or modify it
00015   under the terms of the GNU General Public License as published by the Free
00016   Software Foundation; either version 2 of the License, or (at your option)
00017   any later version.
00018 
00019   This program is distributed in the hope that it will be useful, but WITHOUT
00020   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00021   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00022   more details.
00023 
00024   You should have received a copy of the GNU General Public License along
00025   with this program; if not, write to the Free Software Foundation, Inc.,
00026   51 Franklin St., Fifth Floor, Boston, MA  02110-1301  USA
00027 */
00028 
00029 /*
00030   @(#)loustd.h  1.5     09/25/04
00031   svn/cvs: $Id: dylib_std.h 99 2006-07-07 02:38:06Z lou $
00032 */
00033 
00034 /*
00035   This file contains common definitions.
00036 
00037   First thing to do is haul in the Ansi C standard definitions. Takes care of
00038   NULL plus a few more obscure definitions. Also haul in the standard library
00039   declarations.
00040 */
00041 
00042 #include <stddef.h>
00043 #include <stdlib.h>
00044 
00045 #include "DylpConfig.h"
00046 
00047 /*
00048   A utility definition which allows for easy suppression of unused variable
00049   warnings from GCC. Useful when a variable is used only for assert()
00050   statements, and for sccsid/cvsid strings.
00051 */
00052 #ifndef UNUSED
00053 # if defined(_GNU_SOURCE) || defined(__GNUC__)
00054 #   define UNUSED __attribute__((unused))
00055 # else
00056 #   define UNUSED
00057 # endif
00058 #endif
00059 
00060 /*
00061   Memory copy functions --- memcpy, memset, and other less common ones.
00062 */
00063   
00064 #include <string.h>
00065 
00066 /*
00067   We need a boolean type. Never could understand why C doesn't have this.
00068 
00069   [Aug 10, 01] For compatibility with C++, TRUE and FALSE are defined to be
00070   the corresponding C++ values. BOOL should be set in the compiler command
00071   line to be the storage type (char/short/int/long) that matches the size of
00072   a C++ "bool".  All these are necessary to link with and be called by C++
00073   code in osi-bonsai.
00074 */
00075 
00076 #ifndef __cplusplus
00077 #define FALSE 0
00078 #define TRUE 1
00079 # ifdef BOOL
00080   typedef BOOL bool ;
00081 # else
00082 /*
00083   You're in trouble. The likely source of the problem is that this file is
00084   being included in the course of a build controlled by a makefile that
00085   doesn't know about the booltype utility in the dylp distribution. See the
00086   Utils subdirectory, and also check the makefile for dylp to see how this is
00087   used.  If you don't want to fiddle with your build control files, just
00088   build booltype, run it, and edit in the appropriate definition. If you're
00089   not worried about C++ compatibility, int is a good as anything.
00090 */
00091 # warning The compile-time symbol BOOL is not defined (loustd.h)
00092   typedef int bool ;
00093 # endif
00094 #endif
00095 
00096 #ifdef __cplusplus
00097 #ifndef FALSE
00098 # define FALSE false
00099 #endif
00100 #ifndef TRUE
00101 # define TRUE true
00102 #endif
00103 #endif
00104 
00105 /*
00106   flags is used to indicate a data type composed of one-bit flags. Manipulated
00107   with the set of flag manipulation macros defined below.
00108 */
00109 
00110 typedef unsigned int flags ;
00111 
00112 #define setflg(zz_flgs,zz_flg) ((zz_flgs) |= (zz_flg))
00113 #define clrflg(zz_flgs,zz_flg) ((zz_flgs) &= ~(zz_flg))
00114 #define comflg(zz_flgs,zz_flg) ((zz_flgs) ^= (zz_flg))
00115 #define getflg(zz_flgs,zz_flg) ((zz_flgs)&(zz_flg))
00116 #define flgon(zz_flgs,zz_flg)  ((zz_flgs)&(zz_flg)?TRUE:FALSE)
00117 #define flgoff(zz_flgs,zz_flg) ((zz_flgs)&(zz_flg)?FALSE:TRUE)
00118 #define flgall(zz_flgs,zz_flg) ((((zz_flgs)&(zz_flg)) == (zz_flg))?TRUE:FALSE)
00119 
00120 
00121 /*
00122   lnk_struct is a general-purpose linked list structure.
00123 
00124   Field         Description
00125   -----         -----------
00126   llnxt         pointer to the next list element
00127   llval         pointer to the associated value 
00128 */
00129 
00130 typedef struct lnk_struct_tag
00131 { struct lnk_struct_tag *llnxt ;
00132   void *llval ; } lnk_struct ;
00133 
00134 #define lnk_in(qqlnk,qqval) ((qqlnk)->llval = (void *) (qqval))
00135 #define lnk_out(qqlnk,qqtype) ((qqtype) (qqlnk)->llval)
00136 
00137 
00138 /* Max and min macros */
00139 
00140 #define minn(qa,qb) (((qa) > (qb))?(qb):(qa))
00141 #define maxx(qa,qb) (((qa) > (qb))?(qa):(qb))
00142 
00143 
00144 /*
00145   Some macros to hide the memory allocation functions.
00146 
00147   The serious debugging versions of these macros (MALLOC_DEBUG = 2) use
00148   outfmt from the io library and assume the existence of a string, rtnnme
00149   (typically the name of the current subroutine) that's used to identify the
00150   origin of the message. There's enough information in the messages to track
00151   the allocation and deallocation of blocks, should you not have access to an
00152   interactive debugger with this capability.
00153 
00154   The casual debugging versions (MALLOC_DEBUG = 1) only check for a return
00155   value of 0 and print a message to stderr with the file and line number.
00156   This at least tells you when your code has core dumped because it ran out
00157   of space (as opposed to a bug you can actually fix).
00158 */
00159 
00160 #if (MALLOC_DEBUG == 2)
00161 
00162 #include "dylib_io.h"
00163 
00164 void *zz_ptr_zz ;
00165 ioid  zz_chn_zz ;
00166 
00167 #define MALLOC_DBG_INIT(chn) ( zz_chn_zz = chn )
00168 
00169 #define MALLOC(zz_sze_zz) \
00170   ( zz_ptr_zz = (void *) malloc(zz_sze_zz), \
00171     outfmt(zz_chn_zz,FALSE,":malloc: %d bytes at %#08x in %s.\n", \
00172             zz_sze_zz,zz_ptr_zz,rtnnme), \
00173     zz_ptr_zz )
00174 
00175 #define CALLOC(zz_cnt_zz,zz_sze_zz) \
00176   ( zz_ptr_zz = (void *) calloc(zz_cnt_zz,zz_sze_zz), \
00177     outfmt(zz_chn_zz,FALSE,":calloc: %d (%d*%d) bytes at %#08x in %s.\n", \
00178             zz_cnt_zz*zz_sze_zz,zz_cnt_zz,zz_sze_zz,zz_ptr_zz,rtnnme), \
00179     zz_ptr_zz )
00180 
00181 #define REALLOC(zz_rptr_zz,zz_sze_zz) \
00182   ( zz_ptr_zz = (void *) realloc(zz_rptr_zz,zz_sze_zz), \
00183     outfmt(zz_chn_zz,FALSE, \
00184            ":realloc: %#08x changed to %d bytes at %#08x in %s.\n", \
00185             zz_rptr_zz,zz_sze_zz,zz_ptr_zz,rtnnme), \
00186     zz_ptr_zz )
00187 
00188 #define FREE(zz_fptr_zz) \
00189   ( outfmt(zz_chn_zz,FALSE,":free: %#08x in %s.\n",zz_fptr_zz,rtnnme), \
00190     free((void *) zz_fptr_zz) )
00191 
00192 #elif (MALLOC_DEBUG == 1)
00193 
00194 #include <stdio.h>
00195 void *zz_ptr_zz ;
00196 
00197 #define MALLOC(zz_sze_zz) \
00198   ( zz_ptr_zz = (void *) malloc(zz_sze_zz), \
00199     (zz_ptr_zz != 0)?0:\
00200       fprintf(stderr,":malloc: failed to get %d bytes at %s:%d.\n", \
00201               zz_sze_zz,__FILE__,__LINE__), \
00202     zz_ptr_zz )
00203 
00204 #define CALLOC(zz_cnt_zz,zz_sze_zz) \
00205   ( zz_ptr_zz = (void *) calloc(zz_cnt_zz,zz_sze_zz), \
00206     (zz_ptr_zz != 0)?0:\
00207       fprintf(stderr,":calloc: failed to get %d bytes at %s:%d.\n", \
00208               zz_sze_zz*zz_cnt_zz,__FILE__,__LINE__), \
00209     zz_ptr_zz )
00210 
00211 #define REALLOC(zz_rptr_zz,zz_sze_zz) \
00212   ( zz_ptr_zz = (void *) realloc(zz_rptr_zz,zz_sze_zz), \
00213     (zz_ptr_zz != 0)?0:\
00214       fprintf(stderr,":realloc: failed to get %d bytes at %s:%d.\n", \
00215               zz_sze_zz,__FILE__,__LINE__), \
00216     zz_ptr_zz )
00217 
00218 #define FREE(zz_fptr_zz) free((void *) zz_fptr_zz)
00219 
00220 #else
00221 
00222 #define MALLOC_DBG_INIT(chn)
00223 
00224 #define MALLOC(zz_sze_zz) malloc(zz_sze_zz)
00225 
00226 #define CALLOC(zz_cnt_zz,zz_sze_zz) calloc(zz_cnt_zz,zz_sze_zz)
00227 
00228 #define REALLOC(zz_rptr_zz,zz_sze_zz) realloc(zz_rptr_zz,zz_sze_zz)
00229 
00230 #define FREE(zz_fptr_zz) free((void *) zz_fptr_zz)
00231 
00232 #endif
00233 
00234 
00235 #endif /* _DYLIB_STD_H */

Generated on Wed Aug 22 05:45:12 2007 by  doxygen 1.4.7