#include "cmdlib.h"
#include <sys/types.h>
#include <sys/stat.h>
Include dependency graph for cmdlib.c:

Go to the source code of this file.
Defines | |
| #define | BASEDIRNAME "quake" |
| #define | CRC_INIT_VALUE 0xffff |
| #define | CRC_XOR_VALUE 0x0000 |
| #define | MAX_EX_ARGC 1024 |
| #define | PATHSEPERATOR '/' |
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 | ParseHex (const char *hex) |
| 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,...) |
| FILE * | SafeOpenRead (const char *filename) |
| FILE * | SafeOpenWrite (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 *start) |
| char * | strupr (char *start) |
| int | TryLoadFile (const char *filename, void **bufferptr) |
Variables | |
| qboolean | archive |
| char | archivedir [1024] |
| qboolean | com_eof |
| char | com_token [1024] |
| unsigned short | crctable [256] |
| int | ex_argc |
| char * | ex_argv [MAX_EX_ARGC] |
| char | gamedir [1024] |
| int | myargc |
| char ** | myargv |
| char | qdir [1024] |
| qboolean | verbose = qfalse |
| char | writedir [1024] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||
Here is the call graph for this function:

|
|
Definition at line 1060 of file cmdlib.c. 01061 {
01062 union {byte b[4]; float f;} in, out;
01063
01064 in.f = l;
01065 out.b[0] = in.b[3];
01066 out.b[1] = in.b[2];
01067 out.b[2] = in.b[1];
01068 out.b[3] = in.b[0];
01069
01070 return out.f;
01071 }
|
|
|
Definition at line 1043 of file cmdlib.c. 01044 {
01045 byte b1,b2,b3,b4;
01046
01047 b1 = l&255;
01048 b2 = (l>>8)&255;
01049 b3 = (l>>16)&255;
01050 b4 = (l>>24)&255;
01051
01052 return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
01053 }
|
|
|
Definition at line 1027 of file cmdlib.c. 01028 {
01029 byte b1,b2;
01030
01031 b1 = l&255;
01032 b2 = (l>>8)&255;
01033
01034 return (b1<<8) + b2;
01035 }
|
|
|
Definition at line 606 of file cmdlib.c. References check(), i, myargv, and Q_stricmp(). 00607 {
00608 int i;
00609
00610 for (i = 1;i<myargc;i++)
00611 {
00612 if ( !Q_stricmp(check, myargv[i]) )
00613 return i;
00614 }
00615
00616 return 0;
00617 }
|
Here is the call graph for this function:

|
|
Definition at line 458 of file cmdlib.c. References c, com_eof, com_token, and data. 00459 {
00460 int c;
00461 int len;
00462
00463 len = 0;
00464 com_token[0] = 0;
00465
00466 if (!data)
00467 return NULL;
00468
00469 // skip whitespace
00470 skipwhite:
00471 while ( (c = *data) <= ' ')
00472 {
00473 if (c == 0)
00474 {
00475 com_eof = qtrue;
00476 return NULL; // end of file;
00477 }
00478 data++;
00479 }
00480
00481 // skip // comments
00482 if (c=='/' && data[1] == '/')
00483 {
00484 while (*data && *data != '\n')
00485 data++;
00486 goto skipwhite;
00487 }
00488
00489
00490 // handle quoted strings specially
00491 if (c == '\"')
00492 {
00493 data++;
00494 do
00495 {
00496 c = *data++;
00497 if (c=='\"')
00498 {
00499 com_token[len] = 0;
00500 return data;
00501 }
00502 com_token[len] = c;
00503 len++;
00504 } while (1);
00505 }
00506
00507 // parse single characters
00508 if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
00509 {
00510 com_token[len] = c;
00511 len++;
00512 com_token[len] = 0;
00513 return data+1;
00514 }
00515
00516 // parse a regular word
00517 do
00518 {
00519 com_token[len] = c;
00520 data++;
00521 len++;
00522 c = *data;
00523 if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
00524 break;
00525 } while (c>32);
00526
00527 com_token[len] = 0;
00528 return data;
00529 }
|
|
|
Definition at line 358 of file cmdlib.c. References b, malloc(), s, strcpy(), and strlen().
|
Here is the call graph for this function:

