Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

cmdlib.h File Reference

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <time.h>
#include <stdarg.h>

Include dependency graph for cmdlib.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  cblock_t

Defines

#define MAX_OS_PATH   1024
#define MEM_BLOCKSIZE   4096
#define myoffsetof(type, identifier)   ((size_t)&((type *)0)->identifier)

Typedefs

typedef unsigned char byte

Enumerations

enum  qboolean { qfalse, qtrue }

Functions

void _printf (const char *format,...)
float BigFloat (float l)
int BigLong (int l)
short BigShort (short l)
int CheckParm (const char *check)
char * COM_Parse (char *data)
char * copystring (const char *s)
void CRC_Init (unsigned short *crcvalue)
void CRC_ProcessByte (unsigned short *crcvalue, byte data)
unsigned short CRC_Value (unsigned short crcvalue)
void CreatePath (const char *path)
void DefaultExtension (char *path, const char *extension)
void DefaultPath (char *path, const char *basepath)
void Error (const char *error,...)
char * ExpandArg (const char *path)
char * ExpandGamePath (const char *path)
char * ExpandPath (const char *path)
char * ExpandPathAndArchive (const char *path)
void ExpandWildcards (int *argc, char ***argv)
void ExtractFileBase (const char *path, char *dest)
void ExtractFileExtension (const char *path, char *dest)
void ExtractFilePath (const char *path, char *dest)
qboolean FileExists (const char *filename)
int FileTime (const char *path)
double I_FloatTime (void)
float LittleFloat (float l)
int LittleLong (int l)
short LittleShort (short l)
int LoadFile (const char *filename, void **bufferptr)
int LoadFileBlock (const char *filename, void **bufferptr)
int ParseNum (const char *str)
int Q_filelength (FILE *f)
void Q_getwd (char *out)
void Q_mkdir (const char *path)
int Q_stricmp (const char *s1, const char *s2)
int Q_strncasecmp (const char *s1, const char *s2, int n)
void QCopyFile (const char *from, const char *to)
void qprintf (const char *format,...)
FILESafeOpenRead (const char *filename)
FILESafeOpenWrite (const char *filename)
void SafeRead (FILE *f, void *buffer, int count)
void SafeWrite (FILE *f, const void *buffer, int count)
void SaveFile (const char *filename, const void *buffer, int count)
void SetQdirFromPath (const char *path)
void StripExtension (char *path)
void StripFilename (char *path)
char * strlower (char *in)
char * strupr (char *in)
int TryLoadFile (const char *filename, void **bufferptr)

Variables

qboolean archive
char archivedir [1024]
qboolean com_eof
char com_token [1024]
char gamedir [1024]
int myargc
char ** myargv
char qdir [1024]
qboolean verbose
char writedir [1024]


Define Documentation

#define MAX_OS_PATH   1024
 

Definition at line 59 of file cmdlib.h.

#define MEM_BLOCKSIZE   4096
 

Definition at line 60 of file cmdlib.h.

#define myoffsetof type,
identifier   )     ((size_t)&((type *)0)->identifier)
 

Definition at line 63 of file cmdlib.h.


Typedef Documentation

typedef unsigned char byte
 

Definition at line 56 of file cmdlib.h.


Enumeration Type Documentation

enum qboolean
 

Enumeration values:
qfalse 
qtrue 

Definition at line 55 of file cmdlib.h.

00055 { qfalse, qtrue } qboolean;


Function Documentation

void _printf const char *  format,
  ...
 

Definition at line 178 of file cmdlib.c.

References a, format, LPARAM, NULL, printf(), va_end, va_list, va_start, and vsprintf().

