share.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "../wolfiphone.h"
  16. char com_token[128];
  17. /*
  18. ============================================================================
  19. BYTE ORDER FUNCTIONS
  20. ============================================================================
  21. */
  22. /*
  23. -----------------------------------------------------------------------------
  24. Function: va() -Does a varargs printf into a temp buffer, so I don't need to
  25. have varargs versions of all text functions.
  26. Parameters: format -[in] Format-control string.
  27. ... -[in] Optional arguments.
  28. Returns: Formatted string.
  29. Notes:
  30. If format string is longer than 1024 it will be truncated.
  31. -----------------------------------------------------------------------------
  32. */
  33. PUBLIC char *va( char *format, ... )
  34. {
  35. va_list argptr;
  36. static char string[ 1024 ];
  37. va_start( argptr, format );
  38. (void)vsnprintf( string, sizeof( string ), format, argptr );
  39. va_end( argptr );
  40. string[ sizeof( string ) - 1 ] = '\0';
  41. return string;
  42. }
  43. /*
  44. -----------------------------------------------------------------------------
  45. Function: COM_Parse() -Parse a token out of a string.
  46. Parameters: data_p -[in] String to parse.
  47. Returns: On success it will return the token string, otherwise it will
  48. return "".
  49. Notes:
  50. -----------------------------------------------------------------------------
  51. */
  52. PUBLIC char *COM_Parse( char **data_p )
  53. {
  54. int c;
  55. int len;
  56. char *data;
  57. data = *data_p;
  58. len = 0;
  59. com_token[ 0 ] = 0;
  60. if( ! data )
  61. {
  62. *data_p = NULL;
  63. return "";
  64. }
  65. // skip whitespace
  66. skipwhite:
  67. while( (c = *data) <= ' ')
  68. {
  69. if( c == 0 )
  70. {
  71. *data_p = NULL;
  72. return "";
  73. }
  74. data++;
  75. }
  76. // skip // comments
  77. if( c == '/' && data[ 1 ] == '/' )
  78. {
  79. while( *data && *data != '\n' )
  80. {
  81. data++;
  82. }
  83. goto skipwhite;
  84. }
  85. // handle quoted strings specially
  86. if( c == '\"' )
  87. {
  88. data++;
  89. while( 1 )
  90. {
  91. c = *data++;
  92. if( c == '\"' || ! c )
  93. {
  94. com_token[ len ] = 0;
  95. *data_p = data;
  96. return com_token;
  97. }
  98. if( len < MAX_TOKEN_CHARS )
  99. {
  100. com_token[ len ] = c;
  101. len++;
  102. }
  103. }
  104. }
  105. // parse a regular word
  106. do
  107. {
  108. if( len < MAX_TOKEN_CHARS )
  109. {
  110. com_token[ len ] = c;
  111. len++;
  112. }
  113. data++;
  114. c = *data;
  115. } while( c > 32 );
  116. if( len == MAX_TOKEN_CHARS )
  117. {
  118. // Com_Printf ("Token exceeded %i chars, discarded.\n", MAX_TOKEN_CHARS);
  119. len = 0;
  120. }
  121. com_token[ len ] = 0;
  122. *data_p = data;
  123. return com_token;
  124. }
  125. /*
  126. -----------------------------------------------------------------------------
  127. Function: Com_PageInMemory()
  128. Parameters:
  129. Returns:
  130. Notes:
  131. -----------------------------------------------------------------------------
  132. */
  133. int paged_total;
  134. PUBLIC void Com_PageInMemory( PW8 buffer, int size )
  135. {
  136. int i;
  137. for( i = size - 1 ; i > 0 ; i -= 4096 )
  138. {
  139. paged_total += buffer[ i ];
  140. }
  141. }