Mercurial > hg > early-roguelike
comparison rogue4/mdport.c @ 12:9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
| author | edwarj4 |
|---|---|
| date | Sat, 24 Oct 2009 16:52:52 +0000 |
| parents | |
| children | 107a467612fb |
comparison
equal
deleted
inserted
replaced
| 11:949d558c2162 | 12:9535a08ddc39 |
|---|---|
| 1 /* | |
| 2 mdport.c - Machine Dependent | |
| 3 | |
| 4 Copyright (C) 2005-2008 Nicholas J. Kisseberth | |
| 5 All rights reserved. | |
| 6 | |
| 7 Redistribution and use in source and binary forms, with or without | |
| 8 modification, are permitted provided that the following conditions | |
| 9 are met: | |
| 10 1. Redistributions of source code must retain the above copyright | |
| 11 notice, this list of conditions and the following disclaimer. | |
| 12 2. Redistributions in binary form must reproduce the above copyright | |
| 13 notice, this list of conditions and the following disclaimer in the | |
| 14 documentation and/or other materials provided with the distribution. | |
| 15 3. Neither the name(s) of the author(s) nor the names of other contributors | |
| 16 may be used to endorse or promote products derived from this software | |
| 17 without specific prior written permission. | |
| 18 | |
| 19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS ``AS IS'' AND | |
| 20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 22 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE | |
| 23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
| 25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 26 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
| 28 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 29 SUCH DAMAGE. | |
| 30 */ | |
| 31 | |
| 32 #if defined(_WIN32) | |
| 33 #include <Windows.h> | |
| 34 #include <Lmcons.h> | |
| 35 #include <process.h> | |
| 36 #include <shlobj.h> | |
| 37 #include <sys/types.h> | |
| 38 #include <io.h> | |
| 39 #include <conio.h> | |
| 40 #undef MOUSE_MOVED | |
| 41 #elif defined(__DJGPP__) | |
| 42 #include <process.h> | |
| 43 #else | |
| 44 #include <pwd.h> | |
| 45 #include <sys/utsname.h> | |
| 46 #include <unistd.h> | |
| 47 #include <utmpx.h> | |
| 48 #endif | |
| 49 | |
| 50 #ifdef __INTERIX | |
| 51 char *strdup(const char *s); | |
| 52 #endif | |
| 53 | |
| 54 #include <stdlib.h> | |
| 55 #include <string.h> | |
| 56 | |
| 57 #if defined(_WIN32) && !defined(__MINGW32__) | |
| 58 #define PATH_MAX MAX_PATH | |
| 59 #endif | |
| 60 | |
| 61 #include <curses.h> | |
| 62 #if !defined(DJGPP) | |
| 63 #include <term.h> | |
| 64 #endif | |
| 65 | |
| 66 #include <stdio.h> | |
| 67 #include <fcntl.h> | |
| 68 #include <limits.h> | |
| 69 #include <sys/stat.h> | |
| 70 #include <signal.h> | |
| 71 | |
| 72 #define MOD_MOVE(c) (toupper(c) ) | |
| 73 | |
| 74 void | |
| 75 md_init() | |
| 76 { | |
| 77 #ifdef __INTERIX | |
| 78 char *term; | |
| 79 | |
| 80 term = getenv("TERM"); | |
| 81 | |
| 82 if (term == NULL) | |
| 83 setenv("TERM","interix",1); | |
| 84 #endif | |
| 85 #if defined(__DJGPP__) || defined(_WIN32) | |
| 86 _fmode = _O_BINARY; | |
| 87 #endif | |
| 88 #if defined(__CYGWIN__) || defined(__MSYS__) | |
| 89 ESCDELAY=250; | |
| 90 #endif | |
| 91 } | |
| 92 | |
| 93 int | |
| 94 md_hasclreol() | |
| 95 { | |
| 96 #ifdef CE | |
| 97 return((CE != NULL) && (*CE != 0)); | |
| 98 #elif defined (clr_eol) | |
| 99 return((clr_eol != NULL) && (*clr_eol != 0)); | |
| 100 #elif !defined(__PDCURSES__) | |
| 101 return(clr_eol != NULL); | |
| 102 #else | |
| 103 return(TRUE); | |
| 104 #endif | |
| 105 } | |
| 106 | |
| 107 void | |
| 108 md_putchar(int c) | |
| 109 { | |
| 110 putchar(c); | |
| 111 } | |
| 112 | |
| 113 static int md_standout_mode = 0; | |
| 114 | |
| 115 void | |
| 116 md_raw_standout() | |
| 117 { | |
| 118 #ifdef _WIN32 | |
| 119 CONSOLE_SCREEN_BUFFER_INFO csbiInfo; | |
| 120 HANDLE hStdout; | |
| 121 int fgattr,bgattr; | |
| 122 | |
| 123 if (md_standout_mode == 0) | |
| 124 { | |
| 125 hStdout = GetStdHandle(STD_OUTPUT_HANDLE); | |
| 126 GetConsoleScreenBufferInfo(hStdout, &csbiInfo); | |
| 127 fgattr = (csbiInfo.wAttributes & 0xF); | |
| 128 bgattr = (csbiInfo.wAttributes & 0xF0); | |
| 129 SetConsoleTextAttribute(hStdout,(fgattr << 4) | (bgattr >> 4)); | |
| 130 md_standout_mode = 1; | |
| 131 } | |
| 132 #elif defined(SO) | |
| 133 tputs(SO,0,md_putchar); | |
| 134 fflush(stdout); | |
| 135 #endif | |
| 136 } | |
| 137 | |
| 138 void | |
| 139 md_raw_standend() | |
| 140 { | |
| 141 #ifdef _WIN32 | |
| 142 CONSOLE_SCREEN_BUFFER_INFO csbiInfo; | |
| 143 HANDLE hStdout; | |
| 144 int fgattr,bgattr; | |
| 145 | |
| 146 if (md_standout_mode == 1) | |
| 147 { | |
| 148 hStdout = GetStdHandle(STD_OUTPUT_HANDLE); | |
| 149 GetConsoleScreenBufferInfo(hStdout, &csbiInfo); | |
| 150 fgattr = (csbiInfo.wAttributes & 0xF); | |
| 151 bgattr = (csbiInfo.wAttributes & 0xF0); | |
| 152 SetConsoleTextAttribute(hStdout,(fgattr << 4) | (bgattr >> 4)); | |
| 153 md_standout_mode = 0; | |
| 154 } | |
| 155 #elif defined(SE) | |
| 156 tputs(SE,0,md_putchar); | |
| 157 fflush(stdout); | |
| 158 #endif | |
| 159 } | |
| 160 | |
| 161 int | |
| 162 md_unlink_open_file(char *file, int inf) | |
| 163 { | |
| 164 #ifdef _WIN32 | |
| 165 _close(inf); | |
| 166 _chmod(file, 0600); | |
| 167 return( _unlink(file) ); | |
| 168 #else | |
| 169 return(unlink(file)); | |
| 170 #endif | |
| 171 } | |
| 172 | |
| 173 int | |
| 174 md_unlink(char *file) | |
| 175 { | |
| 176 #ifdef _WIN32 | |
| 177 _chmod(file, 0600); |
