wasapi: Patched to compile on C89 systems, and use SDL_ceilf instead of ceilf.
1 /* See COPYING.txt for the full license governing this code. */
5 * Source file with some helper functions for working with SDL_RWops.
9 #include "SDL_visualtest_sut_configparser.h"
10 #include "SDL_visualtest_rwhelper.h"
13 SDLVisualTest_RWHelperResetBuffer(SDLVisualTest_RWHelperBuffer* buffer)
17 SDLTest_LogError("buffer argument cannot be NULL");
20 buffer->buffer_pos = 0;
21 buffer->buffer_width = 0;
25 SDLVisualTest_RWHelperReadChar(SDL_RWops* rw, SDLVisualTest_RWHelperBuffer* buffer)
29 /* if the buffer has been consumed, we fill it up again */
30 if(buffer->buffer_pos == buffer->buffer_width)
32 buffer->buffer_width = SDL_RWread(rw, buffer->buffer, 1, RWOPS_BUFFER_LEN);
33 buffer->buffer_pos = 0;
34 if(buffer->buffer_width == 0)
38 return buffer->buffer[buffer->buffer_pos - 1];
41 /* does not include new lines in the buffer and adds a trailing null character */
43 SDLVisualTest_RWHelperReadLine(SDL_RWops* rw, char* str, int size,
44 SDLVisualTest_RWHelperBuffer* buffer,
48 int current_pos, done;
51 SDLTest_LogError("rw argument cannot be NULL");
56 SDLTest_LogError("str argument cannot be NULL");
61 SDLTest_LogError("buffer argument cannot be NULL");
66 SDLTest_LogError("size argument should be positive");
73 /* ignore leading whitespace */
74 for(ch = SDLVisualTest_RWHelperReadChar(rw, buffer); ch && SDL_isspace(ch);
75 ch = SDLVisualTest_RWHelperReadChar(rw, buffer));
78 ch && ch != '\n' && ch != '\r' && ch != comment_char;
81 str[current_pos] = ch;
82 if(current_pos >= size - 2)
87 ch = SDLVisualTest_RWHelperReadChar(rw, buffer);
91 if(ch == comment_char) /* discard all characters until the next line */
95 ch = SDLVisualTest_RWHelperReadChar(rw, buffer);
96 }while(ch && ch != '\n' && ch != '\r');
105 str[current_pos] = '\0';
109 /* Lines with all whitespace are ignored */
111 SDLVisualTest_RWHelperCountNonEmptyLines(SDL_RWops* rw,
112 SDLVisualTest_RWHelperBuffer* buffer,
116 char str[MAX_SUTOPTION_LINE_LENGTH];
119 SDLTest_LogError("rw argument cannot be NULL");
124 SDLTest_LogError("buffer argument cannot be NULL");
127 while(SDLVisualTest_RWHelperReadLine(rw, str, MAX_SUTOPTION_LINE_LENGTH,
128 buffer, comment_char))