util.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 4; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009-2011, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // Copyright (c) 2011-2017, SDLPAL development team.
  5. // All rights reserved.
  6. //
  7. // This file is part of SDLPAL.
  8. //
  9. // SDLPAL is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. //
  22. #ifndef UTIL_H
  23. #define UTIL_H
  24. #include "common.h"
  25. PAL_C_LINKAGE_BEGIN
  26. void
  27. UTIL_MsgBox(
  28. char *string
  29. );
  30. long
  31. flength(
  32. FILE *fp
  33. );
  34. void
  35. trim(
  36. char *str
  37. );
  38. char *va(
  39. const char *format,
  40. ...
  41. );
  42. int
  43. RandomLong(
  44. int from,
  45. int to
  46. );
  47. float
  48. RandomFloat(
  49. float from,
  50. float to
  51. );
  52. void
  53. UTIL_Delay(
  54. unsigned int ms
  55. );
  56. void
  57. TerminateOnError(
  58. const char *fmt,
  59. ...
  60. );
  61. void *
  62. UTIL_malloc(
  63. size_t buffer_size
  64. );
  65. void *
  66. UTIL_calloc(
  67. size_t n,
  68. size_t size
  69. );
  70. FILE *
  71. UTIL_OpenRequiredFile(
  72. LPCSTR lpszFileName
  73. );
  74. FILE *
  75. UTIL_OpenRequiredFileForMode(
  76. LPCSTR lpszFileName,
  77. LPCSTR szMode
  78. );
  79. FILE *
  80. UTIL_OpenFile(
  81. LPCSTR lpszFileName
  82. );
  83. FILE *
  84. UTIL_OpenFileForMode(
  85. LPCSTR lpszFileName,
  86. LPCSTR szMode
  87. );
  88. VOID
  89. UTIL_CloseFile(
  90. FILE *fp
  91. );
  92. /*
  93. * Platform-specific utilities
  94. */
  95. BOOL
  96. UTIL_GetScreenSize(
  97. DWORD *pdwScreenWidth,
  98. DWORD *pdwScreenHeight
  99. );
  100. BOOL
  101. UTIL_IsAbsolutePath(
  102. const char *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. /*
  114. * Logging utilities
  115. */
  116. /*++
  117. Purpose:
  118. The pointer to callback function that produces actual log output.
  119. Parameters:
  120. [IN] level - The log level of this output call.
  121. [IN] full_log - The full log string produced by UTIL_LogOutput.
  122. [IN] user_log - The log string produced by user-provided format.
  123. Return value:
  124. None.
  125. --*/
  126. typedef void(*LOGCALLBACK)(LOGLEVEL level, const char *full_log, const char *user_log);
  127. /*++
  128. Purpose:
  129. Adds a log output callback.
  130. Parameters:
  131. [IN] callback - The callback function to be added. Once added,
  132. it will be called by UTIL_LogOutput.
  133. [IN] loglevel - The minimal log level that the callback should
  134. be called. Any log whose level below this will
  135. be ignored by the callback.
  136. Return value:
  137. The slot id (>= 0), -1 if all slots are used or callback is NULL.
  138. --*/
  139. int
  140. UTIL_LogAddOutputCallback(
  141. LOGCALLBACK callback,
  142. LOGLEVEL loglevel
  143. );
  144. /*++
  145. Purpose:
  146. Removes a log output callback.
  147. Parameters:
  148. [IN] id - The id of callback function to be removed.
  149. Return value:
  150. None
  151. --*/
  152. void
  153. UTIL_LogRemoveOutputCallback(
  154. int id
  155. );
  156. /*++
  157. Purpose:
  158. Set the minimal log level that could be output.
  159. Any level below this level will produce no output.
  160. Parameters:
  161. [IN] minlevel - The minimal log level, must be within the
  162. range [LOGLEVEL_MIN, LOGLEVEL_MAX].
  163. Return value:
  164. None.
  165. --*/
  166. void
  167. UTIL_LogOutput(
  168. LOGLEVEL level,
  169. const char *fmt,
  170. ...
  171. );
  172. /*++
  173. Purpose:
  174. Set the minimal log level that could be output.
  175. Any level below this level will produce no output.
  176. Parameters:
  177. [IN] minlevel - The minimal log level, must be within the
  178. range [LOGLEVEL_MIN, LOGLEVEL_MAX].
  179. Return value:
  180. None.
  181. --*/
  182. void
  183. UTIL_LogSetLevel(
  184. LOGLEVEL minlevel
  185. );
  186. void
  187. UTIL_LogToFile(
  188. LOGLEVEL _,
  189. const char *string,
  190. const char *__
  191. );
  192. PAL_C_LINKAGE_END
  193. #endif