doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
macosx_sys.mm
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 // -*- mode: objc -*-
30 #import "../../idlib/precompiled.h"
31 
32 #import "macosx_local.h"
33 #import "macosx_sys.h"
34 
35 #import "macosx_common.h"
36 #import "dlfcn.h"
37 
38 #import <AppKit/AppKit.h>
39 
40 #import <sys/types.h>
41 #import <unistd.h>
42 #import <sys/param.h>
43 #import <sys/mount.h>
44 #import <sys/wait.h>
45 
46 #ifdef OMNI_TIMER
47 #import "macosx_timers.h"
48 #endif
49 
50 void Sys_Init (void);
51 
52 char *Sys_GetCurrentUser( void );
53 
54 void Sys_Error( const char *error, ...);
55 void Sys_Quit (void);
56 char *Sys_GetClipboardData( void ); // note that this isn't journaled...
57 
58 void Sys_Print( const char *msg );
59 //===========================================================================
60 
61 int main(int argc, const char *argv[]) {
62  return NSApplicationMain(argc, argv);
63 }
64 
65 //===========================================================================
66 
67 void Sys_Sleep( const int time ) {
68  sleep( time );
69 }
70 
71 void EditorPrintConsole( const char *test ) {
72 }
73 
74 /*
75 =================
76 Sys_UnloadDll
77 
78 =================
79 */
80 void Sys_UnloadDll( void *dllHandle ) {
81 }
82 
83 /*
84 =================
85 Sys_LoadDll
86 
87 Used to load a development dll instead of a virtual machine
88 =================
89 */
90 extern char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
91 
92 void *Sys_LoadDll( const char *name, int (**entryPoint)(int, ...),
93  int (*systemcalls)(int, ...) )
94 {
95  return NULL;
96 }
97 
98 //===========================================================================
99 
100 char *Sys_GetClipboardData(void) // FIXME
101 {
102  NSPasteboard *pasteboard;
103  NSArray *pasteboardTypes;
104 
105  pasteboard = [NSPasteboard generalPasteboard];
106  pasteboardTypes = [pasteboard types];
107  if ([pasteboardTypes containsObject:NSStringPboardType]) {
108  NSString *clipboardString;
109 
110  clipboardString = [pasteboard stringForType:NSStringPboardType];
111  if (clipboardString && [clipboardString length] > 0) {
112  return strdup([clipboardString cString]);
113  }
114  }
115  return NULL;
116 }
117 
118 //===========================================================================
119 
121 {
122 }
123 
125 {
126 }
127 
128 //===========================================================================
129 
130 /*
131 ================
132 Sys_Init
133 
134 The cvar and file system has been setup, so configurations are loaded
135 ================
136 */
137 void Sys_Init(void)
138 {
139 // Sys_InitNetwork();
140  Sys_InitInput();
141 }
142 
143 /*
144 =================
145 Sys_Shutdown
146 =================
147 */
148 void Sys_Shutdown(void)
149 {
150  common->Printf( "----- Sys_Shutdown -----\n" );
153  common->Printf( "------------------------\n" );
154 }
155 
156 void Sys_Error(const char *error, ...)
157 {
158  va_list argptr;
159  NSString *formattedString;
160 
161  Sys_Shutdown();
162 
163  va_start(argptr,error);
164  formattedString = [[NSString alloc] initWithFormat:[NSString stringWithCString:error] arguments:argptr];
165  va_end(argptr);
166 
167  NSLog(@"Sys_Error: %@", formattedString);
168  NSRunAlertPanel(@"DOOM Error", formattedString, nil, nil, nil);
169 
170  Sys_Quit();
171 }
172 
173 void Sys_Quit(void)
174 {
175  Sys_Shutdown();
176  [NSApp terminate:nil];
177 }
178 
179 /*
180 ================
181 Sys_Print
182 
183 This is called for all console output, even if the game is running
184 full screen and the dedicated console window is hidden.
185 ================
186 */
187 
188 char *ansiColors[8] =
189  { "\033[30m" , /* ANSI Black */
190  "\033[31m" , /* ANSI Red */
191  "\033[32m" , /* ANSI Green */
192  "\033[33m" , /* ANSI Yellow */
193  "\033[34m" , /* ANSI Blue */
194  "\033[36m" , /* ANSI Cyan */
195  "\033[35m" , /* ANSI Magenta */
196  "\033[37m" }; /* ANSI White */
197 
198 void Sys_Print(const char *text)
199 {
200 #if 0
201  /* Okay, this is a stupid hack, but what the hell, I was bored. ;) */
202  char *scan = text;
203  char code;
204  int index;
205 
206  /* Make sure terminal mode is reset at the start of the line... */
207  fputs("\033[0m", stdout);
208 
209  while(*scan) {
210  /* See if we have a color control code. If so, snarf the character,
211  print what we have so far, print the ANSI Terminal color code,
212  skip over the color control code and continue */
213  if(Q_IsColorString(scan)) {
214  index = ColorIndex(scan[1]);
215 
216  /* Flush current message */
217  if(scan != text) {
218  fwrite(text, scan - text, 1, stdout);
219  }
220 
221  /* Write ANSI color code */
222  fputs(ansiColors[index], stdout);
223 
224  /* Reset search */
225  text = scan+2;
226  scan = text;
227  continue;
228  }
229  scan++;
230  }
231 
232  /* Flush whatever's left */
233  fputs(text, stdout);
234 
235  /* Make sure terminal mode is reset at the end of the line too... */
236  fputs("\033[0m", stdout);
237 
238 #else
239  fputs(text, stdout);
240 #endif
241 }
242 
243 void OutputDebugString( const char *text ) {
244  Sys_Print( text );
245 }
246 
247 void Sys_OutputDebugString( const char *text ) {
248  OutputDebugString( text );
249 }
250 
251 /*
252 ================
253 Sys_CheckCD
254 
255 Return true if the proper CD is in the drive
256 ================
257 */
258 bool Sys_CheckCD( void ) {
260 }
void Sys_OutputDebugString(const char *text)
Definition: macosx_sys.mm:247
void Sys_BeginProfiling(void)
Definition: macosx_sys.mm:120
void Sys_Init(void)
Definition: macosx_sys.mm:137
void Sys_ShutdownInput(void)
Definition: dedicated.cpp:41
bool Sys_CheckCD(void)
Definition: macosx_sys.mm:258
void EditorPrintConsole(const char *test)
Definition: macosx_sys.mm:71
int main(int argc, const char *argv[])
Definition: macosx_sys.mm:61
void Sys_Sleep(const int time)
Definition: macosx_sys.mm:67
void Sys_Shutdown(void)
Definition: macosx_sys.mm:148
int test(char *url)
Definition: lib500.c:3
void Sys_EndProfiling(void)
Definition: macosx_sys.mm:124
void Sys_Quit(void)
Definition: macosx_sys.mm:173
void * Sys_LoadDll(const char *name, int(**entryPoint)(int,...), int(*systemcalls)(int,...))
Definition: macosx_sys.mm:92
void Sys_UnloadDll(void *dllHandle)
Definition: macosx_sys.mm:80
void Sys_InitInput(void)
Definition: dedicated.cpp:39
GLuint index
Definition: glext.h:3476
idCommon * common
Definition: Common.cpp:206
void OutputDebugString(const char *text)
Definition: macosx_sys.mm:243
#define NULL
Definition: Lib.h:88
char * FS_BuildOSPath(const char *base, const char *game, const char *qpath)
void Sys_Print(const char *msg)
Definition: macosx_sys.mm:198
char * Sys_GetCurrentUser(void)
Definition: win_shared.cpp:239
virtual void Printf(const char *fmt,...) id_attribute((format(printf
char * strdup(char *s1)
Definition: main.c:183
const GLcharARB * name
Definition: glext.h:3629
GLsizei const GLcharARB const GLint * length
Definition: glext.h:3599
void Sys_Error(const char *error,...)
Definition: macosx_sys.mm:156
idGame * game
Definition: Game_local.cpp:65
const char * macosx_scanForLibraryDirectory(void)
Definition: macosx_utils.mm:45
char * Sys_GetClipboardData(void)
Definition: macosx_sys.mm:100
size_t fwrite(const void *, size_t, size_t, FILE *)
char * ansiColors[8]
Definition: macosx_sys.mm:188