|
|
Definition at line 1130 of file cmdlib.c. Referenced by CRC_ProcessString(). 01131 {
01132 *crcvalue = CRC_INIT_VALUE;
01133 }
|
|
||||||||||||
|
Definition at line 1135 of file cmdlib.c. References byte. 01136 {
01137 *crcvalue = (*crcvalue << 8) ^ crctable[(*crcvalue >> 8) ^ data];
01138 }
|
|
|
Definition at line 1140 of file cmdlib.c. Referenced by CRC_ProcessString(). 01141 {
01142 return crcvalue ^ CRC_XOR_VALUE;
01143 }
|
|
|
Definition at line 1151 of file cmdlib.c. References c, memcpy(), Q_mkdir(), and toupper(). Referenced by AASOuputFile(), and QCopyFile(). 01152 {
01153 const char *ofs;
01154 char c;
01155 char dir[1024];
01156
01157 #ifdef _WIN32
01158 int olddrive = -1;
01159
01160 if ( path[1] == ':' )
01161 {
01162 olddrive = _getdrive();
01163 _chdrive( toupper( path[0] ) - 'A' + 1 );
01164 }
01165 #endif
01166
01167 if (path[1] == ':')
01168 path += 2;
01169
01170 for (ofs = path+1 ; *ofs ; ofs++)
01171 {
01172 c = *ofs;
01173 if (c == '/' || c == '\\')
01174 { // create the directory
01175 memcpy( dir, path, ofs - path );
01176 dir[ ofs - path ] = 0;
01177 Q_mkdir( dir );
01178 }
01179 }
01180
01181 #ifdef _WIN32
01182 if ( olddrive != -1 )
01183 {
01184 _chdrive( olddrive );
01185 }
01186 #endif
01187 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 794 of file cmdlib.c. References src, strcat(), and strlen(). Referenced by Bspinfo(), LightMain(), LoadShaderImage(), main(), ParseShaderFile(), SaveAsDialog(), VLightMain(), and VSoundMain(). 00795 {
00796 char *src;
00797 //
00798 // if path doesnt have a .EXT, append extension
00799 // (extension should include the .)
00800 //
00801 src = path + strlen(path) - 1;
00802
00803 while (*src != '/' && *src != '\\' && src != path)
00804 {
00805 if (*src == '.')
00806 return; // it has an extension
00807 src--;
00808 }
00809
00810 strcat (path, extension);
00811 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 814 of file cmdlib.c. References basepath(), strcat(), and strcpy(). 00815 {
00816 char temp[128];
00817
00818 if (path[0] == PATHSEPERATOR)
00819 return; // absolute path location
00820 strcpy (temp,path);
00821 strcpy (path,basepath);
00822 strcat (path,temp);
00823 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 147 of file cmdlib.c. References _printf(), error(), exit(), va_end, va_list, va_start, and vprintf(). 00148 {
00149 va_list argptr;
00150
00151 _printf ("\n************ ERROR ************\n");
00152
00153 va_start (argptr,error);
00154 vprintf (error,argptr);
00155 va_end (argptr);
00156 _printf ("\r\n");
00157
00158 exit (1);
00159 }
|
Here is the call graph for this function:

|
|
Definition at line 302 of file cmdlib.c. References Q_getwd(), strcat(), and strcpy(). Referenced by LightMain(), VisMain(), VLightMain(), and VSoundMain(). 00303 {
00304 static char full[1024];
00305
00306 if (path[0] != '/' && path[0] != '\\' && path[1] != ':')
00307 {
00308 Q_getwd (full);
00309 strcat (full, path);
00310 }
00311 else
00312 strcpy (full, path);
00313 return full;
00314 }
|
Here is the call graph for this function:

|
|
Definition at line 329 of file cmdlib.c. References Error(), gamedir, sprintf(), and strcpy(). Referenced by LoadAlphaMap(). 00330 {
00331 static char full[1024];
00332 if (!qdir)
00333 Error ("ExpandGamePath called without qdir set");
00334 if (path[0] == '/' || path[0] == '\\' || path[1] == ':') {
00335 strcpy( full, path );
00336 return full;
00337 }
00338 sprintf (full, "%s%s", gamedir, path);
00339 return full;
00340 }
|
Here is the call graph for this function:

|
|
Definition at line 316 of file cmdlib.c. References Error(), qdir, sprintf(), and strcpy(). Referenced by ExpandPathAndArchive(). 00317 {
00318 static char full[1024];
00319 if (!qdir)
00320 Error ("ExpandPath called without qdir set");
00321 if (path[0] == '/' || path[0] == '\\' || path[1] == ':') {
00322 strcpy( full, path );
00323 return full;
00324 }
00325 sprintf (full, "%s%s", qdir, path);
00326 return full;
00327 }
|
Here is the call graph for this function:

|
|
Definition at line 342 of file cmdlib.c. References archivedir, ExpandPath(), QCopyFile(), and sprintf(). 00343 {
00344 char *expanded;
00345 char archivename[1024];
00346
00347 expanded = ExpandPath (path);
00348
00349 if (archive)
00350 {
00351 sprintf (archivename, "%s/%s", archivedir, path);
00352 QCopyFile (expanded, archivename);
00353 }
00354 return expanded;
00355 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 106 of file cmdlib.c. 00107 {
00108 }
|
|
||||||||||||
|
Definition at line 875 of file cmdlib.c. Referenced by AASOuputFile(), and main(). 00876 {
00877 const char *src;
00878
00879 src = path + strlen(path) - 1;
00880
00881 //
00882 // back up until a \ or the start
00883 //
00884 while (src != path && *(src-1) != PATHSEPERATOR)
00885 src--;
00886
00887 while (*src && *src != '.')
00888 {
00889 *dest++ = *src++;
00890 }
00891 *dest = 0;
00892 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 894 of file cmdlib.c. References src, strcpy(), and strlen(). Referenced by AASOuputFile(), Load256Image(), Load32BitImage(), LoadAlphaMap(), QuakeFileType(), and Save256Image(). 00895 {
00896 const char *src;
00897
00898 src = path + strlen(path) - 1;
00899
00900 //
00901 // back up until a . or the start
00902 //
00903 while (src != path && *(src-1) != '.')
00904 src--;
00905 if (src == path)
00906 {
00907 *dest = 0; // no extension
00908 return;
00909 }
00910
00911 strcpy (dest,src);
00912 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 859 of file cmdlib.c. References memcpy(), src, and strlen(). 00860 {
00861 const char *src;
00862
00863 src = path + strlen(path) - 1;
00864
00865 //
00866 // back up until a \ or the start
00867 //
00868 while (src != path && *(src-1) != '\\' && *(src-1) != '/')
00869 src--;
00870
00871 memcpy (dest, path, src-path);
00872 dest[src-path] = 0;
00873 }
|
Here is the call graph for this function:

|
|
Definition at line 684 of file cmdlib.c. References f, fclose(), fopen(), and qboolean. Referenced by LoadImageFile(). 00685 {
00686 FILE *f;
00687
00688 f = fopen (filename, "r");
00689 if (!f)
00690 return qfalse;
00691 fclose (f);
00692 return qtrue;
00693 }
|
Here is the call graph for this function:

|
|
Definition at line 439 of file cmdlib.c. 00440 {
00441 struct stat buf;
00442
00443 if (stat (path,&buf) == -1)
00444 return -1;
00445
00446 return buf.st_mtime;
00447 }
|
|
|
Definition at line 373 of file cmdlib.c. References t, time(), and time_t. 00374 {
00375 time_t t;
00376
00377 time (&t);
00378
00379 return t;
00380 #if 0
00381 // more precise, less portable
00382 struct timeval tp;
00383 struct timezone tzp;
00384 static int secbase;
00385
00386 gettimeofday(&tp, &tzp);
00387
00388 if (!secbase)
00389 {
00390 secbase = tp.tv_sec;
00391 return tp.tv_usec/1000000.0;
00392 }
00393
00394 return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0;
00395 #endif
00396 }
|
Here is the call graph for this function:

|
|
Definition at line 1073 of file cmdlib.c. 01074 {
01075 return l;
01076 }
|
|
|
Definition at line 1055 of file cmdlib.c. 01056 {
01057 return l;
01058 }
|
|
|
Definition at line 1037 of file cmdlib.c. 01038 {
01039 return l;
01040 }
|
|
||||||||||||
|
Definition at line 700 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(). 00701 {
00702 FILE *f;
00703 int length;
00704 void *buffer;
00705
00706 f = SafeOpenRead (filename);
00707 length = Q_filelength (f);
00708 buffer = malloc (length+1);
00709 ((char *)buffer)[length] = 0;
00710 SafeRead (f, buffer, length);
00711 fclose (f);
00712
00713 *bufferptr = buffer;
00714 return length;
00715 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 726 of file cmdlib.c. References buffer, f, fclose(), length(), malloc(), MEM_BLOCKSIZE, memset(), Q_filelength(), SafeOpenRead(), and SafeRead(). Referenced by LoadImageFile(). 00727 {
00728 FILE *f;
00729 int length, nBlock, nAllocSize;
00730 void *buffer;
00731
00732 f = SafeOpenRead (filename);
00733 length = Q_filelength (f);
00734 nAllocSize = length;
00735 nBlock = nAllocSize % MEM_BLOCKSIZE;
00736 if ( nBlock > 0) {
00737 nAllocSize += MEM_BLOCKSIZE - nBlock;
00738 }
00739 buffer = malloc (nAllocSize+1);
00740 memset(buffer, 0, nAllocSize+1);
00741 SafeRead (f, buffer, length);
00742 fclose (f);
00743
00744 *bufferptr = buffer;
00745 return length;
00746 }
|
Here is the call graph for this function:

|
|
Definition at line 920 of file cmdlib.c. References Error(). 00921 {
00922 const char *str;
00923 int num;
00924
00925 num = 0;
00926 str = hex;
00927
00928 while (*str)
00929 {
00930 num <<= 4;
00931 if (*str >= '0' && *str <= '9')
00932 num += *str-'0';
00933 else if (*str >= 'a' && *str <= 'f')
00934 num += 10 + *str-'a';
00935 else if (*str >= 'A' && *str <= 'F')
00936 num += 10 + *str-'A';
00937 else
00938 Error ("Bad hex number: %s",hex);
00939 str++;
00940 }
00941
00942 return num;
00943 }
|
Here is the call graph for this function:

|
|
Definition at line 946 of file cmdlib.c. References atol(), and ParseHex(). 00947 {
00948 if (str[0] == '$')
00949 return ParseHex (str+1);
00950 if (str[0] == '0' && str[1] == 'x')
00951 return ParseHex (str+2);
00952 return atol (str);
00953 }
|
Here is the call graph for this function:

|
|
Definition at line 626 of file cmdlib.c. References f, fseek(), ftell(), SEEK_END, and SEEK_SET. Referenced by ASE_Load(), Bspinfo(), LoadFile(), LoadFileBlock(), LoadFileNoCrash(), LoadQuakeFile(), and TryLoadFile(). 00627 {
00628 int pos;
00629 int end;
00630
00631 pos = ftell (f);
00632 fseek (f, 0, SEEK_END);
00633 end = ftell (f);
00634 fseek (f, pos, SEEK_SET);
00635
00636 return end;
00637 }
|
Here is the call graph for this function:

|
|
Definition at line 398 of file cmdlib.c. Referenced by ExpandArg(), and SetQdirFromPath(). 00399 {
00400 int i = 0;
00401
00402 #ifdef WIN32
00403 _getcwd (out, 256);
00404 strcat (out, "\\");
00405 #else
00406 getcwd (out, 256);
00407 strcat (out, "/");
00408 #endif
00409
00410 while ( out[i] != 0 )
00411 {
00412 if ( out[i] == '\\' )
00413 out[i] = '/';
00414 i++;
00415 }
00416 }
|
Here is the call graph for this function:

|
|
Definition at line 419 of file cmdlib.c. References errno, Error(), and strerror(). Referenced by CreatePath(). 00420 {
00421 #ifdef WIN32
00422 if (_mkdir (path) != -1)
00423 return;
00424 #else
00425 if (mkdir (path |