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.

Typedefs

typedef unsigned char byte
typedef void( PFN_ERR )(const char *pFormat,...)
typedef void( PFN_ERR_NUM )(int nNum, const char *pFormat,...)
typedef void( PFN_PRINTF )(const char *pFormat,...)
typedef void( PFN_PRINTF_NUM )(int nNum, const char *pFormat,...)

Enumerations

enum  boolean { false, true }

Functions

float BigFloat (float l)
int BigLong (int l)
short BigShort (short l)
void ConvertDOSToUnixName (char *dst, const char *src)
void DefaultExtension (char *path, char *extension)
void DefaultPath (char *path, char *basepath)
void Error (const char *pFormat,...)
void ErrorNum (int n, const char *pFormat,...)
void ExtractFileBase (const char *path, char *dest)
void ExtractFileExtension (const char *path, char *dest)
void ExtractFileName (const char *path, char *dest)
void ExtractFilePath (const char *path, char *dest)
float LittleFloat (float l)
int LittleLong (int l)
short LittleShort (short l)
int LoadFile (const char *filename, void **bufferptr)
int LoadFileNoCrash (const char *filename, void **bufferptr)
void Printf (const char *pFormat,...)
void PrintfNum (int n, const char *pFormat,...)
void * qblockmalloc (size_t nSize)
void * qmalloc (size_t size)
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, void *buffer, int count)
void SetErrorHandler (PFN_ERR pe)
void SetErrorHandlerNum (PFN_ERR_NUM pe)
void SetPrintfHandler (PFN_PRINTF pe)
void SetPrintfHandlerNum (PFN_PRINTF_NUM pe)
char * StrDup (const char *pStr)
char * StrDup (char *pStr)
void StripExtension (char *path)
void StripFilename (char *path)


Typedef Documentation

typedef unsigned char byte
 

Definition at line 47 of file cmdlib.h.

typedef void( PFN_ERR)(const char *pFormat,...)
 

Definition at line 78 of file cmdlib.h.

typedef void( PFN_ERR_NUM)(int nNum, const char *pFormat,...)
 

Definition at line 80 of file cmdlib.h.

typedef void( PFN_PRINTF)(const char *pFormat,...)
 

Definition at line 79 of file cmdlib.h.

typedef void( PFN_PRINTF_NUM)(int nNum, const char *pFormat,...)
 

Definition at line 81 of file cmdlib.h.


Enumeration Type Documentation

enum boolean
 

Enumeration values:
false 
true 

Definition at line 41 of file cmdlib.h.

00041 {false, true} boolean;


Function Documentation

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 }

void ConvertDOSToUnixName char *  dst,
const char *  src
 

Definition at line 393 of file cmdlib.cpp.

References src.

00394 {
00395     while ( *src )
00396     {
00397         if ( *src == '\\' )
00398             *dst = '/';
00399         else
00400             *dst = *src;
00401         dst++; src++;
00402     }
00403     *dst = 0;
00404 }

void DefaultExtension char *  path,
char *  extension
 

Definition at line 752 of file l_cmd.c.

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

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 }

Here is the call graph for this function:

void DefaultPath char *  path,
char *  basepath
 

Definition at line 772 of file l_cmd.c.

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

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 }

Here is the call graph for this function:

void Error const char *  pFormat,
  ...
 

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 }

void ErrorNum int  n,
const char *  pFormat,
  ...
 

Definition at line 41 of file cmdlib.cpp.

References g_pfnErrorNum, va_end, va_list, and va_start.

00042 {
00043   if (g_pfnErrorNum)
00044   {
00045     va_list arg_ptr;
00046     va_start(arg_ptr, pFormat);
00047     g_pfnErrorNum(nErr, pFormat, arg_ptr);
00048     va_end(arg_ptr);
00049   }
00050 }

void ExtractFileBase const char *  path,
char *  dest
 

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 }

void ExtractFileExtension const char *  path,
char *  dest
 

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 }

void ExtractFileName const char *  path,
char *  dest
 

Definition at line 332 of file cmdlib.cpp.

References src, and strlen().

Referenced by QE_ExpandBspString().

00333 {
00334     const char *src;
00335 
00336     src = path + strlen(path) - 1;
00337 
00338 //
00339 // back up until a \ or the start
00340 //
00341     while (src != path && *(src-1) != '/' 
00342          && *(src-1) != '\\' )
00343         src--;
00344 
00345     while (*src)
00346     {
00347         *dest++ = *src++;
00348     }
00349     *dest = 0;
00350 }

Here is the call graph for this function:

void ExtractFilePath const char *  path,
char *  dest
 

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 }

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.

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 }

int LoadFileNoCrash const char *  filename,
void **  bufferptr
 

Definition at line 217 of file cmdlib.cpp.

References buffer, f, fclose(), fopen(), length(), Q_filelength(), qmalloc(), and SafeRead().

Referenced by QE_LoadProject().

00218 {
00219     FILE    *f;
00220     int    length;
00221     void    *buffer;
00222 
00223     f = fopen (filename, "rb");
00224     if (!f)
00225         return -1;
00226     length = Q_filelength (f);
00227     buffer = qmalloc (length+1);
00228     ((char *)buffer)[length] = 0;
00229     SafeRead (f, buffer, length);
00230     fclose (f);
00231 
00232     *bufferptr = buffer;
00233     return length;
00234 }

