util.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // All rights reserved.
  5. //
  6. // This file is part of SDLPAL.
  7. //
  8. // SDLPAL is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU General Public License
  19. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. //
  21. #ifndef UTIL_H
  22. #define UTIL_H
  23. #include "common.h"
  24. //#define ENABLE_LOG 1
  25. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #endif
  29. void
  30. UTIL_MsgBox(
  31. char *string
  32. );
  33. long
  34. flength(
  35. FILE *fp
  36. );
  37. void
  38. trim(
  39. char *str
  40. );
  41. char *va(
  42. const char *format,
  43. ...
  44. );
  45. int
  46. RandomLong(
  47. int from,
  48. int to
  49. );
  50. float
  51. RandomFloat(
  52. float from,
  53. float to
  54. );
  55. void
  56. UTIL_Delay(
  57. unsigned int ms
  58. );
  59. void
  60. TerminateOnError(
  61. const char *fmt,
  62. ...
  63. );
  64. void *
  65. UTIL_malloc(
  66. size_t buffer_size
  67. );
  68. void *
  69. UTIL_calloc(
  70. size_t n,
  71. size_t size
  72. );
  73. FILE *
  74. UTIL_OpenRequiredFile(
  75. LPCSTR lpszFileName
  76. );
  77. FILE *
  78. UTIL_OpenRequiredFileForMode(
  79. LPCSTR lpszFileName,
  80. LPCSTR szMode
  81. );
  82. FILE *
  83. UTIL_OpenFile(
  84. LPCSTR lpszFileName
  85. );
  86. FILE *
  87. UTIL_OpenFileForMode(
  88. LPCSTR lpszFileName,
  89. LPCSTR szMode
  90. );
  91. VOID
  92. UTIL_CloseFile(
  93. FILE *fp
  94. );
  95. BOOL
  96. UTIL_GetScreenSize(
  97. DWORD *pdwScreenWidth,
  98. DWORD *pdwScreenHeight
  99. );
  100. BOOL
  101. UTIL_IsAbsolutePath(
  102. LPCSTR lpszFileName
  103. );
  104. INT
  105. UTIL_Platform_Init(
  106. int argc,
  107. char* argv[]
  108. );
  109. VOID
  110. UTIL_Platform_Quit(
  111. VOID
  112. );
  113. #define LOG_EMERG 0 /* system is unusable */
  114. #define LOG_ALERT 1 /* action must be taken immediately */
  115. #define LOG_CRIT 2 /* critical conditions */
  116. #define LOG_ERR 3 /* error conditions */
  117. #define LOG_WARNING 4 /* warning conditions */
  118. #define LOG_NOTICE 5 /* normal but significant condition */
  119. #define LOG_INFO 6 /* informational */
  120. #define LOG_DEBUG 7 /* debug-level messages */
  121. #define LOG_LAST_PRIORITY 8 /* last level */
  122. #ifdef ENABLE_LOG
  123. FILE *
  124. UTIL_OpenLog(
  125. VOID
  126. );
  127. VOID
  128. UTIL_CloseLog(
  129. VOID
  130. );
  131. VOID
  132. UTIL_WriteLog(
  133. int Priority,
  134. const char *Fmt,
  135. ...
  136. );
  137. #else
  138. #define UTIL_OpenLog() ((void)(0))
  139. #define UTIL_CloseLog() ((void)(0))
  140. #define UTIL_WriteLog(...) ((void)(0))
  141. #endif
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif