Skip to content

Commit febcbc5

Browse files
committed
C89 cleanups part 2
1 parent 7961d82 commit febcbc5

File tree

20 files changed

+183
-160
lines changed

20 files changed

+183
-160
lines changed

config.def.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ enum
128128
MENU_XMB,
129129

130130
RECORD_FFMPEG,
131-
RECORD_NULL,
131+
RECORD_NULL
132132
};
133133

134134
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) || defined(__CELLOS_LV2__)

configuration.c

+14-10
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,9 @@ static config_file_t *open_default_config_file(void)
852852
(void)conf_path;
853853
(void)app_path;
854854
(void)saved;
855+
856+
const char *xdg; (void)xdg;
857+
const char *home; (void)home;
855858

856859
#if defined(_WIN32) && !defined(_XBOX)
857860
fill_pathname_application_path(app_path, sizeof(app_path));
@@ -899,7 +902,7 @@ static config_file_t *open_default_config_file(void)
899902
RARCH_WARN("Created new config file in: \"%s\".\n", conf_path);
900903
}
901904
#elif defined(OSX)
902-
const char *home = getenv("HOME");
905+
home = getenv("HOME");
903906

904907
if (!home)
905908
return NULL;
@@ -935,8 +938,8 @@ static config_file_t *open_default_config_file(void)
935938
RARCH_WARN("Created new config file in: \"%s\".\n", conf_path);
936939
}
937940
#elif !defined(__CELLOS_LV2__) && !defined(_XBOX)
938-
const char *xdg = getenv("XDG_CONFIG_HOME");
939-
const char *home = getenv("HOME");
941+
xdg = getenv("XDG_CONFIG_HOME");
942+
home = getenv("HOME");
940943

941944
/* XDG_CONFIG_HOME falls back to $HOME/.config. */
942945
if (xdg)
@@ -1518,9 +1521,12 @@ static bool config_load_file(const char *path, bool set_defaults)
15181521

15191522
CONFIG_GET_BOOL_BASE(conf, settings, rewind_enable, "rewind_enable");
15201523

1521-
int buffer_size = 0;
1522-
if (config_get_int(conf, "rewind_buffer_size", &buffer_size))
1523-
settings->rewind_buffer_size = buffer_size * UINT64_C(1000000);
1524+
{
1525+
/* ugly hack around C89 not allowing mixing declarations and code */
1526+
int buffer_size = 0;
1527+
if (config_get_int(conf, "rewind_buffer_size", &buffer_size))
1528+
settings->rewind_buffer_size = buffer_size * UINT64_C(1000000);
1529+
}
15241530

15251531
CONFIG_GET_INT_BASE(conf, settings, rewind_granularity, "rewind_granularity");
15261532
CONFIG_GET_FLOAT_BASE(conf, settings, slowmotion_ratio, "slowmotion_ratio");
@@ -1821,12 +1827,10 @@ bool config_load_override(void)
18211827
else
18221828
RARCH_LOG("No core-specific overrides found at %s.\n", core_path);
18231829

1824-
new_conf = NULL;
1825-
1826-
// Create a new config file from game_path
1830+
/* Create a new config file from game_path */
18271831
new_conf = config_file_new(game_path);
18281832