Here is the call graph for this function:

void Printf const char *  pFormat,
  ...
 

Definition at line 30 of file cmdlib.cpp.

References g_pfnPrintf, va_end, va_list, and va_start.

00031 {
00032   if (g_pfnPrintf)
00033   {
00034     va_list arg_ptr;
00035     va_start(arg_ptr, pFormat);
00036     g_pfnPrintf(pFormat, arg_ptr);
00037     va_end(arg_ptr);
00038   }
00039 }

void PrintfNum int  n,
const char *  pFormat,
  ...
 

Definition at line 52 of file cmdlib.cpp.

References g_pfnPrintfNum, va_end, va_list, and va_start.

00053 {
00054   if (g_pfnPrintfNum)
00055   {
00056     va_list arg_ptr;
00057     va_start(arg_ptr, pFormat);
00058     g_pfnPrintfNum(nErr, pFormat, arg_ptr);
00059     va_end(arg_ptr);
00060   }
00061 }

void* qblockmalloc size_t  nSize  ) 
 

Definition at line 90 of file cmdlib.cpp.

References b, malloc(), MEM_BLOCKSIZE, and memset().

Referenced by LoadFile().

00091 {
00092     void *b;
00093   // round up to threshold
00094   int nAllocSize = nSize % MEM_BLOCKSIZE;
00095   if ( nAllocSize > 0)
00096   {
00097     nSize += MEM_BLOCKSIZE - nAllocSize;
00098   }
00099     b = malloc(nSize + 1);
00100     memset (b, 0, nSize);
00101     return b;
00102 }

Here is the call graph for this function:

void* qmalloc size_t  size  ) 
 

Definition at line 104 of file cmdlib.cpp.

References b, malloc(), and memset().

Referenced by Brush_Alloc(), Eclass_hasModel(), Eclass_InitFromText(), Entity_Clone(), Entity_CopyClone(), Entity_Create(), Entity_Parse(), Face_Alloc(), GetCachedModel(), Group_Add(), Group_Alloc(), LoadFileNoCrash(), LoadModel(), MakeNewPatch(), MakeNewTerrain(), Map_New(), ParseEpair(), QERApp_AllocateEpair(), QERApp_CreateEntityHandle(), QERApp_GetPoints(), SetKeyValue(), Texture_CreateSolid(), Texture_LoadTexture(), Texture_LoadTGATexture(), Texture_MakeDefault(), Texture_MakeNoshadertexture(), and Winding_Clone().

00105 {
00106     void *b;
00107     b = malloc(nSize + 1);
00108     memset (b, 0, nSize);
00109     return b;
00110 }

Here is the call graph for this function:

FILE* SafeOpenRead const char *  filename  ) 
 

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 }

FILE* SafeOpenWrite const char *  filename  ) 
 

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 }

void SafeRead FILE f,
void *  buffer,
int  count
 

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 }

void SafeWrite FILE f,
const void *  buffer,
int  count
 

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 }

void SaveFile const char *  filename,
void *  buffer,
int  count
 

Definition at line 242 of file cmdlib.cpp.

References buffer, count, f, fclose(), SafeOpenWrite(), and SafeWrite().

00243 {
00244     FILE    *f;
00245 
00246     f = SafeOpenWrite (filename);
00247     SafeWrite (f, buffer, count);
00248     fclose (f);
00249 }

Here is the call graph for this function:

void SetErrorHandler PFN_ERR  pe  ) 
 

Definition at line 65 of file cmdlib.cpp.

References g_pfnError.

00066 {
00067   g_pfnError = pe;
00068 }

void SetErrorHandlerNum PFN_ERR_NUM  pe  ) 
 

Definition at line 75 of file cmdlib.cpp.

References g_pfnErrorNum.

00076 {
00077   g_pfnErrorNum = pe;
00078 }

void SetPrintfHandler PFN_PRINTF  pe  ) 
 

Definition at line 70 of file cmdlib.cpp.

References g_pfnPrintf.

00071 {
00072   g_pfnPrintf = pe;
00073 }

void SetPrintfHandlerNum PFN_PRINTF_NUM  pe  ) 
 

char* StrDup const char *  pStr  ) 
 

Definition at line 416 of file cmdlib.cpp.

References strcpy(), and strlen().

00417 { 
00418   if (pStr)
00419   {
00420     return strcpy(new char[strlen(pStr)+1], pStr); 
00421   }
00422   return NULL;
00423 }

Here is the call graph for this function:

char* StrDup char *  pStr  ) 
 

Definition at line 407 of file cmdlib.cpp.

References strcpy(), and strlen().

00408 { 
00409   if (pStr)
00410   {
00411     return strcpy(new char[strlen(pStr)+1], pStr); 
00412   }
00413   return NULL;
00414 }

Here is the call graph for this function:

void StripExtension char *  path  ) 
 

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 }

void StripFilename char *  path  ) 
 

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 }


Generated on Thu Aug 25 15:45:44 2005 for Quake III Arena by  doxygen 1.3.9.1