Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
141 lines (119 loc) · 3.64 KB

SDL_hints.c

File metadata and controls

141 lines (119 loc) · 3.64 KB
 
Apr 8, 2011
Apr 8, 2011
2
3
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
Apr 8, 2011
Apr 8, 2011
5
6
7
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Apr 8, 2011
Apr 8, 2011
9
10
11
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
Apr 8, 2011
Apr 8, 2011
13
14
15
16
17
18
19
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
20
21
22
23
*/
#include "SDL_config.h"
#include "SDL_hints.h"
Jun 10, 2011
Jun 10, 2011
24
#include "SDL_hints_c.h"
25
26
27
28
29
30
31
32
33
/* Assuming there aren't many hints set and they aren't being queried in
critical performance paths, we'll just use a linked list here.
*/
typedef struct SDL_Hint {
char *name;
char *value;
SDL_HintPriority priority;
Jun 10, 2011
Jun 10, 2011
34
SDL_HintChangedCb callback;
35
36
37
38
39
struct SDL_Hint *next;
} SDL_Hint;
static SDL_Hint *SDL_hints;
Jun 10, 2011
Jun 10, 2011
40
41
42
43
44
45
46
47
48
49
50
51
52
53
SDL_bool
SDL_RegisterHintChangedCb(const char *name, SDL_HintChangedCb hintCb)
{
SDL_Hint *hint;
for (hint = SDL_hints; hint; hint = hint->next) {
if (SDL_strcmp(name, hint->name) == 0) {
hint->callback = hintCb;
return SDL_TRUE;
}
}
return SDL_FALSE;
}
Feb 6, 2011
Feb 6, 2011
56
57
SDL_SetHintWithPriority(const char *name, const char *value,
SDL_HintPriority priority)
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{
const char *env;
SDL_Hint *prev, *hint;
if (!name || !value) {
return SDL_FALSE;
}
env = SDL_getenv(name);
if (env && priority < SDL_HINT_OVERRIDE) {
return SDL_FALSE;
}
prev = NULL;
for (hint = SDL_hints; hint; prev = hint, hint = hint->next) {
if (SDL_strcmp(name, hint->name) == 0) {
if (priority < hint->priority) {
return SDL_FALSE;
}
if (SDL_strcmp(hint->value, value) != 0) {
Jun 10, 2011
Jun 10, 2011
78
79
80
if (hint->callback != NULL) {
(*hint->callback)(name, hint->value, value);
}
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
SDL_free(hint->value);
hint->value = SDL_strdup(value);
}
hint->priority = priority;
return SDL_TRUE;
}
}
/* Couldn't find the hint, add a new one */
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
if (!hint) {
return SDL_FALSE;
}
hint->name = SDL_strdup(name);
hint->value = SDL_strdup(value);
hint->priority = priority;
Jun 10, 2011
Jun 10, 2011
97
hint->callback = NULL;
98
99
100
101
102
hint->next = SDL_hints;
SDL_hints = hint;
return SDL_TRUE;
}
Feb 6, 2011
Feb 6, 2011
103
104
105
106
107
108
SDL_bool
SDL_SetHint(const char *name, const char *value)
{
return SDL_SetHintWithPriority(name, value, SDL_HINT_NORMAL);
}
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const char *
SDL_GetHint(const char *name)
{
const char *env;
SDL_Hint *hint;
env = SDL_getenv(name);
for (hint = SDL_hints; hint; hint = hint->next) {
if (SDL_strcmp(name, hint->name) == 0) {
if (!env || hint->priority == SDL_HINT_OVERRIDE) {
return hint->value;
}
break;
}
}
return env;
}
Feb 12, 2011
Feb 12, 2011
127
void SDL_ClearHints(void)
128
129
130
131
132
133
134
135
136
137
138
139
140
141
{
SDL_Hint *hint;
while (SDL_hints) {
hint = SDL_hints;
SDL_hints = hint->next;
SDL_free(hint->name);
SDL_free(hint->value);
SDL_free(hint);
}
}
/* vi: set ts=4 sw=4 expandtab: */