Mercurial > sdl-ios-xcode
annotate src/SDL_getenv.c @ 1133:609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
To: SDL Developers <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Mon, 30 May 2005 23:29:04 +0200
Subject: [SDL] Mac OS X Video Drivers [patch]
I've updated/added the Carbon and X11 video drivers
to the Mac OS X port of SDL 1.2 (the CVS version),
and made the Cocoa driver and runtime *optional*.
The default is still Cocoa, and the "Quartz" driver.
But you can now also use "toolbox" for Carbon, and
"x11" for running with Apple's (or other) X11 server:
export SDL_VIDEODRIVER=x11
export SDL_VIDEO_GL_DRIVER=/usr/X11R6/lib/libGL.dylib
It also checks if the frameworks are available, by a:
#include <Carbon/Carbon.h> or #import <Cocoa/Cocoa.h>
(this should make it configure on plain Darwin as well?)
Here are the new configure targets:
--enable-video-cocoa use Cocoa/Quartz video driver default=yes
--enable-video-carbon use Carbon/QuickDraw video driver default=yes
--enable-video-x11 use X11 video driver default=no
./configure --enable-video-cocoa --enable-video-carbon
--enable-video-x11 \
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib
The Carbon version is just an updated version of the old
SDL driver for Mac OS 9, and could probably be improved...
(but it does work, including the Carbon version of SDLmain)
If you disable cocoa, you can run with -framework Carbon only,
and the C version of SDL_main.c. And if you disable carbon too,
you can still use the X11 version which doesn't require SDLmain.
I updated the DrawSprocket version, but did not include it.
(no blitters or VRAM GWorlds etc. available on OS X anyway)
Besides for Mac OS 9, I don't think there's any use for it ?
And note that any performance on Mac OS X equals OpenGL anyway...
You can get "fair" software SDL results on captured CG displays,
but for decent frame rates you need to be using GL for rendering.
Finally, here is the patch itself:
http://www.algonet.se/~afb/SDL-12CVS-macvideo.patch
--anders
PS. It says "video", but as usual it applies to mouse/keyboard too.
------
To: A list for developers using the SDL library <sdl@libsdl.org>
From: =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb@algonet.se>
Date: Sun, 4 Sep 2005 10:02:15 +0200
Subject: [SDL] Updated Mac patch
Updated the previous Mac patch to disable Carbon by default.
Also "fixed" the SDL.spec again, so that it builds on Darwin.
http://www.algonet.se/~afb/SDL-1.2.9-mac.patch
Also applied fine to SDL12 CVS, when I tried it.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 08 Sep 2005 06:16:14 +0000 |
parents | b8d311d90021 |
children | f098b247299d |
rev | line source |
---|---|
249 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
249 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library 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 GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
249
diff
changeset
|
20 slouken@libsdl.org |
249 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
0 | 27 |
28 /* Not all environments have a working getenv()/putenv() */ | |
29 | |
30 #ifdef TEST_MAIN | |
31 #define NEED_SDL_GETENV | |
32 #endif | |
33 | |
34 #include "SDL_getenv.h" | |
35 | |
36 #ifdef NEED_SDL_GETENV | |
37 | |
38 #include <stdlib.h> | |
39 #include <string.h> | |
40 | |
41 static char **SDL_env = (char **)0; | |
42 | |
43 /* Put a variable of the form "name=value" into the environment */ | |
44 int SDL_putenv(const char *variable) | |
45 { | |
46 const char *name, *value; | |
47 int added; | |
48 int len, i; | |
49 char **new_env; | |
50 char *new_variable; | |
51 | |
52 /* A little error checking */ | |
53 if ( ! variable ) { | |
54 return(-1); | |
55 } | |
56 name = variable; | |
57 for ( value=variable; *value && (*value != '='); ++value ) { | |
58 /* Keep looking for '=' */ ; | |
59 } | |
60 if ( *value ) { | |
61 ++value; | |
62 } else { | |
63 return(-1); | |
64 } | |
65 | |
66 /* Allocate memory for the variable */ | |
67 new_variable = (char *)malloc(strlen(variable)+1); | |
68 if ( ! new_variable ) { | |
69 return(-1); | |
70 } | |
71 strcpy(new_variable, variable); | |
72 | |
73 /* Actually put it into the environment */ | |
74 added = 0; | |
75 i = 0; | |
76 if ( SDL_env ) { | |
77 /* Check to see if it's already there... */ | |
78 len = (value - name); | |
79 for ( ; SDL_env[i]; ++i ) { | |
80 if ( strncmp(SDL_env[i], name, len) == 0 ) { | |
81 break; | |
82 } | |
83 } | |
84 /* If we found it, just replace the entry */ | |
85 if ( SDL_env[i] ) { | |
86 free(SDL_env[i]); | |
87 SDL_env[i] = new_variable; | |
88 added = 1; | |
89 } | |
90 } | |
91 | |
92 /* Didn't find it in the environment, expand and add */ | |
93 if ( ! added ) { | |
94 new_env = realloc(SDL_env, (i+2)*sizeof(char *)); | |
95 if ( new_env ) { | |
96 SDL_env = new_env; | |
97 SDL_env[i++] = new_variable; | |
98 SDL_env[i++] = (char *)0; | |
99 added = 1; | |
100 } else { | |
101 free(new_variable); | |
102 } | |
103 } | |
104 return (added ? 0 : -1); | |
105 } | |
106 | |
107 /* Retrieve a variable named "name" from the environment */ | |
108 char *SDL_getenv(const char *name) | |
109 { | |
110 int len, i; | |
111 char *value; | |
112 | |
113 value = (char *)0; | |
114 if ( SDL_env ) { | |
115 len = strlen(name); | |
116 for ( i=0; SDL_env[i] && !value; ++i ) { | |
117 if ( (strncmp(SDL_env[i], name, len) == 0) && | |
118 (SDL_env[i][len] == '=') ) { | |
119 value = &SDL_env[i][len+1]; | |
120 } | |
121 } | |
122 } | |
123 return value; | |
124 } | |
125 | |
126 #endif /* NEED_GETENV */ | |
127 | |
128 #ifdef TEST_MAIN | |
129 #include <stdio.h> | |
130 | |
131 int main(int argc, char *argv[]) | |
132 { | |
133 char *value; | |
134 | |
135 printf("Checking for non-existent variable... "); | |
136 fflush(stdout); | |
137 if ( ! getenv("EXISTS") ) { | |
138 printf("okay\n"); | |
139 } else { | |
140 printf("failed\n"); | |
141 } | |
142 printf("Setting FIRST=VALUE1 in the environment... "); | |
143 fflush(stdout); | |
144 if ( putenv("FIRST=VALUE1") == 0 ) { | |
145 printf("okay\n"); | |
146 } else { | |
147 printf("failed\n"); | |
148 } | |
149 printf("Getting FIRST from the environment... "); | |
150 fflush(stdout); | |
151 value = getenv("FIRST"); | |
152 if ( value && (strcmp(value, "VALUE1") == 0) ) { | |
153 printf("okay\n"); | |
154 } else { | |
155 printf("failed\n"); | |
156 } | |
157 printf("Setting SECOND=VALUE2 in the environment... "); | |
158 fflush(stdout); | |
159 if ( putenv("SECOND=VALUE2") == 0 ) { | |
160 printf("okay\n"); | |
161 } else { | |
162 printf("failed\n"); | |
163 } | |
164 printf("Getting SECOND from the environment... "); | |
165 fflush(stdout); | |
166 value = getenv("SECOND"); | |
167 if ( value && (strcmp(value, "VALUE2") == 0) ) { | |
168 printf("okay\n"); | |
169 } else { | |
170 printf("failed\n"); | |
171 } | |
172 printf("Setting FIRST=NOVALUE in the environment... "); | |
173 fflush(stdout); | |
174 if ( putenv("FIRST=NOVALUE") == 0 ) { | |
175 printf("okay\n"); | |
176 } else { | |
177 printf("failed\n"); | |
178 } | |
179 printf("Getting FIRST from the environment... "); | |
180 fflush(stdout); | |
181 value = getenv("FIRST"); | |
182 if ( value && (strcmp(value, "NOVALUE") == 0) ) { | |
183 printf("okay\n"); | |
184 } else { | |
185 printf("failed\n"); | |
186 } | |
187 printf("Checking for non-existent variable... "); | |
188 fflush(stdout); | |
189 if ( ! getenv("EXISTS") ) { | |
190 printf("okay\n"); | |
191 } else { | |
192 printf("failed\n"); | |
193 } | |
194 return(0); | |
195 } | |
196 #endif /* TEST_MAIN */ | |
197 |