Referenced by AddTriangleModels(), Bspinfo(), CalcPassagePortalVis(), CalcPassageVis(), CalcPHS(), CalcPortalVis(), CalcVis(), CheckAreas_r(), CountActivePortals(), CreateEntityLights(), CreateFilters(), CreateNewFloatPlane(), CreatePassages(), CreateSurfaceLights(), EndBSPFile(), Error(), FinishBrush(), FloodAreas_r(), FogDrawSurfs(), GetThreadWork(), GridAndVertexLighting(), LightMain(), LoadMapFile(), LoadPortals(), LoadShaderImage(), main(), MakeTreePortals_r(), MergeLeafPortals(), MergeLeaves(), ParseShaderFile(), PassageFlow(), PassageMemory(), PassagePortalFlow(), PointToPolygonFormFactor(), PortalFlow(), PrintBrush(), PrintCtrl(), PrintMesh(), PrintOccluded(), PrintPortal(), PrintTree_r(), prl(), ProcessWorldModel(), R_LoadMD3(), RemoveDuplicateBrushPlanes(), RemoveLightsInSolid(), RunThreadsOn(), SetBrushContents(), SplitMeshByPlane(), VisMain(), VL_CalcVisibleLightmapPixelArea(), VL_ChopWinding(), VL_ChopWindingWithBrush(), VL_CreateEntityLights(), VL_CreateFakeSurfaceLights(), VL_CreateSkyLights(), VL_DoForcedTraceLightSurfaces(), VL_InitSurfacesForTesting(), VL_LightmapMatrixFromPoints(), VL_LightSurfaceWithVolume(), VL_LightWorld(), VL_LoadPortals(), VL_Radiosity(), VL_SplitLightVolume(), VL_SplitWinding(), VL_StoreLightmap(), VLightMain(), VS_CalcVisibleLightmapPixelArea(), VS_ChopWinding(), VS_ChopWindingWithBrush(), VS_CreateEntitySpeakers(), VS_CreateFakeSurfaceLights(), VS_CreateSkyLights(), VS_DoForcedTraceLightSurfaces(), VS_InitSurfacesForTesting(), VS_LightmapMatrixFromPoints(), VS_LightSurfaceWithVolume(), VS_LightWorld(), VS_LoadPortals(), VS_Radiosity(), VS_SplitLightVolume(), VS_SplitWinding(), VS_StoreLightmap(), VSoundMain(), WriteBspBrushMap(), WriteGLView(), and WritePortalFile().

00178                                         {
00179     va_list argptr;
00180   char text[4096];
00181   ATOM a;
00182 
00183     va_start (argptr,format);
00184     vsprintf (text, format, argptr);
00185     va_end (argptr);
00186 
00187   printf(text);
00188 
00189 #ifdef WIN32
00190   if (!lookedForServer) {
00191     lookedForServer = qtrue;
00192     hwndOut = FindWindow(NULL, "Q3Map Process Server");
00193     if (hwndOut) {
00194       wm_BroadcastCommand = RegisterWindowMessage( "Q3MPS_BroadcastCommand" );
00195     }
00196   }
00197   if (hwndOut) {
00198     a = GlobalAddAtom(text);
00199     PostMessage(hwndOut, wm_BroadcastCommand, 0, (LPARAM)a);
00200   }
00201 #endif
00202 }

Here is the call graph for this function:

float BigFloat float  l  ) 
 

Definition at line 1052 of file l_cmd.c.

01053 {
01054     union {byte b[4]; float f;} in, out;
01055     
01056     in.f = l;
01057     out.b[0] = in.b[3];
01058     out.b[1] = in.b[2];
01059     out.b[2] = in.b[1];
01060     out.b[3] = in.b[0];
01061     
01062     return out.f;
01063 }

int BigLong int  l  ) 
 

Definition at line 1035 of file l_cmd.c.

01036 {
01037     byte    b1,b2,b3,b4;
01038 
01039     b1 = l&255;
01040     b2 = (l>>8)&255;
01041     b3 = (l>>16)&255;
01042     b4 = (l>>24)&255;
01043 
01044     return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
01045 }

short BigShort short  l  ) 
 

Definition at line 1019 of file l_cmd.c.

01020 {
01021     byte    b1,b2;
01022 
01023     b1 = l&255;
01024     b2 = (l>>8)&255;
01025 
01026     return (b1<<8) + b2;
01027 }

int CheckParm const char *  check  ) 
 

Definition at line 601 of file cmdlib.c.

References check(), i, myargv, and Q_stricmp().

