macosx_sys.mm 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. // -*- mode: objc -*-
  21. #import "../../idlib/precompiled.h"
  22. #import "macosx_local.h"
  23. #import "macosx_sys.h"
  24. #import "macosx_common.h"
  25. #import "dlfcn.h"
  26. #import <AppKit/AppKit.h>
  27. #import <sys/types.h>
  28. #import <unistd.h>
  29. #import <sys/param.h>
  30. #import <sys/mount.h>
  31. #import <sys/wait.h>
  32. #ifdef OMNI_TIMER
  33. #import "macosx_timers.h"
  34. #endif
  35. void Sys_Init (void);
  36. char *Sys_GetCurrentUser( void );
  37. void Sys_Error( const char *error, ...);
  38. void Sys_Quit (void);
  39. char *Sys_GetClipboardData( void ); // note that this isn't journaled...
  40. void Sys_Print( const char *msg );
  41. //===========================================================================
  42. int main(int argc, const char *argv[]) {
  43. return NSApplicationMain(argc, argv);
  44. }
  45. //===========================================================================
  46. void Sys_Sleep( const int time ) {
  47. sleep( time );
  48. }
  49. void EditorPrintConsole( const char *test ) {
  50. }
  51. /*
  52. =================
  53. Sys_UnloadDll
  54. =================
  55. */
  56. void Sys_UnloadDll( void *dllHandle ) {
  57. }
  58. /*
  59. =================
  60. Sys_LoadDll
  61. Used to load a development dll instead of a virtual machine
  62. =================
  63. */
  64. extern char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
  65. void *Sys_LoadDll( const char *name, int (**entryPoint)(int, ...),
  66. int (*systemcalls)(int, ...) )
  67. {
  68. return NULL;
  69. }
  70. //===========================================================================
  71. char *Sys_GetClipboardData(void) // FIXME
  72. {
  73. NSPasteboard *pasteboard;
  74. NSArray *pasteboardTypes;
  75. pasteboard = [NSPasteboard generalPasteboard];
  76. pasteboardTypes = [pasteboard types];
  77. if ([pasteboardTypes containsObject:NSStringPboardType]) {
  78. NSString *clipboardString;
  79. clipboardString = [pasteboard stringForType:NSStringPboardType];
  80. if (clipboardString && [clipboardString length] > 0) {
  81. return strdup([clipboardString cString]);
  82. }
  83. }
  84. return NULL;
  85. }
  86. //===========================================================================
  87. void Sys_BeginProfiling(void)
  88. {
  89. }
  90. void Sys_EndProfiling(void)
  91. {
  92. }
  93. //===========================================================================
  94. /*
  95. ================
  96. Sys_Init
  97. The cvar and file system has been setup, so configurations are loaded
  98. ================
  99. */
  100. void Sys_Init(void)
  101. {
  102. // Sys_InitNetwork();
  103. Sys_InitInput();
  104. }
  105. /*
  106. =================
  107. Sys_Shutdown
  108. =================
  109. */
  110. void Sys_Shutdown(void)
  111. {
  112. common->Printf( "----- Sys_Shutdown -----\n" );
  113. Sys_EndProfiling();
  114. Sys_ShutdownInput();
  115. common->Printf( "------------------------\n" );
  116. }
  117. void Sys_Error(const char *error, ...)
  118. {
  119. va_list argptr;
  120. NSString *formattedString;
  121. Sys_Shutdown();
  122. va_start(argptr,error);
  123. formattedString = [[NSString alloc] initWithFormat:[NSString stringWithCString:error] arguments:argptr];
  124. va_end(argptr);
  125. NSLog(@"Sys_Error: %@", formattedString);
  126. NSRunAlertPanel(@"DOOM Error", formattedString, nil, nil, nil);
  127. Sys_Quit();
  128. }
  129. void Sys_Quit(void)
  130. {
  131. Sys_Shutdown();
  132. [NSApp terminate:nil];
  133. }
  134. /*
  135. ================
  136. Sys_Print
  137. This is called for all console output, even if the game is running
  138. full screen and the dedicated console window is hidden.
  139. ================
  140. */
  141. char *ansiColors[8] =
  142. { "\033[30m" , /* ANSI Black */
  143. "\033[31m" , /* ANSI Red */
  144. "\033[32m" , /* ANSI Green */
  145. "\033[33m" , /* ANSI Yellow */
  146. "\033[34m" , /* ANSI Blue */
  147. "\033[36m" , /* ANSI Cyan */
  148. "\033[35m" , /* ANSI Magenta */
  149. "\033[37m" }; /* ANSI White */
  150. void Sys_Print(const char *text)
  151. {
  152. #if 0
  153. /* Okay, this is a stupid hack, but what the hell, I was bored. ;) */
  154. char *scan = text;
  155. char code;
  156. int index;
  157. /* Make sure terminal mode is reset at the start of the line... */
  158. fputs("\033[0m", stdout);
  159. while(*scan) {
  160. /* See if we have a color control code. If so, snarf the character,
  161. print what we have so far, print the ANSI Terminal color code,
  162. skip over the color control code and continue */
  163. if(Q_IsColorString(scan)) {
  164. index = ColorIndex(scan[1]);
  165. /* Flush current message */
  166. if(scan != text) {
  167. fwrite(text, scan - text, 1, stdout);
  168. }
  169. /* Write ANSI color code */
  170. fputs(ansiColors[index], stdout);
  171. /* Reset search */
  172. text = scan+2;
  173. scan = text;
  174. continue;
  175. }
  176. scan++;
  177. }
  178. /* Flush whatever's left */
  179. fputs(text, stdout);
  180. /* Make sure terminal mode is reset at the end of the line too... */
  181. fputs("\033[0m", stdout);
  182. #else
  183. fputs(text, stdout);
  184. #endif
  185. }
  186. void OutputDebugString( const char *text ) {
  187. Sys_Print( text );
  188. }
  189. void Sys_OutputDebugString( const char *text ) {
  190. OutputDebugString( text );
  191. }
  192. /*
  193. ================
  194. Sys_CheckCD
  195. Return true if the proper CD is in the drive
  196. ================
  197. */
  198. bool Sys_CheckCD( void ) {
  199. return macosx_scanForLibraryDirectory() != NULL;
  200. }