#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1995-07-19 13:23 JST by <h-takasi@ssa>.
# Source directory was `/export/home.ssa/h-takasi/work/gnyaclock'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#   1471 -r--r--r-- gnyaclock/Clock.h
#  18694 -r--r--r-- gnyaclock/Clock.c
#   5021 -r--r--r-- gnyaclock/gnyaclock.man
#   1250 -r--r--r-- gnyaclock/XDrBezier.c
#   1035 -r--r--r-- gnyaclock/Imakefile
#   7736 -r--r--r-- gnyaclock/gnyaclock.c
#    807 -r--r--r-- gnyaclock/handdata.h
#   1289 -r--r--r-- gnyaclock/ClockP.h
#
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  echo 'WARNING: not restoring timestamps.  Consider getting and'
  echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
# ============= gnyaclock/Clock.h ==============
if test ! -d 'gnyaclock'; then
  echo 'x - creating directory gnyaclock'
  mkdir 'gnyaclock'
fi
if test -f 'gnyaclock/Clock.h' && test X"$1" != X"-c"; then
  echo 'x - skipping gnyaclock/Clock.h (file already exists)'
else
  echo 'x - extracting gnyaclock/Clock.h (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'gnyaclock/Clock.h' &&
/*
X * Title: Clock.h  --  a gnyaclock widget public header
X * Creator: HAYAKAWA Takashi <h-takasi@is.titech.ac.jp>
X * CreationDate: 94/06/08
X * EndComments
X *
X * $Id: Clock.h,v 1.3 1995/01/06 07:22:25 h-takasi Exp $
X */
X
#ifndef _XtClock_h
#define _XtClock_h
X
/* Parameters:
X
X Name		Class		RepType		Default Value
X ----		-----		-------		-------------
X background	Background	Pixel		XtDefaultBackground
X bitmap		Bitmap		Bitmap		None
X box		Boolean		Boolean		off
X clocktype	Clocktype	Int		0
X cursor		Cursor		Cursor		circle
X digital	Boolean		Boolean		off
X dots		Foreground	Pixel		XtDefaultForeground
X fill		Boolean		Boolean		off
X font		Font		XFontStruct*	XtDefaultFont
X foreground	Foreground	Pixel		XtDefaultForeground
X hand		Foreground	Pixel		XtDefaultForeground
X handWidth	Thickness	Int		100
X height		Height		Int		300
X hour		Length		Int		64
X label		Label		String		NULL
X minute		Length		Int		84
X update		Interval	Int		10
X useBitmapSize	Boolean		Boolean		off
X width		Width		Int		300
X
*/
X
#define	XtNbox "box"
#define	XtNclocktype "clocktype"
#define	XtNcursor "cursor"
#define	XtNdigital "digital"
#define	XtNdots "dots"
#define	XtNfill "fill"
#define	XtNhand "hand"
#define	XtNhandWidth "handWidth"
#define	XtNhour "hour"
#define	XtNminute "minute"
#define	XtNuseBitmapSize "useBitmapSize"
X
#define	XtCClocktype "Clocktype"
X
typedef struct _ClockRec	*ClockWidget;
typedef struct _ClockClassRec	*ClockWidgetClass;
X
extern WidgetClass		clockWidgetClass;
X
#endif	/*_XtClock_h */
SHAR_EOF
  $shar_touch -am 0106162295 'gnyaclock/Clock.h' &&
  chmod 0444 'gnyaclock/Clock.h' ||
  echo 'restore of gnyaclock/Clock.h failed'
  shar_count="`wc -c < 'gnyaclock/Clock.h'`"
  test 1471 -eq "$shar_count" ||
    echo "gnyaclock/Clock.h: original size 1471, current size $shar_count"
fi
# ============= gnyaclock/Clock.c ==============
if test -f 'gnyaclock/Clock.c' && test X"$1" != X"-c"; then
  echo 'x - skipping gnyaclock/Clock.c (file already exists)'
else
  echo 'x - extracting gnyaclock/Clock.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'gnyaclock/Clock.c' &&
