misc.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. Copyright (C) 2009-2011 id Software LLC, a ZeniMax Media company.
  3. Copyright (C) 2009 Id Software, Inc.
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #include "../doomiphone.h"
  17. void Com_Printf( const char *fmt, ... ) {
  18. va_list argptr;
  19. va_start( argptr, fmt );
  20. //gsh, send output to the console buffer
  21. char buffer[1024];
  22. vsnprintf( buffer, sizeof( buffer ), fmt, argptr );
  23. AppendConsoleBuffer(buffer);
  24. vprintf( fmt, argptr );
  25. va_end( argptr );
  26. }
  27. void Com_Error( const char *fmt, ... ) {
  28. va_list argptr;
  29. va_start( argptr, fmt );
  30. //gsh, send output to the console buffer
  31. char buffer[1024];
  32. vsnprintf( buffer, sizeof( buffer ), fmt, argptr );
  33. AppendConsoleBuffer(buffer);
  34. vprintf( fmt, argptr );
  35. va_end( argptr );
  36. //gsh, email the console to id
  37. EmailConsole();
  38. // drop into the editor
  39. abort();
  40. exit( 1 );
  41. }
  42. char *va( const char *format, ... ) {
  43. va_list argptr;
  44. static char string[ 1024 ];
  45. va_start( argptr, format );
  46. (void)vsnprintf( string, sizeof( string ), format, argptr );
  47. va_end( argptr );
  48. string[ sizeof( string ) - 1 ] = '\0';
  49. return string;
  50. }
  51. int HashString( const char *string ) {
  52. int hash = *string;
  53. if( hash ) {
  54. for( string += 1; *string != '\0'; ++string ) {
  55. hash = (hash << 5) - hash + tolower(*string);
  56. }
  57. }
  58. return hash;
  59. }