util.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. 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. BOOL
  93. UTIL_GetScreenSize(
  94. DWORD *pdwScreenWidth,
  95. DWORD *pdwScreenHeight
  96. );
  97. BOOL
  98. UTIL_IsAbsolutePath(
  99. LPCSTR lpszFileName
  100. );
  101. INT
  102. UTIL_Platform_Init(
  103. int argc,
  104. char* argv[]
  105. );
  106. VOID
  107. UTIL_Platform_Quit(
  108. VOID
  109. );
  110. PAL_C_LINKAGE_END
  111. #define LOG_EMERG 0 /* system is unusable */
  112. #define LOG_ALERT 1 /* action must be taken immediately */
  113. #define LOG_CRIT 2 /* critical conditions */
  114. #define LOG_ERR 3 /* error conditions */
  115. #define LOG_WARNING 4 /* warning conditions */
  116. #define LOG_NOTICE 5 /* normal but significant condition */
  117. #define LOG_INFO 6 /* informational */
  118. #define LOG_DEBUG 7 /* debug-level messages */
  119. #define LOG_LAST_PRIORITY 8 /* last level */
  120. #ifdef ENABLE_LOG
  121. PAL_C_LINKAGE_BEGIN
  122. FILE *
  123. UTIL_OpenLog(
  124. VOID
  125. );
  126. VOID
  127. UTIL_CloseLog(
  128. VOID
  129. );
  130. VOID
  131. UTIL_WriteLog(
  132. int Priority,
  133. const char *Fmt,
  134. ...
  135. );
  136. PAL_C_LINKAGE_END
  137. #else
  138. # define UTIL_OpenLog() ((void)(0))
  139. # define UTIL_CloseLog() ((void)(0))
  140. # define UTIL_WriteLog(...) ((void)(0))
  141. #endif
  142. #endif