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 >
Wrap
C/C++ Source or Header
|
1992-08-27
|
3KB
|
125 lines
/*
* BELL.C - Make an audible sound an the terminal. Normally this is used to
* indicate some sort of an error, but it can also be used to play
* little tunes.
*
* PROGRAMMER: Martti Ylikoski
* CREATED: 10.12.1990
*/
static char *VERSION = "Version 1.1. Copyright (c) Martti Ylikoski, 1990, 1991. " ;
/*
*/
/* local prototypes */
int paramfile( char *fname) ;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <param.h>
#include <paramstd.h>
#define INCL_DOS
#include <os2.h>
static char *progname ;
extern unsigned long pflags ;
ParamEntry pentry[12] = {
"P", &ParamSetPause, 0,
"F", &ParamSetFold, 0,
"V", &ParamSetVerbose, 0,
"R", &ParamSetReport, 0,
"S", &ParamSetSubDirs, 0,
"?", &ParamSetHelp, 1,
"H", &ParamSetHelp, 1,
"NOD", &ParamSetNoDefault, 1,
"TEST", &ParamSetTest, 0,
"Y", &ParamSetYes, 0,
"N", &ParamSetTest, 0,
"\0", NULL, 0
} ;
ParamBlock params = {
"/-", IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
pentry
} ;
int main(int argc, char *argv[])
{
USHORT frequency, duration ;
char *freq, *dur ;
int i ;
char buf[512] ;
progname = argv[0] ;
ParamHandle(¶ms, &argc, argv) ;
if (pflags & PA_HELP)
{
printf("%s - make an audible sound on the terminal\n", progname) ;
puts(VERSION) ;
puts("Usage: bell [/H | /?] [frequency(Hz) duration(milliseconds)]* [/F tunefile]") ;
puts("Where,") ;
puts(" /F = File /H,/? = Help");
return( 0 ) ;
}
if (argc == 1)
{
if ( (freq=getenv("BELLFREQ")) != NULL &&
(dur=getenv("BELLDUR")) != NULL && ! (pflags & PA_NODEFAULT) )
{
frequency = atoi(freq) ;
duration = atoi(dur) ;
DosBeep( frequency, duration ) ;
}
else
{
fprintf(stderr, "BELL: stdin assumed.\n") ;
paramfile("-") ;
}
}
else
if (strcmpi(argv[1],"-F") == 0 || strcmpi(argv[1],"/F") == 0)
{
paramfile(argv[2]) ;
}
else
{
for (i = 1; i < argc ; i += 2)
{
frequency = atoi(argv[i]) ;
duration = atoi (argv[i+1]) ;
DosBeep( frequency, duration ) ;
}
}
return( 0 ) ;
}
int paramfile( char *fname)
{
FILE *fptr ;
char buf[512] ;
USHORT frequency, duration ;
if (strcmp(fname, "-") == 0)
fptr = stdin ;
else
if ((fptr = fopen(fname, "r")) == NULL)
{
fprintf(stderr,"%s: error opening file %s\nExiting...\n", progname, fname) ;
return( 1 ) ;
}
while (fgets(buf, sizeof(buf), fptr) != NULL)
{
sscanf(buf, "%d %d", &frequency, &duration) ;
DosBeep( frequency, duration ) ;
}
fclose(fptr) ;
return( 0 ) ;
}