vix@ubvax.UB.Com (Paul Vixie) (04/05/88)
#! /bin/sh ## This is a shell archive. Remove anything before this line, then unpack ## it by saving it into a file and typing "sh file". To overwrite existing ## files, type "sh file -c". You can also feed this as standard input via ## unshar, or by typing "sh <file". If this archive is complete, you will ## see the following message at the end: # "End of shell archive." # Contents: Imakefile README colordemo.c # Wrapped by vix@ubvax on Mon Apr 4 17:32:52 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f Imakefile -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"Imakefile\" else echo shar: Extracting \"Imakefile\" \(250 characters\) sed "s/^X//" >Imakefile <<'END_OF_Imakefile' X INCLUDES = -I$(TOP) X SRCS = colordemo.c X OBJS = colordemo.o XLOCAL_LIBRARIES = $(XAWLIB) $(XTOOLLIB) $(XLIB) X XComplexProgramTarget(colordemo) X XDependTarget() X Xsaber :; saber $(INCLUDES) $(LDFLAGS) $(SRCS) $(LOCAL_LIBRARIES) END_OF_Imakefile if test 250 -ne `wc -c <Imakefile`; then echo shar: \"Imakefile\" unpacked with wrong size! fi # end of overwriting check fi if test -f README -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"README\" else echo shar: Extracting \"README\" \(405 characters\) sed "s/^X//" >README <<'END_OF_README' XColordemo V1.0 XApril 4, 1988 XPaul Vixie Xvix@ub.com X XThis is a quick Xt11 program that reads rgb.txt and generates a label widget Xin each color found therein. It's slow, there are probably better ways to do Xwhat it does. It's also reasonably cute. X XDistribute freely except don't remove my name. Add your own copyrights as you Xplease. Note that many excerpts were ripped from the MIT toolkit examples. END_OF_README if test 405 -ne `wc -c <README`; then echo shar: \"README\" unpacked with wrong size! fi # end of overwriting check fi if test -f colordemo.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"colordemo.c\" else echo shar: Extracting \"colordemo.c\" \(3252 characters\) sed "s/^X//" >colordemo.c <<'END_OF_colordemo.c' X/* colordemo - show all the colors from rgb.txt X * vix 04apr88 [written] X */ X X X#include <stdio.h> X#include <X11/Xatom.h> X#include <X11/Intrinsic.h> X#include <X11/Atoms.h> X#include <X11/Box.h> X#include <X11/Clock.h> X#include <X11/Command.h> X#include <X11/Dialog.h> X#include <X11/Label.h> X#include <X11/Load.h> X#include <X11/Scroll.h> X#include <X11/AsciiText.h> X#include <X11/Core.h> X#include <X11/Viewport.h> X#include <X11/VPaned.h> X#include <X11/Cardinals.h> X#include <X11/Shell.h> X X X#define RGB_TXT "/usr/local/lib/X11/rgb.txt" X X Xstatic XrmOptionDescRec options[] = { X {"-label", XtNlabel, XrmoptionSepArg, NULL} X}; X X Xvoid XSyntax(call) char *call; { X printf("Usage: %s\n", call); X exit(0); X} X X X/* ARGSUSED */ Xvoid XDestroyed(widget, closure, callData) X Widget widget; /* unused */ X caddr_t closure; /* unused */ X caddr_t callData; /* unused */ X{ X exit(0); X} X X X X/* ARGSUSED */ Xvoid XquitFunc(widget, closure, callData) X Widget widget; /* unused */ X caddr_t closure; /* widget to destroy */ X caddr_t callData; /* unused */ X{ X XtDestroyWidget((Widget)closure); X} X X X Xvoid Xmain(argc, argv) X unsigned int argc; X char **argv; X{ X static XtCallbackRec callback[2]; /* K&R: initialized to NULL */ X /**/ Widget toplevel, outer, colors; X /**/ Arg arg[10]; X /**/ int n; X X toplevel = XtInitialize( "main", "colordemo", X options, XtNumber(options), X &argc, argv ); X X if (argc != 1) Syntax(argv[0]); X X n = 0; X XtSetArg(arg[n], XtNwidth, 400); n++; X outer = XtCreateManagedWidget( NULL, vPanedWidgetClass, X toplevel, arg, n ); X XtAddCallback(outer, XtNdestroyCallback, Destroyed, NULL); X X n = 0; X callback[0].callback = quitFunc; X callback[0].closure = (caddr_t) outer; X XtSetArg(arg[n], XtNcallback, callback); n++; X XtCreateManagedWidget( "quit", commandWidgetClass, X outer, arg, n ); X X n = 0; X colors = XtCreateManagedWidget( "colors", boxWidgetClass, X outer, arg, n ); X X colordemo(colors); X X XtRealizeWidget(toplevel); X X XtMainLoop(); X} X X Xstatic Xcolordemo(parent) X Widget parent; X{ X int r, g, b, prev_r, prev_g, prev_b, dups; X char colorname[50], save_colorname[50]; X FILE *rgb; X X if (!(rgb = fopen(RGB_TXT, "r"))) { X perror(RGB_TXT); X exit(2); /* vms will be with me forever */ X } X X dups = 0; X prev_r = prev_g = prev_b = -1; X save_colorname[0] = '\0'; X while (4 == fscanf(rgb, "%d %d %d %[^\n]\n", &r, &g, &b, colorname)) { X if (r == prev_r && g == prev_g && b == prev_b) { X dups++; X strcpy(save_colorname, colorname); X } else { X dups = 0; X if (save_colorname[0]) X do_color(parent, save_colorname); X prev_r = r; X prev_g = g; X prev_b = b; X } X } X if (dups) X do_color(parent, colorname); X} X X Xstatic Pixel XstringToPixel(w, colorname) X Widget w; X String colorname; X{ X XrmValue in, out; X X in.addr = colorname; X in.size = strlen(colorname) + 1; X XtConvert(w, XtRString, &in, XtRPixel, &out); X return *(Pixel*)out.addr; X} X X Xstatic Xdo_color(parent, colorname) X Widget parent; X char *colorname; X{ X Arg arg[10]; X int n; X X n = 0; X XtSetArg(arg[n], XtNborderWidth, 10); n++; X XtSetArg(arg[n], XtNborderColor, stringToPixel(parent, colorname)); X n++; X XtCreateManagedWidget(colorname, labelWidgetClass, parent, arg, n); X} END_OF_colordemo.c if test 3252 -ne `wc -c <colordemo.c`; then echo shar: \"colordemo.c\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of shell archive. exit 0 -- Paul Vixie Consultant Work: 408-562-7798 vix@ub.com vix%ubvax@uunet.uu.net Ungermann-Bass Home: 415-647-7023 {amdahl,ptsfa,pyramid,uunet}!ubvax!vix Santa Clara, CA <<I do not speak for Ungermann-Bass>>