/*
X * $Title: Clock.c  --  a gnyaclock widget $
X * $Creator: HAYAKAWA Takashi <h-takasi@is.titech.ac.jp> $
X * $Id: Clock.c,v 1.2 1995/01/06 07:20:53 h-takasi Exp $
X */
X
#ifndef lint
static char *rcsid =
X    "$Id: Clock.c,v 1.2 1995/01/06 07:20:53 h-takasi Exp $";
#endif
X
#include <math.h>
#include <sys/time.h>
#include <X11/IntrinsicP.h> 
#include <X11/StringDefs.h>
#include <X11/Xmu/Converters.h>			/* for XmuCvtStringToBitmap */
#include "ClockP.h"
#include "handdata.h"
X
#define	DELAY		4000			/* recover from chase */
#define	HALF_DAY	43200			/* 12x60x60(sec) */
X
#define	sind(ang)	sin((double) (ang)*M_PI/1800.0)
#define	cosd(ang)	cos((double) (ang)*M_PI/1800.0)
#define	FLDCMP(s, t, f)	(s->f != t->f)
#define	STRCOMP(s, t)	strcmp((s) ? (s) : "", (t) ? (t) : "")
X
X    
static void
X    ClassInitialize(), Initialize(), Realize(), Resize(),
X    Redisplay(), Destroy(), freeGC(), getGC(), set_linewidth(),
X    get_pix_geom(), make_clock(), draw_hand(), calc_hand(),
X    show_time(), set_timer(), reset_timer(), timerProc(), motion(),
X    toggle_digital(), toggle_chase(), vn_evhandler();
X
static Boolean
X    SetValues();
X
static char
X    *time_str();
X
static int
X    current_time();
X
/*
X * Event Translation
X */
static char defaultTranslations[] = "\
X	<Key>d:		toggle-digital()\n\
X	<Btn1Down>:	toggle-chase()\n\
X	<MotionNotify>:	motion()";
X
/*
X * Action Functions
X */
static XtActionsRec actionList[] = {
X    {"toggle-digital",	toggle_digital},
X    {"toggle-chase",	toggle_chase},
X    {"motion",		motion},
};
X
/*
X * Widget Resources
X */
static XtResource resources[] = {
X    { XtNwidth, XtCWidth, XtRDimension, sizeof(Dimension),
X	XtOffset(Widget, core.width), XtRString, "300"},
X    { XtNheight, XtCHeight, XtRDimension, sizeof(Dimension),
X	XtOffset(Widget, core.height), XtRString, "300"},
X
X    { XtNbitmap, XtCBitmap, XtRBitmap, sizeof(Pixmap),
X	XtOffset(ClockWidget, gnya.bitmap), XtRString, "None"},
X
X    { XtNhandWidth, XtCThickness, XtRInt, sizeof(int),
X	XtOffset(ClockWidget, gnya.handwidth), XtRString, "100"},
X    { XtNminute, XtCLength, XtRInt, sizeof(int),
X	XtOffset(ClockWidget, gnya.hand_l), XtRString, "84"},
X    { XtNhour, XtCLength, XtRInt, sizeof(int),
X	XtOffset(ClockWidget, gnya.hand_s), XtRString, "64"},
X
X    { XtNdigital, XtCBoolean, XtRBoolean, sizeof(Boolean),
X	XtOffset(ClockWidget, gnya.digital), XtRString, XtEoff},
X    { XtNbox, XtCBoolean, XtRBoolean, sizeof(Boolean),
X	XtOffset(ClockWidget, gnya.box), XtRString, XtEoff},
X    { XtNfill, XtCBoolean, XtRBoolean, sizeof(Boolean),
X	XtOffset(ClockWidget, gnya.fill), XtRString, XtEoff},
X    { XtNuseBitmapSize, XtCBoolean, XtRBoolean, sizeof(Boolean),
X	XtOffset(ClockWidget, gnya.bmsize), XtRString, XtEoff},
X
X    { XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel),
X	XtOffset(ClockWidget, core.background_pixel),
X	XtRString, XtExtdefaultbackground},
X    { XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
X	XtOffset(ClockWidget, gnya.fore), XtRString, XtExtdefaultforeground},
X    { XtNdots, XtCForeground, XtRPixel, sizeof(Pixel),
X	XtOffset(ClockWidget, gnya.dots), XtRString, XtExtdefaultforeground},
X    { XtNhand, XtCForeground, XtRPixel, sizeof(Pixel),
X	XtOffset(ClockWidget, gnya.hand), XtRString, XtExtdefaultforeground},
X
X    { XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
X	XtOffset(ClockWidget, gnya.font), XtRString, XtExtdefaultfont},
X    { XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor),
X	XtOffset(ClockWidget, gnya.cursor), XtRString, "circle"},
X    { XtNlabel, XtCLabel, XtRString, sizeof(String),
X	XtOffset(ClockWidget, gnya.label), XtRString, NULL},
X    { XtNclocktype, XtCClocktype, XtRInt, sizeof(int),
X	XtOffset(ClockWidget, gnya.clocktype), XtRString, "0"},
X    { XtNupdate, XtCInterval, XtRInt, sizeof(int),
X	XtOffset(ClockWidget, gnya.update), XtRString, "10"},
};
X
/*
X * Class Record
X */
ClockClassRec clockClassRec = {
X    { /* core fields */
X    /* superclass		*/	&widgetClassRec,
X    /* class name		*/	"Clock",
X    /* widget size		*/	sizeof(ClockRec),
X    /* class_initialize		*/	ClassInitialize,
X    /* class_part_initialize	*/	NULL,
X    /* class_inited		*/	FALSE,
X    /* initialize		*/	Initialize,
X    /* initialize_hook		*/	NULL,
X    /* realize			*/	Realize,
X    /* actions			*/	actionList,
X    /* num_actions		*/	XtNumber(actionList),
X    /* resources		*/	resources,
X    /* resource_count		*/	XtNumber(resources),
X    /* xrm_class		*/	NULLQUARK,
X    /* compress_motion		*/	TRUE,
X    /* compress_exposure	*/	TRUE,
X    /* compress_enterleave	*/	TRUE,
X    /* visible_interest		*/	TRUE,
X    /* destroy			*/	Destroy,
X    /* resize			*/	Resize,
X    /* expose			*/	Redisplay,
X    /* set_values		*/	SetValues,
X    /* set_values_hook		*/	NULL,
X    /* set_value_almost		*/	XtInheritSetValuesAlmost,
X    /* get_values_hook		*/	NULL,
X    /* accept focus		*/	NULL,
X    /* version			*/	XtVersion,
X    /* callback_private		*/	NULL,
X    /* tm_table			*/	defaultTranslations,
X    /* query_geometry		*/	XtInheritQueryGeometry,
X    }
};
WidgetClass  clockWidgetClass = (WidgetClass) &clockClassRec;
X
/*
X * ClassInitialize:
X *	append type converter String->Bitmap.
X */
static void ClassInitialize()
{
X    static XtConvertArgRec xcarg[] = {
X	{ XtWidgetBaseOffset, (caddr_t)XtOffset(Widget, core.screen),
X	  sizeof(Screen*) }
X    };
X    XtAddConverter(XtRString, XtRBitmap, XmuCvtStringToBitmap,
X		   xcarg, XtNumber(xcarg));
}
X
/*
X * Initialize:
X *	initialize the widget.
X */
/*ARGSUSED*/
static void Initialize(request, new)
Widget request, new;
{
X    ClockWidget	cw = (ClockWidget) new;
X
X    XtAddEventHandler(new,			/* widget */
X		      VisibilityChangeMask,	/* event mask */
X		      FALSE,			/* non-maskable */
X		      vn_evhandler,		/* handler */
X		      NULL);			/* client data */
X
X    cw->gnya.chase = FALSE;
X    cw->gnya.visible = TRUE;
X    cw->gnya.pix = (Pixmap) 0;
X    cw->gnya.interval_id = (XtIntervalId) 0;
X
X    getGC(new);
X
X    if(cw->gnya.bmsize &&			/* if useBitmapSize is on, */
X       cw->gnya.bitmap != None)			/*   and bitmap is set,*/
X    {
X	unsigned int wid, hgt;
X
X	get_pix_geom(cw, &wid, &hgt, NULL);	/* set clock size */
X	cw->core.width  = wid;			/*   into that of bitmap */
X	cw->core.height = hgt;
X    }
}
X
/*
X * Realize:
X *	realize the widget.
X */
static void Realize(w, valueMask, attrs)
Widget w;
XXtValueMask *valueMask;
XXSetWindowAttributes *attrs;
{
X    *valueMask |= CWBitGravity | CWCursor;
X    attrs->bit_gravity = ForgetGravity;
X    attrs->cursor = ((ClockWidget)w)->gnya.cursor;
X
X    XtCreateWindow(w, InputOutput, (Visual*) CopyFromParent,
X		   *valueMask, attrs);
X    Resize(w);
}
X
/*
X * Destroy:
X *	destroy the widget.
X */
static void Destroy(w)
Widget w;
{
X    ClockWidget	cw = (ClockWidget) w;
X
X    reset_timer(cw);
X    XFreePixmap(XtDisplay(w), cw->gnya.pix);
X    freeGC(w);
}
X
/*
X * Resize:
X *	create the GC and Pixmap for resized widget.
X */
static void Resize(w)
Widget w;
{
X    if(XtIsRealized(w)) {
X	ClockWidget cw = (ClockWidget) w;
X	Display *dpy = XtDisplay(w);
X	Window win  = XtWindow(w);
X
X	if(cw->gnya.pix)				/* throw the old */
X	    XFreePixmap(dpy, cw->gnya.pix);		/*   buffer away */
X
X	cw->gnya.pix =					/* create new one */
X	    XCreatePixmap(dpy, win,
X			  cw->core.width, cw->core.height, cw->core.depth);
X
X	make_clock(cw);
X    }
}
X
/*
X * Redisplay:
X *	redisplay the widget.
X */
static void Redisplay(w)
Widget w;
{
X    if(XtIsRealized(w)) {
X	ClockWidget cw = (ClockWidget) w;
X	set_linewidth(cw);
X	timerProc((XtPointer) w, NULL);
X    }
}
X
/*
X * SetValues:
X *	check if values were changed,
X *	and redraw if needed.
X */
/*ARGSUSED*/
static Boolean SetValues(current, request, new)
Widget current, request, new;
{
X    ClockWidget cw0 = (ClockWidget) current;
X    ClockWidget cw1 = (ClockWidget) new;
X    Boolean reconf = FALSE;
X    Boolean redraw = FALSE;
X
X    if(FLDCMP(cw0, cw1, gnya.clocktype) ||
X       FLDCMP(cw0, cw1, gnya.font)) reconf = TRUE;
X
X    if(FLDCMP(cw0, cw1, gnya.box) ||
X       FLDCMP(cw0, cw1, gnya.fill) ||
X       FLDCMP(cw0, cw1, gnya.digital)) redraw = TRUE;
X
X    if(FLDCMP(cw0, cw1, core.background_pixel) ||
X       FLDCMP(cw0, cw1, gnya.fore) ||
X       FLDCMP(cw0, cw1, gnya.dots) ||
X       FLDCMP(cw0, cw1, gnya.hand) ||
X       FLDCMP(cw0, cw1, gnya.font) ||
X       FLDCMP(cw0, cw1, gnya.bitmap) ||
X       FLDCMP(cw0, cw1, gnya.handwidth))
X    {
X	getGC(new); freeGC(current);
X	redraw = TRUE;
X    }
X
X    if(STRCOMP(cw0->gnya.label, cw1->gnya.label)) {
X	redraw = TRUE;
X    }
X
X    if(reconf) make_clock(new);
X    if(reconf || redraw) Redisplay(new);
X    return FALSE;
}
X
/*
X * getGC:
X *	get GCs
X */
static void getGC(w)
Widget w;
{
X    ClockWidget cw = (ClockWidget) w;
X    XGCValues xgcv;
X    XtGCMask mask;
X
X    /*
X     * foreground GC
X     */
X    mask = GCForeground | GCFont;
X    xgcv.foreground = cw->gnya.fore;
X    xgcv.font	    = cw->gnya.font->fid;
X    cw->gnya.gc_fore = XtGetGC(w, mask, &xgcv);
X
X    /*
X     * dots GC
X     */
X    mask = GCForeground;
X    xgcv.foreground = cw->gnya.dots;
X    cw->gnya.gc_dots = XtGetGC(w, mask, &xgcv);
X
X    /*
X     * hand GC  --  GC created here is dummy.  The real one
X     *		is created at set_linewidth().
X     */
X    mask = GCForeground;
X    cw->gnya.gc_hand = XtGetGC(w, mask, &xgcv);
X
X    /*
X     * background GC
X     */
X    mask = GCForeground;
X    xgcv.foreground = cw->core.background_pixel;
X    cw->gnya.gc_back = XtGetGC(w, mask, &xgcv);
X
X    /*
X     * tile GC:
X     *	 - if no bitmap is specified, it's same as background.
X     *   - if a bitmap is specified, check it is a BITMAP or PIXMAP.
X     */
X    if(cw->gnya.bitmap == None) {		/* NO TILE */
X	/* same as background GC */
X    } else {					/* A TILE */
X	unsigned int depth;				/* check */
X	get_pix_geom(cw, NULL, NULL, &depth);		/*  BITMAP or PIXMAP */
X
X	if(depth == 1) {				/* when BITMAP */
X	    mask = GCForeground | GCBackground | GCFillStyle | GCStipple;
X	    xgcv.foreground = cw->gnya.fore;
X	    xgcv.background = cw->core.background_pixel;
X	    xgcv.fill_style = FillOpaqueStippled;
X	    xgcv.stipple    = cw->gnya.bitmap;
X	} else {					/* when PIXMAP */
X	    mask = GCFillStyle | GCTile;
X	    xgcv.fill_style = FillTiled;
X	    xgcv.tile = cw->gnya.bitmap;
X	}
X    }
X    cw->gnya.gc_tile = XtGetGC(w, mask, &xgcv);
}
X
/*
X * freeGC:
X *	release GCs.
X */
static void freeGC(w)
Widget w;
{
X    ClockWidget cw = (ClockWidget) w;
X
X    XtReleaseGC(w, cw->gnya.gc_back);
X    XtReleaseGC(w, cw->gnya.gc_dots);
X    XtReleaseGC(w, cw->gnya.gc_fore);
X    XtReleaseGC(w, cw->gnya.gc_hand);
X    XtReleaseGC(w, cw->gnya.gc_tile);
}
X
/*
X * set_linewidth:
X *	set the width of hand.
X */
static void set_linewidth(w)
ClockWidget	w;
{
X    XGCValues xgcv;
X    XtGCMask mask;
X    GC gc_old = w->gnya.gc_hand;
X    int lw = (w->core.width + w->core.height)/80 + 2;
X
X    /* problem with unsigned-int resource.  */
X    if(w->gnya.handwidth < 0) w->gnya.handwidth = 0;
X
X    lw *= w->gnya.handwidth; lw /= 100;
X
X    mask = GCForeground | GCCapStyle | GCJoinStyle | GCLineWidth;
X    xgcv.foreground = w->gnya.hand;
X    xgcv.line_width = lw;
X    xgcv.cap_style  = CapRound;
X    xgcv.join_style = JoinRound;
X    w->gnya.gc_hand = XtGetGC((Widget) w, mask, &xgcv);
X
X    XtReleaseGC((Widget) w, gc_old);
}
X
static void get_pix_geom(cw, rwid, rhgt, rdep)
ClockWidget cw;
unsigned int *rwid, *rhgt, *rdep;
{
X    Pixmap pix = cw->gnya.bitmap;
X    Window root;
X    int x, y;
X    unsigned int wid, hgt, bw, depth;
X
X    if(pix != None)
X	XGetGeometry(XtDisplay((Widget)cw), cw->gnya.bitmap,
X		     &root, &x, &y, &wid, &hgt, &bw, &depth);
X
X    if(rwid) *rwid = wid;
X    if(rhgt) *rhgt = hgt;
X    if(rdep) *rdep = depth;
}
X
/*
X * make_clock:
X *	make the face of the clock.
X */
static void make_clock(cw)
ClockWidget cw;
{
X    int wid = cw->core.width;
X    int hgt = cw->core.height;
X    XRectangle *rect = &cw->gnya.rect;
X    XFontStruct *fs = cw->gnya.font;
X    XArc *arcs = cw->gnya.arcs;
X    int h;
X
X    /*
X     * box for digital/message area
X     */
X    rect->width  = XTextWidth(fs, "00:00", 5) + 7;
X    rect->height = fs->ascent + fs->descent + 2;
X    rect->x = (wid - rect->width)/2;
X    rect->y = hgt*3/4 - rect->height + fs->descent*2/3 + 2;
X
X    /*
X     * dots around the clock
X     */
X    cw->gnya.narcs = 0;
X    for(h=0; h<12; h++) {
X	int cx =  sind(h*300)*wid*0.46 + wid/2;
X	int cy = -cosd(h*300)*hgt*0.46 + hgt/2;
X	double dx = wid*0.02;
X	double dy = hgt*0.02;
X	Boolean dr = TRUE;
X
X	switch(cw->gnya.clocktype) {
X	case 0: dr = FALSE;			break;	/* nothing */
X	case 1: dx *= 0.7; dy *= 0.7;			/* 4 smalls */
X	case 2: dr = (h%3 == 0);		break;	/* 4 larges */
X	case 3: dx *= 0.7; dy *= 0.7;		break;	/* 12 smalls */
X	case 4: 				break;	/* 12 larges */
X	case 5: if(h%3) {dx *= 0.7; dy *= 0.7;}	break;	/* 4L + 8s */
X	case 6: if(h) {dx *= 0.7; dy *= 0.7;}	break;	/* 1L + 11s */
X	case 7: dr = !h;			break;	/* only the top */
X	}
X	if(dr) {
X	    arcs->x = cx - (int) dx;
X	    arcs->y = cy - (int) dy;
X	    arcs->width  = dx*2 + 1;
X	    arcs->height = dy*2 + 1;
X	    arcs->angle1 = 0;
X	    arcs->angle2 = 360*64;
X	    arcs++; cw->gnya.narcs++;
X	}
X    }
}
X
X
/*
X * draw_hand:
X *	draw the hand curve.
X */
static void draw_hand(cw, sec, mess)
ClockWidget cw;
int sec;
char *mess;
{
X    void XDrawBezierCurve();
X    Display *dpy = XtDisplay((Widget) cw);
X    Window win = XtWindow((Widget) cw);			/* frame buffer */
X    Pixmap pix = cw->gnya.pix;				/* working buffer */
X    int wid = cw->core.width;
X    int hgt = cw->core.height;
X    XPoint co[4];
X
X    /*
X     * make the clock board
X     */
X    XFillRectangle(dpy, pix, cw->gnya.gc_tile,		/* background tile */
X		   0, 0, wid, hgt);
X    if(cw->gnya.digital) {				/* digital display */
X	if(cw->gnya.fill)				/*   area */
X	    XFillRectangles(dpy, pix, cw->gnya.gc_back,
X			    &cw->gnya.rect, 1);
X	if(cw->gnya.box)
X	    XDrawRectangles(dpy, pix, cw->gnya.gc_fore,
X			    &cw->gnya.rect, 1);
X    }
X    XFillArcs(dpy, pix, cw->gnya.gc_dots,		/* dots */
X	      cw->gnya.arcs, cw->gnya.narcs);
X
X    /*
X     * digital display -- message area
X     */
X    if(cw->gnya.digital && !(mess && *mess))		/* if no message, */
X	mess = time_str(sec);				/*   show time */
X    if(mess) {
X	XFontStruct *fs = cw->gnya.font;		/* centering */
X	int mlen = strlen(mess);			/*   the message */
X	int mwid = XTextWidth(fs, mess, mlen);
X	int mx = (wid - 2 - mwid) / 2;
X	int my = hgt*3 / 4;
X
X	XDrawString(dpy, pix, cw->gnya.gc_fore, mx, my, mess, mlen);
X    }
X
X    /*
X     * draw hand by Bezier-curve
X     */
X    calc_hand(cw, co, sec);				/* control pts */
X    XDrawBezierCurve(dpy, pix, cw->gnya.gc_hand, co, 4); /* draw it */
X
X    XCopyArea(dpy, pix, win, cw->gnya.gc_fore,		/* copy to */
X	      0, 0, wid, hgt,  0, 0);			/*   frame buffer */
}
X
X
/*
X * calc_hand:
X *	calculate control points for hand curve.
X */
static void calc_hand(w, xp, tm)
ClockWidget w;
XXPoint *xp;
int tm;
{
X    int wid = w->core.width / 2;
X    int hgt = w->core.height / 2;
X    double hl = w->gnya.hand_l / 100.0;
X    double hs = w->gnya.hand_s / 100.0;
X
X    int i;
X    double ip[4];
X
X    int ang1 = tm / 12;		/* hour's angle */
X    int ang2 = tm % 3600;	/* minute's angle */
X    int d1, d2, d3;
X
X    d2 = (ang1-ang2 + 3600) % 3600;
X    d1 = d2 / 300;
X    d2 %= 300;
X    d3 = 300 - d2;
X    for(i=0; i<4; i++)
X	ip[i] = (cv_data[d1][i]*d3 + cv_data[d1+1][i]*d2) / 300;
X
X    xp[0].x = wid * (1 + sind(ang1)*hs);
X    xp[0].y = hgt * (1 - cosd(ang1)*hs);
X
X    xp[1].x = wid * (1 + sind(ang1-ip[0])*hs*ip[1]);
X    xp[1].y = hgt * (1 - cosd(ang1-ip[0])*hs*ip[1]);
X
X    xp[2].x = wid * (1 + sind(ang2-ip[2])*hl*ip[3]);
X    xp[2].y = hgt * (1 - cosd(ang2-ip[2])*hl*ip[3]);
X
X    xp[3].x = wid * (1 + sind(ang2)*hl);
X    xp[3].y = hgt * (1 - cosd(ang2)*hl);
}
X
X
/*
X * current_time:
X *	get the current time.  interested in
X *	local time of day.
X */
static int current_time()
{
X    long time();
X    long cl = time(0);
X    struct tm *lt = localtime(&cl);
X
X    return 3600*lt->tm_hour + 60*lt->tm_min + lt->tm_sec;
}
X
/*
X * time_str:
X *	convert time into time-string(hh:mm).
X *
X * NOTE: the string returned by this function
X *	is stored statically in it.
X */
static char *time_str(cl)
int cl;
{
X    static char cp[6];
X    int mm = cl/60;
X    int hh = mm/60;
X
X    mm %= 60;						/* minute: 0..59 */
X    hh = (hh+11) % 12 + 1;				/* hour:   1..12 */
X    sprintf(cp, "%d:%02d", hh, mm);
X    return cp;
}
X
/*
X * show_time:
X *	if the widget is visible, draw the clock
X */
static void show_time(w)
ClockWidget w;
{
X    if(w->core.visible)					/* if visible, */
X	draw_hand(w, current_time(), w->gnya.label);	/*   draw the hand */
}
X
/*
X * timerProc:
X *	This function is called when the timer has gone.
X *	Show the current time  and set the alarm.
X */
/*ARGSUSED*/
static void timerProc(client_data, timer_id)
XXtPointer client_data;
XXtIntervalId *timer_id;		/* unused */
{
X    ClockWidget cw = (ClockWidget) client_data;
X
X    if(cw->core.visible) {			/* if visible, */
X	show_time(cw);					/* update it */
X	set_timer(cw, 1000 * cw->gnya.update);		/* set timer */
X    } else {					/* if invisible */
X	cw->gnya.visible = FALSE;			/* sleep */
X    }							/* (no timer) */
}
X
/*
X * set_timer:
X *	set the interval timer.
X */
static void set_timer(w, delay)
ClockWidget w;
int delay;
{
X    reset_timer(w);
X    w->gnya.interval_id =
X	XtAppAddTimeOut(XtWidgetToApplicationContext((Widget) w),
X			delay, timerProc, (XtPointer) w);
}
X
/*
X * reset_timer:
X *	reset the timer.
X */
static void reset_timer(w)
ClockWidget w;
{
X    if(w->gnya.interval_id)
X	XtRemoveTimeOut(w->gnya.interval_id);
X    w->gnya.interval_id = 0;
}
X
X
/*
X * Event Action Functions:
X *	toggle-digital
X *	toggle-chase
X *	motion
X */
static void toggle_digital(w)
Widget w;
{
X    ClockWidget cw = (ClockWidget) w;
X    XtVaSetValues(w, XtNdigital, !cw->gnya.digital, NULL);
}
X
static void toggle_chase(w)
Widget w;
{
X    ClockWidget cw = (ClockWidget) w;
X    cw->gnya.chase = !cw->gnya.chase;
X    timerProc((XtPointer) w, NULL);
}
X
static void motion(w, xev)
ClockWidget w;
XXMotionEvent *xev;
{
X    if(w->gnya.chase) {				/* when chase mode, */
X	int x = xev->x - w->core.width/2;
X	int y = xev->y - w->core.height/2;
X	int ang;
X
X	if(x==0 && y==0) y = -1;
X	ang = atan2((double) x, (double) -y) * HALF_DAY/2/M_PI;
X	ang += HALF_DAY; ang %= HALF_DAY;
X
X	draw_hand(w, ang, NULL);
X	set_timer(w, DELAY);
X    }
}
X
/*
X * vn_evhandler:
X *	VisibilityNotify event handler.
X */
/*ARGSUSED*/
static void vn_evhandler(cw, client_data, xev, cont)
ClockWidget cw;
XXtPointer client_data;	/* unused */
XXEvent *xev;
Boolean *cont;		/* unused */
{
X    switch(xev->xvisibility.state) {	/* VISIBLITY turned to  */
X    case VisibilityFullyObscured:		/* INVISIBLE: */
X	cw->gnya.visible = FALSE;			/* do nothing */
X
X    default:					/* VISIBLE: */
X	if(!cw->gnya.visible) {				/* if it was fully */
X	    timerProc((XtPointer) cw, NULL);		/* invisible, update */
X	}						/* the clock now */
X	cw->gnya.visible = TRUE;
X	break;
X    }
}
SHAR_EOF
  $shar_touch -am 0106162095 'gnyaclock/Clock.c' &&
  chmod 0444 'gnyaclock/Clock.c' ||
  echo 'restore of gnyaclock/Clock.c failed'
  shar_count="`wc -c < 'gnyaclock/Clock.c'`"
  test 18694 -eq "$shar_count" ||
    echo "gnyaclock/Clock.c: original size 18694, current size $shar_count"
