src/os2.cpp
author rubidium
Mon, 24 Sep 2007 20:56:33 +0000
changeset 8123 2f8dfb527d7c
parent 7868 25b9aad39e4a
child 8431 68fb2ccbce06
permissions -rw-r--r--
(svn r11158) -Codechange: reduce the amount of Random calls needed when we do not have NewGRF industries that actually need the random bits.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2180
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2180
diff changeset
     2
6677
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6644
diff changeset
     3
/** @file os2.cpp */
0578c2e31ed1 (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents: 6644
diff changeset
     4
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
     5
#include "stdafx.h"
1892
45894b95a925 (svn r2398) - CodeChange: forgot to update unix and os2 specific files as well.
Darkvater
parents: 1890
diff changeset
     6
#include "openttd.h"
2167
99d31f4eeb37 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
     7
#include "variables.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: 1301
diff changeset
     8
#include "string.h"
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
     9
#include "table/strings.h"
1888
5f0398340e05 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
    10
#include "gfx.h"
5f0398340e05 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
    11
#include "gui.h"
2167
99d31f4eeb37 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
    12
#include "functions.h"
99d31f4eeb37 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
    13
#include "macros.h"
6624
554e5aee6c3f (svn r9129) -Codechange: unify parts of DeterminePaths.
rubidium
parents: 6573
diff changeset
    14
#include "fileio.h"
7541
0b79c8fb5e7f (svn r10310) -Fix: Trunk can now be built on OS/2 :)
orudge
parents: 6988
diff changeset
    15
#include "fios.h" // opendir/readdir/closedir
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    16
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    17
#include <dirent.h>
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    18
#include <unistd.h>
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    19
#include <sys/stat.h>
1887
9f1af4f412d4 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
    20
#include <stdlib.h>
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    21
#include <time.h>
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    22
#ifndef __INNOTEK_LIBC__
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    23
	#include <dos.h>
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    24
#endif
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    25
818
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
    26