00602 {
00603     int             i;
00604 
00605     for (i = 1;i<myargc;i++)
00606     {
00607         if ( !Q_stricmp(check, myargv[i]) )
00608             return i;
00609     }
00610 
00611     return 0;
00612 }

Here is the call graph for this function:

char* COM_Parse char *  data  ) 
 

Definition at line 438 of file l_cmd.c.

00439 {
00440     int     c;
00441     int     len;
00442     
00443     len = 0;
00444     com_token[0] = 0;
00445     
00446     if (!data)
00447         return NULL;
00448         
00449 // skip whitespace
00450 skipwhite:
00451     while ( (c = *data) <= ' ')
00452     {
00453         if (c == 0)
00454         {
00455             com_eof = true;
00456             return NULL;            // end of file;
00457         }
00458         data++;
00459     }
00460     
00461 // skip // comments
00462     if (c=='/' && data[1] == '/')
00463     {
00464         while (*data && *data != '\n')
00465             data++;
00466         goto skipwhite;
00467     }
00468     
00469 
00470 // handle quoted strings specially
00471     if (c == '\"')
00472     {
00473         data++;
00474         do
00475         {
00476             c = *data++;
00477             if (c=='\"')
00478             {
00479                 com_token[len] = 0;
00480                 return data;
00481             }
00482             com_token[len] = c;
00483             len++;
00484         } while (1);
00485     }
00486 
00487 // parse single characters
00488     if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
00489     {
00490         com_token[len] = c;
00491         len++;
00492         com_token[len] = 0;
00493         return data+1;
00494     }
00495 
00496 // parse a regular word
00497     do
00498     {
00499         com_token[len] = c;
00500         data++;
00501         len++;
00502         c = *data;
00503     if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
00504             break;
00505     } while (c>32);
00506     
00507     com_token[len] = 0;
00508     return data;
00509 }

char* copystring const char *  s  ) 
 

Definition at line 353 of file cmdlib.c.

References b, malloc(), s, strcpy(), and strlen().

00354 {
00355     char    *b;
00356     b = malloc(strlen(s)+1);
00357     strcpy (b, s);
00358     return b;
00359 }

Here is the call graph for this function:

void CRC_Init unsigned short *  crcvalue  ) 
 

Definition at line 92 of file l_crc.c.

Referenced by CRC_ProcessString().

00093 {
00094     *crcvalue = CRC_INIT_VALUE;
00095 } //end of the function CRC_Init

void CRC_ProcessByte unsigned short *  crcvalue,
byte  data
 

Definition at line 102 of file l_crc.c.

References byte.

00103 {
00104     *crcvalue = (*crcvalue << 8) ^ crctable[(*crcvalue >> 8) ^ data];
00105 } //end of the function CRC_ProcessByte

unsigned short CRC_Value unsigned short  crcvalue  ) 
 

Definition at line 112 of file l_crc.c.

Referenced by CRC_ProcessString().

00113 {
00114     return crcvalue ^ CRC_XOR_VALUE;
00115 } //end of the function CRC_Value

void CreatePath const char *  path  ) 
 

Definition at line 1146 of file cmdlib.c.

References c, memcpy(), Q_mkdir(), and toupper().

Referenced by AASOuputFile(), and QCopyFile().

01147 {
01148     const char  *ofs;
01149     char        c;
01150     char        dir[1024];
01151 
01152 #ifdef _WIN32
01153     int     olddrive = -1;
01154 
01155     if ( path[1] == ':' )
01156     {
01157         olddrive = _getdrive();
01158         _chdrive( toupper( path[0] ) - 'A' + 1 );
01159     }
01160 #endif
01161 
01162     if (path[1] == ':')
01163         path += 2;
01164 
01165     for (ofs = path+1 ; *ofs ; ofs++)
01166     {
01167         c = *ofs;
01168         if (c == '/' || c == '\\')
01169         {   // create the directory
01170             memcpy( dir, path, ofs - path );
01171             dir[ ofs - path ] = 0;
01172             Q_mkdir( dir );
01173         }
01174     }
01175 
01176 #ifdef _WIN32
01177     if ( olddrive != -1 )
01178     {
01179         _chdrive( olddrive );
01180     }
01181 #endif
01182 }

