util.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. //#define ENABLE_LOG 1
  26. PAL_C_LINKAGE_BEGIN
  27. void
  28. UTIL_MsgBox(
  29. char *string
  30. );
  31. long
  32. flength(
  33. FILE *fp
  34. );
  35. void
  36. trim(
  37. char *str
  38. );
  39. char *va(
  40. const char *format,
  41. ...
  42. );
  43. int
  44. RandomLong(
  45. int from,
  46. int to
  47. );
  48. float
  49. RandomFloat(
  50. float from,
  51. float to
  52. );
  53. void
  54. UTIL_Delay(
  55. unsigned int ms
  56. );
  57. void
  58. TerminateOnError(
  59. const char *fmt,
  60. ...
  61. );
  62. void *
  63. UTIL_malloc(
  64. size_t buffer_size
  65. );
  66. void *
  67. UTIL_calloc(
  68. size_t n,
  69. size_t size
  70. );
  71. FILE *
  72. UTIL_OpenRequiredFile(
  73. LPCSTR lpszFileName
  74. );
  75. FILE *
  76. UTIL_OpenRequiredFileForMode(
  77. LPCSTR lpszFileName,
  78. LPCSTR szMode
  79. );
  80. FILE *
  81. UTIL_OpenFile(
  82. LPCSTR lpszFileName
  83. );
  84. FILE *
  85. UTIL_OpenFileForMode(
  86. LPCSTR lpszFileName,
  87. LPCSTR szMode
  88. );
  89. VOID
  90. UTIL_CloseFile(
  91. FILE *fp
  92. );
  93. BOOL
  94. UTIL_GetScreenSize(
  95. DWORD *pdwScreenWidth,
  96. DWORD *pdwScreenHeight
  97. );
  98. BOOL
  99. UTIL_IsAbsolutePath(
  100. LPCSTR lpszFileName
  101. );
  102. INT
  103. UTIL_Platform_Init(
  104. int argc,
  105. char* argv[]
  106. );
  107. VOID
  108. UTIL_Platform_Quit(
  109. VOID
  110. );
  111. PAL_C_LINKAGE_END
  112. #define LOG_EMERG 0 /* system is unusable */
  113. #define LOG_ALERT 1 /* action must be taken immediately */
  114. #define LOG_CRIT 2 /* critical conditions */
  115. #define LOG_ERR 3 /* error conditions */
  116. #define LOG_WARNING 4 /* warning conditions */
  117. #define LOG_NOTICE 5 /* normal but significant condition */
  118. #define LOG_INFO 6 /* informational */
  119. #define LOG_DEBUG 7 /* debug-level messages */
  120. #define LOG_LAST_PRIORITY 8 /* last level */
  121. #ifdef ENABLE_LOG
  122. PAL_C_LINKAGE_BEGIN
  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. PAL_C_LINKAGE_END
  138. #else
  139. # define UTIL_OpenLog() ((void)(0))
  140. # define UTIL_CloseLog() ((void)(0))
  141. # define UTIL_WriteLog(...) ((void)(0))
  142. #endif
  143. #endif