~ubuntu-branches/debian/squeeze/simutrans/squeeze

« back to all changes in this revision

Viewing changes to simsys_posix.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ansgar Burchardt
  • Date: 2009-10-18 15:29:14 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091018152914-ip7am3dx1tl27uyb
Tags: 102.2+svn2786-1
* New upstream release.
  + Refresh patches.
  + Update translations.
* debian/rules: Add get-orig-source target.
* debian/rules: Add update-translations target.
* debian/README.source: Document get-orig-source and update-translations
  targets.
* Bump Standards-Version to 3.8.3 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 1997 - 2001 Hansj�rg Malthaner
 
3
 *
 
4
 * This file is part of the Simutrans project under the artistic licence.
 
5
 */
 
6
 
 
7
#include <SDL/SDL.h>
 
8
 
 
9
#ifndef _MSC_VER
 
10
#include <unistd.h>
 
11
#include <sys/time.h>
 
12
#endif
 
13
 
 
14
#ifdef _WIN32
 
15
#include <SDL/SDL_syswm.h>
 
16
#include <windows.h>
 
17
#else
 
18
#include <sys/stat.h>
 
19
#include <sys/errno.h>
 
20
#endif
 
21
 
 
22
#include <dirent.h>
 
23
#include <stdio.h>
 
24
#include <stddef.h>
 
25
#include <string.h>
 
26
#include <stdlib.h>
 
27
#include <math.h>
 
28
 
 
29
#ifndef PATH_MAX
 
30
#define PATH_MAX (1024)
 
31
#endif
 
32
 
 
33
#undef min
 
34
#undef max
 
35
 
 
36
#include "macros.h"
 
37
#include "simmain.h"
 
38
#include "simsys.h"
 
39
 
 
40
#include <time.h>
 
41
 
 
42
struct sys_event sys_event;
 
43
 
 
44
int dr_os_init(const int*)
 
45
{
 
46
        // prepare for next event
 
47
        sys_event.type = SIM_NOEVENT;
 
48
        sys_event.code = 0;
 
49
        return TRUE;
 
50
}
 
51
 
 
52
int dr_query_screen_width()
 
53
{
 
54
        return 0;
 
55
}
 
56
 
 
57
int dr_query_screen_height()
 
58
{
 
59
        return 0;
 
60
}
 
61
 
 
62
// open the window
 
63
int dr_os_open(int, int, int, int)
 
64
{
 
65
        return TRUE;
 
66
}
 
67
 
 
68
// shut down SDL
 
69
int dr_os_close(void)
 
70
{
 
71
        return TRUE;
 
72
}
 
73
 
 
74
// reiszes screen
 
75
int dr_textur_resize(unsigned short** textur, int, int, int)
 
76
{
 
77
        *textur = NULL;
 
78
        return 1;
 
79
}
 
80
 
 
81
// query home directory
 
82
char *dr_query_homedir(void)
 
