util.h 3.0 KB

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