util.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. typedef void(*LOGCALLBACK)(LOGLEVEL, const char *, const char *);
  128. void
  129. UTIL_LogSetOutput(
  130. LOGCALLBACK callback,
  131. int maxloglen
  132. );
  133. void
  134. UTIL_LogOutput(
  135. LOGLEVEL level,
  136. const char *fmt,
  137. ...
  138. );
  139. void
  140. UTIL_LogSetLevel(
  141. LOGLEVEL minlevel
  142. );
  143. PAL_C_LINKAGE_END
  144. #endif