Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!ulysses!cjc From: cjc@ulysses.homer.nj.att.com (Chris Calabrese) Newsgroups: comp.windows.news Subject: Re: Has anyone figured out how to ring the bell? Summary: a better bell ringer without forkunix Keywords: bell ^G Message-ID: <12305@ulysses.homer.nj.att.com> Date: 20 Oct 89 19:29:10 GMT References: <18083@ppgbms.UUCP> Distribution: na Organization: AT&T Bell Laboratories, Murray Hill Lines: 162 In article <18083@ppgbms.UUCP>, paul@ppgbms (Paul Evan Matz) writes: > I'm sorry if this has been covered before, but I can't seem to remember > if there's a way to ring the audible bell from the NeWS server side. I > suppose one could forkunix an executable to do it. Is there a better way? Yes, it can be done!!! I wrote this code to get the new psterm from the grasshopper group to ring the bell (VisibleBell() is a function in the npsterm code): P.S. no flames about using goto! If you can't figure what's going on in the function it's in (which is the only function in the source file), get your brain checked... /* * @(#)ringbell.c 1.1 10/20/89 * bell ringing routines on a Sun workstation * for the npsterm terminal emulator running NeWS * * Christopher Calabrese * AT&T Bell Laboratories * Murray Hill, NJ * cjc@ulysses.att.com */ #ifdef sun # include # include # include #endif #include "tcap.h" #ifndef lint static char *sccsid="@(#)ringbell.c 1.1 10/20/89 cjc@ulysses.att.com"; #endif RingBell() { # ifdef sun static int kbdfd = -1; /* File descriptor for the keyboard. * -1 means the file's never been * opened and/or we're not running * with the NeWS machine as the * local machine */ if(kbdfd == -1 && newsislocal()) { kbdfd = open("/dev/kbd", 0); } /* * we need this second test if the open failed * or we're not local */ if(kbdfd != -1) { int x; x = KBD_CMD_BELL; ioctl(kbdfd, KIOCCMD, &x); usleep(250000); x = KBD_CMD_NOBELL; ioctl(kbdfd, KIOCCMD, &x); } # endif VisibleBell(); } /* * @(#)newsislocal.c 1.1 10/20/89 * checks if the NEWSSERVER variable is the same as the * local host * * Christopher Calabrese * AT&T Bell Laboratories * Murray Hill, NJ * cjc@ulysses.att.com */ #ifndef lint static char *sccsid="@(#)newsislocal.c 1.1 10/20/89 cjc@ulysses.att.com"; #endif #include #include #include #ifndef MAXHOSTNAMELEN # define MAXHOSTNAMELEN 64 #endif newsislocal() { /* * code is our return code, -1 means we don't know */ static int code = -1; char *ptr; long atol(); unsigned long ntohl(); char buffer[256]; char myhostname[MAXHOSTNAMELEN + 1]; char *strchr(), *getenv(), strncpy(); char *gethostname(); struct hostent *gethostbyname(); struct hostent *hp; if(code != -1) goto end_of_function; if(!(ptr=getenv("NEWSSERVER"))) { /* oops, it's undefined, assume non-local */ code = 0; goto end_of_function; } (void) strncpy(buffer, ptr, 256); buffer[255]='\0'; /* * Buffer now contains the NEWSSERVER environment variable. * The format is host_id.port:host_name. * To do what we want, we must find the '.' and * extract the host_id */ if(!(ptr = strchr(buffer, '.'))) { /* oops, it's the wrong format, assume non-local */ code = 0; goto end_of_function; } *ptr = '\0'; /* * O.k., we know the id of the news host, now let's get * our own id and compare them. * We'll use gethostname() to find the name of the current * machine and then do a gethostbyname() to get it's net * addresses. If we want to do this right in BSD 4.3 or * SunOS 4.0 we should check against all the entries for the * current host, but since setnewshost(1) only looks at the primary * host id and since BSD 4.2 and SunOS 3.0 only know about * the primary id, we'll only use that. */ if(gethostname(myhostname, MAXHOSTNAMELEN)) { /* oops, a serious error getting the host name */ (void) perror("gethostname"); code = 0; goto end_of_function; } myhostname[MAXHOSTNAMELEN] = '\0'; if(!(hp = gethostbyname(myhostname))) { (void) perror(myhostname); code = 0; goto end_of_function; } if((unsigned) atol(buffer) == ntohl(*(u_long *)hp->h_addr)) { code = 1; } else code = 0; end_of_function: return code; } -- Name: Christopher J. Calabrese Brain loaned to: AT&T Bell Laboratories, Murray Hill, NJ att!ulysses!cjc cjc@ulysses.att.com Obligatory Quote: ``Anyone who would tell you that would also try and sell you the Brooklyn Bridge.''