unix.c
author tron
Thu, 21 Jul 2005 22:15:02 +0000
changeset 2159 3b634157c3b2
parent 2099 22f535ad9eea
child 2163 637ec3c361f5
permissions -rw-r--r--
(svn r2669) Shuffle some more stuff around to reduce dependencies
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
1892
45894b95a925 (svn r2398) - CodeChange: forgot to update unix and os2 specific files as well.
Darkvater
parents: 1885
diff changeset
     2
#include "openttd.h"
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
     3
#include "window.h"
1317
f382f1b439c7 (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
     4
#include "string.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 437
diff changeset
     5
#include "table/strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include "hal.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2099
diff changeset
     7
#include "variables.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include <dirent.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include <unistd.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include <sys/stat.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include <time.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include <pwd.h>
1509
2c232b7d2114 (svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents: 1508
diff changeset
    14
#include <signal.h>
1911
ec2b67cf5414 (svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents: 1899
diff changeset
    15
#if !defined(__MORPHOS__) && !defined(__AMIGA__)
ec2b67cf5414 (svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents: 1899
diff changeset
    16
 #include <pthread.h>
ec2b67cf5414 (svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents: 1899
diff changeset
    17
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
1850
7fa9e3ecb486 (svn r2356) Make check if statvfs() is availible a bit more sensible
tron
parents: 1687
diff changeset
    19
#if (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__)
1597
cc09dbccddac (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
    20
	#define HAS_STATVFS
cc09dbccddac (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
    21
#endif
cc09dbccddac (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
    22
cc09dbccddac (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
    23
#ifdef HAS_STATVFS
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include <sys/statvfs.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
#if defined(WITH_SDL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
#include <SDL.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
#ifdef __MORPHOS__
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
#include <exec/types.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
ULONG __stack = (1024*1024)*2; // maybe not that much is needed actually ;)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
#endif /* __MORPHOS__ */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
770
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 704
diff changeset
    37
#ifdef __AMIGA__
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 704
diff changeset
    38
#warning add stack symbol to avoid that user needs to set stack manually (tokai)
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 826
diff changeset
    39
// ULONG __stack =
770
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 704
diff changeset
    40
#endif
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 704
diff changeset
    41
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
static char *_fios_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
static char *_fios_save_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
static char *_fios_scn_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
static FiosItem *_fios_items;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
static int _fios_count, _fios_alloc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1050
diff changeset
    48
static FiosItem *FiosAlloc(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	if (_fios_count == _fios_alloc) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
		_fios_alloc += 256;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
		_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	return &_fios_items[_fios_count++];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
1486
6a31e3d7dfe3 (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
    57
int compare_FiosItems(const void *a, const void *b)
6a31e3d7dfe3 (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
    58
{
6a31e3d7dfe3 (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
    59
	const FiosItem *da = (const FiosItem *)a;
6a31e3d7dfe3 (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
    60
	const FiosItem *db = (const FiosItem *)b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
	int r;
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
	if (_savegame_sort_order < 2) // sort by date
1486
6a31e3d7dfe3 (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
    64
		r = da->mtime < db->mtime ? -1 : 1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
    65
	else
2099
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
    66
		r = strcasecmp(da->title, db->title);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
	if (_savegame_sort_order & 1) r = -r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
	return r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
// Get a list of savegames
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
FiosItem *FiosGetSavegameList(int *num, int mode)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
	FiosItem *fios;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	DIR *dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
	struct dirent *dirent;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
	struct stat sb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
	int sort_start;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
	char filename[MAX_PATH];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
	if (_fios_save_path == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
		_fios_save_path = malloc(MAX_PATH);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
		strcpy(_fios_save_path, _path.save_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
2099
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
    88
	_fios_path = _fios_save_path;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
    89
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
	// Parent directory, only if not in root already.
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
    91
	if (_fios_path[1] != '\0') {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
		fios = FiosAlloc();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
		fios->type = FIOS_TYPE_PARENT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
		fios->mtime = 0;
1572
6d0111113f0b (svn r2076) Set the name for the parent directory to ".."
tron
parents: 1509
diff changeset
    95
		strcpy(fios->name, "..");
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
    96
		strcpy(fios->title, ".. (Parent directory)");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
	}
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
	// Show subdirectories first
1486
6a31e3d7dfe3 (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
   100
	dir = opendir(_fios_path[0] != '\0' ? _fios_path : "/");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
	if (dir != NULL) {
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   102
		while ((dirent = readdir(dir)) != NULL) {
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   103
			snprintf(filename, lengthof(filename), "%s/%s",
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   104
				_fios_path, dirent->d_name);
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   105
			if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) &&
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   106
					dirent->d_name[0] != '.') {
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   107
				fios = FiosAlloc();
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   108
				fios->type = FIOS_TYPE_DIR;
1486
6a31e3d7dfe3 (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
   109
				fios->mtime = 0;
6a31e3d7dfe3 (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
   110
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
6a31e3d7dfe3 (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
   111
				snprintf(fios->title, lengthof(fios->title),
6a31e3d7dfe3 (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
   112
					"%s/ (Directory)", dirent->d_name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
		closedir(dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
307
d251be6c0d54 (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   118
	{
d251be6c0d54 (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   119
		/* XXX ugly global variables ... */
d251be6c0d54 (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   120
		byte order = _savegame_sort_order;
d251be6c0d54 (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   121
		_savegame_sort_order = 2; // sort ascending by name
d251be6c0d54 (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   122
		qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
d251be6c0d54 (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   123
		_savegame_sort_order = order;
d251be6c0d54 (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   124
	}
d251be6c0d54 (svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents: 268
diff changeset
   125
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	// this is where to start sorting
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
	sort_start = _fios_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
1486
6a31e3d7dfe3 (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
   129
	/* Show savegame files
6a31e3d7dfe3 (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
   130
	 * .SAV OpenTTD saved game
6a31e3d7dfe3 (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
   131
	 * .SS1 Transport Tycoon Deluxe preset game
6a31e3d7dfe3 (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
	 * .SV1 Transport Tycoon Deluxe (Patch) saved game
6a31e3d7dfe3 (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
	 * .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
   134
	 */
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   135
	dir = opendir(_fios_path[0] != '\0' ? _fios_path : "/");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
	if (dir != NULL) {
1486
6a31e3d7dfe3 (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
   137
		while ((dirent = readdir(dir)) != NULL) {
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   138
			char *t;
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   139
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   140
			snprintf(filename, lengthof(filename), "%s/%s",
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   141
				_fios_path, dirent->d_name);
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   142
			if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue;
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   143
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   144
			t = strrchr(dirent->d_name, '.');
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   145
			if (t != NULL && strcasecmp(t, ".sav") == 0) { // OpenTTD
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   146
				fios = FiosAlloc();
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   147
				fios->type = FIOS_TYPE_FILE;
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   148
				fios->mtime = sb.st_mtime;
1486
6a31e3d7dfe3 (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
   149
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
2099
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
   150
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
   151
				*t = '\0'; // strip extension
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
   152
				ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title));
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   153
			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   154
				if (t != NULL && (
1486
6a31e3d7dfe3 (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
							strcasecmp(t, ".ss1") == 0 ||
6a31e3d7dfe3 (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
							strcasecmp(t, ".sv1") == 0 ||
6a31e3d7dfe3 (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
   157
							strcasecmp(t, ".sv2") == 0
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   158
						)) { // TTDLX(Patch)
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   159
					fios = FiosAlloc();
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   160
					fios->type = FIOS_TYPE_OLDFILE;
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   161
					fios->mtime = sb.st_mtime;
1486
6a31e3d7dfe3 (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
   162
					ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   163
					GetOldSaveGameName(fios->title, filename);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
		closedir(dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
1486
6a31e3d7dfe3 (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
   170
	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
   171
	*num = _fios_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
	return _fios_items;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
// Get a list of scenarios
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   176
// FIXME: Gross code duplication with FiosGetSavegameList()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
FiosItem *FiosGetScenarioList(int *num, int mode)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	FiosItem *fios;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
	DIR *dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	struct dirent *dirent;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	struct stat sb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	int sort_start;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	char filename[MAX_PATH];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	if (_fios_scn_path == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
		_fios_scn_path = malloc(MAX_PATH);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
		strcpy(_fios_scn_path, _path.scenario_dir);
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
	_fios_path = _fios_scn_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
1486
6a31e3d7dfe3 (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
   192
	// Parent directory, only if not of the type C:\.
6a31e3d7dfe3 (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
   193
	if (_fios_path[1] != '\0' && mode != SLD_NEW_GAME) {
6a31e3d7dfe3 (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
		fios = FiosAlloc();
6a31e3d7dfe3 (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
   195
		fios->type = FIOS_TYPE_PARENT;
6a31e3d7dfe3 (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
   196
		fios->mtime = 0;
6a31e3d7dfe3 (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
   197
		strcpy(fios->title, ".. (Parent directory)");
6a31e3d7dfe3 (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
   198
	}
6a31e3d7dfe3 (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
   199
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
	// Show subdirectories first
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	dir = opendir(_fios_path[0] ? _fios_path : "/");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	if (dir != NULL) {
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   203
		while ((dirent = readdir(dir)) != NULL) {
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   204
			snprintf(filename, lengthof(filename), "%s/%s",
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   205
				_fios_path, dirent->d_name);
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   206
			if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) &&
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   207
					dirent->d_name[0] != '.') {
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   208
				fios = FiosAlloc();
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   209
				fios->type = FIOS_TYPE_DIR;
1486
6a31e3d7dfe3 (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
   210
				fios->mtime = 0;
6a31e3d7dfe3 (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
   211
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
2099
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
   212
				snprintf(fios->title, lengthof(fios->title), "%s/ (Directory)", dirent->d_name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
		closedir(dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	// this is where to start sorting
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
	sort_start = _fios_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
1486
6a31e3d7dfe3 (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
	/* Show scenario files
6a31e3d7dfe3 (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
	 * .SCN OpenTTD style scenario file
6a31e3d7dfe3 (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
	 * .SV0 Transport Tycoon Deluxe (Patch) scenario
6a31e3d7dfe3 (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
	 * .SS0 Transport Tycoon Deluxe preset scenario
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
	 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	dir = opendir(_fios_path[0] ? _fios_path : "/");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
	if (dir != NULL) {
1470
25c332b43280 (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) {
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   229
			char *t;
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   230
2099
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
   231
			snprintf(filename, lengthof(filename), "%s/%s", _fios_path, dirent->d_name);
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   232
			if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue;
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   233
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   234
			t = strrchr(dirent->d_name, '.');
1486
6a31e3d7dfe3 (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
			if (t != NULL && strcasecmp(t, ".scn") == 0) { // OpenTTD
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   236
				fios = FiosAlloc();
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   237
				fios->type = FIOS_TYPE_SCENARIO;
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   238
				fios->mtime = sb.st_mtime;
1486
6a31e3d7dfe3 (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
   239
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
2099
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
   240
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
   241
				*t  = '\0'; // strip extension
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2073
diff changeset
   242
				ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title));
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   243
			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO ||
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   244
					mode == SLD_NEW_GAME) {
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   245
				if (t != NULL && (
1486
6a31e3d7dfe3 (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
   246
							strcasecmp(t, ".sv0") == 0 ||
6a31e3d7dfe3 (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
   247
							strcasecmp(t, ".ss0") == 0
6a31e3d7dfe3 (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
   248
						)) { // TTDLX(Patch)
1449
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   249
					fios = FiosAlloc();
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   250
					fios->type = FIOS_TYPE_OLD_SCENARIO;
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   251
					fios->mtime = sb.st_mtime;
71331c8f3f90 (svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents: 1390
diff changeset
   252
					GetOldScenarioGameName(fios->title, filename);
1486
6a31e3d7dfe3 (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
   253
					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
   254
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
		closedir(dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
1486
6a31e3d7dfe3 (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
   260
	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
   261
	*num = _fios_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
	return _fios_items;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
// Free the list of savegames
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1050
diff changeset
   267
void FiosFreeSavegameList(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
	free(_fios_items);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
	_fios_items = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
	_fios_alloc = _fios_count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
// Browse to
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
char *FiosBrowseTo(const FiosItem *item)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	char *path = _fios_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
	char *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   280
	switch (item->type) {
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   281
		case FIOS_TYPE_PARENT:
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   282
			s = strrchr(path, '/');
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   283
			if (s != NULL) *s = '\0';
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   284
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   286
		case FIOS_TYPE_DIR:
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   287
			s = strchr(item->name, '/');
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   288
			if (s != NULL) *s = '\0';
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   289
			strcat(path, "/");
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   290
			strcat(path, item->name);
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   291
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   293
		case FIOS_TYPE_FILE:
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   294
		case FIOS_TYPE_OLDFILE:
1486
6a31e3d7dfe3 (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
		case FIOS_TYPE_SCENARIO:
6a31e3d7dfe3 (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
   296
		case FIOS_TYPE_OLD_SCENARIO: {
6a31e3d7dfe3 (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
   297
			static char str_buffr[512];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   298
1486
6a31e3d7dfe3 (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
   299
			sprintf(str_buffr, "%s/%s", path, item->name);
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   300
			return str_buffr;
1486
6a31e3d7dfe3 (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
   301
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
	}
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
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
1596
c1c439a2d5b2 (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
   307
/**
c1c439a2d5b2 (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
   308
 * Get descriptive texts. Returns the path and free space
c1c439a2d5b2 (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
   309
 * left on the device
c1c439a2d5b2 (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
   310
 * @param path string describing the path
c1c439a2d5b2 (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
   311
 * @param tfs total free space in megabytes, optional (can be NULL)
c1c439a2d5b2 (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
   312
 * @return StringID describing the path (free space or failure)
c1c439a2d5b2 (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
   313
 */
c1c439a2d5b2 (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
   314
StringID FiosGetDescText(const char **path, uint32 *tot)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
{
1596
c1c439a2d5b2 (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
   316
	uint32 free = 0;
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   317
	*path = _fios_path[0] != '\0' ? _fios_path : "/";
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
1597
cc09dbccddac (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
   319
#ifdef HAS_STATVFS
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
	{
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   321
		struct statvfs s;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
1597
cc09dbccddac (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
   323
		if (statvfs(*path, &s) == 0) {
cc09dbccddac (svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents: 1596
diff changeset
   324
			free = (uint64)s.f_frsize * s.f_bavail >> 20;
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   325
		} else
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   326
			return STR_4006_UNABLE_TO_READ_DRIVE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	}
1596
c1c439a2d5b2 (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
   328
#endif
c1c439a2d5b2 (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
   329
	if (tot != NULL) *tot = free;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   330
	return STR_4005_BYTES_FREE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
void FiosMakeSavegameName(char *buf, const char *name)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
{
1508
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   335
	const char* extension;
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   336
	const char* period;
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   337
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   338
	if (_game_mode == GM_EDITOR)
1508
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   339
		extension = ".scn";
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
	else
1508
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   341
		extension = ".sav";
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   342
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   343
	// Don't append the extension, if it is already there
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   344
	period = strrchr(name, '.');
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   345
	if (period != NULL && strcasecmp(period, extension) == 0) extension = "";
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   346
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1495
diff changeset
   347
	sprintf(buf, "%s/%s%s", _fios_path, name, extension);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
void FiosDelete(const char *name)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
{
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1317
diff changeset
   352
	char path[512];
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1317
diff changeset
   353
1495
c8a61d136f26 (svn r1999) r1990 broke savegame deletion, fix that [1161729]
tron
parents: 1486
diff changeset
   354
	snprintf(path, lengthof(path), "%s/%s", _fios_path, name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	unlink(path);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
const DriverDesc _video_driver_descs[] = {
179
003096efeb9d (svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents: 164
diff changeset
   359
	{"null",	"Null Video Driver",	&_null_video_driver,	0},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
#if defined(WITH_SDL)
179
003096efeb9d (svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents: 164
diff changeset
   361
	{ "sdl",	"SDL Video Driver",		&_sdl_video_driver,		1},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
#endif
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
   363
	{ "dedicated", "Dedicated Video Driver", &_dedicated_video_driver, 0},
179
003096efeb9d (svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents: 164
diff changeset
   364
	{ NULL,		NULL,									NULL,									0}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
const DriverDesc _sound_driver_descs[] = {
179
003096efeb9d (svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents: 164
diff changeset
   368
	{"null",	"Null Sound Driver",	&_null_sound_driver,		0},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
#if defined(WITH_SDL)
179
003096efeb9d (svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents: 164
diff changeset
   370
	{ "sdl",	"SDL Sound Driver",		&_sdl_sound_driver,			1},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
#endif
179
003096efeb9d (svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents: 164
diff changeset
   372
	{ NULL,		NULL,									NULL,										0}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
#if defined(__APPLE__)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
#define EXTMIDI_PRI 2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
#else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
#define EXTMIDI_PRI 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
const DriverDesc _music_driver_descs[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
#ifndef __BEOS__
569
2e86ae517874 (svn r980) Fixed issues where MorphOS would get problems if AmigaOS would get a port, since MorphOS also have the flag __AMIGA__ defined (Tokai)
bjarni
parents: 561
diff changeset
   383
#if !defined(__MORPHOS__) && !defined(__AMIGA__)
2e86ae517874 (svn r980) Fixed issues where MorphOS would get problems if AmigaOS would get a port, since MorphOS also have the flag __AMIGA__ defined (Tokai)
bjarni
parents: 561
diff changeset
   384
// MorphOS and AmigaOS have no music support
179
003096efeb9d (svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents: 164
diff changeset
   385
	{"extmidi",	"External MIDI Driver",	&_extmidi_music_driver,	EXTMIDI_PRI},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
#ifdef __BEOS__
179
003096efeb9d (svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents: 164
diff changeset
   389
	{ "bemidi",	"BeOS MIDI Driver",			&_bemidi_music_driver,	1},
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   390
#endif
179
003096efeb9d (svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents: 164
diff changeset
   391
	{   "null",	"Null Music Driver",		&_null_music_driver,		1},
003096efeb9d (svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents: 164
diff changeset
   392
	{     NULL,	NULL,										NULL,										0}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
223
0e5cc5a65df6 (svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents: 222
diff changeset
   395
/* GetOSVersion returns the minimal required version of OS to be able to use that driver.
0e5cc5a65df6 (svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents: 222
diff changeset
   396
	 Not needed for *nix. */
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1050
diff changeset
   397
byte GetOSVersion(void)
223
0e5cc5a65df6 (svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents: 222
diff changeset
   398
{
826
0e2b569b737b (svn r1297) Language fixes in the source.. (ln-)
miham
parents: 770
diff changeset
   399
	return 2;  // any arbitrary number bigger than 0
268
00fabd0160bc (svn r274) Mac: restored extmusic to be default, which were accidently turned off by a windows music fix
bjarni
parents: 238
diff changeset
   400
				// numbers lower than 2 breaks default music selection on mac
223
0e5cc5a65df6 (svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents: 222
diff changeset
   401
}
0e5cc5a65df6 (svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents: 222
diff changeset
   402
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
bool FileExists(const char *filename)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
{
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   405
	return access(filename, 0) == 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
static int LanguageCompareFunc(const void *a, const void *b)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
{
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
   410
	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
   411
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
int GetLanguageList(char **languages, int max)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
	DIR *dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
	struct dirent *dirent;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	int num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
	dir = opendir(_path.lang_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
	if (dir != NULL) {
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   421
		while ((dirent = readdir(dir)) != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
			char *t = strrchr(dirent->d_name, '.');
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   423
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   424
			if (t != NULL && strcmp(t, ".lng") == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
				languages[num++] = strdup(dirent->d_name);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
				if (num == max) break;
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
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
		closedir(dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   431
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
	qsort(languages, num, sizeof(char*), LanguageCompareFunc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	return num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
1050
e76fa5c5d835 (svn r1551) Silence a warning and simplify a preprocessor check
tron
parents: 1010
diff changeset
   436
#if defined(__BEOS__) || defined(__linux__)
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 307
diff changeset
   437
static void ChangeWorkingDirectory(char *exe)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
	char *s = strrchr(exe, '/');
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
	if (s != NULL) {
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   441
		*s = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
		chdir(exe);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
		*s = '/';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
}
1050
e76fa5c5d835 (svn r1551) Silence a warning and simplify a preprocessor check
tron
parents: 1010
diff changeset
   446
#endif
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
void ShowInfo(const char *str)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
	puts(str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
void ShowOSErrorBox(const char *buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
{
529
3b23d5073d32 (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
   455
#if defined(__APPLE__)
3b23d5073d32 (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
   456
	// this creates an error in the console and then opens the console.
3b23d5073d32 (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
   457
	// Colourcodes are not used in the console, so they are skipped here
3b23d5073d32 (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
   458
	fprintf(stderr, "Error: %s", buf);
561
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   459
	system("/Applications/Utilities/Console.app/Contents/MacOS/Console &");
529
3b23d5073d32 (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
   460
#else
3b23d5073d32 (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
   461
	// all systems, but OSX
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
	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
   463
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
int CDECL main(int argc, char* argv[])
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
	// change the working directory to enable doubleclicking in UIs
1050
e76fa5c5d835 (svn r1551) Silence a warning and simplify a preprocessor check
tron
parents: 1010
diff changeset
   469
#if defined(__BEOS__) || defined(__linux__)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
	ChangeWorkingDirectory(argv[0]);
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
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 193
diff changeset
   473
	_random_seeds[0][1] = _random_seeds[0][0] = time(NULL);
2073
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   474
	SeedMT(_random_seeds[0][1]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
1509
2c232b7d2114 (svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents: 1508
diff changeset
   476
	signal(SIGPIPE, SIG_IGN);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
	return ttd_main(argc, argv);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1050
diff changeset
   481
void DeterminePaths(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
	char *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   485
	_path.game_data_dir = malloc(MAX_PATH);
561
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   486
	ttd_strlcpy(_path.game_data_dir, GAME_DATA_DIR, MAX_PATH);
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   487
	#if defined SECOND_DATA_DIR
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   488
	_path.second_data_dir = malloc(MAX_PATH);
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   489
	ttd_strlcpy(_path.second_data_dir, SECOND_DATA_DIR, MAX_PATH);
561
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   490
	#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
#if defined(USE_HOMEDIR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
	{
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   494
		const char *homedir = getenv("HOME");
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   495
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   496
		if (homedir == NULL) {
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   497
			const struct passwd *pw = getpwuid(getuid());
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   498
			if (pw != NULL) homedir = pw->pw_dir;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   500
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
		_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
   502
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   503
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
#else /* not defined(USE_HOMEDIR) */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   506
	_path.personal_dir = malloc(MAX_PATH);
561
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   507
	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
   508
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
	// check if absolute or relative path
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
	s = strchr(_path.personal_dir, '/');
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   511
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
	// add absolute path
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   513
	if (s == NULL || _path.personal_dir != s) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
		getcwd(_path.personal_dir, MAX_PATH);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
		s = strchr(_path.personal_dir, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
		*s++ = '/';
561
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   517
		ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   519
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
#endif /* defined(USE_HOMEDIR) */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	s = strchr(_path.personal_dir, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   523
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
	// append a / ?
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   525
	if (s[-1] != '/') strcpy(s, "/");
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   526
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	_path.save_dir = str_fmt("%ssave", _path.personal_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
	_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
   529
	_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
	_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
   531
	_path.data_dir = str_fmt("%sdata/", _path.game_data_dir);
1482
46a8146adecf (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
   532
46a8146adecf (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
   533
	if (_config_file == NULL)
46a8146adecf (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
   534
		_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
46a8146adecf (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
   535
983
1be852dcdd4c (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
   536
	_highscore_file = str_fmt("%shs.dat", _path.personal_dir);
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 569
diff changeset
   537
	_log_file = str_fmt("%sopenttd.log", _path.personal_dir);
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 826
diff changeset
   538
561
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   539
#if defined CUSTOM_LANG_DIR
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   540
	// sets the search path for lng files to the custom one
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   541
	_path.lang_dir = malloc( MAX_PATH );
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   542
	ttd_strlcpy( _path.lang_dir, CUSTOM_LANG_DIR, MAX_PATH);
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   543
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
	_path.lang_dir = str_fmt("%slang/", _path.game_data_dir);
561
e3b9689745ab (svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents: 543
diff changeset
   545
#endif
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   546
238
a73a3e50c7f9 (svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents: 223
diff changeset
   547
	// create necessary folders
a73a3e50c7f9 (svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents: 223
diff changeset
   548
	mkdir(_path.personal_dir, 0755);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
	mkdir(_path.save_dir, 0755);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
	mkdir(_path.autosave_dir, 0755);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
	mkdir(_path.scenario_dir, 0755);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
1470
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   554
bool InsertTextBufferClipboard(Textbuf *tb)
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   555
{
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   556
	return false;
25c332b43280 (svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents: 1449
diff changeset
   557
}
1885
4ce583a5275b (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
   558
1911
ec2b67cf5414 (svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents: 1899
diff changeset
   559
/** Dummy stubs as MorphOS/ AmigaOS does not really
ec2b67cf5414 (svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents: 1899
diff changeset
   560
 *  know about a thread concept nor has a working libpthread */
ec2b67cf5414 (svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents: 1899
diff changeset
   561
#if defined(__MORPHOS__) || defined(__AMIGA__)
ec2b67cf5414 (svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents: 1899
diff changeset
   562
 typedef int pthread_t;
ec2b67cf5414 (svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents: 1899
diff changeset
   563
 #define pthread_create(thread, attr, function, arg) (true)
1912
a62eacfdd5ff (svn r2418) - Fix: typo
Darkvater
parents: 1911
diff changeset
   564
 #define pthread_join(thread, retval)
1911
ec2b67cf5414 (svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents: 1899
diff changeset
   565
#endif
ec2b67cf5414 (svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents: 1899
diff changeset
   566
1885
4ce583a5275b (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
   567
static pthread_t thread1 = 0;
1911
ec2b67cf5414 (svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents: 1899
diff changeset
   568
1885
4ce583a5275b (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
   569
bool CreateOTTDThread(void *func, void *param)
4ce583a5275b (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
   570
{
1899
98317b840d7b (svn r2405) Simplify a few '? true : false' and '? false : true', especially the latter is confusing
tron
parents: 1892
diff changeset
   571
	return pthread_create(&thread1, NULL, func, param) == 0;
1885
4ce583a5275b (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
   572
}
4ce583a5275b (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
   573
4ce583a5275b (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
   574
void CloseOTTDThread(void) {return;}
4ce583a5275b (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
   575
4ce583a5275b (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
   576
void JoinOTTDThread(void)
4ce583a5275b (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
   577
{
4ce583a5275b (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
   578
	if (thread1 == 0) return;
4ce583a5275b (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
   579
4ce583a5275b (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
   580
	pthread_join(thread1, NULL);
4ce583a5275b (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
   581
}
2073
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   582
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   583
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   584
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   585
#ifdef ENABLE_NETWORK
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   586
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   587
// multi os compatible sleep function
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   588
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   589
#ifdef __AMIGA__
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   590
// usleep() implementation
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   591
#	include <devices/timer.h>
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   592
#	include <dos/dos.h>
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   593
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   594
	extern struct Device      *TimerBase    = NULL;
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   595
	extern struct MsgPort     *TimerPort    = NULL;
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   596
	extern struct timerequest *TimerRequest = NULL;
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   597
#endif // __AMIGA__
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   598
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   599
void CSleep(int milliseconds)
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   600
{
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   601
	#if !defined(__BEOS__) && !defined(__AMIGA__)
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   602
		usleep(milliseconds * 1000);
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   603
	#endif
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   604
	#ifdef __BEOS__
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   605
		snooze(milliseconds * 1000);
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   606
	#endif
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   607
	#if defined(__AMIGA__)
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   608
	{
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   609
		ULONG signals;
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   610
		ULONG TimerSigBit = 1 << TimerPort->mp_SigBit;
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   611
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   612
		// send IORequest
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   613
		TimerRequest->tr_node.io_Command = TR_ADDREQUEST;
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   614
		TimerRequest->tr_time.tv_secs    = (milliseconds * 1000) / 1000000;
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   615
		TimerRequest->tr_time.tv_micro   = (milliseconds * 1000) % 1000000;
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   616
		SendIO((struct IORequest *)TimerRequest);
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   617
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   618
		if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) {
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   619
			AbortIO((struct IORequest *)TimerRequest);
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   620
		}
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   621
		WaitIO((struct IORequest *)TimerRequest);
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   622
	}
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   623
	#endif // __AMIGA__
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   624
}
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   625
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   626
#endif /* ENABLE_NETWORK */
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 1912
diff changeset
   627