1
2 #ifndef _load_h
3 #define _load_h
4
5 #include <stdlib.h>
6 #include <string.h>
7 #ifdef WIN32 // For access() prototype
8 #include <io.h>
9 #define F_OK 0
10 #define access _access
11 #else
12 #ifdef macintosh
strdup(const char * str)13 static inline char *strdup(const char *str)
14 {
15 char *newstr;
16
17 newstr = (char *)malloc(strlen(str)+1);
18 if ( newstr ) {
19 strcpy(newstr, str);
20 }
21 return(newstr);
22 }
23 #endif
24 #if defined(unix) || defined(__MACH__) || defined(__BEOS__)
25 #include <unistd.h>
26 #endif
27 #endif /* WIN32 */
28
29 #include "SDL_FrameBuf.h"
30
31 /* Pathing stuff for the different operating systems */
32 #if defined(unix) || defined(__MACH__)
33 #define DIR_SEP "/"
34 #define CUR_DIR "."
35 #elif defined(WIN32)
36 #define DIR_SEP "/"
37 #define CUR_DIR "."
38 #elif defined(__BEOS__)
39 #define DIR_SEP "/"
40 #define CUR_DIR "."
41 #elif defined(macintosh)
42 #define DIR_SEP ":"
43 #define CUR_DIR ":"
44 #else
45 #error Unspecified platform!
46 #endif /* Choose your platform */
47
48 #ifndef LIBDIR
49 #if defined(unix) || defined(__MACH__)
50 #define LIBDIR "/usr/local/lib/Maelstrom"
51 #else
52 #define LIBDIR CUR_DIR
53 #endif
54 #endif /* !defined(LIBDIR) */
55
56 class LibPath {
57
58 private:
59 static char *exepath;
60
61 public:
SetExePath(const char * exe)62 static void SetExePath(const char *exe) {
63 char *exep;
64
65 exepath = strdup(exe);
66 for ( exep = exepath+strlen(exe); exep > exepath; --exep ) {
67 if ( (*exep == *DIR_SEP) || (*exep == '\\') ) {
68 break;
69 }
70 }
71 if ( exep > exepath ) {
72 *exep = '\0';
73 } else {
74 strcpy(exepath, CUR_DIR);
75 }
76 }
77
78 public:
LibPath()79 LibPath() {
80 path = NULL;
81 }
LibPath(char * file)82 LibPath(char *file) {
83 path = NULL;
84 Path(file);
85 }
~LibPath()86 ~LibPath() {
87 if ( path ) delete[] path;
88 }
89
Path(const char * filename)90 const char *Path(const char *filename) {
91 char *directory;
92
93 directory = getenv("MAELSTROM_LIB");
94 if ( directory == NULL ) {
95 directory = LIBDIR;
96 #ifndef macintosh
97 if ( access(directory, F_OK) < 0 ) {
98 directory = exepath;
99 }
100 #endif
101 }
102
103 if ( path != NULL )
104 delete[] path;
105 path = new char[strlen(directory)+1+strlen(filename)+1];
106 if ( strcmp(directory, DIR_SEP) == 0 ) {
107 sprintf(path, DIR_SEP"%s", filename);
108 } else {
109 sprintf(path, "%s"DIR_SEP"%s", directory, filename);
110 }
111 return(path);
112 }
Path(void)113 const char *Path(void) {
114 return(path);
115 }
116
117 private:
118 char *path;
119 };
120
121 /* Functions exported from load.cc */
122 extern SDL_Surface *Load_Icon(char **xpm);
123 extern SDL_Surface *Load_Title(FrameBuf *screen, int title_id);
124 extern SDL_Surface *GetCIcon(FrameBuf *screen, short cicn_id);
125
126 #endif /* _load_h */
127