Remove static label from game functions
[kraptor.git] / src / filedata.c
blob73d7a203dd69577657a0754cbbdb4e24137197e5
1 // --------------------------------------------------------
2 // filedata.c
3 // --------------------------------------------------------
4 // Copyright (c) Kronoman
5 // En memoria de mi querido padre
6 // --------------------------------------------------------
7 // This file is used as a wrapper for load_datafile and other similar
8 // I use this for reach the datafile searching in common paths
9 // Is specially useful for datafiles in Windows, because most
10 // of the time Windows don't start the program in the executable path,
11 // and the program is unable to find the datafile.
12 // --------------------------------------------------------
14 #include <allegro.h>
15 #include <stdio.h>
16 #include "filedata.h"
17 // --------------------------------------------------------
18 // This checks for the filename in several places.
19 // Returns where the filename is located in buffer
20 // buffer should be a 2048 bytes char
21 // If the file is not found, return the filename...
22 // --------------------------------------------------------
23 char *where_is_the_filename(char *buffer, const char *filename)
25 char str[2048], str2[2048]; // buffer for path making
27 // check in current executable path
28 get_executable_name(str, 2048);
29 replace_filename(str2, str, filename, 2048);
31 if (! exists(filename) )
33 if (exists(str2))
35 sprintf(buffer,"%s", str2);
36 return buffer;
38 else
40 get_executable_name(str, 2048);
41 replace_filename(str, str, "", 2048);
42 if (! find_allegro_resource(str2, filename, get_extension(filename), NULL, NULL, NULL, str, 2048) )
44 sprintf(buffer,"%s", str2);
45 return buffer;
50 // default
51 sprintf(buffer,"%s", filename);
52 return buffer;
55 // --------------------------------------------------------
56 // This functions is a wrapper of load_datafile
57 // Just pass a file name (without path), and this will try to seach and load it
58 // Will return a pointer to the DATAFILE or NULL if error.
59 // --------------------------------------------------------
60 DATAFILE *krono_load_datafile(const char *filename)
62 char str[2048];
64 return load_datafile(where_is_the_filename(str, filename)); // return what we found...
68 DATAFILE *krono_load_datafile_callback(const char *filename, void (*callback)(DATAFILE *d))
70 char str[2048];
72 return load_datafile_callback(where_is_the_filename(str, filename), callback); // return what we found...
75 DATAFILE *krono_load_datafile_object(const char *filename, const char *objectname)
77 char str[2048];
79 return load_datafile_object(where_is_the_filename(str, filename), objectname); // return what we found...