Here is the call graph for this function:

void DefaultExtension char *  path,
const char *  extension
 

Definition at line 789 of file cmdlib.c.

References src, strcat(), and strlen().

Referenced by Bspinfo(), LightMain(), LoadShaderImage(), main(), ParseShaderFile(), SaveAsDialog(), VLightMain(), and VSoundMain().

00790 {
00791     char    *src;
00792 //
00793 // if path doesnt have a .EXT, append extension
00794 // (extension should include the .)
00795 //
00796     src = path + strlen(path) - 1;
00797 
00798     while (*src != '/' && *src != '\\' && src != path)
00799     {
00800         if (*src == '.')
00801             return;                 // it has an extension
00802         src--;
00803     }
00804 
00805     strcat (path, extension);
00806 }

Here is the call graph for this function:

void DefaultPath char *  path,
const char *  basepath
 

Definition at line 809 of file cmdlib.c.

References basepath(), strcat(), and strcpy().

00810 {
00811     char    temp[128];
00812 
00813     if (path[0] == PATHSEPERATOR)
00814         return;                   // absolute path location
00815     strcpy (temp,path);
00816     strcpy (path,basepath);
00817     strcat (path,temp);
00818 }

Here is the call graph for this function:

void Error const char *  error,
  ...
 

Definition at line 143 of file cmdlib.c.

References _printf(), error(), exit(), va_end, va_list, va_start, and vprintf().

00144 {
00145     va_list argptr;
00146 
00147     _printf ("\n************ ERROR ************\n");
00148 
00149     va_start (argptr,error);
00150     vprintf (error,argptr);
00151     va_end (argptr);
00152     _printf ("\r\n");
00153 
00154     exit (1);
00155 }

Here is the call graph for this function:

char* ExpandArg const char *  path  ) 
 

Definition at line 297 of file cmdlib.c.

References Q_getwd(), strcat(), and strcpy().

Referenced by LightMain(), VisMain(), VLightMain(), and VSoundMain().

00298 {
00299     static char full[1024];
00300 
00301     if (path[0] != '/' && path[0] != '\\' && path[1] != ':')
00302     {
00303         Q_getwd (full);
00304         strcat (full, path);
00305     }
00306     else
00307         strcpy (full, path);
00308     return full;
00309 }

Here is the call graph for this function:

char* ExpandGamePath const char *  path  ) 
 

Definition at line 324 of file cmdlib.c.

References Error(), gamedir, sprintf(), and strcpy().

Referenced by LoadAlphaMap().

00325 {
00326     static char full[1024];
00327     if (!qdir)
00328         Error ("ExpandGamePath called without qdir set");
00329     if (path[0] == '/' || path[0] == '\\' || path[1] == ':') {
00330         strcpy( full, path );
00331         return full;
00332     }
00333     sprintf (full, "%s%s", gamedir, path);
00334     return full;
00335 }

Here is the call graph for this function:

char* ExpandPath const char *  path  ) 
 

Definition at line 311 of file cmdlib.c.

References Error(), qdir, sprintf(), and strcpy().

Referenced by ExpandPathAndArchive().

00312 {
00313     static char full[1024];
00314     if (!qdir)
00315         Error ("ExpandPath called without qdir set");
00316     if (path[0] == '/' || path[0] == '\\' || path[1] == ':') {
00317         strcpy( full, path );
00318         return full;
00319     }
00320     sprintf (full, "%s%s", qdir, path);
00321     return full;
00322 }

Here is the call graph for this function:

char* ExpandPathAndArchive const char *  path  ) 
 

Definition at line 337 of file cmdlib.c.

References archivedir, ExpandPath(), QCopyFile(), and sprintf().

00338 {
00339     char    *expanded;
00340     char    archivename[1024];
00341 
00342     expanded = ExpandPath (path);
00343 
00344     if (archive)
00345     {
00346         sprintf (archivename, "%s/%s", archivedir, path);
00347         QCopyFile (expanded, archivename);
00348     }
00349     return expanded;
00350 }

Here is the call graph for this function:

