#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:

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

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,...) |
| 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 *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] |
|
|
Definition at line 59 of file cmdlib.h. Referenced by LoadShaderInfo(). |
|
|
Definition at line 60 of file cmdlib.h. Referenced by __qblockmalloc(), LoadFileBlock(), and qblockmalloc(). |
|
|
|
|
|
|
|
|
Definition at line 55 of file cmdlib.h. 00055 { qfalse, qtrue } qboolean;
|
|
||||||||||||
|
Definition at line 178 of file cmdlib.c. 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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
Definition at line 601 of file cmdlib.c. 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 }
|
|
|
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 }
|
|
|
Definition at line 353 of file cmdlib.c.
|
|
|
Definition at line 92 of file l_crc.c. 00093 {
00094 *crcvalue = CRC_INIT_VALUE;
00095 } //end of the function CRC_Init
|
|
||||||||||||
|
Definition at line 102 of file l_crc.c. 00103 {
00104 *crcvalue = (*crcvalue << 8) ^ crctable[(*crcvalue >> 8) ^ data];
00105 } //end of the function CRC_ProcessByte
|
|
|
Definition at line 112 of file l_crc.c. 00113 {
00114 return crcvalue ^ CRC_XOR_VALUE;
00115 } //end of the function CRC_Value
|
|
|
Definition at line 1146 of file cmdlib.c. 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 }
|
|
||||||||||||
|
Definition at line 789 of file cmdlib.c. 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 }
|
|
||||||||||||
|
Definition at line 809 of file cmdlib.c. 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 }
|
|
||||||||||||
|
Definition at line 143 of file cmdlib.c. 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 }
|
|
|
Definition at line 297 of file cmdlib.c. 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 }
|
|
|
Definition at line 324 of file cmdlib.c. 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 }
|
|
|
Definition at line 311 of file cmdlib.c. 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 }
|
|
|
Definition at line 337 of file cmdlib.c. 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 }
|
|
||||||||||||
|
Definition at line 110 of file l_cmd.c. 00111 {
00112 }
|
|
||||||||||||
|
Definition at line 870 of file cmdlib.c. 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 }
|
|
||||||||||||
|
Definition at line 889 of file cmdlib.c. 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 }
|
|
||||||||||||
|
Definition at line 854 of file cmdlib.c. 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 }
|
|
|
Definition at line 679 of file cmdlib.c. 00680 {
00681 FILE *f;
00682
00683 f = fopen (filename, "r");
00684 if (!f)
00685 return qfalse;
00686 fclose (f);
00687 return qtrue;
00688 }
|
|
|
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 }
|
|
|
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 }
|
|
|
Definition at line 1065 of file l_cmd.c. 01066 {
01067 return l;
01068 }
|
|
|
Definition at line 1047 of file l_cmd.c. 01048 {
01049 return l;
01050 }
|
|
|
Definition at line 1029 of file l_cmd.c. 01030 {
01031 return l;
01032 }
|
|
||||||||||||
|
Definition at line 695 of file cmdlib.c. 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 }
|
|
||||||||||||
|
Definition at line 721 of file cmdlib.c. 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 }
|
|
|
Definition at line 941 of file cmdlib.c. 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 }
|
|
|
Definition at line 615 of file l_cmd.c. 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 }
|
|
|
Definition at line 387 of file l_cmd.c. 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 }
|
|
|
Definition at line 414 of file cmdlib.c. 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 }
|
|
||||||||||||
|
Definition at line 785 of file q_shared.c. 00785 {
00786 return (s1 && s2) ? Q_stricmpn (s1, s2, 99999) : -1;
00787 }
|
|
||||||||||||||||
|
Definition at line 527 of file cmdlib.c. 00528 {
00529 int c1, c2;
00530
00531 do
00532 {
00533 c1 = *s1++;
00534 c2 = *s2++;
00535
00536 if (!n--)
00537 return 0; // strings are equal until end point
00538
00539 if (c1 != c2)
00540 {
00541 if (c1 >= 'a' && c1 <= 'z')
00542 c1 -= ('a' - 'A');
00543 if (c2 >= 'a' && c2 <= 'z')
00544 c2 -= ('a' - 'A');
00545 if (c1 != c2)
00546 return -1; // strings not equal
00547 }
00548 } while (c1);
00549
00550 return 0; // strings are equal
00551 }
|
|
||||||||||||
|
Definition at line 1192 of file cmdlib.c. 01193 {
01194 void *buffer;
01195 int length;
01196
01197 length = LoadFile (from, &buffer);
01198 CreatePath (to);
01199 SaveFile (to, buffer, length);
01200 free (buffer);
01201 }
|
|
||||||||||||
|
Definition at line 160 of file cmdlib.c. 00160 {
00161 va_list argptr;
00162
00163 if (!verbose)
00164 return;
00165
00166 va_start (argptr,format);
00167 vprintf (format,argptr);
00168 va_end (argptr);
00169
00170 }
|
|
|
Definition at line 647 of file cmdlib.c. 00648 {
00649 FILE *f;
00650
00651 f = fopen(filename, "rb");
00652
00653 if (!f)
00654 Error ("Error opening %s: %s",filename,strerror(errno));
00655
00656 return f;
00657 }
|
|
|
Definition at line 635 of file cmdlib.c. 00636 {
00637 FILE *f;
00638
00639 f = fopen(filename, "wb");
00640
00641 if (!f)
00642 Error ("Error opening %s: %s",filename,strerror(errno));
00643
00644 return f;
00645 }
|
|
||||||||||||||||
|
Definition at line 654 of file l_cmd.c. 00655 {
00656 if ( fread (buffer, 1, count, f) != (size_t)count)
00657 Error ("File read failure");
00658 }
|
|
||||||||||||||||
|
Definition at line 667 of file cmdlib.c. 00668 {
00669 if (fwrite (buffer, 1, count, f) != (size_t)count)
00670 Error ("File write failure");
00671 }
|
|
||||||||||||||||
|
Definition at line 778 of file cmdlib.c. 00779 {
00780 FILE *f;
00781
00782 f = SafeOpenWrite (filename);
00783 SafeWrite (f, buffer, count);
00784 fclose (f);
00785 }
|
|
|
Definition at line 220 of file cmdlib.c. 00221 {
00222 char temp[1024];
00223 const char *c;
00224 const char *sep;
00225 int len, count;
00226
00227 if (!(path[0] == '/' || path[0] == '\\' || path[1] == ':'))
00228 { // path is partial
00229 Q_getwd (temp);
00230 strcat (temp, path);
00231 path = temp;
00232 }
00233
00234 // search for "quake2" in path
00235
00236 len = strlen(BASEDIRNAME);
00237 for (c=path+strlen(path)-1 ; c != path ; c--)
00238 {
00239 int i;
00240
00241 if (!Q_strncasecmp (c, BASEDIRNAME, len))
00242 {
00243 //
00244 //strncpy (qdir, path, c+len+2-path);
00245 // the +2 assumes a 2 or 3 following quake which is not the
00246 // case with a retail install
00247 // so we need to add up how much to the next separator
00248 sep = c + len;
00249 count = 1;
00250 while (*sep && *sep != '/' && *sep != '\\')
00251 {
00252 sep++;
00253 count++;
00254 }
00255 strncpy (qdir, path, c+len+count-path);
00256 qprintf ("qdir: %s\n", qdir);
00257 for ( i = 0; i < strlen( qdir ); i++ )
00258 {
00259 if ( qdir[i] == '\\' )
00260 qdir[i] = '/';
00261 }
00262
00263 c += len+count;
00264 while (*c)
00265 {
00266 if (*c == '/' || *c == '\\')
00267 {
00268 strncpy (gamedir, path, c+1-path);
00269
00270 for ( i = 0; i < strlen( gamedir ); i++ )
00271 {
00272 if ( gamedir[i] == '\\' )
00273 gamedir[i] = '/';
00274 }
00275
00276 qprintf ("gamedir: %s\n", gamedir);
00277
00278 if ( !writedir[0] )
00279 strcpy( writedir, gamedir );
00280 else if ( writedir[strlen( writedir )-1] != '/' )
00281 {
00282 writedir[strlen( writedir )] = '/';
00283 writedir[strlen( writedir )+1] = 0;
00284 }
00285
00286 return;
00287 }
00288 c++;
00289 }
00290 Error ("No gamedir in %s", path);
00291 return;
00292 }
00293 }
00294 Error ("SetQdirFromPath: no '%s' in %s", BASEDIRNAME, path);
00295 }
|
|
|
Definition at line 794 of file l_cmd.c. 00795 {
00796 int length;
00797
00798 length = strlen(path)-1;
00799 while (length > 0 && path[length] != '.')
00800 {
00801 length--;
00802 if (path[length] == '/')
00803 return; // no extension
00804 }
00805 if (length)
00806 path[length] = 0;
00807 }
|
|
|
Definition at line 784 of file l_cmd.c. 00785 {
00786 int length;
00787
00788 length = strlen(path)-1;
00789 while (length > 0 && path[length] != PATHSEPERATOR)
00790 length--;
00791 path[length] = 0;
00792 }
|
|
|
Definition at line 565 of file l_cmd.c. 00566 {
00567 char *in;
00568 in = start;
00569 while (*in)
00570 {
00571 *in = tolower(*in);
00572 in++;
00573 }
00574 return start;
00575 }
|
|
|
Definition at line 553 of file l_cmd.c. 00554 {
00555 char *in;
00556 in = start;
00557 while (*in)
00558 {
00559 *in = toupper(*in);
00560 in++;
00561 }
00562 return start;
00563 }
|
|
||||||||||||
|
Definition at line 751 of file cmdlib.c. 00752 {
00753 FILE *f;
00754 int length;
00755 void *buffer;
00756
00757 *bufferptr = NULL;
00758
00759 f = fopen (filename, "rb");
00760 if (!f)
00761 return -1;
00762 length = Q_filelength (f);
00763 buffer = malloc (length+1);
00764 ((char *)buffer)[length] = 0;
00765 SafeRead (f, buffer, length);
00766 fclose (f);
00767
00768 *bufferptr = buffer;
00769 return length;
00770 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.3.9.1