2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file os2.cpp OS2 related OS support. */
|
2007-03-21 15:19:33 +00:00
|
|
|
|
2004-12-24 00:00:10 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:39:29 +00:00
|
|
|
#include "openttd.h"
|
2005-07-22 16:14:24 +00:00
|
|
|
#include "variables.h"
|
2005-06-02 10:39:46 +00:00
|
|
|
#include "gui.h"
|
2008-08-31 11:51:09 +00:00
|
|
|
#include "fileio_func.h"
|
|
|
|
#include "fios.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "functions.h"
|
|
|
|
#include "core/random_func.hpp"
|
2008-01-11 18:53:52 +00:00
|
|
|
#include "string_func.h"
|
|
|
|
#include "textbuf_gui.h"
|
2004-12-24 00:00:10 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2007-01-10 19:39:54 +00:00
|
|
|
#include <dirent.h>
|
2004-12-24 00:00:10 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
2005-06-02 09:51:01 +00:00
|
|
|
#include <stdlib.h>
|
2004-12-24 00:00:10 +00:00
|
|
|
#include <time.h>
|
2007-01-10 19:39:54 +00:00
|
|
|
#ifndef __INNOTEK_LIBC__
|
|
|
|
#include <dos.h>
|
|
|
|
#endif
|
2004-12-24 00:00:10 +00:00
|
|
|
|
2004-12-28 12:11:34 +00:00
|
|
|
#define INCL_WIN
|
2005-03-19 22:36:13 +00:00
|
|
|
#define INCL_WINCLIPBOARD
|
2004-12-27 10:40:04 +00:00
|
|
|
|
2004-12-24 00:00:10 +00:00
|
|
|
#include <os2.h>
|
2007-01-10 19:39:54 +00:00
|
|
|
#ifndef __INNOTEK_LIBC__
|
|
|
|
#include <i86.h>
|
|
|
|
#endif
|
2005-07-22 16:14:24 +00:00
|
|
|
|
2006-08-05 00:59:45 +00:00
|
|
|
bool FiosIsRoot(const char *file)
|
2004-12-27 10:40:04 +00:00
|
|
|
{
|
2007-01-10 19:39:54 +00:00
|
|
|
return file[3] == '\0';
|
2004-12-27 10:40:04 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void FiosGetDrives()
|
2004-12-24 00:00:10 +00:00
|
|
|
{
|
2009-01-03 17:28:22 +00:00
|
|
|
uint disk, disk2, save, total;
|
2006-08-05 00:47:32 +00:00
|
|
|
|
2007-01-10 19:39:54 +00:00
|
|
|
#ifndef __INNOTEK_LIBC__
|
2006-08-05 00:47:32 +00:00
|
|
|
_dos_getdrive(&save); // save original drive
|
2007-01-10 19:39:54 +00:00
|
|
|
#else
|
|
|
|
save = _getdrive(); // save original drive
|
2007-07-22 17:21:25 +00:00
|
|
|
char wd[MAX_PATH];
|
|
|
|
getcwd(wd, MAX_PATH);
|
2007-01-10 19:39:54 +00:00
|
|
|
total = 'z';
|
|
|
|
#endif
|
2006-08-05 00:47:32 +00:00
|
|
|
|
|
|
|
/* get an available drive letter */
|
2007-01-10 19:39:54 +00:00
|
|
|
#ifndef __INNOTEK_LIBC__
|
2006-08-05 00:47:32 +00:00
|
|
|
for (disk = 1;; disk++) {
|
|
|
|
_dos_setdrive(disk, &total);
|
2007-01-10 19:39:54 +00:00
|
|
|
#else
|
|
|
|
for (disk = 'A';; disk++) {
|
|
|
|
_chdrive(disk);
|
|
|
|
#endif
|
2007-07-22 17:21:25 +00:00
|
|
|
if (disk >= total) break;
|
2007-01-10 19:39:54 +00:00
|
|
|
|
|
|
|
#ifndef __INNOTEK_LIBC__
|
2006-08-05 00:47:32 +00:00
|
|
|
_dos_getdrive(&disk2);
|
2007-01-10 19:39:54 +00:00
|
|
|
#else
|
|
|
|
disk2 = _getdrive();
|
|
|
|
#endif
|
2006-08-05 00:47:32 +00:00
|
|
|
|
|
|
|
if (disk == disk2) {
|
2008-06-02 14:30:55 +00:00
|
|
|
FiosItem *fios = _fios_items.Append();
|
2006-08-05 00:47:32 +00:00
|
|
|
fios->type = FIOS_TYPE_DRIVE;
|
|
|
|
fios->mtime = 0;
|
2007-01-10 19:39:54 +00:00
|
|
|
#ifndef __INNOTEK_LIBC__
|
2006-08-05 00:47:32 +00:00
|
|
|
snprintf(fios->name, lengthof(fios->name), "%c:", 'A' + disk - 1);
|
2007-01-10 19:39:54 +00:00
|
|
|
#else
|
|
|
|
snprintf(fios->name, lengthof(fios->name), "%c:", disk);
|
|
|
|
#endif
|
2008-11-02 11:20:15 +00:00
|
|
|
strecpy(fios->title, fios->name, lastof(fios->title));
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-10 19:39:54 +00:00
|
|
|
/* Restore the original drive */
|
|
|
|
#ifndef __INNOTEK_LIBC__
|
|
|
|
_dos_setdrive(save, &total);
|
|
|
|
#else
|
2007-07-22 17:21:25 +00:00
|
|
|
chdir(wd);
|
2007-01-10 19:39:54 +00:00
|
|
|
#endif
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 12:59:47 +00:00
|
|
|
bool FiosGetDiskFreeSpace(const char *path, uint64 *tot)
|
2004-12-24 00:00:10 +00:00
|
|
|
{
|
2007-01-10 19:39:54 +00:00
|
|
|
#ifndef __INNOTEK_LIBC__
|
2006-08-05 00:53:09 +00:00
|
|
|
struct diskfree_t free;
|
|
|
|
char drive = path[0] - 'A' + 1;
|
2004-12-24 00:00:10 +00:00
|
|
|
|
2006-08-05 00:53:09 +00:00
|
|
|
if (tot != NULL && _getdiskfree(drive, &free) == 0) {
|
|
|
|
*tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector;
|
|
|
|
return true;
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 00:53:09 +00:00
|
|
|
return false;
|
2007-01-10 19:39:54 +00:00
|
|
|
#else
|
2009-01-16 12:59:47 +00:00
|
|
|
uint64 free = 0;
|
2007-01-10 19:39:54 +00:00
|
|
|
|
|
|
|
#ifdef HAS_STATVFS
|
|
|
|
{
|
|
|
|
struct statvfs s;
|
|
|
|
|
|
|
|
if (statvfs(path, &s) != 0) return false;
|
2009-01-16 12:59:47 +00:00
|
|
|
free = (uint64)s.f_frsize * s.f_bavail;
|
2007-01-10 19:39:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (tot != NULL) *tot = free;
|
|
|
|
return true;
|
|
|
|
#endif
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 00:53:09 +00:00
|
|
|
bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb)
|
2004-12-24 00:00:10 +00:00
|
|
|
{
|
2006-08-05 00:53:09 +00:00
|
|
|
char filename[MAX_PATH];
|
2004-12-24 00:00:10 +00:00
|
|
|
|
2006-08-05 00:53:09 +00:00
|
|
|
snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name);
|
2007-03-06 22:37:04 +00:00
|
|
|
return stat(filename, sb) == 0;
|
|
|
|
}
|
2004-12-27 10:40:04 +00:00
|
|
|
|
2007-03-06 22:37:04 +00:00
|
|
|
bool FiosIsHiddenFile(const struct dirent *ent)
|
|
|
|
{
|
|
|
|
return ent->d_name[0] == '.';
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 20:41:24 +00:00
|
|
|
void ShowInfo(const char *str)
|
2004-12-24 00:00:10 +00:00
|
|
|
{
|
2004-12-28 12:11:34 +00:00
|
|
|
HAB hab;
|
|
|
|
HMQ hmq;
|
|
|
|
ULONG rc;
|
2005-01-06 18:45:28 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* init PM env. */
|
2004-12-28 12:11:34 +00:00
|
|
|
hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* display the box */
|
2007-06-24 20:41:24 +00:00
|
|
|
rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, (const unsigned char *)str, (const unsigned char *)"OpenTTD", 0, MB_OK | MB_MOVEABLE | MB_INFORMATION);
|
2004-12-28 12:11:34 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* terminate PM env. */
|
2004-12-28 12:11:34 +00:00
|
|
|
WinDestroyMsgQueue(hmq);
|
|
|
|
WinTerminate(hab);
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 20:54:52 +00:00
|
|
|
void ShowOSErrorBox(const char *buf, bool system)
|
2004-12-24 00:00:10 +00:00
|
|
|
{
|
2004-12-28 12:11:34 +00:00
|
|
|
HAB hab;
|
|
|
|
HMQ hmq;
|
|
|
|
ULONG rc;
|
2005-01-06 18:45:28 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* init PM env. */
|
2004-12-28 12:11:34 +00:00
|
|
|
hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* display the box */
|
2007-06-24 20:41:24 +00:00
|
|
|
rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, (const unsigned char *)buf, (const unsigned char *)"OpenTTD", 0, MB_OK | MB_MOVEABLE | MB_ERROR);
|
2004-12-28 12:11:34 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* terminate PM env. */
|
2004-12-28 12:11:34 +00:00
|
|
|
WinDestroyMsgQueue(hmq);
|
|
|
|
WinTerminate(hab);
|
2004-12-24 00:00:10 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 00:31:47 +00:00
|
|
|
int CDECL main(int argc, char *argv[])
|
2004-12-24 00:00:10 +00:00
|
|
|
{
|
2007-11-21 19:13:38 +00:00
|
|
|
SetRandomSeed(time(NULL));
|
2004-12-24 00:00:10 +00:00
|
|
|
|
|
|
|
return ttd_main(argc, argv);
|
|
|
|
}
|
|
|
|
|
2005-06-02 10:39:46 +00:00
|
|
|
/**
|
|
|
|
* Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard
|
|
|
|
* and append this up to the maximum length (either absolute or screenlength). If maxlength
|
|
|
|
* is zero, we don't care about the screenlength but only about the physical length of the string
|
2007-04-17 21:09:38 +00:00
|
|
|
* @param tb Textbuf type to be changed
|
2007-07-30 13:36:09 +00:00
|
|
|
* @return Return true on successful change of Textbuf, or false otherwise
|
2005-06-02 10:39:46 +00:00
|
|
|
*/
|
2005-03-11 14:14:54 +00:00
|
|
|
bool InsertTextBufferClipboard(Textbuf *tb)
|
|
|
|
{
|
2007-01-10 19:39:54 +00:00
|
|
|
/* XXX -- Currently no clipboard support implemented with GCC */
|
|
|
|
#ifndef __INNOTEK_LIBC__
|
2005-06-02 19:55:37 +00:00
|
|
|
HAB hab = 0;
|
2005-03-19 22:36:13 +00:00
|
|
|
|
|
|
|
if (WinOpenClipbrd(hab))
|
|
|
|
{
|
2009-01-10 00:31:47 +00:00
|
|
|
const char *text = (const char*)WinQueryClipbrdData(hab, CF_TEXT);
|
2005-06-02 10:39:46 +00:00
|
|
|
|
2005-06-02 19:55:37 +00:00
|
|
|
if (text != NULL)
|
|
|
|
{
|
|
|
|
uint length = 0;
|
|
|
|
uint width = 0;
|
2009-01-10 00:31:47 +00:00
|
|
|
const char *i;
|
2005-03-19 22:36:13 +00:00
|
|
|
|
2005-06-02 19:55:37 +00:00
|
|
|
for (i = text; IsValidAsciiChar(*i); i++)
|
|
|
|
{
|
|
|
|
uint w;
|
2005-06-02 10:39:46 +00:00
|
|
|
|
2008-10-22 20:23:50 +00:00
|
|
|
if (tb->size + length + 1 > tb->maxsize) break;
|
2005-06-02 10:39:46 +00:00
|
|
|
|
2006-05-09 15:43:40 +00:00
|
|
|
w = GetCharacterWidth(FS_NORMAL, (byte)*i);
|
2005-06-02 19:55:37 +00:00
|
|
|
if (tb->maxwidth != 0 && width + tb->width + w > tb->maxwidth) break;
|
2005-06-02 10:39:46 +00:00
|
|
|
|
2005-06-02 19:55:37 +00:00
|
|
|
width += w;
|
|
|
|
length++;
|
|
|
|
}
|
|
|
|
|
2008-10-22 20:23:50 +00:00
|
|
|
memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->size - tb->caretpos);
|
2005-06-02 19:55:37 +00:00
|
|
|
memcpy(tb->buf + tb->caretpos, text, length);
|
|
|
|
tb->width += width;
|
|
|
|
tb->caretxoffs += width;
|
2008-10-22 20:23:50 +00:00
|
|
|
tb->size += length;
|
2005-06-02 19:55:37 +00:00
|
|
|
tb->caretpos += length;
|
|
|
|
|
|
|
|
WinCloseClipbrd(hab);
|
|
|
|
return true;
|
|
|
|
}
|
2005-06-02 10:39:46 +00:00
|
|
|
|
2005-06-02 19:55:37 +00:00
|
|
|
WinCloseClipbrd(hab);
|
|
|
|
}
|
2007-01-10 19:39:54 +00:00
|
|
|
#endif
|
2005-06-02 19:55:37 +00:00
|
|
|
return false;
|
2005-03-11 14:14:54 +00:00
|
|
|
}
|
2005-06-02 09:51:01 +00:00
|
|
|
|
2005-07-22 16:14:24 +00:00
|
|
|
|
|
|
|
void CSleep(int milliseconds)
|
|
|
|
{
|
2007-01-10 19:39:54 +00:00
|
|
|
#ifndef __INNOTEK_LIBC__
|
2007-04-18 22:41:53 +00:00
|
|
|
delay(milliseconds);
|
2007-01-10 19:39:54 +00:00
|
|
|
#else
|
|
|
|
usleep(milliseconds * 1000);
|
|
|
|
#endif
|
2005-07-22 16:14:24 +00:00
|
|
|
}
|
2006-11-28 14:42:31 +00:00
|
|
|
|
|
|
|
const char *FS2OTTD(const char *name) {return name;}
|
|
|
|
const char *OTTD2FS(const char *name) {return name;}
|