comparison test/automated/testsdl.c @ 3460:ba48701b0534

Added support for generic getopt() function instead of getopt_long(). Because not all platforms have getopt_long().
author Mike Gorchak <lestat@i.com.ua>
date Thu, 19 Nov 2009 09:07:09 +0000
parents 63d4517fc4ac
children 78db4f7ae2f3
comparison
equal deleted inserted replaced
3459:feea0def118d 3460:ba48701b0534
14 #include "rwops/rwops.h" 14 #include "rwops/rwops.h"
15 #include "surface/surface.h" 15 #include "surface/surface.h"
16 #include "render/render.h" 16 #include "render/render.h"
17 #include "audio/audio.h" 17 #include "audio/audio.h"
18 18
19 #if defined(__QNXNTO__)
20 #define NO_GETOPT_LONG 1
21 #endif /* __QNXNTO__ */
22
19 #include <stdio.h> /* printf */ 23 #include <stdio.h> /* printf */
20 #include <stdlib.h> /* exit */ 24 #include <stdlib.h> /* exit */
21 #include <unistd.h> /* getopt */ 25 #include <unistd.h> /* getopt */
26 #include <string.h> /* strcmp */
27 #if !defined(NO_GETOPT_LONG)
22 #include <getopt.h> /* getopt_long */ 28 #include <getopt.h> /* getopt_long */
23 #include <string.h> /* strcmp */ 29 #endif /* !NO_GETOPT_LONG */
24 30
25 31
26 /* 32 /*
27 * Tests to run. 33 * Tests to run.
28 */ 34 */
43 49
44 50
45 /** 51 /**
46 * @brief Displays program usage. 52 * @brief Displays program usage.
47 */ 53 */
54 #if !defined(NO_GETOPT_LONG)
48 static void print_usage( const char *name ) 55 static void print_usage( const char *name )
49 { 56 {
50 printf("Usage: %s [OPTIONS]\n", name); 57 printf("Usage: %s [OPTIONS]\n", name);
51 printf("Options are:\n"); 58 printf("Options are:\n");
52 printf(" -m, --manual enables tests that require user interaction\n"); 59 printf(" -m, --manual enables tests that require user interaction\n");
53 printf(" --noplatform do not run the platform tests\n"); 60 printf(" -p, --noplatform do not run the platform tests\n");
54 printf(" --norwops do not run the rwops tests\n"); 61 printf(" -o, --norwops do not run the rwops tests\n");
55 printf(" --nosurface do not run the surface tests\n"); 62 printf(" -s, --nosurface do not run the surface tests\n");
56 printf(" --norender do not run the render tests\n"); 63 printf(" -r, --norender do not run the render tests\n");
57 printf(" --noaudio do not run the audio tests\n"); 64 printf(" -a, --noaudio do not run the audio tests\n");
58 printf(" -v, --verbose increases verbosity level by 1 for each -v\n"); 65 printf(" -v, --verbose increases verbosity level by 1 for each -v\n");
59 printf(" -q, --quiet only displays errors\n"); 66 printf(" -q, --quiet only displays errors\n");
60 printf(" -h, --help display this message and exit\n"); 67 printf(" -h, --help display this message and exit\n");
61 } 68 }
62 69 #endif /* !NO_GETOPT_LONG */
70
71 #if defined(NO_GETOPT_LONG)
72 static void print_usage( const char *name )
73 {
74 printf("Usage: %s [OPTIONS]\n", name);
75 printf("Options are:\n");
76 printf(" -m, enables tests that require user interaction\n");
77 printf(" -p, do not run the platform tests\n");
78 printf(" -o, do not run the rwops tests\n");
79 printf(" -s, do not run the surface tests\n");
80 printf(" -r, do not run the render tests\n");
81 printf(" -a, do not run the audio tests\n");
82 printf(" -v, increases verbosity level by 1 for each -v\n");
83 printf(" -q, only displays errors\n");
84 printf(" -h, display this message and exit\n");
85 }
86 #endif /* NO_GETOPT_LONG */
63 87
64 /** 88 /**
65 * @brief Handles the options. 89 * @brief Handles the options.
66 */ 90 */
91 #if !defined(NO_GETOPT_LONG)
67 static void parse_options( int argc, char *argv[] ) 92 static void parse_options( int argc, char *argv[] )
68 { 93 {
69 static struct option long_options[] = { 94 static struct option long_options[] = {
70 { "manual", no_argument, 0, 'm' }, 95 { "manual", no_argument, 0, 'm' },
71 { "noplatform", no_argument, 0, 0 }, 96 { "noplatform", no_argument, 0, 'p' },
72 { "norwops", no_argument, 0, 0 }, 97 { "norwops", no_argument, 0, 'o' },
73 { "nosurface", no_argument, 0, 0 }, 98 { "nosurface", no_argument, 0, 's' },
74 { "norender", no_argument, 0, 0 }, 99 { "norender", no_argument, 0, 'r' },
75 { "noaudio", no_argument, 0, 0 }, 100 { "noaudio", no_argument, 0, 'a' },
76 { "verbose", no_argument, 0, 'v' }, 101 { "verbose", no_argument, 0, 'v' },
77 { "quiet", no_argument, 0, 'q' }, 102 { "quiet", no_argument, 0, 'q' },
78 { "help", no_argument, 0, 'h' }, 103 { "help", no_argument, 0, 'h' },
79 {NULL,0,0,0} 104 {NULL,0,0,0}
80 }; 105 };
83 int i; 108 int i;
84 const char *str; 109 const char *str;
85 110
86 /* Iterate over options. */ 111 /* Iterate over options. */
87 while ((c = getopt_long( argc, argv, 112 while ((c = getopt_long( argc, argv,
88 "vqh", 113 "mposravqh",
89 long_options, &option_index)) != -1) { 114 long_options, &option_index)) != -1) {
90 115
91 /* Handle options. */ 116 /* Handle options. */
92 switch (c) { 117 switch (c) {
93 case 0: 118 case 0:
107 /* Manual. */ 132 /* Manual. */
108 case 'm': 133 case 'm':
109 run_manual = 1; 134 run_manual = 1;
110 break; 135 break;
111 136
137 /* No platform. */
138 case 'p':
139 run_platform = 0;
140 break;
141
142 /* No rwops. */
143 case 'o':
144 run_rwops = 0;
145 break;
146
147 /* No surface. */
148 case 's':
149 run_surface = 0;
150 break;
151
152 /* No render. */
153 case 'r':
154 run_render = 0;
155 break;
156
157 /* No audio. */
158 case 'a':
159 run_audio = 0;
160 break;
161
112 /* Verbosity. */ 162 /* Verbosity. */
113 case 'v': 163 case 'v':
114 SDL_ATgeti( SDL_AT_VERBOSE, &i ); 164 SDL_ATgeti( SDL_AT_VERBOSE, &i );
115 SDL_ATseti( SDL_AT_VERBOSE, i+1 ); 165 SDL_ATseti( SDL_AT_VERBOSE, i+1 );
116 break; 166 break;
124 case 'h': 174 case 'h':
125 print_usage( argv[0] ); 175 print_usage( argv[0] );
126 exit(EXIT_SUCCESS); 176 exit(EXIT_SUCCESS);
127 } 177 }
128 } 178 }
129 179 }
130 } 180 #endif /* !NO_GETOPT_LONG */
131 181
182 #if defined(NO_GETOPT_LONG)
183 static void parse_options( int argc, char *argv[] )
184 {
185 static char* short_options="mposravqh";
186 int c = 0;
187 int i;
188
189 /* Iterate over options. */
190 while ((c = getopt(argc, argv, short_options)) != -1) {
191 /* Handle options. */
192 switch (c) {
193 /* Manual. */
194 case 'm':
195 run_manual = 1;
196 break;
197
198 /* No platform. */
199 case 'p':
200 run_platform = 0;
201 break;
202
203 /* No rwops. */
204 case 'o':
205 run_rwops = 0;
206 break;
207
208 /* No surface. */
209 case 's':
210 run_surface = 0;
211 break;
212
213 /* No render. */
214 case 'r':
215 run_render = 0;
216 break;
217
218 /* No audio. */
219 case 'a':
220 run_audio = 0;
221 break;
222
223 /* Verbosity. */
224 case 'v':
225 SDL_ATgeti( SDL_AT_VERBOSE, &i );
226 SDL_ATseti( SDL_AT_VERBOSE, i+1 );
227 break;
228
229 /* Quiet. */
230 case 'q':
231 SDL_ATseti( SDL_AT_QUIET, 1 );
232 break;
233
234 /* Help. */
235 case 'h':
236 print_usage( argv[0] );
237 exit(EXIT_SUCCESS);
238 }
239 }
240 }
241 #endif /* NO_GETOPT_LONG */
132 242
133 /** 243 /**
134 * @brief Main entry point. 244 * @brief Main entry point.
135 */ 245 */
136 int main( int argc, char *argv[] ) 246 int main( int argc, char *argv[] )