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