fi
# ============= gnyaclock/gnyaclock.man ==============
if test -f 'gnyaclock/gnyaclock.man' && test X"$1" != X"-c"; then
  echo 'x - skipping gnyaclock/gnyaclock.man (file already exists)'
else
  echo 'x - extracting gnyaclock/gnyaclock.man (binary)'
  sed 's/^X//' << 'SHAR_EOF' | uudecode &&
begin 600 gnyaclock/gnyaclock.man
M+EPB("14:71L93H@9VYY86-L;V-K+C$@("TM("!G;GEA8VQO8VL@;6%N=6%L
M("0*+EPB("1#<F5A=&]R.B!(05E!2T%702!486MA<VAI(#QH+71A:V%S:4!I
M<RYT:71E8V@N86,N:G`^("0*+EPB("1)9#H@9VYY86-L;V-K+FUA;BQV(#$N
M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YJ&\I;:D
MSJ7;H;REX*7'I:.E[*6OI<BEZ@H*+E-((*70I;`*I<>EN*6_I>O)O;RHI/*D
MMZ3&I*2DRJ2DI,BAHKO^N>^DK*3HI*_*K*2KI.JDWJ2[I/.AHPH*6'2DSE!I
M>&UA<,W1I,ZEZJ6]H;REN:6SI?.ET*&\I;^D\KKNI.JAH@I0:7AM87"EZJ6]
MH;REN:3RI::EHZ6XI:>EPZ7(I,ZEZJ6]H;REN:3(I+>DQKSUI+')U:2QI.ND
MV:2MI,>DN:&C"D)I=&UA<,W1I,ZELZ7SI="AO*6_I,^EK:7CI<.EMZ7EI,JD
MR:3.I+^DX:3+M^NYO<JCNZBDQZ&B"J2]I.RDR,:QQ/C%V:3.I.*DSJ3RO?&D
MKZ3.I,^\ZK36I*RDJZ2KI.JDO:2FI,>DN:&C("`*"BY32"##^+S4"L'AP.X@
MO_(L(,7LM?ZYJ;;(PN>SV,W]L]C)]+[PRO.RRK/8LLH*+F)R"BYI;B`K.`HH
::"UT86MA<VE`:7,N=&ET96-H+F%C+FIP*0JR
`
end
SHAR_EOF
  $shar_touch -am 0106162495 'gnyaclock/gnyaclock.man' &&
  chmod 0444 'gnyaclock/gnyaclock.man' ||
  echo 'restore of gnyaclock/gnyaclock.man failed'
  shar_count="`wc -c < 'gnyaclock/gnyaclock.man'`"
  test 3779 -eq "$shar_count" ||
    echo "gnyaclock/gnyaclock.man: original size 3779, current size $shar_count"
fi
# ============= gnyaclock/XDrBezier.c ==============
if test -f 'gnyaclock/XDrBezier.c' && test X"$1" != X"-c"; then
  echo 'x - skipping gnyaclock/XDrBezier.c (file already exists)'
else
  echo 'x - extracting gnyaclock/XDrBezier.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'gnyaclock/XDrBezier.c' &&
/*
X * $Title: XDrBezier.c  --  draw a Bezier curve (like an Xlib function) $
X * $Creator: HAYAKAWA Takashi <h-takasi@is.titech.ac.jp> $
X * $Id: XDrBezier.c,v 1.3 1994/11/30 13:03:12 h-takasi Exp $
X */
X
#ifndef lint
static char *rcsid = "\
$Id: XDrBezier.c,v 1.3 1994/11/30 13:03:12 h-takasi Exp $\n\
";
#endif
X
#include <X11/Xlib.h>
#define	NUM_DIVISION	30	/* resolution of the curve */
X				/*  -- this should be more flexible! */
/*
X * Description:
X *   XDrawBezierCurve(dpy, d, gc, npoints, points)
X *	dpy	Display
X *	d	Window/Pixmap
X *	gc	GC
X *	points	control points of Bezier curve
X *	npoints number of points
X *
X * NOTE: Now it supports only 4-point-Bezier-curve.
X */
/*ARGSUSED*/
void XDrawBezierCurve(dpy, d, gc, points, npoints)
Display *dpy;
Drawable d;
GC gc;
XXPoint *points;
int npoints;	/* unused now */
{
X    XPoint pp[NUM_DIVISION + 1];
X    int i;
X
X    for(i=0; i<NUM_DIVISION+1; i++) {
X	double t = (double) i/NUM_DIVISION;
X	double s = 1.0 - t;
X
X	pp[i].x =   s*s*s*points[0].x + 3*s*s*t*points[1].x +
X	          3*s*t*t*points[2].x +   t*t*t*points[3].x;
X	pp[i].y =   s*s*s*points[0].y + 3*s*s*t*points[1].y +
X	          3*s*t*t*points[2].y +   t*t*t*points[3].y;
X    }
X    XDrawLines(dpy, d, gc, pp, NUM_DIVISION+1, CoordModeOrigin);
}
SHAR_EOF
  $shar_touch -am 1130220294 'gnyaclock/XDrBezier.c' &&
  chmod 0444 'gnyaclock/XDrBezier.c' ||
  echo 'restore of gnyaclock/XDrBezier.c failed'
  shar_count="`wc -c < 'gnyaclock/XDrBezier.c'`"
  test 1250 -eq "$shar_count" ||
    echo "gnyaclock/XDrBezier.c: original size 1250, current size $shar_count"
fi
# ============= gnyaclock/Imakefile ==============
if test -f 'gnyaclock/Imakefile' && test X"$1" != X"-c"; then
  echo 'x - skipping gnyaclock/Imakefile (file already exists)'
else
  echo 'x - extracting gnyaclock/Imakefile (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'gnyaclock/Imakefile' &&
XXCOMM ------------------------------------------------------------------
XXCOMM $Title: Imakefile  --  for gnyaclock $
XXCOMM $Creator: HAYAKAWA Takashi <h-takasi@is.titech.ac.jp> $
XXCOMM $Id: Imakefile,v 1.2 1995/01/06 07:25:50 h-takasi Exp $
XXCOMM ------------------------------------------------------------------
X
#define SUPPORT_EDITRES
#define SUPPORT_XPM
X
/*
X * for XPM support
X */
#ifdef SUPPORT_XPM
X    EXTRA_INCLUDES = -I/usr/local/include
X       XPM_LIBRARY = -lXpm
#endif
X
/*
X * for Editres Protocol support
X */
#ifdef SUPPORT_EDITRES
X           DEFINES = -DSUPPORT_EDITRES
X           DEPLIBS = XawClientDepLibs
X   LOCAL_LIBRARIES = $(XPM_LIBRARY) XawClientLibs
#else
X           DEPLIBS = $(DEPXTOOLLIB) $(DEPXMULIB) $(DEPEXTENSIONLIB) $(DEPXLIB)
X   LOCAL_LIBRARIES = $(XPM_LIBRARY) $(XTOOLLIB) $(XMULIB) \
X                     $(EXTENSIONLIB) $(XLIB)
#endif
X
X
X     SYS_LIBRARIES = -lm
X              SRCS = gnyaclock.c Clock.c XDrBezier.c
X              OBJS = gnyaclock.o Clock.o XDrBezier.o
X
ComplexProgramTarget(gnyaclock)
SHAR_EOF
  $shar_touch -am 0106162595 'gnyaclock/Imakefile' &&
  chmod 0444 'gnyaclock/Imakefile' ||
  echo 'restore of gnyaclock/Imakefile failed'
  shar_count="`wc -c < 'gnyaclock/Imakefile'`"
  test 1035 -eq "$shar_count" ||
    echo "gnyaclock/Imakefile: original size 1035, current size $shar_count"
fi
# ============= gnyaclock/gnyaclock.c ==============
if test -f 'gnyaclock/gnyaclock.c' && test X"$1" != X"-c"; then
  echo 'x - skipping gnyaclock/gnyaclock.c (file already exists)'
else
  echo 'x - extracting gnyaclock/gnyaclock.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'gnyaclock/gnyaclock.c' &&
/*
X * $Title: gnyaclock.c  --  program to demonstrate the gnyaclock widget $
X * $Creator: HAYAKAWA Takashi <h-takasi@is.titech.ac.jp> $
X * $Id: gnyaclock.c,v 1.3 1995/01/06 07:24:01 h-takasi Exp $
X */
X
#ifndef lint
static char *rcsid = "\
$Creator: HAYAKAWA Takashi <h-takasi@is.titech.ac.jp> $\n\
$Id: gnyaclock.c,v 1.3 1995/01/06 07:24:01 h-takasi Exp $\n\
";
#endif
X
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
X
#ifdef SUPPORT_XPM
#   include <X11/xpm.h>
#endif
X
#include "Clock.h"				/* Clock Widget */
X
#ifndef MAIL_PATH				/* path name of mail spool */
#   ifdef SYSV
#	define MAIL_PATH "/usr/mail"
#   else
#	define MAIL_PATH "/usr/spool/mail"
#   endif
#endif /* MAIL_PATH */
#define MAXPATH 1024
X
extern char  *getenv();
static void  quit(), biff();
X
/*
X * application resources
X */
typedef struct _GnyaRes {
X    int biff_update;				/* biff update (sec) */
X    Pixmap biff_bit;				/* biff bitmap */
X    String biff_file;				/* biff mailfile */
X
#ifdef SUPPORT_XPM
X    String xpm_back;				/* xpm file (back) */
X    String xpm_biff;				/* xpm file (biff) */
X    String xpm_path;				/* xpm file path */
#endif
X
X    Boolean havemail;
X    Widget clock_w;
X    Pixmap gnya_bit;
} GnyaRes;
X
static XtResource resources[] = {
X    {"biffUpdate", XtCInterval, XtRInt, sizeof(int),
X	XtOffset(GnyaRes*, biff_update), XtRString, "30"},
X    {"biffBitmap", XtCBitmap, XtRBitmap, sizeof(Pixmap),
X	XtOffset(GnyaRes*, biff_bit), XtRString, "grid8"},
X    {"biffFilename", XtCFile, XtRString, sizeof(String),
X	XtOffset(GnyaRes*, biff_file), XtRString, NULL},
X
#ifdef SUPPORT_XPM
#define XtCXpmFile "XpmFile"
#define XtCXpmFilePath "XpmFilePath"
X    {"pixmap", XtCXpmFile, XtRString, sizeof(String),
X	XtOffset(GnyaRes*, xpm_back), XtRString, NULL},
X    {"biffPixmap", XtCXpmFile, XtRString, sizeof(String),
X	XtOffset(GnyaRes*, xpm_biff), XtRString, NULL},
X    {"xpmFilePath", XtCXpmFilePath, XtRString, sizeof(String),
X	XtOffset(GnyaRes*, xpm_path), XtRString, NULL},
#endif
};
X
/*
X * additional actions
X */
static XtActionsRec actions[] = {
X    {"quit", quit}
};
X
/*
X * command line options
X */
static XrmOptionDescRec options[] = {
X    {"-bitmap",		"*Clock.bitmap",	XrmoptionSepArg, NULL},
X    {"-hand",		"*Clock.hand",		XrmoptionSepArg, NULL},
X    {"-dots",		"*Clock.dots",		XrmoptionSepArg, NULL},
X    {"-digital",	"*Clock.digital",	XrmoptionNoArg,  XtEon},
X    {"-box",		"*Clock.box",		XrmoptionNoArg,  XtEon},
X    {"-fill",		"*Clock.fill",		XrmoptionNoArg,	 XtEon},
X    {"-handwidth",	"*Clock.handWidth",	XrmoptionSepArg, NULL},
X    {"-clocktype",	"*Clock.clocktype",	XrmoptionSepArg, NULL},
X    {"-update",		"*Clock.update",	XrmoptionSepArg, NULL},
X    {"-usebmsize",	"*Clock.useBitmapSize",	XrmoptionNoArg,  XtEon},
X
X    {"-biffupdate",	"*biffUpdate",		XrmoptionSepArg, NULL},
X    {"-biffbitmap",	"*biffBitmap",		XrmoptionSepArg, NULL},
};
X
static Atom wm_del_win;
X
/*
X * usage
X */
void Usage(st, estat)
FILE *st;
int estat;
{
X    static char *mess[] = {
X	"Usage: gnyaclock  [-geometry <geom>] [-fn <font>]\n",
X	"    [-fg <pixel>] [-bg <pixel>] [-dots <pixel>] [-hand <pixel>]\n",
X	"    [-bitmap <filename>] [-handwidth <percentage>] [-digital]\n",
X	"    [-box] [-fill] [-clocktype <0..7>] [-update <seconds>]\n",
X	"    [-biffupdate <second>] [-biffbitmap <filename>]\n",
X	"    [-usebmsize]\n",
X	0
X    };
X    char **sp;
X
X    for(sp=mess; *sp; sp++) fputs(*sp, st);
X    exit(estat);
}
X
X
#ifdef SUPPORT_XPM
/*
X * ReadXpmFile:
X *     take NAME as an xpm filename, and try to read it.
X *   if succeeded, create a pixmap from it, and return.
X */
Pixmap ReadXpmFile(w, name)
Widget w;
char *name;
{
X    Display *dpy = XtDisplay(w);
X    Window root = RootWindowOfScreen(XtScreen(w));
X    Pixmap pix = None;
X    int state;
X
X    state = XpmReadFileToPixmap(dpy, root, name, &pix, NULL, NULL);
X    if(state != XpmSuccess) pix = None;		/* (not necessery) */
X
X    return pix;
}
X
/*
X * FindXpmFile:
X *     find an xpm file NAME from pathlist PATH.
X *   if found, create a pixmap from it and return.
X */
Pixmap FindXpmFile(w, name, path)
Widget w;
char *name, *path;
{
X    Pixmap pix;
X
X    if(!name) return None;			/* when no file */
X
X    pix = ReadXpmFile(w, name);			/* plain filename */
X    while(pix == None && *path) {		/* path prefixed filename */
X	char buf[MAXPATH];
X	char *bp = buf;
X
X	if(*path == '~') {			/* expand ~ to */
X	    char *home = getenv("HOME");	/*   home directory */
X	    if(home) {
X		strcpy(bp, home); bp += strlen(bp);
X		path++;
X	    }
X	}
X
X	while(*path && *path != ':')		/* extract a path from */
X	    *bp++ = *path++;			/*   colon-separated list */
X	if(*path == ':') path++;
X
X	strcpy(bp, "/");			/* append "/" */
X	strcat(bp, name);			/* append filename */
X	pix = ReadXpmFile(w, buf);		/* read it as xpm file */
X    }
X    return pix;
}
#endif
X
X
int main(argc, argv)
int argc;
char **argv;
{
X    XtAppContext app_con;
X    GnyaRes gr;
X    Widget top;					/* top of widget tree */
X    Arg args[1];
X    int narg = 0;
X    Pixmap pix;
X
X    top = XtAppInitialize(&app_con, "Gnyaclock",
X			  options, XtNumber(options),
X			  &argc, argv, NULL, NULL, 0);
X    if(argc != 1) Usage(stdout, 1);
X
X    XtGetApplicationResources(top, (XtPointer) &gr, resources,
X			      XtNumber(resources), NULL, 0);
X
#ifdef SUPPORT_XPM
X    /*
X     * override Bitmaps with XPMs.
X     */
X    pix = FindXpmFile(top, gr.xpm_back, gr.xpm_path);
X    if(pix != None) {
X	XtSetArg(args[narg], XtNbitmap, pix); narg++;
X    }
X    pix = FindXpmFile(top, gr.xpm_biff, gr.xpm_path);
X    if(pix != None) gr.biff_bit = pix;
#endif
X
X    gr.clock_w =
X	XtCreateManagedWidget("clock", clockWidgetClass, top,
X			      args, narg);
X
X    XtAppAddActions(app_con, actions, XtNumber(actions));
X    XtOverrideTranslations(top,
X	   XtParseTranslationTable("<Message>WM_PROTOCOLS: quit()"));
X    XtRealizeWidget(top);
X    wm_del_win = XInternAtom(XtDisplay(top), "WM_DELETE_WINDOW", False);
X    XSetWMProtocols(XtDisplay(top), XtWindow(top), &wm_del_win, 1);
X
X    /*
X     * initialization for BIFF
X     */
X    if(!gr.biff_file) {				/* if biffFile is not set, */
X	static char mail_path[MAXPATH] = "";	/*   set it according to */
X	char *u = getenv("USER");		/*   user name */
X
X	if(u) {
X	    gr.biff_file = mail_path;
X	    sprintf(mail_path, "%s/%s", MAIL_PATH, u);
X	}
X    }
X    gr.havemail = 0;
X    biff((XtPointer) &gr, NULL);
X
X    XtAppMainLoop(app_con);
X    /*NOTREACHED*/
X    return 0;
}
X
X
/*
X * biff:
X *	check the mailbox file.
X */
/*ARGSUSED*/
static void biff(client_data, timer)
XXtPointer client_data;
XXtIntervalId *timer;		/* unused */
{
X    GnyaRes *gr = (GnyaRes *) client_data;
X    struct stat fs;
X    Widget w = gr->clock_w;
X    int mailnow;
X
X    mailnow =
X	gr->biff_file &&
X	    (stat(gr->biff_file, &fs)?  0 : fs.st_size);
X
X    if(!gr->havemail) {
X	XtVaGetValues(w, XtNbitmap, &gr->gnya_bit, NULL);
X	if(mailnow) XBell(XtDisplay(w), 0);
X    }
X
X    XtVaSetValues(w, XtNbitmap, mailnow?  gr->biff_bit : gr->gnya_bit,
X		     XtNlabel,  mailnow?  "Mail"       : NULL,
X		     NULL);
X
X    gr->havemail = mailnow;
X    XtAppAddTimeOut(XtWidgetToApplicationContext(w),
X		    1000*gr->biff_update, biff, client_data);
}
X
/*
X * quit:
X *	quit the program.  almost for event
X *	from window manager.
X */
static void quit(w, xev)
Widget w;
XXEvent *xev;
{
X    if(xev && xev->type == ClientMessage &&
X       xev->xclient.data.l[0] == wm_del_win)
X    {
X	XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
X	exit(0);
X    }
}
X
/*
X * for Xaw-Editres protocol
X *	(to link libXaw... i like editres, but there'd be a better way)
X */
#ifdef SUPPORT_EDITRES
#include <X11/Xaw/XawInit.h>
static void _Editres_Xaw()
{
X    XawInitializeWidgetSet();
}
#endif
SHAR_EOF
  $shar_touch -am 0106162395 'gnyaclock/gnyaclock.c' &&
  chmod 0444 'gnyaclock/gnyaclock.c' ||
  echo 'restore of gnyaclock/gnyaclock.c failed'
  shar_count="`wc -c < 'gnyaclock/gnyaclock.c'`"
  test 7736 -eq "$shar_count" ||
    echo "gnyaclock/gnyaclock.c: original size 7736, current size $shar_count"
fi
# ============= gnyaclock/handdata.h ==============
if test -f 'gnyaclock/handdata.h' && test X"$1" != X"-c"; then
  echo 'x - skipping gnyaclock/handdata.h (file already exists)'
else
  echo 'x - extracting gnyaclock/handdata.h (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'gnyaclock/handdata.h' &&
/*
X * $Title: handdata.h  --  data for Bezier curved hand $
X * $Creator: HAYAKAWA Takashi <h-takasi@is.titech.ac.jp> $
X * $Id: handdata.h,v 1.2 1994/11/30 13:01:01 h-takasi Exp $
X */
static double cv_data[13][4] = {
X    {-1500,  0.70,   1500,  0.65},		/* 12 */
X    {-1350,  0.65,   1300,  0.60},		/*  1 */
X    {-1200,  0.55,   1200,  0.50},		/*  2 */
X
X    { -900,  0.45,    900,  0.40},		/*  3 */
X    { -600,  0.40,    600,  0.35},		/*  4 */
X    { -700,  0.30,   -450,  0.30},		/*  5 */
X
X    {-1000,  0.25,   -800,  0.25},		/*  6 */
X    { -700,  0.30,   -600,  0.30},		/*  7 */
X    {  450,  0.35,   -450,  0.35},		/*  8 */
X
X    {  900,  0.40,   -900,  0.38},		/*  9 */
X    { 1350,  0.55,  -1350,  0.50},		/* 10 */
X    { 2000,  0.65,  -2000,  0.60},		/* 11 */
X
X    { 2100,  0.70,  -2100,  0.65}		/* 12 */
};
SHAR_EOF
  $shar_touch -am 1130220094 'gnyaclock/handdata.h' &&
  chmod 0444 'gnyaclock/handdata.h' ||
  echo 'restore of gnyaclock/handdata.h failed'
  shar_count="`wc -c < 'gnyaclock/handdata.h'`"
  test 807 -eq "$shar_count" ||
    echo "gnyaclock/handdata.h: original size 807, current size $shar_count"
fi
# ============= gnyaclock/ClockP.h ==============
if test -f 'gnyaclock/ClockP.h' && test X"$1" != X"-c"; then
  echo 'x - skipping gnyaclock/ClockP.h (file already exists)'
else
  echo 'x - extracting gnyaclock/ClockP.h (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'gnyaclock/ClockP.h' &&
/*
X * $Title: ClockP.h  --  gnyaclock widget private header $
X * $Creator: HAYAKAWA Takashi <h-takasi@is.titech.ac.jp> $
X * $Id: ClockP.h,v 1.3 1994/11/30 13:05:10 h-takasi Exp $
X */
X
#ifndef	_XtClockP_h
#define _XtClockP_h
X
#include <X11/CoreP.h>
#include "Clock.h"
X
typedef struct _ClockPart {
X    /*
X     * resource values
X     */
X    Pixel	fore, dots, hand;	/* colors		*/
X    Pixmap	bitmap;			/* clock face bitmap	*/
X    Cursor	cursor;			/* mouse cursor		*/
X    XFontStruct	*font;			/* digital clock font	*/
X    Boolean	digital, box, fill;	/* switches		*/
X    Boolean	bmsize;
X    String	label;			/* message label	*/
X    int		clocktype, update;
X    int		handwidth, hand_l, hand_s;
X
X    /*
X     * internal values
X     */
X    XtIntervalId interval_id;
X    Boolean	chase, visible;
X    Pixmap	pix;			/* double buffer	*/
X    GC		gc_fore, gc_tile, gc_dots, gc_hand, gc_back;
X
X    XArc	arcs[12];		/* dots of clock */
X    int		narcs;
X    XRectangle	rect;			/* box of digital area */
} ClockPart;
X
typedef struct _ClockRec {
X    CorePart	core;
X    ClockPart	gnya;
} ClockRec;
X
typedef struct {int dummy;} ClockClassPart;
X
typedef struct	_ClockClassRec {
X    CoreClassPart	core_class;
X    ClockClassPart	gnya_class;
} ClockClassRec;
X
extern ClockClassRec	clockClassRec;
X
#endif	/* _XtClockP_h */
SHAR_EOF
  $shar_touch -am 1130220494 'gnyaclock/ClockP.h' &&
  chmod 0444 'gnyaclock/ClockP.h' ||
  echo 'restore of gnyaclock/ClockP.h failed'
  shar_count="`wc -c < 'gnyaclock/ClockP.h'`"
  test 1289 -eq "$shar_count" ||
    echo "gnyaclock/ClockP.h: original size 1289, current size $shar_count"
fi
exit 0