#define INCL_WIN
1524
85efc2f52e2c (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
    27
#define INCL_WINCLIPBOARD
810
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    28
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    29
#include <os2.h>
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    30
#ifndef __INNOTEK_LIBC__
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    31
	#include <i86.h>
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    32
#endif
2167
99d31f4eeb37 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
    33
4223
0f9535dda7ed (svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents: 4222
diff changeset
    34
bool FiosIsRoot(const char *file)
810
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    35
{
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    36
	return file[3] == '\0';
810
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    37
}
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    38
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6566
diff changeset
    39
void FiosGetDrives()
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    40
{
4221
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    41
	unsigned disk, disk2, save, total;
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    42
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    43
#ifndef __INNOTEK_LIBC__
4221
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    44
	_dos_getdrive(&save); // save original drive
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    45
#else
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    46
	save = _getdrive(); // save original drive
7798
e80da98ed2c7 (svn r10651) -Fix: Fix chdir problem with open/save dialog on OS/2 (Paul Smedley)
orudge
parents: 7541
diff changeset
    47
	char wd[MAX_PATH];
e80da98ed2c7 (svn r10651) -Fix: Fix chdir problem with open/save dialog on OS/2 (Paul Smedley)
orudge
parents: 7541
diff changeset
    48
	getcwd(wd, MAX_PATH);
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    49
	total = 'z';
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    50
#endif
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
    51
4221
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    52
	/* get an available drive letter */
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    53
#ifndef __INNOTEK_LIBC__
4221
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    54
	for (disk = 1;; disk++) {
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    55
		_dos_setdrive(disk, &total);
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    56
#else
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    57
	for (disk = 'A';; disk++) {
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    58
		_chdrive(disk);
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    59
#endif
7798
e80da98ed2c7 (svn r10651) -Fix: Fix chdir problem with open/save dialog on OS/2 (Paul Smedley)
orudge
parents: 7541
diff changeset
    60
		if (disk >= total)  break;
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    61
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    62
#ifndef __INNOTEK_LIBC__
4221
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    63
		_dos_getdrive(&disk2);
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    64
#else
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    65
		disk2 = _getdrive();
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    66
#endif
2099
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
    67
4221
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    68
		if (disk == disk2) {
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    69
			FiosItem *fios = FiosAlloc();
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    70
			fios->type = FIOS_TYPE_DRIVE;
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    71
			fios->mtime = 0;
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    72
#ifndef __INNOTEK_LIBC__
4221
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    73
			snprintf(fios->name, lengthof(fios->name),  "%c:", 'A' + disk - 1);
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    74
#else
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    75
			snprintf(fios->name, lengthof(fios->name),  "%c:", disk);
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    76
#endif
4221
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    77
			ttd_strlcpy(fios->title, fios->name, lengthof(fios->title));
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    78
		}
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    79
	}
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    80
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    81
	/* Restore the original drive */
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    82
#ifndef __INNOTEK_LIBC__
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    83
	_dos_setdrive(save, &total);
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    84
#else
7798
e80da98ed2c7 (svn r10651) -Fix: Fix chdir problem with open/save dialog on OS/2 (Paul Smedley)
orudge
parents: 7541
diff changeset
    85
	chdir(wd);
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    86
#endif
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    87
}
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    88
4222
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    89
bool FiosGetDiskFreeSpace(const char *path, uint32 *tot)
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    90
{
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
    91
#ifndef __INNOTEK_LIBC__
4222
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    92
	struct diskfree_t free;
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    93
	char drive = path[0] - 'A' + 1;
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    94
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    95
	if (tot != NULL && _getdiskfree(drive, &free) == 0) {
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    96
		*tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector;
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    97
		return true;
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    98
	}
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    99
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   100
	return false;
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   101
#else
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   102
	uint32 free = 0;
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   103
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   104
#ifdef HAS_STATVFS
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   105
	{
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   106
		struct statvfs s;
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   107
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   108
		if (statvfs(path, &s) != 0) return false;
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   109
		free = (uint64)s.f_frsize * s.f_bavail >> 20;
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   110
	}
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   111
#endif
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   112
	if (tot != NULL) *tot = free;
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   113
	return true;
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   114
#endif
4222
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   115
}
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   116
4221
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   117
bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb)
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   118
{
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   119
	char filename[MAX_PATH];
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   120
4221
bb06fe8dcce2 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   121
	snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name);
6566
a780a47d6af3 (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 5842
diff changeset
   122
	return stat(filename, sb) == 0;
a780a47d6af3 (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 5842
diff changeset
   123
}
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
   124
6566
a780a47d6af3 (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 5842
diff changeset
   125
bool FiosIsHiddenFile(const struct dirent *ent)
a780a47d6af3 (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 5842
diff changeset
   126
{
a780a47d6af3 (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 5842
diff changeset
   127
	return ent->d_name[0] == '.';
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   128
}
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   129
7541
0b79c8fb5e7f (svn r10310) -Fix: Trunk can now be built on OS/2 :)
orudge
parents: 6988
diff changeset
   130
void ShowInfo(const char *str)
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   131
{
818
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   132
	HAB hab;
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   133
	HMQ hmq;
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   134
	ULONG rc;
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   135
818
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   136
	// init PM env.
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   137
	hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   138
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   139
	// display the box
7541
0b79c8fb5e7f (svn r10310) -Fix: Trunk can now be built on OS/2 :)
orudge
parents: 6988
diff changeset
   140
	rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, (const unsigned char *)str, (const unsigned char *)"OpenTTD", 0, MB_OK | MB_MOVEABLE | MB_INFORMATION);
818
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   141
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   142
	// terminate PM env.
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   143
	WinDestroyMsgQueue(hmq);
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   144
	WinTerminate(hab);
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   145
}
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   146
7541
0b79c8fb5e7f (svn r10310) -Fix: Trunk can now be built on OS/2 :)
orudge
parents: 6988
diff changeset
   147
void ShowOSErrorBox(const char *buf)
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   148
{
818
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   149
	HAB hab;
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   150
	HMQ hmq;
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   151
	ULONG rc;
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   152
818
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   153
	// init PM env.
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   154
	hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   155
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   156
	// display the box
7541
0b79c8fb5e7f (svn r10310) -Fix: Trunk can now be built on OS/2 :)
orudge
parents: 6988
diff changeset
   157
	rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, (const unsigned char *)buf, (const unsigned char *)"OpenTTD", 0, MB_OK | MB_MOVEABLE | MB_ERROR);
818
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   158
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   159
	// terminate PM env.
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   160
	WinDestroyMsgQueue(hmq);
906f21e653b2 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   161
	WinTerminate(hab);
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   162
}
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   163
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   164
int CDECL main(int argc, char* argv[])
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   165
{
4369
02b9ab2cf501 (svn r6086) -Fix: InteractiveRandom was not seeded properly resulting in the dedicated server always generating the same map. Thanks to the #openttdcoop team for detecting.
rubidium
parents: 4300
diff changeset
   166
	_random_seeds[1][1] = _random_seeds[1][0] = _random_seeds[0][1] = _random_seeds[0][0] = time(NULL);
801
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   167
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   168
	return ttd_main(argc, argv);
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   169
}
bfa47ec110b0 (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   170
1888
5f0398340e05 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   171
/**
5f0398340e05 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   172
 * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard
5f0398340e05 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   173
 * and append this up to the maximum length (either absolute or screenlength). If maxlength
5f0398340e05 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   174
 * is zero, we don't care about the screenlength but only about the physical length of the string
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6677
diff changeset
   175
 * @param tb Textbuf type to be changed
7868
25b9aad39e4a (svn r10736) -Fix: Correct all mispellings of 'successful'.
peter1138
parents: 7798
diff changeset
   176
 * @return Return true on successful change of Textbuf, or false otherwise
1888
5f0398340e05 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   177
 */
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
   178
bool InsertTextBufferClipboard(Textbuf *tb)
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
   179
{
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   180
/* XXX -- Currently no clipboard support implemented with GCC */
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   181
#ifndef __INNOTEK_LIBC__
1893
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   182
	HAB hab = 0;
1524
85efc2f52e2c (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   183
85efc2f52e2c (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   184
	if (WinOpenClipbrd(hab))
85efc2f52e2c (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   185
	{
1893
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   186
		const char* text = (const char*)WinQueryClipbrdData(hab, CF_TEXT);
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   187
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   188
		if (text != NULL)
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   189
		{
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   190
			uint length = 0;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   191
			uint width = 0;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   192
			const char* i;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   193
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   194
			for (i = text; IsValidAsciiChar(*i); i++)
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   195
			{
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   196
				uint w;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   197
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   198
				if (tb->length + length >= tb->maxlength - 1) break;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   199
3800
6ea101b2464b (svn r4808) - Fix GetCharacterWidth() change in os2.c missed in r4802.
peter1138
parents: 3329
diff changeset
   200
				w = GetCharacterWidth(FS_NORMAL, (byte)*i);
1893
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   201
				if (tb->maxwidth != 0 && width + tb->width + w > tb->maxwidth) break;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   202
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   203
				width += w;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   204
				length++;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   205
			}
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   206
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   207
			memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos + 1);
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   208
			memcpy(tb->buf + tb->caretpos, text, length);
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   209
			tb->width += width;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   210
			tb->caretxoffs += width;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   211
			tb->length += length;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   212
			tb->caretpos += length;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   213
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   214
			WinCloseClipbrd(hab);
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   215
			return true;
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   216
		}
1888
5f0398340e05 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   217
1524
85efc2f52e2c (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   218
		WinCloseClipbrd(hab);
85efc2f52e2c (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   219
	}
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   220
#endif
1893
278bddd649be (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   221
	return false;
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
   222
}
1887
9f1af4f412d4 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   223
2167
99d31f4eeb37 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
   224
99d31f4eeb37 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
   225
void CSleep(int milliseconds)
99d31f4eeb37 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
   226
{
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   227
#ifndef __INNOTEK_LIBC__
6988
76eba6a9cc6f (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6979
diff changeset
   228
	delay(milliseconds);
5842
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   229
#else
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   230
	usleep(milliseconds * 1000);
180c71b8fc14 (svn r8042) - Fix: OS/2 compilation with GCC (thanks to Paul Smedley and TrueBrain for their help)
orudge
parents: 5835
diff changeset
   231
#endif
2167
99d31f4eeb37 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
   232
}
5167
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4369
diff changeset
   233
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4369
diff changeset
   234
const char *FS2OTTD(const char *name) {return name;}
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4369
diff changeset
   235
const char *OTTD2FS(const char *name) {return name;}