Path: utzoo!attcan!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!elwell
From: elwell@tut.cis.ohio-state.edu (Clayton Elwell)
Newsgroups: comp.windows.news
Subject: Mailbox monitor for NeWS
Message-ID: <19691@tut.cis.ohio-state.edu>
Date: 10 Aug 88 19:35:45 GMT
Reply-To: elwell@tut.cis.ohio-state.edu.UUCP (Clayton Elwell)
Organization: The Ohio State University Dept of Computer and Information Science
Lines: 159


This little program, while less flashy than some that have come by in
this newsgroup, is quite useful.  You give it a pair of x and y
coordinates, and it puts up an icon showing whether or not you have
mail.  It could be made smarter, but it works.

-----------------------------CUT HERE---------------------------------
#! /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:
#	psbiff.c
#	psbiff.cps
# This archive created: Wed Aug 10 15:27:43 1988
export PATH; PATH=/bin:$PATH
if test -f 'psbiff.c'
then
	echo shar: will not over-write existing file "'psbiff.c'"
else
cat << \SHAR_EOF > 'psbiff.c'
#include 
#include 
#include 
#include 
#include 
#include "psbiff.h"

char mailbox[80];
struct passwd *pw;
struct stat st;

main(argc, argv)
int argc;
char **argv;
{
    long t;
    int x, y;

    if (argc < 3) {
	fprintf(stderr, "usage: psbiff x y");
	exit(1);
    }
    x = atoi(argv[1]);
    y = atoi(argv[2]);

    ps_open_PostScript();
    initialize(x, y);
    ps_flush_PostScript();
    pw = getpwuid(getuid());
    sprintf(mailbox, "/usr/spool/mail/%s", pw->pw_name);

    for (;;) {
	time(&t);
	sleep(10);
	if (stat(mailbox, &st)) {
	    nomail();
	} else if (t <= st.st_mtime) {
	    newmail();
	} else if (st.st_size > 0) oldmail();
	else nomail();
	ps_flush_PostScript();
    }
    ps_close_PostScript();
}
SHAR_EOF
fi # end of overwriting check
if test -f 'psbiff.cps'
then
	echo shar: will not over-write existing file "'psbiff.cps'"
else
cat << \SHAR_EOF > 'psbiff.cps'
%!
cdef initialize(x,y)
    newprocessgroup
    /icon framebuffer newcanvas def
    /xcurs /xcurs_m icon setstandardcursor
    gsave framebuffer setcanvas 0 0 64 64 rectpath icon reshapecanvas grestore
    icon /Retained true put
    icon setcanvas
    x y movecanvas
    /destroy { icon /Mapped false put currentprocess killprocessgroup } def
    /slide { gsave icon setcanvas InteractionLock { interactivemove } monitor
    grestore
    } def
    [
	/DoItEvent { gsave /ClientData get cvx exec grestore }
	/Window null eventmgrinterest

	AdjustButton { slide }
	DownTransition icon eventmgrinterest
    ] forkeventmgr
    /mailimage 64 64 1 [64 0 0 -64 0 64] {
    
    } buildimage def
    /nomailimage 64 64 1 [64 0 0 -64 0 64] {
    
    } buildimage def
    gsave textcolor setcolor 64 64 scale false nomailimage imagemaskcanvas
    backgroundcolor setcolor true nomailimage imagemaskcanvas grestore
    icon /Mapped true put
    


cdef oldmail()
    icon setcanvas
    gsave textcolor setcolor 64 64 scale false mailimage imagemaskcanvas
    backgroundcolor setcolor true mailimage imagemaskcanvas grestore

cdef nomail()
    icon setcanvas
    gsave textcolor setcolor 64 64 scale false nomailimage imagemaskcanvas
    backgroundcolor setcolor true nomailimage imagemaskcanvas grestore

cdef newmail()
    icon setcanvas
    gsave backgroundcolor setgray 64 64 scale false mailimage imagemaskcanvas
    textcolor setgray true mailimage imagemaskcanvas grestore
SHAR_EOF
fi # end of overwriting check
#	End of shell archive
exit 0


Clayton M. Elwell 
Ohio State University CIS Dept. Research Computing Facility

"... there was a *third* possibility that we hadn't even counted
upon ..."		--Arlo Guthrie, "Alice's Restaurant"