bu.h

Go to the documentation of this file.
00001 /*                            B U . H
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 /** @addtogroup libbu */
00022 /*@{*/
00023 /** @file bu.h
00024  * 
00025  * @brief
00026  *  Header file for the BRL-CAD Utility Library, LIBBU.
00027  *
00028  *  This library provides several layers of low-level utility routines,
00029  *  providing features that make coding much easier.
00030  *      Parallel processing support:  threads, sempahores, parallel-malloc.
00031  *      Consolodated logging support:  bu_log(), bu_bomb().
00032  *
00033  *  The intention is that these routines are general extensions to
00034  *  the data types offered by the C language itself, and to the
00035  *  basic C runtime support provided by the system LIBC.
00036  *
00037  *  All of the data types provided by this library are defined in bu.h;
00038  *  none of the routines in this library will depend on data types defined
00039  *  in other BRL-CAD header files, such as vmath.h.
00040  *  Look for those routines in LIBBN.
00041  *
00042  *  @@authorMichael John Muuss
00043  *
00044  *  @par Source
00045  *      The U. S. Army Research Laboratory                      @n 
00046  *      Aberdeen Proving Ground, Maryland  21005-5068  USA      @n
00047  *
00048  *  Proper include Sequencing -
00049 @code
00050         #include "common.h"
00051         #include <stdio.h>
00052         #include "machine.h"    /_* For fastf_t definition on this machine *_/
00053         #include "rtlist.h"     /_* OPTIONAL, auto-included by bu.h *_/
00054         #include "bu.h"
00055 @endcode
00056  *
00057  *  @par Libraries Used -
00058  *      -lm -lc
00059  *
00060  *  $Header: /cvsroot/brlcad/brlcad/include/bu.h,v 14.38 2006/09/18 05:24:07 lbutler Exp $
00061  */
00062 
00063 #ifndef __BU_H__
00064 #define __BU_H__
00065 
00066 #include "common.h"
00067 
00068 __BEGIN_DECLS
00069 
00070 /* Included for Tcl_Interp definition */
00071 #include "tcl.h"
00072 
00073 #ifndef BU_EXPORT
00074 #  if defined(_WIN32) && !defined(__CYGWIN__) && defined(BRLCAD_DLL)
00075 #    ifdef BU_EXPORT_DLL
00076 #      define BU_EXPORT __declspec(dllexport)
00077 #    else
00078 #      define BU_EXPORT __declspec(dllimport)
00079 #    endif
00080 #  else
00081 #    define BU_EXPORT
00082 #  endif
00083 #endif
00084 
00085 #include <setjmp.h>
00086 
00087 #define BU_H_VERSION    "@(#)$Header: /cvsroot/brlcad/brlcad/include/bu.h,v 14.38 2006/09/18 05:24:07 lbutler Exp $ (BRL)"
00088 
00089 
00090 /** @def BU_DIR_SEPARATOR
00091  * define BU_DIR_SEPARATOR to the directory separator character
00092  */
00093 #ifdef DIR_SEPARATOR
00094 #  define BU_DIR_SEPARATOR DIR_SEPARATOR
00095 #else
00096 #  ifdef DIR_SEPARATOR_2
00097 #    define BU_DIR_SEPARATOR DIR_SEPARATOR_2
00098 #  else
00099 #    ifdef _WIN32
00100 #      define BU_DIR_SEPARATOR '\\'
00101 #    else
00102 #      define BU_DIR_SEPARATOR '/'
00103 #    endif  /* _WIN32 */
00104 #  endif  /* DIR_SEPARATOR_2 */
00105 #endif  /* DIR_SEPARATOR */
00106 
00107 /** 
00108  * Maximum length of a filesystem path.  Typically defined in a system file
00109  * but if it isn't set, we create it.
00110  */
00111 #ifndef MAXPATHLEN
00112 #  define MAXPATHLEN 1024
00113 #endif
00114 
00115 /**
00116  * set to the path list separator character
00117  */
00118 #if defined(PATH_SEPARATOR)
00119 #  define BU_PATH_SEPARATOR PATH_SEPARATOR
00120 #else
00121 #  if defined(_WIN32)
00122 #    define BU_PATH_SEPARATOR ';'
00123 #  else
00124 #    define BU_PATH_SEPARATOR ':'
00125 #  endif  /* _WIN32 */
00126 #endif  /* PATH_SEPARATOR */
00127 
00128 
00129 /** @def BU_FLSTR
00130  *
00131  * Macro for getting a concatenated string of the current
00132  * file and line number.  Produces something of the form:
00133  *   "filename.c"":""1234"
00134  */
00135 #define bu_cpp_str(s) # s
00136 #define bu_cpp_xstr(s)  bu_cpp_str(s)
00137 #define bu_cpp_glue(a, b) a ## b
00138 #define bu_cpp_xglue(a, b) bu_cpp_glue(a, b)
00139 #define BU_FLSTR __FILE__ ":" bu_cpp_xstr(__LINE__)
00140 #define BU_QFLSTR bu_cpp_xstr(__FILE__ line __LINE__)
00141 
00142 /*
00143  *  Macros for providing function prototypes, regardless of whether
00144  *  the compiler understands them or not.
00145  *  It is vital that the argument list given for "args" be enclosed
00146  *  in parens.
00147  *  The setting of USE_PROTOTYPES is done in machine.h
00148  */
00149 #if USE_PROTOTYPES
00150 #       define  BU_EXTERN(type_and_name,args)   extern type_and_name args
00151 #       define  BU_ARGS(args)                   args
00152 #else
00153 #       define  BU_EXTERN(type_and_name,args)   extern type_and_name()
00154 #       define  BU_ARGS(args)                   ()
00155 #endif
00156 
00157 /**
00158  *                      B U _ F O R T R A N
00159  * @def BU_FORTRAN
00160  *
00161  *  This macro is used to take the 'C' function name,
00162  *  and convert it at compile time to the
00163  *  FORTRAN calling convention used for this particular system.
00164  *
00165  *  Both lower-case and upper-case alternatives have to be provided
00166  *  because there is no way to get the C preprocessor to change the
00167  *  case of a token.
00168  */
00169 #if defined(CRAY)
00170 #       define  BU_FORTRAN(lc,uc)       uc
00171 #endif
00172 #if defined(apollo) || defined(mips) || defined(aux) || defined(linux)
00173         /* Lower case, with a trailing underscore */
00174 #ifdef __STDC__
00175 #       define  BU_FORTRAN(lc,uc)       lc ## _
00176 #else
00177 #       define  BU_FORTRAN(lc,uc)       lc/**/_
00178 #endif
00179 #endif
00180 #if !defined(BU_FORTRAN)
00181 #       define  BU_FORTRAN(lc,uc)       lc
00182 #endif
00183 
00184 /**
00185  * Handy memory allocator macro
00186  *
00187  * @def BU_GETSTRUCT(ptr,struct_type)
00188  * Allocate storage for a structure
00189  *
00190  * @def BU_GETUNION(ptr,union_type)
00191  * Allocate storage for a union
00192 */
00193 /* Acquire storage for a given struct, eg, BU_GETSTRUCT(ptr,structname); */
00194 #if __STDC__
00195 #  define BU_GETSTRUCT(_p,_str) \
00196         _p = (struct _str *)bu_calloc(1,sizeof(struct _str), #_str " (getstruct)" BU_FLSTR)
00197 #  define BU_GETUNION(_p,_unn) \
00198         _p = (union _unn *)bu_calloc(1,sizeof(union _unn), #_unn " (getunion)" BU_FLSTR)
00199 #else
00200 #  define BU_GETSTRUCT(_p,_str) \
00201         _p = (struct _str *)bu_calloc(1,sizeof(struct _str), "_str (getstruct)" )
00202 #  define BU_GETUNION(_p,_unn) \
00203         _p = (union _unn *)bu_calloc(1,sizeof(union _unn), "_unn (getunion)" )
00204 #endif
00205 
00206 /**
00207  *                B U _ G E T T Y P E
00208  *
00209  *
00210  * Acquire storage for a given TYPE, eg, BU_GETTYPE(ptr, typename);
00211  * Equivalent to BU_GETSTRUCT, except without the 'struct' Useful
00212  * for typedef'ed objects.
00213  */
00214 #if __STDC__
00215 #  define BU_GETTYPE(_p,_type) \
00216         _p = (_type *)bu_calloc(1,sizeof(_type), #_type " (gettype)" )
00217 #else
00218 #  define BU_GETTYPE(_p,_type) \
00219         _p = (_type *)bu_calloc(1,sizeof(_type), "_type (getstruct)")
00220 #endif
00221 
00222 
00223 
00224 /*                      B U _ C K M A G
00225  *
00226  * @def BU_CKMAG(ptr,magic,string)
00227  *
00228  *  Macros to check and validate a structure pointer, given that
00229  *  the first entry in the structure is a magic number.
00230  */
00231 #ifdef NO_BOMBING_MACROS
00232 #  define BU_CKMAG(_ptr, _magic, _str)
00233 #  define BU_CKMAG_TCL(_interp, _ptr, _magic, _str)
00234 #else
00235 #  define BU_CKMAG(_ptr, _magic, _str)  \
00236         if( !(_ptr) || ( ((long)(_ptr)) & (sizeof(long)-1) ) || \
00237             *((unsigned long *)(_ptr)) != (unsigned long)(_magic) )  { \
00238                 bu_badmagic( (long *)(_ptr), (unsigned long)_magic, _str, __FILE__, __LINE__ ); \
00239         }
00240 #  define BU_CKMAG_TCL(_interp, _ptr, _magic, _str)     \
00241         if( !(_ptr) || ( ((long)(_ptr)) & (sizeof(long)-1) ) || \
00242              *((long *)(_ptr)) != (_magic) )  { \
00243                 bu_badmagic_tcl( (_interp), (long *)(_ptr), (unsigned long)_magic, _str, __FILE__, __LINE__ ); \
00244                 return TCL_ERROR; \
00245         }
00246 #endif
00247 
00248 /**                     B U _ A S S E R T
00249  *
00250  * @def BU_ASSERT(eqn)
00251  *  Quick and easy macros to generate an informative error message and
00252  *  abort execution if the specified condition does not hold true.
00253  * @def BU_ASSERT_PTR(eqn)
00254  *  Quick and easy macros to generate an informative error message and
00255  *  abort execution if the specified condition does not hold true.
00256  * @def BU_ASSERT_LONG(eqn)
00257  *  Quick and easy macros to generate an informative error message and
00258  *  abort execution if the specified condition does not hold true.
00259  * @def BU_ASSERT_DOUBLE(eqn)
00260  *  Quick and easy macros to generate an informative error message and
00261  *  abort execution if the specified condition does not hold true.
00262  *
00263  *  Example:            BU_ASSERT_LONG( j+7, <, 42 );
00264  */
00265 #ifdef NO_BOMBING_MACROS
00266 #  define BU_ASSERT(_equation)
00267 #else
00268 #  ifdef __STDC__
00269 #    define BU_ASSERT(_equation)        \
00270         if( !(_equation) )  { \
00271                 bu_log("BU_ASSERT( " #_equation " ) failed, file %s, line %d\n", \
00272                         __FILE__, __LINE__ ); \
00273                 bu_bomb("assertion failure\n"); \
00274         }
00275 #  else
00276 #    define BU_ASSERT(_equation)        \
00277         if( !(_equation) )  { \
00278                 bu_log("BU_ASSERT( _equation ) failed, file %s, line %d\n", \
00279                         __FILE__, __LINE__ ); \
00280                 bu_bomb("assertion failure\n"); \
00281         }
00282 #  endif
00283 #endif
00284 
00285 #ifdef NO_BOMBING_MACROS
00286 #  define BU_ASSERT_PTR(_lhs,_relation,_rhs)
00287 #else
00288 #  ifdef __STDC__
00289 #    define BU_ASSERT_PTR(_lhs,_relation,_rhs)  \
00290         if( !((_lhs) _relation (_rhs)) )  { \
00291                 bu_log("BU_ASSERT_PTR( " #_lhs #_relation #_rhs " ) failed, lhs=x%lx, rhs=x%lx, file %s, line %d\n", \
00292                         (long)(_lhs), (long)(_rhs),\
00293                         __FILE__, __LINE__ ); \
00294                 bu_bomb("BU_ASSERT_PTR failure\n"); \
00295         }
00296 #  else
00297 #    define BU_ASSERT_PTR(_lhs,_relation,_rhs)  \
00298         if( !((_lhs) _relation (_rhs)) )  { \
00299                 bu_log("BU_ASSERT_PTR( _lhs _relation _rhs ) failed, lhs=x%lx, rhs=x%lx, file %s, line %d\n", \
00300                         (long)(_lhs), (long)(_rhs),\
00301                         __FILE__, __LINE__ ); \
00302                 bu_bomb("BU_ASSERT_PTR failure\n"); \
00303         }
00304 #  endif
00305 #endif
00306 
00307 
00308 #ifdef NO_BOMBING_MACROS
00309 #  define BU_ASSERT_LONG(_lhs,_relation,_rhs)
00310 #else
00311 #  ifdef __STDC__
00312 #    define BU_ASSERT_LONG(_lhs,_relation,_rhs) \
00313         if( !((_lhs) _relation (_rhs)) )  { \
00314                 bu_log("BU_ASSERT_LONG( " #_lhs #_relation #_rhs " ) failed, lhs=%ld, rhs=%ld, file %s, line %d\n", \
00315                         (long)(_lhs), (long)(_rhs),\
00316                         __FILE__, __LINE__ ); \
00317                 bu_bomb("BU_ASSERT_LONG failure\n"); \
00318         }
00319 #  else
00320 #    define BU_ASSERT_LONG(_lhs,_relation,_rhs) \
00321         if( !((_lhs) _relation (_rhs)) )  { \
00322                 bu_log("BU_ASSERT_LONG( _lhs _relation _rhs ) failed, lhs=%ld, rhs=%ld, file %s, line %d\n", \
00323                         (long)(_lhs), (long)(_rhs),\
00324                         __FILE__, __LINE__ ); \
00325                 bu_bomb("BU_ASSERT_LONG failure\n"); \
00326         }
00327 #  endif
00328 #endif
00329 
00330 
00331 #ifdef NO_BOMBING_MACROS
00332 #  define BU_ASSERT_DOUBLE(_lhs,_relation,_rhs)
00333 #else
00334 #  ifdef __STDC__
00335 #    define BU_ASSERT_DOUBLE(_lhs,_relation,_rhs)       \
00336         if( !((_lhs) _relation (_rhs)) )  { \
00337                 bu_log("BU_ASSERT_DOUBLE( " #_lhs #_relation #_rhs " ) failed, lhs=%lf, rhs=%lf, file %s, line %d\n", \
00338                         (double)(_lhs), (double)(_rhs),\
00339                         __FILE__, __LINE__ ); \
00340                 bu_bomb("BU_ASSERT_DOUBLE failure\n"); \
00341         }
00342 #  else
00343 #    define BU_ASSERT_DOUBLE(_lhs,_relation,_rhs)       \
00344         if( !((_lhs) _relation (_rhs)) )  { \
00345                 bu_log("BU_ASSERT_DOUBLE( _lhs _relation _rhs ) failed, lhs=%lf, rhs=%lf, file %s, line %d\n", \
00346                         (long)(_lhs), (long)(_rhs),\
00347                         __FILE__, __LINE__ ); \
00348                 bu_bomb("BU_ASSERT_DOUBLE failure\n"); \
00349         }
00350 #  endif
00351 #endif
00352 /*@}*/
00353 
00354 /*----------------------------------------------------------------------*/
00355 /** @addtogroup hton */
00356 /*@{*/
00357 /**
00358  *  Sizes of "network" format data.
00359  *  We use the same convention as the TCP/IP specification,
00360  *  namely, big-Endian, IEEE format, twos compliment.
00361  *  This is the BRL-CAD external data representation (XDR).
00362  *  See also the support routines in libbu/xdr.c
00363  *
00364  */
00365 #define SIZEOF_NETWORK_SHORT    2       /* htons(), bu_gshort(), bu_pshort() */
00366 #define SIZEOF_NETWORK_LONG     4       /* htonl(), bu_glong(), bu_plong() */
00367 #define SIZEOF_NETWORK_FLOAT    4       /* htonf() */
00368 #define SIZEOF_NETWORK_DOUBLE   8       /* htond() */
00369 /*@}*/
00370 
00371 /*----------------------------------------------------------------------*/
00372 /* convert.c
00373  */
00374 /** @addtogroup conv */
00375 /**@{*/
00376 /*
00377  * Forward declarations.
00378  */
00379 BU_EXPORT BU_EXTERN(int bu_cv_itemlen,
00380                     (int cookie));
00381 BU_EXPORT BU_EXTERN(int bu_cv_cookie,
00382                     (char *in));
00383 BU_EXPORT BU_EXTERN(int bu_cv_optimize,
00384                     (int cookie));
00385 BU_EXPORT BU_EXTERN(int bu_cv_w_cookie,
00386                     (genptr_t,
00387                      int,
00388                      size_t,
00389                      genptr_t,
00390                      int,
00391                      int));
00392 
00393 BU_EXPORT BU_EXTERN(int bu_cv_ntohss,
00394                     (signed short *,
00395                      size_t,
00396                      genptr_t,
00397                      int));
00398 BU_EXPORT BU_EXTERN(int bu_cv_ntohus,
00399                     (unsigned short *,
00400                      size_t,
00401                      genptr_t,
00402                      int));
00403 BU_EXPORT BU_EXTERN(int bu_cv_ntohsl,
00404                     (signed long int *,
00405                      size_t,
00406                      genptr_t,
00407                      int));
00408 BU_EXPORT BU_EXTERN(int bu_cv_ntohul,
00409                     (unsigned long int *,
00410                      size_t,
00411                      genptr_t,
00412                      int));
00413 BU_EXPORT BU_EXTERN(int bu_cv_htonss,
00414                     (genptr_t,
00415                      size_t,
00416                      signed short *,
00417                      int));
00418 BU_EXPORT BU_EXTERN(int bu_cv_htonus,
00419                     (genptr_t,
00420                      size_t,
00421                      unsigned short *,
00422                      int));
00423 BU_EXPORT BU_EXTERN(int bu_cv_htonsl,
00424                     (genptr_t,
00425                      size_t,
00426                      long *,
00427                      int));
00428 BU_EXPORT BU_EXTERN(int bu_cv_htonul,
00429                     (genptr_t,
00430                      size_t,
00431                      unsigned long *,
00432                      int));
00433 
00434 /*
00435  * Theses should be moved to a header file soon.
00436  */
00437 #define CV_CHANNEL_MASK 0x00ff
00438 #define CV_HOST_MASK    0x0100
00439 #define CV_SIGNED_MASK  0x0200
00440 #define CV_TYPE_MASK    0x1c00  /* 0001 1100 0000 0000 */
00441 #define CV_CONVERT_MASK 0x6000  /* 0110 0000 0000 0000 */
00442 
00443 #define CV_TYPE_SHIFT   10
00444 #define CV_CONVERT_SHIFT 13
00445 
00446 #define CV_8    0x0400
00447 #define CV_16   0x0800
00448 #define CV_32   0x0c00
00449 #define CV_64   0x1000
00450 #define CV_D    0x1400
00451 
00452 #define CV_CLIP         0x0000
00453 #define CV_NORMAL       0x2000
00454 #define CV_LIT          0x4000
00455 
00456 #define IND_NOTSET      0
00457 #define IND_BIG         1
00458 #define IND_LITTLE      2
00459 #define IND_ILL         3               /* PDP-11 */
00460 #define IND_CRAY        4
00461 /**@}*/
00462 
00463 /*----------------------------------------------------------------------*/
00464 /* list.c */
00465 
00466 /** @addtogroup bu_list
00467  *                                                                      
00468  *                           B U _ L I S T                              
00469  *
00470  *                      Doubly-linked list support                      
00471  *                                                                      
00472  *  These macros assume that all user-provided structures will have     
00473  *  a "struct bu_list" as their first element (often named "l" [ell]).  
00474  *  Thus, a pointer to the bu_list struct is a "pun" for the            
00475  *  user-provided structure as well, and the pointers can be converted  
00476  *  back and forth safely with type casts.                              
00477  *                                                                      
00478  *  Furthermore, the head of the linked list could be                   
00479  *  a full instance of the user-provided structure                      
00480  *  (although the storage-conscious programmer could make the head      
00481  *  just an bu_list structure, with careful type casting).              
00482  *  This results in a doubly-linked circular list, with the head        
00483  *  having the same shape as all the list members.                      
00484  *  The application is free to make use of this symmetry and store      
00485  *  data values in the head, or the extra storage in the head can       
00486  *  be ignored.                                                         
00487  *                                                                      
00488  *  Where a macro expects an argument "p", it should be a pointer to    
00489  *  a user-provided structure.                                          
00490  *                                                                      
00491  *  Where a macro expects an argument "hp", it should be a pointer to   
00492  *  a "struct bu_list" located in the list head, e.g., &(head.l).       
00493  *                                                                      
00494  *  Where a macro expects an argument "old", "new", or "cur", it should 
00495  *  be a pointer to the "struct bu_list" located either                 
00496  *  in a user-provided structure, e.g. &((p)->l),                       
00497  *  or for the case of "old" it may also be in the list head, e.g.      
00498  *      BU_LIST_INSERT( &(head.l), &((p)->l) );                         
00499  *                                                                      
00500  *  Dequeueing the head of a list is a valid and                        
00501  *  well defined operation which should be performed with caution.      
00502  *  Unless a pointer to some other element of the list is retained      
00503  *  by the application, the rest of the linked list can no longer be    
00504  *  referred to.                                                        
00505  *                                                                      
00506  *  The "magic" field of the list header _must_ be set to the constant  
00507  *  BU_LIST_HEAD_MAGIC, but the "magic" field of all list members       
00508  *  should be established by user code, to identify the type of         
00509  *  structure that the bu_list structure is embedded in.                
00510  *  It is permissible for one list to contain an arbitrarily mixed      
00511  *  set of user "magic" numbers, as long as the head is properly marked.
00512  *                                                                      
00513  *  There is a dual set of terminology used in some of the macros:      
00514  *      FIRST / LAST    from the point of view of the list head         
00515  *      NEXT / PREV     from the point of view of a list member         
00516  *      forw / back     the actual pointer names                        
00517  *                                                                      
00518  ************************************************************************/
00519 /**@{*/
00520 
00521 struct bu_list {
00522     long                magic;          /**< @brief Magic # for mem id/check */
00523     struct bu_list      *forw;          /**< @brief "forward", "next" */
00524     struct bu_list      *back;          /**< @brief "back", "last" */
00525 };
00526 #define BU_LIST_HEAD_MAGIC      0x01016580      /* Magic num for list head */
00527 #define BU_LIST_NULL    ((struct bu_list *)0)
00528 
00529 typedef struct bu_list bu_list_t;
00530 
00531 BU_EXPORT BU_EXTERN(struct bu_list *bu_list_new, ());
00532 BU_EXPORT BU_EXTERN(struct bu_list *bu_list_pop, (struct bu_list *hp));
00533 
00534 #define BU_LIST_CLOSE( hp ) { \
00535         assert( (hp) != NULL ); \
00536         if( (hp) == NULL ) \
00537                 return; \
00538         assert( BU_LIST_IS_EMPTY( (hp) ) ); \
00539         bu_list_free( (hp) ); \
00540         bu_free( (char *)(hp), "bu_list head" ); \
00541 }
00542 
00543 
00544 /*
00545  *  Insert "new" item in front of "old" item.  Often, "old" is the head.
00546  *  To put the new item at the tail of the list, insert before the head, e.g.
00547  *      BU_LIST_INSERT( &(head.l), &((p)->l) );
00548  */
00549 #define BU_LIST_INSERT(old,new) { \
00550         (new)->back = (old)->back; \
00551         (old)->back = (new); \
00552         (new)->forw = (old); \
00553         (new)->back->forw = (new);  }
00554 
00555 /*
00556  *  Append "new" item after "old" item.  Often, "old" is the head.
00557  *  To put the new item at the head of the list, append after the head, e.g.
00558  *      BU_LIST_APPEND( &(head.l), &((p)->l) );
00559  */
00560 #define BU_LIST_APPEND(old,new) { \
00561         (new)->forw = (old)->forw; \
00562         (new)->back = (old); \
00563         (old)->forw = (new); \
00564         (new)->forw->back = (new);  }
00565 
00566 /* Dequeue "cur" item from anywhere in doubly-linked list */
00567 #define BU_LIST_DEQUEUE(cur)    { \
00568         (cur)->forw->back = (cur)->back; \
00569         (cur)->back->forw = (cur)->forw; \
00570         (cur)->forw = (cur)->back = BU_LIST_NULL;  /* sanity */ }
00571 
00572 /* Dequeue "cur" but do not fix its links */
00573 #define BU_LIST_DQ(cur) {\
00574         (cur)->forw->back = (cur)->back; \
00575         (cur)->back->forw = (cur)->forw; }
00576 
00577 #define BU_LIST_DQ_T(cur, type) (\
00578         (cur)->forw->back = (cur)->back, \
00579         (cur)->back->forw = (cur)->forw, \
00580         (type *)(cur) )
00581 
00582 /* This version of BU_LIST_DEQUEUE uses the comma operator
00583  * inorder to return a typecast version of the dequeued pointer
00584  */
00585 #define BU_LIST_DEQUEUE_T( cur, type ) (\
00586         (cur)->forw->back = (cur)->back, \
00587         (cur)->back->forw = (cur)->forw, \
00588         (cur)->forw = (cur)->back = BU_LIST_NULL, \
00589         (type *)(cur) )
00590 
00591 
00592 /*
00593  *  The Stack Discipline
00594  *
00595  *  BU_LIST_PUSH places p at the tail of hp.
00596  *  BU_LIST_POP  sets p to last element in hp's list (else NULL)
00597  *                and, if p is non-null, dequeues it.
00598  */
00599 #define BU_LIST_PUSH(hp,p)                                      \
00600         BU_LIST_APPEND(hp, (struct bu_list *)(p))
00601 
00602 #define BU_LIST_POP(structure,hp,p)                             \
00603         {                                                       \
00604                 if (BU_LIST_NON_EMPTY(hp))                              \
00605                 {                                                       \
00606                     (p) = ((struct structure *)((hp)->forw));           \
00607                     BU_LIST_DEQUEUE((struct bu_list *)(p));             \
00608                 }                                                       \
00609                 else                                                    \
00610                      (p) = (struct structure *) 0;                      \
00611         }
00612 
00613 #define BU_LIST_POP_T(hp, type )                                \
00614         (type *)bu_list_pop( hp )
00615 
00616 /**
00617  *  "Bulk transfer" all elements from the list headed by src_hd
00618  *  onto the list headed by dest_hd, without examining every element
00619  *  in the list.  src_hd is left with a valid but empty list.
00620  *
00621  *  BU_LIST_INSERT_LIST places src_hd elements at head of dest_hd list,
00622  *  BU_LIST_APPEND_LIST places src_hd elements at end of dest_hd list.
00623  */
00624 #define BU_LIST_INSERT_LIST(dest_hp,src_hp) \
00625         if( BU_LIST_NON_EMPTY(src_hp) )  { \
00626                 register struct bu_list *_first = (src_hp)->forw; \
00627                 register struct bu_list *_last = (src_hp)->back; \
00628                 (dest_hp)->forw->back = _last; \
00629                 _last->forw = (dest_hp)->forw; \
00630                 (dest_hp)->forw = _first; \
00631                 _first->back = (dest_hp); \
00632                 (src_hp)->forw = (src_hp)->back = (src_hp); \
00633         }
00634 
00635 #define BU_LIST_APPEND_LIST(dest_hp,src_hp) \
00636         if( BU_LIST_NON_EMPTY(src_hp) )  {\
00637                 register struct bu_list *_first = (src_hp)->forw; \
00638                 register struct bu_list *_last = (src_hp)->back; \
00639                 _first->back = (dest_hp)->back; \
00640                 (dest_hp)->back->forw = _first; \
00641                 (dest_hp)->back = _last; \
00642                 _last->forw = (dest_hp); \
00643                 (src_hp)->forw = (src_hp)->back = (src_hp); \
00644         }
00645 
00646 /** Test if a doubly linked list is empty, given head pointer */
00647 #define BU_LIST_IS_EMPTY(hp)    ((hp)->forw == (hp))
00648 #define BU_LIST_NON_EMPTY(hp)   ((hp)->forw != (hp))
00649 #define BU_LIST_NON_EMPTY_P(p,structure,hp)     \
00650         (((p)=(struct structure *)((hp)->forw)) != (struct structure *)(hp))
00651 #define BU_LIST_IS_CLEAR(hp)    ((hp)->magic == 0 && \
00652                         (hp)->forw == BU_LIST_NULL && \
00653                         (hp)->back == BU_LIST_NULL)
00654 
00655 /* Handle list initialization */
00656 #define BU_LIST_UNINITIALIZED(hp)       ((hp)->forw == BU_LIST_NULL)
00657 #define BU_LIST_IS_INITIALIZED(hp)      ((hp)->forw != BU_LIST_NULL)
00658 #define BU_LIST_INIT(hp)        { \
00659         (hp)->forw = (hp)->back = (hp); \
00660         (hp)->magic = BU_LIST_HEAD_MAGIC;       /* used by circ. macros */ }
00661 #define BU_LIST_MAGIC_SET(hp,val)       {(hp)->magic = (val);}
00662 #define BU_LIST_MAGIC_OK(hp,val)        ((hp)->magic == (val))
00663 #define BU_LIST_MAGIC_WRONG(hp,val)     ((hp)->magic != (val))
00664 
00665 /* Return re-cast pointer to first element on list.
00666  * No checking is performed to see if list is empty.
00667  */
00668 #define BU_LIST_LAST(structure,hp)      \
00669         ((struct structure *)((hp)->back))
00670 #define BU_LIST_BACK(structure,hp)      \
00671         ((struct structure *)((hp)->back))
00672 #define BU_LIST_PREV(structure,hp)      \
00673         ((struct structure *)((hp)->back))
00674 #define BU_LIST_FIRST(structure,hp)     \
00675         ((struct structure *)((hp)->forw))
00676 #define BU_LIST_FORW(structure,hp)      \
00677         ((struct structure *)((hp)->forw))
00678 #define BU_LIST_NEXT(structure,hp)      \
00679         ((struct structure *)((hp)->forw))
00680 
00681 /* Boolean test to see if current list element is the head */
00682 #define BU_LIST_IS_HEAD(p,hp)   \
00683         (((struct bu_list *)(p)) == (hp))
00684 #define BU_LIST_NOT_HEAD(p,hp)  \
00685         (((struct bu_list *)(p)) != (hp))
00686 #define BU_CK_LIST_HEAD( _p )   BU_CKMAG( (_p), BU_LIST_HEAD_MAGIC, "bu_list")
00687 
00688 /* Boolean test to see if previous list element is the head */
00689 #define BU_LIST_PREV_IS_HEAD(p,hp)\
00690         (((struct bu_list *)(p))->back == (hp))
00691 #define BU_LIST_PREV_NOT_HEAD(p,hp)\
00692         (((struct bu_list *)(p))->back != (hp))
00693 
00694 /* Boolean test to see if the next list element is the head */
00695 #define BU_LIST_NEXT_IS_HEAD(p,hp)      \
00696         (((struct bu_list *)(p))->forw == (hp))
00697 #define BU_LIST_NEXT_NOT_HEAD(p,hp)     \
00698         (((struct bu_list *)(p))->forw != (hp))
00699 
00700 #define BU_LIST_EACH( hp, p, type ) \
00701          for( (p)=(type *)BU_LIST_FIRST(bu_list,hp); \
00702               BU_LIST_NOT_HEAD(p,hp); \
00703               (p)=(type *)BU_LIST_PNEXT(bu_list,p) ) \
00704 
00705 #define BU_LIST_REVEACH( hp, p, type ) \
00706          for( (p)=(type *)BU_LIST_LAST(bu_list,hp); \
00707               BU_LIST_NOT_HEAD(p,hp); \
00708               (p)=(type *)BU_LIST_PREV(bu_list,((struct bu_list *)(p))) ) \
00709 
00710 #define BU_LIST_TAIL( hp, start, p, type ) \
00711          for( (p)=(type *)start ; \
00712               BU_LIST_NOT_HEAD(p,hp); \
00713               (p)=(type *)BU_LIST_PNEXT(bu_list,(p)) )
00714 
00715 /**
00716  *  Intended as innards for a for() loop to visit all nodes on list, e.g.:
00717  *      for( BU_LIST_FOR( p, structure, hp ) )  {
00718  *              work_on( p );
00719  *      }
00720  */
00721 #define BU_LIST_FOR(p,structure,hp)     \
00722         (p)=BU_LIST_FIRST(structure,hp); \
00723         BU_LIST_NOT_HEAD(p,hp); \
00724         (p)=BU_LIST_PNEXT(structure,p)
00725 
00726 #define BU_LIST_FOR_BACKWARDS(p,structure,hp)   \
00727         (p)=BU_LIST_LAST(structure,hp); \
00728         BU_LIST_NOT_HEAD(p,hp); \
00729         (p)=BU_LIST_PLAST(structure,p)
00730 
00731 /**
00732  *  Process all the list members except hp and the actual head.
00733  *  Useful when starting somewhere besides the head.
00734  */
00735 #define BU_LIST_FOR_CIRC(p,structure,hp)        \
00736         (p)=BU_LIST_PNEXT_CIRC(structure,hp); \
00737         (p) != (hp); \
00738         (p)=BU_LIST_PNEXT_CIRC(structure,p)
00739 
00740 /*
00741  *  Intended as innards for a for() loop to visit elements of two lists
00742  *      in tandem, e.g.:
00743  *          for (BU_LIST_FOR2(p1, p2, structure, hp1, hp2) ) {
00744  *                  process( p1, p2 );
00745  *          }
00746  */
00747 #define BU_LIST_FOR2(p1,p2,structure,hp1,hp2)                           \
00748                 (p1)=BU_LIST_FIRST(structure,hp1),                      \
00749                 (p2)=BU_LIST_FIRST(structure,hp2);                      \
00750                 BU_LIST_NOT_HEAD((struct bu_list *)(p1),(hp1)) &&       \
00751                 BU_LIST_NOT_HEAD((struct bu_list *)(p2),(hp2));         \
00752                 (p1)=BU_LIST_NEXT(structure,(struct bu_list *)(p1)),    \
00753                 (p2)=BU_LIST_NEXT(structure,(struct bu_list *)(p2))
00754 
00755 /**
00756  *  Innards for a while() loop that constantly picks off the first element.
00757  *  Useful mostly for a loop that will dequeue every list element, e.g.:
00758  *      while( BU_LIST_WHILE(p, structure, hp) )  {
00759  *@n            BU_LIST_DEQUEUE( &(p->l) );
00760  *@n            free( (char *)p );
00761  *@n    }
00762  */
00763 #define BU_LIST_WHILE(p,structure,hp)   \
00764         (((p)=(struct structure *)((hp)->forw)) != (struct structure *)(hp))
00765 
00766 /** Return the magic number of the first (or last) item on a list */
00767 #define BU_LIST_FIRST_MAGIC(hp)         ((hp)->forw->magic)
00768 #define BU_LIST_LAST_MAGIC(hp)          ((hp)->back->magic)
00769 
00770 /** Return pointer to next (or previous) element, which may be the head */
00771 #define BU_LIST_PNEXT(structure,p)      \
00772         ((struct structure *)(((struct bu_list *)(p))->forw))
00773 #define BU_LIST_PLAST(structure,p)      \
00774         ((struct structure *)(((struct bu_list *)(p))->back))
00775 
00776 /** Return pointer two links away, which may include the head */
00777 #define BU_LIST_PNEXT_PNEXT(structure,p)        \
00778         ((struct structure *)(((struct bu_list *)(p))->forw->forw))
00779 #define BU_LIST_PNEXT_PLAST(structure,p)        \
00780         ((struct structure *)(((struct bu_list *)(p))->forw->back))
00781 #define BU_LIST_PLAST_PNEXT(structure,p)        \
00782         ((struct structure *)(((struct bu_list *)(p))->back->forw))
00783 #define BU_LIST_PLAST_PLAST(structure,p)        \
00784         ((struct structure *)(((struct bu_list *)(p))->back->back))
00785 
00786 /** Return pointer to circular next element; ie, ignoring the list head */
00787 #define BU_LIST_PNEXT_CIRC(structure,p) \
00788         ((BU_LIST_FIRST_MAGIC((struct bu_list *)(p)) == BU_LIST_HEAD_MAGIC) ? \
00789                 BU_LIST_PNEXT_PNEXT(structure,(struct bu_list *)(p)) : \
00790                 BU_LIST_PNEXT(structure,p) )
00791 
00792 /** Return pointer to circular last element; ie, ignoring the list head */
00793 #define BU_LIST_PPREV_CIRC(structure,p) \
00794         ((BU_LIST_LAST_MAGIC((struct bu_list *)(p)) == BU_LIST_HEAD_MAGIC) ? \
00795                 BU_LIST_PLAST_PLAST(structure,(struct bu_list *)(p)) : \
00796                 BU_LIST_PLAST(structure,p) )
00797 
00798 /**
00799  *  Support for membership on multiple linked lists.
00800  *
00801  *  When a structure of type '_type' contains more than one bu_list structure
00802  *  within it (such as the NMG edgeuse), this macro can be used to convert
00803  *  a pointer '_ptr2' to a "midway" bu_list structure (an element called
00804  *  '_name2' in structure '_type') back into a pointer to the overall
00805  *  enclosing structure.  Examples:
00806  *
00807  *  eu = BU_LIST_MAIN_PTR( edgeuse, midway, l2 );
00808  *
00809  *  eu1 = BU_LIST_MAIN_PTR(edgeuse, BU_LIST_FIRST(bu_list, &eg1->eu_hd2), l2);
00810  *
00811  *  Files using BU_LIST_MAIN_PTR will need to include stddef.h
00812  */
00813 #define BU_LIST_MAIN_PTR(_type, _ptr2, _name2)  \
00814         ((struct _type *)(((char *)(_ptr2)) - offsetof(struct _type, _name2.magic)))
00815 /*@}*/
00816 /*----------------------------------------------------------------------*/
00817 /* bitv.c */
00818 /*
00819  *                      B U _ B I T V
00820  */
00821 /** @addtogroup bitv */
00822 /**@{*/
00823 /**
00824  * 
00825  * @brief
00826  *  Bit vector data structure.
00827  *
00828  *  bu_bitv uses a little-endian encoding, placing bit 0 on the
00829  *  right side of the 0th word.
00830  *  This is done only because left-shifting a 1 can be done in an
00831  *  efficient word-length-independent manner;
00832  *  going the other way would require a compile-time constant with
00833  *  only the sign bit set, and an unsigned right shift, which some
00834  *  machines don't have in hardware, or an extra subtraction.
00835  *
00836  *  Application code should *never* peak at the bit-buffer; use the macros.
00837  *
00838  *  The external hex form is most signigicant byte first (bit 0 is at the right).
00839  *  Note that MUVES does it differently
00840  */
00841 struct bu_bitv {
00842     struct bu_list      l;              /**< @brief linked list for caller's use  */
00843     unsigned int        nbits;          /**< @brief actual size of bits[], in bits  */
00844     bitv_t              bits[2];        /**< @brief variable size array  */
00845 };
00846 
00847 #define BU_BITV_MAGIC           0x62697476      /* 'bitv' */
00848 #define BU_CK_BITV(_vp)         BU_CKMAG(_vp, BU_BITV_MAGIC, "bu_bitv")
00849 
00850 /*
00851  *  Bit-string manipulators for arbitrarily long bit strings
00852  *  stored as an array of bitv_t's.
00853  */
00854 #define BU_BITS2BYTES(_nb)      (BU_BITS2WORDS(_nb)*sizeof(bitv_t))
00855 #define BU_BITS2WORDS(_nb)      (((_nb)+BITV_MASK)>>BITV_SHIFT)
00856 #define BU_WORDS2BITS(_nw)      ((_nw)*sizeof(bitv_t)*8)
00857 
00858 #if 1
00859 #define BU_BITTEST(_bv,bit)     \
00860         (((_bv)->bits[(bit)>>BITV_SHIFT] & (((bitv_t)1)<<((bit)&BITV_MASK)))!=0)
00861 #else
00862 static __inline__ int BU_BITTEST(volatile void * addr, int nr)
00863 {
00864         int oldbit;
00865 
00866         __asm__ __volatile__(
00867                 "btl %2,%1\n\tsbbl %0,%0"
00868                 :"=r" (oldbit)
00869                 :"m" (addr),"Ir" (nr));
00870         return oldbit;
00871 }
00872 #endif
00873 
00874 #define BU_BITSET(_bv,bit)      \
00875         ((_bv)->bits[(bit)>>BITV_SHIFT] |= (((bitv_t)1)<<((bit)&BITV_MASK)))
00876 #define BU_BITCLR(_bv,bit)      \
00877         ((_bv)->bits[(bit)>>BITV_SHIFT] &= ~(((bitv_t)1)<<((bit)&BITV_MASK)))
00878 #define BU_BITV_ZEROALL(_bv)    \
00879         { memset( (char *)((_bv)->bits), 0, BU_BITS2BYTES( (_bv)->nbits ) ); }
00880 
00881 /* This is not done by default for performance reasons */
00882 #ifdef NO_BOMBING_MACROS
00883 #  define BU_BITV_BITNUM_CHECK(_bv,_bit)
00884 #else
00885 #  define BU_BITV_BITNUM_CHECK(_bv,_bit)        /* Validate bit number */ \
00886         if( ((unsigned)(_bit)) >= (_bv)->nbits )  {\
00887                 bu_log("BU_BITV_BITNUM_CHECK bit number (%u) out of range (0..%u)\n", \
00888                         ((unsigned)(_bit)), (_bv)->nbits); \
00889                 bu_bomb("process self-terminating\n");\
00890         }
00891 #endif
00892 
00893 #ifdef NO_BOMBING_MACROS
00894 #  define BU_BITV_NBITS_CHECK(_bv,_nbits)
00895 #else
00896 #  define BU_BITV_NBITS_CHECK(_bv,_nbits)       /* Validate number of bits */ \
00897         if( ((unsigned)(_nbits)) > (_bv)->nbits )  {\
00898                 bu_log("BU_BITV_NBITS_CHECK number of bits (%u) out of range (> %u)", \
00899                         ((unsigned)(_nbits)), (_bv)->nbits ); \
00900                 bu_bomb("process self-terminating"); \
00901                 }
00902 #endif
00903 
00904 
00905 /**
00906  *  Macros to efficiently find all the ONE bits in a bit vector.
00907  *  Counts words down, counts bits in words going up, for speed & portability.
00908  *  It does not matter if the shift causes the sign bit to smear to the right.
00909  *
00910  *  @par Example:
00911 @code
00912         BU_BITV_LOOP_START(bv)  {
00913                 fiddle(BU_BITV_LOOP_INDEX);
00914         } BU_BITV_LOOP_END;
00915 @endcode
00916  *
00917  */
00918 #define BU_BITV_LOOP_START(_bv) \
00919 { \
00920         register int            _wd;    /* Current word number */  \
00921         BU_CK_BITV(_bv); \
00922         for( _wd=BU_BITS2WORDS((_bv)->nbits)-1; _wd>=0; _wd-- )  {  \
00923                 register int    _b;     /* Current bit-in-word number */  \
00924                 register bitv_t _val;   /* Current word value */  \
00925                 if((_val = (_bv)->bits[_wd])==0) continue;  \
00926                 for(_b=0; _b < BITV_MASK+1; _b++, _val >>= 1 ) { \
00927                         if( !(_val & 1) )  continue;
00928 
00929 /**
00930  *  This macro is valid only between a BU_BITV_LOOP_START/LOOP_END pair,
00931  *  and gives the bit number of the current iteration.
00932  */
00933 #define BU_BITV_LOOP_INDEX      ((_wd << BITV_SHIFT) | _b)
00934 
00935 #define BU_BITV_LOOP_END        \
00936                 } /* end for(_b) */ \
00937         } /* end for(_wd) */ \
00938 } /* end block */
00939 /*@}*/
00940 
00941 /*----------------------------------------------------------------------*/
00942 /* hist.c */
00943 
00944 /** @addtogroup bu_hist */
00945 /*@{*/
00946 /**
00947  *                      B U _ H I S T
00948  *
00949  * @struct bu_hist bu.h
00950  * @brief histogram support
00951  */
00952 struct bu_hist  {
00953     long                magic;          /**< @brief magic # for id/check  */
00954     fastf_t             hg_min;         /**< @brief minimum value  */
00955     fastf_t             hg_max;         /**< @brief maximum value  */
00956     fastf_t             hg_clumpsize;   /**< @brief (max-min+1)/nbins+1  */
00957     long                hg_nsamples;    /**< @brief total number of samples spread into histogram  */
00958     long                hg_nbins;       /**< @brief # of bins in hg_bins[]  */
00959     long                *hg_bins;       /**< @brief array of counters  */
00960 };
00961 #define BU_HIST_MAGIC   0x48697374      /* Hist */
00962 #define BU_CK_HIST(_p)  BU_CKMAG(_p, BU_HIST_MAGIC, "struct bu_hist")
00963 
00964 #define BU_HIST_TALLY( _hp, _val )      { \
00965         if( (_val) <= (_hp)->hg_min )  { \
00966                 (_hp)->hg_bins[0]++; \
00967         } else if( (_val) >= (_hp)->hg_max )  { \
00968                 (_hp)->hg_bins[(_hp)->hg_nbins]++; \
00969         } else { \
00970                 (_hp)->hg_bins[(int)(((_val)-(_hp)->hg_min)/(_hp)->hg_clumpsize)]++; \
00971         } \
00972         (_hp)->hg_nsamples++;  }
00973 
00974 #define BU_HIST_TALLY_MULTIPLE( _hp, _val, _count )     { \
00975         register int    __count = (_count); \
00976         if( (_val) <= (_hp)->hg_min )  { \
00977                 (_hp)->hg_bins[0] += __count; \
00978         } else if( (_val) >= (_hp)->hg_max )  { \
00979                 (_hp)->hg_bins[(_hp)->hg_nbins] += __count; \
00980         } else { \
00981                 (_hp)->hg_bins[(int)(((_val)-(_hp)->hg_min)/(_hp)->hg_clumpsize)] += __count; \
00982         } \
00983         (_hp)->hg_nsamples += __count;  }
00984 
00985 /*@}*/
00986 /*----------------------------------------------------------------------*/
00987 /* ptbl.c */
00988 /**
00989  * @addtogroup ptbl
00990  * @struct bu_ptbl
00991  * @brief
00992  *  Support for generalized "pointer tables".
00993  */
00994 /*@{*/
00995 
00996 struct bu_ptbl {
00997     struct bu_list      l;      /**< @brief linked list for caller's use  */
00998     int         end;    /**< @brief index into buffer of first available location  */
00999     int         blen;   /**< @brief # of (long *)'s worth of storage at *buffer  */
01000     long                **buffer; /**< @brief data storage area  */
01001 };
01002 #define BU_PTBL_MAGIC           0x7074626c              /* "ptbl" */
01003 #define BU_CK_PTBL(_p)          BU_CKMAG(_p, BU_PTBL_MAGIC, "bu_ptbl")
01004 
01005 #define BU_PTBL_INIT    0       /**< @brief  initialize table pointer struct & get storage */
01006 #define BU_PTBL_INS     1       /**< @brief  insert an item (long *) into a table */
01007 #define BU_PTBL_LOC     2       /**< @brief  locate a (long *) in an existing table */
01008 #define BU_PTBL_FREE    3       /**< @brief  deallocate buffer associated with a table */
01009 #define BU_PTBL_RST     4       /**< @brief  empty a table, but keep storage on hand */
01010 #define BU_PTBL_CAT     5       /**< @brief  catenate one table onto another */
01011 #define BU_PTBL_RM      6       /**< @brief  remove all occurrences of an item from a table */
01012 #define BU_PTBL_INS_UNIQUE 7    /**< @brief  insert item into table, if not present */
01013 #define BU_PTBL_ZERO    8       /**< @brief  replace all occurrences of an item by 0 */
01014 /*
01015  *  For those routines that have to "peek" into the ptbl a little bit.
01016  */
01017 #define BU_PTBL_BASEADDR(ptbl)  ((ptbl)->buffer)
01018 #define BU_PTBL_LASTADDR(ptbl)  ((ptbl)->buffer + (ptbl)->end - 1)
01019 #define BU_PTBL_END(ptbl)       ((ptbl)->end)
01020 #define BU_PTBL_LEN(p)  ((p)->end)
01021 #define BU_PTBL_GET(ptbl,i)     ((ptbl)->buffer[(i)])
01022 #define BU_PTBL_SET(ptbl,i,val) ((ptbl)->buffer[(i)] = (long*)(val))
01023 #define BU_PTBL_TEST(ptbl)      ((ptbl)->l.magic == BU_PTBL_MAGIC)
01024 #define BU_PTBL_CLEAR_I(_ptbl, _i) ((_ptbl)->buffer[(_i)] = (long *)0)
01025 
01026 /**
01027  *  A handy way to visit all the elements of the table is:
01028  *
01029  *      struct edgeuse **eup;
01030  *      for( eup = (struct edgeuse **)BU_PTBL_LASTADDR(&eutab);
01031  *           eup >= (struct edgeuse **)BU_PTBL_BASEADDR(&eutab); eup-- )  {
01032  *              NMG_CK_EDGEUSE(*eup);
01033  *      }
01034  *  or
01035  *      for( BU_PTBL_FOR( eup, (struct edgeuse **), &eutab ) )  {
01036  *              NMG_CK_EDGEUSE(*eup);
01037  *      }
01038  */
01039 #define BU_PTBL_FOR(ip,cast,ptbl)       \
01040     ip = cast BU_PTBL_LASTADDR(ptbl); ip >= cast BU_PTBL_BASEADDR(ptbl); ip--
01041 
01042 
01043 /* vlist, vlblock?  But they use vmath.h... */
01044 /*@}*/
01045 
01046 /*----------------------------------------------------------------------*/
01047 /* mappedfile.c */
01048 /**
01049  *                      B U _ M A P P E D _ F I L E
01050  * @addtogroup mf
01051  * @struct bu_mapped_file bu.h
01052  * @brief
01053  *  Structure for opening a mapped file.
01054  *  Each file is opened and mapped only once (per application,
01055  *  as tagged by the string in "appl" field).
01056  *  Subsequent opens require an exact match on both strings.
01057  *
01058  *  Before allocating apbuf and performing data conversion into it,
01059  *  openers should check to see if the file has already been opened and
01060  *  converted previously.
01061  *
01062  *  When used in RT, the mapped files are not closed at the end of a frame,
01063  *  so that subsequent frames may take advantage of the large data files
01064  *  having already been read and converted.
01065  *  Examples include EBMs, texture maps, and height fields.
01066  *
01067  *  For appl == "db_i", file is a ".g" database & apbuf is (struct db_i *).
01068  */
01069 /*@{*/
01070 struct bu_mapped_file {
01071         struct bu_list  l;
01072     char                *name;          /**< @brief bu_strdup() of file name  */
01073     genptr_t    buf;            /**< @brief In-memory copy of file (may be mmapped)  */
01074     long                buflen;         /**< @brief # bytes in 'buf'  */
01075     int         is_mapped;      /**< @brief 1=mmap() used, 0=bu_malloc/fread  */
01076     char                *appl;          /**< @brief bu_strdup() of tag for application using 'apbuf'  */
01077     genptr_t    apbuf;          /**< @brief opt: application-specific buffer  */
01078     long                apbuflen;       /**< @brief opt: application-specific buflen  */
01079     long                modtime;        /**< @brief date stamp, in case file is modified  */
01080     int         uses;           /**< @brief # ptrs to this struct handed out  */
01081     int         dont_restat;    /**< @brief 1=on subsequent opens, don't re-stat()  */
01082 };
01083 #define BU_MAPPED_FILE_MAGIC    0x4d617066      /* Mapf */
01084 #define BU_CK_MAPPED_FILE(_p)   BU_CKMAG(_p, BU_MAPPED_FILE_MAGIC, "bu_mapped_file")
01085 
01086 /*@}*/
01087 /*----------------------------------------------------------------------*/
01088 
01089 /* formerly rt_g.rtg_logindent, now use bu_log_indent_delta() */
01090 typedef int (*bu_hook_t)BU_ARGS((genptr_t, genptr_t));
01091 
01092 struct bu_hook_list {
01093     struct bu_list      l; /**< @brief linked list  */
01094     bu_hook_t   hookfunc; /**< @brief function to call  */
01095     genptr_t    clientdata; /**< @brief data for caller  */
01096 };
01097 
01098 #define BUHOOK_NULL 0
01099 #define BUHOOK_LIST_MAGIC       0x90d5dead      /* Nietzsche? */
01100 #define BUHOOK_LIST_NULL        ((struct bu_hook_list *) 0)
01101 
01102 BU_EXPORT extern struct bu_hook_list bu_log_hook_list;
01103 BU_EXPORT extern struct bu_hook_list bu_bomb_hook_list;
01104 
01105 /*----------------------------------------------------------------------*/
01106 /* avs.c */
01107 /** @addtogroup avs */
01108 /*@{*/
01109 /*
01110  *  Attribute/value sets
01111  */
01112 
01113 /**
01114  *                      B U _ A T T R I B U T E _ V A L U E _ P A I R
01115  *
01116  *  These strings may or may not be individually allocated,
01117  *  it depends on usage.
01118  */
01119 struct bu_attribute_value_pair {
01120     const char  *name;  /**< @brief attribute name  */
01121     const char  *value; /**< @brief attribute value  */
01122 };
01123 
01124 /**
01125  *                      B U _ A T T R I B U T E _ V A L U E _ S E T
01126  *
01127  *  A variable-sized attribute-value-pair array.
01128  *
01129  *  avp points to an array of [max] slots.
01130  *  The interface routines will realloc to extend as needed.
01131  *
01132  *  In general,
01133  *  each of the names and values is a local copy made with bu_strdup(),
01134  *  and each string needs to be freed individually.
01135  *  However, if a name or value pointer is between
01136  *  readonly_min and readonly_max, then it is part of a big malloc
01137  *  block that is being freed by the caller, and should not be individually
01138  *  freed.
01139  */
01140 struct bu_attribute_value_set {
01141         long                            magic;
01142     int                         count;  /**< @brief # valid entries in avp  */
01143     int                         max;    /**< @brief # allocated slots in avp  */
01144         genptr_t                        readonly_min;
01145         genptr_t                        readonly_max;
01146     struct bu_attribute_value_pair      *avp;   /**< @brief array[max]  */
01147 };
01148 #define BU_AVS_MAGIC            0x41765321      /* AvS! */
01149 #define BU_CK_AVS(_avp)         BU_CKMAG(_avp, BU_AVS_MAGIC, "bu_attribute_value_set")
01150 
01151 #define BU_AVS_FOR(_pp, _avp)   \
01152         (_pp) = &(_avp)->avp[(_avp)->count-1]; (_pp) >= (_avp)->avp; (_pp)--
01153 
01154 /**
01155  *  Some (but not all) attribute name and value string pointers are
01156  *  taken from an on-disk format bu_external block,
01157  *  while others have been bu_strdup()ed and need to be freed.
01158  *  This macro indicates whether the pointer needs to be freed or not.
01159  */
01160 #define AVS_IS_FREEABLE(_avsp, _p)      \
01161         ( (_avsp)->readonly_max == NULL || \
01162             ((genptr_t)(_p) < (genptr_t)(_avsp)->readonly_min || (genptr_t)(_p) > (genptr_t)(_avsp)->readonly_max) )
01163 
01164 /*@}*/
01165 /*----------------------------------------------------------------------*/
01166 /* vls.c */
01167 /** @addtogroup vls */
01168 /*@{*/
01169 /*
01170  *  Variable Length Strings: bu_vls support (formerly rt_vls in rtstring.h)
01171  */
01172 struct bu_vls  {
01173         long    vls_magic;
01174     char        *vls_str;       /**< @brief Dynamic memory for buffer  */
01175     int vls_offset;     /**< @brief Offset into vls_str where data is good  */
01176     int vls_len;        /**< @brief Length, not counting the null  */
01177         int     vls_max;
01178 };
01179 #define BU_VLS_MAGIC            0x89333bbb
01180 #define BU_CK_VLS(_vp)          BU_CKMAG(_vp, BU_VLS_MAGIC, "bu_vls")
01181 #define BU_VLS_IS_INITIALIZED(_vp)      \
01182         ((_vp) && ((_vp)->vls_magic == BU_VLS_MAGIC))
01183 
01184 /*
01185  *  Section for manifest constants for bu_semaphore_acquire()
01186  */
01187 #define BU_SEM_SYSCALL  0
01188 #define BU_SEM_LISTS    1
01189 #define BU_SEM_BN_NOISE 2
01190 #define BU_SEM_MAPPEDFILE 3
01191 #define BU_SEM_LAST     (BU_SEM_MAPPEDFILE+1)   /* allocate this many for LIBBU+LIBBN */
01192 /*
01193  *  Automatic restart capability in bu_bomb().
01194  *  The return from BU_SETJUMP is the return from the setjmp().
01195  *  It is 0 on the first pass through, and non-zero when
01196  *  re-entered via a longjmp() from bu_bomb().
01197  *  This is only safe to use in non-parallel applications.
01198  */
01199 #define BU_SETJUMP      setjmp((bu_setjmp_valid=1,bu_jmpbuf))
01200 #define BU_UNSETJUMP    (bu_setjmp_valid=0)
01201 /* These are global because BU_SETJUMP must be macro.  Please don't touch. */
01202 BU_EXPORT extern int    bu_setjmp_valid;                /* !0 = bu_jmpbuf is valid */
01203 BU_EXPORT extern jmp_buf        bu_jmpbuf;                      /* for BU_SETJMP() */
01204 /*@}*/
01205 /*-------------------------------------------------------------------------*/
01206 /** @addtogroup mro */
01207 /*@{*/
01208 /**                     B U _ M R O
01209  *
01210  *      Support for Multiply Represented Objects
01211  */
01212 
01213 struct bu_mro {
01214         long            magic;
01215         struct bu_vls   string_rep;
01216         char            long_rep_is_valid;
01217         long            long_rep;
01218         char            double_rep_is_valid;
01219         double          double_rep;
01220 };
01221 
01222 #define BU_MRO_MAGIC    0x4D524F4F      /* MROO */
01223 #define BU_CK_MRO(_vp)          BU_CKMAG(_vp, BU_MRO_MAGIC, "bu_mro")
01224 
01225 #define BU_MRO_INVALIDATE(_p ) {\
01226         _p->long_rep_is_valid = '\0';\
01227         _p->double_rep_is_valid = '\0';\
01228 }
01229 
01230 #define BU_MRO_GETDOUBLE( _p ) ( _p->double_rep_is_valid ? _p->double_rep : \
01231         (_p->double_rep = strtod( bu_vls_addr( &_p->string_rep ), NULL ), \
01232         ( _p->double_rep_is_valid='y', _p->double_rep ) ) )
01233 
01234 #define BU_MRO_GETLONG( _p ) ( _p->long_rep_is_valid ? _p->long_rep : \
01235         (_p->long_rep = strtol( bu_vls_addr( &_p->string_rep ), NULL, 10 ), \
01236         ( _p->long_rep_is_valid='y', _p->long_rep ) ) )
01237 
01238 #define BU_MRO_GETSTRING( _p ) bu_vls_addr( &_p->string_rep )
01239 
01240 #define BU_MRO_STRLEN( _p ) bu_vls_strlen( &_p->string_rep )
01241 /*@}*/
01242 
01243 /*----------------------------------------------------------------------*/
01244 /** @addtogroup bu_debug Debugging 
01245  * @ingroup libbu
01246  */
01247 /*@{*/
01248 /*
01249  * Section for BU_DEBUG values
01250  *
01251  * These can be set from the command-line of RT-compatible programs
01252  * using the "-! ###" option.
01253  */
01254 BU_EXPORT extern int    bu_debug;
01255 /* These definitions are each for one bit */
01256 #define BU_DEBUG_OFF            0       /* No debugging */
01257 
01258 #define BU_DEBUG_COREDUMP       0x00000001      /* 001 If set, bu_bomb() will dump core */
01259 
01260 #define BU_DEBUG_MEM_CHECK      0x00000002      /* 002 Mem barrier & leak checking */
01261 #define BU_DEBUG_MEM_LOG        0x00000004      /* 003 Print all dynamic memory operations */
01262 #define BU_DEBUG_DB             0x00000008      /* 004 Database debugging */
01263 
01264 #define BU_DEBUG_PARALLEL       0x00000010      /* 005 parallel support */
01265 #define BU_DEBUG_MEM_QCHECK     0x00000020      /* 006 Fast mem leak checking (won't work with corruption) */
01266 #define BU_DEBUG_MATH           0x00000100      /* 011 Fundamental math routines (plane.c, mat.c) */
01267 #define BU_DEBUG_PTBL           0x00000200      /* 012 bu_ptbl_*() logging */
01268 #define BU_DEBUG_AVS            0x00000400      /* 013 bu_avs_*() logging */
01269 #define BU_DEBUG_MAPPED_FILE    0x00000800      /* 014 bu_mapped_file logging */
01270 
01271 #define BU_DEBUG_TABDATA        0x00010000      /* 025 LIBBN: tabdata */
01272 
01273 /* Format string for bu_printb() */
01274 #define BU_DEBUG_FORMAT \
01275 "\020\
01276 \025TABDATA\
01277 \015?\
01278 \014MAPPED_FILE\013AVS\012PTBL\011MATH\010?\7?\6MEM_QCHECK\5PARALLEL\
01279 \4?\3MEM_LOG\2MEM_CHECK\1COREDUMP"
01280 
01281 /*@}*/
01282 /*----------------------------------------------------------------------*/
01283 /* parse.c */
01284 /** @addtogroup parse */
01285 /*@{*/
01286 /*
01287  *      Structure parse/print
01288  *
01289  *  Definitions and data structures needed for routines that assign values
01290  *  to elements of arbitrary data structures, the layout of which is
01291  *  described by tables of "bu_structparse" structures.
01292  */
01293 
01294 /**
01295  * b u _ o f f s e t o f
01296  * b u _ o f f s e t o f a r r a y
01297  *
01298  * The general problem of word-addressed hardware where (int *) and
01299  * (char *) have different representations is handled in the parsing
01300  * routines that use sp_offset, because of the limitations placed on
01301  * compile-time initializers.
01302  *
01303  * Files using bu_offsetof or bu_offsetofarray will need to include
01304  * stddef.h
01305  */
01306 #if __STDC__ && !defined(ipsc860)
01307 #       define bu_offsetofarray(_t, _m) offsetof(_t, _m[0])
01308 #else
01309 #       define bu_offsetofarray(_t, _m) (int)( (((_t *)0)->_m))
01310 #endif
01311 #if !defined(offsetof)
01312 #       define bu_offsetof(_t, _m) (int)(&(((_t *)0)->_m))
01313 #else
01314 #       define bu_offsetof(_t, _m) offsetof(_t, _m)
01315 #endif
01316 
01317 /**
01318  *  b u _ b y t e o f f s e t
01319  *
01320  *  Convert address of global data object into byte "offset" from address 0.
01321  *
01322  *  Strictly speaking, the C language only permits initializers of the
01323  *  form: address +- constant, where here the intent is to measure the
01324  *  byte address of the indicated variable.
01325  *  Matching compensation code for the CRAY is located in librt/parse.c
01326  */
01327 #if defined(CRAY)
01328 #       define bu_byteoffset(_i)        (((int)&(_i)))  /* actually a word offset */
01329 #else
01330 #  if defined(IRIX) && IRIX > 5 && _MIPS_SIM != _ABIN32 && _MIPS_SIM != _MIPS_SIM_ABI32
01331 #      define bu_byteoffset(_i) ((size_t)__INTADDR__(&(_i)))
01332 #  else
01333 #    if defined(sgi) || defined(__convexc__) || defined(ultrix) || defined(_HPUX_SOURCE)
01334        /* "Lazy" way.  Works on reasonable machines with byte addressing */
01335 #      define bu_byteoffset(_i) ((int)((char *)&(_i)))
01336 #    else
01337 #      if defined(__ia64__) || defined(__x86_64__) || defined(__sparc64__)
01338 #        if defined (__INTEL_COMPILER)
01339 #          define bu_byteoffset(_i)     ((long)((char *)&(_i)))
01340 #        else
01341 #          define bu_byteoffset(_i)     ((long)(((void *)&(_i))-((void *)0)))
01342 #        endif
01343 #      else
01344          /* "Conservative" way of finding # bytes as diff of 2 char ptrs */
01345 #        define bu_byteoffset(_i)       ((int)(((char *)&(_i))-((char *)0)))
01346 #      endif
01347 #    endif
01348 #  endif
01349 #endif
01350 
01351 /**
01352  * The "bu_structparse" struct describes one element of a structure.
01353  * Collections of these are combined to describe entire structures (or at
01354  * least those portions for which parse/print/import/export support is
01355  * desired.  For example:
01356  *@code
01357   struct data_structure {
01358         char    a_char;
01359         char    str[32];
01360         short   a_short;
01361         int     a_int;
01362         double  a_double;
01363   }
01364  
01365   struct data_structure data_default =
01366         { 'c', "the default string", 32767, 1, 1.0 };
01367  
01368   struct data_structure my_values;
01369  
01370   struct bu_structparse data_sp[] ={
01371  
01372   {"%c", 1,  "a_char",   bu_offsetof(data_structure, a_char),
01373         BU_STRUCTPARSE_FUNC_NULL,
01374         "a single character",   (void*)&default.a_char },
01375  
01376   {"%s", 32, "str",      bu_offsetofarray(data_structure, str),
01377         BU_STRUCTPARSE_FUNC_NULL,
01378         "This is a full character string", (void*)default.str }, },
01379  
01380   {"%i", 1,  "a_short",  bu_offsetof(data_structure, a_short),
01381         BU_STRUCTPARSE_FUNC_NULL,
01382         "A 16bit integer",      (void*)&default.a_short },
01383  
01384   {"%d", 1,  "a_int",    bu_offsetof(data_structure, a_int),
01385         BU_STRUCTPARSE_FUNC_NULL,
01386         "A full integer",       (void*)&default.a_int },
01387  
01388   {"%f", 1,  "a_double", bu_offsetof(data_structure, a_double),
01389         BU_STRUCTPARSE_FUNC_NULL,
01390         "A double-precision floating point value",  (void*)&default.a_double },
01391  
01392   { "", 0, (char *)NULL, 0,
01393         BU_STRUCTPARSE_FUNC_NULL,
01394         (char *)NULL, (void *)NULL }
01395  
01396   };
01397  @endcode
01398  *
01399  * To parse a string, call:
01400  *
01401  *      bu_struct_parse( vls_string, data_sp, (char *)my_values)
01402  *
01403  * this will parse the vls string and assign values to the members of the
01404  * structure my_values
01405  *
01406  *  A gross hack:  To set global variables (or others for that matter) you
01407  *      can store the actual address of the variable in the sp_offset field
01408  *      and pass a null pointer as the last argument to bu_struct_parse().
01409  *      If you don't understand why this would work, you probably shouldn't
01410  *      use this technique.
01411  */
01412 struct bu_structparse {
01413     char                sp_fmt[4];              /**< @brief "i" or "%f", etc  */
01414     long                sp_count;               /**< @brief number of elements  */
01415     char                *sp_name;               /**< @brief Element's symbolic name  */
01416     long                sp_offset;              /**< @brief Byte offset in struct  */
01417     void                (*sp_hook)();           /**< @brief Optional hooked function, or indir ptr  */
01418     char                *sp_desc;               /**< @brief description of element  */
01419     void                *sp_default;            /**< @brief ptr to default value  */
01420 };
01421 #define BU_STRUCTPARSE_FUNC_NULL        ((void (*)())0)
01422 
01423 
01424 
01425 
01426 /*----------------------------------------------------------------------*/
01427 /**
01428  *                      B U _ E X T E R N A L
01429  *
01430  *  An "opaque" handle for holding onto objects,
01431  *  typically in some kind of external form that is not directly
01432  *  usable without passing through an "importation" function.
01433  * A "bu_external" struct holds the "external binary" representation of a
01434  * structure or other block of arbitrary data.
01435  */
01436 struct bu_external  {
01437         long    ext_magic;
01438         long    ext_nbytes;
01439         genptr_t ext_buf;
01440 };
01441 #define BU_EXTERNAL_MAGIC       0x768dbbd0
01442 #define BU_INIT_EXTERNAL(_p)    {(_p)->ext_magic = BU_EXTERNAL_MAGIC; \
01443         (_p)->ext_buf = (genptr_t)NULL; (_p)->ext_nbytes = 0;}
01444 #define BU_CK_EXTERNAL(_p)      BU_CKMAG(_p, BU_EXTERNAL_MAGIC, "bu_external")
01445 
01446 /*@}*/
01447 /*----------------------------------------------------------------------*/
01448 /* color.c */
01449 #define HUE             0
01450 #define SAT             1
01451 #define VAL             2
01452 #define ACHROMATIC      -1.0
01453 
01454 struct bu_color
01455 {
01456     long        buc_magic;
01457     fastf_t     buc_rgb[3];
01458 };
01459 #define BU_COLOR_MAGIC          0x6275636c
01460 #define BU_COLOR_NULL           ((struct bu_color *) 0)
01461 #define BU_CK_COLOR(_bp)        BU_CKMAG(_bp, BU_COLOR_MAGIC, "bu_color")
01462 
01463 /*----------------------------------------------------------------------*/
01464 /* red-black tree support */
01465 /** @addtogroup rb */
01466 /*@{*/
01467 /*
01468  *      The data structures and constants for red-black trees.
01469  *
01470  *      Many of these routines are based on the algorithms in chapter 13
01471  *      of T. H. Cormen, C. E. Leiserson, and R. L. Rivest,
01472  *      _Introduction to algorithms_, MIT Press, Cambridge, MA, 1990.
01473  *
01474  *      Author: Paul Tanenbaum
01475  *
01476  */
01477 
01478 /**
01479  *                          B U _ R B _ L I S T
01480  *
01481  *                  List of nodes or packages
01482  *
01483  *      The red-black tree package uses this structure to maintain lists
01484  *      of all the nodes and all the packages in the tree.  Applications
01485  *      should not muck with these things.  They are maintained only to
01486  *      facilitate freeing bu_rb_trees.
01487  */
01488 struct bu_rb_list
01489 {
01490     struct bu_list      l;
01491     union
01492     {
01493         struct bu_rb_node    *rbl_n;
01494         struct bu_rb_package *rbl_p;
01495     }                   rbl_u;
01496 };
01497 #define rbl_magic       l.magic
01498 #define rbl_node        rbl_u.rbl_n
01499 #define rbl_package     rbl_u.rbl_p
01500 #define BU_RB_LIST_NULL ((struct bu_rb_list *) 0)
01501 
01502 
01503 /**
01504  *                      B U _ R B _ T R E E
01505  *
01506  *      This is the only data structure used in the red-black tree package
01507  *      to which application software need make any explicit reference.
01508  *
01509  *      The members of this structure are grouped into three
01510  *      classes:
01511  *          Class I:    Reading is appropriate, when necessary,
01512  *                      but applications should not modify.
01513  *          Class II:   Reading and modifying are both appropriate,
01514  *                      when necessary.
01515  *          Class III:  All access should be through routines
01516  *                      provided in the package.  Touch these
01517  *                      at your own risk!
01518  */
01519 typedef struct
01520 {
01521     /* CLASS I - Applications may read directly... */
01522     long                rbt_magic;        /**< @brief  Magic no. for integrity check */
01523     int                 rbt_nm_nodes;     /**< @brief  Number of nodes */
01524     /* CLASS II - Applications may read/write directly... */
01525     void                (*rbt_print)();   /**< @brief  Data pretty-print function */
01526     int                 rbt_debug;        /**< @brief  Debug bits */
01527     char                *rbt_description; /**< @brief  Comment for diagnostics */
01528     /* CLASS III - Applications should not manipulate directly... */
01529     int                 rbt_nm_orders;    /**< @brief  Number of simultaneous orders */
01530     int                 (**rbt_order)();  /**< @brief  Comparison functions */
01531     struct bu_rb_node   **rbt_root;       /**< @brief  The actual trees */
01532     char                *rbt_unique;      /**< @brief  Uniqueness flags */
01533     struct bu_rb_node   *rbt_current;     /**< @brief  Current node */
01534     struct bu_rb_list   rbt_nodes;        /**< @brief  All nodes */
01535     struct bu_rb_list   rbt_packages;     /**< @brief  All packages */
01536     struct bu_rb_node   *rbt_empty_node;  /**< @brief  Sentinel representing nil */
01537 }       bu_rb_tree;
01538 #define BU_RB_TREE_NULL ((bu_rb_tree *) 0)
01539 #define BU_RB_TREE_MAGIC        0x72627472
01540 
01541 /*
01542  *      Debug bit flags for member rbt_debug
01543  */
01544 #define BU_RB_DEBUG_INSERT      0x00000001      /**< @brief  Insertion process */
01545 #define BU_RB_DEBUG_UNIQ        0x00000002      /**< @brief  Uniqueness of inserts */
01546 #define BU_RB_DEBUG_ROTATE      0x00000004      /**< @brief  Rotation process */
01547 #define BU_RB_DEBUG_OS  0x00000008      /**< @brief  Order-statistic operations */
01548 #define BU_RB_DEBUG_DELETE      0x00000010      /**< @brief  Deletion process */
01549 
01550 /**
01551  *                      B U _ R B _ P A C K A G E
01552  *
01553  *                  Wrapper for application data
01554  *
01555  *      This structure provides a level of indirection between
01556  *      the application software's data and the red-black nodes
01557  *      in which the data is stored.  It is necessary because of
01558  *      the algorithm for deletion, which generally shuffles data
01559  *      among nodes in the tree.  The package structure allows
01560  *      the application data to remember which node "contains" it
01561  *      for each order.
01562  */
01563 struct bu_rb_package
01564 {
01565     long                rbp_magic;      /**< @brief Magic no. for integrity check  */
01566     struct bu_rb_node   **rbp_node;     /**< @brief Containing nodes  */
01567     struct bu_rb_list   *rbp_list_pos;  /**< @brief Place in the list of all pkgs.  */
01568     void                *rbp_data;      /**< @brief Application data  */
01569 };
01570 #define BU_RB_PKG_NULL  ((struct bu_rb_package *) 0)
01571 
01572 /**
01573  *                          B U _ R B _ N O D E
01574  *
01575  *      For the most part, there is a one-to-one correspondence
01576  *      between nodes and chunks of application data.  When a
01577  *      node is created, all of its package pointers (one per
01578  *      order of the tree) point to the same chunk of data.
01579  *      However, subsequent deletions usually muddy this tidy
01580  *      state of affairs.
01581  */
01582 struct bu_rb_node
01583 {
01584     long                rbn_magic;      /**< @brief Magic no. for integrity check  */
01585     bu_rb_tree          *rbn_tree;      /**< @brief Tree containing this node  */
01586     struct bu_rb_node   **rbn_parent;   /**< @brief Parents  */
01587     struct bu_rb_node   **rbn_left;     /**< @brief Left subtrees  */
01588     struct bu_rb_node   **rbn_right;    /**< @brief Right subtrees  */
01589     char                *rbn_color;     /**< @brief Colors of this node  */
01590     int                 *rbn_size;      /**< @brief Sizes of subtrees rooted here  */
01591     struct bu_rb_package **rbn_package; /**< @brief Contents of this node  */
01592     int                 rbn_pkg_refs;   /**< @brief How many orders are being used?  */
01593     struct bu_rb_list   *rbn_list_pos;  /**< @brief Place in the list of all nodes  */
01594 };
01595 #define BU_RB_NODE_NULL ((struct bu_rb_node *) 0)
01596 
01597 /*
01598  *      Applications interface to bu_rb_extreme()
01599  */
01600 #define SENSE_MIN       0
01601 #define SENSE_MAX       1
01602 #define bu_rb_min(t,o)  bu_rb_extreme((t), (o), SENSE_MIN)
01603 #define bu_rb_max(t,o)  bu_rb_extreme((t), (o), SENSE_MAX)
01604 #define bu_rb_pred(t,o) bu_rb_neighbor((t), (o), SENSE_MIN)
01605 #define bu_rb_succ(t,o) bu_rb_neighbor((t), (o), SENSE_MAX)
01606 
01607 /*
01608  *      Applications interface to bu_rb_walk()
01609  */
01610 #define PREORDER        0
01611 #define INORDER         1
01612 #define POSTORDER       2
01613 
01614 
01615 /**
01616  *                      B U _ O B S E R V E R
01617  *
01618  */
01619 struct bu_observer {
01620   struct bu_list        l;
01621   struct bu_vls         observer;
01622   struct bu_vls         cmd;
01623 };
01624 #define BU_OBSERVER_NULL        ((struct bu_observer *)0)
01625 
01626 /**
01627  *                      B U _ C M D T A B
01628  */
01629 struct bu_cmdtab {
01630   char *ct_name;
01631   int (*ct_func)();
01632 };
01633 
01634 /*----------------------------------------------------------------------*/
01635 /* Miscellaneous macros */
01636 #define bu_made_it()            bu_log("Made it to %s:%d\n",    \
01637                                         __FILE__, __LINE__)
01638 /*----------------------------------------------------------------------*/
01639 /*
01640  *  Declarations of external functions in LIBBU.
01641  *  Source file names listed alphabetically.
01642  */
01643 /**@}*/
01644 
01645 /** @addtogroup avs */
01646 /*@{*/
01647 /* avs.c */
01648 BU_EXPORT BU_EXTERN(void bu_avs_init,
01649                     (struct bu_attribute_value_set *avp,
01650                      int len,
01651                      const char *str));
01652 BU_EXPORT BU_EXTERN(void bu_avs_init_empty,
01653                     (struct bu_attribute_value_set *avp));
01654 BU_EXPORT BU_EXTERN(struct bu_attribute_value_set *bu_avs_new,
01655                     (int len,
01656                      const char *str));
01657 BU_EXPORT BU_EXTERN(int bu_avs_add,
01658                     (struct bu_attribute_value_set *avp,
01659                      const char *attribute,
01660                      const char *value));
01661 BU_EXPORT BU_EXTERN(int bu_avs_add_vls,
01662                     (struct bu_attribute_value_set *avp,
01663                      const char *attribute,
01664                      const struct bu_vls *value_vls));
01665 BU_EXPORT BU_EXTERN(void bu_avs_merge,
01666                     (struct bu_attribute_value_set *dest,
01667                      const struct bu_attribute_value_set *src));
01668 BU_EXPORT BU_EXTERN(const char *bu_avs_get,
01669                     (const struct bu_attribute_value_set *avp,
01670                      const char *attribute));
01671 BU_EXPORT BU_EXTERN(int bu_avs_remove,
01672                     (struct bu_attribute_value_set *avp,
01673                      const char *attribute));
01674 BU_EXPORT BU_EXTERN(void bu_avs_free,
01675                     (struct bu_attribute_value_set *avp));
01676 BU_EXPORT BU_EXTERN(void bu_avs_print,
01677                     (const struct bu_attribute_value_set *avp,
01678                      const char *title));
01679 BU_EXPORT BU_EXTERN(void bu_avs_add_nonunique,
01680                     (struct bu_attribute_value_set *avsp,
01681                      char *attribute,
01682                      char *value));
01683 /*@}*/
01684 
01685 /** @addtogroup magic */
01686 /*@{*/
01687 /* badmagic.c */
01688 BU_EXPORT BU_EXTERN(void bu_badmagic,
01689                     (const long *ptr,
01690                      unsigned long magic,
01691                      const char *str,
01692                      const char *file,
01693                      int line));
01694 /*@}*/
01695 
01696 /** @addtogroup bitv */
01697 /*@{*/
01698 /* bitv.c */
01699 BU_EXPORT BU_EXTERN(struct bu_bitv *bu_bitv_new,
01700                     (unsigned int nbits));
01701 BU_EXPORT BU_EXTERN(void bu_bitv_clear,
01702                     (struct bu_bitv *bv));
01703 BU_EXPORT BU_EXTERN(void bu_bitv_or,
01704                     (struct bu_bitv *ov,
01705                      const struct bu_bitv *iv));
01706 BU_EXPORT BU_EXTERN(void bu_bitv_and,
01707                     (struct bu_bitv *ov,
01708                      const struct bu_bitv *iv));
01709 BU_EXPORT BU_EXTERN(void bu_bitv_vls,
01710                     (struct bu_vls *v,
01711                      const struct bu_bitv *bv));
01712 BU_EXPORT BU_EXTERN(void bu_pr_bitv,
01713                     (const char *str,
01714                      const struct bu_bitv *bv));
01715 BU_EXPORT BU_EXTERN(void bu_bitv_to_hex,
01716                     (struct bu_vls *v,
01717                      const struct bu_bitv *bv));
01718 BU_EXPORT BU_EXTERN(struct bu_bitv *bu_hex_to_bitv,
01719                     (const char *str));
01720 BU_EXPORT BU_EXTERN(struct bu_bitv *bu_bitv_dup,
01721                     (const struct bu_bitv *bv));
01722 BU_EXPORT BU_EXTERN(void bu_bitv_free,
01723                     (struct bu_bitv *bv));
01724 
01725 /*@}*/
01726 /** @addtogroup bu_log */
01727 /*@{*/
01728 
01729 /* bomb.c */
01730 BU_EXPORT BU_EXTERN(void bu_bomb,
01731                     (const char *str));
01732 
01733 /* bu_fgets.c */
01734 BU_EXPORT BU_EXTERN(char *bu_fgets,
01735                     ( char *s, int size, FILE *stream));
01736 /*@}*/
01737 /** @addtogroup color */
01738 /*@{*/
01739 
01740 
01741 /* color.c */
01742 BU_EXPORT BU_EXTERN(void bu_rgb_to_hsv,
01743                     (unsigned char *rgb,
01744                      fastf_t *hsv));
01745 BU_EXPORT BU_EXTERN(int bu_hsv_to_rgb,
01746                     (fastf_t *hsv,
01747                      unsigned char *rgb));
01748 BU_EXPORT BU_EXTERN(int bu_str_to_rgb,
01749                     (char *str,
01750                      unsigned char *rgb));
01751 BU_EXPORT BU_EXTERN(void bu_color_of_rgb_chars,
01752                     (struct bu_color *cp,
01753                      unsigned char *rgb));
01754 BU_EXPORT BU_EXTERN(int bu_color_to_rgb_chars,
01755                     (struct bu_color *cp,
01756                      unsigned char *rgb));
01757 BU_EXPORT BU_EXTERN(int bu_color_of_rgb_floats,
01758                     (struct bu_color *cp,
01759                      fastf_t *rgb));
01760 BU_EXPORT BU_EXTERN(int bu_color_to_rgb_floats,
01761                     (struct bu_color *cp,
01762                      fastf_t *rgb));
01763 BU_EXPORT BU_EXTERN(int bu_color_of_hsv_floats,
01764                     (struct bu_color *cp,
01765                      fastf_t *hsv));
01766 BU_EXPORT BU_EXTERN(int bu_color_to_hsv_floats,
01767                     (struct bu_color *cp,
01768                      fastf_t *hsv));
01769 /*@}*/
01770 /** @addtogroup bu_log */
01771 /*@{*/
01772 
01773 /* file.c */
01774 BU_EXPORT BU_EXTERN(struct bu_file *bu_fopen,
01775                     (char *fname, char *type));
01776 BU_EXPORT BU_EXTERN(int bu_fclose,
01777                     (struct bu_file *bfp));
01778 BU_EXPORT BU_EXTERN(int bu_fgetc,
01779                     (struct bu_file *bfp));
01780 BU_EXPORT BU_EXTERN(void bu_printfile,
01781                     (struct bu_file *bfp));
01782 
01783 /* stat.c */
01784 BU_EXPORT BU_EXTERN(int bu_file_exists, (const char *path));
01785 
01786 /* brlcad_path.c */
01787 BU_EXPORT BU_EXTERN(const char *bu_getprogname, (void));
01788 BU_EXPORT BU_EXTERN(void bu_setprogname, (const char *path));
01789 BU_EXPORT BU_EXTERN(char *bu_brlcad_path, /* deprecated call */
01790                     (const char *rhs, int fail_quietly));
01791 BU_EXPORT BU_EXTERN(char *bu_brlcad_root,
01792                     (const char *rhs, int fail_quietly));
01793 BU_EXPORT BU_EXTERN(char *bu_brlcad_data,
01794                     (const char *rhs, int fail_quietly));
01795 
01796 /* fopen_uniq */
01797 BU_EXPORT BU_EXTERN(FILE *bu_fopen_uniq,
01798                     (const char *outfmt,
01799                      const char *namefmt,
01800                      int n));
01801 
01802 /* file.c */
01803 BU_EXPORT BU_EXTERN(struct bu_file *bu_fopen,
01804                     (char *fname, char *type));
01805 BU_EXPORT BU_EXTERN(int bu_fclose,
01806                     (struct bu_file *bfp));
01807 BU_EXPORT BU_EXTERN(int bu_fgetc,
01808                     (struct bu_file *bfp));
01809 BU_EXPORT BU_EXTERN(void bu_printfile,
01810                     (struct bu_file *bfp));
01811 
01812 /*@}*/
01813 /** @addtogroup getopt */
01814 /*@{*/
01815 
01816 /* getopt.c */
01817 BU_EXPORT extern int                    bu_opterr;
01818 BU_EXPORT extern int                    bu_optind;
01819 BU_EXPORT extern int                    bu_optopt;
01820 BU_EXPORT extern char *                 bu_optarg;
01821 BU_EXPORT BU_EXTERN(int bu_getopt,
01822                     (int nargc, char * const nargv[],
01823                      const char *ostr));
01824 
01825 /*@}*/
01826 /** @addtogroup bu_hist */
01827 /*@{*/
01828 
01829 /* hist.c */
01830 BU_EXPORT BU_EXTERN(void bu_hist_free,
01831                     (struct bu_hist *histp));
01832 BU_EXPORT BU_EXTERN(void bu_hist_init,
01833                     (struct bu_hist *histp,
01834                      fastf_t min,
01835                      fastf_t max,
01836                      unsigned int nbins));
01837 BU_EXPORT BU_EXTERN(void bu_hist_range,
01838                     (struct bu_hist *hp,
01839                      fastf_t low,
01840                      fastf_t high));
01841 BU_EXPORT BU_EXTERN(void bu_hist_pr,
01842                     (const struct bu_hist *histp,
01843                      const char *title));
01844 
01845 /*@}*/
01846 /** @addtogroup hton */
01847 /*@{*/
01848 
01849 /* htond.c */
01850 BU_EXPORT BU_EXTERN(void htond,
01851                     (unsigned char *out,
01852                      const unsigned char *in,
01853                      int count));
01854 BU_EXPORT BU_EXTERN(void ntohd,
01855                     (unsigned char *out,
01856                      const unsigned char *in,
01857                      int count));
01858 
01859 /* htonf.c */
01860 BU_EXPORT BU_EXTERN(void htonf,
01861                     (unsigned char *out,
01862                      const unsigned char *in,
01863                      int count));
01864 BU_EXPORT BU_EXTERN(void ntohf,
01865                     (unsigned char *out,
01866                      const unsigned char *in,
01867                      int count));
01868 
01869 /*@}*/
01870 /** @addtogroup thread */
01871 /*@{*/
01872 
01873 /* ispar.c */
01874 BU_EXPORT BU_EXTERN(int bu_is_parallel,
01875                     ());
01876 BU_EXPORT BU_EXTERN(void bu_kill_parallel,
01877                     ());
01878 
01879 /*@}*/
01880 /** @addtogroup bu_log */
01881 /*@{*/
01882 
01883 /* linebuf.c */
01884 BU_EXPORT BU_EXTERN(void bu_setlinebuf,
01885                     (FILE *fp));
01886 
01887 /*@}*/
01888 /** @addtogroup bu_list */
01889 /*@{*/
01890 
01891 /* list.c */
01892 BU_EXPORT BU_EXTERN(int bu_list_len,
01893                     (const struct bu_list *hd));
01894 BU_EXPORT BU_EXTERN(void bu_list_reverse,
01895                     (struct bu_list *hd));
01896 BU_EXPORT BU_EXTERN(void bu_list_free,
01897                     (struct bu_list *hd));
01898 BU_EXPORT BU_EXTERN(void bu_list_parallel_append,
01899                     (struct bu_list *headp,
01900                      struct bu_list *itemp));
01901 BU_EXPORT BU_EXTERN(struct bu_list *bu_list_parallel_dequeue,
01902                     (struct bu_list *headp));
01903 BU_EXPORT BU_EXTERN(void bu_ck_list,
01904                     (const struct bu_list *hd,
01905                      const char *str));
01906 BU_EXPORT BU_EXTERN(void bu_ck_list_magic,
01907                     (const struct bu_list *hd,
01908                      const char *str,
01909                      const long magic));
01910 
01911 /*@}*/
01912 /** @addtogroup bu_log */
01913 /*@{*/
01914 /* hook.c */
01915 BU_EXPORT BU_EXTERN(void bu_hook_list_init,
01916                     (struct bu_hook_list *hlp));
01917 BU_EXPORT BU_EXTERN(void bu_add_hook,
01918                     (struct bu_hook_list *hlp,
01919                      bu_hook_t func,
01920                      genptr_t clientdata));
01921 BU_EXPORT BU_EXTERN(void bu_delete_hook,
01922                     (struct bu_hook_list *hlp,
01923                      bu_hook_t func,
01924                      genptr_t clientdata));
01925 BU_EXPORT BU_EXTERN(void bu_call_hook,
01926                     (struct bu_hook_list *hlp,
01927                      genptr_t buf));
01928 
01929 /*@}*/
01930 /** @addtogroup bu_log */
01931 /*@{*/
01932 /* log.c */
01933 BU_EXPORT BU_EXTERN(void bu_log_indent_delta,
01934                     (int delta));
01935 BU_EXPORT BU_EXTERN(void bu_log_indent_vls,
01936                     (struct bu_vls *v));
01937 BU_EXPORT BU_EXTERN(void bu_log_add_hook,
01938                     (bu_hook_t func,
01939                      genptr_t clientdata));
01940 BU_EXPORT BU_EXTERN(void bu_log_delete_hook,
01941                     (bu_hook_t func,
01942                      genptr_t clientdata));
01943 BU_EXPORT BU_EXTERN(void bu_putchar,
01944                     (int c));
01945 #if defined(HAVE_STDARG_H)
01946 BU_EXPORT BU_EXTERN(void bu_log,
01947                     (char *, ... ));
01948 BU_EXPORT BU_EXTERN(void bu_flog,
01949                     (FILE *, char *, ... ));
01950 #else
01951 BU_EXPORT BU_EXTERN(void bu_log,
01952                     ());
01953 BU_EXPORT BU_EXTERN(void bu_flog,
01954                     ());
01955 #endif
01956 
01957 /*@}*/
01958 /** @addtogroup magic */
01959 /*@{*/
01960 
01961 /* magic.c */
01962 BU_EXPORT BU_EXTERN(const char *bu_identify_magic,
01963                     (long magic));
01964 
01965 /*@}*/
01966 /** @addtogroup malloc */
01967 /*@{*/
01968 
01969 /* malloc.c */
01970 BU_EXPORT extern long           bu_n_malloc;
01971 BU_EXPORT extern long           bu_n_free;
01972 BU_EXPORT extern long           bu_n_realloc;
01973 BU_EXPORT BU_EXTERN(genptr_t bu_malloc,
01974                     (unsigned int cnt,
01975                      const char *str));
01976 BU_EXPORT BU_EXTERN(void bu_free,
01977                     (genptr_t ptr,
01978                      const char *str));
01979 BU_EXPORT BU_EXTERN(genptr_t bu_realloc,
01980                     (genptr_t ptr,
01981                      unsigned int cnt,
01982                      const char *str));
01983 BU_EXPORT BU_EXTERN(genptr_t bu_calloc,
01984                     (unsigned int nelem,
01985                      unsigned int elsize,
01986                      const char *str));
01987 BU_EXPORT BU_EXTERN(void bu_prmem,
01988                     (const char *str));
01989 BU_EXPORT BU_EXTERN(char *bu_strdupm,
01990                     (const char *cp, const char *label));
01991 
01992 #define bu_strdup(s) bu_strdupm(s, "bu_srtdup " BU_FLSTR)
01993 #if 0
01994 BU_EXPORT BU_EXTERN(char *bu_strdup,
01995                     (const char *cp));
01996 #endif
01997 BU_EXPORT BU_EXTERN(char *bu_dirname,
01998                     (const char *cp));
01999 BU_EXPORT BU_EXTERN(int bu_malloc_len_roundup,
02000                     (int nbytes));
02001 BU_EXPORT BU_EXTERN(void bu_ck_malloc_ptr,
02002                     (genptr_t ptr, const char *str));
02003 BU_EXPORT BU_EXTERN(int bu_mem_barriercheck,
02004                     ());
02005 
02006 /*@}*/
02007 /** @addtogroup mf */
02008 /*@{*/
02009 
02010 /* mappedfile.c */
02011 BU_EXPORT BU_EXTERN(struct bu_mapped_file *bu_open_mapped_file,
02012                     (const char *name,
02013                      const char *appl));
02014 BU_EXPORT BU_EXTERN(void bu_close_mapped_file,
02015                     (struct bu_mapped_file *mp));
02016 BU_EXPORT BU_EXTERN(void bu_pr_mapped_file,
02017                     (const char *title,
02018                      const struct bu_mapped_file *mp));
02019 BU_EXPORT BU_EXTERN(void bu_free_mapped_files,
02020                     (int verbose));
02021 BU_EXPORT BU_EXTERN(struct bu_mapped_file *bu_open_mapped_file_with_path,
02022                     (char * const *path,
02023                      const char *name,
02024                      const char *appl));
02025 
02026 
02027 /*@}*/
02028 /** @addtogroup thread */
02029 /*@{*/
02030 
02031 /* parallel.c */
02032 BU_EXPORT BU_EXTERN(void bu_nice_set,
02033                     (int newnice));
02034 BU_EXPORT BU_EXTERN(int bu_cpulimit_get,
02035                     ());
02036 BU_EXPORT BU_EXTERN(void bu_cpulimit_set,
02037                     (int sec));
02038 BU_EXPORT BU_EXTERN(int bu_avail_cpus,
02039                     ());
02040 BU_EXPORT BU_EXTERN(fastf_t bu_get_load_average,
02041                     ());
02042 BU_EXPORT BU_EXTERN(int bu_get_public_cpus,
02043                     ());
02044 BU_EXPORT BU_EXTERN(int bu_set_realtime,
02045                     ());
02046 BU_EXPORT BU_EXTERN(void bu_parallel,
02047                     (void (*func)BU_ARGS((int ncpu, genptr_t arg)),
02048                      int ncpu,
02049                      genptr_t arg));
02050 
02051 /*@}*/
02052 /** @addtogroup parse */
02053 /*@{*/
02054 
02055 /* parse.c */
02056 BU_EXPORT BU_EXTERN(int bu_struct_export,
02057                     (struct bu_external *ext,
02058                      const genptr_t base,
02059                      const struct bu_structparse *imp));
02060 BU_EXPORT BU_EXTERN(int bu_struct_import,
02061                     (genptr_t base,
02062                      const struct bu_structparse *imp,
02063                      const struct bu_external *ext));
02064 BU_EXPORT BU_EXTERN(int bu_struct_put,
02065                     (FILE *fp,
02066                      const struct bu_external *ext));
02067 BU_EXPORT BU_EXTERN(int bu_struct_get,
02068                     (struct bu_external *ext,
02069                      FILE *fp));
02070 BU_EXPORT BU_EXTERN(void bu_struct_wrap_buf,
02071                     (struct bu_external *ext,
02072                      genptr_t buf));
02073 BU_EXPORT BU_EXTERN(int bu_struct_parse,
02074                     (const struct bu_vls *in_vls,
02075                      const struct bu_structparse *desc,
02076                      const char *base));
02077 BU_EXPORT BU_EXTERN(void bu_struct_print,
02078                     (const char *title,
02079                      const struct bu_structparse *parsetab,
02080                      const char *base));
02081 BU_EXPORT BU_EXTERN(void bu_vls_struct_print,
02082                     (struct bu_vls *vls,
02083                      const struct bu_structparse *sdp,
02084                      const char *base));
02085 BU_EXPORT BU_EXTERN(void bu_vls_struct_print2,
02086                     (struct bu_vls *vls,
02087                      const char *title,
02088                      const struct bu_structparse *sdp,
02089                      const char *base));
02090 BU_EXPORT BU_EXTERN(void bu_vls_struct_item,
02091                     (struct bu_vls *vp,
02092                      const struct bu_structparse *sdp,
02093                      const char *base,
02094                      int sep_char));
02095 BU_EXPORT BU_EXTERN(int bu_vls_struct_item_named,
02096                     (struct bu_vls *vp,
02097                      const struct bu_structparse *sdp,
02098                      const char *name,
02099                      const char *base,
02100                      int sep_char));
02101 BU_EXPORT BU_EXTERN(void bu_parse_mm,
02102                     (const struct bu_structparse *sdp,
02103                      const char *name,
02104                      char *base,
02105                      const char *value));
02106 BU_EXPORT BU_EXTERN(int bu_key_eq_to_key_val,
02107                     (char *in,
02108                      char **next,
02109                      struct bu_vls *vls));
02110 BU_EXPORT BU_EXTERN(int bu_shader_to_tcl_list,
02111                     (char *in,
02112                      struct bu_vls *vls));
02113 BU_EXPORT BU_EXTERN(int bu_key_val_to_key_eq,
02114                     (char *in));
02115 BU_EXPORT BU_EXTERN(int bu_shader_to_key_eq,
02116                     (char *in, struct bu_vls *vls));
02117 BU_EXPORT BU_EXTERN(int bu_fwrite_external,
02118                     (FILE *fp,
02119                      const struct bu_external *ep));
02120 BU_EXPORT BU_EXTERN(void bu_hexdump_external,
02121                     (FILE *fp, const struct bu_external *ep,
02122                      const char *str));
02123 BU_EXPORT BU_EXTERN(void bu_free_external,
02124                     (struct bu_external *ep));
02125 BU_EXPORT BU_EXTERN(void bu_copy_external,
02126                     (struct bu_external *op,
02127                      const struct bu_external *ip));
02128 BU_EXPORT BU_EXTERN(char *bu_next_token,
02129                     (char *str));
02130 
02131 /*@}*/
02132 /** @addtogroup bitv */
02133 /*@{*/
02134 
02135 /* printb.c */
02136 BU_EXPORT BU_EXTERN(void bu_vls_printb,
02137                     (struct bu_vls *vls,
02138                      const char *s, unsigned long v,
02139                      const char *bits));
02140 BU_EXPORT BU_EXTERN(void bu_printb,
02141                     (const char *s,
02142                      unsigned long v,
02143                      const char *bits));
02144 
02145 /* ptbl.c */
02146 BU_EXPORT BU_EXTERN(void bu_ptbl_init,
02147                     (struct bu_ptbl *b,
02148                      int len,
02149                      const char *str));
02150 BU_EXPORT BU_EXTERN(void bu_ptbl_reset,
02151                     (struct bu_ptbl     *b));
02152 BU_EXPORT BU_EXTERN(int bu_ptbl_ins,
02153                     (struct bu_ptbl *b,
02154                      long *p));
02155 BU_EXPORT BU_EXTERN(int bu_ptbl_locate,
02156                     (const struct bu_ptbl *b,
02157                      const long *p));
02158 BU_EXPORT BU_EXTERN(void bu_ptbl_zero,
02159                     (struct bu_ptbl *b,
02160                      const long *p));
02161 BU_EXPORT BU_EXTERN(int bu_ptbl_ins_unique,
02162                     (struct bu_ptbl *b, long *p));
02163 BU_EXPORT BU_EXTERN(int bu_ptbl_rm,
02164                     (struct bu_ptbl *b,
02165                      const long *p));
02166 BU_EXPORT BU_EXTERN(void bu_ptbl_cat,
02167                     (struct bu_ptbl *dest,
02168                      const struct bu_ptbl *src));
02169 BU_EXPORT BU_EXTERN(void bu_ptbl_cat_uniq,
02170                     (struct bu_ptbl *dest,
02171                      const struct bu_ptbl *src));
02172 BU_EXPORT BU_EXTERN(void bu_ptbl_free,
02173                     (struct bu_ptbl     *b));
02174 BU_EXPORT BU_EXTERN(int bu_ptbl,
02175                     (struct bu_ptbl *b,
02176                      int func, long *p));
02177 BU_EXPORT BU_EXTERN(void bu_pr_ptbl,
02178                     (const char *title,
02179                      const struct bu_ptbl *tbl,
02180                      int verbose));
02181 BU_EXPORT BU_EXTERN(void bu_ptbl_trunc,
02182                     (struct bu_ptbl *tbl,
02183                      int end));
02184 
02185 /*@}*/
02186 /** @addtogroup rb */
02187 /*@{*/
02188 
02189 /* rb_create.c */
02190 BU_EXPORT BU_EXTERN(bu_rb_tree *bu_rb_create,
02191                     (char               *description,
02192                      int                nm_orders,
02193                      int                (**order_funcs)()));
02194 BU_EXPORT BU_EXTERN(bu_rb_tree *bu_rb_create1,
02195                     (char               *description,
02196                      int                (*order_func)()));
02197 /* rb_delete.c */
02198 BU_EXPORT BU_EXTERN(void bu_rb_delete,
02199                     (bu_rb_tree *tree,
02200                      int        order));
02201 #define         bu_rb_delete1(t)        bu_rb_delete((t), 0)
02202 
02203 /* rb_diag.c */
02204 BU_EXPORT BU_EXTERN(void bu_rb_diagnose_tree,
02205                     (bu_rb_tree *tree,
02206                      int        order,
02207                      int        trav_type));
02208 BU_EXPORT BU_EXTERN(void bu_rb_summarize_tree,
02209                     (bu_rb_tree *tree));
02210 /* rb_extreme.c */
02211 BU_EXPORT BU_EXTERN(void *bu_rb_curr,
02212                     (bu_rb_tree *tree,
02213                      int                order));
02214 #define         bu_rb_curr1(t)  bu_rb_curr((t), 0)
02215 BU_EXPORT BU_EXTERN(void *bu_rb_extreme,
02216                     (bu_rb_tree *tree,
02217                      int        order,
02218                      int        sense));
02219 BU_EXPORT BU_EXTERN(void *bu_rb_neighbor,
02220                     (bu_rb_tree *tree,
02221                      int        order,
02222                      int        sense));
02223 /* rb_free.c */
02224 BU_EXPORT BU_EXTERN(void bu_rb_free,
02225                     (bu_rb_tree *tree,
02226                      void       (*free_data)()));
02227 #define BU_RB_RETAIN_DATA       ((void (*)()) 0)
02228 #define         bu_rb_free1(t,f)                                        \
02229                 {                                                       \
02230                     BU_CKMAG((t), BU_RB_TREE_MAGIC, "red-black tree");  \
02231                     bu_free((char *) ((t) -> rbt_order),                \
02232                                 "red-black order function");            \
02233                     bu_rb_free(t,f);                                    \
02234                 }
02235 /* rb_insert.c */
02236 BU_EXPORT BU_EXTERN(int bu_rb_insert,
02237                     (bu_rb_tree *tree,
02238                      void       *data));
02239 BU_EXPORT BU_EXTERN(int bu_rb_is_uniq,
02240                     (bu_rb_tree *tree,
02241                      int        order));
02242 #define         bu_rb_is_uniq1(t)       bu_rb_is_uniq((t), 0)
02243 BU_EXPORT BU_EXTERN(void bu_rb_set_uniqv,
02244                     (bu_rb_tree *tree,
02245                      bitv_t     vec));
02246 BU_EXPORT BU_EXTERN(void bu_rb_uniq_all_off,
02247                     (bu_rb_tree *tree));
02248 BU_EXPORT BU_EXTERN(void bu_rb_uniq_all_on,
02249                     (bu_rb_tree *tree));
02250 BU_EXPORT BU_EXTERN(int bu_rb_uniq_off,
02251                     (bu_rb_tree *tree,
02252                      int        order));
02253 #define         bu_rb_uniq_off1(t)      bu_rb_uniq_off((t), 0)
02254 BU_EXPORT BU_EXTERN(int bu_rb_uniq_on,
02255                     (bu_rb_tree *tree,
02256                      int        order));
02257 #define         bu_rb_uniq_on1(t)       bu_rb_uniq_on((t), 0)
02258 
02259 /* rb_order_stats.c */
02260 BU_EXPORT BU_EXTERN(int bu_rb_rank,
02261                     (bu_rb_tree *tree,
02262                      int        order));
02263 #define         bu_rb_rank1(t)  bu_rb_rank1((t), 0)
02264 BU_EXPORT BU_EXTERN(void *bu_rb_select,
02265                     (bu_rb_tree *tree,
02266                      int        order,
02267                      int        k));
02268 #define         bu_rb_select1(t,k)      bu_rb_select((t), 0, (k))
02269 
02270 /* rb_search.c */
02271 BU_EXPORT BU_EXTERN(void *bu_rb_search,
02272                     (bu_rb_tree *tree,
02273                      int        order,
02274                      void       *data));
02275 #define         bu_rb_search1(t,d)      bu_rb_search((t), 0, (d))
02276 
02277 /* rb_walk.c */
02278 BU_EXPORT BU_EXTERN(void bu_rb_walk,
02279                     (bu_rb_tree *tree,
02280                      int        order,
02281                      void       (*visit)(),
02282                      int        trav_type));
02283 #define         bu_rb_walk1(t,v,d)      bu_rb_walk((t), 0, (v), (d))
02284 
02285 /*@}*/
02286 /** @addtogroup thread */
02287 /*@{*/
02288 
02289 /* semaphore.c */
02290 BU_EXPORT BU_EXTERN(void bu_semaphore_init,
02291                     (unsigned int nsemaphores));
02292 BU_EXPORT BU_EXTERN(void bu_semaphore_acquire,
02293                     (unsigned int i));
02294 BU_EXPORT BU_EXTERN(void bu_semaphore_release,
02295                     (unsigned int i));
02296 
02297 /*@}*/
02298 /** @addtogroup vls */
02299 /*@{*/
02300 
02301 /* vls.c */
02302 BU_EXPORT BU_EXTERN(void bu_vls_init,
02303                     (struct bu_vls *vp));
02304 BU_EXPORT BU_EXTERN(void bu_vls_init_if_uninit,
02305                     (struct bu_vls *vp));
02306 BU_EXPORT BU_EXTERN(struct bu_vls *bu_vls_vlsinit,
02307                     ());
02308 BU_EXPORT BU_EXTERN(char *bu_vls_addr,
02309                     (const struct bu_vls *vp));
02310 BU_EXPORT BU_EXTERN(char *bu_vls_strdup,
02311                     (const struct bu_vls *vp));
02312 BU_EXPORT BU_EXTERN(char *bu_vls_strgrab,
02313                     (struct bu_vls *vp));
02314 BU_EXPORT BU_EXTERN(void bu_vls_extend,
02315                     (struct bu_vls *vp,
02316                      unsigned int extra));
02317 BU_EXPORT BU_EXTERN(void bu_vls_setlen,
02318                     (struct bu_vls *vp,
02319                      int newlen));
02320 BU_EXPORT BU_EXTERN(int bu_vls_strlen,
02321                     (const struct bu_vls *vp));
02322 BU_EXPORT BU_EXTERN(void bu_vls_trunc,
02323                     (struct bu_vls *vp,
02324                      int len));
02325 BU_EXPORT BU_EXTERN(void bu_vls_trunc2,
02326                     (struct bu_vls *vp,
02327                      int len));
02328 BU_EXPORT BU_EXTERN(void bu_vls_nibble,
02329                     (struct bu_vls *vp,
02330                      int len));
02331 BU_EXPORT BU_EXTERN(void bu_vls_free,
02332                     (struct bu_vls *vp));
02333 BU_EXPORT BU_EXTERN(void bu_vls_vlsfree,
02334                     (struct bu_vls *vp));
02335 BU_EXPORT BU_EXTERN(void bu_vls_strcpy,
02336                     (struct bu_vls *vp,
02337                      const char *s));
02338 BU_EXPORT BU_EXTERN(void bu_vls_strncpy,
02339                     (struct bu_vls *vp,
02340                      const char *s,
02341                      long n));
02342 BU_EXPORT BU_EXTERN(void bu_vls_strcat,
02343                     (struct bu_vls *vp,
02344                      const char *s));
02345 BU_EXPORT BU_EXTERN(void bu_vls_strncat,
02346                     (struct bu_vls *vp,
02347                      const char *s,
02348                      long n));
02349 BU_EXPORT BU_EXTERN(void bu_vls_vlscat,
02350                     (struct bu_vls *dest,
02351                      const struct bu_vls *src));
02352 BU_EXPORT BU_EXTERN(void bu_vls_vlscatzap,
02353                     (struct bu_vls *dest,
02354                      struct bu_vls *src));
02355 BU_EXPORT BU_EXTERN(void bu_vls_from_argv,
02356                     (struct bu_vls *vp,
02357                      int argc,
02358                      const char *argv[]));
02359 BU_EXPORT BU_EXTERN(int bu_argv_from_string,
02360                     (char **argv,
02361                      int lim,
02362                      char *lp));
02363 BU_EXPORT BU_EXTERN(void bu_vls_fwrite,
02364                     (FILE *fp,
02365                      const struct bu_vls *vp));
02366 BU_EXPORT BU_EXTERN(void bu_vls_write,
02367                     (int fd,
02368                      const struct bu_vls *vp));
02369 BU_EXPORT BU_EXTERN(int bu_vls_read,
02370                     (struct bu_vls *vp,
02371                      int fd));
02372 BU_EXPORT BU_EXTERN(int bu_vls_gets,
02373                     (struct bu_vls *vp,
02374                      FILE *fp));
02375 BU_EXPORT BU_EXTERN(void bu_vls_putc,
02376                     (struct bu_vls *vp,
02377                      int c));
02378 BU_EXPORT BU_EXTERN(void bu_vls_trimspace,
02379                     (struct bu_vls *vp));
02380 #if 0
02381 BU_EXPORT BU_EXTERN(void bu_vls_vprintf,
02382                     (struct bu_vls *vls,
02383                      const char *fmt,
02384                      va_list ap));
02385 #endif
02386 BU_EXPORT BU_EXTERN(void bu_vls_printf,
02387                     (struct bu_vls *vls,
02388                      char *fmt, ...));
02389 BU_EXPORT BU_EXTERN(void bu_vls_sprintf,
02390                     (struct bu_vls *vls,
02391                      char *fmt, ...));
02392 BU_EXPORT BU_EXTERN(void bu_vls_spaces,
02393                     (struct bu_vls *vp,
02394                      int cnt));
02395 BU_EXPORT BU_EXTERN(int bu_vls_print_positions_used,
02396                     (const struct bu_vls *vp));
02397 BU_EXPORT BU_EXTERN(void bu_vls_detab,
02398                     (struct bu_vls *vp));
02399 
02400 #if 0
02401 BU_EXPORT BU_EXTERN(void bu_vls_blkset,
02402                     (struct bu_vls *vp,
02403                      int len,
02404                      int ch));
02405 #endif
02406 
02407 BU_EXPORT BU_EXTERN(void bu_vls_prepend,
02408                     (struct bu_vls *vp,
02409                      char *str));
02410 
02411 /*@}*/
02412 
02413 
02414 /* vers.c */
02415 BU_EXPORT extern const char             bu_version[];
02416 
02417 /** @addtogroup bu_log */
02418 /*@{*/
02419 /* units.c */
02420 BU_EXPORT BU_EXTERN(double bu_units_conversion,
02421                     (const char *str));
02422 BU_EXPORT BU_EXTERN(const char *bu_units_string,
02423                     (const double mm));
02424 BU_EXPORT BU_EXTERN(double bu_mm_value,
02425                     (const char *s));
02426 BU_EXPORT BU_EXTERN(void bu_mm_cvt,
02427                     (register const struct bu_structparse *sdp,
02428                      register const char *name,
02429                      char *base,
02430                      const char *value));
02431 
02432 
02433 
02434 /*@}*/
02435 /** @addtogroup hton */
02436 /*@{*/
02437 
02438 /* xdr.c */
02439 /* Macro version of library routine bu_glong() */
02440 /* The argument is expected to be of type "unsigned char" */
02441 #define BU_GLONGLONG(_cp)       \
02442             ((((long)((_cp)[0])) << 56) |       \
02443              (((long)((_cp)[1])) << 48) |       \
02444              (((long)((_cp)[2])) << 40) |       \
02445              (((long)((_cp)[3])) << 32) |       \
02446              (((long)((_cp)[4])) << 24) |       \
02447              (((long)((_cp)[5])) << 16) |       \
02448              (((long)((_cp)[6])) <<  8) |       \
02449               ((long)((_cp)[7])) )
02450 #define BU_GLONG(_cp)   \
02451             ((((long)((_cp)[0])) << 24) |       \
02452              (((long)((_cp)[1])) << 16) |       \
02453              (((long)((_cp)[2])) <<  8) |       \
02454               ((long)((_cp)[3])) )
02455 #define BU_GSHORT(_cp)  \
02456             ((((short)((_cp)[0])) << 8) | \
02457                        (_cp)[1] )
02458 
02459 BU_EXPORT BU_EXTERN(unsigned short bu_gshort,
02460                     (const unsigned char *msgp));
02461 BU_EXPORT BU_EXTERN(unsigned long bu_glong,
02462                     (const unsigned char *msgp));
02463 BU_EXPORT BU_EXTERN(unsigned char *bu_pshort,
02464                     (register unsigned char *msgp,
02465                      register int s));
02466 BU_EXPORT BU_EXTERN(unsigned char *bu_plong,
02467                     (register unsigned char *msgp,
02468                      register unsigned long l));
02469 
02470 
02471 
02472 /*@}*/
02473 /** @addtogroup bu_log */
02474 /*@{*/
02475 
02476 /* association.c */
02477 BU_EXPORT BU_EXTERN(struct bu_vls *bu_association,
02478                     (const char *fname,
02479                      const char *value,
02480                      int field_sep));
02481 
02482 
02483 /*@}*/
02484 /** @addtogroup butcl */
02485 /*@{*/
02486 
02487 /* Things that live in libbu/observer.c */
02488 BU_EXPORT extern struct bu_cmdtab bu_observer_cmds[];
02489 BU_EXPORT BU_EXTERN(void bu_observer_notify,
02490                     ());
02491 BU_EXPORT BU_EXTERN(void bu_observer_free,
02492                     (struct bu_observer *));
02493 
02494 /* bu_tcl.c */
02495 /* The presence of Tcl_Interp as an arg prevents giving arg list */
02496 BU_EXPORT BU_EXTERN(void bu_badmagic_tcl,
02497                     (Tcl_Interp *interp,
02498                      const long *ptr,
02499                      unsigned long      magic,
02500                      const char *str,
02501                      const char *file,
02502                      int        line));
02503 
02504 BU_EXPORT BU_EXTERN(void bu_structparse_get_terse_form,
02505                     (Tcl_Interp *interp,
02506                      const struct bu_structparse *sp));
02507 
02508 BU_EXPORT BU_EXTERN(int bu_structparse_argv,
02509                     (Tcl_Interp                         *interp,
02510                      int                                argc,
02511                      char                               **argv,
02512                      const struct bu_structparse        *desc,
02513                      char                               *base));
02514 
02515 BU_EXPORT BU_EXTERN(int bu_tcl_mem_barriercheck,
02516                     (ClientData clientData,
02517                      Tcl_Interp *interp,
02518                      int        argc,
02519                      char       **argv));
02520 
02521 BU_EXPORT BU_EXTERN(int bu_tcl_ck_malloc_ptr,
02522                     (ClientData         clientData,
02523                      Tcl_Interp         *interp,
02524                      int                argc,
02525                      char               **argv));
02526 
02527 BU_EXPORT BU_EXTERN(int bu_tcl_malloc_len_roundup,
02528                     (ClientData clientData,
02529                      Tcl_Interp *interp,
02530                      int        argc,
02531                      char       **argv));
02532 
02533 BU_EXPORT BU_EXTERN(int bu_tcl_prmem,
02534                     (ClientData clientData,
02535                      Tcl_Interp *interp,
02536                      int        argc,
02537                      char       **argv));
02538 
02539 BU_EXPORT BU_EXTERN(int bu_tcl_printb,
02540                     (ClientData clientData,
02541                      Tcl_Interp *interp,
02542                      int        argc,
02543                      char       **argv));
02544 
02545 BU_EXPORT BU_EXTERN(int bu_get_value_by_keyword,
02546                     (ClientData clientData,
02547                      Tcl_Interp *interp,
02548                      int        argc,
02549                      char       **argv));
02550 
02551 BU_EXPORT BU_EXTERN(int bu_get_all_keyword_values,
02552                     (ClientData clientData,
02553                      Tcl_Interp *interp,
02554                      int        argc,
02555                      char       **argv));
02556 
02557 BU_EXPORT BU_EXTERN(int bu_tcl_rgb_to_hsv,
02558                     (ClientData clientData,
02559                      Tcl_Interp *interp,
02560                      int        argc,
02561                      char       **argv));
02562 
02563 BU_EXPORT BU_EXTERN(int bu_tcl_hsv_to_rgb,
02564                     (ClientData clientData,
02565                      Tcl_Interp *interp,
02566                      int        argc,
02567                      char       **argv));
02568 
02569 BU_EXPORT BU_EXTERN(int bu_tcl_key_eq_to_key_val,
02570                     (ClientData clientData,
02571                      Tcl_Interp *interp,
02572                      int        argc,
02573                      char       **argv));
02574 
02575 BU_EXPORT BU_EXTERN(int bu_tcl_shader_to_key_val,
02576                     (ClientData clientData,
02577                      Tcl_Interp *interp,
02578                      int        argc,
02579                      char       **argv));
02580 
02581 BU_EXPORT BU_EXTERN(int bu_tcl_key_val_to_key_eq,
02582                     (ClientData clientData,
02583                      Tcl_Interp *interp,
02584                      int        argc,
02585                      char       **argv));
02586 
02587 BU_EXPORT BU_EXTERN(int bu_tcl_shader_to_key_eq,
02588                     (ClientData clientData,
02589                      Tcl_Interp *interp,
02590                      int        argc,
02591                      char       **argv));
02592 
02593 BU_EXPORT BU_EXTERN(int bu_tcl_brlcad_root,
02594                     (ClientData clientData,
02595                      Tcl_Interp *interp,
02596                      int         argc,
02597                      char       **argv));
02598 
02599 BU_EXPORT BU_EXTERN(int bu_tcl_brlcad_data,
02600                     (ClientData clientData,
02601                      Tcl_Interp *interp,
02602                      int         argc,
02603                      char       **argv));
02604 
02605 /* bu_tcl_brlcad_path is deprecated */
02606 BU_EXPORT BU_EXTERN(int bu_tcl_brlcad_path,
02607                     (ClientData clientData,
02608                      Tcl_Interp *interp,
02609                      int         argc,
02610                      char       **argv));
02611 
02612 BU_EXPORT BU_EXTERN(int bu_tcl_units_conversion,
02613                     (ClientData clientData,
02614                      Tcl_Interp *interp,
02615                      int        argc,
02616                      char       **argv));
02617 
02618 BU_EXPORT BU_EXTERN(void bu_tcl_setup,
02619                     (Tcl_Interp *interp));
02620 
02621 #ifdef BRLCAD_DEBUG
02622 BU_EXPORT BU_EXTERN(int Bu_d_Init,
02623                     (Tcl_Interp *interp));
02624 #else
02625 BU_EXPORT BU_EXTERN(int Bu_Init,
02626                     (Tcl_Interp *interp));
02627 #endif
02628 
02629 
02630 /*@}*/
02631 /** @addtogroup bu_log */
02632 /*@{*/
02633 
02634 /* lex.c */
02635 #define BU_LEX_ANY      0       /* pseudo type */
02636 struct bu_lex_t_int {
02637         int type;
02638         int value;
02639 };
02640 #define BU_LEX_INT      1
02641 struct bu_lex_t_dbl {
02642         int     type;
02643         double  value;
02644 };
02645 #define BU_LEX_DOUBLE   2
02646 struct bu_lex_t_key {
02647         int     type;
02648         int     value;
02649 };
02650 #define BU_LEX_SYMBOL   3
02651 #define BU_LEX_KEYWORD  4
02652 struct bu_lex_t_id {
02653         int     type;
02654         char    *value;
02655 };
02656 #define BU_LEX_IDENT    5
02657 #define BU_LEX_NUMBER   6       /* Pseudo type */
02658 union bu_lex_token {
02659         int                     type;
02660         struct  bu_lex_t_int    t_int;
02661         struct  bu_lex_t_dbl    t_dbl;
02662         struct  bu_lex_t_key    t_key;
02663         struct  bu_lex_t_id     t_id;
02664 };
02665 struct bu_lex_key {
02666         int     tok_val;
02667         char    *string;
02668 };
02669 #define BU_LEX_NEED_MORE        0
02670 
02671 BU_EXPORT BU_EXTERN(int bu_lex,
02672                     (union bu_lex_token *token,
02673                      struct bu_vls *rtstr,
02674                      struct bu_lex_key *keywords,
02675                      struct bu_lex_key *symbols));
02676 
02677 
02678 /* mread.c */
02679 BU_EXPORT BU_EXTERN(long int bu_mread,
02680                     (int fd, void *bufp, long int n));
02681 
02682 /* mro.c */
02683 BU_EXPORT BU_EXTERN(void bu_mro_init_with_string,
02684                     (struct bu_mro *mrop, const char *string));
02685 BU_EXPORT BU_EXTERN(void bu_mro_set,
02686                     (struct bu_mro *mrop,
02687                      const char *string));
02688 BU_EXPORT BU_EXTERN(void bu_mro_init,
02689                     (struct bu_mro *mrop));
02690 BU_EXPORT BU_EXTERN(void bu_mro_free,
02691                     (struct bu_mro *mrop));
02692 
02693 
02694 /*@}*/
02695 /** @addtogroup bu_hash */
02696 /*@{*/
02697 
02698 
02699 /* hash.c */
02700 struct bu_hash_entry {
02701         long magic;
02702         unsigned char *key;
02703         unsigned char *value;
02704         int key_len;
02705         struct bu_hash_entry *next;
02706 };
02707 
02708 struct bu_hash_tbl {
02709         long magic;
02710         unsigned long mask;
02711         unsigned long num_lists;
02712         unsigned long num_entries;
02713         struct bu_hash_entry **lists;
02714 };
02715 
02716 struct bu_hash_record {
02717         long magic;
02718         struct bu_hash_tbl *tbl;
02719         unsigned long index;
02720         struct bu_hash_entry *hsh_entry;
02721 };
02722 
02723 #define BU_HASH_TBL_MAGIC       0x48415348      /* "HASH" */
02724 #define BU_HASH_RECORD_MAGIC    0x68617368      /* "hash" */
02725 #define BU_HASH_ENTRY_MAGIC     0x48454E54      /* "HENT" */
02726 #define BU_CK_HASH_TBL(_hp)     BU_CKMAG( _hp, BU_HASH_TBL_MAGIC, "bu_hash_tbl" )
02727 #define BU_CK_HASH_RECORD(_rp)  BU_CKMAG( _rp, BU_HASH_RECORD_MAGIC, "bu_hash_record" )
02728 #define BU_CK_HASH_ENTRY(_ep)   BU_CKMAG( _ep, BU_HASH_ENTRY_MAGIC, "bu_hash_entry" )
02729 
02730 BU_EXPORT BU_EXTERN(unsigned long bu_hash,
02731                     (unsigned char *str,
02732                      int len));
02733 BU_EXPORT BU_EXTERN(struct bu_hash_tbl *bu_create_hash_tbl,
02734                     (unsigned long tbl_size));
02735 BU_EXPORT BU_EXTERN(struct bu_hash_entry *bu_find_hash_entry,
02736                     (struct bu_hash_tbl *hsh_tbl,
02737                      unsigned char *key,
02738                      int key_len,
02739                      struct bu_hash_entry **prev,
02740                      unsigned long *index2));
02741 BU_EXPORT BU_EXTERN(void bu_set_hash_value,
02742                     (struct bu_hash_entry *hsh_entry,
02743                      unsigned char *value));
02744 BU_EXPORT BU_EXTERN(unsigned char *bu_get_hash_value,
02745                     (struct bu_hash_entry *hsh_entry));
02746 BU_EXPORT BU_EXTERN(unsigned char *bu_get_hash_key,
02747                     (struct bu_hash_entry *hsh_entry));
02748 BU_EXPORT BU_EXTERN(struct bu_hash_entry *bu_hash_add_entry,
02749                     (struct bu_hash_tbl *hsh_tbl,
02750                      unsigned char *key,
02751                      int key_len,
02752                      int *new_entry));
02753 BU_EXPORT BU_EXTERN(void bu_hash_tbl_pr,
02754                     (struct bu_hash_tbl *hsh_tbl,
02755                      char *str));
02756 BU_EXPORT BU_EXTERN(void bu_hash_tbl_free,
02757                     (struct bu_hash_tbl *hsh_tbl));
02758 BU_EXPORT BU_EXTERN(struct bu_hash_entry *bu_hash_tbl_first,
02759                     (struct bu_hash_tbl *hsh_tbl,
02760                      struct bu_hash_record *rec));
02761 BU_EXPORT BU_EXTERN(struct bu_hash_entry *bu_hash_tbl_next,
02762                     (struct bu_hash_record *rec));
02763 
02764 __END_DECLS
02765 
02766 #endif  /* __BU_H__ */
02767 /*@}*/
02768 /*
02769  * Local Variables:
02770  * mode: C
02771  * tab-width: 8
02772  * c-basic-offset: 4
02773  * indent-tabs-mode: t
02774  * End:
02775  * ex: shiftwidth=4 tabstop=8
02776  */
02777 

Generated on Mon Sep 18 01:24:40 2006 for BRL-CAD by  doxygen 1.4.6