playmus.c
changeset 256 6d7e102500c9
parent 245 63b3650714de
child 257 8a32c0a3c609
     1.1 --- a/playmus.c	Tue Dec 21 17:52:16 2004 +0000
     1.2 +++ b/playmus.c	Tue Dec 21 20:08:57 2004 +0000
     1.3 @@ -57,7 +57,7 @@
     1.4  
     1.5  void Usage(char *argv0)
     1.6  {
     1.7 -	fprintf(stderr, "Usage: %s [-i] [-l] [-8] [-r rate] [-c channels] [-b buffers] [-v N] <musicfile>\n", argv0);
     1.8 +	fprintf(stderr, "Usage: %s [-i] [-l] [-8] [-r rate] [-c channels] [-b buffers] [-v N] [-rwops] <musicfile>\n", argv0);
     1.9  }
    1.10  
    1.11  void Menu(void)
    1.12 @@ -93,6 +93,7 @@
    1.13  
    1.14  int main(int argc, char *argv[])
    1.15  {
    1.16 +	SDL_RWops *rwfp;
    1.17  	int audio_rate;
    1.18  	Uint16 audio_format;
    1.19  	int audio_channels;
    1.20 @@ -100,6 +101,7 @@
    1.21  	int audio_volume = MIX_MAX_VOLUME;
    1.22  	int looping = 0;
    1.23  	int interactive = 0;
    1.24 +	int rwops = 0;
    1.25  	int i;
    1.26  
    1.27  	/* Initialize variables */
    1.28 @@ -137,6 +139,9 @@
    1.29  		} else
    1.30  		if ( strcmp(argv[i], "-8") == 0 ) {
    1.31  			audio_format = AUDIO_U8;
    1.32 +		} else
    1.33 +		if ( strcmp(argv[i], "-rwops") == 0 ) {
    1.34 +			rwops = 1;
    1.35  		} else {
    1.36  			Usage(argv[0]);
    1.37  			return(1);
    1.38 @@ -180,7 +185,12 @@
    1.39  		next_track = 0;
    1.40  		
    1.41  		/* Load the requested music file */
    1.42 -		music = Mix_LoadMUS(argv[i]);
    1.43 +		if ( rwops ) {
    1.44 +			rwfp = SDL_RWFromFile(argv[i], "rb");
    1.45 +			music = Mix_LoadMUS(argv[i]);
    1.46 +		} else {
    1.47 +			music = Mix_LoadMUS(argv[i]);
    1.48 +		}
    1.49  		if ( music == NULL ) {
    1.50  			fprintf(stderr, "Couldn't load %s: %s\n",
    1.51  				argv[i], SDL_GetError());
    1.52 @@ -197,6 +207,9 @@
    1.53  				SDL_Delay(100);
    1.54  		}
    1.55  		Mix_FreeMusic(music);
    1.56 +		if ( rwops ) {
    1.57 +			SDL_FreeRW(rwfp);
    1.58 +		}
    1.59  		music = NULL;
    1.60  
    1.61  		/* If the user presses Ctrl-C more than once, exit. */