tron@2186: /* $Id$ */ tron@2186: truelight@0: #include "stdafx.h" Darkvater@1892: #include "openttd.h" tron@2163: #include "functions.h" Darkvater@1390: #include "window.h" tron@1317: #include "string.h" tron@507: #include "table/strings.h" truelight@0: #include "hal.h" tron@2159: #include "variables.h" truelight@0: truelight@0: #include truelight@0: #include truelight@0: #include truelight@0: #include tron@1509: #include truelight@0: tron@2323: #ifdef USE_HOMEDIR tron@2323: #include tron@2323: #endif tron@2323: tron@1850: #if (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__) tron@1597: #define HAS_STATVFS tron@1597: #endif tron@1597: tron@1597: #ifdef HAS_STATVFS truelight@0: #include truelight@0: #endif truelight@0: truelight@0: truelight@0: #ifdef __MORPHOS__ truelight@0: #include truelight@0: ULONG __stack = (1024*1024)*2; // maybe not that much is needed actually ;) tron@2356: tron@2356: // The system supplied definition of SIG_IGN does not match tron@2356: #undef SIG_IGN tron@2356: #define SIG_IGN (void (*)(int))1 truelight@0: #endif /* __MORPHOS__ */ truelight@0: bjarni@770: #ifdef __AMIGA__ bjarni@770: #warning add stack symbol to avoid that user needs to set stack manually (tokai) tron@915: // ULONG __stack = bjarni@770: #endif bjarni@770: bjarni@2188: #if defined(__APPLE__) bjarni@2217: #if defined(WITH_SDL) bjarni@2217: //the mac implementation needs this file included in the same file as main() bjarni@2217: #include bjarni@2217: #endif bjarni@2188: #endif bjarni@2188: truelight@0: static char *_fios_path; truelight@0: static char *_fios_save_path; truelight@0: static char *_fios_scn_path; truelight@0: static FiosItem *_fios_items; truelight@0: static int _fios_count, _fios_alloc; truelight@0: tron@1093: static FiosItem *FiosAlloc(void) truelight@0: { truelight@0: if (_fios_count == _fios_alloc) { truelight@0: _fios_alloc += 256; truelight@0: _fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem)); truelight@0: } truelight@0: return &_fios_items[_fios_count++]; truelight@0: } truelight@0: tron@1486: int compare_FiosItems(const void *a, const void *b) tron@1486: { tron@1486: const FiosItem *da = (const FiosItem *)a; tron@1486: const FiosItem *db = (const FiosItem *)b; truelight@0: int r; truelight@0: tron@2526: if (_savegame_sort_order & SORT_BY_NAME) { tron@2526: r = strcasecmp(da->title, db->title); tron@2526: } else { tron@1486: r = da->mtime < db->mtime ? -1 : 1; tron@2526: } truelight@0: tron@2526: if (_savegame_sort_order & SORT_DESCENDING) r = -r; truelight@0: return r; truelight@0: } truelight@0: truelight@0: truelight@0: // Get a list of savegames truelight@0: FiosItem *FiosGetSavegameList(int *num, int mode) truelight@0: { truelight@0: FiosItem *fios; truelight@0: DIR *dir; truelight@0: struct dirent *dirent; truelight@0: struct stat sb; truelight@0: int sort_start; truelight@0: char filename[MAX_PATH]; truelight@0: truelight@0: if (_fios_save_path == NULL) { truelight@0: _fios_save_path = malloc(MAX_PATH); truelight@0: strcpy(_fios_save_path, _path.save_dir); truelight@0: } truelight@0: Darkvater@2099: _fios_path = _fios_save_path; truelight@193: truelight@0: // Parent directory, only if not in root already. tron@1470: if (_fios_path[1] != '\0') { truelight@0: fios = FiosAlloc(); truelight@0: fios->type = FIOS_TYPE_PARENT; truelight@0: fios->mtime = 0; tron@1572: strcpy(fios->name, ".."); pasky@1449: strcpy(fios->title, ".. (Parent directory)"); truelight@0: } truelight@0: truelight@0: // Show subdirectories first tron@2334: dir = opendir(_fios_path); truelight@0: if (dir != NULL) { tron@1470: while ((dirent = readdir(dir)) != NULL) { tron@1470: snprintf(filename, lengthof(filename), "%s/%s", tron@1470: _fios_path, dirent->d_name); tron@1470: if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) && tron@1470: dirent->d_name[0] != '.') { pasky@1449: fios = FiosAlloc(); pasky@1449: fios->type = FIOS_TYPE_DIR; tron@1486: fios->mtime = 0; tron@1486: ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); tron@1486: snprintf(fios->title, lengthof(fios->title), tron@1486: "%s/ (Directory)", dirent->d_name); peter1138@2940: str_validate(fios->title); truelight@0: } truelight@0: } truelight@0: closedir(dir); truelight@0: } truelight@0: darkvater@307: { darkvater@307: /* XXX ugly global variables ... */ darkvater@307: byte order = _savegame_sort_order; tron@2526: _savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING; darkvater@307: qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems); darkvater@307: _savegame_sort_order = order; darkvater@307: } darkvater@307: truelight@0: // this is where to start sorting truelight@0: sort_start = _fios_count; truelight@0: tron@1486: /* Show savegame files tron@1486: * .SAV OpenTTD saved game tron@1486: * .SS1 Transport Tycoon Deluxe preset game tron@1486: * .SV1 Transport Tycoon Deluxe (Patch) saved game tron@1486: * .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game truelight@0: */ tron@2334: dir = opendir(_fios_path); truelight@0: if (dir != NULL) { tron@1486: while ((dirent = readdir(dir)) != NULL) { pasky@1449: char *t; pasky@1449: tron@1470: snprintf(filename, lengthof(filename), "%s/%s", tron@1470: _fios_path, dirent->d_name); tron@1470: if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue; pasky@1449: pasky@1449: t = strrchr(dirent->d_name, '.'); tron@2338: if (t == NULL) continue; tron@2338: tron@2338: if (strcasecmp(t, ".sav") == 0) { // OpenTTD pasky@1449: fios = FiosAlloc(); pasky@1449: fios->type = FIOS_TYPE_FILE; pasky@1449: fios->mtime = sb.st_mtime; tron@1486: ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); Darkvater@2099: Darkvater@2099: *t = '\0'; // strip extension Darkvater@2099: ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); peter1138@2940: str_validate(fios->title); pasky@1449: } else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { tron@2338: if (strcasecmp(t, ".ss1") == 0 || tron@2338: strcasecmp(t, ".sv1") == 0 || tron@2338: strcasecmp(t, ".sv2") == 0) { // TTDLX(Patch) pasky@1449: fios = FiosAlloc(); pasky@1449: fios->type = FIOS_TYPE_OLDFILE; pasky@1449: fios->mtime = sb.st_mtime; tron@1486: ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); pasky@1449: GetOldSaveGameName(fios->title, filename); truelight@0: } truelight@0: } truelight@0: } truelight@0: closedir(dir); truelight@0: } truelight@0: tron@1486: qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); truelight@0: *num = _fios_count; truelight@0: return _fios_items; truelight@0: } truelight@0: truelight@0: // Get a list of scenarios pasky@1449: // FIXME: Gross code duplication with FiosGetSavegameList() truelight@0: FiosItem *FiosGetScenarioList(int *num, int mode) truelight@0: { truelight@0: FiosItem *fios; truelight@0: DIR *dir; truelight@0: struct dirent *dirent; truelight@0: struct stat sb; truelight@0: int sort_start; truelight@0: char filename[MAX_PATH]; truelight@0: truelight@0: if (_fios_scn_path == NULL) { truelight@0: _fios_scn_path = malloc(MAX_PATH); truelight@0: strcpy(_fios_scn_path, _path.scenario_dir); truelight@0: } tron@2334: truelight@0: _fios_path = _fios_scn_path; truelight@0: tron@1486: // Parent directory, only if not of the type C:\. tron@1486: if (_fios_path[1] != '\0' && mode != SLD_NEW_GAME) { tron@1486: fios = FiosAlloc(); tron@1486: fios->type = FIOS_TYPE_PARENT; tron@1486: fios->mtime = 0; tron@1486: strcpy(fios->title, ".. (Parent directory)"); tron@1486: } tron@1486: truelight@0: // Show subdirectories first tron@2334: dir = opendir(_fios_path); truelight@0: if (dir != NULL) { tron@1470: while ((dirent = readdir(dir)) != NULL) { tron@1470: snprintf(filename, lengthof(filename), "%s/%s", tron@1470: _fios_path, dirent->d_name); tron@1470: if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) && tron@1470: dirent->d_name[0] != '.') { pasky@1449: fios = FiosAlloc(); pasky@1449: fios->type = FIOS_TYPE_DIR; tron@1486: fios->mtime = 0; tron@1486: ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); Darkvater@2099: snprintf(fios->title, lengthof(fios->title), "%s/ (Directory)", dirent->d_name); peter1138@2940: str_validate(fios->title); truelight@0: } truelight@0: } truelight@0: closedir(dir); truelight@0: } truelight@0: tron@2334: { tron@2334: /* XXX ugly global variables ... */ tron@2334: byte order = _savegame_sort_order; tron@2526: _savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING; tron@2334: qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems); tron@2334: _savegame_sort_order = order; tron@2334: } tron@2334: truelight@0: // this is where to start sorting truelight@0: sort_start = _fios_count; truelight@0: tron@1486: /* Show scenario files tron@1486: * .SCN OpenTTD style scenario file tron@1486: * .SV0 Transport Tycoon Deluxe (Patch) scenario tron@1486: * .SS0 Transport Tycoon Deluxe preset scenario truelight@0: */ tron@2334: dir = opendir(_fios_path); truelight@0: if (dir != NULL) { tron@1470: while ((dirent = readdir(dir)) != NULL) { pasky@1449: char *t; pasky@1449: Darkvater@2099: snprintf(filename, lengthof(filename), "%s/%s", _fios_path, dirent->d_name); tron@1470: if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue; pasky@1449: pasky@1449: t = strrchr(dirent->d_name, '.'); tron@2338: if (t == NULL) continue; tron@2338: tron@2338: if (strcasecmp(t, ".scn") == 0) { // OpenTTD pasky@1449: fios = FiosAlloc(); pasky@1449: fios->type = FIOS_TYPE_SCENARIO; pasky@1449: fios->mtime = sb.st_mtime; tron@1486: ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); Darkvater@2099: tron@2334: *t = '\0'; // strip extension Darkvater@2099: ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); peter1138@2940: str_validate(fios->title); tron@1470: } else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || tron@1470: mode == SLD_NEW_GAME) { tron@2338: if (strcasecmp(t, ".sv0") == 0 || tron@2338: strcasecmp(t, ".ss0") == 0) { // TTDLX(Patch) pasky@1449: fios = FiosAlloc(); pasky@1449: fios->type = FIOS_TYPE_OLD_SCENARIO; pasky@1449: fios->mtime = sb.st_mtime; pasky@1449: GetOldScenarioGameName(fios->title, filename); tron@1486: ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); truelight@0: } truelight@0: } truelight@0: } truelight@0: closedir(dir); truelight@0: } truelight@0: tron@1486: qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); truelight@0: *num = _fios_count; truelight@0: return _fios_items; truelight@0: } truelight@0: truelight@0: truelight@0: // Free the list of savegames tron@1093: void FiosFreeSavegameList(void) truelight@0: { truelight@0: free(_fios_items); truelight@0: _fios_items = NULL; truelight@0: _fios_alloc = _fios_count = 0; truelight@0: } truelight@0: truelight@0: // Browse to truelight@0: char *FiosBrowseTo(const FiosItem *item) truelight@0: { truelight@0: char *path = _fios_path; truelight@0: char *s; truelight@0: tron@1470: switch (item->type) { tron@1470: case FIOS_TYPE_PARENT: tron@1470: s = strrchr(path, '/'); tron@2334: if (s != path) tron@2334: s[0] = '\0'; tron@2334: else tron@2334: s[1] = '\0'; tron@1470: break; truelight@0: tron@1470: case FIOS_TYPE_DIR: tron@2334: if (path[1] != '\0') strcat(path, "/"); tron@1470: strcat(path, item->name); tron@1470: break; truelight@0: Darkvater@2559: case FIOS_TYPE_DIRECT: Darkvater@2560: sprintf(path, "%s/", item->name); Darkvater@2560: s = strrchr(path, '/'); Darkvater@2560: if (s[1] == '\0') s[0] = '\0'; // strip trailing slash Darkvater@2559: break; Darkvater@2559: tron@1470: case FIOS_TYPE_FILE: tron@1470: case FIOS_TYPE_OLDFILE: tron@1486: case FIOS_TYPE_SCENARIO: tron@1486: case FIOS_TYPE_OLD_SCENARIO: { tron@1486: static char str_buffr[512]; truelight@193: tron@1486: sprintf(str_buffr, "%s/%s", path, item->name); tron@1470: return str_buffr; tron@1486: } truelight@0: } truelight@0: truelight@0: return NULL; truelight@0: } truelight@0: darkvater@1596: /** darkvater@1596: * Get descriptive texts. Returns the path and free space darkvater@1596: * left on the device darkvater@1596: * @param path string describing the path darkvater@1596: * @param tfs total free space in megabytes, optional (can be NULL) darkvater@1596: * @return StringID describing the path (free space or failure) darkvater@1596: */ darkvater@1596: StringID FiosGetDescText(const char **path, uint32 *tot) truelight@0: { darkvater@1596: uint32 free = 0; tron@2338: *path = _fios_path; truelight@0: tron@1597: #ifdef HAS_STATVFS truelight@0: { tron@1470: struct statvfs s; truelight@0: tron@1597: if (statvfs(*path, &s) == 0) { tron@1597: free = (uint64)s.f_frsize * s.f_bavail >> 20; tron@1470: } else tron@1470: return STR_4006_UNABLE_TO_READ_DRIVE; truelight@0: } darkvater@1596: #endif darkvater@1596: if (tot != NULL) *tot = free; truelight@193: return STR_4005_BYTES_FREE; truelight@0: } truelight@0: celestar@9948: void FiosMakeSavegameName(char *buf, const char *name, size_t size) truelight@0: { tron@1508: const char* extension; tron@1508: const char* period; tron@1508: tron@1470: if (_game_mode == GM_EDITOR) tron@1508: extension = ".scn"; truelight@0: else tron@1508: extension = ".sav"; tron@1508: tron@1508: // Don't append the extension, if it is already there tron@1508: period = strrchr(name, '.'); tron@1508: if (period != NULL && strcasecmp(period, extension) == 0) extension = ""; tron@1508: celestar@9948: snprintf(buf, size, "%s/%s%s", _fios_path, name, extension); truelight@0: } truelight@0: tron@2255: bool FiosDelete(const char *name) truelight@0: { tron@1336: char path[512]; tron@1336: celestar@9948: FiosMakeSavegameName(path, name, sizeof(path)); tron@2255: return unlink(path) == 0; truelight@0: } truelight@0: truelight@0: bool FileExists(const char *filename) truelight@0: { truelight@193: return access(filename, 0) == 0; truelight@0: } truelight@0: truelight@0: static int LanguageCompareFunc(const void *a, const void *b) truelight@0: { darkvater@222: return strcmp(*(const char* const *)a, *(const char* const *)b); truelight@0: } truelight@0: truelight@0: int GetLanguageList(char **languages, int max) truelight@0: { truelight@0: DIR *dir; truelight@0: struct dirent *dirent; truelight@0: int num = 0; truelight@0: truelight@0: dir = opendir(_path.lang_dir); truelight@0: if (dir != NULL) { tron@1470: while ((dirent = readdir(dir)) != NULL) { truelight@0: char *t = strrchr(dirent->d_name, '.'); tron@1470: tron@1470: if (t != NULL && strcmp(t, ".lng") == 0) { truelight@0: languages[num++] = strdup(dirent->d_name); truelight@0: if (num == max) break; truelight@0: } truelight@0: } truelight@0: closedir(dir); truelight@0: } truelight@193: truelight@0: qsort(languages, num, sizeof(char*), LanguageCompareFunc); truelight@0: return num; truelight@0: } truelight@0: tron@1050: #if defined(__BEOS__) || defined(__linux__) tron@410: static void ChangeWorkingDirectory(char *exe) truelight@0: { truelight@0: char *s = strrchr(exe, '/'); truelight@0: if (s != NULL) { tron@1470: *s = '\0'; truelight@0: chdir(exe); truelight@0: *s = '/'; truelight@0: } truelight@0: } tron@1050: #endif truelight@0: truelight@0: void ShowInfo(const char *str) truelight@0: { truelight@0: puts(str); truelight@0: } truelight@0: truelight@0: void ShowOSErrorBox(const char *buf) truelight@0: { bjarni@2731: #if defined(__APPLE__) bjarni@2188: // this creates an NSAlertPanel with the contents of 'buf' bjarni@2188: // this is the native and nicest way to do this on OSX bjarni@2188: ShowMacDialog( buf, "See readme for more info\nMost likely you are missing files from the original TTD", "Quit" ); bjarni@529: #else bjarni@529: // all systems, but OSX truelight@0: fprintf(stderr, "\033[1;31mError: %s\033[0;39m\n", buf); truelight@0: #endif truelight@0: } truelight@0: bjarni@2736: #ifdef WITH_COCOA bjarni@2736: void cocoaSetWorkingDirectory(void); bjarni@2736: void cocoaSetupAutoreleasePool(void); bjarni@2736: void cocoaReleaseAutoreleasePool(void); bjarni@2736: #endif bjarni@2736: truelight@0: int CDECL main(int argc, char* argv[]) truelight@0: { bjarni@2736: int ret; bjarni@2736: bjarni@2736: #ifdef WITH_COCOA bjarni@2736: cocoaSetupAutoreleasePool(); bjarni@2736: /* This is passed if we are launched by double-clicking */ bjarni@2736: if(argc >= 2 && strncmp (argv[1], "-psn", 4) == 0) { bjarni@2736: argv[1] = NULL; bjarni@2736: argc = 1; bjarni@2736: cocoaSetWorkingDirectory(); bjarni@2736: } bjarni@2736: #endif bjarni@2736: truelight@0: // change the working directory to enable doubleclicking in UIs tron@1050: #if defined(__BEOS__) || defined(__linux__) truelight@0: ChangeWorkingDirectory(argv[0]); truelight@0: #endif truelight@0: signde@206: _random_seeds[0][1] = _random_seeds[0][0] = time(NULL); ludde@2073: SeedMT(_random_seeds[0][1]); truelight@0: tron@1509: signal(SIGPIPE, SIG_IGN); truelight@0: bjarni@2736: ret = ttd_main(argc, argv); bjarni@2736: bjarni@2736: #ifdef WITH_COCOA bjarni@2736: cocoaReleaseAutoreleasePool(); bjarni@2736: #endif bjarni@2736: bjarni@2736: return ret; truelight@0: } truelight@0: tron@1093: void DeterminePaths(void) truelight@0: { truelight@0: char *s; truelight@0: tron@1470: _path.game_data_dir = malloc(MAX_PATH); bjarni@561: ttd_strlcpy(_path.game_data_dir, GAME_DATA_DIR, MAX_PATH); bjarni@561: #if defined SECOND_DATA_DIR tron@1470: _path.second_data_dir = malloc(MAX_PATH); tron@1470: ttd_strlcpy(_path.second_data_dir, SECOND_DATA_DIR, MAX_PATH); bjarni@561: #endif truelight@0: truelight@0: #if defined(USE_HOMEDIR) truelight@0: { tron@1470: const char *homedir = getenv("HOME"); truelight@193: tron@1470: if (homedir == NULL) { tron@1470: const struct passwd *pw = getpwuid(getuid()); tron@1470: if (pw != NULL) homedir = pw->pw_dir; truelight@0: } truelight@193: truelight@0: _path.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); truelight@0: } truelight@193: truelight@0: #else /* not defined(USE_HOMEDIR) */ truelight@0: tron@1470: _path.personal_dir = malloc(MAX_PATH); bjarni@561: ttd_strlcpy(_path.personal_dir, PERSONAL_DIR, MAX_PATH); truelight@193: truelight@0: // check if absolute or relative path truelight@0: s = strchr(_path.personal_dir, '/'); truelight@193: truelight@0: // add absolute path tron@1470: if (s == NULL || _path.personal_dir != s) { truelight@0: getcwd(_path.personal_dir, MAX_PATH); truelight@0: s = strchr(_path.personal_dir, 0); truelight@0: *s++ = '/'; bjarni@561: ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH); truelight@0: } truelight@193: truelight@0: #endif /* defined(USE_HOMEDIR) */ truelight@0: truelight@0: s = strchr(_path.personal_dir, 0); truelight@193: truelight@0: // append a / ? tron@1470: if (s[-1] != '/') strcpy(s, "/"); truelight@193: truelight@0: _path.save_dir = str_fmt("%ssave", _path.personal_dir); truelight@0: _path.autosave_dir = str_fmt("%s/autosave", _path.save_dir); truelight@0: _path.scenario_dir = str_fmt("%sscenario", _path.personal_dir); truelight@0: _path.gm_dir = str_fmt("%sgm/", _path.game_data_dir); truelight@0: _path.data_dir = str_fmt("%sdata/", _path.game_data_dir); Darkvater@1482: Darkvater@1482: if (_config_file == NULL) Darkvater@1482: _config_file = str_fmt("%sopenttd.cfg", _path.personal_dir); Darkvater@1482: darkvater@983: _highscore_file = str_fmt("%shs.dat", _path.personal_dir); truelight@704: _log_file = str_fmt("%sopenttd.log", _path.personal_dir); tron@915: bjarni@561: #if defined CUSTOM_LANG_DIR bjarni@561: // sets the search path for lng files to the custom one bjarni@561: _path.lang_dir = malloc( MAX_PATH ); bjarni@561: ttd_strlcpy( _path.lang_dir, CUSTOM_LANG_DIR, MAX_PATH); bjarni@561: #else truelight@0: _path.lang_dir = str_fmt("%slang/", _path.game_data_dir); bjarni@561: #endif truelight@193: dominik@238: // create necessary folders dominik@238: mkdir(_path.personal_dir, 0755); truelight@0: mkdir(_path.save_dir, 0755); truelight@0: mkdir(_path.autosave_dir, 0755); truelight@0: mkdir(_path.scenario_dir, 0755); truelight@0: } truelight@0: tron@1470: bool InsertTextBufferClipboard(Textbuf *tb) tron@1470: { tron@1470: return false; tron@1470: } Darkvater@1885: ludde@2073: ludde@2073: // multi os compatible sleep function ludde@2073: ludde@2073: #ifdef __AMIGA__ ludde@2073: // usleep() implementation ludde@2073: # include ludde@2073: # include ludde@2073: ludde@2073: extern struct Device *TimerBase = NULL; ludde@2073: extern struct MsgPort *TimerPort = NULL; ludde@2073: extern struct timerequest *TimerRequest = NULL; ludde@2073: #endif // __AMIGA__ ludde@2073: ludde@2073: void CSleep(int milliseconds) ludde@2073: { ludde@2073: #if !defined(__BEOS__) && !defined(__AMIGA__) ludde@2073: usleep(milliseconds * 1000); ludde@2073: #endif ludde@2073: #ifdef __BEOS__ ludde@2073: snooze(milliseconds * 1000); ludde@2073: #endif ludde@2073: #if defined(__AMIGA__) ludde@2073: { ludde@2073: ULONG signals; ludde@2073: ULONG TimerSigBit = 1 << TimerPort->mp_SigBit; ludde@2073: ludde@2073: // send IORequest ludde@2073: TimerRequest->tr_node.io_Command = TR_ADDREQUEST; ludde@2073: TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000; ludde@2073: TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000; ludde@2073: SendIO((struct IORequest *)TimerRequest); ludde@2073: ludde@2073: if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) { ludde@2073: AbortIO((struct IORequest *)TimerRequest); ludde@2073: } ludde@2073: WaitIO((struct IORequest *)TimerRequest); ludde@2073: } ludde@2073: #endif // __AMIGA__ ludde@2073: }