| 1 | #cxx . . $ `<file>/src/files.cpp`/include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <SDL/SDL.h> |
| 4 | #include <SDL/SDL_image.h> |
| 5 | #include "files.h"cxx . . $ `<file>/src/files.h`/ |
| 6 | |
| 7 | static char *data_dircxx . . $ data_dir. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 8 | |
| 9 | // Find a file's full path based on the name of a file |
| 10 | char *Find_Data_Filecxx . . $ Find_Data_File(7a9722d75b371431).(char *filename) |
| 11 | { |
| 12 | char *location; |
| 13 | FILE *my_file; |
| 14 | |
| 15 | location = (char *) calloccxx . . $ calloc(95acc9b79bb49189).( strlen(filename) + 64, sizeof(char) ); |
| 16 | if (! location) |
| 17 | return filename; |
| 18 | |
| 19 | // maybe we already know the directory and don't have to search |
| 20 | if (data_dircxx . . $ data_dir.) |
| 21 | { |
| 22 | sprintf(location, "%s/%s", data_dircxx . . $ data_dir., filename); |
| 23 | return location; |
| 24 | } |
| 25 | |
| 26 | sprintf(location, "%s/%s", DATADIRcxx . . $ `<built-in>:487:9`!, filename); |
| 27 | my_file = fopen(location, "r"); |
| 28 | if (my_file) |
| 29 | { |
| 30 | fclose(my_file); |
| 31 | data_dircxx . . $ data_dir. = DATADIRcxx . . $ `<built-in>:487:9`!; |
| 32 | return location; |
| 33 | } |
| 34 | |
| 35 | /* |
| 36 | This is the old way of guessing one location at a time. Now we |
| 37 | can use the DATADIR definition to make sure we check the correct |
| 38 | place. |
| 39 | |
| 40 | sprintf(location, "/usr/local/share/games/openssn/%s", filename); |
| 41 | my_file = fopen(location, "r"); |
| 42 | if (my_file) |
| 43 | { |
| 44 | fclose(my_file); |
| 45 | data_dir = "/usr/local/share/games/openssn"; |
| 46 | return location; |
| 47 | } |
| 48 | |
| 49 | sprintf(location, "/usr/share/games/openssn/%s", filename); |
| 50 | my_file = fopen(location, "r"); |
| 51 | if (my_file) |
| 52 | { |
| 53 | fclose(my_file); |
| 54 | data_dir = "/usr/share/games/openssn"; |
| 55 | return location; |
| 56 | } |
| 57 | */ |
| 58 | |
| 59 | // last chance, try OPTDIR |
| 60 | sprintf(location, "%s/%s", OPTDIRcxx . . $ `<built-in>:488:9`!, filename); |
| 61 | my_file = fopen(location, "r"); |
| 62 | if (my_file) |
| 63 | { |
| 64 | fclose(my_file); |
| 65 | data_dircxx . . $ data_dir. = OPTDIRcxx . . $ `<built-in>:488:9`!; |
| 66 | return location; |
| 67 | } |
| 68 | data_dircxx . . $ data_dir. = "."; |
| 69 | return filename; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | SDL_Surface *Load_Imagecxx . . $ Load_Image(ad2755de9658a3fe).(char *filename) |
| 74 | { |
| 75 | char *file_name; |
| 76 | SDL_Surface *my_image = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 77 | |
| 78 | file_name = Find_Data_Filecxx . . $ Find_Data_File(7a9722d75b371431).(filename); |
| 79 | if (file_name) |
| 80 | my_image = IMG_Load(file_name); |
| 81 | if ( (file_name) && (file_name != filename) ) |
| 82 | freecxx . . $ free(bd21765a0afc8e3c).(file_name); |
| 83 | return my_image; |
| 84 | |
| 85 | } |
| 86 | |
| 87 |