unix.c
author Darkvater
Mon, 31 Jul 2006 22:40:55 +0000
changeset 4204 3aa39be759f2
parent 4134 cfcb0c8b78f6
child 4219 72768a8f3a97
permissions -rw-r--r--
(svn r5688) - Forward-port the release-changes from the 0.4 branch back to trunk. This ensures an updated changelog, known-bugs, etc.
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"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "hal.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2099
diff changeset
    10
#include "variables.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include <dirent.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include <unistd.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include <sys/stat.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include <time.h>
1509
795ba683e4f0 (svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents: 1508
diff changeset
    16
#include <signal.h>
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
2323
eadae7d611e7 (svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents: 2285
diff changeset
    18
#ifdef USE_HOMEDIR
eadae7d611e7 (svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents: 2285
diff changeset
    19
#include <pwd.h>
eadae7d611e7 (svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents: 2285
diff changeset
    20
#endif
eadae7d611e7 (svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents: 2285
diff changeset
    21
1850
15826a18b5ac (svn r2356) Make check if statvfs() is availible a bit more sensible
tron
parents: 1687
diff changeset
    22
#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
    23
	#define HAS_STATVFS
ef6253448620 (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
    24
#endif
ef6253448620 (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
    25
ef6253448620 (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
    26
#ifdef HAS_STATVFS
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
#include <sys/statvfs.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
#endif
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
#ifdef __MORPHOS__
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
#include <exec/types.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
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
    34
43d1812406e7 (svn r2882) Some fixes for MorphOS (by tokai)
tron
parents: 2338
diff changeset
    35
// The system supplied definition of SIG_IGN does not match
43d1812406e7 (svn r2882) Some fixes for MorphOS (by tokai)
tron
parents: 2338
diff changeset
    36
#undef SIG_IGN
43d1812406e7 (svn r2882) Some fixes for MorphOS (by tokai)
tron
parents: 2338
diff changeset
    37
#define SIG_IGN (void (*)(int))1
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
#endif /* __MORPHOS__ */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
770
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 704
diff changeset
    40
#ifdef __AMIGA__
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 704
diff changeset
    41
#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
    42
// ULONG __stack =
770
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 704
diff changeset
    43
#endif
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 704
diff changeset
    44
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
    45
#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
    46
	#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
    47
		//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
    48
		#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
    49
	#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
    50
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
static char *_fios_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
static char *_fios_save_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
static char *_fios_scn_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
static FiosItem *_fios_items;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
static int _fios_count, _fios_alloc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1050
diff changeset
    57
static FiosItem *FiosAlloc(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
	if (_fios_count == _fios_alloc) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
		_fios_alloc += 256;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
		_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
	return &_fios_items[_fios_count++];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    66
int compare_FiosItems(const void *a, const void *b)
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    67
{
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    68
	const FiosItem *da = (const FiosItem *)a;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    69
	const FiosItem *db = (const FiosItem *)b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
	int r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
2526
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2380
diff changeset
    72
	if (_savegame_sort_order & SORT_BY_NAME) {
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2380
diff changeset
    73
		r = strcasecmp(da->title, db->title);
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2380
diff changeset
    74
	} else {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    75
		r = da->mtime < db->mtime ? -1 : 1;
2526
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2380
diff changeset
    76
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
2526
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2380
diff changeset
    78
	if (_savegame_sort_order & SORT_DESCENDING) r = -r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
	return r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
4134
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    82
#if !defined(__MORPHOS__) && !defined(__AMIGAOS__)
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    83
#define ISROOT(__p)  (__p[1] == '\0')
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    84
#define PATHTEMPLATE "%s/%s"
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    85
#else
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    86
/*  on MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory".
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    87
 *  This is some evil magic which tries to handle this transparently w/o
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    88
 *  disturbing code with too much #ifdefs. It's not possible to switch the
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    89
 *  volume, but at least it doesn't crash :) (tokai)
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    90
 */
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    91
static bool __isroot; /* not very thread save, but will do in this case */
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    92
#define ISROOT(__p)  (__isroot = (__p[strlen(__p)-1] == ':'))
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    93
#define PATHTEMPLATE (__isroot ? "%s:%s" : "%s/%s")
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
    94
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
// Get a list of savegames
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
FiosItem *FiosGetSavegameList(int *num, int mode)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
	FiosItem *fios;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
	DIR *dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
	struct dirent *dirent;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	struct stat sb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
	int sort_start;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	char filename[MAX_PATH];
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
	if (_fios_save_path == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
		_fios_save_path = malloc(MAX_PATH);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
		strcpy(_fios_save_path, _path.save_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
2099
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
   111
	_fios_path = _fios_save_path;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   112
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	// Parent directory, only if not in root already.
4134
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   114
	if (!ISROOT(_fios_path)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
		fios = FiosAlloc();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
		fios->type = FIOS_TYPE_PARENT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
		fios->mtime = 0;
1572
cf4613ca991e (svn r2076) Set the name for the parent directory to ".."
tron
parents: 1509
diff changeset
   118
		strcpy(fios->name, "..");
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   119
		strcpy(fios->title, ".. (Parent directory)");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
	// Show subdirectories first
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   123
	dir = opendir(_fios_path);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	if (dir != NULL) {
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   125
		while ((dirent = readdir(dir)) != NULL) {
4134
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   126
			snprintf(filename, lengthof(filename), PATHTEMPLATE,
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   127
				_fios_path, dirent->d_name);
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   128
			if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) &&
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   129
					dirent->d_name[0] != '.') {
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   130
				fios = FiosAlloc();
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   131
				fios->type = FIOS_TYPE_DIR;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   132
				fios->mtime = 0;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   133
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
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
   134
				snprintf(fios->title, lengthof(fios->title), "%s/ (Directory)", FS2OTTD(dirent->d_name));
2940
2b86050d1a94 (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents: 2736
diff changeset
   135
				str_validate(fios->title);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
		closedir(dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
307
69da52d9b50f (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   141
	{
69da52d9b50f (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   142
		/* XXX ugly global variables ... */
69da52d9b50f (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   143
		byte order = _savegame_sort_order;
2526
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2380
diff changeset
   144
		_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
307
69da52d9b50f (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   145
		qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
69da52d9b50f (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   146
		_savegame_sort_order = order;
69da52d9b50f (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   147
	}
69da52d9b50f (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   148
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	// this is where to start sorting
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	sort_start = _fios_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   152
	/* Show savegame files
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   153
	 * .SAV OpenTTD saved game
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   154
	 * .SS1 Transport Tycoon Deluxe preset game
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   155
	 * .SV1 Transport Tycoon Deluxe (Patch) saved game
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   156
	 * .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	 */
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   158
	dir = opendir(_fios_path);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	if (dir != NULL) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   160
		while ((dirent = readdir(dir)) != NULL) {
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   161
			char *t;
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   162
4134
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   163
			snprintf(filename, lengthof(filename), PATHTEMPLATE,
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   164
				_fios_path, dirent->d_name);
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   165
			if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue;
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   166
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   167
			t = strrchr(dirent->d_name, '.');
2338
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   168
			if (t == NULL) continue;
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   169
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   170
			if (strcasecmp(t, ".sav") == 0) { // OpenTTD
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   171
				fios = FiosAlloc();
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   172
				fios->type = FIOS_TYPE_FILE;
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   173
				fios->mtime = sb.st_mtime;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   174
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
2099
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
   175
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
   176
				*t = '\0'; // strip extension
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
   177
				ttd_strlcpy(fios->title, FS2OTTD(dirent->d_name), lengthof(fios->title));
2940
2b86050d1a94 (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents: 2736
diff changeset
   178
				str_validate(fios->title);
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   179
			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
2338
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   180
				if (strcasecmp(t, ".ss1") == 0 ||
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   181
						strcasecmp(t, ".sv1") == 0 ||
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   182
						strcasecmp(t, ".sv2") == 0) { // TTDLX(Patch)
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   183
					fios = FiosAlloc();
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   184
					fios->type = FIOS_TYPE_OLDFILE;
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   185
					fios->mtime = sb.st_mtime;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   186
					ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   187
					GetOldSaveGameName(fios->title, filename);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
		closedir(dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   194
	qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
	*num = _fios_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
	return _fios_items;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
// Get a list of scenarios
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   200
// FIXME: Gross code duplication with FiosGetSavegameList()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
FiosItem *FiosGetScenarioList(int *num, int mode)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
	FiosItem *fios;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	DIR *dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
	struct dirent *dirent;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	struct stat sb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	int sort_start;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
	char filename[MAX_PATH];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
	if (_fios_scn_path == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
		_fios_scn_path = malloc(MAX_PATH);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
		strcpy(_fios_scn_path, _path.scenario_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
	}
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   214
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	_fios_path = _fios_scn_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   217
	// Parent directory, only if not of the type C:\.
4134
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   218
	if ((!ISROOT(_fios_path)) && mode != SLD_NEW_GAME) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   219
		fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   220
		fios->type = FIOS_TYPE_PARENT;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   221
		fios->mtime = 0;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   222
		strcpy(fios->title, ".. (Parent directory)");
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   223
	}
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   224
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
	// Show subdirectories first
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   226
	dir = opendir(_fios_path);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
	if (dir != NULL) {
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   228
		while ((dirent = readdir(dir)) != NULL) {
4134
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   229
			snprintf(filename, lengthof(filename), PATHTEMPLATE,
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   230
				_fios_path, dirent->d_name);
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   231
			if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) &&
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   232
					dirent->d_name[0] != '.') {
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   233
				fios = FiosAlloc();
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   234
				fios->type = FIOS_TYPE_DIR;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   235
				fios->mtime = 0;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   236
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
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
   237
				snprintf(fios->title, lengthof(fios->title), "%s/ (Directory)", FS2OTTD(dirent->d_name));
2940
2b86050d1a94 (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents: 2736
diff changeset
   238
				str_validate(fios->title);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
		closedir(dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   244
	{
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   245
		/* XXX ugly global variables ... */
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   246
		byte order = _savegame_sort_order;
2526
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2380
diff changeset
   247
		_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   248
		qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   249
		_savegame_sort_order = order;
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   250
	}
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   251
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
	// this is where to start sorting
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
	sort_start = _fios_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   255
	/* Show scenario files
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   256
	 * .SCN OpenTTD style scenario file
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   257
	 * .SV0 Transport Tycoon Deluxe (Patch) scenario
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   258
	 * .SS0 Transport Tycoon Deluxe preset scenario
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	 */
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   260
	dir = opendir(_fios_path);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
	if (dir != NULL) {
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   262
		while ((dirent = readdir(dir)) != NULL) {
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   263
			char *t;
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   264
4134
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   265
			snprintf(filename, lengthof(filename), PATHTEMPLATE, _fios_path, dirent->d_name);
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   266
			if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue;
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   267
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   268
			t = strrchr(dirent->d_name, '.');
2338
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   269
			if (t == NULL) continue;
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   270
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   271
			if (strcasecmp(t, ".scn") == 0) { // OpenTTD
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   272
				fios = FiosAlloc();
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   273
				fios->type = FIOS_TYPE_SCENARIO;
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   274
				fios->mtime = sb.st_mtime;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   275
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
2099
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
   276
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2323
diff changeset
   277
				*t = '\0'; // strip extension
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
   278
				ttd_strlcpy(fios->title, FS2OTTD(dirent->d_name), lengthof(fios->title));
2940
2b86050d1a94 (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents: 2736
diff changeset
   279
				str_validate(fios->title);
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   280
			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO ||
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   281
					mode == SLD_NEW_GAME) {
2338
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   282
				if (strcasecmp(t, ".sv0") == 0 ||
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   283
						strcasecmp(t, ".ss0") == 0) { // TTDLX(Patch)
1449
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   284
					fios = FiosAlloc();
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   285
					fios->type = FIOS_TYPE_OLD_SCENARIO;
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   286
					fios->mtime = sb.st_mtime;
df3ccdd9ee66 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   287
					GetOldScenarioGameName(fios->title, filename);
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   288
					ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
		closedir(dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   295
	qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	*num = _fios_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
	return _fios_items;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
// Free the list of savegames
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1050
diff changeset
   302
void FiosFreeSavegameList(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	free(_fios_items);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	_fios_items = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	_fios_alloc = _fios_count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
// Browse to
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
char *FiosBrowseTo(const FiosItem *item)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
	char *path = _fios_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	char *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   315
	switch (item->type) {
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   316
		case FIOS_TYPE_PARENT:
4134
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   317
			/* Check for possible NULL ptr (not required for UNIXes, but AmigaOS-alikes) */
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   318
			if ((s = strrchr(path, '/'))) {
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   319
				if (s != path) {
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   320
					s[0] = '\0';
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   321
				} else {
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   322
					s[1] = '\0';
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   323
				}
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3408
diff changeset
   324
			}
4134
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   325
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   326
			else {
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   327
				if ((s = strrchr(path, ':'))) {
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   328
					s[1] = '\0';
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   329
				}
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   330
			}
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   331
#endif
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   332
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   334
		case FIOS_TYPE_DIR:
4134
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   335
			if (!ISROOT(path)) strcat(path, "/");
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   336
			strcat(path, item->name);
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   337
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
2559
fe757666278c (svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents: 2526
diff changeset
   339
		case FIOS_TYPE_DIRECT:
2560
14bc4eaa3551 (svn r3097) - Fix (regression): unix has a trailing slash after the paths, windows does not, no idea why os2 has. Way to go consistency :s. So anyways, just strip trailing slash
Darkvater
parents: 2559
diff changeset
   340
			sprintf(path, "%s/", item->name);
14bc4eaa3551 (svn r3097) - Fix (regression): unix has a trailing slash after the paths, windows does not, no idea why os2 has. Way to go consistency :s. So anyways, just strip trailing slash
Darkvater
parents: 2559
diff changeset
   341
			s = strrchr(path, '/');
14bc4eaa3551 (svn r3097) - Fix (regression): unix has a trailing slash after the paths, windows does not, no idea why os2 has. Way to go consistency :s. So anyways, just strip trailing slash
Darkvater
parents: 2559
diff changeset
   342
			if (s[1] == '\0') s[0] = '\0'; // strip trailing slash
2559
fe757666278c (svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents: 2526
diff changeset
   343
			break;
fe757666278c (svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents: 2526
diff changeset
   344
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   345
		case FIOS_TYPE_FILE:
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   346
		case FIOS_TYPE_OLDFILE:
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   347
		case FIOS_TYPE_SCENARIO:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   348
		case FIOS_TYPE_OLD_SCENARIO: {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   349
			static char str_buffr[512];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   350
4134
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   351
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   352
			ISROOT(path); /* init __isroot for PATHTEMPLATE */
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   353
#endif
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   354
cfcb0c8b78f6 (svn r5491) -Fix: [#9] MorphOS crashed when you go a level up on root level (tokai)
truelight
parents: 4077
diff changeset
   355
			sprintf(str_buffr, PATHTEMPLATE, path, item->name);
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   356
			return str_buffr;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   357
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
1596
483007886b59 (svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents: 1572
diff changeset
   363
/**
483007886b59 (svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents: 1572
diff changeset
   364
 * Get descriptive texts. Returns the path and free space
483007886b59 (svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents: 1572
diff changeset
   365
 * left on the device
483007886b59 (svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents: 1572
diff changeset
   366
 * @param path string describing the path
483007886b59 (svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents: 1572
diff changeset
   367
 * @param tfs total free space in megabytes, optional (can be NULL)
483007886b59 (svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents: 1572
diff changeset
   368
 * @return StringID describing the path (free space or failure)
483007886b59 (svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents: 1572
diff changeset
   369
 */
483007886b59 (svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents: 1572
diff changeset
   370
StringID FiosGetDescText(const char **path, uint32 *tot)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
{
1596
483007886b59 (svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents: 1572
diff changeset
   372
	uint32 free = 0;
2338
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   373
	*path = _fios_path;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
1597
ef6253448620 (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
   375
#ifdef HAS_STATVFS
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
	{
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   377
		struct statvfs s;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
1597
ef6253448620 (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
   379
		if (statvfs(*path, &s) == 0) {
ef6253448620 (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
   380
			free = (uint64)s.f_frsize * s.f_bavail >> 20;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3408
diff changeset
   381
		} else {
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   382
			return STR_4006_UNABLE_TO_READ_DRIVE;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3408
diff changeset
   383
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
	}
1596
483007886b59 (svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents: 1572
diff changeset
   385
#endif
483007886b59 (svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents: 1572
diff changeset
   386
	if (tot != NULL) *tot = free;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   387
	return STR_4005_BYTES_FREE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
3287
609b5f5fdccb (svn r4001) - Add length parameter to FiosMakeSavegameName() and use this function for creating the full path instead of home-brewn snprintf.
Darkvater
parents: 3280
diff changeset
   390
void FiosMakeSavegameName(char *buf, const char *name, size_t size)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
{
1508
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   392
	const char* extension;
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   393
	const char* period;
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   394
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3408
diff changeset
   395
	extension = (_game_mode == GM_EDITOR ? ".scn" : ".sav");
1508
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   396
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   397
	// Don't append the extension, if it is already there
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   398
	period = strrchr(name, '.');
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   399
	if (period != NULL && strcasecmp(period, extension) == 0) extension = "";
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   400
3287
609b5f5fdccb (svn r4001) - Add length parameter to FiosMakeSavegameName() and use this function for creating the full path instead of home-brewn snprintf.
Darkvater
parents: 3280
diff changeset
   401
	snprintf(buf, size, "%s/%s%s", _fios_path, name, extension);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
2255
fd5d5adee9d9 (svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents: 2223
diff changeset
   404
bool FiosDelete(const char *name)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
{
1336
69391734ce23 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1317
diff changeset
   406
	char path[512];
69391734ce23 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1317
diff changeset
   407
3287
609b5f5fdccb (svn r4001) - Add length parameter to FiosMakeSavegameName() and use this function for creating the full path instead of home-brewn snprintf.
Darkvater
parents: 3280
diff changeset
   408
	FiosMakeSavegameName(path, name, sizeof(path));
2255
fd5d5adee9d9 (svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents: 2223
diff changeset
   409
	return unlink(path) == 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
bool FileExists(const char *filename)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
{
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   414
	return access(filename, 0) == 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
static int LanguageCompareFunc(const void *a, const void *b)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
{
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 206
diff changeset
   419
	return strcmp(*(const char* const *)a, *(const char* const *)b);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
int GetLanguageList(char **languages, int max)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	DIR *dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
	struct dirent *dirent;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
	int num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	dir = opendir(_path.lang_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
	if (dir != NULL) {
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   430
		while ((dirent = readdir(dir)) != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
			char *t = strrchr(dirent->d_name, '.');
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   432
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   433
			if (t != NULL && strcmp(t, ".lng") == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
				languages[num++] = strdup(dirent->d_name);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
				if (num == max) break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
		closedir(dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   440
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	qsort(languages, num, sizeof(char*), LanguageCompareFunc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
	return num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
1050
958032fed209 (svn r1551) Silence a warning and simplify a preprocessor check
tron
parents: 1010
diff changeset
   445
#if defined(__BEOS__) || defined(__linux__)
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 307
diff changeset
   446
static void ChangeWorkingDirectory(char *exe)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	char *s = strrchr(exe, '/');
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
	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
   450
		*s = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
		chdir(exe);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
		*s = '/';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
}
1050
958032fed209 (svn r1551) Silence a warning and simplify a preprocessor check
tron
parents: 1010
diff changeset
   455
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
void ShowInfo(const char *str)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
	puts(str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
void ShowOSErrorBox(const char *buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
{
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
   464
#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
   465
	// 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
   466
	// 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
   467
	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
   468
#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
   469
	// all systems, but OSX
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
	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
   471
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
2736
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   474
#ifdef WITH_COCOA
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   475
void cocoaSetWorkingDirectory(void);
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   476
void cocoaSetupAutoreleasePool(void);
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   477
void cocoaReleaseAutoreleasePool(void);
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   478
#endif
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   479
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
int CDECL main(int argc, char* argv[])
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
{
2736
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   482
	int ret;
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   483
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   484
#ifdef WITH_COCOA
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   485
	cocoaSetupAutoreleasePool();
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3408
diff changeset
   486
	/* 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
   487
	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
   488
		argv[1] = NULL;
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   489
		argc = 1;
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   490
		cocoaSetWorkingDirectory();
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   491
	}
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   492
#endif
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   493
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
	// 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
   495
#if defined(__BEOS__) || defined(__linux__)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
	ChangeWorkingDirectory(argv[0]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   499
	_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
   500
	SeedMT(_random_seeds[0][1]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
1509
795ba683e4f0 (svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents: 1508
diff changeset
   502
	signal(SIGPIPE, SIG_IGN);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
2736
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   504
	ret = ttd_main(argc, argv);
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   505
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   506
#ifdef WITH_COCOA
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   507
	cocoaReleaseAutoreleasePool();
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   508
#endif
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   509
3d6487cbbb69 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2731
diff changeset
   510
	return ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1050
diff changeset
   513
void DeterminePaths(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
	char *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   517
	_path.game_data_dir = malloc(MAX_PATH);
561
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   518
	ttd_strlcpy(_path.game_data_dir, GAME_DATA_DIR, MAX_PATH);
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   519
	#if defined SECOND_DATA_DIR
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   520
	_path.second_data_dir = malloc(MAX_PATH);
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   521
	ttd_strlcpy(_path.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
   522
	#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
#if defined(USE_HOMEDIR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
	{
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   526
		const char *homedir = getenv("HOME");
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   527
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   528
		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
   529
			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
   530
			if (pw != NULL) homedir = pw->pw_dir;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   532
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
		_path.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   535
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
#else /* not defined(USE_HOMEDIR) */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   538
	_path.personal_dir = malloc(MAX_PATH);
561
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   539
	ttd_strlcpy(_path.personal_dir, PERSONAL_DIR, MAX_PATH);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   540
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
	// check if absolute or relative path
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
	s = strchr(_path.personal_dir, '/');
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   543
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
	// add absolute path
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   545
	if (s == NULL || _path.personal_dir != s) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
		getcwd(_path.personal_dir, MAX_PATH);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
		s = strchr(_path.personal_dir, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
		*s++ = '/';
561
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   549
		ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   551
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
#endif /* defined(USE_HOMEDIR) */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
	s = strchr(_path.personal_dir, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   555
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
	// 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
   557
	if (s[-1] != '/') strcpy(s, "/");
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   558
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
	_path.save_dir = str_fmt("%ssave", _path.personal_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
	_path.autosave_dir = str_fmt("%s/autosave", _path.save_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
	_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
	_path.gm_dir = str_fmt("%sgm/", _path.game_data_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
	_path.data_dir = str_fmt("%sdata/", _path.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
   564
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
   565
	if (_config_file == NULL)
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
   566
		_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
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
   567
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 915
diff changeset
   568
	_highscore_file = str_fmt("%shs.dat", _path.personal_dir);
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 569
diff changeset
   569
	_log_file = str_fmt("%sopenttd.log", _path.personal_dir);
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 826
diff changeset
   570
561
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   571
#if defined CUSTOM_LANG_DIR
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   572
	// sets the search path for lng files to the custom one
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   573
	_path.lang_dir = malloc( MAX_PATH );
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   574
	ttd_strlcpy( _path.lang_dir, CUSTOM_LANG_DIR, MAX_PATH);
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   575
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
	_path.lang_dir = str_fmt("%slang/", _path.game_data_dir);
561
9a0c469a251c (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   577
#endif
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   578
238
a73a3e50c7f9 (svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents: 223
diff changeset
   579
	// create necessary folders
a73a3e50c7f9 (svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents: 223
diff changeset
   580
	mkdir(_path.personal_dir, 0755);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
	mkdir(_path.save_dir, 0755);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
	mkdir(_path.autosave_dir, 0755);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
	mkdir(_path.scenario_dir, 0755);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
1470
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   586
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
   587
{
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   588
	return false;
a8fd3e037531 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   589
}
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
   590
2073
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   591
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   592
// multi os compatible sleep function
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   593
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   594
#ifdef __AMIGA__
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   595
// usleep() implementation
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   596
#	include <devices/timer.h>
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   597
#	include <dos/dos.h>
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   598
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   599
	extern struct Device      *TimerBase    = NULL;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   600
	extern struct MsgPort     *TimerPort    = NULL;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   601
	extern struct timerequest *TimerRequest = NULL;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   602
#endif // __AMIGA__
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   603
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   604
void CSleep(int milliseconds)
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   605
{
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   606
	#if !defined(__BEOS__) && !defined(__AMIGA__)
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   607
		usleep(milliseconds * 1000);
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   608
	#endif
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   609
	#ifdef __BEOS__
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   610
		snooze(milliseconds * 1000);
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   611
	#endif
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   612
	#if defined(__AMIGA__)
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   613
	{
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   614
		ULONG signals;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   615
		ULONG TimerSigBit = 1 << TimerPort->mp_SigBit;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   616
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   617
		// send IORequest
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   618
		TimerRequest->tr_node.io_Command = TR_ADDREQUEST;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   619
		TimerRequest->tr_time.tv_secs    = (milliseconds * 1000) / 1000000;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   620
		TimerRequest->tr_time.tv_micro   = (milliseconds * 1000) % 1000000;
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   621
		SendIO((struct IORequest *)TimerRequest);
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   622
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   623
		if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) {
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   624
			AbortIO((struct IORequest *)TimerRequest);
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   625
		}
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   626
		WaitIO((struct IORequest *)TimerRequest);
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   627
	}
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   628
	#endif // __AMIGA__
2d63300e4a44 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   629
}
3260
ed19f95eb4f7 (svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents: 2952
diff changeset
   630
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
   631
#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
   632
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
   633
#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
   634
#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
   635
#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
   636
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
   637
#define INTERNALCODE "ISO-8859-15"
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
   638
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
   639
/** 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
   640
 * 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
   641
 * locale can be found, don't do any conversion "" */
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
   642
static const char *GetLocalCode(void)
3260
ed19f95eb4f7 (svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents: 2952
diff changeset
   643
{
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
   644
#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
   645
	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
   646
#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
   647
	/* 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
   648
	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
   649
	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
   650
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
   651
	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
   652
#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
   653
}
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
   654
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
   655
/** 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
   656
 * 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
   657
 * 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
   658
 * 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
   659
 * 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
   660
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
   661
{
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
   662
	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
   663
	/* 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
   664
	 * 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
   665
	 * 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
   666
#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
   667
	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
   668
#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
   669
	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
   670
#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
   671
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
   672
	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
   673
	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
   674
	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
   675
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
   676
	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
   677
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
   678
	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
   679
	if (iconv(convd, &inbuf, &inlen, &outbuf, &outlen) == (size_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
   680
		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
   681
	}
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
   682
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
   683
	*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
   684
	// 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
   685
	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
   686
}
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
   687
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
   688
/** 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
   689
 * @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
   690
 * @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
   691
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
   692
{
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
   693
	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
   694
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
   695
	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
   696
		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
   697
		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
   698
		if (convd == (iconv_t)(-1)) {
3330
9059c6bd735d (svn r4107) - Fix (r4105): Mixup of string parameters in debug message if iconv_open() failed. Also clarify the message a bit.
Darkvater
parents: 3329
diff changeset
   699
			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
   700
			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
   701
		}
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
   702
	}
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
   703
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
   704
	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
   705
}
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
   706
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
   707
/** 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
   708
 * @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
   709
 * @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
   710
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
   711
{
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
   712
	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
   713
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
   714
	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
   715
		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
   716
		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
   717
		if (convd == (iconv_t)(-1)) {
3330
9059c6bd735d (svn r4107) - Fix (r4105): Mixup of string parameters in debug message if iconv_open() failed. Also clarify the message a bit.
Darkvater
parents: 3329
diff changeset
   718
			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
   719
			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
   720
		}
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
   721
	}
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
   722
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
   723
	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
   724
}
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
   725
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
   726
#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
   727
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
   728
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
   729
#endif /* WITH_ICONV */