#include "l_cmd.h"
#include "l_log.h"
#include "l_mem.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
Include dependency graph for l_cmd.c:

Go to the source code of this file.
Defines | |
| #define | BASEDIRNAME "quake2" |
| #define | CRC_INIT_VALUE 0xffff |
| #define | CRC_XOR_VALUE 0x0000 |
| #define | MAX_EX_ARGC 1024 |
| #define | PATHSEPERATOR '/' |
Functions | |
| float | BigFloat (float l) |
| int | BigLong (int l) |
| short | BigShort (short l) |
| unsigned | BigUnsigned (unsigned l) |
| unsigned short | BigUnsignedShort (unsigned short l) |
| int | CheckParm (char *check) |
| void | Com_Error (int level, char *error,...) |
| char * | COM_Parse (char *data) |
| void | Com_Printf (const char *fmt,...) |
| char * | copystring (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 (char *path) |
| void | DefaultExtension (char *path, char *extension) |
| void | DefaultPath (char *path, char *basepath) |
| void | Error (char *error,...) |
| char * | ExpandArg (char *path) |
| char * | ExpandPath (char *path) |
| char * | ExpandPathAndArchive (char *path) |
| void | ExpandWildcards (int *argc, char ***argv) |
| void | ExtractFileBase (char *path, char *dest) |
| void | ExtractFileExtension (char *path, char *dest) |
| void | ExtractFilePath (char *path, char *dest) |
| qboolean | FileExists (char *filename) |
| int | FileTime (char *path) |
| int | FS_FOpenFileRead (const char *filename, FILE **file, qboolean uniqueFILE) |
| void | FS_FreeFile (void *buf) |
| int | FS_ReadFileAndCache (const char *qpath, void **buffer) |
| double | I_FloatTime (void) |
| float | LittleFloat (float l) |
| int | LittleLong (int l) |
| short | LittleShort (short l) |
| unsigned | LittleUnsigned (unsigned l) |
| unsigned short | LittleUnsignedShort (unsigned short l) |
| int | LoadFile (char *filename, void **bufferptr, int offset, int length) |
| int | ParseHex (char *hex) |
| int | ParseNum (char *str) |
| int | Q_filelength (FILE *f) |
| void | Q_getwd (char *out) |
| void | Q_mkdir (char *path) |
| int | Q_strcasecmp (char *s1, char *s2) |
| int | Q_stricmp (char *s1, char *s2) |
| int | Q_strncasecmp (char *s1, char *s2, int n) |
| void | Q_strncpyz (char *dest, const char *src, int destsize) |
| void | QCopyFile (char *from, char *to) |
| void | qprintf (char *format,...) |
| FILE * | SafeOpenRead (char *filename) |
| FILE * | SafeOpenWrite (char *filename) |
| void | SafeRead (FILE *f, void *buffer, int count) |
| void | SafeWrite (FILE *f, void *buffer, int count) |
| void | SaveFile (char *filename, void *buffer, int count) |
| void | SetQdirFromPath (char *path) |
| void | StripExtension (char *path) |
| void | StripFilename (char *path) |
| char * | strlower (char *start) |
| char * | strupr (char *start) |
| int | TryLoadFile (char *filename, void **bufferptr) |
| void | Warning (char *warning,...) |
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 = true |
|
|
Definition at line 45 of file l_cmd.c. Referenced by SetQdirFromPath(). |
|
|
|
|
|
|
|
|
|
|
|
Definition at line 46 of file l_cmd.c. Referenced by DefaultExtension(). |
|
|
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. Referenced by CL_Connect_f(), CL_RequestAuthorization(), CL_RequestMotd(), NET_AdrToString(), SV_Ban_f(), SV_BanNum_f(), and SV_GetChallenge(). 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 1087 of file l_cmd.c. 01088 {
01089 byte b1,b2,b3,b4;
01090
01091 b1 = l&255;
01092 b2 = (l>>8)&255;
01093 b3 = (l>>16)&255;
01094 b4 = (l>>24)&255;
01095
01096 return ((unsigned)b1<<24) + ((unsigned)b2<<16) + ((unsigned)b3<<8) + b4;
01097 }
|
|
|
Definition at line 1071 of file l_cmd.c. 01072 {
01073 byte b1,b2;
01074
01075 b1 = l&255;
01076 b2 = (l>>8)&255;
01077
01078 return (b1<<8) + b2;
01079 }
|
|
|
Definition at line 595 of file l_cmd.c. 00596 {
00597 int i;
00598
00599 for (i = 1;i<myargc;i++)
00600 {
00601 if ( !Q_strcasecmp(check, myargv[i]) )
00602 return i;
00603 }
00604
00605 return 0;
00606 }
|
|
||||||||||||||||
|
Definition at line 232 of file l_cmd.c. References Error(), error(), va_end, va_list, va_start, and vsprintf(). 00233 {
00234 va_list argptr;
00235 char text[1024];
00236
00237 va_start(argptr, error);
00238 vsprintf(text, error, argptr);
00239 va_end(argptr);
00240 Error(text);
00241 } //end of the funcion Com_Error
|
Here is the call graph for this function:

|
|
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 243 of file l_cmd.c. 00244 {
00245 va_list argptr;
00246 char text[1024];
00247
00248 va_start(argptr, fmt);
00249 vsprintf(text, fmt, argptr);
00250 va_end(argptr);
00251 Log_Print(text);
00252 } //end of the funcion Com_Printf
|
|
|
Definition at line 347 of file l_cmd.c. 00348 {
00349 char *b;
00350 b = GetMemory(strlen(s)+1);
00351 strcpy (b, s);
00352 return b;
00353 }
|
|
|
Definition at line 1157 of file l_cmd.c. 01158 {
01159 *crcvalue = CRC_INIT_VALUE;
01160 }
|
|
||||||||||||
|
Definition at line 1162 of file l_cmd.c. References byte. 01163 {
01164 *crcvalue = (*crcvalue << 8) ^ crctable[(*crcvalue >> 8) ^ data];
01165 }
|
|
|
Definition at line 1167 of file l_cmd.c. 01168 {
01169 return crcvalue ^ CRC_XOR_VALUE;
01170 }
|
|
|
Definition at line 1178 of file l_cmd.c. 01179 {
01180 char *ofs, c;
01181
01182 if (path[1] == ':')
01183 path += 2;
01184
01185 for (ofs = path+1 ; *ofs ; ofs++)
01186 {
01187 c = *ofs;
01188 if (c == '/' || c == '\\')
01189 { // create the directory
01190 *ofs = 0;
01191 Q_mkdir (path);
01192 *ofs = c;
01193 }
01194 }
01195 }
|
|
||||||||||||
|
Definition at line 752 of file l_cmd.c. 00753 {
00754 char *src;
00755 //
00756 // if path doesnt have a .EXT, append extension
00757 // (extension should include the .)
00758 //
00759 src = path + strlen(path) - 1;
00760
00761 while (*src != PATHSEPERATOR && src != path)
00762 {
00763 if (*src == '.')
00764 return; // it has an extension
00765 src--;
00766 }
00767
00768 strcat (path, extension);
00769 }
|
|
||||||||||||
|
Definition at line 772 of file l_cmd.c. 00773 {
00774 char temp[128];
00775
00776 if (path[0] == PATHSEPERATOR)
00777 return; // absolute path location
00778 strcpy (temp,path);
00779 strcpy (path,basepath);
00780 strcat (path,temp);
00781 }
|
|
||||||||||||
|
Definition at line 178 of file l_cmd.c. 00179 {
00180 va_list argptr;
00181 char text[1024];
00182
00183 va_start(argptr, error);
00184 vsprintf(text, error, argptr);
00185 va_end(argptr);
00186 printf("ERROR: %s\n", text);
00187
00188 Log_Write(text);
00189 Log_Close();
00190
00191 exit (1);
00192 } //end of the function Error
|
|
|
Definition at line 306 of file l_cmd.c. Referenced by main(). 00307 {
00308 static char full[1024];
00309
00310 if (path[0] != '/' && path[0] != '\\' && path[1] != ':')
00311 {
00312 Q_getwd (full);
00313 strcat (full, path);
00314 }
00315 else
00316 strcpy (full, path);
00317 return full;
00318 }
|
|
|
Definition at line 320 of file l_cmd.c. Referenced by AddScriptToStack(). 00321 {
00322 static char full[1024];
00323 if (!qdir)
00324 Error ("ExpandPath called without qdir set");
00325 if (path[0] == '/' || path[0] == '\\' || path[1] == ':')
00326 return path;
00327 sprintf (full, "%s%s", qdir, path);
00328 return full;
00329 }
|
|
|
Definition at line 331 of file l_cmd.c. 00332 {
00333 char *expanded;
00334 char archivename[1024];
00335
00336 expanded = ExpandPath (path);
00337
00338 if (archive)
00339 {
00340 sprintf (archivename, "%s/%s", archivedir, path);
00341 QCopyFile (expanded, archivename);
00342 }
00343 return expanded;
00344 }
|
|
||||||||||||
|
Definition at line 110 of file l_cmd.c. 00111 {
00112 }
|
|
||||||||||||
|
Definition at line 833 of file l_cmd.c. 00834 {
00835 char *src;
00836
00837 src = path + strlen(path) - 1;
00838
00839 //
00840 // back up until a \ or the start
00841 //
00842 while (src != path && *(src-1) != '\\' && *(src-1) != '/')
00843 src--;
00844
00845 while (*src && *src != '.')
00846 {
00847 *dest++ = *src++;
00848 }
00849 *dest = 0;
00850 }
|
|
||||||||||||
|
Definition at line 852 of file l_cmd.c. 00853 {
00854 char *src;
00855
00856 src = path + strlen(path) - 1;
00857
00858 //
00859 // back up until a . or the start
00860 //
00861 while (src != path && *(src-1) != '.')
00862 src--;
00863 if (src == path)
00864 {
00865 *dest = 0; // no extension
00866 return;
00867 }
00868
00869 strcpy (dest,src);
00870 }
|
|
||||||||||||
|
Definition at line 817 of file l_cmd.c. 00818 {
00819 char *src;
00820
00821 src = path + strlen(path) - 1;
00822
00823 //
00824 // back up until a \ or the start
00825 //
00826 while (src != path && *(src-1) != '\\' && *(src-1) != '/')
00827 src--;
00828
00829 memcpy (dest, path, src-path);
00830 dest[src-path] = 0;
00831 }
|
|
|
Definition at line 673 of file l_cmd.c. 00674 {
00675 FILE *f;
00676
00677 f = fopen (filename, "r");
00678 if (!f)
00679 return false;
00680 fclose (f);
00681 return true;
00682 }
|
|
|
Definition at line 419 of file l_cmd.c. 00420 {
00421 struct stat buf;
00422
00423 if (stat (path,&buf) == -1)
00424 return -1;
00425
00426 return buf.st_mtime;
00427 }
|
|
||||||||||||||||
|
Definition at line 1226 of file l_cmd.c. 01227 {
01228 *file = fopen(filename, "rb");
01229 return (*file != NULL);
01230 } //end of the function FS_FOpenFileRead
|
Here is the call graph for this function:

|
|
Definition at line 1216 of file l_cmd.c. 01217 {
01218 FreeMemory(buf);
01219 } //end of the function FS_FreeFile
|
|
||||||||||||
|
Definition at line 1221 of file l_cmd.c. References buffer, and LoadFile(). 01222 {
01223 return LoadFile((char *) qpath, buffer, 0, 0);
01224 } //end of the function FS_ReadFileAndCache
|
Here is the call graph for this function:

|
|
Definition at line 362 of file l_cmd.c. Referenced by AAS_Create(), LightMain(), main(), RunThreadsOn(), VisMain(), and WriteMapFile(). 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. Referenced by R_LoadMD3(). 01048 {
01049 return l;
01050 }
|
|
|
Definition at line 1029 of file l_cmd.c. 01030 {
01031 return l;
01032 }
|
|
|
Definition at line 1099 of file l_cmd.c. Referenced by Sin_SwapBSPFile(). 01100 {
01101 return l;
01102 }
|
|
|
Definition at line 1081 of file l_cmd.c. Referenced by Sin_SwapBSPFile(). 01082 {
01083 return l;
01084 }
|
|
||||||||||||||||||||
|
Definition at line 689 of file l_cmd.c. 00690 {
00691 FILE *f;
00692 void *buffer;
00693
00694 f = SafeOpenRead(filename);
00695 fseek(f, offset, SEEK_SET);
00696 if (!length) length = Q_filelength(f);
00697 buffer = GetMemory(length+1);
00698 ((char *)buffer)[length] = 0;
00699 SafeRead(f, buffer, length);
00700 fclose(f);
00701
00702 *bufferptr = buffer;
00703 return length;
00704 }
|
|
|
Definition at line 878 of file l_cmd.c. References Error(). 00879 {
00880 char *str;
00881 int num;
00882
00883 num = 0;
00884 str = hex;
00885
00886 while (*str)
00887 {
00888 num <<= 4;
00889 if (*str >= '0' && *str <= '9')
00890 num += *str-'0';
00891 else if (*str >= 'a' && *str <= 'f')
00892 num += 10 + *str-'a';
00893 else if (*str >= 'A' && *str <= 'F')
00894 num += 10 + *str-'A';
00895 else
00896 Error ("Bad hex number: %s",hex);
00897 str++;
00898 }
00899
00900 return num;
00901 }
|
Here is the call graph for this function:

|
|
Definition at line 904 of file l_cmd.c. 00905 {
00906 if (str[0] == '$')
00907 return ParseHex (str+1);
00908 if (str[0] == '0' && str[1] == 'x')
00909 return ParseHex (str+2);
00910 return atol (str);
00911 }
|
|
|
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 399 of file l_cmd.c. 00400 {
00401 #ifdef WIN32
00402 if (_mkdir (path) != -1)
00403 return;
00404 #else
00405 if (mkdir (path, 0777) != -1)
00406 return;
00407 #endif
00408 if (errno != EEXIST)
00409 Error ("mkdir %s: %s",path, strerror(errno));
00410 }
|
|
||||||||||||
|
Definition at line 538 of file l_cmd.c. References Q_strncasecmp(). Referenced by CheckParm(), and Q1_TextureContents(). 00539 {
00540 return Q_strncasecmp (s1, s2, 99999);
00541 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 543 of file l_cmd.c. References Q_strncasecmp(). 00544 {
00545 return Q_strncasecmp (s1, s2, 99999);
00546 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 512 of file l_cmd.c. 00513 {
00514 int c1, c2;
00515
00516 do
00517 {
00518 c1 = *s1++;
00519 c2 = *s2++;
00520
00521 if (!n--)
00522 return 0; // strings are equal until end point
00523
00524 if (c1 != c2)
00525 {
00526 if (c1 >= 'a' && c1 <= 'z')
00527 c1 -= ('a' - 'A');
00528 if (c2 >= 'a' && c2 <= 'z')
00529 c2 -= ('a' - 'A');
00530 if (c1 != c2)
00531 return -1; // strings not equal
00532 }
00533 } while (c1);
00534
00535 return 0; // strings are equal
00536 }
|
|
||||||||||||||||
|
Definition at line 548 of file l_cmd.c. 00548 {
00549 strncpy( dest, src, destsize-1 );
00550 dest[destsize-1] = 0;
00551 }
|
|
||||||||||||
|
Definition at line 1205 of file l_cmd.c. 01206 {
01207 void *buffer;
01208 int length;
01209
01210 length = LoadFile (from, &buffer, 0, 0);
01211 CreatePath (to);
01212 SaveFile (to, buffer, length);
01213 FreeMemory(buffer);
01214 }
|
|
||||||||||||
|
Definition at line 212 of file l_cmd.c. 00213 {
00214 va_list argptr;
00215 #ifdef WINBSPC
00216 char buf[2048];
00217 #endif //WINBSPC
00218
00219 if (!verbose)
00220 return;
00221
00222 va_start(argptr,format);
00223 #ifdef WINBSPC
00224 vsprintf(buf, format, argptr);
00225 WinBSPCPrint(buf);
00226 #else
00227 vprintf(format, argptr);
00228 #endif //WINBSPC
00229 va_end(argptr);
00230 } //end of the function qprintf
|
|
|
Definition at line 641 of file l_cmd.c. 00642 {
00643 FILE *f;
00644
00645 f = fopen(filename, "rb");
00646
00647 if (!f)
00648 Error ("Error opening %s: %s",filename,strerror(errno));
00649
00650 return f;
00651 }
|
|
|
Definition at line 629 of file l_cmd.c. 00630 {
00631 FILE *f;
00632
00633 f = fopen(filename, "wb");
00634
00635 if (!f)
00636 Error ("Error opening %s: %s",filename,strerror(errno));
00637
00638 return f;
00639 }
|
|
||||||||||||||||
|
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 661 of file l_cmd.c. 00662 {
00663 if (fwrite (buffer, 1, count, f) != (size_t)count)
00664 Error ("File write failure");
00665 }
|
|
||||||||||||||||
|
Definition at line 741 of file l_cmd.c. 00742 {
00743 FILE *f;
00744
00745 f = SafeOpenWrite (filename);
00746 SafeWrite (f, buffer, count);
00747 fclose (f);
00748 }
|
|
|
Definition at line 268 of file l_cmd.c. 00269 {
00270 char temp[1024];
00271 char *c;
00272 int len;
00273
00274 if (!(path[0] == '/' || path[0] == '\\' || path[1] == ':'))
00275 { // path is partial
00276 Q_getwd (temp);
00277 strcat (temp, path);
00278 path = temp;
00279 }
00280
00281 // search for "quake2" in path
00282
00283 len = strlen(BASEDIRNAME);
00284 for (c=path+strlen(path)-1 ; c != path ; c--)
00285 if (!Q_strncasecmp (c, BASEDIRNAME, len))
00286 {
00287 strncpy (qdir, path, c+len+1-path);
00288 qprintf ("qdir: %s\n", qdir);
00289 c += len+1;
00290 while (*c)
00291 {
00292 if (*c == '/' || *c == '\\')
00293 {
00294 strncpy (gamedir, path, c+1-path);
00295 qprintf ("gamedir: %s\n", gamedir);
00296 return;
00297 }
00298 c++;
00299 }
00300 Error ("No gamedir in %s", path);
00301 return;
00302 }
00303 Error ("SetQdirFromPath: no '%s' in %s", BASEDIRNAME, path);
00304 }
|
|