util.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. typedef enum LOGLEVEL
  117. {
  118. LOGLEVEL_MIN,
  119. LOGLEVEL_VERBOSE = LOGLEVEL_MIN,
  120. LOGLEVEL_DEBUG,
  121. LOGLEVEL_INFO,
  122. LOGLEVEL_WARNING,
  123. LOGLEVEL_ERROR,
  124. LOGLEVEL_FATAL,
  125. LOGLEVEL_MAX = LOGLEVEL_FATAL,
  126. } LOGLEVEL;
  127. /*++
  128. Purpose:
  129. The pointer to callback function that produces actual log output.
  130. Parameters:
  131. [IN] level - The log level of this output call.
  132. [IN] full_log - The full log string produced by UTIL_LogOutput.
  133. [IN] user_log - The log string produced by user-provided format.
  134. Return value:
  135. None.
  136. --*/
  137. typedef void(*LOGCALLBACK)(LOGLEVEL level, const char *full_log, const char *user_log);
  138. /*++
  139. Purpose:
  140. Initialize the internal log system.
  141. Parameters:
  142. [IN] callback - The callback function to be called at each
  143. call of UTIL_LogOutput.
  144. [IN] maxloglen - The max buffer size that holds the output
  145. correspoind to user-provided format string,
  146. not including the terminal null-character.
  147. [IN] staticbuffer - Whether UTIL_LogOutput should generate the
  148. output string into a one-time allocated global
  149. buffer, or to a per-call allocated locall buffer.
  150. Return value:
  151. None.
  152. --*/
  153. void
  154. UTIL_LogSetOutput(
  155. LOGCALLBACK callback,
  156. int maxloglen,
  157. BOOL staticbuffer
  158. );
  159. /*++
  160. Purpose:
  161. Set the minimal log level that could be output.
  162. Any level below this level will produce no output.
  163. Parameters:
  164. [IN] minlevel - The minimal log level, must be within the
  165. range [LOGLEVEL_MIN, LOGLEVEL_MAX].
  166. Return value:
  167. None.
  168. --*/
  169. void
  170. UTIL_LogOutput(
  171. LOGLEVEL level,
  172. const char *fmt,
  173. ...
  174. );
  175. /*++
  176. Purpose:
  177. Set the minimal log level that could be output.
  178. Any level below this level will produce no output.
  179. Parameters:
  180. [IN] minlevel - The minimal log level, must be within the
  181. range [LOGLEVEL_MIN, LOGLEVEL_MAX].
  182. Return value:
  183. None.
  184. --*/
  185. void
  186. UTIL_LogSetLevel(
  187. LOGLEVEL minlevel
  188. );
  189. PAL_C_LINKAGE_END
  190. #endif