home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 376_01 / os2tool.000 / BELL.C < prev    next >
C/C++ Source or Header  |  1992-08-27  |  3KB  |  125 lines

  1. /*
  2. * BELL.C - Make an audible sound an the terminal. Normally this is used to
  3. *       indicate some sort of an error, but it can also be used to play
  4. *       little tunes.
  5. *
  6. * PROGRAMMER:        Martti Ylikoski
  7. * CREATED:        10.12.1990
  8. */
  9. static char *VERSION = "Version 1.1. Copyright (c) Martti Ylikoski, 1990, 1991. " ;
  10. /*
  11. */
  12.  
  13. /* local prototypes */
  14. int paramfile( char *fname) ;
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include <param.h>
  20. #include <paramstd.h>
  21. #define INCL_DOS
  22. #include <os2.h>
  23.  
  24. static char *progname ;
  25.  
  26. extern unsigned long pflags ;
  27.  
  28. ParamEntry pentry[12] = {
  29.      "P", &ParamSetPause, 0,
  30.      "F", &ParamSetFold, 0,
  31.      "V", &ParamSetVerbose, 0,
  32.      "R", &ParamSetReport, 0,
  33.      "S", &ParamSetSubDirs, 0,
  34.      "?", &ParamSetHelp, 1,
  35.      "H", &ParamSetHelp, 1,
  36.      "NOD", &ParamSetNoDefault, 1,
  37.      "TEST", &ParamSetTest, 0,
  38.      "Y", &ParamSetYes, 0,
  39.      "N", &ParamSetTest, 0,
  40.      "\0", NULL, 0
  41. } ;
  42.  
  43. ParamBlock params = {
  44.     "/-",   IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
  45.     pentry
  46. } ;
  47.  
  48. int main(int argc, char *argv[])
  49. {
  50. USHORT frequency, duration ;
  51. char *freq, *dur ;
  52. int i ;
  53. char buf[512] ;
  54.  
  55.    progname = argv[0] ;
  56.  
  57.    ParamHandle(¶ms, &argc, argv) ;
  58.  
  59.    if (pflags & PA_HELP)
  60.    {
  61.       printf("%s - make an audible sound on the terminal\n", progname) ;
  62.       puts(VERSION) ;
  63.       puts("Usage: bell [/H | /?] [frequency(Hz) duration(milliseconds)]* [/F tunefile]") ;
  64.       puts("Where,") ;
  65.       puts("     /F    = File    /H,/? = Help");
  66.       return( 0 ) ;
  67.    }
  68.  
  69.    if (argc == 1)
  70.    {
  71.       if ( (freq=getenv("BELLFREQ")) != NULL &&
  72.            (dur=getenv("BELLDUR")) != NULL && ! (pflags & PA_NODEFAULT) )
  73.       {
  74.          frequency = atoi(freq) ;
  75.          duration = atoi(dur) ;
  76.          DosBeep( frequency, duration ) ;
  77.       }
  78.       else
  79.       {
  80.          fprintf(stderr, "BELL: stdin assumed.\n") ;
  81.          paramfile("-") ;
  82.       }
  83.    }
  84.    else
  85.       if (strcmpi(argv[1],"-F") == 0 || strcmpi(argv[1],"/F") == 0)
  86.       {
  87.      paramfile(argv[2]) ;
  88.       }
  89.       else
  90.       {
  91.      for (i = 1; i < argc ; i += 2)
  92.      {
  93.         frequency = atoi(argv[i]) ;
  94.         duration = atoi (argv[i+1]) ;
  95.         DosBeep( frequency, duration ) ;
  96.      }
  97.       }
  98.    return( 0 ) ;
  99. }
  100.  
  101. int paramfile( char *fname)
  102. {
  103. FILE *fptr ;
  104. char buf[512] ;
  105. USHORT frequency, duration ;
  106.  
  107.    if (strcmp(fname, "-") == 0)
  108.       fptr = stdin ;
  109.    else
  110.       if ((fptr = fopen(fname, "r")) == NULL)
  111.       {
  112.      fprintf(stderr,"%s: error opening file %s\nExiting...\n", progname, fname) ;
  113.      return( 1 ) ;
  114.       }
  115.  
  116.    while (fgets(buf, sizeof(buf), fptr) != NULL)
  117.    {
  118.       sscanf(buf, "%d %d", &frequency, &duration) ;
  119.       DosBeep( frequency, duration ) ;
  120.    }
  121.  
  122.    fclose(fptr) ;
  123.    return( 0 ) ;
  124. }
  125.