Skip to content

Latest commit

 

History

History
87 lines (75 loc) · 3.16 KB

SDL_visualtest_rwhelper.h

File metadata and controls

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