Bleeper Program
S. Wilson
swi at cs.paisley.ac.uk
Sat Oct 4 02:44:03 AEST 1986
Sender:Scott Wilson
This is a small terminal bleeper program to alert non loged in
users
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# bleep.c
# This archive created: Wed Sep 17 12:08:09 1986
export PATH; PATH=/bin:$PATH
if test -f 'bleep.c'
then
echo shar: will not over-write existing file "'bleep.c'"
else
cat << \SHAR_EOF > 'bleep.c'
/* Terminal bleeper program
* Scott Wilson
* Paisley College of Technology
*/
#include <stdio.h>
#define HEADER "Terminal Bleeper"
#define REV "REV 4.2"
#define PROMPT1 "tty #: "
#define PROMPT2 "message: "
#define BLEEP 0007
main ()
{
char ttyid[2];
char devstr [20];
char message[90];
int i,x,y,r, s;
float res;
FILE *outfile;
printf ("%s %s \n \n", HEADER, REV);
r = 0;
while (r == 0 ) {
printf (PROMPT1);
r = getstr (ttyid);
}
r = 0;
while (r == 0) { /* Get new ttyid */
printf (PROMPT2);
r = getstr (message);
}
strcpy (devstr,"/dev/tty");
strcat (devstr,ttyid);
outfile = fopen (devstr,"w");
if (outfile == NULL) {
printf("Cannot open %s\n",devstr);
exit(-1);
}
printf("Bleeping %s\n",devstr);
fprintf (outfile,"%s\n",message);
for (;;) {
sleep (1);
fputc (BLEEP,outfile);
fflush (outfile);
}
}
/* Routine to input string, length returned in p */
getstr (s)
char s[];
{
int p,c;
for (p = 0; (c = getchar()) != '\n'; ++p)
s[p] = c;
s[p] = '\0';
return (p);
}
SHAR_EOF
chmod +x 'bleep.c'
fi # end of overwriting check
# End of shell archive
exit 0
JANET: swi at uk.ac.paisley.cs Scott Wilson
EMAIL: swi at cs.paisley.ac.uk | Post: Paisley College
UUCP: ...!seismo!mcvax!ukc!paisley!swi| Department of Mathematics,
Phone: +44 41 887 1241 Ext. 260 | High St. Paisley.
| Scotland.
| PA1 2BE
More information about the Comp.sources.unix
mailing list