1829-
// If a game override exists, add it's location to append_config_path
1833+
/* If a game override exists, add it's location to append_config_path */
18301834
if (new_conf)
18311835
{
18321836
RARCH_LOG("Game-specific overrides found at %s. Appending.\n", game_path);

dynamic.c

+16-15
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,13 @@ static dylib_t libretro_get_system_info_lib(const char *path,
159159
struct retro_system_info *info, bool *load_no_content)
160160
{
161161
dylib_t lib = dylib_load(path);
162+
void (*proc)(struct retro_system_info*);
163+
162164
if (!lib)
163165
return NULL;
164166

165-
void (*proc)(struct retro_system_info*) =
166-
(void (*)(struct retro_system_info*))dylib_proc(lib,
167-
"retro_get_system_info");
167+
proc = (void (*)(struct retro_system_info*))
168+
dylib_proc(lib, "retro_get_system_info");
168169

169170
if (!proc)
170171
{
@@ -176,10 +177,10 @@ static dylib_t libretro_get_system_info_lib(const char *path,
176177

177178
if (load_no_content)
178179
{
180+
void (*set_environ)(retro_environment_t);
179181
*load_no_content = false;
180-
void (*set_environ)(retro_environment_t) =
181-
(void (*)(retro_environment_t))dylib_proc(lib,
182-
"retro_set_environment");
182+
set_environ = (void (*)(retro_environment_t))
183+
dylib_proc(lib, "retro_set_environment");
183184

184185
if (!set_environ)
185186
return lib;
@@ -735,6 +736,13 @@ bool rarch_environment_cb(unsigned cmd, void *data)
735736
unsigned retro_id, retro_port;
736737
const struct retro_input_descriptor *desc = NULL;
737738

739+
static const char *libretro_btn_desc[] = {
740+
"B (bottom)", "Y (left)", "Select", "Start",
741+
"D-Pad Up", "D-Pad Down", "D-Pad Left", "D-Pad Right",
742+
"A (right)", "X (up)",
743+
"L", "R", "L2", "R2", "L3", "R3",
744+
};
745+
738746
memset(system->input_desc_btn, 0,
739747
sizeof(system->input_desc_btn));
740748

@@ -792,13 +800,6 @@ bool rarch_environment_cb(unsigned cmd, void *data)
792800
system->input_desc_btn[retro_port][retro_id] = desc->description;
793801
}
794802

795-
static const char *libretro_btn_desc[] = {
796-
"B (bottom)", "Y (left)", "Select", "Start",
797-
"D-Pad Up", "D-Pad Down", "D-Pad Left", "D-Pad Right",
798-
"A (right)", "X (up)",
799-
"L", "R", "L2", "R2", "L3", "R3",
800-
};
801-
802803
RARCH_LOG("Environ SET_INPUT_DESCRIPTORS:\n");
803804
for (p = 0; p < settings->input.max_users; p++)
804805
{
@@ -933,11 +934,11 @@ bool rarch_environment_cb(unsigned cmd, void *data)
933934
#if defined(HAVE_THREADS) && !defined(__CELLOS_LV2__)
934935
case RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK:
935936
{
936-
RARCH_LOG("Environ SET_AUDIO_CALLBACK.\n");
937937
const struct retro_audio_callback *info =
938938
(const struct retro_audio_callback*)data;
939+
RARCH_LOG("Environ SET_AUDIO_CALLBACK.\n");
939940

940-
if (driver->recording_data) // A/V sync is a must.
941+
if (driver->recording_data) /* A/V sync is a must. */
941942
return false;
942943

943944
#ifdef HAVE_NETPLAY

file_path_special.c

+20-17
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,16 @@ void fill_pathname_abbreviate_special(char *out_path,
122122
char application_dir[PATH_MAX_LENGTH] = {0};
123123
const char *home = getenv("HOME");
124124

125-
fill_pathname_application_path(application_dir, sizeof(application_dir));
126-
path_basedir(application_dir);
127-
128125
/* application_dir could be zero-string. Safeguard against this.
129126
*
130127
* Keep application dir in front of home, moving app dir to a
131128
* new location inside home would break otherwise. */
132129

133-
const char *candidates[3] = { application_dir, home, NULL };
130+
const char *candidates[3] = { application_dir, home, NULL }; /* ugly hack - use application_dir before filling it in. C89 reasons */
134131
const char *notations[3] = { ":", "~", NULL };
132+
133+
fill_pathname_application_path(application_dir, sizeof(application_dir));
134+
path_basedir(application_dir);
135135

136136
for (i = 0; candidates[i]; i++)
137137
{
@@ -197,24 +197,27 @@ void fill_pathname_application_path(char *buf, size_t size)
197197
}
198198
}
199199
#else
200-
*buf = '\0';
201-
pid_t pid = getpid();
202-
char link_path[PATH_MAX_LENGTH] = {0};
203-
/* Linux, BSD and Solaris paths. Not standardized. */
204-
static const char *exts[] = { "exe", "file", "path/a.out" };
205-
for (i = 0; i < ARRAY_SIZE(exts); i++)
206200
{
207-
snprintf(link_path, sizeof(link_path), "/proc/%u/%s",
208-
(unsigned)pid, exts[i]);
209-
ssize_t ret = readlink(link_path, buf, size - 1);
210-
if (ret >= 0)
201+
*buf = '\0';
202+
pid_t pid = getpid();
203+
char link_path[PATH_MAX_LENGTH] = {0};
204+
/* Linux, BSD and Solaris paths. Not standardized. */
205+
static const char *exts[] = { "exe", "file", "path/a.out" };
206+
for (i = 0; i < ARRAY_SIZE(exts); i++)
211207
{
212-
buf[ret] = '\0';
213-
return;
208+
ssize_t ret;
209+
snprintf(link_path, sizeof(link_path), "/proc/%u/%s",
210+
(unsigned)pid, exts[i]);
211+
ret = readlink(link_path, buf, size - 1);
212+
if (ret >= 0)
213+
{
214+
buf[ret] = '\0';
215+
return;
216+
}
214217
}
215218
}
216219

217-
/* Cannot resolve application path! This should not happen. */
220+
RARCH_ERR("Cannot resolve application path! This should not happen.");
218221
#endif
219222
}
220223
#endif

frontend/drivers/platform_linux.c

+5-8
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,10 @@ bool frontend_linux_powerstate_check_apm(enum frontend_powerstate *state,
348348
else
349349
*state = FRONTEND_POWERSTATE_ON_POWER_SOURCE;
350350

351-
const int pct = battery_percent;
352-
const int secs = battery_time;
353-
354-
if (pct >= 0) /* -1 == unknown */
355-
*percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
356-
if (secs >= 0) /* -1 == unknown */
357-
*seconds = secs;
351+
if (battery_percent >= 0) /* -1 == unknown */
352+
*percent = (battery_percent > 100) ? 100 : battery_percent; /* clamp between 0%, 100% */
353+
if (battery_time >= 0) /* -1 == unknown */
354+
*seconds = battery_time;
358355

359356
return true;
360357
}
@@ -464,7 +461,7 @@ static void frontend_linux_get_os(char *s, size_t len, int *major, int *minor)
464461
if (uname(&buffer) != 0)
465462
return;
466463

467-
sscanf(buffer.release, "%u.%u.%u", major, minor, &krel);
464+
sscanf(buffer.release, "%d.%d.%d", major, minor, &krel);
468465
strlcpy(s, "Linux", len);
469466
}
470467

gfx/common/x11_common.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ static Atom XA_NET_MOVERESIZE_WINDOW;
6666

6767
void x11_windowed_fullscreen(Display *dpy, Window win)
6868
{
69+
XEvent xev = {0};
70+
6971
XA_INIT(_NET_WM_STATE);
7072
XA_INIT(_NET_WM_STATE_FULLSCREEN);
7173

72-
XEvent xev = {0};
73-
7474
xev.xclient.type = ClientMessage;
7575
xev.xclient.send_event = True;
7676
xev.xclient.message_type = XA_NET_WM_STATE;

gfx/drivers/gl.c

+32-28
Original file line numberDiff line numberDiff line change
@@ -1370,37 +1370,41 @@ static INLINE void gl_copy_frame(gl_t *gl, const void *frame,
13701370
}
13711371
}
13721372
#elif defined(HAVE_PSGL)
1373-
unsigned h;
1374-
size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size;
1375-
size_t buffer_stride = gl->tex_w * gl->base_size;
1376-
const uint8_t *frame_copy = frame;
1377-
size_t frame_copy_size = width * gl->base_size;
1378-
1379-
uint8_t *buffer = (uint8_t*)glMapBuffer(
1380-
GL_TEXTURE_REFERENCE_BUFFER_SCE, GL_READ_WRITE) + buffer_addr;
1381-
for (h = 0; h < height; h++, buffer += buffer_stride, frame_copy += pitch)
1382-
memcpy(buffer, frame_copy, frame_copy_size);
1383-
1384-
glUnmapBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE);
1385-
#else
1386-
const GLvoid *data_buf = frame;
1387-
glPixelStorei(GL_UNPACK_ALIGNMENT, video_pixel_get_alignment(pitch));
1388-
1389-
if (gl->base_size == 2 && !gl->have_es2_compat)
13901373
{
1391-
/* Convert to 32-bit textures on desktop GL. */
1392-
gl_convert_frame_rgb16_32(gl, gl->conv_buffer,
1393-
frame, width, height, pitch);
1394-
data_buf = gl->conv_buffer;
1374+
unsigned h;
1375+
size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size;
1376+
size_t buffer_stride = gl->tex_w * gl->base_size;
1377+
const uint8_t *frame_copy = frame;
1378+
size_t frame_copy_size = width * gl->base_size;
1379+
1380+
uint8_t *buffer = (uint8_t*)glMapBuffer(
1381+
GL_TEXTURE_REFERENCE_BUFFER_SCE, GL_READ_WRITE) + buffer_addr;
1382+
for (h = 0; h < height; h++, buffer += buffer_stride, frame_copy += pitch)
1383+
memcpy(buffer, frame_copy, frame_copy_size);
1384+
1385+
glUnmapBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE);
13951386
}
1396-
else
1397-
glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size);
1387+
#else
1388+
{
1389+
const GLvoid *data_buf = frame;
1390+
glPixelStorei(GL_UNPACK_ALIGNMENT, video_pixel_get_alignment(pitch));
13981391

1399-
glTexSubImage2D(GL_TEXTURE_2D,
1400-
0, 0, 0, width, height, gl->texture_type,
1401-
gl->texture_fmt, data_buf);
1392+
if (gl->base_size == 2 && !gl->have_es2_compat)
1393+
{
1394+
/* Convert to 32-bit textures on desktop GL. */
1395+
gl_convert_frame_rgb16_32(gl, gl->conv_buffer,
1396+
frame, width, height, pitch);
1397+
data_buf = gl->conv_buffer;
1398+
}
1399+
else
1400+
glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size);
1401+
1402+
glTexSubImage2D(GL_TEXTURE_2D,
1403+
0, 0, 0, width, height, gl->texture_type,
1404+
gl->texture_fmt, data_buf);
14021405

1403-
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1406+
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
1407+
}
14041408
#endif
14051409
RARCH_PERFORMANCE_STOP(copy_frame);
14061410
}
@@ -2639,7 +2643,7 @@ static bool gl_set_shader(void *data,
26392643
{
26402644
unsigned textures = gl->shader->get_prev_textures() + 1;
26412645

2642-
if (textures > gl->textures) // Have to reinit a bit.
2646+
if (textures > gl->textures) /* Have to reinit a bit. */
26432647
{
26442648
#if defined(HAVE_FBO)
26452649
gl_deinit_hw_render(gl);

gfx/drivers/sdl2_gfx.c

+20-16
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,22 @@ static void sdl2_render_msg(sdl2_video_t *vid, const char *msg)
186186
tex_x = gly->atlas_offset_x;
187187
tex_y = gly->atlas_offset_y;
188188

189-
SDL_Rect srcrect = {
190-
tex_x, tex_y,
191-
(int)gly->width, (int)gly->height
192-
};
193-
194-
SDL_Rect dstrect = {
195-
x + delta_x + off_x, y + delta_y + off_y,
196-
(int)gly->width, (int)gly->height
197-
};
198-
199-
SDL_RenderCopyEx(vid->renderer, vid->font.tex, &srcrect, &dstrect, 0, NULL, SDL_FLIP_NONE);
200-
201-
delta_x += gly->advance_x;
202-
delta_y -= gly->advance_y;
189+
{
190+
SDL_Rect srcrect = {
191+
tex_x, tex_y,
192+
(int)gly->width, (int)gly->height
193+
};
194+
195+
SDL_Rect dstrect = {
196+
x + delta_x + off_x, y + delta_y + off_y,
197+
(int)gly->width, (int)gly->height
198+
};
199+
200+
SDL_RenderCopyEx(vid->renderer, vid->font.tex, &srcrect, &dstrect, 0, NULL, SDL_FLIP_NONE);
201+
202+
delta_x += gly->advance_x;
203+
delta_y -= gly->advance_y;
204+
}
203205
}
204206
}
205207

@@ -250,8 +252,9 @@ static void sdl2_init_renderer(sdl2_video_t *vid)
250252

251253
static void sdl_refresh_renderer(sdl2_video_t *vid)
252254
{
255+
SDL_Rect r;
253256
SDL_RenderClear(vid->renderer);
254-
SDL_Rect r = { vid->vp.x, vid->vp.y, (int)vid->vp.width, (int)vid->vp.height };
257+
r = (SDL_Rect){ vid->vp.x, vid->vp.y, (int)vid->vp.width, (int)vid->vp.height };
255258
SDL_RenderSetViewport(vid->renderer, &r);
256259

257260
/* breaks int scaling */
@@ -370,6 +373,7 @@ static void *sdl2_gfx_init(const video_info_t *video, const input_driver_t **inp
370373
int i;
371374
unsigned flags;
372375
settings_t *settings = config_get_ptr();
376+
sdl2_video_t *vid;
373377

374378
#ifdef HAVE_X11
375379
XInitThreads();
@@ -383,7 +387,7 @@ static void *sdl2_gfx_init(const video_info_t *video, const input_driver_t **inp
383387
else if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
384388
return NULL;
385389

386-
sdl2_video_t *vid = (sdl2_video_t*)calloc(1, sizeof(*vid));
390+
vid = (sdl2_video_t*)calloc(1, sizeof(*vid));
387391
if (!vid)
388392
return NULL;
389393

gfx/drivers_context/gfx_null_ctx.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* If not, see <http://www.gnu.org/licenses/>.
1515
*/
1616

17-
// Null context.
17+
/* Null context. */
1818

1919
#include "../../driver.h"
2020
#include "../video_context_driver.h"

0 commit comments

Comments
 (0)