1 /* 2 Copyright (C) 1996-1997 Id Software, Inc. 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 */ 20 // comndef.h -- general definitions 21 22 #if !defined BYTE_DEFINED 23 typedef unsigned char byte; 24 #define BYTE_DEFINED 1 25 #endif 26 27 // #undef true 28 // #undef false 29 // typedef enum _qboolean {false, true} qboolean; 30 31 // NOTE: qboolean must not be typedefed as a C++ bool because it is 32 // used to store values other than 0 or 1 in the global array "used". See 33 // the implementation of FanLength() 34 35 typedef unsigned int qboolean; 36 37 //============================================================================ 38 39 typedef struct sizebuf_s 40 { 41 qboolean allowoverflow; // if false, do a Sys_Error 42 qboolean overflowed; // set to true if the buffer size failed 43 byte *data; 44 int maxsize; 45 int cursize; 46 } sizebuf_t; 47 48 void SZ_Alloc (sizebuf_t *buf, int startsize); 49 void SZ_Free (sizebuf_t *buf); 50 void SZ_Clear (sizebuf_t *buf); 51 void *SZ_GetSpace (sizebuf_t *buf, int length); 52 void SZ_Write (sizebuf_t *buf, const void *data, int length); 53 void SZ_Print (sizebuf_t *buf, const char *data); // strcats onto the sizebuf 54 55 //============================================================================ 56 57 typedef struct link_s 58 { 59 struct link_s *prev, *next; 60 } link_t; 61 62 63 void ClearLink (link_t *l); 64 void RemoveLink (link_t *l); 65 void InsertLinkBefore (link_t *l, link_t *before); 66 void InsertLinkAfter (link_t *l, link_t *after); 67 68 // (type *)STRUCT_FROM_LINK(link_t *link, type, member) 69 // ent = STRUCT_FROM_LINK(link,entity_t,order) 70 // FIXME: remove this mess! 71 #define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m))) 72 73 //============================================================================ 74 75 #ifndef NULL 76 #define NULL ((void *)0) 77 #endif 78 79 #define Q_MAXCHAR ((char)0x7f) 80 #define Q_MAXSHORT ((short)0x7fff) 81 #define Q_MAXINT ((int)0x7fffffff) 82 #define Q_MAXLONG ((int)0x7fffffff) 83 #define Q_MAXFLOAT ((int)0x7fffffff) 84 85 #define Q_MINCHAR ((char)0x80) 86 #define Q_MINSHORT ((short)0x8000) 87 #define Q_MININT ((int)0x80000000) 88 #define Q_MINLONG ((int)0x80000000) 89 #define Q_MINFLOAT ((int)0x7fffffff) 90 91 //============================================================================ 92 93 extern qboolean bigendien; 94 95 extern short (*BigShort) (short l); 96 extern short (*LittleShort) (short l); 97 extern int (*BigLong) (int l); 98 extern int (*LittleLong) (int l); 99 extern float (*BigFloat) (float l); 100 extern float (*LittleFloat) (float l); 101 102 //============================================================================ 103 104 void MSG_WriteChar (sizebuf_t *sb, int c); 105 void MSG_WriteByte (sizebuf_t *sb, int c); 106 void MSG_WriteShort (sizebuf_t *sb, int c); 107 void MSG_WriteLong (sizebuf_t *sb, int c); 108 void MSG_WriteFloat (sizebuf_t *sb, float f); 109 void MSG_WriteString (sizebuf_t *sb, const char *s); 110 void MSG_WriteCoord (sizebuf_t *sb, float f); 111 void MSG_WriteAngle (sizebuf_t *sb, float f); 112 113 extern int msg_readcount; 114 extern qboolean msg_badread; // set if a read goes beyond end of message 115 116 void MSG_BeginReading (void); 117 int MSG_ReadChar (void); 118 int MSG_ReadByte (void); 119 int MSG_ReadShort (void); 120 int MSG_ReadLong (void); 121 float MSG_ReadFloat (void); 122 char *MSG_ReadString (void); 123 124 float MSG_ReadCoord (void); 125 float MSG_ReadAngle (void); 126 127 //============================================================================ 128 129 void Q_memset (void *dest, int fill, int count); 130 void Q_memcpy (void *dest, const void *src, int count); 131 int Q_memcmp (const void *m1, const void *m2, int count); 132 void Q_strcpy (char *dest, const char *src); 133 void Q_strncpy (char *dest, const char *src, int count); 134 int Q_strlen (const char *str); 135 char *Q_strrchr (const char *s, char c); 136 void Q_strcat (char *dest, const char *src); 137 int Q_strcmp (const char *s1, const char *s2); 138 int Q_strncmp (const char *s1, const char *s2, int count); 139 int Q_strcasecmp (const char *s1, const char *s2); 140 int Q_strncasecmp (const char *s1, const char *s2, int n); 141 int Q_atoi (const char *str); 142 float Q_atof (const char *str); 143 144 //============================================================================ 145 146 extern char com_token[1024]; 147 extern qboolean com_eof; 148 149 char *COM_Parse (char *data); 150 151 152 extern int com_argc; 153 extern const char **com_argv; 154 155 int COM_CheckParm (const char *parm); 156 void COM_Init (const char *path); 157 void COM_InitArgv (int argc, const char **argv); 158 159 const char *COM_SkipPath (const char *pathname); 160 void COM_StripExtension (const char *in, char *out); 161 void COM_FileBase (const char *in, char *out, size_t outLength); 162 void COM_DefaultExtension (char *path, const char *extension); 163 164 char *va(const char *format, ...); 165 // does a varargs printf into a temp buffer 166 167 168 //============================================================================ 169 170 extern int com_filesize; 171 struct cache_user_s; 172 173 extern char com_gamedir[MAX_OSPATH]; 174 175 void COM_WriteFile (const char *filename, void *data, int len); 176 int COM_OpenFile (const char *filename, int *hndl); 177 int COM_FOpenFile (const char *filename, FILE **file); 178 void COM_CloseFile (int h); 179 180 byte *COM_LoadStackFile (const char *path, void *buffer, int bufsize); 181 byte *COM_LoadTempFile (const char *path); 182 byte *COM_LoadHunkFile (const char *path); 183 void COM_LoadCacheFile (const char *path, struct cache_user_s *cu); 184 185 186 extern struct cvar_s registered; 187 188 extern qboolean standard_quake, rogue, hipnotic; 189