home *** CD-ROM | disk | FTP | other *** search
Wrap
Path: uunet!zaphod.mps.ohio-state.edu!mips!msi!dcmartin From: lfernand@ee.ryerson.ca (luis fernandes) Newsgroups: comp.sources.x Subject: v16i044: X abacus, Part03/04 Message-ID: <1992Feb5.145945.20984@msi.com> Date: 5 Feb 92 14:59:45 GMT References: <csx-16i042-xabacus@uunet.UU.NET> Sender: dcmartin@msi.com (David C. Martin - Moderator) Organization: Molecular Simulations, Inc. Lines: 1810 Approved: dcmartin@msi.com Originator: dcmartin@fascet Submitted-by: lfernand@ee.ryerson.ca (luis fernandes) Posting-number: Volume 16, Issue 44 Archive-name: xabacus/part03 # into a shell via "sh file" or similar. To overwrite existing files, # type "sh file -c". # The tool that generated this appeared in the comp.sources.unix newsgroup; # send mail to comp-sources-unix@uunet.uu.net if you want that tool. # If this archive is complete, you will see the following message at the end: # "End of archive 3 (of 4)." # Contents: Lesson1.cmd Makefile XAbacus.ad Xinit.c demo.h icon.bm # main.c resource.h xabacus.man # Wrapped by dcmartin@snoopy on Mon Jan 13 16:06:31 1992 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'Lesson1.cmd' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Lesson1.cmd'\" else echo shar: Extracting \"'Lesson1.cmd'\" \(3689 characters\) sed "s/^X//" >'Lesson1.cmd' <<'END_OF_FILE' X41 X-4 6 4 XLesson 1: Counting from 1 to 20 XThe beads will move at each step with an Xappropriate explanation in this window. XPress Space-bar to Begin X4 6 4 XLesson 1: Counting X1 X XPress Space-bar to Continue X5 6 4 XLesson 1: Counting X2 X XPress Space-bar to Continue X6 6 4 XLesson 1: Counting X3 X XPress Space-bar to Continue X7 6 4 XLesson 1: Counting X4 X XPress Space-bar to Continue X8 6 4 XLesson 1: Counting X5 X(We're not done yet...) XPress Space-bar to Continue X-8 6 4 XLesson 1: Counting XIt gets a bit tricky here. A carry to the upperdeck, and a Xreset of the lower deck will complete counting 5. XPress Space-bar to Continue X1 6 4 XLesson 1: Counting X5 (pending operation) XCarry-over to Upper-deck... XPress Space-bar to Continue X3 6 4 XLesson 1: Counting X5 X...and Reset Lower-deck... XPress Space-bar X-3 6 4 XLesson 1: Counting XThis is 5. In reality, the 5th bead is never moved, the Xcarry-reset operation is performed in one motion. XPress Space-bar to Continue X4 6 4 XLesson 1: Counting X6 X XPress Space-bar to Continue X5 6 4 XLesson 1: Counting X7 X XPress Space-bar to Continue X6 6 4 XLesson 1: Counting X8 X XPress Space-bar to Continue X7 6 4 XLesson 1: Counting X9 X XPress Space-bar to Continue X8 6 4 XLesson 1: Counting X10 X(pending operation) XPress Space-bar to Continue X0 6 4 XLesson 1: Counting X10 (pending operation) XCarry-over to Upper-deck... XPress Space-bar to Continue X3 6 4 XLesson 1: Counting X10 (pending operation) X...Reset Lower-deck... XPress Space-bar to Continue X4 5 4 XLesson 1: Counting X10 XCarry-over to Previous Column XPress Space-bar X2 6 4 XLesson 1: Counting X10 XReset Upper-deck... XPress Space-bar to Continue X-4 5 4 XLesson 1: Counting XCounting 10 was similar to counting 5, with the Xaddition of the extra carry to the Previous Column XPress Space-bar to Continue X4 6 4 XLesson 1: Counting X11 X XPress Space-bar to Continue X5 6 4 XLesson 1: Counting X12 X XPress Space-bar to Continue X6 6 4 XLesson 1: Counting X13 X XPress Space-bar to Continue X7 6 4 XLesson 1: Counting X14 X XPress Space-bar to Continue X3 6 4 XLesson 1: Counting X15 (pending operation) XReset Bottom-deck... XPress Space-bar to Continue X1 6 4 XLesson 1: Counting X15 X...Carry-over to Upper-deck. XPress Space-bar to Continue X4 6 4 XLesson 1: Counting X16 X XPress Space-bar to Continue X5 6 4 XLesson 1: Counting X17 X XPress Space-bar to Continue X6 6 4 XLesson 1: Counting X18 X XPress Space-bar to Continue X7 6 4 XLesson 1: Counting X19 X XPress Space-bar to Continue X8 6 4 XLesson 1: Counting X20 (pending operation) X XPress Space-bar to Continue X0 6 4 XLesson 1: Counting X20 (pending operation) XCarry-over to the Upper-deck... XPress Space-bar to Continue X3 6 4 XLesson 1: Counting X20 (pending operation) X...Reset Lower-deck... XPress Space-bar to Continue X5 5 4 XLesson 1: Counting X20 (pending operation) X...Carry-over To The Previous Column. XPress Space-bar to Continue X2 6 4 XLesson 1: Counting X20 X...And Reset Upper-deck... XPress Space-bar to Continue X3 5 4 XLesson 1: End XAnd now, some conclusions... X XPress Space-bar to Continue X-7 6 4 XConclusion: XEach of the 2 beads on the upper-deck has a value of 5. XEach of the 5 beads on the lower-deck has a value of 1. XPress Space-bar to Continue X-7 6 4 XConclusion: (continued) XCounting 5 beads on the lower deck requires a carry of X1 bead to the upper-deck. XPress Space-bar to Continue X-7 6 4 XConclusion: (continued) XCounting 2 beads on the upper deck requires a carry of X1 bead on the lower-deck of the previous column. XPress Space-bar X-7 6 4 XConclusion: (continued) XThe 1's column is at the middle of the abacus. Every Xcolumn to the left is an order of magnitude greater. XPress Space-bar X-7 6 4 XConclusion: (End) XColumns to the right of the 1's column are used Xfor calculations involving decimals. XPress Space-bar END_OF_FILE if test 3689 -ne `wc -c <'Lesson1.cmd'`; then echo shar: \"'Lesson1.cmd'\" unpacked with wrong size! fi # end of 'Lesson1.cmd' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(9485 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' X# Makefile generated by imake - do not edit! X# $XConsortium: imake.c,v 1.51 89/12/12 12:37: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# Makefile generated from "Imake.tmpl" and </tmp/IIf.a22422> X# $XConsortium: Imake.tmpl,v 1.77 89/12/18 17:01:37 jim Exp $ X# X# Platform-specific parameters may be set in the appropriate .cf X# configuration files. Site-wide parameters may be set in the file X# site.def. Full rebuilds are recommended if any parameters are changed. 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.cf to change X X# platform: $XConsortium: sun.cf,v 1.38 89/12/23 16:10:10 jim Exp $ X# operating system: SunOS 4.1 X X########################################################################### X# site-specific configuration parameters - edit site.def to change X X# site: $XConsortium: site.def,v 1.21 89/12/06 11:46:50 jim Exp $ X X SHELL = /bin/sh X X TOP = . X CURRENT_DIR = . X X AR = ar cq X BOOTSTRAPCFLAGS = X CC = cc X X COMPRESS = compress X CPP = /lib/cpp $(STD_CPP_DEFINES) X PREPROCESSCMD = cc -E $(STD_CPP_DEFINES) X INSTALL = install X LD = ld X LINT = lint X LINTLIBFLAG = -C X LINTOPTS = -axz X LN = ln -s X MAKE = make X MV = mv X CP = cp X RANLIB = ranlib X RANLIBINSTFLAGS = X RM = rm -f X STD_INCLUDES = X STD_CPP_DEFINES = X STD_DEFINES = X EXTRA_LOAD_FLAGS = X EXTRA_LIBRARIES = X TAGS = ctags X X SHAREDCODEDEF = -DSHAREDCODE X SHLIBDEF = -DSUNSHLIB X X PROTO_DEFINES = X X INSTPGMFLAGS = X X INSTBINFLAGS = -m 0755 X INSTUIDFLAGS = -m 4755 X INSTLIBFLAGS = -m 0664 X INSTINCFLAGS = -m 0444 X INSTMANFLAGS = -m 0444 X INSTDATFLAGS = -m 0444 X INSTKMEMFLAGS = -m 4755 X X DESTDIR = X X TOP_INCLUDES = -I$(INCROOT) X X CDEBUGFLAGS = -O X CCOPTIONS = X COMPATFLAGS = X X ALLINCLUDES = $(STD_INCLUDES) $(TOP_INCLUDES) $(INCLUDES) $(EXTRA_INCLUDES) X ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(PROTO_DEFINES) $(DEFINES) $(COMPATFLAGS) X CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES) X LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES) X LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES) X LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS) X LDCOMBINEFLAGS = -X -r X X MACROFILE = sun.cf X RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut X X IMAKE_DEFINES = X X IRULESRC = $(CONFIGDIR) X IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES) X X ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \ X $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \ X $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES) X X########################################################################### X# X Window System Build Parameters X# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $ X X########################################################################### X# X Window System make variables; this need to be coordinated with rules X# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $ X X PATHSEP = / X USRLIBDIR = $(DESTDIR)/usr/lib X BINDIR = $(DESTDIR)/usr/bin/X11 X INCROOT = $(DESTDIR)/usr/include X BUILDINCROOT = $(TOP) X BUILDINCDIR = $(BUILDINCROOT)/X11 X BUILDINCTOP = .. X INCDIR = $(INCROOT)/X11 X ADMDIR = $(DESTDIR)/usr/adm X LIBDIR = $(USRLIBDIR)/X11 X CONFIGDIR = $(LIBDIR)/config X LINTLIBDIR = $(USRLIBDIR)/lint X X FONTDIR = $(LIBDIR)/fonts X XINITDIR = $(LIBDIR)/xinit X XDMDIR = $(LIBDIR)/xdm X AWMDIR = $(LIBDIR)/awm X TWMDIR = $(LIBDIR)/twm X GWMDIR = $(LIBDIR)/gwm X MANPATH = $(DESTDIR)/usr/man X MANSOURCEPATH = $(MANPATH)/man X MANDIR = $(MANSOURCEPATH)n X LIBMANDIR = $(MANSOURCEPATH)3 X XAPPLOADDIR = $(LIBDIR)/app-defaults X X SOXLIBREV = 4.2 X SOXTREV = 4.0 X SOXAWREV = 4.0 X SOOLDXREV = 4.0 X SOXMUREV = 4.0 X SOXEXTREV = 4.0 X X FONTCFLAGS = -t X X INSTAPPFLAGS = $(INSTDATFLAGS) X X IMAKE = imake X DEPEND = makedepend X RGB = rgb X FONTC = bdftosnf X MKFONTDIR = mkfontdir X MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier.sh X X CONFIGSRC = $(TOP)/config 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 SCRIPTSRC = $(UTILSRC)/scripts X EXAMPLESRC = $(TOP)/examples X CONTRIBSRC = $(TOP)/../contrib X DOCSRC = $(TOP)/doc X RGBSRC = $(TOP)/rgb X DEPENDSRC = $(UTILSRC)/makedepend X IMAKESRC = $(CONFIGSRC) X XAUTHSRC = $(LIBSRC)/Xau X XLIBSRC = $(LIBSRC)/X X XMUSRC = $(LIBSRC)/Xmu X TOOLKITSRC = $(LIBSRC)/Xt X AWIDGETSRC = $(LIBSRC)/Xaw X OLDXLIBSRC = $(LIBSRC)/oldX X XDMCPLIBSRC = $(LIBSRC)/Xdmcp X BDFTOSNFSRC = $(FONTSRC)/bdftosnf X MKFONTDIRSRC = $(FONTSRC)/mkfontdir X EXTENSIONSRC = $(TOP)/extensions X X DEPEXTENSIONLIB = $(USRLIBDIR)/libXext.a X EXTENSIONLIB = -lXext X X DEPXLIB = $(DEPEXTENSIONLIB) X XLIB = $(EXTENSIONLIB) -lX11 X X DEPXAUTHLIB = $(USRLIBDIR)/libXau.a X XAUTHLIB = -lXau X X DEPXMULIB = X XMULIB = -lXmu X X DEPOLDXLIB = X OLDXLIB = -loldX X X DEPXTOOLLIB = X XTOOLLIB = -lXt X X DEPXAWLIB = X XAWLIB = -lXaw X X LINTEXTENSIONLIB = $(USRLIBDIR)/llib-lXext.ln X LINTXLIB = $(USRLIBDIR)/llib-lX11.ln X LINTXMU = $(USRLIBDIR)/llib-lXmu.ln X LINTXTOOL = $(USRLIBDIR)/llib-lXt.ln X LINTXAW = $(USRLIBDIR)/llib-lXaw.ln X X DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB) X X DEPLIBS1 = $(DEPLIBS) X DEPLIBS2 = $(DEPLIBS) X DEPLIBS3 = $(DEPLIBS) X X########################################################################### X# Imake rules for building libraries, programs, scripts, and data files X# rules: $XConsortium: Imake.rules,v 1.67 89/12/18 17:14:15 jim Exp $ X X########################################################################### X# start of Imakefile X X# X# run makedepend for dependancies X# -g enable dbx debugging info; XCDEBUGFLAGS = -g X X#-DDEBUG will '#define DEBUG' statements (trace) X#CDEBUGFLAGS = -DDEBUG X X#Optimize X#CDEBUGFLAGS = -O X X# -lm enables the math lib (needed if you #include <math.h>) X#EXTRA_LOAD_FLAGS = -lm X XSRCS= main.c Xinit.c aba.c demo.c XOBJS= main.o Xinit.o aba.o demo.o X XLOCAL_LIBRARIES = $(XLIB) $(XTOOLLIB) X X PROGRAM = xabacus X Xall:: xabacus X Xxabacus: $(OBJS) $(DEPLIBS) X $(RM) $@ X $(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS) X Xinstall:: xabacus X $(INSTALL) -c $(INSTPGMFLAGS) xabacus $(BINDIR) X Xinstall.man:: xabacus.man X $(INSTALL) -c $(INSTMANFLAGS) xabacus.man $(MANDIR)/xabacus.n X Xdepend:: X $(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS) X Xlint: X $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS) Xlint1: X $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS) X Xclean:: X $(RM) $(PROGRAM) X X# Distribution: Make the shar-files ~no bigger than 64K Xshar: main.c Xinit.c aba.c demo.c Imakefile Makefile README xabacus.man XAbacus.ad icon.bm Lesson1.cmd Lesson2.cmd Lesson3.cmd xabacus.man XAbacus.ad X shar -s 64000 README *.[ch] xabacus.man I* Makefile icon.bm *.cmd XAbacus.ad X# Distribution: split the PS file into 2 files & shar them assuming the source X# can be contained in shar1 & shar2 Xpsshar: abacus.ps X split -2500 abacus.ps abacus.ps X shar -h shar3 abacus.psaa X shar -h shar4 abacus.psab X X# join 2 PS files to create Abacus.ps Xps: X cat abacus.psaa abacus.psab >Abacus.ps X rm -f abacus.ps?? X X########################################################################### X# common rules for all Makefiles - do not edit X Xemptyrule:: X Xclean:: X $(RM_CMD) \#* X XMakefile:: X -@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) -DCURDIR=$(CURRENT_DIR) 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 in $(CURRENT_DIR) done" X Xinstall.man:: X @echo "install.man in $(CURRENT_DIR) done" X XMakefiles:: X Xincludes:: X X########################################################################### X# dependencies generated by makedepend X END_OF_FILE if test 9485 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'XAbacus.ad' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'XAbacus.ad'\" else echo shar: Extracting \"'XAbacus.ad'\" \(275 characters\) sed "s/^X//" >'XAbacus.ad' <<'END_OF_FILE' X!Example resources for xabacus (default, as specified) X!Installation of this file in /usr/lib/X11/app-defaults/ is UNECESSARY X! XXAbacus.beadwidth: 30 XXAbacus.beadheight: 20 XXAbacus.framewidth: 10 XXAbacus.ncols: 13 XXAbacus.demofont: -*-times-*-r-*-*-*-180-* XXAbacus.demo: ./ END_OF_FILE if test 275 -ne `wc -c <'XAbacus.ad'`; then echo shar: \"'XAbacus.ad'\" unpacked with wrong size! fi # end of 'XAbacus.ad' fi if test -f 'Xinit.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Xinit.c'\" else echo shar: Extracting \"'Xinit.c'\" \(8800 characters\) sed "s/^X//" >'Xinit.c' <<'END_OF_FILE' X#include <stdio.h> X#include <X11/cursorfont.h> X X#include "icon.bm" X X#include "main.h" X XPixel getcolor(); XPixel bgcolor, bdcolor; /* background & border*/ X X/*-------------------------------------------------------------------- X * makeWindows, connects to X-server, creates the application windows, X * allocates GC's & sets WM hints, creates cursors & maps windows X * X * passed: argc, argv straight from the commandline X * returns: nothing X * dep: win struct, a bunch of globals; see maindefs.h X */ XmakeWindows(argc, argv, display_name) Xint argc; Xchar **argv; Xchar *display_name; X{ Xunsigned int border_width=1; Xchar *window_name=APPNAME; Xchar *icon_name=APPNAME; X/*char *display_name=NULL;*/ XPixmap icon_pixmap; Xint i; X X#ifdef DEBUG X fprintf(stderr,"DEBUG: makeWIndows()\n"); X#endif X X /* connect to X server */ X if ( (display=XOpenDisplay(display_name)) == NULL ) { X fprintf(stderr,"%s: cannot connect to X server %s\n", argv[0], XXDisplayName(display_name)); X exit( -1 ); X } X X /* get screen size from display structure macro */ X screen = DefaultScreen(display); X X bgcolor=getcolor(colors[BACKGROUND]); X bdcolor=getcolor(BDWINCOLOR); X X /* create opaque window;inherit attributes from root*/ X base= XCreateSimpleWindow(display, RootWindow(display, screen), Xposx, posy, width, height, border_width, bdcolor, bgcolor); X X if(demo){ X demobase=XCreateSimpleWindow(display, RootWindow(display, screen), Xposx, posy, demowidth, demoheight, border_width, bdcolor, bgcolor); X X load_font(&font_info); X } X X /* create separate GC for drawing */ X for(i=0; i<MAXCOLORS; i++) makeGCs(&gc[i], colors[i]); X X /* do special settings*/ X XSetLineAttributes(display, gc[FRAME], framewidth, LineSolid, CapButt, XJoinMiter); /* extra thick lines for the frame*/ X X if(demo) XSetFont(display, gc[FRAME], font_info->fid); X XSetFillStyle(display,gc[BEADS],FillSolid); X XSetFunction(display,gc[BEADS],GXxor); /* so we don't disturb BG while X animating beads*/ X X /* Create bitmap for icon */ X icon_pixmap= XCreateBitmapFromData(display, base, icon_bits, icon_width, Xicon_height); X X if(demo){ X /* Set resize hints */ X size_hints.flags= PPosition | PMinSize | PMaxSize; X size_hints.width= demowidth; X size_hints.height= demoheight; X size_hints.min_width=size_hints.max_width=demowidth; X size_hints.min_height=size_hints.max_height=demoheight; X size_hints.x= posx+10; size_hints.y= posy+10; X X /* set Properties for window manager (always before mapping) */ X XSetStandardProperties(display, demobase, DEMOWINAME, DEMOWINAME, X icon_pixmap, argv, argc, &size_hints); X X /* Select event types wanted */ X XSelectInput(display, demobase, ExposureMask | KeyPressMask | X ButtonPressMask | ButtonReleaseMask); X } X X /* Set resize hints re-using size_hints struct for the base-window*/ X size_hints.flags= PPosition | PSize | PMinSize|PMaxSize; X size_hints.width=size_hints.min_width=width; X size_hints.height= height; X /* the abacus can be made as wide as the screen or MAXCOLS (whichever is X * smaller)*/ X size_hints.max_width=DisplayWidth(display, screen); X /* height is fixed at run-time */ X size_hints.min_height=size_hints.max_height=height; X size_hints.x= posx; size_hints.y= posy; X X /* set Properties for window manager (always before mapping) */ X XSetStandardProperties(display, base, window_name, icon_name, Xicon_pixmap, argv, argc, &size_hints); X X /* Select event types wanted */ X XSelectInput(display, base, ExposureMask | KeyPressMask | ButtonPressMask | XStructureNotifyMask | PointerMotionHintMask | ButtonMotionMask | XButtonReleaseMask); X X /* create & map unique cursor to this window*/ X Hand=XCreateFontCursor(display, XC_hand2); X XDefineCursor(display, base, Hand); X X if (demo) XDefineCursor(display, demobase, Hand); X X XMapWindow(display, base); X if (demo) XMapWindow(display, demobase); X X}/*make Windows*/ X/*----------------------------------------------------------------- X * makeGCs, creates a default GC then sets the color, line & X * font attributes; font must have been loaded before this is called X * X * passed: pointer to GC to be set, X * colorname to set("red","green"...) X * returns: nothing X * dep: XGC values, win, display, getcolor() X */ XmakeGCs(gc, colorname) XGC *gc; Xchar *colorname; X{ Xunsigned long valuemask = 0; /* use defaults*/ XXGCValues values; X X *gc = XCreateGC(display, base, valuemask, &values); /* ...create gc*/ X X /* ...set color & other GC attributes*/ X XSetForeground(display, *gc, getcolor(colorname)); X XSetBackground(display, *gc, getcolor(colors[BACKGROUND])); X XSetLineAttributes(display, *gc, 0, LineSolid, CapButt, JoinMiter); X X}/* makeGCs*/ X X/*------------------------------------------------------------------- X * closeDisplay, de-allocates GC's, fonts & pixmaps, breaks connection with X * X server & de-allocates all data, exits application X * X * passed: nothing X * returns:doesn't return X * dep: globals in maindefs.h X */ X/* ARGSUSED*/ XcloseDisplay() X{ Xint i; X for(i=0; i<MAXCOLORS; i++) XFreeGC(display, gc[i]); X X if (demo) XUnloadFont(display, font_info->fid); X X XFreeCursor(display, Hand); X X XCloseDisplay(display); X X exit(0); X} X X/*------------------------------------------------------------------------ X * getcolor, allocates requested color in the default colormap & returns X * a RGB pixel-value for use in allocating a GC. X * Automatically detects a monochrome display, & assumes X * black-on-white thus returning black instead of requested colors X * & white when requested. X * X * passed: colorname to allocate X * returns: RGB pixel-value encoided in an unsigned long (I'm X * breaking Rule#1 of Xlib programming by accessing X * the individual structure elements rather than X * using correct types (Pixel is defined for Xt only)) X * dep: nothing X */ Xunsigned long getcolor(colorname) Xchar *colorname; X{ Xint depth; /* of the screen*/ XColormap cmap; /* for allocating colors*/ XXColor generic; /* hold pixel-values while making different GC's*/ Xint i; X X depth=DisplayPlanes(display, screen); /* is it mono or color*/ X cmap=DefaultColormap(display, screen); X X /* mono screen; ignore colorname; default: black on white */ X if(depth==1){ X if(!strcmp(colorname,"white")) /* user wants white*/ X return(WhitePixel(display, screen)); X else X return(BlackPixel(display, screen)); X } X else{ X X /* parse the color & get pixel values to set color... */ X if(!XParseColor(display, cmap, colorname, &generic)){ X fprintf(stdout,"%s: Bad colorname:%s \n", APPNAME, colorname); X return(BlackPixel(display, screen)); /* send back default*/ X } X X /* allocate color in colormap if space is available*/ X if(!XAllocColor(display, cmap, &generic)){ X fprintf(stdout,"Could not allocate %s, colormap full or \ Xwrite-immune\n",colorname); X return(BlackPixel(display, screen)); X } X X /* color is good*/ X return(generic.pixel); X } X}/* get color*/ X Xload_font(font_info) XXFontStruct **font_info; X{ X /*char *fontname = "-*-times-*-r-*-*-*-180-*";*/ X char *altfontname = "8x13"; X X /* Access font */ X if ((*font_info=XLoadQueryFont(display,demofont)) == NULL) { X (void) fprintf( stderr, "Cannot open %s font\n",demofont); X (void) fprintf( stderr, "Attempting %s font as alternate\n", X altfontname); X X if((*font_info=XLoadQueryFont(display,altfontname)) == NULL) { X (void) fprintf( stderr, "Cannot open %s alternate font\n", X altfontname); X (void) fprintf( stderr, "use the -demofont option to specify a \ Xfont to use\n"); X exit( -1 ); X } X } X} X X/*----------------------------------------------------------------- X * report_button, reports which of the 3 mouse button was pressed X * This implementation is *technically* incorrect, X * I looked-up the type of data the button-event was (unsigned int); X * I don't know how else to do it. X * To maintain portability integrity the user must never directly X * access the data-types! (I just broke this rule) X * -LF X * X * passed: the xevent item with the value of button pressed X * returns: 1- if left-button pressed X * 2- if middle button X * 3- if right button X */ Xint report_button(butn) Xunsigned int butn; X{ X X switch(butn){ X case Button1: X return(1); X X case Button2: X return(2); X X case Button3: X return(3); X }/* switch*/ X X}/* report button*/ X END_OF_FILE if test 8800 -ne `wc -c <'Xinit.c'`; then echo shar: \"'Xinit.c'\" unpacked with wrong size! fi # end of 'Xinit.c' fi if test -f 'demo.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'demo.h'\" else echo shar: Extracting \"'demo.h'\" \(120 characters\) sed "s/^X//" >'demo.h' <<'END_OF_FILE' Xextern drawIntro(); Xextern lesson1(); Xextern lesson2(); Xextern lesson3(); Xextern drawQuery(); Xextern drawDemoWindow(); X END_OF_FILE if test 120 -ne `wc -c <'demo.h'`; then echo shar: \"'demo.h'\" unpacked with wrong size! fi # end of 'demo.h' fi if test -f 'icon.bm' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'icon.bm'\" else echo shar: Extracting \"'icon.bm'\" \(5763 characters\) sed "s/^X//" >'icon.bm' <<'END_OF_FILE' X#define icon_width 100 X#define icon_height 70 Xstatic char icon_bits[] = { X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, X 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, X 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, X 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, X 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, X 0xff, 0xff, 0xff, 0xff, 0x0f, 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, X 0x02, 0x02, 0x02, 0x02, 0x82, 0x0f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, X 0x07, 0x07, 0x07, 0x07, 0x07, 0x87, 0x0f, 0x9f, 0x8f, 0x8f, 0x8f, 0x8f, X 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x0f, 0xdf, 0xdf, 0xdf, 0xdf, X 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0x9f, 0x0f, 0xdf, 0xdf, 0xdf, X 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0x9f, 0x0f, 0xdf, 0xdf, X 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0x9f, 0x0f, 0x9f, X 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x0f, X 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x87, X 0x0f, 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, X 0x82, 0x0f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, X 0x07, 0x87, 0x0f, 0x9f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, X 0x8f, 0x8f, 0x8f, 0x0f, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, X 0xdf, 0xdf, 0xdf, 0x9f, 0x0f, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, X 0xdf, 0xdf, 0xdf, 0xdf, 0x9f, 0x0f, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, X 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0x9f, 0x0f, 0x9f, 0x8f, 0x8f, 0x8f, 0x8f, X 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x0f, 0x1f, 0x07, 0x07, 0x07, X 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x87, 0x0f, 0x1f, 0x02, 0x02, X 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x0f, 0x1f, 0x02, X 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x0f, 0x1f, X 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x0f, X 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, X 0x0f, 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, X 0x82, 0x0f, 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, X 0x02, 0x82, 0x0f, 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, X 0x02, 0x02, 0x82, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, X 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, X 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x1f, 0x02, 0x02, 0x02, X 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x0f, 0x1f, 0x02, 0x02, X 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x0f, 0x1f, 0x02, X 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x0f, 0x1f, X 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x0f, X 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, X 0x0f, 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, X 0x82, 0x0f, 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, X 0x02, 0x82, 0x0f, 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, X 0x02, 0x02, 0x82, 0x0f, 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, X 0x02, 0x02, 0x02, 0x82, 0x0f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, X 0x07, 0x07, 0x07, 0x07, 0x87, 0x0f, 0x9f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, X 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x0f, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, X 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0x9f, 0x0f, 0xdf, 0xdf, 0xdf, 0xdf, X 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0x9f, 0x0f, 0xdf, 0xdf, 0xdf, X 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0x9f, 0x0f, 0x9f, 0x8f, X 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x0f, 0x1f, X 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x87, 0x0f, X 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, X 0x0f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, X 0x87, 0x0f, 0x9f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, X 0x8f, 0x8f, 0x0f, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, X 0xdf, 0xdf, 0x9f, 0x0f, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, X 0xdf, 0xdf, 0xdf, 0x9f, 0x0f, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, X 0xdf, 0xdf, 0xdf, 0xdf, 0x9f, 0x0f, 0x9f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, X 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x0f, 0x1f, 0x07, 0x07, 0x07, 0x07, X 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x87, 0x0f, 0x1f, 0x02, 0x02, 0x02, X 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x0f, 0x1f, 0x07, 0x07, X 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x87, 0x0f, 0x9f, 0x8f, X 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x0f, 0xdf, X 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0x9f, 0x0f, X 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0x9f, X 0x0f, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, X 0x9f, 0x0f, 0x9f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, X 0x8f, 0x8f, 0x0f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, X 0x07, 0x07, 0x87, 0x0f, 0x1f, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, X 0x02, 0x02, 0x02, 0x82, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, X 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f}; END_OF_FILE if test 5763 -ne `wc -c <'icon.bm'`; then echo shar: \"'icon.bm'\" unpacked with wrong size! fi # end of 'icon.bm' fi if test -f 'main.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'main.c'\" else echo shar: Extracting \"'main.c'\" \(12962 characters\) sed "s/^X//" >'main.c' <<'END_OF_FILE' X/* xabacus begun on: Mon Jun 24 14:45:32 EDT 1991 X * by Luis Fernandes X * X * Mon Sep 9 15:36:57 EDT 1991 X * re-doing demo-implementaion from hard-code to script-driven X * trashed SCCS & restarted: base version has all up to -display & q,Q,^c X * modifying -demo option to be folowed by a path to where the scripts are X * X * Mon Oct 7 16:38:39 EDT 1991 X * added ability to override font used in demo from command-line X * X * Mon Nov 11 14:39:17 EST 1991 X * deleted un-used functions in demo.c & added checking for MAXLESSON X * Lesson-1 script modifed to show proper method when carrying X */ X X/* XCopyright (c) 1991, Luis Fernandes. X XPermission to use, copy, hack, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that Xboth that copyright notice and this permission notice appear in Xsupporting documentation. X XThis software is presented as is without any implied or written warranty. X*/ X Xstatic char SccsId[]="@(#)main.c 1.4 11/20/91"; X X#include <stdio.h> X#include <string.h> X#include <X11/StringDefs.h> X#include <X11/Intrinsic.h> X X#include "patchlevel.h" X#include "maindefs.h" X#include "demo.h" X X/* If more "lessons" are added, modify MAXLESSON accordingly. xabacus is X * set-up to wrap-around to the beginning after the last lesson. X */ X#define MAXLESSON 3 X Xextern int democount, br; Xextern char displaytext[4][64]; X Xtypedef unsigned int Column; /* int's MUST be more than 9 bits wide*/ XColumn column[MAXCOLS]; X XDisplay *display; Xint screen; XWindow root, child, base, demobase; XWidget topLevel; Xunsigned int mask; XXSizeHints size_hints; XXFontStruct *font_info; Xunsigned int width=INITWIDTH, demowidth=DEMOINITWIDTH, X height=INITHEIGHT, demoheight=DEMOINITHEIGHT; Xunsigned int posx=INITPOSX, X posy=INITPOSY; /* position of main window */ X XGC gc[MAXCOLORS]; XCursor Hand; XKeySym key; Xchar keytext[KEYBUFFERSIZE]; X X#include "resource.h" X Xint beadwidth; int beadheight; int framewidth; int ncols; XBoolean demo; XBoolean script; X Xint midframey=MIDFRAME; Xint colgap=COLGAP; int rowgap=ROWGAP; X Xchar display_name[COLORSTRLEN<<1]; Xchar colors[MAXCOLORS][COLORSTRLEN]; Xchar demopath[128]; Xchar demofont[128]; XFILE *fp; Xint demorow, democol, demolines, lessonlen; X XWidget TopLevel; /* used only to access the resource manger*/ X Xusage(appname) Xchar *appname; X{ X fprintf (stderr, "%s Release %s\n",appname, RELEASENUM); X fprintf (stderr, "Usage: %s [ options ... ]\nWhere options are:\n",appname); X fprintf (stderr," -display\t name \tdisplay name\n"); X fprintf (stderr," -demo\t path \tpath to script files\n"); X fprintf (stderr," -script\t \t(prints row,col to stdout when beads are \ Xmoved)\n"); X fprintf (stderr," -ncols\t n \tnumber of columns\n"); X fprintf (stderr," -beadwidth\t w \twidth of the beads (in pixels)\n"); X fprintf (stderr,"-beadheight\t h \theight of the beads (in pixels)\n"); X fprintf (stderr,"-framewidth\t w \twidth of the frame (in pixels)\n\n"); X fprintf (stderr,"-framecolor\t color \tcolor-name for the frame\n"); X fprintf (stderr," -bg\t color \tcolor-name for the background \n"); X fprintf (stderr," -beadcolor\t color \tcolor-name for the beads\n"); X fprintf (stderr," -railcolor\t color \tcolor-name for the rails\n\n"); X fprintf (stderr," -help\t print this list\n\n"); X X exit (1); X} X Xmain(argc, argv) Xint argc; Xchar **argv; X{ XXEvent report; X X TopLevel = XtInitialize (NULL, "XAbacus", options, XtNumber (options), X &argc, argv); X X if (argc != 1) usage (argv[0]); X X XtGetApplicationResources (TopLevel, (caddr_t) &app_resources, X resources, XtNumber(resources), X (ArgList) NULL, (Cardinal) 0); X X transferResources(); X makeWindows(argc, argv, display_name); X initAbacus(); X X if(demo) X doDemo(); X else do { /* the main event loop*/ X XNextEvent(display, &report); X } while (TakeEvents(report)); X X}/* main*/ X X/* This function exists for the simple reason that, when the X * code was originally written there were no resources and things would X * certainly get out of hand if I sed'ed all my source replacing all X * occurences of one var with that of another. X * Besides, typing in 'beadwidth' is a lot easier than typing in X * 'app_resources.beadwidth'. (Yes, I'm aware of cpp ) X * X * Also, this is a good place for checking & overriding user-supplied options. X */ XtransferResources() X{ Xint i; X X if(app_resources.demo[0]!=' ') demo=True; X X sprintf(demopath,"%s",app_resources.demo); X X if(app_resources.script==True){ X script=True; X (void)fprintf(stderr,"Scripting Enabled, output to stdout...\n"); X } X X if(demo){ /* use standardized values*/ X strcpy(demofont, app_resources.demofont); X beadwidth=BEADWIDTH; X beadheight=BEADHEIGHT; X framewidth=FRAMEWIDTH; X /* if anything, ncols MUST be overriden to the same number as when the X demo (using -script) was created) */ X ncols=NCOLS; X midframey=MIDFRAME; X height=INITHEIGHT; X width=INITWIDTH; X } X else{ /* acknowledge options */ X beadwidth=app_resources.beadwidth; X beadheight=app_resources.beadheight; X framewidth=app_resources.framewidth; X ncols=app_resources.ncols; X midframey=(framewidth+(NTOPROWS*beadheight)+((NTOPROWS+1)*ROWGAP)); X height=((3*framewidth)+(NROWS*beadheight)+((NROWS+1)*ROWGAP)); X width=((2*framewidth)+(ncols*beadwidth)+((ncols+1)*COLGAP)); X } X X if(app_resources.display[0]==' ' ) X *display_name=NULL; X else X strcpy(display_name, app_resources.display); X X for(i=0; i<MAXCOLORS; i++) X strcpy(colors[i],app_resources.colors[i]); X X}/*transferResources*/ X X X/*----------------------------------------------------------------- X * TakeEvents, the main event loop X * X * passed: XEvent variable returned from XNextEvent X * returns: 1 for every other valid event X * Never returns when the user quits; automatically X * vectored to quit routine X */ X Xint XTakeEvents(report) XXEvent report; X{ Xint cx=0, cy=0; /*pointer-position in window when button pressed*/ Xint window_size=OK; /* OK, or SMALL */ Xint root_x, root_y; /* coodrs of click relative to root*/ Xint keyretval, i; Xstatic int oldwidth; X#ifdef DEBUG X (void)fprintf(stderr," DEBUG TakeEvents:\n"); X#endif X switch (report.type) { X X case Expose: X /* get rid of unecessary Expose events in queue*/ X while (XCheckTypedEvent(display, Expose, &report)); X X if (window_size == SMALL) X fprintf(stderr,"Window is too small"); X else /*refresh all windows */ X drawAbacus(); X X break; X X case ConfigureNotify: X /* when the window is resized, the abacus should be resized X * accordingly; window has been resized, change width */ X oldwidth=width; X width = report.xconfigure.width; X cx=ncols; /* temp */ X /* calc number of new cols to be added */ X ncols=((int)width-oldwidth)/(colgap+beadwidth); X X /* take new value only if it's valid*/ X /*ncols=(ncols<=0)?cx:(width-oldwidth)/(colgap+beadwidth);*/ X if(ncols==0) ncols=cx; X else ncols+=cx; X X /* for bogus/none/retarded WM's*/ X if ((width<size_hints.min_width) || (height<size_hints.min_height)) X window_size = SMALL; X else{ X window_size = OK; X }/* else*/ X break; X X case ButtonPress: X X /* get current coords of pointer*/ X XQueryPointer(display, base, &root, &child, &root_x, &root_y, &cx, &cy, &mask); X X /* row,col returned in cx,cy*/ X i=translateXY2RowCol(&cx,&cy); X X if(i){ /*valid row,col...*/ X if(RowOccupied(cy,column[cx])){ /*& it's occupied...*/ X#ifdef DEBUG X (void)fprintf(stderr," DEBUG:(bead present) col=%4d row=%4d\n", cx, cy); X#endif X X if(script) (void)fprintf(stdout,"%d %d\n",cy,cx); X X animateBead((unsigned)cy,(unsigned)cx); X } X } X else{ X#ifdef DEBUG X (void)fprintf(stderr," DEBUG: INVALID\n"); X#endif X /*XBell(display);*/ X X } X X break; X X case KeyPress: X keyretval=XLookupString(&report, keytext, KEYBUFFERSIZE, &key, 0); X X if(keyretval==1){ /* user pressed 1 key...*/ X if(keytext[0]=='q'||keytext[0]=='Q'||keytext[0]=='\03') X closeDisplay(); X } X X keyretval=0; X break; X X default: X /* all events selected by StructureNotifyMask X * are thrown away here X */ X break; X }/*switch*/ X X X return(1); X X}/*TakeEvents*/ X X/* ------------------------------------------------------------ X * translateXY2RowCol, converts x,y coord returned by XQueryPointer to X * a row,col coord. The top deck has 3 rows (1 is empty), the bottom X * deck has 6 rows (1 is empty). Row # 3 is invalid because the middle-frame X * occupies this position. Coordinates for the bottom deck are adjusted X * for this anomaly, i.e. row #4 on the screen, is actually index #3 X * into the Column array. X * X * passed: (pointers to) absolute x,y coordinates representing X * the click-location X * returns: row (0-9),col (0-NCOLS) index in the same variables passed X * True if click was at any location BUT mid-frame X * False if click was at mid-frame location X */ Xint XtranslateXY2RowCol(cx,cy) Xint *cx, *cy; X{ X X#ifdef DEBUG X (void)fprintf(stderr," DEBUG :%d, %d\n", *cx, *cy); X#endif X X *cx=(*cx-framewidth)/(colgap+beadwidth); X X if(*cy<midframey){ X *cy=(*cy-framewidth)/(rowgap+beadheight); X } X else{ /* account for the middle-frame (+1 bead height (Jun 29 14:50))*/ X *cy=(*cy-(2*framewidth-beadheight))/(rowgap+beadheight); X } X X if(*cy==3) return(0); /* technically, the mid-frame occupies position 3 X * & click is invalid*/ X else if(*cy>2){ /* if pos (row) is greater than 3 ...*/ X (*cy)--; /* ...adjust by 1 row*/ X return(1); X } X else X return(1); X X}/* translateXY2RowCol*/ X X X Xint XdoDemo() X{ XXEvent report; Xint keyretval; X/* when rv=doLesson return's FALSE(lesson is finished) queryrunning=1*/ Xstatic int demorunning, queryrunning; Xstatic int lessoncount; X X#ifdef DEBUG X (void)fprintf(stderr," DEBUG: doDemo()\n"); X#endif X X do{ X XNextEvent(display, &report); X X switch (report.type) { X X case Expose: X /* discard unecessary Expose events in queue*/ X while (XCheckTypedEvent(display, Expose, &report)); X X drawAbacus(); X X if(demorunning) X drawDemoWindow(); X else if(queryrunning) X drawQuery(); X else if(!demorunning) X drawIntro(); X X break; X X case ButtonPress: X demorunning=1; X queryrunning=0; X lessoncount=0; /* begin demo with lesson 1 (count=0)*/ X X initAbacus(); X drawAbacus(); X startLesson(lessoncount); X doLesson(lessoncount); X break; X X case KeyPress: X keyretval=XLookupString(&report, keytext, KEYBUFFERSIZE, &key, 0); X X if(keyretval==1){ /* user pressed a key...*/ X if(keytext[0]=='r'){ X initAbacus(); X drawAbacus(); X startLesson(lessoncount);/* keep the same lesson */ X doLesson(lessoncount); X demorunning=1; X queryrunning=0; X } X else if(keytext[0]=='c'){ X initAbacus(); X drawAbacus(); X X lessoncount++; /* go on to next lesson */ X if(lessoncount>=MAXLESSON) X lessoncount=0; /* wrap-around to beginning*/ X X startLesson(lessoncount); X X doLesson(lessoncount); X demorunning=1; X queryrunning=0; X } X else if(keytext[0]==' '){ X if(!demorunning) break; /* ignore space if waiting*/ X X if( !(doLesson(lessoncount)) ){ X queryrunning=1; X demorunning=0; X } X } X else if(keytext[0]=='q') X closeDisplay(); X } X X keyretval=0; X break; X X default: X /* throw away all other events here */ X break; X X }/* switch*/ X X }while(1); X} X XstartLesson(lc) X{ Xstatic char fname[128]; Xint i; X#if 0 X if(lc>=MAXLESSON) lc=0; /* wrap-around to beginning*/ X#endif X X sprintf(fname,"%s/Lesson%d.cmd",demopath,lc+1); X X if((fp=fopen(fname,"r"))==NULL){ X (void)fprintf(stderr, X "%s: Error Could not open script-file:%s\n",APPNAME,fname); X exit(1); X } X X (void)fscanf(fp,"%d", &lessonlen); X X /*load first instance*/ X (void)fscanf(fp,"%d %d %d\n",&demorow,&democol,&demolines); X X for(i=0; i<demolines; i++){ X fgets(displaytext[i], 64, fp); X displaytext[i][strlen(displaytext[i])-1]='\0'; X } X X} X Xint XdoLesson(lc) X{ Xint i; X X /* A negative value in demorow signifies that only the text is to be X * displayed. X */ X if(lessonlen && demorow>=0) X animateBead((unsigned)demorow, (unsigned)democol); X X drawDemoWindow(); X X /*load first instance*/ X (void)fscanf(fp,"%d %d %d\n",&demorow,&democol,&demolines); X X for(i=0; i<demolines; i++){ X (void)fgets(displaytext[i], 64, fp); X displaytext[i][strlen(displaytext[i])-1]='\0'; X } X X if(--lessonlen>=0) X return(1); /* lines left*/ X else { X fclose(fp); X X strcpy(displaytext[0],"Here Endth The Lesson"); X strcpy(displaytext[1]," "); X strcpy(displaytext[2]," "); strcpy(displaytext[3]," "); X XClearWindow(display,demobase); X drawDemoWindow(); X sleep(1); X drawQuery(); X X return(0); /* lesson over*/ X } X} END_OF_FILE if test 12962 -ne `wc -c <'main.c'`; then echo shar: \"'main.c'\" unpacked with wrong size! fi # end of 'main.c' fi if test -f 'resource.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'resource.h'\" else echo shar: Extracting \"'resource.h'\" \(2283 characters\) sed "s/^X//" >'resource.h' <<'END_OF_FILE' X/* resource.h: X * definitions for the resource & command-line parser for xabaxus. X * Make sure main.h is also modified to reflect changes to resources made in X * this file. X */ X Xstruct _resources { X String display; X int beadwidth; X int beadheight; X int framewidth; X int ncols; X String colors[4]; X String demo; X String demofont; X Boolean script; X} app_resources; X X#define offset(field) XtOffset (struct _resources *, field) X Xstatic XtResource resources[] = { X { "display","Display", XtRString, sizeof(String), X offset(display), XtRString, " "}, X { "beadwidth","Beadwidth",XtRInt, sizeof (int), X offset(beadwidth),XtRString, "30"}, X { "beadheight","Beadheight",XtRInt, sizeof (int), X offset(beadheight),XtRString, "20"}, X { "framewidth","Framewidth",XtRInt, sizeof (int), X offset(framewidth),XtRString, "10"}, X { "ncols","Ncols",XtRInt, sizeof (int), X offset(ncols),XtRString, "13"}, X { "framecolor","Framecolor", XtRString, sizeof(String), X offset(colors[0]), XtRString, "brown"}, X { "bg","Bg", XtRString, sizeof(String), X offset(colors[1]), XtRString, "white"}, X { "beadcolor","Beadcolor", XtRString, sizeof(String), X offset(colors[2]), XtRString, "green4"}, X { "railcolor","Railcolor", XtRString, sizeof(String), X offset(colors[3]), XtRString, "black"}, X { "demo","Demo",XtRString, sizeof(String), X offset(demo), XtRString, " " }, X { "demofont","Demofont",XtRString, sizeof(String), X offset(demofont), XtRString, "-*-times-*-r-*-*-*-180-*-*-*-*" }, X { "script","Script",XtRBoolean, sizeof(Boolean), X offset(script), XtRString, "False" }, X X}; X Xstatic XrmOptionDescRec options[] = { X { "-display","display",XrmoptionSepArg, NULL}, X { "-beadwidth","beadwidth",XrmoptionSepArg, NULL}, X { "-beadheight","beadheight",XrmoptionSepArg, NULL}, X { "-framewidth","framewidth",XrmoptionSepArg, NULL}, X { "-ncols","ncols",XrmoptionSepArg, NULL}, X { "-framecolor","framecolor",XrmoptionSepArg, NULL}, X { "-bg","bg",XrmoptionSepArg, NULL}, X { "-beadcolor","beadcolor",XrmoptionSepArg, NULL}, X { "-railcolor","railcolor",XrmoptionSepArg, NULL}, X { "-demo","demo",XrmoptionSepArg, NULL}, X { "-demofont","demofont", XrmoptionSepArg, NULL}, X { "-fn","demofont", XrmoptionSepArg, NULL}, X { "-script","script",XrmoptionNoArg, (caddr_t)"TRUE"}, X}; X END_OF_FILE if test 2283 -ne `wc -c <'resource.h'`; then echo shar: \"'resource.h'\" unpacked with wrong size! fi # end of 'resource.h' fi if test -f 'xabacus.man' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xabacus.man'\" else echo shar: Extracting \"'xabacus.man'\" \(7566 characters\) sed "s/^X//" >'xabacus.man' <<'END_OF_FILE' X.\" @(#)xabacus.n 1.00 91/11/13; Copyright (c) 1991 Luis Fernandes X.TH XABACUS 1 "13 Nov 1991" "X11R4" X.SH NAME Xxabacus \- abacus calculator for X X X.SH SYNOPSIS X.B xabacus X[-display \fIdisplayname\fP ] [ -demo \fIpathtoscriptfiles\fP -demofont | X-fn \fIXfontstring\fP ] [ -script ] [ -beadwidth \fIwidth\fP -beadheight X\fIheight\fP -framewidth \fIwidth\fP -framecolor \fIcolorname\fP -bg X\fIcolorname\fP -beadcolor \fIcolorname\fP -railcolor \fIcolorname\fP ] X X.SH DESCRIPTION XThis is an implementation of the classic Chinese abacus. X XThe device has two decks. XEach deck, separated by a beam, normally has 13 rods on which are mounted beads. XEach rod on the top deck contains 2 beads, and each rod on the bottom deck contains 5 beads. XEach bead on the upper deck has a value of five, while each bead on the lower deck has value of one. XBeads are considered counted, when moved \fItowards\fP the beam separating the decks. X XThe device has two decks ("new & improved" models have auxilliary decks stacked above the principal decks that enable multiplication, division and square-root (honest!) computations to be performed with equal ease as addition and subtraction). X X.SH OPTIONS X.TP 8 X-demo \fI path to script files \fP XUse this option to interactively learn to use the abacus. XLesson 1 teaches counting, lesson 2 teachs addition & lesson 3 teachs subtraction. XThe application will ignore command-line options regarding size (beadwidth, beadheight, framewidth); all other options are acknowledged. X XThe script for lesson-1 is called Lesson1.cmd, lesson-2 is contained in XLesson2.cmd and so on. X XThe script-files should be installed in /usr/lib/X11/xabacus. X XFor example: X.nf X \fIxabacus -demo ./\fP X.fi Xwill instruct \fIxabacus\fP to look for the script-files in the current directory. X XSimilarily, the \fIXAbacus.demo\fP resource may also be used to specify the demo-path: X.nf X \fIXAbacus.demo: ./\fP X.fi X XUsing this method, the \fI-demo\fP option need not be specified on the command-line. X XIf the script-files have been installed, then run the demo as: X.nf X \fIxabacus -demo /usr/lib/X11/xabacus\fP X.fi X X XRefer to the section titled: OPERATION, for details about the demo-mode. X X.TP 8 X-demofont | -fn \fIXfontstring\fP XSpecify an alternate font for the explanatory text that appears in the Xsecondary window, during the demo. The default font is 18 point Times-Roman (-*-times-*-r-*-*-*-180-*). The alternate font is 8x13. X X.TP 8 X-script X XUsing this option, the application will log (to \fIstdout\fP ) a set of row/column coordinates according to the beads the user clicks. X XThis data may be logged to a file as follows: X.nf X \fIxabacus -script >script.log\fP X.fi X XThe script may then be edited and then used to generate new demos. X X.TP 8 X-beadwidth \fI width \fP XThe width of a bead, in pixels. The default is 30. XFor the sake of authenticity, the bead-width should be about 2/3 greater than the bead-height. If the bead-width is equal to the bead-height then the beads will (vaguely, even then, one has to squint) resemble circles (the screen's aspect ratio is not accounted for). X X.TP 8 X-beadheight \fI height \fP XThe height of a bead, in pixels. The default is 20. X X.TP 8 X-framewidth \fI width \fP XIn pixels, the width of the frame around, and separating the two decks. XThe default is 10. X X.TP 8 X-ncols \fI columns \fP XAn integer representing the number of columns the abacus is to have, up to Xa maximum of 100. The default is 13. X X.TP 8 X-framecolor \fI colorname \fP XA valid color-name for the frame of the abacus. Default is "brown". X X.TP 8 X-bg \fI colorname \fP XA valid color-name for the background. Default is "white". XSpecifying a color other than the default will result in the beads having an unpredictable color. X(This happens because the bead-image is XOR'd with the background when animating it.) X X.TP 8 X-bead-color \fI colorname \fP XA valid color-name for the color of the beads. Default is "green4". X X.TP 8 X-railcolor \fI colorname \fP XA valid color-name for the color of the rails. Default is "green4". X X.TP 8 X-help XPrints a summary of the command-line options. X X.SH OPERATION X\fINormal Operation:\fP XThe beads may be moved by clicking on them with the mouse-pointer; the beads will shift themselves to vacate the row and column that was clicked. XThe abacus will beep when the mouse is clicked on an invalid location (like the middle-frame). X XThe abacus may be resized to accomodate more (or less, but no less than the Xminimum as specified with \fI-ncols\fP) columns; it resizes in width only. XColumns are added only if the amount resized can accomodate a complete column. XA maximum of 100 columns is possible, i.e. operations with numbers with up to X100 digits is possible. X XPressing 'q', 'Q' or '^C' will quit. X X\fIDemo Mode:\fP XIn this mode, the abacus is controlled by the program. XWhen started with the demo option, a second window is presented that should be placed directly below the abacus-window. Descriptive text, and user prompts are displayed in this window. X XPressing 'q' during the demo will quit it. Clicking the left mouse-button with Xthe pointer in the window will restart the demo (beginning with lesson-1). X X.SH RESOURCES X.nf XThe application class name is XAbacus. XEvery command-line option has its equivalent X-resource as follows: X XXAbacus X .beadwidth X .beadheight X .framewidth X .ncols X .framecolor X .bg X .beadcolor X .railcolor X .demo X .demofont X.if X X.SH SEE ALSO X\fIThe Abacus: The Art of Calculation Using Beads\fP, details all the known techniques for performing additions & subtractions. X Xxcalc(1), xfontsel(1), xrdb(1), X(1) X X.SH SCRIPT-FILE FORMAT X.nf XThe format of the lesson script-file (Lesson\fIn\fP.cmd) is as follows: X<number of moves in the script> X<row> <col> <number-of-text-lines-that-follow> Xtext-line1 X : X : Xtext-line4 X<row> <col> <number-of-text-lines> Xtext-line1 X : X : Xtext-line4 X : X : X.fi X XThe text is displayed in the secondary window that appears during the demo. X\fI<number-of-text-lines-that-follow>\fP cannot exceed 4 text-lines. XEach row/col/text batch represents 1 "move". XA row beginning with a negative number signifies that the move be ignored & Xthat just the descriptove text be displayed. This is useful for explanatory Xpauses in the lesson. XRefer to any of Lesson1.cmd, Lesson2.cmd or Lesson3.cmd. X X.SH FEATURES XA cosmetic bug occurs, when certain user-defined frame-widths are specified and a top-deck bead is moved down. X XColumns are added only if the amount resized can accomodate a complete column. X XWhen the application is resized, an incremental amount that does not accomodate a full column, it loses track of the correct number of columns. X X.SH ACKNOWLEDGEMENTS XAgustine Lee, instructor at the Ryerson Electrical Engineering Department provided a real, live abacus in addition to invaluable documentation on its use and Xcomments on improving it. X XNick Colonello, for alpha-testing the application and providing constructive Xcriticism. X XEva Dudova, for beta-testing the application. X XAnd to those, before me, who have written X-applications, from whose code I have learned the art of X. X X.SH COPYRIGHT XCopyright 1991, Luis Fernandes. X XPermission to use, copy, hack, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that Xboth that copyright notice and this permission notice appear in Xsupporting documentation. X XThis software is presented as is without any implied or written warranty. X X.SH AUTHOR XLuis Fernandes (lfernand@ryelect.uucp) END_OF_FILE if test 7566 -ne `wc -c <'xabacus.man'`; then echo shar: \"'xabacus.man'\" unpacked with wrong size! fi # end of 'xabacus.man' fi echo shar: End of archive 3 \(of 4\). cp /dev/null ark3isdone MISSING="" for I in 1 2 3 4 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 4 archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- Molecular Simulations, Inc. mail: dcmartin@msi.com 796 N. Pastoria Avenue uucp: uunet!dcmartin Sunnyvale, California 94086 at&t: 408/522-9236