/usr/include/plib/ul.h is in libplib-dev 1.8.5-5.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 | /*
PLIB - A Suite of Portable Game Libraries
Copyright (C) 1998,2002 Steve Baker
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For further information visit http://plib.sourceforge.net
$Id: ul.h 2117 2007-09-13 23:21:09Z fayjf $
*/
//
// UL - utility library
//
// Contains:
// - necessary system includes
// - basic types
// - error message routines
// - high performance clocks
// - ulList
// - ulLinkedList
// - more to come (endian support, version ID)
//
#ifndef _INCLUDED_UL_H_
#define _INCLUDED_UL_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
/**********************\
* *
* Determine OS type *
* *
\**********************/
#if defined(__CYGWIN__)
#define UL_WIN32 1
#define UL_CYGWIN 1 /* Windoze AND Cygwin. */
#elif defined(_WIN32) || defined(__WIN32__) || defined(_MSC_VER)
#define UL_WIN32 1
#define UL_MSVC 1 /* Windoze AND MSVC. */
#elif defined(__BEOS__)
#define UL_BEOS 1
#elif defined( macintosh )
#define UL_MACINTOSH 1
#elif defined(__APPLE__)
#define UL_MAC_OSX 1
#elif defined(__linux__)
#define UL_LINUX 1
#elif defined(__sgi)
#define UL_IRIX 1
#elif defined(_AIX)
#define UL_AIX 1
#elif defined(SOLARIS) || defined(sun)
#define UL_SOLARIS 1
#elif defined(hpux)
#define UL_HPUX 1
#elif defined(__GNU__)
#define UL_GNU 1
#elif (defined(__unix__) || defined(unix)) && !defined(USG)
#define UL_BSD 1
#endif
/*
Add specialised includes/defines...
*/
#ifdef UL_WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mmsystem.h>
#include <regstr.h>
#define UL_WGL 1
#endif
#ifdef UL_CYGWIN
#include <unistd.h>
#define UL_WGL 1
#endif
#ifdef UL_BEOS
#include <be/kernel/image.h>
#define UL_GLX 1
#endif
#ifdef UL_MACINTOSH
#include <CodeFragments.h>
#include <unistd.h>
#define UL_AGL 1
#endif
#ifdef UL_MAC_OSX
#include <unistd.h>
#define UL_CGL 1
#endif
#if defined(UL_LINUX) || defined(UL_BSD) || defined(UL_IRIX) || defined(UL_SOLARIS) || defined(UL_AIX)
#include <unistd.h>
#include <dlfcn.h>
#include <fcntl.h>
#define UL_GLX 1
#endif
#if defined(UL_BSD)
#include <sys/param.h>
#define UL_GLX 1
#endif
#ifdef UL_GNU
#include <unistd.h>
#include <dlfcn.h>
#define UL_GLX 1
#endif
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <float.h>
#include <errno.h>
/* PLIB version macros */
#define PLIB_MAJOR_VERSION 1
#define PLIB_MINOR_VERSION 8
#define PLIB_TINY_VERSION 5
#define PLIB_VERSION (PLIB_MAJOR_VERSION*100 \
+PLIB_MINOR_VERSION*10 \
+PLIB_TINY_VERSION)
/* SGI machines seem to suffer from a lack of FLT_EPSILON so... */
#ifndef FLT_EPSILON
#define FLT_EPSILON 1.19209290e-07f
#endif
#ifndef DBL_EPSILON
#define DBL_EPSILON 1.19209290e-07f
#endif
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
/* SUNWspro 4.2 and earlier need bool to be defined */
#if defined(__SUNPRO_CC) && __SUNPRO_CC < 0x500
typedef int bool ;
const int true = 1 ;
const int false = 0 ;
#endif
/* Let's define our own "min" and "max" so that different operating systems
* don't complain
*/
#define ulMax(a,b) ((a)>(b)?(a):(b))
#define ulMin(a,b) ((a)<(b)?(a):(b))
/*
Basic Types
*/
/*
High precision clocks.
*/
class ulClock
{
double start ;
double now ;
double delta ;
double last_time ;
double max_delta ;
#ifdef UL_WIN32
static double res ;
static int perf_timer ;
void initPerformanceTimer () ;
#endif
double getRawTime () const ;
public:
ulClock () { reset () ; }
void reset ()
{
#ifdef UL_WIN32
initPerformanceTimer () ;
#endif
start = getRawTime () ;
now = 0.0 ;
max_delta = 0.2 ;
delta = 0.0000001 ; /* Faked so stoopid programs won't div0 */
last_time = 0.0 ;
}
void setMaxDelta ( double maxDelta ) { max_delta = maxDelta ; }
double getMaxDelta () const { return max_delta ; }
void update () ;
double getAbsTime () const { return now ; }
double getDeltaTime () const { return delta ; }
double getFrameRate () const { return 1.0 / delta ; }
} ;
inline void ulSleep ( int seconds )
{
if ( seconds >= 0 )
{
#ifdef UL_WIN32
Sleep ( 1000 * seconds ) ;
#else
sleep ( seconds ) ;
#endif
}
}
inline void ulMilliSecondSleep ( int milliseconds )
{
if ( milliseconds >= 0 )
{
#ifdef UL_WIN32
Sleep ( milliseconds ) ;
#else
usleep ( milliseconds * 1000 ) ;
#endif
}
}
/*
This is extern C to enable 'configure.in' to
find it with a C-coded probe.
*/
extern "C" void ulInit () ;
/*
Error handler.
*/
enum ulSeverity
{
UL_DEBUG, // Messages that can safely be ignored.
UL_WARNING, // Messages that are important.
UL_FATAL, // Errors that we cannot recover from.
UL_MAX_SEVERITY
} ;
typedef void (*ulErrorCallback) ( enum ulSeverity severity, char* msg ) ;
void ulSetError ( enum ulSeverity severity, const char *fmt, ... ) ;
char* ulGetError ( void ) ;
void ulClearError ( void ) ;
ulErrorCallback ulGetErrorCallback ( void ) ;
void ulSetErrorCallback ( ulErrorCallback cb ) ;
/*
Directory Reading
*/
#define UL_NAME_MAX 256
typedef struct _ulDir ulDir ;
struct ulDirEnt
{
char d_name [ UL_NAME_MAX+1 ];
bool d_isdir ;
} ;
int ulIsAbsolutePathName ( const char *pathname ) ;
char *ulGetCWD ( char *result, int maxlength ) ;
ulDir* ulOpenDir ( const char* dirname ) ;
ulDirEnt* ulReadDir ( ulDir* dir ) ;
void ulCloseDir ( ulDir* dir ) ;
// file handling
char* ulMakePath( char* path, const char* dir, const char* fname );
bool ulFileExists ( const char *fileName ) ;
void ulFindFile( char *filenameOutput, const char *path,
const char * tfnameInput, const char *sAPOM ) ;
/*
Endian handling
*/
static const int _ulEndianTest = 1;
#define ulIsLittleEndian (*((char *) &_ulEndianTest ) != 0)
#define ulIsBigEndian (*((char *) &_ulEndianTest ) == 0)
inline void ulEndianSwap(unsigned int *x)
{
*x = (( *x >> 24 ) & 0x000000FF ) |
(( *x >> 8 ) & 0x0000FF00 ) |
(( *x << 8 ) & 0x00FF0000 ) |
(( *x << 24 ) & 0xFF000000 ) ;
}
inline void ulEndianSwap(unsigned short *x)
{
*x = (( *x >> 8 ) & 0x00FF ) |
(( *x << 8 ) & 0xFF00 ) ;
}
inline void ulEndianSwap(float *x) { ulEndianSwap((unsigned int *)x); }
inline void ulEndianSwap(int *x) { ulEndianSwap((unsigned int *)x); }
inline void ulEndianSwap(short *x) { ulEndianSwap((unsigned short *)x); }
inline unsigned short ulEndianLittle16(unsigned short x) {
if (ulIsLittleEndian) {
return x;
} else {
ulEndianSwap(&x);
return x;
}
}
inline unsigned int ulEndianLittle32(unsigned int x) {
if (ulIsLittleEndian) {
return x;
} else {
ulEndianSwap(&x);
return x;
}
}
inline float ulEndianLittleFloat(float x) {
if (ulIsLittleEndian) {
return x;
} else {
ulEndianSwap(&x);
return x;
}
}
inline void ulEndianLittleArray16(unsigned short *x, int length) {
if (ulIsLittleEndian) {
return;
} else {
for (int i = 0; i < length; i++) {
ulEndianSwap(x++);
}
}
}
inline void ulEndianLittleArray32(unsigned int *x, int length) {
if (ulIsLittleEndian) {
return;
} else {
for (int i = 0; i < length; i++) {
ulEndianSwap(x++);
}
}
}
inline void ulEndianLittleArrayFloat(float *x, int length) {
if (ulIsLittleEndian) {
return;
} else {
for (int i = 0; i < length; i++) {
ulEndianSwap(x++);
}
}
}
inline void ulEndianBigArray16(unsigned short *x, int length) {
if (ulIsBigEndian) {
return;
} else {
for (int i = 0; i < length; i++) {
ulEndianSwap(x++);
}
}
}
inline void ulEndianBigArray32(unsigned int *x, int length) {
if (ulIsBigEndian) {
return;
} else {
for (int i = 0; i < length; i++) {
ulEndianSwap(x++);
}
}
}
inline void ulEndianBigArrayFloat(float *x, int length) {
if (ulIsBigEndian) {
return;
} else {
for (int i = 0; i < length; i++) {
ulEndianSwap(x++);
}
}
}
inline unsigned short ulEndianBig16(unsigned short x) {
if (ulIsBigEndian) {
return x;
} else {
ulEndianSwap(&x);
return x;
}
}
inline unsigned int ulEndianBig32(unsigned int x) {
if (ulIsBigEndian) {
return x;
} else {
ulEndianSwap(&x);
return x;
}
}
inline float ulEndianBigFloat(float x) {
if (ulIsBigEndian) {
return x;
} else {
ulEndianSwap(&x);
return x;
}
}
inline unsigned short ulEndianReadLittle16(FILE *f) {
unsigned short x;
fread(&x, 2, 1, f);
return ulEndianLittle16(x);
}
inline unsigned int ulEndianReadLittle32(FILE *f) {
unsigned int x;
fread(&x, 4, 1, f);
return ulEndianLittle32(x);
}
inline float ulEndianReadLittleFloat(FILE *f) {
float x;
fread(&x, 4, 1, f);
return ulEndianLittleFloat(x);
}
inline unsigned short ulEndianReadBig16(FILE *f) {
unsigned short x;
fread(&x, 2, 1, f);
return ulEndianBig16(x);
}
inline unsigned int ulEndianReadBig32(FILE *f) {
unsigned int x;
fread(&x, 4, 1, f);
return ulEndianBig32(x);
}
inline float ulEndianReadBigFloat(FILE *f) {
float x;
fread(&x, 4, 1, f);
return ulEndianBigFloat(x);
}
inline size_t ulEndianWriteLittle16(FILE *f, unsigned short x) {
x = ulEndianLittle16(x);
return fwrite( &x, 2, 1, f );
}
inline size_t ulEndianWriteLittle32(FILE *f, unsigned int x) {
x = ulEndianLittle32(x);
return fwrite( &x, 4, 1, f );
}
inline size_t ulEndianWriteLittleFloat(FILE *f, float x) {
x = ulEndianLittleFloat(x);
return fwrite( &x, 4, 1, f );
}
inline size_t ulEndianWriteBig16(FILE *f, unsigned short x) {
x = ulEndianBig16(x);
return fwrite( &x, 2, 1, f );
}
inline size_t ulEndianWriteBig32(FILE *f, unsigned int x) {
x = ulEndianBig32(x);
return fwrite( &x, 4, 1, f );
}
inline size_t ulEndianWriteBigFloat(FILE *f, float x) {
x = ulEndianBigFloat(x);
return fwrite( &x, 4, 1, f );
}
/*
Windoze/BEOS code based on contribution from Sean L. Palmer
*/
#ifdef UL_WIN32
class ulDynamicLibrary
{
HMODULE handle ;
public:
ulDynamicLibrary ( const char *libname )
{
char dllname[1024];
strcpy ( dllname, libname ) ;
strcat ( dllname, ".dll" ) ;
handle = (HMODULE) LoadLibrary ( dllname ) ;
}
void *getFuncAddress ( const char *funcname )
{
return (void *) GetProcAddress ( handle, funcname ) ; //lint !e611
}
~ulDynamicLibrary ()
{
if ( handle != NULL )
FreeLibrary ( handle ) ;
}
} ;
#elif defined (UL_MACINTOSH)
class ulDynamicLibrary
{
CFragConnectionID connection;
OSStatus error;
public:
ulDynamicLibrary ( const char *libname )
{
Str63 pstr;
int sz;
sz = strlen (libname);
if (sz < 64) {
pstr[0] = sz;
memcpy (pstr+1, libname, sz);
error = GetSharedLibrary (pstr, kPowerPCCFragArch, kReferenceCFrag,
&connection, NULL, NULL);
}
else
error = 1;
}
~ulDynamicLibrary ()
{
if ( ! error )
CloseConnection (&connection);
}
void* getFuncAddress ( const char *funcname )
{
if ( ! error ) {
char* addr;
Str255 sym;
int sz;
sz = strlen (funcname);
if (sz < 256) {
sym[0] = sz;
memcpy (sym+1, funcname, sz);
error = FindSymbol (connection, sym, &addr, 0);
if ( ! error )
return addr;
}
}
return NULL;
}
};
#elif defined (UL_MAC_OSX)
class ulDynamicLibrary
{
public:
ulDynamicLibrary ( const char *libname )
{
}
~ulDynamicLibrary ()
{
}
void* getFuncAddress ( const char *funcname )
{
ulSetError ( UL_WARNING, "ulDynamicLibrary unsuppored on Mac OS X" );
return NULL;
}
};
#elif defined (__BEOS__)
class ulDynamicLibrary
{
image_id *handle ;
public:
ulDynamicLibrary ( const char *libname )
{
char addonname[1024] ;
strcpy ( addonname, libname ) ;
strcat ( addonname, ".so" ) ;
handle = new image_id ;
*handle = load_add_on ( addonname ) ;
if ( *handle == B_ERROR )
{
delete handle ;
handle = NULL ;
}
}
void *getFuncAddress ( const char *funcname )
{
void *sym = NULL ;
if ( handle &&
get_image_symbol ( handle, "funcname",
B_SYMBOL_TYPE_TEXT, &sym ) == B_NO_ERROR )
return sym ;
return NULL ;
}
~ulDynamicLibrary ()
{
if ( handle != NULL )
unload_add_on ( handle ) ;
delete handle ;
}
} ;
# else
/*
Linux/UNIX
*/
class ulDynamicLibrary
{
void *handle ;
public:
ulDynamicLibrary ( const char *libname )
{
char dsoname [ 1024 ] ;
strcpy ( dsoname, libname ) ;
strcat ( dsoname, ".so" ) ;
handle = (void *) dlopen ( dsoname, RTLD_NOW | RTLD_GLOBAL ) ;
if ( handle == NULL )
ulSetError ( UL_WARNING, "ulDynamicLibrary: %s\n", dlerror() ) ;
}
void *getFuncAddress ( const char *funcname )
{
return (handle==NULL) ? NULL : dlsym ( handle, funcname ) ;
}
~ulDynamicLibrary ()
{
if ( handle != NULL )
dlclose ( handle ) ;
}
} ;
#endif
class ulList
{
protected:
unsigned int total ; /* The total number of entities in the list */
unsigned int limit ; /* The current limit on number of entities */
unsigned int next ; /* The next entity when we are doing getNext ops */
void **entity_list ; /* The list. */
void sizeChk (void) ;
public:
ulList ( int init_max = 1 ) ;
virtual ~ulList (void) ;
void *getEntity ( unsigned int n )
{
next = n + 1 ;
return ( n >= total ) ? (void *) NULL : entity_list [ n ] ;
}
virtual void addEntity ( void *entity ) ;
virtual void addEntityBefore ( int n, void *entity ) ;
virtual void removeEntity ( unsigned int n ) ;
void removeAllEntities () ;
void removeEntity ( void *entity )
{
removeEntity ( searchForEntity ( entity ) ) ;
}
virtual void replaceEntity ( unsigned int n, void *new_entity ) ;
void replaceEntity ( void *old_entity, void *new_entity )
{
replaceEntity ( searchForEntity ( old_entity ), new_entity ) ;
}
void *getNextEntity (void) { return getEntity ( next ) ; }
int getNumEntities (void) const { return total ; }
int searchForEntity ( void *entity ) const ;
} ;
typedef bool (*ulIterateFunc)( const void *data, void *user_data ) ;
typedef int (*ulCompareFunc)( const void *data1, const void *data2 ) ;
/*
Linked list.
*/
class ulListNode ;
class ulLinkedList
{
protected:
ulListNode *head ;
ulListNode *tail ;
int nnodes ;
bool sorted ;
void unlinkNode ( ulListNode *prev, ulListNode *node ) ;
bool isValidPosition ( int pos ) const
{
if ( ( pos < 0 ) || ( pos >= nnodes ) )
{
ulSetError ( UL_WARNING, "ulLinkedList: Invalid 'pos' %u", pos ) ;
return false ;
}
return true ;
}
public:
ulLinkedList ()
{
head = tail = NULL ;
nnodes = 0 ;
sorted = true ;
}
~ulLinkedList () { empty () ; }
int getNumNodes ( void ) const { return nnodes ; }
bool isSorted ( void ) const { return sorted ; }
int getNodePosition ( void *data ) const ;
void insertNode ( void *data, int pos ) ;
void prependNode ( void *data ) { insertNode ( data, 0 ) ; }
void appendNode ( void *data ) ;
int insertSorted ( void *data, ulCompareFunc comparefn ) ;
void removeNode ( void *data ) ;
void * removeNode ( int pos ) ;
void * getNodeData ( int pos ) const ;
void * forEach ( ulIterateFunc fn, void *user_data = NULL ) const ;
void empty ( ulIterateFunc destroyfn = NULL, void *user_data = NULL ) ;
} ;
extern char *ulStrDup ( const char *s ) ;
extern int ulStrNEqual ( const char *s1, const char *s2, int len );
extern int ulStrEqual ( const char *s1, const char *s2 );
//lint -restore
#endif
|