Mercurial > sdl-ios-xcode
annotate src/SDL_hints.c @ 5203:01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 05 Feb 2011 20:02:37 -0800 |
parents | 6f6a9340fb93 |
children | b530ef003506 |
rev | line source |
---|---|
5192
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2010 Sam Lantinga |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 #include "SDL_hints.h" |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 /* Assuming there aren't many hints set and they aren't being queried in |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 critical performance paths, we'll just use a linked list here. |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 */ |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 typedef struct SDL_Hint { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 char *name; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 char *value; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 SDL_HintPriority priority; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 struct SDL_Hint *next; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 } SDL_Hint; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 static SDL_Hint *SDL_hints; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 SDL_bool |
5203
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5192
diff
changeset
|
41 SDL_SetHintWithPriority(const char *name, const char *value, |
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5192
diff
changeset
|
42 SDL_HintPriority priority) |
5192
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 const char *env; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 SDL_Hint *prev, *hint; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 if (!name || !value) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 return SDL_FALSE; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 env = SDL_getenv(name); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 if (env && priority < SDL_HINT_OVERRIDE) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 return SDL_FALSE; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 prev = NULL; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 for (hint = SDL_hints; hint; prev = hint, hint = hint->next) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 if (SDL_strcmp(name, hint->name) == 0) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 if (priority < hint->priority) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 return SDL_FALSE; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 if (SDL_strcmp(hint->value, value) != 0) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 SDL_free(hint->value); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 hint->value = SDL_strdup(value); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 hint->priority = priority; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 return SDL_TRUE; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 /* Couldn't find the hint, add a new one */ |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 if (!hint) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 return SDL_FALSE; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 hint->name = SDL_strdup(name); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 hint->value = SDL_strdup(value); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 hint->priority = priority; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 hint->next = SDL_hints; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 SDL_hints = hint; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 return SDL_TRUE; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 |
5203
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5192
diff
changeset
|
84 SDL_bool |
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5192
diff
changeset
|
85 SDL_SetHint(const char *name, const char *value) |
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5192
diff
changeset
|
86 { |
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5192
diff
changeset
|
87 return SDL_SetHintWithPriority(name, value, SDL_HINT_NORMAL); |
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5192
diff
changeset
|
88 } |
01bced9a4cc1
Created a simpler version of SDL_SetHint() that doesn't need a priority.
Sam Lantinga <slouken@libsdl.org>
parents:
5192
diff
changeset
|
89 |
5192
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 const char * |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 SDL_GetHint(const char *name) |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 const char *env; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 SDL_Hint *hint; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 env = SDL_getenv(name); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 for (hint = SDL_hints; hint; hint = hint->next) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 if (SDL_strcmp(name, hint->name) == 0) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 if (!env || hint->priority == SDL_HINT_OVERRIDE) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 return hint->value; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 break; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 return env; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 void SDL_ClearHints() |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 SDL_Hint *hint; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 while (SDL_hints) { |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 hint = SDL_hints; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 SDL_hints = hint->next; |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 SDL_free(hint->name); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 SDL_free(hint->value); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 SDL_free(hint); |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 } |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 |
6f6a9340fb93
Added a hint system to allow configuration hints to be specified by the application.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 /* vi: set ts=4 sw=4 expandtab: */ |