Skip to content

Commit

Permalink
Merge pull request #65 from ccawley2011/const-arrays
Browse files Browse the repository at this point in the history
Make more static arrays const
  • Loading branch information
AliceLR committed Jul 5, 2024
2 parents 54bdcd7 + 2d1a998 commit 041ee9f
Show file tree
Hide file tree
Showing 31 changed files with 94 additions and 247 deletions.
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AM_CFLAGS = -Wall
bin_PROGRAMS = xmp

xmp_SOURCES = \
commands.c common.h delay.c getopt_long.h list.h getopt_long.c info.c \
commands.c common.h delay.c getopt_long.h getopt_long.c info.c \
main.c options.c read_config.c sound.c sound.h sound_file.c sound_null.c \
sound_wav.c sound_aiff.c terminal.c util.c xmp_version.h
xmp_LDADD = ${LIBXMP_LIBS}
Expand Down
2 changes: 1 addition & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct control {
int mixer_type; /* Mixer type (from player) */
};

extern struct player_mode pmode[];
extern const struct player_mode pmode[];

void delay_ms(unsigned int);
#ifdef XMP_AMIGA
Expand Down
2 changes: 1 addition & 1 deletion src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void info_mod(const struct xmp_module_info *mi, int mode)
report("Module type : %s", mi->mod->type);

