Debian Codegraph @

code/game/bg_lib.h

raw
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 // bg_lib.h -- standard C library replacement routines used by code
23 // compiled for the virtual machine
24
25 // This file is NOT included on native builds
26 #if !defined( BG_LIB_H ) && defined( Q3_VM )
27 #define BG_LIB_H
28
29 //Ignore __attribute__ on non-gcc platforms
30 #ifndef __GNUC__
31 #ifndef __attribute__
32 #define __attribute__(x)
33 #endif
34 #endif
35
36 #ifndef NULL
37 #define NULL ((void *)0)
38 #endif
39
40 typedef int size_t;
41
42 typedef char * va_list;
43 #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
44 #define va_start(ap,v) ( ap = (va_list)&v + _INTSIZEOF(v) )
45 #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
46 #define va_end(ap) ( ap = (va_list)0 )
47
48 #define CHAR_BIT 8 /* number of bits in a char */
49 #define SCHAR_MAX 0x7f /* maximum signed char value */
50 #define SCHAR_MIN (-SCHAR_MAX - 1) /* minimum signed char value */
51 #define UCHAR_MAX 0xff /* maximum unsigned char value */
52
53 #define SHRT_MAX 0x7fff /* maximum (signed) short value */
54 #define SHRT_MIN (-SHRT_MAX - 1) /* minimum (signed) short value */
55 #define USHRT_MAX 0xffff /* maximum unsigned short value */
56 #define INT_MAX 0x7fffffff /* maximum (signed) int value */
57 #define INT_MIN (-INT_MAX - 1) /* minimum (signed) int value */
58 #define UINT_MAX 0xffffffff /* maximum unsigned int value */
59 #define LONG_MAX 0x7fffffffL /* maximum (signed) long value */
60 #define LONG_MIN (-LONG_MAX - 1) /* minimum (signed) long value */
61 #define ULONG_MAX 0xffffffffUL /* maximum unsigned long value */
62
63 #define isalnum(c) (isalpha(c) || isdigit(c))
64 #define isalpha(c) (isupper(c) || islower(c))
65 #define isascii(c) ((c) > 0 && (c) <= 0x7f)
66 #define iscntrl(c) (((c) >= 0) && (((c) <= 0x1f) || ((c) == 0x7f)))
67 #define isdigit(c) ((c) >= '0' && (c) <= '9')
68 #define isgraph(c) ((c) != ' ' && isprint(c))
69 #define islower(c) ((c) >= 'a' && (c) <= 'z')
70 #define isprint(c) ((c) >= ' ' && (c) <= '~')
71 #define ispunct(c) (((c) > ' ' && (c) <= '~') && !isalnum(c))
72 #define isspace(c) ((c) == ' ' || (c) == '\f' || (c) == '\n' || (c) == '\r' || \
73 (c) == '\t' || (c) == '\v')
74 #define isupper(c) ((c) >= 'A' && (c) <= 'Z')
75 #define isxdigit(c) (isxupper(c) || isxlower(c))
76 #define isxlower(c) (isdigit(c) || (c >= 'a' && c <= 'f'))
77 #define isxupper(c) (isdigit(c) || (c >= 'A' && c <= 'F'))
78
79 // Misc functions
80 typedef int cmp_t(const void *, const void *);
81 void qsort(void *a, size_t n, size_t es, cmp_t *cmp);
82 void srand( unsigned seed );
83 int rand( void );
84
85 // String functions
86 size_t strlen( const char *string );
87 char *strcat( char *strDestination, const char *strSource );
88 char *strcpy( char *strDestination, const char *strSource );
89 int strcmp( const char *string1, const char *string2 );
90 char *strchr( const char *string, int c );
91 char *strrchr(const char *string, int c);
92 char *strstr( const char *string, const char *strCharSet );
93 char *strncpy( char *strDest, const char *strSource, size_t count );
94 int tolower( int c );
95 int toupper( int c );
96
97 double atof( const char *string );
98 double _atof( const char **stringPtr );
99 double strtod( const char *nptr, const char **endptr );
100 int atoi( const char *string );
101 int _atoi( const char **stringPtr );
102 long strtol( const char *nptr, const char **endptr, int base );
103
104 int Q_vsnprintf( char *buffer, size_t length, const char *fmt, va_list argptr );
105 int Q_snprintf( char *buffer, size_t length, const char *fmt, ... ) __attribute__ ((format (printf, 3, 4)));
106
107 int sscanf( const char *buffer, const char *fmt, ... ) __attribute__ ((format (scanf, 2, 3)));
108
109 // Memory functions
110 void *memmove( void *dest, const void *src, size_t count );
111 void *memset( void *dest, int c, size_t count );
112 void *memcpy( void *dest, const void *src, size_t count );
113
114 // Math functions
115 double ceil( double x );
116 double floor( double x );
117 double sqrt( double x );
118 double sin( double x );
119 double cos( double x );
120 double atan2( double y, double x );
121 double tan( double x );
122 int abs( int n );
123 double fabs( double x );
124 double acos( double x );
125
126 #endif // BG_LIB_H