util.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  3. // All rights reserved.
  4. //
  5. // This file is part of SDLPAL.
  6. //
  7. // SDLPAL is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. //
  20. #ifndef UTIL_H
  21. #define UTIL_H
  22. #include "common.h"
  23. //#define ENABLE_LOG 1
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. void
  29. trim(
  30. char *str
  31. );
  32. char *va(
  33. const char *format,
  34. ...
  35. );
  36. int
  37. RandomLong(
  38. int from,
  39. int to
  40. );
  41. float
  42. RandomFloat(
  43. float from,
  44. float to
  45. );
  46. void
  47. UTIL_Delay(
  48. unsigned int ms
  49. );
  50. void
  51. TerminateOnError(
  52. const char *fmt,
  53. ...
  54. );
  55. void *
  56. UTIL_malloc(
  57. size_t buffer_size
  58. );
  59. void *
  60. UTIL_calloc(
  61. size_t n,
  62. size_t size
  63. );
  64. FILE *
  65. UTIL_OpenRequiredFile(
  66. LPCSTR lpszFileName
  67. );
  68. VOID
  69. UTIL_CloseFile(
  70. FILE *fp
  71. );
  72. #define _PATH_LOG PAL_PREFIX "log.txt"
  73. #define LOG_EMERG 0 /* system is unusable */
  74. #define LOG_ALERT 1 /* action must be taken immediately */
  75. #define LOG_CRIT 2 /* critical conditions */
  76. #define LOG_ERR 3 /* error conditions */
  77. #define LOG_WARNING 4 /* warning conditions */
  78. #define LOG_NOTICE 5 /* normal but significant condition */
  79. #define LOG_INFO 6 /* informational */
  80. #define LOG_DEBUG 7 /* debug-level messages */
  81. #define LOG_LAST_PRIORITY 8 /* last level */
  82. #ifdef ENABLE_LOG
  83. FILE *
  84. UTIL_OpenLog(
  85. VOID
  86. );
  87. VOID
  88. UTIL_CloseLog(
  89. VOID
  90. );
  91. VOID
  92. UTIL_WriteLog(
  93. int Priority,
  94. const char *Fmt,
  95. ...
  96. );
  97. #else
  98. #define UTIL_OpenLog() ((void)(0))
  99. #define UTIL_CloseLog() ((void)(0))
  100. #ifdef _MSC_VER
  101. __forceinline VOID UTIL_WriteLog(int i, const char *p, ...) {}
  102. #else
  103. #define UTIL_WriteLog(...) ((void)(0))
  104. #endif
  105. #endif
  106. #ifdef __cplusplus
  107. }
  108. #endif
  109. #endif