if (mode != XMP_MODE_AUTO) {
struct player_mode *pm;
const struct player_mode *pm;
for (pm = pmode; pm->name != NULL; pm++) {
if (pm->mode == mode) {
report(" [play as:%s]", pm->desc);
Expand Down
142 changes: 0 additions & 142 deletions src/list.h

This file was deleted.

4 changes: 1 addition & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include <windows.h>
#endif

static struct sound_driver *sound;
static const struct sound_driver *sound;
static unsigned int foreground_in, foreground_out;
static int refresh_status;

Expand Down Expand Up @@ -269,8 +269,6 @@ int main(int argc, char **argv)
srand(tv.tv_usec);
#endif

init_sound_drivers();

memset(&opt, 0, sizeof (struct options));
memset(&control, 0, sizeof (struct control));

Expand Down
21 changes: 9 additions & 12 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@

#include "common.h"
#include "sound.h"
#include "list.h"
#include "xmp_version.h"

extern struct list_head sound_driver_list;

enum {
OPT_FX9BUG = 0x105,
OPT_PROBEONLY,
Expand All @@ -34,7 +31,7 @@ enum {
OPT_NUMVOICES,
};

struct player_mode pmode[] = {
const struct player_mode pmode[] = {
{ "auto", "Autodetect", XMP_MODE_AUTO },
{ "mod", "Generic MOD player", XMP_MODE_MOD },
{ "noisetracker", "Noisetracker", XMP_MODE_NOISETRACKER },
Expand All @@ -51,22 +48,22 @@ struct player_mode pmode[] = {

static void usage(char *s, struct options *options)
{
struct list_head *head;
struct sound_driver *sd;
struct player_mode *pm;
const struct sound_driver *sd;
const struct player_mode *pm;
const char *const *hlp;
int i;

printf("Usage: %s [options] [modules]\n", s);

printf("\nAvailable drivers:\n");

list_for_each(head, &sound_driver_list) {
sd = list_entry(head, struct sound_driver, list);
for (i = 0; sound_driver_list[i] != NULL; i++) {
sd = sound_driver_list[i];
printf(" %s (%s)\n", sd->id, sd->description);
}

list_for_each(head, &sound_driver_list) {
sd = list_entry(head, struct sound_driver, list);
for (i = 0; sound_driver_list[i] != NULL; i++) {
sd = sound_driver_list[i];
if (sd->help)
printf("\n%s options:\n", sd->description);
for (hlp = sd->help; hlp && *hlp; hlp += 2)
Expand Down Expand Up @@ -178,7 +175,7 @@ static char *token;

void get_options(int argc, char **argv, struct options *options)
{
struct player_mode *pm;
const struct player_mode *pm;
int optidx = 0;
int o;
char const* driver_guess = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/read_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static void parse_modconf(struct options *o, const char *confname, const unsigne
{
FILE *rc;
char *hash, *var, *val, line[256];
struct player_mode *pm;
const struct player_mode *pm;
int active = 0;
int mono = 0;

Expand Down
73 changes: 33 additions & 40 deletions src/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,93 +10,86 @@
#include <string.h>
#include "sound.h"

LIST_HEAD(sound_driver_list);

static void register_sound_driver(struct sound_driver *sd)
{
list_add_tail(&sd->list, &sound_driver_list);
}

void init_sound_drivers(void)
{
const struct sound_driver *const sound_driver_list[] = {
#ifdef SOUND_AHI
register_sound_driver(&sound_ahi);
&sound_ahi,
#endif
#ifdef SOUND_BEOS
register_sound_driver(&sound_beos);
&sound_beos,
#endif
#ifdef SOUND_SNDIO
register_sound_driver(&sound_sndio);
&sound_sndio,
#endif
#ifdef SOUND_NETBSD
register_sound_driver(&sound_netbsd);
&sound_netbsd,
#endif
#ifdef SOUND_BSD
register_sound_driver(&sound_bsd);
&sound_bsd,
#endif
#ifdef SOUND_SOLARIS
register_sound_driver(&sound_solaris);
&sound_solaris,
#endif
#ifdef SOUND_SGI
register_sound_driver(&sound_sgi);
&sound_sgi,
#endif
#ifdef SOUND_HPUX
register_sound_driver(&sound_hpux);
&sound_hpux,
#endif
#ifdef SOUND_AIX
register_sound_driver(&sound_aix);
&sound_aix,
#endif
#ifdef SOUND_COREAUDIO
register_sound_driver(&sound_coreaudio);
&sound_coreaudio,
#endif
#ifdef SOUND_OS2DART
register_sound_driver(&sound_os2dart);
&sound_os2dart,
#endif
#ifdef SOUND_WIN32
register_sound_driver(&sound_win32);
&sound_win32,
#endif
#ifdef SOUND_PULSEAUDIO
register_sound_driver(&sound_pulseaudio);
&sound_pulseaudio,
#endif
#ifdef SOUND_ALSA
register_sound_driver(&sound_alsa);
&sound_alsa,
#endif
#ifdef SOUND_ALSA05
register_sound_driver(&sound_alsa05);
&sound_alsa05,
#endif
#ifdef SOUND_OSS
register_sound_driver(&sound_oss);
&sound_oss,
#endif
#ifdef SOUND_QNX
register_sound_driver(&sound_qnx);
&sound_qnx,
#endif
#ifdef SOUND_SB
register_sound_driver(&sound_sb);
#endif
register_sound_driver(&sound_wav);
register_sound_driver(&sound_aiff);
register_sound_driver(&sound_file);
register_sound_driver(&sound_null);
}
&sound_sb,
#endif
&sound_wav,
&sound_aiff,
&sound_file,
&sound_null,
NULL
};

struct sound_driver *select_sound_driver(struct options *options)
const struct sound_driver *select_sound_driver(struct options *options)
{
struct list_head *head;
struct sound_driver *sd;
const struct sound_driver *sd;
const char *pref = options->driver_id;
int i;

if (pref) {
list_for_each(head, &sound_driver_list) {
sd = list_entry(head, struct sound_driver, list);
for (i = 0; sound_driver_list[i] != NULL; i++) {
sd = sound_driver_list[i];
if (strcmp(sd->id, pref) == 0) {
if (sd->init(options) == 0) {
return sd;
}
}
}
} else {
list_for_each(head, &sound_driver_list) {
sd = list_entry(head, struct sound_driver, list);
for (i = 0; sound_driver_list[i] != NULL; i++) {
sd = sound_driver_list[i];
/* Probing */
if (sd->init(options) == 0) {
/* found */
Expand Down
Loading

0 comments on commit 041ee9f

Please sign in to comment.