src/unix.cpp
author rubidium
Wed, 07 Mar 2007 11:47:46 +0000
changeset 6247 7d81e3a5d803
parent 6240 9d9874ef9f0b
child 6298 01c80746f308
permissions -rw-r--r--
(svn r9050) -Codechange: Foo(void) -> Foo()
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2177
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2177
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1892
8717d92b32b1 (svn r2398) - CodeChange: forgot to update unix and os2 specific files as well.
Darkvater
parents: 1885
diff changeset
     4
#include "openttd.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     5
#include "functions.h"
1390
e7cdf3ce0fb6 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
     6
#include "window.h"
1317
3c90086ff34f (svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents: 1093
diff changeset
     7
#include "string.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 437
diff changeset
     8
#include "table/strings.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2099
diff changeset
     9
#include "variables.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include <dirent.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include <unistd.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include <sys/stat.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include <time.h>
1509
795ba683e4f0 (svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents: 1508
diff changeset
    15
#include <signal.h>
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
2323
eadae7d611e7 (svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents: 2285
diff changeset
    17
#ifdef USE_HOMEDIR
eadae7d611e7 (svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents: 2285
diff changeset
    18
#include <pwd.h>
eadae7d611e7 (svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents: 2285
diff changeset
    19
#endif
eadae7d611e7 (svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents: 2285
diff changeset
    20
1850
15826a18b5ac (svn r2356) Make check if statvfs() is availible a bit more sensible
tron
parents: 1687
diff changeset
    21
#if (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__)
1597
ef6253448620 (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
    22
	#define HAS_STATVFS
ef6253448620 (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
    23
#endif
ef6253448620 (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
    24
ef6253448620 (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
    25
#ifdef HAS_STATVFS
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
#include <sys/statvfs.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
#ifdef __MORPHOS__
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
#include <exec/types.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
ULONG __stack = (1024*1024)*2; // maybe not that much is needed actually ;)
2356
43d1812406e7 (svn r2882) Some fixes for MorphOS (by tokai)
tron
parents: 2338
diff changeset
    33
43d1812406e7 (svn r2882) Some fixes for MorphOS (by tokai)
tron
parents: 2338
diff changeset
    34
// The system supplied definition of SIG_IGN does not match
43d1812406e7 (svn r2882) Some fixes for MorphOS (by tokai)
tron
parents: 2338
diff changeset
    35
#undef SIG_IGN
43d1812406e7 (svn r2882) Some fixes for MorphOS (by tokai)
tron
parents: 2338
diff changeset
    36
#define SIG_IGN (void (*)(int))1
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
#endif /* __MORPHOS__ */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
770
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 704
diff changeset
    39
#ifdef __AMIGA__
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 704
diff changeset
    40
#warning add stack symbol to avoid that user needs to set stack manually (tokai)
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 826
diff changeset
    41
// ULONG __stack =
770
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 704
diff changeset
    42
#endif
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 704
diff changeset
    43
2188
640a0a5f77ea (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents: 2186
diff changeset
    44
#if defined(__APPLE__)
2217
7a5d829eca29 (svn r2735) -Fix: [OSX] fixed issue introduced in 2733 where dedicated servers on OSX included sdl.h even when WITH_SDL was not defined (oops)
bjarni
parents: 2215
diff changeset
    45
	#if defined(WITH_SDL)
7a5d829eca29 (svn r2735) -Fix: [OSX] fixed issue introduced in 2733 where dedicated servers on OSX included sdl.h even when WITH_SDL was not defined (oops)
bjarni
parents: 2215
diff changeset
    46
		//the mac implementation needs this file included in the same file as main()
7a5d829eca29 (svn r2735) -Fix: [OSX] fixed issue introduced in 2733 where dedicated servers on OSX included sdl.h even when WITH_SDL was not defined (oops)
bjarni
parents: 2215
diff changeset
    47
		#include <SDL.h>
7a5d829eca29 (svn r2735) -Fix: [OSX] fixed issue introduced in 2733 where dedicated servers on OSX included sdl.h even when WITH_SDL was not defined (oops)
bjarni
parents: 2215
diff changeset
    48
	#endif
2188
640a0a5f77ea (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents: 2186
diff changeset
    49
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    51
bool FiosIsRoot(const char *path)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
{
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    53
#if !defined(__MORPHOS__) && !defined(__AMIGAOS__)
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    54
	return path[1] == '\0';
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    55
#else
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    56
	/* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    57
	const char *s = strchr(path, ':');
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    58
	return s[1] == '\0';
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    59
#endif
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    60
}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    61
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6240
diff changeset
    62
void FiosGetDrives()
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    63
{
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    64
	return;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    65
}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    66
4222
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    67
bool FiosGetDiskFreeSpace(const char *path, uint32 *tot)
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    68
{
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    69
	uint32 free = 0;
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    70
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    71
#ifdef HAS_STATVFS
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    72
	{
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    73
		struct statvfs s;
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    74
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    75
		if (statvfs(path, &s) != 0) return false;
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    76
		free = (uint64)s.f_frsize * s.f_bavail >> 20;
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    77
	}
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    78
#endif
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    79
	if (tot != NULL) *tot = free;
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    80
	return true;
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    81
}
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    82
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    83
bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb)
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    84
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
	char filename[MAX_PATH];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    87
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    88
	/* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    89
	if (FiosIsRoot(path)) {
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    90
		snprintf(filename, lengthof(filename), "%s:%s", path, ent->d_name);
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    91
	} else // XXX - only next line!
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    92
#endif
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    93
	snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
6240
9d9874ef9f0b (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6022
diff changeset
    95
	return stat(filename, sb) == 0;
9d9874ef9f0b (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6022
diff changeset
    96
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
6240
9d9874ef9f0b (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6022
diff changeset
    98
bool FiosIsHiddenFile(const struct dirent *ent)
9d9874ef9f0b (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6022
diff changeset
    99
{
9d9874ef9f0b (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6022
diff changeset
   100
	return ent->d_name[0] == '.';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
1050
958032fed209 (svn r1551) Silence a warning and simplify a preprocessor check
tron
parents: 1010
diff changeset
   103
#if defined(__BEOS__) || defined(__linux__)
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 307
diff changeset
   104
static void ChangeWorkingDirectory(char *exe)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
	char *s = strrchr(exe, '/');
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	if (s != NULL) {
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   108
		*s = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
		chdir(exe);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
		*s = '/';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
}
1050
958032fed209 (svn r1551) Silence a warning and simplify a preprocessor check
tron
parents: 1010
diff changeset
   113
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
void ShowInfo(const char *str)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
{
5674
abe7d6b7b1d4 (svn r8134) -Fix (r8013): Add a newline after the ShowInfo console output
Darkvater
parents: 5609
diff changeset
   117
	fprintf(stderr, "%s\n", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
void ShowOSErrorBox(const char *buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
{
2731
888a994e9fe9 (svn r3276) reverted the last two commits. OSX 10.2 kept finding new stuff to prevent it from running OpenTTD, so now it's not supported anymore
bjarni
parents: 2730
diff changeset
   122
#if defined(__APPLE__)
2188
640a0a5f77ea (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents: 2186
diff changeset
   123
	// this creates an NSAlertPanel with the contents of 'buf'
640a0a5f77ea (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents: 2186
diff changeset
   124
	// this is the native and nicest way to do this on OSX
640a0a5f77ea (svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents: 2186
diff changeset
   125
	ShowMacDialog( buf, "See readme for more info\nMost likely you are missing files from the original TTD", "Quit" );
529
39d3b5a074c4 (svn r869) Mac: finally made asserts open the console, so people should be able to see what went wrong even if they opened the game in the GUI
bjarni
parents: 507
diff changeset
   126
#else
39d3b5a074c4 (svn r869) Mac: finally made asserts open the console, so people should be able to see what went wrong even if they opened the game in the GUI
bjarni
parents: 507
diff changeset
   127
	// all systems, but OSX
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
	fprintf(stderr, "\033[1;31mError: %s\033[0;39m\n", buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
2736
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   132
#ifdef WITH_COCOA
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6240
diff changeset
   133
void cocoaSetWorkingDirectory();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6240
diff changeset
   134
void cocoaSetupAutoreleasePool();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6240
diff changeset
   135
void cocoaReleaseAutoreleasePool();
2736
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   136
#endif
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   137
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
int CDECL main(int argc, char* argv[])
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
{
2736
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   140
	int ret;
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   141
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   142
#ifdef WITH_COCOA
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   143
	cocoaSetupAutoreleasePool();
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3408
diff changeset
   144
	/* This is passed if we are launched by double-clicking */
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3408
diff changeset
   145
	if (argc >= 2 && strncmp(argv[1], "-psn", 4) == 0) {
2736
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   146
		argv[1] = NULL;
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   147
		argc = 1;
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   148
		cocoaSetWorkingDirectory();
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   149
	}
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   150
#endif
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   151
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	// change the working directory to enable doubleclicking in UIs
1050
958032fed209 (svn r1551) Silence a warning and simplify a preprocessor check
tron
parents: 1010
diff changeset
   153
#if defined(__BEOS__) || defined(__linux__)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	ChangeWorkingDirectory(argv[0]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
4369
3812b4335df9 (svn r6086) -Fix: InteractiveRandom was not seeded properly resulting in the dedicated server always generating the same map. Thanks to the #openttdcoop team for detecting.
rubidium
parents: 4300
diff changeset
   157
	_random_seeds[1][1] = _random_seeds[1][0] = _random_seeds[0][1] = _random_seeds[0][0] = time(NULL);
2073
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   158
	SeedMT(_random_seeds[0][1]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
1509
795ba683e4f0 (svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents: 1508
diff changeset
   160
	signal(SIGPIPE, SIG_IGN);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
2736
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   162
	ret = ttd_main(argc, argv);
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   163
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   164
#ifdef WITH_COCOA
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   165
	cocoaReleaseAutoreleasePool();
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   166
#endif
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   167
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   168
	return ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6240
diff changeset
   171
void DeterminePaths()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	char *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   175
	_paths.game_data_dir = MallocT<char>(MAX_PATH);
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   176
	ttd_strlcpy(_paths.game_data_dir, GAME_DATA_DIR, MAX_PATH);
561
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   177
	#if defined SECOND_DATA_DIR
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   178
	_paths.second_data_dir = MallocT<char>(MAX_PATH);
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   179
	ttd_strlcpy(_paths.second_data_dir, SECOND_DATA_DIR, MAX_PATH);
561
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   180
	#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
#if defined(USE_HOMEDIR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	{
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   184
		const char *homedir = getenv("HOME");
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   185
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   186
		if (homedir == NULL) {
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   187
			const struct passwd *pw = getpwuid(getuid());
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   188
			if (pw != NULL) homedir = pw->pw_dir;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   190
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   191
		_paths.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   193
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
#else /* not defined(USE_HOMEDIR) */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   196
	_paths.personal_dir = MallocT<char>(MAX_PATH);
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   197
	ttd_strlcpy(_paths.personal_dir, PERSONAL_DIR, MAX_PATH);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   198
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	// check if absolute or relative path
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   200
	s = strchr(_paths.personal_dir, '/');
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   201
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	// add absolute path
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   203
	if (s == NULL || _paths.personal_dir != s) {
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   204
		getcwd(_paths.personal_dir, MAX_PATH);
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   205
		s = strchr(_paths.personal_dir, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
		*s++ = '/';
561
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   207
		ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   209
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
#endif /* defined(USE_HOMEDIR) */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   212
	s = strchr(_paths.personal_dir, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   213
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
	// append a / ?
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   215
	if (s[-1] != '/') strcpy(s, "/");
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   216
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   217
	_paths.save_dir = str_fmt("%ssave", _paths.personal_dir);
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   218
	_paths.autosave_dir = str_fmt("%s/autosave", _paths.save_dir);
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   219
	_paths.scenario_dir = str_fmt("%sscenario", _paths.personal_dir);
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   220
	_paths.heightmap_dir = str_fmt("%sscenario/heightmap", _paths.personal_dir);
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   221
	_paths.gm_dir = str_fmt("%sgm/", _paths.game_data_dir);
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   222
	_paths.data_dir = str_fmt("%sdata/", _paths.game_data_dir);
1482
80e315adc3bd (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1470
diff changeset
   223
80e315adc3bd (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1470
diff changeset
   224
	if (_config_file == NULL)
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   225
		_config_file = str_fmt("%sopenttd.cfg", _paths.personal_dir);
1482
80e315adc3bd (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1470
diff changeset
   226
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   227
	_highscore_file = str_fmt("%shs.dat", _paths.personal_dir);
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   228
	_log_file = str_fmt("%sopenttd.log", _paths.personal_dir);
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 826
diff changeset
   229
561
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   230
#if defined CUSTOM_LANG_DIR
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   231
	// sets the search path for lng files to the custom one
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   232
	_paths.lang_dir = MallocT<char>(MAX_PATH);
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   233
	ttd_strlcpy( _paths.lang_dir, CUSTOM_LANG_DIR, MAX_PATH);
561
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   234
#else
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   235
	_paths.lang_dir = str_fmt("%slang/", _paths.game_data_dir);
561
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   236
#endif
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   237
238
a73a3e50c7f9 (svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents: 223
diff changeset
   238
	// create necessary folders
5296
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   239
	mkdir(_paths.personal_dir, 0755);
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   240
	mkdir(_paths.save_dir, 0755);
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   241
	mkdir(_paths.autosave_dir, 0755);
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   242
	mkdir(_paths.scenario_dir, 0755);
e7acddfdd8a7 (svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents: 5108
diff changeset
   243
	mkdir(_paths.heightmap_dir, 0755);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   246
bool InsertTextBufferClipboard(Textbuf *tb)
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   247
{
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   248
	return false;
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   249
}
1885
aef601001f5e (svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents: 1850
diff changeset
   250
2073
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   251
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   252
// multi os compatible sleep function
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   253
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   254
#ifdef __AMIGA__
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   255
// usleep() implementation
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   256
#	include <devices/timer.h>
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   257
#	include <dos/dos.h>
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   258
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   259
	extern struct Device      *TimerBase    = NULL;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   260
	extern struct MsgPort     *TimerPort    = NULL;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   261
	extern struct timerequest *TimerRequest = NULL;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   262
#endif // __AMIGA__
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   263
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   264
void CSleep(int milliseconds)
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   265
{
6022
cc9e80081d01 (svn r8745) [PSP] -Add: added a CSleep() for PSP
truelight
parents: 5941
diff changeset
   266
	#if defined(PSP)
cc9e80081d01 (svn r8745) [PSP] -Add: added a CSleep() for PSP
truelight
parents: 5941
diff changeset
   267
		sceKernelDelayThread(milliseconds * 1000);
cc9e80081d01 (svn r8745) [PSP] -Add: added a CSleep() for PSP
truelight
parents: 5941
diff changeset
   268
	#elif defined(__BEOS__)
2073
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   269
		snooze(milliseconds * 1000);
6022
cc9e80081d01 (svn r8745) [PSP] -Add: added a CSleep() for PSP
truelight
parents: 5941
diff changeset
   270
	#elif defined(__AMIGA__)
2073
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   271
	{
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   272
		ULONG signals;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   273
		ULONG TimerSigBit = 1 << TimerPort->mp_SigBit;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   274
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   275
		// send IORequest
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   276
		TimerRequest->tr_node.io_Command = TR_ADDREQUEST;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   277
		TimerRequest->tr_time.tv_secs    = (milliseconds * 1000) / 1000000;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   278
		TimerRequest->tr_time.tv_micro   = (milliseconds * 1000) % 1000000;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   279
		SendIO((struct IORequest *)TimerRequest);
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   280
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   281
		if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) {
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   282
			AbortIO((struct IORequest *)TimerRequest);
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   283
		}
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   284
		WaitIO((struct IORequest *)TimerRequest);
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   285
	}
6022
cc9e80081d01 (svn r8745) [PSP] -Add: added a CSleep() for PSP
truelight
parents: 5941
diff changeset
   286
	#else
cc9e80081d01 (svn r8745) [PSP] -Add: added a CSleep() for PSP
truelight
parents: 5941
diff changeset
   287
		usleep(milliseconds * 1000);
cc9e80081d01 (svn r8745) [PSP] -Add: added a CSleep() for PSP
truelight
parents: 5941
diff changeset
   288
	#endif
2073
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   289
}
3260
ed19f95eb4f7 (svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents: 2952
diff changeset
   290
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   291
#ifdef WITH_ICONV
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   292
3332
7a671549da48 (svn r4109) - Fix (r4105) [iconv]: Only include the needed headers when ICONV is actually used. Thanks for noticing Bjarni
Darkvater
parents: 3330
diff changeset
   293
#include <iconv.h>
7a671549da48 (svn r4109) - Fix (r4105) [iconv]: Only include the needed headers when ICONV is actually used. Thanks for noticing Bjarni
Darkvater
parents: 3330
diff changeset
   294
#include <errno.h>
7a671549da48 (svn r4109) - Fix (r4105) [iconv]: Only include the needed headers when ICONV is actually used. Thanks for noticing Bjarni
Darkvater
parents: 3330
diff changeset
   295
#include "debug.h"
7a671549da48 (svn r4109) - Fix (r4105) [iconv]: Only include the needed headers when ICONV is actually used. Thanks for noticing Bjarni
Darkvater
parents: 3330
diff changeset
   296
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4369
diff changeset
   297
#define INTERNALCODE "UTF-8"
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   298
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   299
/** Try and try to decipher the current locale from environmental
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   300
 * variables. MacOSX is hardcoded, other OS's are dynamic. If no suitable
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   301
 * locale can be found, don't do any conversion "" */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6240
diff changeset
   302
static const char *GetLocalCode()
3260
ed19f95eb4f7 (svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents: 2952
diff changeset
   303
{
3408
1da501b2eae1 (svn r4219) - Add support for WITH_ICONV. It is enabled by default for OSX > 10.3 for all others set it with WITH_ICONV in Makefile.config or with --with-iconv with configure. --with-config=/somedir will search for iconv include files somewhere (or in Makefile.config with WITH_ICONV_PATH). Custom library loading is not (yet) supported
Darkvater
parents: 3332
diff changeset
   304
#if defined(__APPLE__)
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   305
	return "UTF-8-MAC";
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   306
#else
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   307
	/* Strip locale (eg en_US.UTF-8) to only have UTF-8 */
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   308
	const char *locale = GetCurrentLocale("LC_CTYPE");
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   309
	if (locale != NULL) locale = strchr(locale, '.');
3260
ed19f95eb4f7 (svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents: 2952
diff changeset
   310
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   311
	return (locale == NULL) ? "" : locale + 1;
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   312
#endif
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   313
}
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   314
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   315
/** FYI: This is not thread-safe.
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   316
 * convert between locales, which from and which to is set in the calling
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   317
 * functions OTTD2FS() and FS2OTTD(). You should NOT use this function directly
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   318
 * NOTE: iconv was added in OSX 10.3. 10.2.x will still have the invalid char
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   319
 * issues. There aren't any easy fix for this */
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   320
static const char *convert_tofrom_fs(iconv_t convd, const char *name)
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   321
{
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   322
	static char buf[1024];
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   323
	/* Work around buggy iconv implementation where inbuf is wrongly typed as
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   324
	 * non-const. Correct implementation is at
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   325
	 * http://www.opengroup.org/onlinepubs/007908799/xsh/iconv.html */
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   326
#if defined (__GLIBC__) || defined (__GNU_LIBRARY__)
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   327
	char *inbuf = (char*)name;
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   328
#else
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   329
	const char *inbuf = name;
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   330
#endif
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   331
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   332
	char *outbuf  = buf;
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   333
	size_t outlen = sizeof(buf) - 1;
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   334
	size_t inlen  = strlen(name);
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   335
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   336
	ttd_strlcpy(outbuf, name, sizeof(buf));
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   337
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   338
	iconv(convd, NULL, NULL, NULL, NULL);
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   339
	if (iconv(convd, &inbuf, &inlen, &outbuf, &outlen) == (size_t)(-1)) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5296
diff changeset
   340
		DEBUG(misc, 0, "[iconv] error converting '%s'. Errno %d", name, errno);
3260
ed19f95eb4f7 (svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents: 2952
diff changeset
   341
	}
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   342
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   343
	*outbuf = '\0';
3260
ed19f95eb4f7 (svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents: 2952
diff changeset
   344
	// FIX: invalid characters will abort conversion, but they shouldn't occur?
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   345
	return buf;
3260
ed19f95eb4f7 (svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents: 2952
diff changeset
   346
}
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   347
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   348
/** Convert from OpenTTD's encoding to that of the local environment
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   349
 * @param name pointer to a valid string that will be converted
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   350
 * @return pointer to a new stringbuffer that contains the converted string */
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   351
const char *OTTD2FS(const char *name)
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   352
{
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   353
	static iconv_t convd = (iconv_t)(-1);
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   354
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   355
	if (convd == (iconv_t)(-1)) {
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   356
		const char *env = GetLocalCode();
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   357
		convd = iconv_open(env, INTERNALCODE);
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   358
		if (convd == (iconv_t)(-1)) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5296
diff changeset
   359
			DEBUG(misc, 0, "[iconv] conversion from codeset '%s' to '%s' unsupported", INTERNALCODE, env);
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   360
			return name;
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   361
		}
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   362
	}
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   363
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   364
	return convert_tofrom_fs(convd, name);
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   365
}
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   366
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   367
/** Convert to OpenTTD's encoding from that of the local environment
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   368
 * @param name pointer to a valid string that will be converted
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   369
 * @return pointer to a new stringbuffer that contains the converted string */
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   370
const char *FS2OTTD(const char *name)
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   371
{
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   372
	static iconv_t convd = (iconv_t)(-1);
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   373
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   374
	if (convd == (iconv_t)(-1)) {
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   375
		const char *env = GetLocalCode();
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   376
		convd = iconv_open(INTERNALCODE, env);
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   377
		if (convd == (iconv_t)(-1)) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5296
diff changeset
   378
			DEBUG(misc, 0, "[iconv] conversion from codeset '%s' to '%s' unsupported", env, INTERNALCODE);
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   379
			return name;
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   380
		}
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   381
	}
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   382
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   383
	return convert_tofrom_fs(convd, name);
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   384
}
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   385
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   386
#else
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   387
const char *FS2OTTD(const char *name) {return name;}
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   388
const char *OTTD2FS(const char *name) {return name;}
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3294
diff changeset
   389
#endif /* WITH_ICONV */