void ExpandWildcards int *  argc,
char ***  argv
 

Definition at line 110 of file l_cmd.c.

00111 {
00112 }

void ExtractFileBase const char *  path,
char *  dest
 

Definition at line 870 of file cmdlib.c.

References src, and strlen().

Referenced by AASOuputFile(), and main().

00871 {
00872     const char    *src;
00873 
00874     src = path + strlen(path) - 1;
00875 
00876 //
00877 // back up until a \ or the start
00878 //
00879     while (src != path && *(src-1) != PATHSEPERATOR)
00880         src--;
00881 
00882     while (*src && *src != '.')
00883     {
00884         *dest++ = *src++;
00885     }
00886     *dest = 0;
00887 }

Here is the call graph for this function:

void ExtractFileExtension const char *  path,
char *  dest
 

Definition at line 889 of file cmdlib.c.

References src, strcpy(), and strlen().

Referenced by AASOuputFile(), Load256Image(), Load32BitImage(), LoadAlphaMap(), QuakeFileType(), and Save256Image().

00890 {
00891     const char    *src;
00892 
00893     src = path + strlen(path) - 1;
00894 
00895 //
00896 // back up until a . or the start
00897 //
00898     while (src != path && *(src-1) != '.')
00899         src--;
00900     if (src == path)
00901     {
00902         *dest = 0;  // no extension
00903         return;
00904     }
00905 
00906     strcpy (dest,src);
00907 }

Here is the call graph for this function:

void ExtractFilePath const char *  path,
char *  dest
 

Definition at line 854 of file cmdlib.c.

References memcpy(), src, and strlen().

00855 {
00856     const char    *src;
00857 
00858     src = path + strlen(path) - 1;
00859 
00860 //
00861 // back up until a \ or the start
00862 //
00863     while (src != path && *(src-1) != '\\' && *(src-1) != '/')
00864         src--;
00865 
00866     memcpy (dest, path, src-path);
00867     dest[src-path] = 0;
00868 }

Here is the call graph for this function:

qboolean FileExists const char *  filename  ) 
 

Definition at line 679 of file cmdlib.c.

References f, fclose(), fopen(), and qboolean.

Referenced by LoadImageFile().

00680 {
00681     FILE    *f;
00682 
00683     f = fopen (filename, "r");
00684     if (!f)
00685         return qfalse;
00686     fclose (f);
00687     return qtrue;
00688 }

Here is the call graph for this function:

int FileTime const char *  path  ) 
 

Definition at line 434 of file cmdlib.c.

00435 {
00436     struct  stat    buf;
00437     
00438     if (stat (path,&buf) == -1)
00439         return -1;
00440     
00441     return buf.st_mtime;
00442 }

double I_FloatTime void   ) 
 

Definition at line 362 of file l_cmd.c.

00363 {
00364     time_t  t;
00365     
00366     time (&t);
00367     
00368     return t;
00369 #if 0
00370 // more precise, less portable
00371     struct timeval tp;
00372     struct timezone tzp;
00373     static int      secbase;
00374 
00375     gettimeofday(&tp, &tzp);
00376     
00377     if (!secbase)
00378     {
00379         secbase = tp.tv_sec;
00380         return tp.tv_usec/1000000.0;
00381     }
00382     
00383     return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0;
00384 #endif
00385 }

float LittleFloat float  l  ) 
 

Definition at line 1065 of file l_cmd.c.

01066 {
01067     return l;
01068 }

int LittleLong int  l  ) 
 

Definition at line 1047 of file l_cmd.c.

01048 {
01049     return l;
01050 }

short LittleShort short  l  ) 
 

Definition at line 1029 of file l_cmd.c.

01030 {
01031     return l;
01032 }

int LoadFile const char *  filename,
void **  bufferptr
 

Definition at line 695 of file cmdlib.c.

References buffer, f, fclose(), length(), malloc(), Q_filelength(), SafeOpenRead(), and SafeRead().

