v11i086: xtartan, Part02/02
Jim McBeath
jimmc at Snoqualmie.hisoft.infocomm.com
Mon Feb 18 07:05:53 AEST 1991
Submitted-by: jimmc at Snoqualmie.hisoft.infocomm.com (Jim McBeath)
Posting-number: Volume 11, Issue 86
Archive-name: xtartan/part02
#! /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: Makefile Imakefile patchlevel.h tartan.h tartcursor.h
# actions.c color.c draw.c main.c misc.c setrootbg.c tartan.c
# Wrapped by jimmc at snoqualmie on Mon Feb 11 16:50:47 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Makefile -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(7738 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X# Makefile generated by imake - do not edit!
X# $XConsortium: imake.c,v 1.37 88/10/08 20:08:30 jim Exp $
X#
X# The cpp used on this machine replaces all newlines and multiple tabs and
X# spaces in a macro expansion with a single space. Imake tries to compensate
X# for this, but is not always successful.
X#
X
X###########################################################################
X# X Window System Makefile generated from template file Imake.tmpl
X# $XConsortium: Imake.tmpl,v 1.91 88/10/23 22:37:10 jim Exp $
X#
X# Do not change the body of the imake template file. Server-specific
X# parameters may be set in the appropriate .macros file; site-specific
X# parameters (but shared by all servers) may be set in site.def. If you
X# make any changes, you'll need to rebuild the makefiles using
X# "make World" (at best) or "make Makefile; make Makefiles" (at least) in
X# the top level directory.
X#
X# If your C preprocessor doesn't define any unique symbols, you'll need
X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
X# "make Makefile", "make Makefiles", or "make World").
X#
X# If you absolutely can't get imake to work, you'll need to set the
X# variables at the top of each Makefile as well as the dependencies at the
X# bottom (makedepend will do this automatically).
X#
X
X###########################################################################
X# platform-specific configuration parameters - edit Sun.macros to change
X
X# platform: $XConsortium: Sun.macros,v 1.52 88/10/23 11:00:55 jim Exp $
X# operating system: SunOS 3.4
X
XBOOTSTRAPCFLAGS =
X AS = as
X CC = cc
X CPP = /lib/cpp
X LD = ld
X LINT = lint
X INSTALL = install
X TAGS = ctags
X RM = rm -f
X MV = mv
X LN = ln -s
X RANLIB = ranlib
XRANLIBINSTFLAGS = -t
X AR = ar clq
X LS = ls
X LINTOPTS = -axz
X LINTLIBFLAG = -C
X MAKE = make
XSTD_CPP_DEFINES =
X STD_DEFINES =
X
X###########################################################################
X# site-specific configuration parameters - edit site.def to change
X
X# site: $XConsortium: site.def,v 1.16 88/10/12 10:30:24 jim Exp $
X
X###########################################################################
X# definitions common to all Makefiles - do not edit
X
X SHELL = /bin/sh
X
X DESTDIR =
X USRLIBDIR = $(DESTDIR)/usr/lib
X BINDIR = $(DESTDIR)/usr/bin/X11
X INCDIR = $(DESTDIR)/usr/include/X11
X ADMDIR = $(DESTDIR)/usr/adm
X LIBDIR = $(USRLIBDIR)/X11
X LINTLIBDIR = $(USRLIBDIR)/lint
X FONTDIR = $(LIBDIR)/fonts
X XINITDIR = $(LIBDIR)/xinit
X XDMDIR = $(LIBDIR)/xdm
X UWMDIR = $(LIBDIR)/uwm
X AWMDIR = $(LIBDIR)/awm
X TWMDIR = $(LIBDIR)/twm
X MANPATH = $(DESTDIR)/usr/man
X MANSOURCEPATH = $(MANPATH)/man
X MANDIR = $(MANSOURCEPATH)n
X LIBMANDIR = $(MANSOURCEPATH)3
X XAPPLOADDIR = $(LIBDIR)/app-defaults
X
X INSTBINFLAGS = -m 0755
X INSTUIDFLAGS = -m 4755
X INSTLIBFLAGS = -m 0664
X INSTINCFLAGS = -m 0444
X INSTMANFLAGS = -m 0444
X INSTAPPFLAGS = -m 0444
X INSTKMEMFLAGS = -m 4755
X FCFLAGS = -t
X CDEBUGFLAGS = -g
X
X PATHSEP = /
X DEPEND = $(DEPENDSRC)/makedepend
X IMAKE = $(IMAKESRC)/imake
X RGB = $(RGBSRC)/rgb
X FC = $(BDFTOSNFSRC)/bdftosnf
X MKFONTDIR = $(MKFONTDIRSRC)/mkfontdir
X MKDIRHIER = $(SCRIPTSSRC)/mkdirhier.sh
X
X CFLAGS = $(CDEBUGFLAGS) $(INCLUDES) $(STD_DEFINES) $(DEFINES)
X LINTFLAGS = $(LINTOPTS) $(INCLUDES) $(STD_DEFINES) $(DEFINES) -DLINT
X LDFLAGS = $(CDEBUGFLAGS) $(SYS_LIBRARIES) $(SYSAUX_LIBRARIES)
X TOP = .
X CLIENTSRC = $(TOP)/clients
X DEMOSRC = $(TOP)/demos
X LIBSRC = $(TOP)/lib
X FONTSRC = $(TOP)/fonts
X INCLUDESRC = $(TOP)/X11
X SERVERSRC = $(TOP)/server
X UTILSRC = $(TOP)/util
X SCRIPTSSRC = $(UTILSRC)/scripts
X EXAMPLESRC = $(TOP)/examples
X CONTRIBSRC = $(TOP)/contrib
X DOCSRC = $(TOP)/doc
X RGBSRC = $(TOP)/rgb
X DEPENDSRC = $(UTILSRC)/makedepend
X IMAKESRC = $(UTILSRC)/imake
X IRULESRC = $(UTILSRC)/imake.includes
X XLIBSRC = $(LIBSRC)/X
X XMUSRC = $(LIBSRC)/Xmu
X TOOLKITSRC = $(LIBSRC)/Xt
X AWIDGETSRC = $(LIBSRC)/Xaw
X OLDXLIBSRC = $(LIBSRC)/oldX
X BDFTOSNFSRC = $(FONTSRC)/bdftosnf
X MKFONTDIRSRC = $(FONTSRC)/mkfontdir
X EXTENSIONSRC = $(TOP)/extensions
X EXTENSIONLIB = $(EXTENSIONSRC)/lib/libXext.a
X XLIB = $(XLIBSRC)/libX11.a
X XMULIB = $(XMUSRC)/libXmu.a
X OLDXLIB = $(OLDXLIBSRC)/liboldX.a
X XTOOLLIB = $(TOOLKITSRC)/libXt.a
X XAWLIB = $(AWIDGETSRC)/libXaw.a
X LINTXLIB = $(XLIBSRC)/llib-lX11.ln
X LINTXMU = $(XMUSRC)/llib-lXmu.ln
X LINTXTOOL = $(TOOLKITSRC)/llib-lXt.ln
X LINTXAW = $(AWIDGETSRC)/llib-lXaw.ln
X INCLUDES = -I$(TOP)
X MACROFILE = Sun.macros
X ICONFIGFILES = $(IRULESRC)/Imake.tmpl \
X $(IRULESRC)/$(MACROFILE) $(IRULESRC)/site.def
X IMAKE_DEFINES =
X IMAKE_CMD = $(NEWTOP)$(IMAKE) -TImake.tmpl -I$(NEWTOP)$(IRULESRC) \
X -s Makefile $(IMAKE_DEFINES)
X RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a \
X .emacs_* tags TAGS make.log MakeOut
X
X###########################################################################
X# rules: $XConsortium: Imake.rules,v 1.71 88/10/23 22:46:34 jim Exp $
X
X###########################################################################
X# start of Imakefile
X
XLOCAL_LIBRARIES =
X SYS_LIBRARIES = -lXt -lX11
X
X OBJS = actions.o \
X color.o \
X draw.o \
X main.o \
X misc.o \
X setrootbg.o \
X tartan.o
X SRCS = actions.c \
X color.c \
X draw.c \
X main.c \
X misc.c \
X setrootbg.c \
X tartan.c
X
X PROGRAM = xtartan
X
Xall:: xtartan
X
Xxtartan: $(OBJS) $(LOCAL_LIBRARIES)
X $(RM) $@
X $(CC) -o $@ $(OBJS) $(LOCAL_LIBRARIES) $(LDFLAGS) $(SYSLAST_LIBRARIES)
X
Xrelink::
X $(RM) $(PROGRAM)
X $(MAKE) $(MFLAGS) $(PROGRAM)
X
Xinstall:: xtartan
X $(INSTALL) -c $(INSTALLFLAGS) xtartan $(BINDIR)
X
Xinstall.man:: xtartan.man
X $(INSTALL) -c $(INSTMANFLAGS) xtartan.man $(MANDIR)/xtartan.n
X
Xdepend:: $(DEPEND)
X
Xdepend::
X $(DEPEND) -s "# DO NOT DELETE" -- $(CFLAGS) -- $(SRCS)
X
X$(DEPEND):
X @echo "making $@"; \
X cd $(DEPENDSRC); $(MAKE)
X
Xclean::
X $(RM) $(PROGRAM)
X
X###########################################################################
X# Imake.tmpl common rules for all Makefiles - do not edit
X
Xemptyrule::
X
Xclean::
X $(RM_CMD) \#*
X
XMakefile:: $(IMAKE)
X
XMakefile:: Imakefile \
X $(IRULESRC)/Imake.tmpl \
X $(IRULESRC)/Imake.rules \
X $(IRULESRC)/site.def \
X $(IRULESRC)/$(MACROFILE)
X - at if [ -f Makefile ]; then \
X echo "$(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
X $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
X else exit 0; fi
X $(IMAKE_CMD) -DTOPDIR=$(TOP)
X
X$(IMAKE):
X @echo "making $@"; \
X cd $(IMAKESRC); $(MAKE) BOOTSTRAPCFLAGS=$(BOOTSTRAPCFLAGS)
X
Xtags::
X $(TAGS) -w *.[ch]
X $(TAGS) -xw *.[ch] > TAGS
X
X###########################################################################
X# empty rules for directories that do not have SUBDIRS - do not edit
X
Xinstall::
X @echo "install done"
X
Xinstall.man::
X @echo "install.man done"
X
XMakefiles::
X
X###########################################################################
X# dependencies generated by makedepend
X
X# DO NOT DELETE
X
Xcolor.o: /usr/include/X11/Intrinsic.h /usr/include/X11/Xlib.h
Xdraw.o: /usr/include/X11/Intrinsic.h /usr/include/X11/Xlib.h
Xmain.o: tartcursor.h patchlevel.h \
X /usr/include/X11/Intrinsic.h /usr/include/X11/Xlib.h \
X /usr/include/X11/Xatom.h /usr/include/X11/StringDefs.h
Xmisc.o: /usr/include/X11/Intrinsic.h /usr/include/X11/Xlib.h
Xsetrootbg.o: /usr/include/X11/Intrinsic.h /usr/include/X11/Xlib.h \
X /usr/include/X11/Xatom.h
END_OF_Makefile
if test 7738 -ne `wc -c <Makefile`; then
echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f Imakefile -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"Imakefile\"
else
echo shar: Extracting \"Imakefile\" \(235 characters\)
sed "s/^X//" >Imakefile <<'END_OF_Imakefile'
XLOCAL_LIBRARIES =
X SYS_LIBRARIES = -lXt -lX11
X OBJS = actions.o color.o draw.o main.o misc.o setrootbg.o tartan.o
X SRCS = actions.c color.c draw.c main.c misc.c setrootbg.c tartan.c
X
XComplexProgramTarget(xtartan)
END_OF_Imakefile
if test 235 -ne `wc -c <Imakefile`; then
echo shar: \"Imakefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f patchlevel.h -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"patchlevel.h\"
else
echo shar: Extracting \"patchlevel.h\" \(635 characters\)
sed "s/^X//" >patchlevel.h <<'END_OF_patchlevel.h'
X/* patchlevel.h for xtartan
X */
X
X#define VERSION "xtartan version 2.0 February 11, 1990"
X/* by Jim McBeath (jimmc at hisoft.uucp, jimmc at netcom.com) */
X
X/*
X * v1 posted November 1989
X *
X * patch1, version 1.1, December 1989:
X * add extra braces to TI*.h files to conform to ANSI C;
X * change Imakefile to "ComplexProgramTarget".
X *
X * version 2.0, February 1991:
X * Use XTartan resource file for sizes, translations, color mappings, and
X * tartan (sett) definitions. There is no longer any sett info compiled
X * into the program, so you can add new tartans (or replace exising tartans)
X * without recompiling.
X */
X
X/* end */
END_OF_patchlevel.h
if test 635 -ne `wc -c <patchlevel.h`; then
echo shar: \"patchlevel.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f tartan.h -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"tartan.h\"
else
echo shar: Extracting \"tartan.h\" \(1804 characters\)
sed "s/^X//" >tartan.h <<'END_OF_tartan.h'
X/* tartan.h (formerly tartaninfo.h)
X * Jim McBeath (jimmc at hisoft.uucp)
X *
X * 11.Jan.88 jimmc Extracted from xtartan.c
X * 13.Jan.88 Remove numstripes field in Sinfo, use null color name instead
X * 9.Jan.99 jimmc v2.0: Resource-based version
X */
X
X/* fill styles */
X#define VSTRIPE (1<<10)
X#define HSTRIPE (1<<11)
X#define SOLID 1 /* solid rectangle */
X#define RLINES 2 /* lines in same direction as stripes */
X#define HLINES 3 /* horizontal lines */
X#define VLINES 4 /* vertical lines */
X#define NOP 5 /* draw nothing */
X#define ALINES 6 /* angled lines (lower left to upper right) */
X
X/* stripe group flags */
X#define HVSAME (1<<0) /* vertical stripes are same as horizontal */
X#define SYM (1<<1) /* symmetrical stripe pattern */
X#define PIVOT2 (1<<2) /* last two colors are double-pivot */
X
Xtypedef struct _s1info { /* info about one stripe */
X char *color; /* name of color code of the stripe */
X /* (null indicates end of a list of stripes) */
X int width; /* width of the stripe */
X int style; /* style of the stripe */
X} S1info;
X
Xtypedef struct _sinfo { /* info about a set of stripes */
X int flags; /* flags about the stripe group */
X S1info *slist; /* info about each stripe */
X /* end of the list is specified by a stripe with a null
X * color name. */
X} Sinfo;
X
Xtypedef struct _tartaninfo {
X struct _tartaninfo *next, *prev;
X char *name; /* name of this tartan */
X char *sett; /* the sett data */
X/* the remainder of the structure is filled in only when the tartan sett
X * string is parsed (on demand) */
X int isparsed; /* true after it has been parsed */
X Sinfo hstripes; /* info about horizontal stripes */
X /* stripes listed from bottom to top */
X Sinfo vstripes; /* info about vertical stripes */
X /* stripes listed from left to right */
X} TartanInfo;
X
X/* end */
END_OF_tartan.h
if test 1804 -ne `wc -c <tartan.h`; then
echo shar: \"tartan.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f tartcursor.h -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"tartcursor.h\"
else
echo shar: Extracting \"tartcursor.h\" \(687 characters\)
sed "s/^X//" >tartcursor.h <<'END_OF_tartcursor.h'
X#define tartcursor_width 16
X#define tartcursor_height 16
X#define tartcursor_x_hot 7
X#define tartcursor_y_hot 7
Xstatic char tartcursor_bits[] = {
X 0x14, 0x45, 0x08, 0x22, 0x14, 0x45, 0x5d, 0x77, 0xbe, 0xef, 0x5d, 0x77,
X 0x14, 0x45, 0x08, 0x22, 0x14, 0x45, 0x5d, 0x77, 0xbe, 0xef, 0x5d, 0x77,
X 0x14, 0x45, 0x08, 0x22, 0xbe, 0xef, 0x08, 0x22};
X
X#define tartmask_width 16
X#define tartmask_height 16
X#define tartmask_x_hot -1
X#define tartmask_y_hot -1
Xstatic char tartmask_bits[] = {
X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
END_OF_tartcursor.h
if test 687 -ne `wc -c <tartcursor.h`; then
echo shar: \"tartcursor.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f actions.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"actions.c\"
else
echo shar: Extracting \"actions.c\" \(2144 characters\)
sed "s/^X//" >actions.c <<'END_OF_actions.c'
X/* actions.c - translation table stuff and action routines for xtartan
X * by Jim McBeath (jimmc at hisoft.uucp)
X *
X * 25.Oct.89 jimmc Initial definition
X * 9.Jan.91 jimmc v2.0: Use XTartan resource file
X */
X
X#include <X11/Intrinsic.h>
X#include <stdio.h>
X
Xextern char *GetStringResource();
X
Xextern Widget TTopWidget;
Xextern char *TartanName;
Xextern char *TartanSett;
X
Xstatic void
XHelp(w,xev,argv,argcp)
XWidget w;
XXEvent *xev;
XString *argv;
Xint *argcp;
X{
X char *s;
X
X s = GetStringResource(TTopWidget,"helpString");
X if (s) {
X (void)printf("%s",s);
X XtFree(s);
X } else {
X (void)printf("No help available\n");
X }
X}
X
Xstatic void
XSetTart(w,xev,argv,argcp)
XWidget w;
XXEvent *xev;
XString *argv;
Xint *argcp;
X{
X if (*argcp>0)
X (void)setTartan(argv[0]);
X}
X
Xstatic void
XPrintName(w,xev,argv,argcp)
XWidget w;
XXEvent *xev;
XString *argv;
Xint *argcp;
X{
X (void)printf("%s\n", TartanName);
X}
X
Xstatic void
XPrintSettAction(w,xev,argv,argcp)
XWidget w;
XXEvent *xev;
XString *argv;
Xint *argcp;
X{
X PrintSett();
X}
X
Xstatic void
XDoExit(w,xev,argv,argcp)
XWidget w;
XXEvent *xev;
XString *argv;
Xint *argcp;
X{
X exit(0);
X}
X
Xstatic void
XInfo(w,xev,argv,argcp)
XWidget w;
XXEvent *xev;
XString *argv;
Xint *argcp;
X{
X (void)printf("%s scale=%d linewidth=%d\n",
X TartanName,getScale(),getWidth());
X}
X
Xstatic void
XScale(w,xev,argv,argcp)
XWidget w;
XXEvent *xev;
XString *argv;
Xint *argcp;
X{
X if (*argcp>0)
X changeScale(argv[0]);
X else
X changeScale("2"); /* default */
X}
X
Xstatic void
XLineWidth(w,xev,argv,argcp)
XWidget w;
XXEvent *xev;
XString *argv;
Xint *argcp;
X{
X if (*argcp>0)
X changeWidth(argv[0]);
X else
X changeWidth("1"); /* default */
X}
X
Xstatic void
XDump(w,xev,argv,argcp)
XWidget w;
XXEvent *xev;
XString *argv;
Xint *argcp;
X{
X (void)printf("Tartan setts:\n");
X DumpTartans();
X (void)printf("Color codes in cache:\n");
X dumpColors();
X}
X
XXtActionsRec actions[] = {
X {"dump", Dump },
X {"exit", DoExit },
X {"help", Help },
X {"info", Info },
X {"lineWidth", LineWidth },
X {"name", PrintName },
X {"scale", Scale },
X {"setTartan", SetTart },
X {"sett", PrintSettAction },
X};
X
XinitActions(appctx)
XXtAppContext appctx;
X{
X XtAppAddActions(appctx,actions,XtNumber(actions));
X}
X
X/* end */
END_OF_actions.c
if test 2144 -ne `wc -c <actions.c`; then
echo shar: \"actions.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f color.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"color.c\"
else
echo shar: Extracting \"color.c\" \(2120 characters\)
sed "s/^X//" >color.c <<'END_OF_color.c'
X/* color.c - functions dealing with colors
X * by Jim McBeath (jimmc at hisoft.uucp)
X *
X * 7.Jan.88 jimmc Initial definition (X10)
X * 24.Oct.89 jimmc Convert to X11, Xt; general restructuring
X * 9.Jan.91 jimmc v2.0: Use resources to do color translations
X */
X
X#include <X11/Intrinsic.h>
X
Xtypedef struct _cinfo { /* info about one color */
X struct _cinfo *next;
X char *name;
X char *longname;
X int pixel;
X} Cinfo;
X
Xextern char *GetSubResource();
X
Xextern Display *TDisplay;
Xextern Widget TTopWidget;
Xextern Colormap TColormap;
X
XCinfo *colorinfo;
X
Xint /* returns the pixel value */
XcolorPixel(color)
Xchar *color; /* the color code */
X{
X Cinfo *p;
X char *tcolor;
X int t,pixel;
X XColor xdef, sdef;
X
X /* see if we have already translated this color */
X for (p=colorinfo; p; p=p->next) {
X if (strcmp(p->name,color)==0)
X return p->pixel;
X }
X /* we have not seen it before, make the translation */
X pixel = 0; /* we use 0 on any errors */
X tcolor = GetSubResource(TTopWidget,"colorCode",color);
X if (!tcolor) {
X Warn("No color translation for code %s",color);
X tcolor = "<No translation>";
X } else {
X t = XLookupColor(TDisplay,TColormap,tcolor,&xdef,&sdef);
X if (t==0) {
X Warn("Error getting definition for color %s, code %s",
X tcolor, color);
X } else {
X t = XAllocColor(TDisplay,TColormap,&xdef);
X if (t==0) {
X Warn("Can't allocate color %s, code %s",
X tcolor, color);
X } else {
X pixel = xdef.pixel;
X }
X }
X }
X p = (Cinfo *)XtMalloc(sizeof(Cinfo));
X p->name = XtMalloc(strlen(color)+1);
X (void)strcpy(p->name,color);
X p->longname = XtMalloc(strlen(tcolor)+1);
X (void)strcpy(p->longname,tcolor);
X p->pixel = pixel;
X p->next = colorinfo;
X colorinfo = p;
X return p->pixel;
X}
X
Xchar *
XcolorLongname(color)
Xchar *color; /* the color code */
X{
X Cinfo *p;
X
X (void)colorPixel(color); /* load it if not already loaded */
X for (p=colorinfo; p; p=p->next) {
X if (strcmp(p->name,color)==0)
X return p->longname;
X }
X return "<no translation>"; /* should never happen */
X}
X
XdumpColors()
X{
X Cinfo *p;
X
X for (p=colorinfo; p; p=p->next) {
X (void)printf("%s: %s\n", p->name, p->longname);
X }
X}
X
X/* end */
END_OF_color.c
if test 2120 -ne `wc -c <color.c`; then
echo shar: \"color.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f draw.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"draw.c\"
else
echo shar: Extracting \"draw.c\" \(6669 characters\)
sed "s/^X//" >draw.c <<'END_OF_draw.c'
X/* draw.c - the routines which actually do the tartan drawing
X * by Jim McBeath (jimmc at hisoft.uucp)
X *
X * 7.Jan.88 jimmc Initial definition (X10)
X * 24.Oct.89 jimmc Convert to X11, Xt; general restructuring
X */
X
X#include <X11/Intrinsic.h>
X#include <stdio.h>
X#include "tartan.h"
X
Xextern TartanInfo *curtartan;
Xextern Display *TDisplay;
Xextern Screen *TScreen;
Xextern Drawable TDrawable;
Xextern Window TWindow;
Xextern GC Tgc;
X
Xstatic int scale;
Xstatic int lwidth;
Xstatic int drwheight;
X
XsetScaleWidth(s,w)
Xint s,w;
X{
X scale = s;
X lwidth = w;
X}
X
XchangeScale(s)
Xchar *s;
X{
X int newscale;
X
X if (s[0]=='+')
X newscale = scale + atoi(s+1);
X else if (s[0]=='-')
X newscale = scale - atoi(s+1);
X else
X newscale = atoi(s);
X if (newscale<=0) {
X Bell();
X return;
X }
X scale = newscale;
X redraw();
X
X}
X
Xint getScale() {
X return scale;
X}
X
XchangeWidth(s)
Xchar *s;
X{
X int newlwidth;
X
X if (s[0]=='+')
X newlwidth = lwidth + atoi(s+1);
X else if (s[0]=='-')
X newlwidth = lwidth - atoi(s+1);
X else
X newlwidth = atoi(s);
X if (newlwidth<=0) {
X Bell();
X return;
X }
X lwidth = newlwidth;
X redraw();
X
X}
X
Xint getWidth() {
X return lwidth;
X}
X
XDrawTartan(rx,ry,rw,rh) /* draws the currently selected tartan */
Xint rx,ry,rw,rh; /* region to draw in */
X{
X TartanInfo *ti;
X Sinfo *si;
X int bgpixel;
X
X ti = curtartan;
X if (!ti) return; /* nothing to draw */
X bgpixel = colorPixel(ti->hstripes.slist[0].color);
X FillBox(rx,ry,rw,rh,bgpixel,SOLID);
X /* fill region with background */
X si = &(ti->hstripes); /* do the horizontal stripes */
X FillStripes(ry,rh,rx,rw,si,0);
X si = &(ti->vstripes); /* do the vertical stripes */
X if (si->flags & HVSAME)
X si = &(ti->hstripes); /* vertical same as horizontal */
X FillStripes(rx,rw,ry,rh,si,1);
X}
X
XFillStripes(org,size,othorg,othsize,si,vflag)
Xint org,size; /* origin and size in direction of interest */
Xint othorg, othsize; /* origin and size in the other direction */
XSinfo *si; /* the stripe info */
Xint vflag; /* set for vertical stripes, clear for horizontal */
X{
X int corg; /* current x or y origin */
X int n;
X int delta;
X S1info *s1i;
X int sw;
X int sflag;
X int pixel;
X
X corg = 0; /* start at the top/left of the screen */
X n = 0; /* start with the first stripe */
X delta = 1;
X sflag = vflag?HSTRIPE:VSTRIPE;
X while (corg<org+size) { /* repeat the pattern */
X s1i = si->slist+n;
X sw = s1i->width*scale;
X if (corg+sw>=org) {
X pixel = colorPixel(s1i->color);
X if (vflag) {
X FillBox(corg,othorg,sw,othsize,
X pixel, s1i->style|sflag);
X } else {
X FillBox(othorg,corg,othsize,sw,
X pixel, s1i->style|sflag);
X }
X /* fill the area with the proper pattern */
X }
X corg += sw;
X n += delta;
X if (n<0) { /* from counting backwards */
X n = 1;
X delta = 1;
X }
X else if (!si->slist[n].color) { /* if at the end... */
X if (si->flags & SYM) {
X if (si->flags & PIVOT2)
X n -= 3; /* double-pivot */
X else
X n -= 2; /* single-pivot (normal) */
X delta = -1; /* count backwards */
X }
X else n=0; /* wrap on overflow */
X }
X }
X}
X
XFillBox(x,y,w,h,pixel,style)
Xint x,y; /* origin of box, (0,0) is lower left */
Xint w,h; /* size of box */
Xint pixel; /* pixel value to use */
Xint style; /* what style to draw in */
X{
X int nstyle;
X int offset;
X int d;
X int cx, cy;
X int x0,y0,x1,y1;
X int lw;
X int q=0;
X
X XSetForeground(TDisplay,Tgc,pixel);
X y = drwheight-h-y; /* change to X screen coords */
X offset = (style&HSTRIPE)?1:0;
X if (offset)
X w+=lwidth;
X nstyle = style & ~(HSTRIPE|VSTRIPE);
X if (!nstyle)
X nstyle = ALINES; /* default style */
X switch (nstyle) {
X case RLINES: /* same direction as length of stripe */
X nstyle = (style&HSTRIPE)?HLINES:VLINES;
X break;
X case NOP:
X return; /* no nothing */
X default:
X break;
X }
X switch (nstyle) {
X case SOLID:
X XFillRectangle(TDisplay,TDrawable,Tgc,x,y,w,h);
X break;
X case HLINES:
X cy = (y+lwidth-1)/lwidth;
X cy -= offset^(cy&1);
X cy *= lwidth;
X XSetLineAttributes(TDisplay,Tgc,lwidth==1?0:lwidth,0,0,0);
X for (; cy<y+h; cy+=2*lwidth) {
X XDrawLine(TDisplay,TDrawable,Tgc,x,cy,x+w-1,cy);
X }
X break;
X case VLINES:
X cx = (x+lwidth-1)/lwidth;
X cx -= offset^(cx&1);
X cx *= lwidth;
X XSetLineAttributes(TDisplay,Tgc,lwidth==1?0:lwidth,0,0,0);
X for (; cx<x+w; cx+=2*lwidth) {
X XDrawLine(TDisplay,TDrawable,Tgc,cx,y,cx,y+h-1);
X }
X break;
X case ALINES:
X cx = (x+y+lwidth-1)/lwidth;
X d = -(offset^(cx&1));
X d *= lwidth;
X d += lwidth-1-((x+y+lwidth-1)%lwidth);
X lw = (int)(0.8*((float)(lwidth)));
X XSetLineAttributes(TDisplay,Tgc,lw<=1?0:lw,0,0,0);
X for (; d<w+h-1; d+=2*lwidth) {
X if (d<w) {
X x0 = x+d;
X y0 = y;
X } else {
X x0 = x+(w-q);
X y0 = y+d-(w-q);
X }
X if (d<h) {
X x1 = x;
X y1 = y+d;
X } else {
X x1 = x+d-(h-q);
X y1 = y+(h-q);
X }
X XDrawLine(TDisplay,TDrawable,Tgc,x0,y0,x1,y1);
X }
X break;
X default:
X break; /* should never get here */
X }
X}
X
XtartanSize(si)
XSinfo *si;
X{
X S1info *s1i;
X int w;
X
X s1i = si->slist;
X w = 0;
X while (s1i->color) {
X w += s1i->width*scale;
X s1i++;
X }
X if (si->flags & SYM) {
X w *= 2;
X s1i--; /* back up to last entry */
X w -= s1i->width*scale; /* it doesn't get doubled */
X s1i = si->slist; /* first entry */
X w -= s1i->width*scale; /* it doesn't get doubled */
X }
X return w;
X}
X
X/* the redraw function creates a pixmap, draws the tartan into it, and
X * makes that the window background pixmap.
X * When we draw into a pixmap, we have to draw a larger area and then
X * use the inside of it to avoid edge effects on the line drawing.
X * The constant K indicates how much larger the area is.
X */
Xredraw()
X{
X#define K 20 /* kludge factor */
X int w,h;
X int d;
X TartanInfo *ti;
X Sinfo *si;
X Pixmap newpix;
X Pixmap newpixK;
X Pixmap oldpix;
X
X d = DefaultDepthOfScreen(TScreen);
X ti = curtartan;
X if (!ti) return;
X si = &(ti->hstripes); /* do the horizontal stripes */
X h = tartanSize(si);
X si = &(ti->vstripes); /* do vertical stripes */
X if (si->flags & HVSAME)
X w = h;
X else
X w = tartanSize(si);
X newpix = XCreatePixmap(TDisplay,TWindow,w,h,d);
X if (!newpix) {
X Warn("error creating new pixmap");
X return;
X }
X newpixK = XCreatePixmap(TDisplay,TWindow,w+K,h+K,d);
X if (!newpix) {
X Warn("error creating new pixmap");
X return;
X }
X drwheight = h+K;
X oldpix = TDrawable;
X TDrawable = newpixK;
X DrawTartan(0,0,w+K,h+K);
X XSetFunction(TDisplay,Tgc,GXcopy);
X XSetPlaneMask(TDisplay,Tgc,AllPlanes);
X XCopyArea(TDisplay,newpixK,newpix,Tgc,K/2,K/2,w+K,h+K,0,0);
X /* copy center portion into new pixmap */
X XSetWindowBackgroundPixmap(TDisplay,TWindow,newpix);
X XClearWindow(TDisplay,TWindow); /* put up the new background */
X XFreePixmap(TDisplay,newpixK);
X if (oldpix)
X XFreePixmap(TDisplay,oldpix);
X TDrawable = newpix; /* for possible use by setrootbg */
X}
X
X/* end */
END_OF_draw.c
if test 6669 -ne `wc -c <draw.c`; then
echo shar: \"draw.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f main.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"main.c\"
else
echo shar: Extracting \"main.c\" \(5648 characters\)
sed "s/^X//" >main.c <<'END_OF_main.c'
X/* main.c - main module for xtartan
X * by Jim McBeath (jimmc at hisoft.uucp, jimmc at netcom.com)
X *
X * 7.Jan.88 jimmc Initial definition (X10)
X * 24.Oct.89 jimmc Convert to X11, Xt; general restructuring
X * 9.Jan.91 jimmc V2.0: use XTartan resource file
X */
X
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/Xatom.h>
X#include <stdio.h>
X#include "patchlevel.h"
X
Xextern char *strrchr();
X
Xchar *Progname;
XDisplay *TDisplay;
XScreen *TScreen;
XGC Tgc;
XColormap TColormap;
XWindow TWindow, TRootWindow;
XXtAppContext TAppCtx;
XWidget TTopWidget;
XDrawable TDrawable;
Xchar *NamePattern;
Xchar *SettPattern;
X
X#include "tartcursor.h" /* define our cursor */
X
Xstatic char *version=VERSION; /* from patchlevel.h */
X
Xtypedef struct rinfo {
X Bool useroot;
X int scale;
X int lwidth;
X char *tartanname;
X char *action;
X char *namepattern;
X char *settpattern;
X} RInfo, *RInfoPtr;
XRInfo Rdata;
X
Xstatic XrmOptionDescRec options[] = {
X {"-draw", "action", XrmoptionNoArg, "draw"},
X {"-list", "action", XrmoptionNoArg, "list"},
X {"-print", "action", XrmoptionNoArg, "print"},
X {"-version", "action", XrmoptionNoArg, "version"},
X {"-r", "useRoot", XrmoptionNoArg, "TRUE" },
X {"-s", "scale", XrmoptionSepArg, NULL },
X {"-t", "tartan", XrmoptionSepArg, NULL },
X {"-w", "lineWidth", XrmoptionSepArg, NULL },
X {"-np", "namePattern", XrmoptionSepArg, NULL },
X {"-sp", "settPattern", XrmoptionSepArg, NULL },
X};
X
Xstatic XtResource resources[] = {
X {"action", "Action", XtRString, sizeof(String),
X XtOffset(RInfoPtr,action), XtRString, "draw"},
X {"lineWidth", "LineWidth", XtRInt, sizeof(int),
X XtOffset(RInfoPtr,lwidth), XtRImmediate, (caddr_t)1},
X {"scale", "Scale", XtRInt, sizeof(int),
X XtOffset(RInfoPtr,scale), XtRImmediate, (caddr_t)2},
X {"tartan", "Tartan", XtRString, sizeof(String),
X XtOffset(RInfoPtr,tartanname), XtRString, "MacBeth"},
X {"useRoot", "UseRoot", XtRBool, sizeof(Bool),
X XtOffset(RInfoPtr,useroot), XtRBool, 0},
X {"namePattern", "NamePattern", XtRString, sizeof(String),
X XtOffset(RInfoPtr,namepattern), XtRString, ""},
X {"settPattern", "SettPattern", XtRString, sizeof(String),
X XtOffset(RInfoPtr,settpattern), XtRString, ""},
X};
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X char buf[1000];
X
X Progname = strrchr(argv[0],'/');
X if (Progname) Progname++;
X else Progname=argv[0];
X
X TTopWidget = XtInitialize(Progname,"XTartan",options,XtNumber(options),
X &argc,argv);
X if (argc!=1) Usage(1);
X TDisplay = XtDisplay(TTopWidget);
X TAppCtx = XtWidgetToApplicationContext(TTopWidget);
X initActions(TAppCtx);
X
X XtGetApplicationResources(TTopWidget,(char *)&Rdata,
X resources,XtNumber(resources),(ArgList)NULL,(Cardinal)0);
X
X NamePattern = Rdata.namepattern;
X SettPattern = Rdata.settpattern;
X
X readTartans(); /* load up all the tartan info */
X
X if (!anyTartanMatches()) {
X Fatal("No tartans matching specified patterns\n");
X exit(1);
X }
X
X if (!setTartan(Rdata.tartanname)) {
X Warn("Can't find tartan %s",Rdata.tartanname);
X ListTartans();
X exit(1);
X }
X setScaleWidth(Rdata.scale,Rdata.lwidth);
X
X if (strcmp(Rdata.action,"version")==0) {
X (void)printf("%s\n",version);
X exit(0);
X }
X
X if (strcmp(Rdata.action,"list")==0) {
X ListTartans();
X exit(0);
X }
X
X if (strcmp(Rdata.action,"print")==0) {
X PrintTartan();
X exit(0);
X }
X
X if (strcmp(Rdata.action,"draw")!=0) {
X Fatal("Bad action %s",Rdata.action);
X }
X
X (void)sprintf(buf,"%s %s",Progname,Rdata.tartanname);
X initDisplay(TTopWidget,buf,Rdata.useroot);
X
X (void)setTartan(""); /* update now that we have the window */
X
X if (Rdata.useroot) {
X setrootbg(TDisplay,TScreen,TRootWindow,TDrawable);
X } else {
X /* for non-root window, let user enter commands */
X XtAppMainLoop(TAppCtx);
X /* NOTREACHED */
X }
X XCloseDisplay(TDisplay);
X exit(0);
X}
X
Xstatic
XinitDisplay(top,winname,rflag)
XWidget top;
Xchar *winname;
Xint rflag;
X{
X Pixmap bm,mbm;
X Cursor tart_cursor;
X XColor fgc, bgc;
X
X
X TScreen = DefaultScreenOfDisplay(TDisplay);
X TColormap = DefaultColormapOfScreen(TScreen);
X Tgc = DefaultGCOfScreen(TScreen);
X TRootWindow = DefaultRootWindow(TDisplay);
X if (rflag) {
X TWindow = TRootWindow;
X return;
X }
X XtSetMappedWhenManaged(top,0);
X XtRealizeWidget(top);
X TWindow = XtWindow(top);
X XStoreName(TDisplay,TWindow,winname);
X bm = XCreateBitmapFromData(TDisplay,TWindow,tartcursor_bits,
X tartcursor_width,tartcursor_height);
X mbm = XCreateBitmapFromData(TDisplay,TWindow,tartmask_bits,
X tartmask_width,tartmask_height);
X fgc.pixel = BlackPixelOfScreen(TScreen);
X bgc.pixel = WhitePixelOfScreen(TScreen);
X XQueryColor(TDisplay,TColormap,&fgc);
X XQueryColor(TDisplay,TColormap,&bgc);
X tart_cursor = XCreatePixmapCursor(TDisplay,bm,mbm,&fgc,&bgc,
X tartcursor_x_hot,tartcursor_y_hot);
X if (!tart_cursor) Warn("can't make cursor");
X else XDefineCursor(TDisplay,TWindow,tart_cursor);
X XtMapWidget(top);
X XtSetMappedWhenManaged(top,1);
X}
X
XUsage(x)
Xint x; /* exit code (-1 means return) */
X{
X (void)printf("usage: %s [-draw] [-list] [-print] [std Xt args]\n\
X[-r] [-s scale] [-t tartanname] [-w linewidth]\n\
X[-np namepattern] [-sp settpattern]\n",
X Progname);
X (void)printf("-draw draw the specified tartan (default)\n");
X (void)printf("-list print a list of available tartans\n");
X (void)printf("-print print out info about the specified tartan\n");
X (void)printf("-r use root window\n");
X (void)printf("-s provide an expansion scale factor\n");
X (void)printf("-t specify the tartan name to use\n");
X (void)printf("-w provide a line width factor\n");
X (void)printf("-np use only tartans with specified pattern in name\n");
X (void)printf("-sp use only tartans with specified pattern in sett\n");
X if (x<0) return;
X exit(x);
X}
X
X/* end */
END_OF_main.c
if test 5648 -ne `wc -c <main.c`; then
echo shar: \"main.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f misc.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"misc.c\"
else
echo shar: Extracting \"misc.c\" \(2139 characters\)
sed "s/^X//" >misc.c <<'END_OF_misc.c'
X/* misc.c - miscellaneous functions for xtartan
X * by Jim McBeath (jimmc at hisoft.uucp)
X *
X * 7.Jan.88 jimmc Initial definition (X10)
X * 24.Oct.89 jimmc Convert to X11, Xt; general restructuring
X * 9.Jan.91 jimmc v2.0: Split out tartan data stuff to tartan.c
X */
X
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <stdio.h>
X#include <varargs.h>
X
Xextern char *Progname;
Xextern Display *TDisplay;
X
XBell()
X{
X XBell(TDisplay,0);
X}
X
X/* VARARGS1 - like printf */
XWarn(va_alist) /* print message */
Xva_dcl
X{
X va_list pvar;
X char *fmt;
X
X va_start(pvar);
X fmt = va_arg(pvar,char *);
X (void)fprintf(stderr,"%s: ",Progname);
X (void)vfprintf(stderr,fmt,pvar);
X (void)fprintf(stderr,"\n");
X va_end(pvar);
X}
X
X/* VARARGS1 - like printf */
XFatal(va_alist) /* print message and exit */
Xva_dcl
X{
X va_list pvar;
X char *fmt;
X
X va_start(pvar);
X fmt = va_arg(pvar,char *);
X (void)fprintf(stderr,"%s: ",Progname);
X (void)vfprintf(stderr,fmt,pvar);
X (void)fprintf(stderr,"\n");
X va_end(pvar);
X exit(1);
X}
X
Xchar *
XGetSubResource(widget,sub,name)
XWidget widget;
Xchar *sub, *name;
X{
X String string;
X static XtResource resources[] = {
X { "", "", XtRString, sizeof(String),
X 0, XtRString, NULL},
X };
X XtResource *tresource;
X
X tresource = (XtResource *)XtMalloc(sizeof(resources));
X tresource[0] = resources[0];
X tresource->resource_name = name;
X tresource->resource_class = name;
X XtGetSubresources(widget, &string, sub, sub,
X tresource, (Cardinal)1, (ArgList)NULL, (Cardinal)0 );
X XtFree((char *)tresource);
X return string;
X}
X
XString
XGetStringResource(widget, resourcename)
XWidget widget;
Xchar *resourcename; /* what to look up in the file */
X{
X String string;
X static XtResource resources[] = {
X { "", "", XtRString, sizeof(String),
X 0, XtRString, (caddr_t)NULL}
X };
X XtResource *tresource;
X
X tresource = (XtResource *)XtMalloc(sizeof(resources));
X tresource[0] = resources[0];
X tresource->resource_name = resourcename;
X tresource->resource_class = resourcename;
X XtGetApplicationResources( widget, &string,
X tresource, (Cardinal)1, (ArgList)NULL, (Cardinal)0 );
X XtFree((char *)tresource);
X return string;
X}
X
X/* end */
END_OF_misc.c
if test 2139 -ne `wc -c <misc.c`; then
echo shar: \"misc.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f setrootbg.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"setrootbg.c\"
else
echo shar: Extracting \"setrootbg.c\" \(1339 characters\)
sed "s/^X//" >setrootbg.c <<'END_OF_setrootbg.c'
X/* setrootbg.c - makes the current root background permanent.
X * A modularized version of the function from the xsetroot program.
X *
X * 24.Oct.89 jimmc Initial definition (borrowed from xsetroot)
X * 9.Jan.91 jimmc Pass dpy info as args instead of globals
X */
X
X#include <X11/Xlib.h>
X#include <X11/Xatom.h>
X
X#define Dynamic 1
X
Xsetrootbg(TDisplay,TScreen,TRootWindow,TDrawable)
XDisplay *TDisplay;
XScreen *TScreen;
XWindow TRootWindow;
XDrawable TDrawable;
X{
X Atom prop,type;
X int format;
X unsigned long length,after;
X unsigned char *data;
X
X /* for root window, get rid of old root pixmap and colors
X * and save new pixmap and colors.
X * (this code borrowed from xsetroot)
X */
X if (DefaultVisualOfScreen(TScreen)->class & Dynamic) {
X prop = XInternAtom(TDisplay,"_XSETROOT_ID",False);
X XGetWindowProperty(TDisplay,TRootWindow,prop,0L,1L,True,
X AnyPropertyType,
X &type,&format,&length,&after,&data);
X if ((type == XA_PIXMAP) && (format == 32) &&
X (length == 1) && (after == 0))
X XKillClient(TDisplay, *((Pixmap *)data));
X /* zap old colors */
X else if (type != None)
X Warn("_XSETROOT_ID property is garbage");
X /* save colors used in pixmap */
X XChangeProperty(TDisplay,TRootWindow,prop,XA_PIXMAP,32,
X PropModeReplace,(unsigned char *)&TDrawable,1);
X XSetCloseDownMode(TDisplay, RetainPermanent);
X }
X}
X
X/* end */
END_OF_setrootbg.c
if test 1339 -ne `wc -c <setrootbg.c`; then
echo shar: \"setrootbg.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f tartan.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"tartan.c\"
else
echo shar: Extracting \"tartan.c\" \(7784 characters\)
sed "s/^X//" >tartan.c <<'END_OF_tartan.c'
X/* tartan.c - tartan data functions
X * by Jim McBeath (jimmc at hisoft.uucp)
X *
X * 9.Jan.91 jimmc v2.0: Split out from misc.c
X */
X
X#include <X11/Intrinsic.h>
X#include <stdio.h>
X#include <ctype.h>
X#include "tartan.h"
X
Xextern char *GetStringResource();
Xextern char *GetSubResource();
X
Xextern char *Progname;
Xextern Display *TDisplay;
Xextern Window TWindow;
Xextern Widget TTopWidget;
Xextern char *NamePattern;
Xextern char *SettPattern;
X
XTartanInfo *firsttartan, *lasttartan;
XTartanInfo *curtartan;
Xchar *TartanName;
Xchar *TartanSett;
XS1info zaps1info = {0};
X
Xstatic
Xchar *
Xfindsubstr(sub,main)
Xchar *sub;
Xchar *main;
X{
X int sl, ml;
X char *m;
X
X sl = strlen(sub);
X ml = strlen(main);
X m = main;
X while (sl<=ml) {
X if (strncmp(m,sub,sl)==0)
X return m;
X m++; ml--;
X }
X return (char *)0;
X}
X
Xstatic
Xint
XtartanMatches(p)
XTartanInfo *p;
X{
X if (NamePattern && *NamePattern) {
X if (!findsubstr(NamePattern,p->name))
X return 0; /* name does not match */
X }
X if (SettPattern && *SettPattern) {
X if (!findsubstr(SettPattern,p->sett))
X return 0; /* sett does not match */
X }
X return 1; /* matches */
X}
X
Xint
XanyTartanMatches()
X{
X TartanInfo *p;
X
X for (p=firsttartan; p; p=p->next) {
X if (tartanMatches(p))
X return 1;
X }
X return 0; /* none of the tartans match the patterns */
X}
X
Xstatic TartanInfo *
XfindTartan(name)
Xchar *name;
X{
X TartanInfo *p;
X
X for (p=firsttartan; p; p=p->next) {
X if (strcmp(p->name,name)==0)
X return p;
X }
X return (TartanInfo *)0;
X}
X
Xstatic char *tbuf;
Xstatic int tbufsize;
X
Xint /* 1 if we found the tartan, 0 if can't do it */
XsetTartan(name)
Xchar *name;
X{
X int l;
X TartanInfo *p;
X
X if (!curtartan) {
X if (!firsttartan) {
X Bell();
X return 0;
X }
X curtartan = firsttartan;
X }
X if (strcmp(name,"")==0) {
X /* no change to current tartan - just update */
X }
X else if (strcmp(name,"+")==0) {
X /* move to next tartan */
X curtartan = curtartan->next;
X if (!curtartan)
X curtartan = firsttartan;
X while (!tartanMatches(curtartan)) {
X curtartan = curtartan->next;
X if (!curtartan)
X curtartan = firsttartan;
X }
X }
X else if (strcmp(name,"-")==0) {
X /* move to previous tartan */
X curtartan = curtartan->prev;
X if (!curtartan)
X curtartan = lasttartan;
X while (!tartanMatches(curtartan)) {
X curtartan = curtartan->prev;
X if (!curtartan)
X curtartan = lasttartan;
X }
X }
X else if (strcmp(name,"0")==0) {
X /* move to first tartan in list */
X curtartan = firsttartan;
X while (!tartanMatches(curtartan)) {
X curtartan = curtartan->next;
X if (!curtartan)
X curtartan = firsttartan;
X }
X }
X else {
X /* move to named tartan */
X p = findTartan(name);
X if (!p) {
X Bell();
X return 0;
X }
X curtartan = p;
X }
X TartanName = curtartan->name;
X TartanSett = curtartan->sett;
X parseTartan();
X
X if (!TWindow) return 1;
X
X l = strlen(Progname)+strlen(TartanName)+2;
X if (l>tbufsize) {
X tbufsize = l;
X if (tbuf) free(tbuf);
X tbuf = XtMalloc(tbufsize);
X }
X (void)sprintf(tbuf,"%s %s",Progname,TartanName);
X redraw();
X XStoreName(TDisplay,TWindow,tbuf);
X return 1;
X}
X
XListTartans()
X{
X TartanInfo *p;
X int l,d;
X
X (void)printf("Known tartans are:\n");
X l = 0;
X for (p=firsttartan; p; p=p->next) {
X if (!tartanMatches(p)) continue;
X d = strlen(p->name)+1;
X if (l+d>=80) {
X (void)printf("\n");
X l = 0;
X }
X (void)printf(" %s",p->name);
X l += d;
X }
X (void)printf("\n");
X}
X
XPrintTartan()
X{
X if (!curtartan) {
X (void)printf("No tartan selected\n");
X return;
X }
X (void)printf("Name: %s\n", curtartan->name);
X (void)printf("Sett: %s\n", curtartan->sett);
X}
X
XPrintSett()
X{
X if (!curtartan) {
X (void)printf("No tartan selected\n");
X return;
X }
X (void)printf("%s: %s\n", curtartan->name, curtartan->sett);
X (void)printf("Color translations:\n");
X PrintStripeColors(&(curtartan->hstripes),(Sinfo *)0);
X if (!(curtartan->vstripes.flags & HVSAME))
X PrintStripeColors(&(curtartan->vstripes),&(curtartan->hstripes));
X}
X
Xint
XIsInStripeList(sinfo,n,s1i)
XSinfo *sinfo;
Xint n;
XS1info *s1i;
X{
X int i;
X
X if (!sinfo) return 0;
X for (i=0; sinfo->slist[i].color && (i<n || n<0); i++) {
X if (strcmp(sinfo->slist[i].color,s1i->color)==0)
X return 1;
X }
X return 0;
X}
X
XPrintStripeColors(sinfo, refsinfo)
XSinfo *sinfo;
XSinfo *refsinfo;
X{
X int i;
X S1info *s1i;
X char *color;
X char *colorLongname();
X
X for (i=0; sinfo->slist[i].color; i++) {
X s1i = sinfo->slist+i;
X if (IsInStripeList(sinfo,i,sinfo->slist+i))
X continue;
X if (IsInStripeList(refsinfo,-1,sinfo->slist+i))
X continue;
X color = s1i->color;
X (void)printf(" %s: %s\n",color,colorLongname(color));
X }
X}
X
XDumpTartans()
X{
X TartanInfo *p;
X
X for (p=firsttartan; p; p=p->next) {
X (void)printf("%s: %s\n",p->name, p->sett);
X }
X}
X
XaddTartan(name,sett)
Xchar *name;
Xchar *sett;
X{
X TartanInfo *p;
X
X p = (TartanInfo *)XtCalloc(1,sizeof(TartanInfo));
X p->name = name;
X p->sett = sett;
X p->next = (TartanInfo *)0;
X if (firsttartan) {
X lasttartan->next = p;
X p->prev = lasttartan;
X lasttartan = p;
X } else {
X firsttartan = lasttartan = p;
X p->prev = (TartanInfo *)0;
X }
X}
X
XreadTartans()
X{
X char *name;
X char *sett;
X
X name = GetStringResource(TTopWidget,"firstTartan");
X if (!name) {
X Warn("No firstTartan resource specified - no tartans loaded");
X return;
X }
X while (name) {
X sett = GetSubResource(TTopWidget,name,"sett");
X if (sett) {
X addTartan(name,sett);
X } else {
X Warn("No sett resource for tartan %s",name);
X }
X name = GetSubResource(TTopWidget,name,"nextTartan");
X }
X}
X
Xstatic S1info *sbuf;
Xstatic int sbufcount, sbufalloc;
X
X/* parses the sett string in the current tartan */
XparseTartan()
X{
X char *s;
X char ccbuf[100]; /* color code */
X char *p;
X int n;
X int size;
X int bflag=0;
X Sinfo *stripes;
X
X if (!curtartan) return;
X if (curtartan->isparsed) return;
X /* set up defaults */
X curtartan->hstripes.flags = SYM;
X curtartan->vstripes.flags = HVSAME;
X stripes = &(curtartan->hstripes);
X s = curtartan->sett;
X sbufcount = 0;
X while (*s) {
X while (isspace(*s)) s++;
X if (!*s) break;
X if (*s=='(') { /* look for comments */
X while (*s && *s!=')') s++; /* skip to end */
X if (*s==')') s++;
X /* can't use close paren in a comment */
X continue;
X }
X if (*s=='%') { /* look for specials */
X s++;
X switch (*s) {
X case 'a': /* asymmetric */
X stripes->flags &= ~SYM;
X break;
X case 'b': /* halve all thread counts */
X bflag = 1;
X break;
X case 'p': /* double-pivot */
X stripes->flags |= PIVOT2;
X break;
X case 'v': /* done with horiz, now comes vert */
X size = (sbufcount+1)*sizeof(S1info);
X stripes->slist = (S1info *)XtMalloc(size);
X bcopy((char *)sbuf,(char *)(stripes->slist),
X size);
X stripes->slist[sbufcount].color = (char *)0;
X stripes = &(curtartan->vstripes);
X stripes->flags = SYM;
X sbufcount = 0;
X break;
X default:
X Warn("Unknown % code %c in sett for %s",
X *s, curtartan->name);
X break;
X }
X s++; /* skip over flag */
X continue; /* back to start of while loop */
X }
X if (!isalpha(*s)) {
X Warn("Bad character %c in sett string for %s",
X *s, curtartan->name);
X s++;
X continue;
X }
X p = ccbuf;
X while (isalpha(*s)) *p++ = *s++;
X *p = 0;
X while (isspace(*s)) s++;
X if (!*s) break;
X n = 0;
X while (isdigit(*s)) n = n*10 + (*s++ - '0');
X if (bflag) n = n/2;
X if (sbufcount>=sbufalloc) {
X if (sbufalloc) sbufalloc *= 2;
X else sbufalloc = 15;
X size = sbufalloc * sizeof(S1info);
X if (sbuf) sbuf=(S1info *)XtRealloc((char *)sbuf,size);
X else sbuf=(S1info *)XtMalloc(size);
X }
X sbuf[sbufcount] = zaps1info;
X sbuf[sbufcount].color = XtMalloc(strlen(ccbuf)+1);
X (void)strcpy(sbuf[sbufcount].color,ccbuf);
X sbuf[sbufcount].width = n;
X sbufcount++;
X }
X size = (sbufcount+1)*sizeof(S1info);
X stripes->slist = (S1info *)XtMalloc(size);
X bcopy((char *)sbuf,(char *)(stripes->slist),size);
X stripes->slist[sbufcount].color = (char *)0;
X curtartan->isparsed = 1;
X}
X
X/* end */
END_OF_tartan.c
if test 7784 -ne `wc -c <tartan.c`; then
echo shar: \"tartan.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
--
Dan Heller
------------------------------------------------
O'Reilly && Associates Zyrcom Inc
Senior Writer President
argv at ora.com argv at zipcode.com
More information about the Comp.sources.x
mailing list