common.h 5.3 KB

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