Referenced by AddScriptToStack(), CheckBspProcess(), Eclass_ScanFile(), EndBSPFile(), FS_ReadFile(), FS_ReadFileAndCache(), HL_LoadBSPFile(), LoadBMP(), LoadBSPFile(), LoadJPG(), LoadLBM(), LoadModel(), LoadPCX(), LoadShader(), LoadShaders(), LoadTGA(), Map_ImportFile(), Map_LoadFile(), Q1_LoadBSPFile(), Q2_LoadBSPFile(), QCopyFile(), QERApp_LoadFile(), Sin_LoadBSPFile(), Texture_ForName(), Texture_ForNamePath(), and ViewShader().

00696 {
00697     FILE    *f;
00698     int    length;
00699     void    *buffer;
00700 
00701     f = SafeOpenRead (filename);
00702     length = Q_filelength (f);
00703     buffer = malloc (length+1);
00704     ((char *)buffer)[length] = 0;
00705     SafeRead (f, buffer, length);
00706     fclose (f);
00707 
00708     *bufferptr = buffer;
00709     return length;
00710 }

Here is the call graph for this function:

int LoadFileBlock const char *  filename,
void **  bufferptr
 

Definition at line 721 of file cmdlib.c.

References buffer, f, fclose(), length(), malloc(), MEM_BLOCKSIZE, memset(), Q_filelength(), SafeOpenRead(), and SafeRead().

Referenced by LoadImageFile().

00722 {
00723     FILE    *f;
00724     int    length, nBlock, nAllocSize;
00725     void    *buffer;
00726 
00727     f = SafeOpenRead (filename);
00728     length = Q_filelength (f);
00729   nAllocSize = length;
00730   nBlock = nAllocSize % MEM_BLOCKSIZE;
00731   if ( nBlock > 0) {
00732     nAllocSize += MEM_BLOCKSIZE - nBlock;
00733   }
00734     buffer = malloc (nAllocSize+1);
00735   memset(buffer, 0, nAllocSize+1);
00736     SafeRead (f, buffer, length);
00737     fclose (f);
00738 
00739     *bufferptr = buffer;
00740     return length;
00741 }

Here is the call graph for this function:

int ParseNum const char *  str  ) 
 

Definition at line 941 of file cmdlib.c.

References atol(), and ParseHex().

00942 {
00943     if (str[0] == '$')
00944         return ParseHex (str+1);
00945     if (str[0] == '0' && str[1] == 'x')
00946         return ParseHex (str+2);
00947     return atol (str);
00948 }

Here is the call graph for this function:

int Q_filelength FILE f  ) 
 

Definition at line 615 of file l_cmd.c.

References f, fseek(), ftell(), SEEK_END, and SEEK_SET.

Referenced by ASE_Load(), Bspinfo(), LoadFile(), LoadFileBlock(), LoadFileNoCrash(), LoadQuakeFile(), and TryLoadFile().

00616 {
00617     int     pos;
00618     int     end;
00619 
00620     pos = ftell (f);
00621     fseek (f, 0, SEEK_END);
00622     end = ftell (f);
00623     fseek (f, pos, SEEK_SET);
00624 
00625     return end;
00626 }

Here is the call graph for this function:

void Q_getwd char *  out  ) 
 

Definition at line 387 of file l_cmd.c.

References i, and strcat().

Referenced by ExpandArg(), and SetQdirFromPath().

00388 {
00389 #if defined(WIN32) || defined(_WIN32)
00390    getcwd (out, 256);
00391    strcat (out, "\\");
00392 #else
00393    getwd(out);
00394    strcat(out, "/");
00395 #endif
00396 }

Here is the call graph for this function:

void Q_mkdir const char *  path  ) 
 

Definition at line 414 of file cmdlib.c.

References errno, Error(), and strerror().

Referenced by CreatePath().

00415 {
00416 #ifdef WIN32
00417     if (_mkdir (path) != -1)
00418         return;
00419 #else
00420     if (mkdir (path, 0777) != -1)
00421         return;
00422 #endif
00423     if (errno != EEXIST)
00424         Error ("mkdir %s: %s",path, strerror(errno));
00425 }

Here is the call graph for this function:

int Q_stricmp const char *  s1,
const char *  s2
 

Definition at line 785 of file q_shared.c.

00785                                                {
00786     return