changeset 148:d51546293fd1

Support for multiple file extensions in the decoders, and a SIGINT catcher.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 01 Nov 2001 19:12:36 +0000
parents 9d122da5f5a9
children 1df5c106504e
files playsound/playsound.c
diffstat 1 files changed, 41 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/playsound/playsound.c	Tue Oct 23 18:29:00 2001 +0000
+++ b/playsound/playsound.c	Thu Nov 01 19:12:36 2001 +0000
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
+#include <signal.h>
 #include "SDL.h"
 #include "SDL_sound.h"
 
@@ -48,12 +49,11 @@
     SDL_VERSION(&sdl_compiled);
     sdl_linked = SDL_Linked_Version();
 
-    fprintf(stderr,
-            "%s version %d.%d.%d.\n"
-            " Compiled against SDL_sound version %d.%d.%d,\n"
-            " and linked against %d.%d.%d.\n"
-            " Compiled against SDL version %d.%d.%d,\n"
-            " and linked against %d.%d.%d.\n\n",
+    printf("%s version %d.%d.%d.\n"
+           " Compiled against SDL_sound version %d.%d.%d,\n"
+           " and linked against %d.%d.%d.\n"
+           " Compiled against SDL version %d.%d.%d,\n"
+           " and linked against %d.%d.%d.\n\n",
              argv0,
              PLAYSOUND_VER_MAJOR, PLAYSOUND_VER_MINOR, PLAYSOUND_VER_PATCH,
              compiled.major, compiled.minor, compiled.patch,
@@ -67,26 +67,53 @@
 {
     const Sound_DecoderInfo **rc = Sound_AvailableDecoders();
     const Sound_DecoderInfo **i;
+    const char **ext;
 
-    fprintf(stderr, "Supported sound formats:\n");
+    printf("Supported sound formats:\n");
     if (rc == NULL)
-        fprintf(stderr, " * Apparently, NONE!\n");
+        printf(" * Apparently, NONE!\n");
     else
     {
         for (i = rc; *i != NULL; i++)
         {
-            fprintf(stderr, " * %s: %s\n    Written by %s.\n    %s\n",
-                    (*i)->extension, (*i)->description,
-                    (*i)->author, (*i)->url);
+            printf(" * %s\n", (*i)->description);
+            for (ext = (*i)->extensions; *ext != NULL; ext++)
+                printf("   Extension \"%s\"\n", *ext);
+            printf("   Written by %s.\n   %s\n\n", (*i)->author, (*i)->url);
         } /* for */
     } /* else */
 
-    fprintf(stderr, "\n");
+    printf("\n");
 } /* output_decoders */
 
 
 static volatile int done_flag = 0;
 
+
+void sigint_catcher(int signum)
+{
+    static Uint32 last_sigint = 0;
+    Uint32 ticks = SDL_GetTicks();
+
+    assert(signum == SIGINT);
+
+    if ((last_sigint != 0) && (ticks - last_sigint < 500))
+    {
+        SDL_PauseAudio(1);
+        SDL_CloseAudio();
+        Sound_Quit();
+        SDL_Quit();
+        exit(1);
+    } /* if */
+
+    else
+    {
+        last_sigint = ticks;
+        done_flag = 1;
+    } /* else */
+} /* sigint_catcher */
+
+
 static Uint8 *decoded_ptr = NULL;
 static Uint32 decoded_bytes = 0;
 
@@ -288,6 +315,8 @@
         return(42);
     } /* if */
 
+    signal(SIGINT, sigint_catcher);
+
     for (i = 1; i < argc; i++)
     {
             /* !!! FIXME: This is ugly! */