util.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // All rights reserved.
  5. //
  6. // This file is part of SDLPAL.
  7. //
  8. // SDLPAL is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU General Public License
  19. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. //
  21. #ifndef UTIL_H
  22. #define UTIL_H
  23. #include "common.h"
  24. //#define ENABLE_LOG 1
  25. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #endif
  29. void
  30. trim(
  31. char *str
  32. );
  33. char *va(
  34. const char *format,
  35. ...
  36. );
  37. int
  38. RandomLong(
  39. int from,
  40. int to
  41. );
  42. float
  43. RandomFloat(
  44. float from,
  45. float to
  46. );
  47. void
  48. UTIL_Delay(
  49. unsigned int ms
  50. );
  51. void
  52. TerminateOnError(
  53. const char *fmt,
  54. ...
  55. );
  56. void *
  57. UTIL_malloc(
  58. size_t buffer_size
  59. );
  60. void *
  61. UTIL_calloc(
  62. size_t n,
  63. size_t size
  64. );
  65. FILE *
  66. UTIL_OpenRequiredFile(
  67. LPCSTR lpszFileName
  68. );
  69. FILE *
  70. UTIL_OpenRequiredFileForMode(
  71. LPCSTR lpszFileName,
  72. LPCSTR szMode
  73. );
  74. FILE *
  75. UTIL_OpenFile(
  76. LPCSTR lpszFileName
  77. );
  78. FILE *
  79. UTIL_OpenFileForMode(
  80. LPCSTR lpszFileName,
  81. LPCSTR szMode
  82. );
  83. VOID
  84. UTIL_CloseFile(
  85. FILE *fp
  86. );
  87. LPCSTR
  88. UTIL_BasePath(
  89. VOID
  90. );
  91. LPCSTR
  92. UTIL_SavePath(
  93. VOID
  94. );
  95. LPCSTR
  96. UTIL_ConfigPath(
  97. VOID
  98. );
  99. LPCSTR
  100. UTIL_ScreenShotPath(
  101. VOID
  102. );
  103. BOOL
  104. UTIL_GetScreenSize(
  105. DWORD *pdwScreenWidth,
  106. DWORD *pdwScreenHeight
  107. );
  108. #if PAL_HAS_TOUCH
  109. BOOL
  110. UTIL_TouchEnabled(
  111. VOID
  112. );
  113. #endif
  114. INT
  115. UTIL_Platform_Init(
  116. int argc,
  117. char* argv[]
  118. );
  119. VOID
  120. UTIL_Platform_Quit(
  121. VOID
  122. );
  123. #define LOG_EMERG 0 /* system is unusable */
  124. #define LOG_ALERT 1 /* action must be taken immediately */
  125. #define LOG_CRIT 2 /* critical conditions */
  126. #define LOG_ERR 3 /* error conditions */
  127. #define LOG_WARNING 4 /* warning conditions */
  128. #define LOG_NOTICE 5 /* normal but significant condition */
  129. #define LOG_INFO 6 /* informational */
  130. #define LOG_DEBUG 7 /* debug-level messages */
  131. #define LOG_LAST_PRIORITY 8 /* last level */
  132. #ifdef ENABLE_LOG
  133. FILE *
  134. UTIL_OpenLog(
  135. VOID
  136. );
  137. VOID
  138. UTIL_CloseLog(
  139. VOID
  140. );
  141. VOID
  142. UTIL_WriteLog(
  143. int Priority,
  144. const char *Fmt,
  145. ...
  146. );
  147. #else
  148. #define UTIL_OpenLog() ((void)(0))
  149. #define UTIL_CloseLog() ((void)(0))
  150. #define UTIL_WriteLog(...) ((void)(0))
  151. #endif
  152. #ifdef __cplusplus
  153. }
  154. #endif
  155. #endif