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