25#define HOSTNAME_LEN 200
35 char *p = str + strlen(str);
36 while(*str !=
'\0' && *str !=
'\r' && *str !=
'\n' && isspace(*str)) {
40 while(p > str && isspace(p[-1])) {
55#define NMAGICEVENTS (sizeof(magic_events) / sizeof(*magic_events))
76#define NEVENTS (event_names_size() + NMAGICEVENTS)
92 fprintf(stderr,
"BUG: sound_fd not set but sound inited.\n");
103 rplay_perror(
"create");
110 if((
rp = calloc(
NEVENTS,
sizeof(RPLAY *))) == NULL) {
111 perror(
"calloc() rplay control");
141 rplay_destroy(
rp[i]);
161 fprintf(stderr,
"Tried to load sounds before subsystem inited.\n");
166 if((home = getenv(
"HOME")) == NULL) {
169 if(asprintf(&soundfile,
"%s/.ctwm-sounds", home) < 0) {
170 perror(
"Failed building path to sound file");
173 fl = fopen(soundfile,
"r");
181 fprintf(stderr,
"RplaySounds set in ctwmrc, not reading "
182 "~/.ctwm-sounds.\n");
196 while(fgets(buffer, 100, fl) != NULL) {
197 char *ename, *sndfile;
200 if(ename == NULL || *ename ==
'#') {
205 if(sndfile == NULL || *sndfile ==
'#') {
210 fprintf(stderr,
"Error adding sound for %s; maybe event "
211 "name is invalid?\n", ename);
225 if(snd < 0 || snd >=
NEVENTS) {
236 fprintf(stderr,
"BUG: play_sound() Sound should be initted already.\n");
241 if(
rp[snd] == NULL) {
247 rplay_perror(
"rplay");
333 fprintf(stderr,
"%s(): internal error: called before initialized.\n", __func__);
338 if(
rp[snd] != NULL) {
339 rplay_destroy(
rp[snd]);
343 rp[snd] = rplay_create(RPLAY_PLAY);
344 if(
rp[snd] == NULL) {
345 rplay_perror(
"create");
348 if(rplay_set(
rp[snd], RPLAY_INSERT, 0, RPLAY_SOUND, soundfile, NULL)
350 rplay_perror(
"rplay");
size_t event_names_size(void)
int event_num_by_name(const char *ename)
void sound_clear_list(void)
static int sound_from_config
void sound_load_list(void)
static int need_sound_init
void sound_set_from_config(void)
int set_sound_event_name(const char *ename, const char *soundfile)
static int sound_magic_event_name2num(const char *name)
static char hostname[200]
static const char * magic_events[]
int set_sound_event(int snd, const char *soundfile)
void play_startup_sound(void)
void play_exit_sound(void)
void set_sound_host(char *host)
static char * trim_spaces(char *str)