util.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. Initialize the internal log system.
  130. Parameters:
  131. [IN] callback - The callback function to be called at each
  132. call of UTIL_LogOutput.
  133. [IN] maxloglen - The max buffer size that holds the output
  134. correspoind to user-provided format string,
  135. not including the terminal null-character.
  136. [IN] staticbuffer - Whether UTIL_LogOutput should generate the
  137. output string into a one-time allocated global
  138. buffer, or to a per-call allocated locall buffer.
  139. Return value:
  140. None.
  141. --*/
  142. void
  143. UTIL_LogSetOutput(
  144. LOGCALLBACK callback,
  145. int maxloglen,
  146. BOOL staticbuffer
  147. );
  148. /*++
  149. Purpose:
  150. Set the minimal log level that could be output.
  151. Any level below this level will produce no output.
  152. Parameters:
  153. [IN] minlevel - The minimal log level, must be within the
  154. range [LOGLEVEL_MIN, LOGLEVEL_MAX].
  155. Return value:
  156. None.
  157. --*/
  158. void
  159. UTIL_LogOutput(
  160. LOGLEVEL level,
  161. const char *fmt,
  162. ...
  163. );
  164. /*++
  165. Purpose:
  166. Set the minimal log level that could be output.
  167. Any level below this level will produce no output.
  168. Parameters:
  169. [IN] minlevel - The minimal log level, must be within the
  170. range [LOGLEVEL_MIN, LOGLEVEL_MAX].
  171. Return value:
  172. None.
  173. --*/
  174. void
  175. UTIL_LogSetLevel(
  176. LOGLEVEL minlevel
  177. );
  178. PAL_C_LINKAGE_END
  179. #endif