83
{
 
84
        static char buffer[PATH_MAX];
 
85
        char b2[PATH_MAX];
 
86
#ifdef _WIN32
 
87
        DWORD len=PATH_MAX-24;
 
88
        HKEY hHomeDir;
 
89
        if(RegOpenKeyExA(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", 0, KEY_READ, &hHomeDir)==ERROR_SUCCESS) {
 
90
                RegQueryValueExA(hHomeDir,"Personal",NULL,NULL,(BYTE *)buffer,&len);
 
91
                strcat(buffer,"\\Simutrans");
 
92
                CreateDirectoryA( buffer, NULL);
 
93
                strcat(buffer, "\\");
 
94
 
 
95
                // create other subdirectories
 
96
                sprintf(b2, "%ssave", buffer );
 
97
                CreateDirectoryA( b2, NULL );
 
98
                sprintf(b2, "%sscreenshot", buffer );
 
99
                CreateDirectoryA( b2, NULL );
 
100
                sprintf(b2, "%smaps", buffer );
 
101
                CreateDirectoryA( b2, NULL );
 
102
 
 
103
                return buffer;
 
104
        }
 
105
        return NULL;
 
106
#else
 
107
#ifndef __MACOS__
 
108
        sprintf( buffer, "%s/simutrans", getenv("HOME") );
 
109
#else
 
110
        sprintf( buffer, "%s/Documents/simutrans", getenv("HOME") );
 
111
#endif
 
112
        int err = mkdir( buffer, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
 
113
        if(err  &&  err!=EEXIST) {
 
114
                // could not create directory
 
115
                // we assume success anyway
 
116
        }
 
117
        strcat( buffer, "/" );
 
118
        sprintf( b2, "%smaps", buffer );
 
119
        mkdir( b2, 0700 );
 
120
        sprintf( b2, "%sscreenshot", buffer );
 
121
        mkdir( b2, 0700 );
 
122
        sprintf( b2, "%ssave", buffer );
 
123
        mkdir( b2, 0700 );
 
124
        return buffer;
 
125
#endif
 
126
}
 
127
 
 
128
unsigned short *dr_textur_init()
 
129
{
 
130
        return NULL;
 
131
}
 
132
 
 
133
unsigned int get_system_color(unsigned int, unsigned int, unsigned int)
 
134
{
 
135
        return 1;
 
136
}
 
137
 
 
138
void dr_setRGB8multi(int, int, unsigned char*)
 
139
{
 
140
}
 
141
 
 
142
void dr_prepare_flush()
 
143
{
 
144
}
 
145
 
 
146
void dr_flush(void)
 
147
{
 
148
}
 
149
 
 
150
void dr_textur(int, int, int, int)
 
151
{
 
152
}
 
153
 
 
154
void move_pointer(int, int)
 
155
{
 
156
}
 
157
 
 
158
void set_pointer(int)
 
159
{
 
160
}
 
161
 
 
162
int dr_screenshot(const char *)
 
163
{
 
164
        return -1;
 
165
}
 
166
 
 
167
static inline unsigned int ModifierKeys(void)
 
168
{
 
169
        return 0;
 
170
}
 
171
 
 
172
void GetEvents(void)
 
173
{
 
174
}
 
175
 
 
176
void GetEventsNoWait(void)
 
177
{
 
178
}
 
179
 
 
180
void show_pointer(int)
 
181
{
 
182
}
 
183
 
 
184
void ex_ord_update_mx_my()
 
185
{
 
186
}
 
187
 
 
188
unsigned long dr_time(void)
 
189
{
 
190
        return time(NULL);
 
191
}
 
192
 
 
193
void dr_sleep(uint32 usec)
 
194
{
 
195
        timespec sleepfor, zero;
 
196
        sleepfor.tv_sec = usec/1000;
 
197
        usec = usec % 1000;
 
198
        sleepfor.tv_nsec = 1000 * usec;
 
199
        nanosleep( &sleepfor, &zero);
 
200
}
 
201
 
 
202
bool dr_fatal_notify(const char* msg, int choices)
 
203
{
 
204
        fputs(msg, stderr);
 
205
        return choices;
 
206
}
 
207
 
 
208
int main(int argc, char **argv)
 
209
{
 
210
#ifndef __BEOS__
 
211
#       if defined __GLIBC__
 
212
        /* glibc has a non-standard extension */
 
213
        char* buffer2 = NULL;
 
214
#       else
 
215
        char buffer2[PATH_MAX];
 
216
#       endif
 
217
        char buffer[PATH_MAX];
 
218
        int length = readlink("/proc/self/exe", buffer, lengthof(buffer) - 1);
 
219
        if (length != -1) {
 
220
                buffer[length] = '\0'; /* readlink() does not NUL-terminate */
 
221
                argv[0] = buffer;
 
222
        }
 
223
        // no process file system => need to parse argv[0]
 
224
        /* should work on most unix or gnu systems */
 
225
        argv[0] = realpath(argv[0], buffer2);
 
226
#endif
 
227
        return simu_main(argc, argv);
 
228
}