comparison playsound/playsound.c @ 320:8195b86207bb

Mac fixes, and removed all alloca() calls.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 29 Apr 2002 06:03:03 +0000
parents 9e21cb0d3ae7
children f0f894d897bf
comparison
equal deleted inserted replaced
319:4a2cd7d4aa06 320:8195b86207bb
32 #include <signal.h> 32 #include <signal.h>
33 #include "SDL.h" 33 #include "SDL.h"
34 #include "SDL_sound.h" 34 #include "SDL_sound.h"
35 35
36 #if SUPPORT_PHYSFS 36 #if SUPPORT_PHYSFS
37 #include <alloca.h>
38 #include "physfs.h" 37 #include "physfs.h"
39 #include "physfsrwops.h" 38 #include "physfsrwops.h"
40 #endif 39 #endif
41 40
42 #define DEFAULT_DECODEBUF 16384 41 #define DEFAULT_DECODEBUF 16384
186 #if SUPPORT_PHYSFS 185 #if SUPPORT_PHYSFS
187 static SDL_RWops *rwops_from_physfs(const char *filename) 186 static SDL_RWops *rwops_from_physfs(const char *filename)
188 { 187 {
189 SDL_RWops *retval = NULL; 188 SDL_RWops *retval = NULL;
190 189
191 char *path = (char *) alloca(strlen(filename) + 1); 190 char *path = (char *) malloc(strlen(filename) + 1);
192 char *archive; 191 char *archive;
192
193 if (path == NULL)
194 {
195 fprintf(stderr, "Out of memory!\n");
196 return(NULL);
197 } /* if */
193 198
194 strcpy(path, filename); 199 strcpy(path, filename);
195 archive = strchr(path, '@'); 200 archive = strchr(path, '@');
196 if (archive != NULL) 201 if (archive != NULL)
197 { 202 {
198 *(archive++) = '\0'; /* blank '@', point to archive name. */ 203 *(archive++) = '\0'; /* blank '@', point to archive name. */
199 if (!PHYSFS_addToSearchPath(archive, 0)) 204 if (!PHYSFS_addToSearchPath(archive, 0))
200 { 205 {
201 fprintf(stderr, "Couldn't open archive: %s\n", 206 fprintf(stderr, "Couldn't open archive: %s\n",
202 PHYSFS_getLastError()); 207 PHYSFS_getLastError());
208 free(path);
203 return(NULL); 209 return(NULL);
204 } /* if */ 210 } /* if */
205 211
206 retval = PHYSFSRWOPS_openRead(path); 212 retval = PHYSFSRWOPS_openRead(path);
207 } /* if */ 213 } /* if */
208 214
215 free(path);
209 return(retval); 216 return(retval);
210 } /* rwops_from_physfs */ 217 } /* rwops_from_physfs */
211 #endif 218 #endif
212 219
213 220
214 static Sound_Sample *sample_from_archive(const char *fname, 221 static Sound_Sample *sample_from_archive(const char *fname,
215 Sound_AudioInfo *desired, 222 Sound_AudioInfo *desired,
216 Uint32 decode_buffersize) 223 Uint32 decode_buffersize)
217 { 224 {
225 Sound_Sample *retval = NULL;
226
218 #if SUPPORT_PHYSFS 227 #if SUPPORT_PHYSFS
219 SDL_RWops *rw = rwops_from_physfs(fname); 228 SDL_RWops *rw = rwops_from_physfs(fname);
220 if (rw != NULL) 229 if (rw != NULL)
221 { 230 {
222 char *path = (char *) alloca(strlen(fname) + 1); 231 char *path = (char *) malloc(strlen(fname) + 1);
223 char *ptr; 232 char *ptr;
224 strcpy(path, fname); 233 strcpy(path, fname);
225 ptr = strchr(path, '@'); 234 ptr = strchr(path, '@');
226 *ptr = '\0'; 235 *ptr = '\0';
227 ptr = strrchr(path, '.'); 236 ptr = strrchr(path, '.');
228 if (ptr != NULL) 237 if (ptr != NULL)
229 ptr++; 238 ptr++;
230 239
231 return(Sound_NewSample(rw, ptr, desired, decode_buffersize)); 240 retval = Sound_NewSample(rw, ptr, desired, decode_buffersize);
241 free(path);
232 } /* if */ 242 } /* if */
233 #endif 243 #endif
234 244
235 return(NULL); 245 return(retval);
236 } /* sample_from_archive */ 246 } /* sample_from_archive */
237 247
238 248
239 static void close_archive(const char *filename) 249 static void close_archive(const char *filename)
240 { 250 {
558 568
559 569
560 static void parse_seek_list(const char *_list) 570 static void parse_seek_list(const char *_list)
561 { 571 {
562 Uint32 i; 572 Uint32 i;
563 char *list = alloca(strlen(_list) + 1); 573
574 char *list = (char*) malloc(strlen(_list) + 1);
575 char *save_list = list;
564 if (list == NULL) 576 if (list == NULL)
565 { 577 {
566 fprintf(stderr, "alloca() failed. Skipping seek list.\n"); 578 fprintf(stderr, "malloc() failed. Skipping seek list.\n");
567 return; 579 return;
568 } /* if */ 580 } /* if */
569 581
570 strcpy(list, _list); 582 strcpy(list, _list);
571 583
587 if (ptr != NULL) 599 if (ptr != NULL)
588 *ptr = '\0'; 600 *ptr = '\0';
589 seek_list[i] = parse_time_str(list); 601 seek_list[i] = parse_time_str(list);
590 list = ptr + 1; 602 list = ptr + 1;
591 } /* for */ 603 } /* for */
604
605 free(save_list);
592 } /* parse_seek_list */ 606 } /* parse_seek_list */
593 607
594 608
595 static int str_to_fmt(char *str) 609 static int str_to_fmt(char *str)
596 { 610 {
918 printf("done.\n"); 932 printf("done.\n");
919 } /* else */ 933 } /* else */
920 } /* if */ 934 } /* if */
921 935
922 SDL_PauseAudio(0); 936 SDL_PauseAudio(0);
937 #if ENABLE_EVENTS
938 {
939 SDL_Surface *screen;
940 SDL_Event event;
941
942 screen = SDL_SetVideoMode (320, 240, 8, 0);
943
944 while (!done_flag) {
945
946 SDL_Delay(1);
947 SDL_PollEvent (&event);
948
949 if (event.type == SDL_KEYDOWN) {
950
951 done_flag = 1;
952 break;
953 }
954
955 }
956 }
957 #endif /* ENABLE_EVENTS */
923 while (!done_flag) 958 while (!done_flag)
924 { 959 {
925 SDL_Delay(10); 960 SDL_Delay(10);
926 } /* while */ 961 } /* while */
927 SDL_PauseAudio(1); 962 SDL_PauseAudio(1);