playmus.c
changeset 488 94b190330355
parent 386 695494546b3c
child 503 0c77794aaef2
     1.1 --- a/playmus.c	Tue Apr 13 22:28:38 2010 -0700
     1.2 +++ b/playmus.c	Tue Apr 13 22:30:19 2010 -0700
     1.3 @@ -25,7 +25,10 @@
     1.4  #include <stdlib.h>
     1.5  #include <stdio.h>
     1.6  #include <string.h>
     1.7 +
     1.8 +#ifdef HAVE_SIGNAL_H
     1.9  #include <signal.h>
    1.10 +#endif
    1.11  #ifdef unix
    1.12  #include <unistd.h>
    1.13  #endif
    1.14 @@ -67,25 +70,28 @@
    1.15  
    1.16  	printf("Available commands: (p)ause (r)esume (h)alt volume(v#) > ");
    1.17  	fflush(stdin);
    1.18 -	scanf("%s",buf);
    1.19 -	switch(buf[0]){
    1.20 -	case 'p': case 'P':
    1.21 -		Mix_PauseMusic();
    1.22 -		break;
    1.23 -	case 'r': case 'R':
    1.24 -		Mix_ResumeMusic();
    1.25 -		break;
    1.26 -	case 'h': case 'H':
    1.27 -		Mix_HaltMusic();
    1.28 -		break;
    1.29 -	case 'v': case 'V':
    1.30 -		Mix_VolumeMusic(atoi(buf+1));
    1.31 -		break;
    1.32 +	if (scanf("%s",buf) == 1) {
    1.33 +		switch(buf[0]){
    1.34 +		case 'p': case 'P':
    1.35 +			Mix_PauseMusic();
    1.36 +			break;
    1.37 +		case 'r': case 'R':
    1.38 +			Mix_ResumeMusic();
    1.39 +			break;
    1.40 +		case 'h': case 'H':
    1.41 +			Mix_HaltMusic();
    1.42 +			break;
    1.43 +		case 'v': case 'V':
    1.44 +			Mix_VolumeMusic(atoi(buf+1));
    1.45 +			break;
    1.46 +		}
    1.47  	}
    1.48  	printf("Music playing: %s Paused: %s\n", Mix_PlayingMusic() ? "yes" : "no", 
    1.49  		   Mix_PausedMusic() ? "yes" : "no");
    1.50  }
    1.51  
    1.52 +#ifdef HAVE_SIGNAL_H
    1.53 +
    1.54  void IntHandler(int sig)
    1.55  {
    1.56  	switch (sig) {
    1.57 @@ -95,9 +101,11 @@
    1.58  	}
    1.59  }
    1.60  
    1.61 +#endif
    1.62 +
    1.63  int main(int argc, char *argv[])
    1.64  {
    1.65 -	SDL_RWops *rwfp;
    1.66 +	SDL_RWops *rwfp = NULL;
    1.67  	int audio_rate;
    1.68  	Uint16 audio_format;
    1.69  	int audio_channels;
    1.70 @@ -162,8 +170,10 @@
    1.71  		return(255);
    1.72  	}
    1.73  
    1.74 +#ifdef HAVE_SIGNAL_H
    1.75  	signal(SIGINT, IntHandler);
    1.76  	signal(SIGTERM, CleanUp);
    1.77 +#endif
    1.78  
    1.79  	/* Open the audio device */
    1.80  	if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
    1.81 @@ -183,7 +193,7 @@
    1.82  	Mix_VolumeMusic(audio_volume);
    1.83  
    1.84  	/* Set the external music player, if any */
    1.85 -	Mix_SetMusicCMD(getenv("MUSIC_CMD"));
    1.86 +	Mix_SetMusicCMD(SDL_getenv("MUSIC_CMD"));
    1.87  
    1.88  	while (argv[i]) {
    1.89  		next_track = 0;