SDL_visualtest_rwhelper.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* See LICENSE.txt for the full license governing this code. */
  2. /**
  3. * \file rwhelper.c
  4. *
  5. * Header file with some helper functions for working with SDL_RWops.
  6. */
  7. #include <SDL_rwops.h>
  8. #ifndef SDL_visualtest_rwhelper_h_
  9. #define SDL_visualtest_rwhelper_h_
  10. /** Length of the buffer in SDLVisualTest_RWHelperBuffer */
  11. #define RWOPS_BUFFER_LEN 256
  12. /* Set up for C function definitions, even when using C++ */
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /**
  17. * Struct that is used as a buffer by the RW helper functions. Should be initialized by calling
  18. * SDLVisualTest_RWHelperResetBuffer() before being used.
  19. */
  20. typedef struct SDLVisualTest_RWHelperBuffer
  21. {
  22. /*! Character buffer that data is read into */
  23. char buffer[RWOPS_BUFFER_LEN];
  24. /*! buffer[buffer_pos] is the next character to be read from the buffer */
  25. int buffer_pos;
  26. /*! Number of character read into the buffer */
  27. int buffer_width;
  28. } SDLVisualTest_RWHelperBuffer;
  29. /**
  30. * Resets the buffer pointed to by \c buffer used by some of the helper functions.
  31. * This function should be called when you're using one of the helper functions
  32. * with a new SDL_RWops object.
  33. */
  34. void SDLVisualTest_RWHelperResetBuffer(SDLVisualTest_RWHelperBuffer* buffer);
  35. /**
  36. * Reads a single character using the SDL_RWops object pointed to by \c rw.
  37. * This function reads data in blocks and stores them in the buffer pointed to by
  38. * \c buffer, so other SDL_RWops functions should not be used in conjunction
  39. * with this function.
  40. *
  41. * \return The character that was read.
  42. */
  43. char SDLVisualTest_RWHelperReadChar(SDL_RWops* rw,
  44. SDLVisualTest_RWHelperBuffer* buffer);
  45. /**
  46. * Reads characters using the SDL_RWops object pointed to by \c rw into the
  47. * character array pointed to by \c str (of size \c size) until either the
  48. * array is full or a new line is encountered. If \c comment_char is encountered,
  49. * all characters from that position till the end of the line are ignored. The new line
  50. * is not included as part of the buffer. Lines with only whitespace and comments
  51. * are ignored. This function reads data in blocks and stores them in the buffer
  52. * pointed to by \c buffer, so other SDL_RWops functions should not be used in
  53. * conjunction with this function.
  54. *
  55. * \return pointer to the string on success, NULL on failure or EOF.
  56. */
  57. char* SDLVisualTest_RWHelperReadLine(SDL_RWops* rw, char* str, int size,
  58. SDLVisualTest_RWHelperBuffer* buffer,
  59. char comment_char);
  60. /**
  61. * Counts the number of lines that are not all whitespace and comments using the
  62. * SDL_RWops object pointed to by \c rw. \c comment_char indicates the character
  63. * used for comments. Uses the buffer pointed to by \c buffer to read data in blocks.
  64. *
  65. * \return Number of lines on success, -1 on failure.
  66. */
  67. int SDLVisualTest_RWHelperCountNonEmptyLines(SDL_RWops* rw,
  68. SDLVisualTest_RWHelperBuffer* buffer,
  69. char comment_char);
  70. /* Ends C function definitions when using C++ */
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif /* SDL_visualtest_rwhelper_h_ */
  75. /* vi: set ts=4 sw=4 expandtab: */