home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / INTERNET / UPC2S1.ZIP / TRUMPET.C < prev    next >
C/C++ Source or Header  |  1993-09-20  |  5KB  |  147 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       t r u m p e t . c                                            */
  3. /*                                                                    */
  4. /*       Audio support for UUPC/extended                              */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  9. /*       Wonderworks.                                                 */
  10. /*                                                                    */
  11. /*       All rights reserved except those explicitly granted by       */
  12. /*       the UUPC/extended license agreement.                         */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: trumpet.c 1.2 1993/09/20 04:39:51 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: trumpet.c $
  24.  * Revision 1.2  1993/09/20  04:39:51  ahd
  25.  * OS/2 2.x support
  26.  *
  27.  * Revision 1.1  1993/07/31  16:22:16  ahd
  28.  * Initial revision
  29.  *
  30.  */
  31.  
  32. /*--------------------------------------------------------------------*/
  33. /*    Use a complex beep upon mail delivery if way to control the     */
  34. /*    speaker is available; if using MS C 6.0 under DOS, we can't     */
  35. /*    so don't try                                                    */
  36. /*--------------------------------------------------------------------*/
  37.  
  38. #if defined(__TURBOC__) && !defined(_Windows)
  39. #define SMARTBEEP
  40. #endif
  41.  
  42. #if defined(FAMILYAPI) || defined(WIN32) || defined(__OS2__)
  43. #define SMARTBEEP
  44. #endif
  45.  
  46. /*--------------------------------------------------------------------*/
  47. /*                        System include files                        */
  48. /*--------------------------------------------------------------------*/
  49.  
  50. #include <stdio.h>
  51. #include <stdlib.h>
  52. #include <io.h>
  53. #include <ctype.h>
  54. #include <sys/types.h>
  55. #include <string.h>
  56. #include <process.h>
  57. #include <limits.h>
  58.  
  59. #ifdef __TURBOC__
  60. #include <dos.h>
  61. #endif
  62.  
  63. #ifdef WIN32
  64. #include <windows.h>
  65. #endif
  66.  
  67. #if defined(FAMILYAPI) || defined(__OS2__)
  68. #include <os2.h>
  69. #endif
  70.  
  71. /*--------------------------------------------------------------------*/
  72. /*                    UUPC/extended include files                     */
  73. /*--------------------------------------------------------------------*/
  74.  
  75. #include "lib.h"
  76.  
  77. #ifdef SMARTBEEP
  78. #include "ssleep.h"
  79. #endif
  80.  
  81. /*--------------------------------------------------------------------*/
  82. /*    t r u m p e t                                                   */
  83. /*                                                                    */
  84. /*    Trumpet the arrival of remote mail to a local user              */
  85. /*--------------------------------------------------------------------*/
  86.  
  87. void trumpet( const char *tune)
  88. {
  89. #ifdef SMARTBEEP
  90.    char buf[BUFSIZ];
  91.    char *token = buf;
  92.    size_t tone, duration;
  93. #endif
  94.  
  95.    if (tune == NULL)          /* Should we announce?  */
  96.       return;                 /* No --> Return quietly (literally)   */
  97.  
  98. /*--------------------------------------------------------------------*/
  99. /*             We are to announce the arrival of the mail             */
  100. /*--------------------------------------------------------------------*/
  101.  
  102. #ifdef SMARTBEEP
  103.    strcpy(buf,tune);          /* Save the data                       */
  104.  
  105.    while( (token = strtok( token, ",")) != NULL)
  106.    {
  107.       tone = (size_t) atoi(token);
  108.       token = strtok( NULL, ",");
  109.       duration = (token == NULL) ? 500 : (size_t) atoi(token);
  110.  
  111. #ifdef WIN32
  112.       Beep( tone, duration );
  113.  
  114.       if (tone == 0)
  115.          ddelay(duration);
  116.  
  117. #elif defined(FAMILYAPI) || defined(__OS2__)
  118.  
  119.       DosBeep( tone, duration );
  120.  
  121.       if (tone == 0)
  122.          ddelay(duration);
  123.  
  124. #else
  125.       if (tone != 0)
  126.          sound( tone );
  127.  
  128.       ddelay(duration);
  129.  
  130.       nosound();
  131.  
  132. #endif /* __TURBOC__ */
  133.  
  134.       token = NULL;           /* Look at next part of string   */
  135.    } /* while */
  136.  
  137. #else /* SMARTBEEP */
  138.  
  139. /*--------------------------------------------------------------------*/
  140. /*      We cannot play the requested tune; just beep at the user      */
  141. /*--------------------------------------------------------------------*/
  142.  
  143.    fputc('\a', stdout);
  144. #endif /* SMARTBEEP */
  145.  
  146. } /* trumpet */
  147.