Mercurial > sdl-ios-xcode
comparison test/testloadso.c @ 2120:2c835d58faad
make indent
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 14 Jun 2007 13:21:29 +0000 |
parents | f16a7d02a176 |
children | 9de326b3099c |
comparison
equal
deleted
inserted
replaced
2119:9341a884a4d9 | 2120:2c835d58faad |
---|---|
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 | 7 |
8 #include "SDL.h" | 8 #include "SDL.h" |
9 | 9 |
10 typedef int (*fntype)(const char *); | 10 typedef int (*fntype) (const char *); |
11 | 11 |
12 int main(int argc, char *argv[]) | 12 int |
13 main(int argc, char *argv[]) | |
13 { | 14 { |
14 int retval = 0; | 15 int retval = 0; |
15 int hello = 0; | 16 int hello = 0; |
16 const char *libname = NULL; | 17 const char *libname = NULL; |
17 const char *symname = NULL; | 18 const char *symname = NULL; |
18 void *lib = NULL; | 19 void *lib = NULL; |
19 fntype fn = NULL; | 20 fntype fn = NULL; |
20 | 21 |
21 if (argc != 3) { | 22 if (argc != 3) { |
22 const char *app = argv[0]; | 23 const char *app = argv[0]; |
23 fprintf(stderr, "USAGE: %s <library> <functionname>\n", app); | 24 fprintf(stderr, "USAGE: %s <library> <functionname>\n", app); |
24 fprintf(stderr, " %s --hello <lib with puts()>\n", app); | 25 fprintf(stderr, " %s --hello <lib with puts()>\n", app); |
25 return 1; | 26 return 1; |
26 } | 27 } |
27 | 28 |
28 /* Initialize SDL */ | 29 /* Initialize SDL */ |
29 if ( SDL_Init(0) < 0 ) { | 30 if (SDL_Init(0) < 0) { |
30 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | 31 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
31 return 2; | 32 return 2; |
32 } | 33 } |
33 | 34 |
34 if (strcmp(argv[1], "--hello") == 0) { | 35 if (strcmp(argv[1], "--hello") == 0) { |
35 hello = 1; | 36 hello = 1; |
36 libname = argv[2]; | 37 libname = argv[2]; |
37 symname = "puts"; | 38 symname = "puts"; |
38 } else { | 39 } else { |
39 libname = argv[1]; | 40 libname = argv[1]; |
40 symname = argv[2]; | 41 symname = argv[2]; |
41 } | 42 } |
42 | 43 |
43 lib = SDL_LoadObject(libname); | 44 lib = SDL_LoadObject(libname); |
44 if (lib == NULL) { | 45 if (lib == NULL) { |
45 fprintf(stderr, "SDL_LoadObject('%s') failed: %s\n", | 46 fprintf(stderr, "SDL_LoadObject('%s') failed: %s\n", |
46 libname, SDL_GetError()); | 47 libname, SDL_GetError()); |
47 retval = 3; | 48 retval = 3; |
48 } else { | 49 } else { |
49 fn = (fntype) SDL_LoadFunction(lib, symname); | 50 fn = (fntype) SDL_LoadFunction(lib, symname); |
50 if (fn == NULL) { | 51 if (fn == NULL) { |
51 fprintf(stderr, "SDL_LoadFunction('%s') failed: %s\n", | 52 fprintf(stderr, "SDL_LoadFunction('%s') failed: %s\n", |
52 symname, SDL_GetError()); | 53 symname, SDL_GetError()); |
53 retval = 4; | 54 retval = 4; |
54 } else { | 55 } else { |
55 printf("Found %s in %s at %p\n", symname, libname, fn); | 56 printf("Found %s in %s at %p\n", symname, libname, fn); |
56 if (hello) { | 57 if (hello) { |
57 printf("Calling function...\n"); | 58 printf("Calling function...\n"); |
58 fflush(stdout); | 59 fflush(stdout); |
59 fn(" HELLO, WORLD!\n"); | 60 fn(" HELLO, WORLD!\n"); |
60 printf("...apparently, we survived. :)\n"); | 61 printf("...apparently, we survived. :)\n"); |
61 printf("Unloading library...\n"); | 62 printf("Unloading library...\n"); |
62 fflush(stdout); | 63 fflush(stdout); |
63 } | 64 } |
64 } | 65 } |
65 SDL_UnloadObject(lib); | 66 SDL_UnloadObject(lib); |
66 } | 67 } |
67 SDL_Quit(); | 68 SDL_Quit(); |
68 return(0); | 69 return (0); |
69 } | 70 } |
70 | |
71 |