Project

General

Profile

Feature #2163 ยป 0055-audio-.-ch-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 08/24/2026 03:46 AM

View differences:

client/audio.c
#include "audio.h"
#define MAX_NUM_PLUGINS 2
#define SNDSPEC_SUFFIX ".soundspec"
#define MAX_NUM_PLUGINS 2
#define SNDSPEC_SUFFIX ".soundspec"
#define MUSICSPEC_SUFFIX ".musicspec"
#define SOUNDSPEC_CAPSTR "+Freeciv-soundset-3.4-Devel-2026.Aug.05"
#define MUSICSPEC_CAPSTR "+Freeciv-3.2-musicspec"
/* Keep them open throughout */
static struct section_file *ss_tagfile = NULL;
static struct section_file *ms_tagfile = NULL;
static struct section_file *ss_tagfile = nullptr;
static struct section_file *ms_tagfile = nullptr;
static struct audio_plugin plugins[MAX_NUM_PLUGINS];
static int num_plugins_used = 0;
......
**************************************************************************/
const struct strvec *get_soundplugin_list(const struct option *poption)
{
static struct strvec *plugin_list = NULL;
static struct strvec *plugin_list = nullptr;
if (NULL == plugin_list) {
if (plugin_list == nullptr) {
int i;
plugin_list = strvec_new();
......
Returns a static string vector of audiosets of given type available
on the system by searching all data directories for files matching
suffix.
The list is NULL-terminated.
The list is nullptr-terminated.
**************************************************************************/
static const struct strvec *get_audio_speclist(const char *suffix,
struct strvec **audio_list)
{
if (NULL == *audio_list) {
if (*audio_list == nullptr) {
*audio_list = fileinfolist(get_data_dirs(), suffix);
}
......
**************************************************************************/
const struct strvec *get_soundset_list(const struct option *poption)
{
static struct strvec *sound_list = NULL;
static struct strvec *sound_list = nullptr;
return get_audio_speclist(SNDSPEC_SUFFIX, &sound_list);
}
......
**************************************************************************/
const struct strvec *get_musicset_list(const struct option *poption)
{
static struct strvec *music_list = NULL;
static struct strvec *music_list = nullptr;
return get_audio_speclist(MUSICSPEC_SUFFIX, &music_list);
}
......
}
/**********************************************************************//**
Returns the filename for the given audio set. Returns NULL if
Returns the filename for the given audio set. Returns nullptr if
set couldn't be found. Caller has to free the return value.
**************************************************************************/
static const char *audiospec_fullname(const char *audioset_name,
......
}
if (strcmp(audioset_name, audioset_default) == 0) {
/* avoid endless recursion */
return NULL;
/* Avoid endless recursion */
return nullptr;
}
/* Marked for translation, as user may see this when
......
const char *file_capstr;
file_capstr = secfile_lookup_str(sfile, "%s", opt_path);
if (NULL == file_capstr) {
if (file_capstr == nullptr) {
log_fatal("Audio spec-file \"%s\" doesn't have capability string.",
filename);
exit(EXIT_FAILURE);
......
if (strcmp(preferred_plugin_name, "none") == 0) {
/* We explicitly choose none plugin, silently skip the code below */
log_verbose("Proceeding with sound support disabled.");
ss_tagfile = NULL;
ss_tagfile = nullptr;
musicspec_close(ms_tagfile);
ms_tagfile = NULL;
ms_tagfile = nullptr;
return;
}
......
log_normal(_("Proceeding with sound support disabled."));
log_normal(_("For sound support, install SDL2_mixer"));
log_normal("https://github.com/libsdl-org/SDL_mixer");
ss_tagfile = NULL;
ss_tagfile = nullptr;
musicspec_close(ms_tagfile);
ms_tagfile = NULL;
ms_tagfile = nullptr;
return;
}
......
log_normal(_("Get sound sets from <%s>."),
"https://www.freeciv.org/wiki/Sounds");
log_normal(_("Proceeding with sound support disabled."));
ss_tagfile = NULL;
ss_tagfile = nullptr;
musicspec_close(ms_tagfile);
ms_tagfile = NULL;
ms_tagfile = nullptr;
return;
}
......
enum keep_style keep_old_style)
{
const char *soundfile;
const char *fullpath = NULL;
audio_finished_callback cb = NULL;
const char *fullpath = nullptr;
audio_finished_callback cb = nullptr;
int ret = 0;
if (!tag || strcmp(tag, "-") == 0) {
......
if (sfile) {
soundfile = secfile_lookup_str(sfile, "files.%s", tag);
if (soundfile == NULL) {
if (soundfile == nullptr) {
const char *files[MAX_ALT_AUDIO_FILES];
int excluded = -1;
int i;
......
for (i = 0; i < MAX_ALT_AUDIO_FILES; i++) {
const char *ftmp = secfile_lookup_str(sfile, "files.%s_%d", tag, i);
if (ftmp == NULL) {
if (ftmp == nullptr) {
if (excluded != -1 && j == 0) {
/* Cannot exclude the only track */
excluded = -1;
j++;
}
files[j] = NULL;
files[j] = nullptr;
break;
}
files[j] = ftmp;
......
cb = music_finished_callback;
}
if (NULL == soundfile) {
if (soundfile == nullptr) {
log_verbose("No sound file for tag %s", tag);
} else {
fullpath = fileinfoname(get_data_dirs(), soundfile);
......
const char *pretty_alt2_tag = alt_tag2 ? alt_tag2 : "(null)";
if (gui_options.sound_enable_effects) {
fc_assert_ret(tag != NULL);
fc_assert_ret(tag != nullptr);
log_debug("audio_play_sound('%s', '%s', '%s')",
tag, pretty_alt_tag, pretty_alt2_tag);
......
{
char *pretty_alt_tag = alt_tag ? alt_tag : "(null)";
fc_assert_ret(tag != NULL);
fc_assert_ret(tag != nullptr);
log_debug("audio_play_music('%s', '%s')", tag, pretty_alt_tag);
......
audio_stop_usage();
if (play_quit_tag) {
audio_play_sound("e_client_quit", NULL, NULL);
audio_play_sound("e_client_quit", nullptr, nullptr);
}
if (plugins[selected_plugin].initialized) {
......
plugins[selected_plugin].shutdown(&(plugins[selected_plugin]));
}
if (NULL != ss_tagfile) {
if (ss_tagfile != nullptr) {
secfile_destroy(ss_tagfile);
ss_tagfile = NULL;
ss_tagfile = nullptr;
}
if (NULL != ms_tagfile) {
if (ms_tagfile != nullptr) {
musicspec_close(ms_tagfile);
ms_tagfile = NULL;
ms_tagfile = nullptr;
}
}
client/audio.h
/* utility */
#include "support.h" /* bool type */
#define MAX_AUDIO_NAME_LEN 20
#define MAX_AUDIO_DESCR_LEN 200
#define MAX_AUDIO_NAME_LEN 20
#define MAX_AUDIO_DESCR_LEN 200
#define MAX_ALT_AUDIO_FILES 25
client/audio_sdl.c
#ifdef AUDIO_SDL3
#define MIX_CHANNELS 8
static MIX_Audio *mus = NULL;
static MIX_Mixer *mixer = NULL;
static MIX_Audio *mus = nullptr;
static MIX_Mixer *mixer = nullptr;
static MIX_Track *tracks[MIX_CHANNELS];
static SDL_PropertiesID forever_loop;
#else /* AUDIO_SDL3 */
static Mix_Music *mus = NULL;
static Mix_Music *mus = nullptr;
#endif /* AUDIO_SDL3 */
static struct sample samples[MIX_CHANNELS];
......
{
int j;
#ifdef AUDIO_SDL3
MIX_Audio *wave = NULL;
MIX_Audio *wave = nullptr;
int channel;
static int channel_turn = 1; /* Channel 0 is music */
#else /* AUDIO_SDL3 */
int i;
Mix_Chunk *wave = NULL;
Mix_Chunk *wave = nullptr;
#endif /* AUDIO_SDL3 */
if (!fullpath) {
......
#else /* AUDIO_SDL3 */
mus = Mix_LoadMUS(fullpath);
#endif /* AUDIO_SDL3 */
if (mus == NULL) {
if (mus == nullptr) {
log_error("Can't open file \"%s\": %s",
fullpath, SDL_GetError());
}
if (cb == NULL) {
if (cb == nullptr) {
#ifdef AUDIO_SDL3
MIX_SetTrackAudio(tracks[channel], mus);
MIX_PlayTrack(tracks[channel], forever_loop);
......
#else /* AUDIO_SDL3 */
wave = Mix_LoadWAV(fullpath);
#endif /* AUDIO_SDL3 */
if (wave == NULL) {
if (wave == nullptr) {
log_error("Can't open file \"%s\"", fullpath);
}
......
longer be playing by the time we get here */
if (samples[channel].wave) {
MIX_DestroyAudio(samples[channel].wave);
samples[channel].wave = NULL;
samples[channel].wave = nullptr;
}
/* Remember for caching */
......
return FALSE;
}
log_verbose("Playing file \"%s\" on channel %d", fullpath, i);
/* Free previous sample on this channel. it will by definition no
/* Free previous sample on this channel. It will by definition no
longer be playing by the time we get here */
if (samples[i].wave) {
Mix_FreeChunk(samples[i].wave);
samples[i].wave = NULL;
samples[i].wave = nullptr;
}
/* Remember for caching */
......
}
#ifdef AUDIO_SDL3
mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, NULL);
if (mixer == NULL) {
mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, nullptr);
if (mixer == nullptr) {
log_error("Error calling MIX_CreateMixerDevice()");
#else /* AUDIO_SDL3 */
/* Initialize variables */
......
#ifdef AUDIO_SDL3
tracks[i] = MIX_CreateTrack(mixer);
#endif /* AUDIO_SDL3 */
samples[i].wave = NULL;
samples[i].wave = nullptr;
}
/* Sanity check, for now; add volume controls later */
    (1-1/1)