home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / MPW / Play Tool 1.0.0 / source / Play.c next >
Encoding:
C/C++ Source or Header  |  1994-04-01  |  2.7 KB  |  103 lines  |  [TEXT/MPS ]

  1. /*****************************************************************
  2. *    Play.c -- Gregory E. Allen
  3. ******************************************************************
  4. *    v1.00 -- 31 Mar 94; Initial release
  5. ******************************************************************
  6. *    Name:
  7. *        Play -- Play a System 7 Sound file
  8. *    Synopsis:
  9. *        Play file…
  10. *    Description:
  11. *        "Play" plays the sound file.
  12. *        (actually plays all sound resources in a file)
  13. ******************************************************************
  14. *    ©1994, Gregory E. Allen <gallen@arlut.utexas.edu>
  15. *    This file may be distributed freely for non-profit use,
  16. *    as long as this header message accompanies it.
  17. *****************************************************************/
  18.  
  19. #include    <Types.h>
  20. #include     <ctype.h>
  21. #include     <fcntl.h>
  22. #include     <string.h>
  23. #include     <stdio.h>
  24. #include    <ErrMgr.h>
  25. #include    <CursorCtl.h>
  26. #include    <Errors.h>
  27. #include    <Devices.h>
  28. #include    <Serial.h>
  29. #include    <Files.h>
  30. #include    <Events.h>
  31. #include     <Strings.h>
  32. #include     <Resources.h>
  33. #include     <Sound.h>
  34.  
  35.  
  36. /* Variables local to this file */
  37.  
  38. static    char    errorBuffer[256];
  39.  
  40. static    char    *usage = "# Usage - %s file….\n";
  41.  
  42. main(int argc, char *argv[])
  43. {
  44.     long            status;
  45.     long            parms;
  46.     long            files;
  47.     long            length;
  48.     long            max;
  49.     FInfo            fi;
  50.     short            input;
  51.     short            err;
  52.     char            pName[256];
  53.     short            i,n;
  54.     Handle            snd;
  55.     
  56.     status = files = 0;
  57.     max = strlen("Total");
  58.     InitCursorCtl(nil);
  59.         
  60.     for (parms = 1; parms < argc; parms++) {
  61.         length = strlen(argv[parms]);
  62.         if (*argv[parms] != '-') {
  63.             argv[++files] = argv[parms];
  64.             if (max < length)
  65.                 max = length;
  66.         } else {
  67.             fprintf(stderr,"### %s - \"%s\" is not an option.\n", argv[0], argv[parms]);
  68.             fprintf(stderr, usage, argv[0]);
  69.             return 1;
  70.         }
  71.     }
  72.     if (files == 0) {
  73.         fprintf(stderr,"# %s - No file specified.\n", argv[0]);
  74.     } else {
  75.         for (parms = 1; parms <= files; parms++) {
  76.             strncpy(pName,argv[parms],255);
  77.             c2pstr(pName);
  78.             if( err = GetFInfo( pName, 0, &fi )) {
  79.                 fprintf(stderr,"### %s - Unable to open file '%s'.\n", argv[0], argv[parms]);
  80.                 fprintf(stderr,"# %s\n", GetSysErrText(err, errorBuffer));
  81.                 status = 2;
  82.             } else {
  83.                 if ( fi.fdType != 'sfil' )
  84.                     fprintf(stderr,"### '%s' is not a System 7 Sound.\n", argv[parms]);
  85.                 if ( (input = OpenResFile( pName )) == -1 ) {
  86.                     fprintf(stderr,"### Error opening resource file '%s'.\n", argv[parms]);
  87.                     status = 2;
  88.                 } else {
  89.                     if ( !(n = Count1Resources('snd ')) )
  90.                         fprintf(stderr,"### '%s' Contains no sound resources.\n", argv[parms]);
  91.                     for (i=1; i<=n; i++ )
  92.                         if (snd = Get1IndResource('snd ', i))
  93.                             if (err = SndPlay(NULL, snd, 0))
  94.                                 fprintf(stderr,"# Error playing sound resource.\n");
  95.                     CloseResFile(input);
  96.                 }
  97.             }
  98.         }
  99.     }
  100.     fflush(stdout);
  101.     return status;
  102. }
  103.