Skip to content

Commit 041ee9f

Browse files
authored
Merge pull request #65 from ccawley2011/const-arrays
Make more static arrays const
2 parents 54bdcd7 + 2d1a998 commit 041ee9f

31 files changed

+94
-247
lines changed

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ AM_CFLAGS = -Wall
77
bin_PROGRAMS = xmp
88

99
xmp_SOURCES = \
10-
commands.c common.h delay.c getopt_long.h list.h getopt_long.c info.c \
10+
commands.c common.h delay.c getopt_long.h getopt_long.c info.c \
1111
main.c options.c read_config.c sound.c sound.h sound_file.c sound_null.c \
1212
sound_wav.c sound_aiff.c terminal.c util.c xmp_version.h
1313
xmp_LDADD = ${LIBXMP_LIBS}

src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct control {
7878
int mixer_type; /* Mixer type (from player) */
7979
};
8080

81-
extern struct player_mode pmode[];
81+
extern const struct player_mode pmode[];
8282

8383
void delay_ms(unsigned int);
8484
#ifdef XMP_AMIGA

src/info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void info_mod(const struct xmp_module_info *mi, int mode)
5252
report("Module type : %s", mi->mod->type);
5353

5454
if (mode != XMP_MODE_AUTO) {
55-
struct player_mode *pm;
55+
const struct player_mode *pm;
5656
for (pm = pmode; pm->name != NULL; pm++) {
5757
if (pm->mode == mode) {
5858
report(" [play as:%s]", pm->desc);

src/list.h

Lines changed: 0 additions & 142 deletions
This file was deleted.

src/main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include <windows.h>
4646
#endif
4747

48-
static struct sound_driver *sound;
48+
static const struct sound_driver *sound;
4949
static unsigned int foreground_in, foreground_out;
5050
static int refresh_status;
5151

@@ -269,8 +269,6 @@ int main(int argc, char **argv)
269269
srand(tv.tv_usec);
270270
#endif
271271

272-
init_sound_drivers();
273-
274272
memset(&opt, 0, sizeof (struct options));
275273
memset(&control, 0, sizeof (struct control));
276274

src/options.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
#include "common.h"
1919
#include "sound.h"
20-
#include "list.h"
2120
#include "xmp_version.h"
2221

23-
extern struct list_head sound_driver_list;
24-
2522
enum {
2623
OPT_FX9BUG = 0x105,
2724
OPT_PROBEONLY,
@@ -34,7 +31,7 @@ enum {
3431
OPT_NUMVOICES,
3532
};
3633

37-
struct player_mode pmode[] = {
34+
const struct player_mode pmode[] = {
3835
{ "auto", "Autodetect", XMP_MODE_AUTO },
3936
{ "mod", "Generic MOD player", XMP_MODE_MOD },
4037
{ "noisetracker", "Noisetracker", XMP_MODE_NOISETRACKER },
@@ -51,22 +48,22 @@ struct player_mode pmode[] = {
5148

5249
static void usage(char *s, struct options *options)
5350
{
54-
struct list_head *head;
55-
struct sound_driver *sd;
56-
struct player_mode *pm;
51+
const struct sound_driver *sd;
52+
const struct player_mode *pm;
5753
const char *const *hlp;
54+
int i;
5855

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

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

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

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

179176
void get_options(int argc, char **argv, struct options *options)
180177
{
181-
struct player_mode *pm;
178+
const struct player_mode *pm;
182179
int optidx = 0;
183180
int o;
184181
char const* driver_guess = NULL;

src/read_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static void parse_modconf(struct options *o, const char *confname, const unsigne
203203
{
204204
FILE *rc;
205205
char *hash, *var, *val, line[256];
206-
struct player_mode *pm;
206+
const struct player_mode *pm;
207207
int active = 0;
208208
int mono = 0;
209209

src/sound.c

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,93 +10,86 @@
1010
#include <string.h>
1111
#include "sound.h"
1212

13-
LIST_HEAD(sound_driver_list);
14-
15-
static void register_sound_driver(struct sound_driver *sd)
16-
{
17-
list_add_tail(&sd->list, &sound_driver_list);
18-
}
19-
20-
void init_sound_drivers(void)
21-
{
13+
const struct sound_driver *const sound_driver_list[] = {
2214
#ifdef SOUND_AHI
23-
register_sound_driver(&sound_ahi);
15+
&sound_ahi,
2416
#endif
2517
#ifdef SOUND_BEOS
26-
register_sound_driver(&sound_beos);
18+
&sound_beos,
2719
#endif
2820
#ifdef SOUND_SNDIO
29-
register_sound_driver(&sound_sndio);
21+
&sound_sndio,
3022
#endif
3123
#ifdef SOUND_NETBSD
32-
register_sound_driver(&sound_netbsd);
24+
&sound_netbsd,
3325
#endif
3426
#ifdef SOUND_BSD
35-
register_sound_driver(&sound_bsd);
27+
&sound_bsd,
3628
#endif
3729
#ifdef SOUND_SOLARIS
38-
register_sound_driver(&sound_solaris);
30+
&sound_solaris,
3931
#endif
4032
#ifdef SOUND_SGI
41-
register_sound_driver(&sound_sgi);
33+
&sound_sgi,
4234
#endif
4335
#ifdef SOUND_HPUX
44-
register_sound_driver(&sound_hpux);
36+
&sound_hpux,
4537
#endif
4638
#ifdef SOUND_AIX
47-
register_sound_driver(&sound_aix);
39+
&sound_aix,
4840
#endif
4941
#ifdef SOUND_COREAUDIO
50-
register_sound_driver(&sound_coreaudio);
42+
&sound_coreaudio,
5143
#endif
5244
#ifdef SOUND_OS2DART
53-
register_sound_driver(&sound_os2dart);
45+
&sound_os2dart,
5446
#endif
5547
#ifdef SOUND_WIN32
56-
register_sound_driver(&sound_win32);
48+
&sound_win32,
5749
#endif
5850
#ifdef SOUND_PULSEAUDIO
59-
register_sound_driver(&sound_pulseaudio);
51+
&sound_pulseaudio,
6052
#endif
6153
#ifdef SOUND_ALSA
62-
register_sound_driver(&sound_alsa);
54+
&sound_alsa,
6355
#endif
6456
#ifdef SOUND_ALSA05
65-
register_sound_driver(&sound_alsa05);
57+
&sound_alsa05,
6658
#endif
6759
#ifdef SOUND_OSS
68-
register_sound_driver(&sound_oss);
60+
&sound_oss,
6961
#endif
7062
#ifdef SOUND_QNX
71-
register_sound_driver(&sound_qnx);
63+
&sound_qnx,
7264
#endif
7365
#ifdef SOUND_SB
74-
register_sound_driver(&sound_sb);
75-
#endif
76-
register_sound_driver(&sound_wav);
77-
register_sound_driver(&sound_aiff);
78-
register_sound_driver(&sound_file);
79-
register_sound_driver(&sound_null);
80-
}
66+
&sound_sb,
67+
#endif
68+
&sound_wav,
69+
&sound_aiff,
70+
&sound_file,
71+
&sound_null,
72+
NULL
73+
};
8174

82-
struct sound_driver *select_sound_driver(struct options *options)
75+
const struct sound_driver *select_sound_driver(struct options *options)
8376
{
84-
struct list_head *head;
85-
struct sound_driver *sd;
77+
const struct sound_driver *sd;
8678
const char *pref = options->driver_id;
79+
int i;
8780

8881
if (pref) {
89-
list_for_each(head, &sound_driver_list) {
90-
sd = list_entry(head, struct sound_driver, list);
82+
for (i = 0; sound_driver_list[i] != NULL; i++) {
83+
sd = sound_driver_list[i];
9184
if (strcmp(sd->id, pref) == 0) {
9285
if (sd->init(options) == 0) {
9386
return sd;
9487
}
9588
}
9689
}
9790
} else {
98-
list_for_each(head, &sound_driver_list) {
99-
sd = list_entry(head, struct sound_driver, list);
91+
for (i = 0; sound_driver_list[i] != NULL; i++) {
92+
sd = sound_driver_list[i];
10093
/* Probing */
10194
if (sd->init(options) == 0) {
10295
/* found */

0 commit comments

Comments
 (0)