X-Window to Postscript Filter

John Cristy cristy at eplrx7.uucp
Sat May 26 00:20:46 AEST 1990


#! /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", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  XtoPS.man Imakefile Makefile XtoPS.c encode.c
# Wrapped by cristy at sunburst on Fri May 25 10:03:09 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'XtoPS.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'XtoPS.man'\"
else
echo shar: Extracting \"'XtoPS.man'\" \(2872 characters\)
sed "s/^X//" >'XtoPS.man' <<'END_OF_FILE'
X.ad l
X.nh
X.TH XtoPS 1 "24 September 1989" "X Version 11"
X.SH NAME
XXtoPS - dump an image of an X window
X.SH SYNOPSIS
X.B "XtoPS"
X[ \fIoptions\fP ... ] \fIfile\fP
X.SH DESCRIPTION
X.PP
X.I XtoPS
Xis an X Window System window dumping utility.
X.I XtoPS
Xallows X users to store window images in a postscript file.  This file
Xcan then be printed on a postscript compatible printer in either color
Xor grayscale.  The target window is selected by clicking the mouse in
Xthe desired window.  The keyboard bell is rung once at the beginning of
Xthe dump and twice when the dump is completed.
X.SH OPTIONS
X.TP
X.B "+border"
Xinclude image borders in the output image.
X.TP
X.B "-display \fIhost:display[.screen]\fP"
Xa display other than the default specified by the DISPLAY environment variable.
X.TP
X.B "+frame"
Xinclude window manager frame.
X.TP
X.B "+grayscale"
Xsave image as grayscale.
X.TP
X.B "id \fIvalue\fP"
Xselect window with this id.
X.TP
X.B "name \fIname\fP"
Xselect window with this name.
X.TP
X.B "-root"
Xselect root window.
X.PP
XChange \fI+\fP to \fI-\fP in any option above to reverse its effect.  For
Xexample \fB-border\fP means do not save image border.
X.PP
XSpecify \fIfile\fP as \fI-\fP for standard input or output.
X.PP
X.SH ENVIRONMENT
X.PP
X.TP
X.B DISPLAY
XTo get the default host, display number, and screen.
X.SH SEE ALSO
XX(1), display(1), import(1)
X.SH COPYRIGHT
XCopyright 1990 E. I. Dupont de Nemours & Company                           
X.PP                                                                           
XPermission to use, copy, modify, distribute, and sell this software and    
Xits documentation for any purpose is hereby granted without fee,           
Xprovided that the above copyright notice appear in all copies and that     
Xboth that copyright notice and this permission notice appear in            
Xsupporting documentation, and that the name of E. I. Dupont de Nemours     
X& Company not be used in advertising or publicity pertaining to            
Xdistribution of the software without specific, written prior               
Xpermission.  E. I. Dupont de Nemours & Company makes no representations    
Xabout the suitability of this software for any purpose.  It is provided    
X"as is" without express or implied warranty.                               
X.PP
XE. I. Dupont de Nemours & Company disclaims all warranties with regard     
Xto this software, including all implied warranties of merchantability      
Xand fitness, in no event shall E. I. Dupont de Nemours & Company be        
Xliable for any special, indirect or consequential damages or any           
Xdamages whatsoever resulting from loss of use, data or profits, whether    
Xin an action of contract, negligence or other tortious action, arising     
Xout of or in connection with the use or performance of this software.      
X.SH AUTHORS
XJohn Cristy, E.I. DuPont De Nemours & Company Incorporated
X
END_OF_FILE
if test 2872 -ne `wc -c <'XtoPS.man'`; then
    echo shar: \"'XtoPS.man'\" unpacked with wrong size!
fi
chmod +x 'XtoPS.man'
# end of 'XtoPS.man'
fi
if test -f 'Imakefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Imakefile'\"
else
echo shar: Extracting \"'Imakefile'\" \(143 characters\)
sed "s/^X//" >'Imakefile' <<'END_OF_FILE'
XPROGRAMS= XtoPS 
XSYS_LIBRARIES= $(XLIB) -lm
XSRCS= XtoPS.c encode.c
XOBJS= XtoPS.o encode.o
X
XAllTarget($(PROGRAMS))
X
XComplexProgramTarget(XtoPS)
END_OF_FILE
if test 143 -ne `wc -c <'Imakefile'`; then
    echo shar: \"'Imakefile'\" unpacked with wrong size!
fi
chmod +x 'Imakefile'
# end of 'Imakefile'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(8857 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 <Imakefile>
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.0.3
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
XPROGRAMS= XtoPS
XSYS_LIBRARIES= $(XLIB) -lm
XSRCS= XtoPS.c encode.c
XOBJS= XtoPS.o encode.o
X
Xall:: $(PROGRAMS)
X
X PROGRAM = XtoPS
X
Xall:: XtoPS
X
XXtoPS: $(OBJS) $(DEPLIBS)
X	$(RM) $@
X	$(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
X
Xsaber_XtoPS:
X	#load $(ALLDEFINES) $(SRCS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X
Xosaber_XtoPS:
X	#load $(ALLDEFINES) $(OBJS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X
Xinstall:: XtoPS
X	$(INSTALL) -c $(INSTPGMFLAGS)   XtoPS $(BINDIR)
X
Xinstall.man:: XtoPS.man
X	$(INSTALL) -c $(INSTMANFLAGS) XtoPS.man $(MANDIR)/XtoPS.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###########################################################################
X# common rules for all Makefiles - do not edit
X
Xemptyrule::
X
Xclean::
X	$(RM_CMD) \#*
X
XMakefile::
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) -DCURDIR=$(CURRENT_DIR)
X
Xtags::
X	$(TAGS) -w *.[ch]
X	$(TAGS) -xw *.[ch] > TAGS
X
Xsaber:
X	#load $(ALLDEFINES) $(SRCS)
X
Xosaber:
X	#load $(ALLDEFINES) $(OBJS)
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 8857 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'XtoPS.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'XtoPS.c'\"
else
echo shar: Extracting \"'XtoPS.c'\" \(39621 characters\)
sed "s/^X//" >'XtoPS.c' <<'END_OF_FILE'
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                     X   X  TTTTT   OOO   PPPP   SSSSS                       %
X%                      X X     T    O   O  P   P  S                           %
X%                       X      T    O   O  PPPP    SSS                        %
X%                      X X     T    O   O  P          S                       %
X%                     X   X    T     OOO   P      SSSSS                       %
X%                                                                             %
X%                                                                             %
X%                  Import X11 image to a postscript format.                   %
X%                                                                             %
X%                                                                             %
X%                           Software Design                                   %
X%                             John Cristy                                     %
X%                            January  1990                                    %
X%                                                                             %
X%                                                                             %
X%  Copyright 1990 E. I. Dupont de Nemours & Company                           %
X%                                                                             %
X%  Permission to use, copy, modify, distribute, and sell this software and    %
X%  its documentation for any purpose is hereby granted without fee,           %
X%  provided that the above copyright notice appear in all copies and that     %
X%  both that copyright notice and this permission notice appear in            %
X%  supporting documentation, and that the name of E. I. Dupont de Nemours     %
X%  & Company not be used in advertising or publicity pertaining to            %
X%  distribution of the software without specific, written prior               %
X%  permission.  E. I. Dupont de Nemours & Company makes no representations    %
X%  about the suitability of this software for any purpose.  It is provided    %
X%  "as is" without express or implied warranty.                               %
X%                                                                             %
X%  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
X%  to this software, including all implied warranties of merchantability      %
X%  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
X%  liable for any special, indirect or consequential damages or any           %
X%  damages whatsoever resulting from loss of use, data or profits, whether    %
X%  in an action of contract, negligence or other tortious action, arising     %
X%  out of or in connection with the use or performance of this software.      %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  The XtoPS program reads a X11 image from any visible window on a display
X%  and converts it to postscript format.  The image can then be printed on a
X%  postscript compatible printer in either color or grayscale.
X%
X%  The XtoPS program command syntax is:
X%
X%  Usage: XToPS [options ...] file
X%
X%  Where options include:
X%    +border        include image borders in the output image
X%    -display name  X server to contact
X%    +frame         include window manager frame
X%    +grayscale     print image as gray scale colors
X%    -id number     select window with this id
X%    -name name     select window with this name
X%    -root          select root window
X%
X%  Change '+' to '-' in any option above to reverse its effect.
X%  For example, -borders means do not include image borders).
X%
X%  Specify 'file' as '-' for standard input or output.
X%
X%
X*/
X
X/*
X  Include declarations.
X*/
X#include <X11/Xlib.h>
X#include <X11/Xutil.h>
X#include <X11/cursorfont.h>
X#include "display.h"
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%   C l i e n t W i n d o w                                                   %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  Function ClientWindow finds a window, at or below the specified window,  
X%  which has a WM_STATE property.  If such a window is found, it is returned,  
X%  otherwise the argument window is returned.
X%
X%  The format of the ClientWindow function is:
X%
X%      child=ClientWindow(display,window)
X%
X%  A description of each parameter follows:
X%
X%    o child:  ClientWindow returns a window, at or below the specified 
X%      window, which has a WM_STATE property otherwise the argument window
X%      is returned.
X%
X%    o display:  Specifies a pointer to the Display structure;  returned from
X%      XOpenDisplay.
X%
X%    o window:  Specifies the window to find a WM_STATE property.
X%
X%
X*/
XWindow ClientWindow(display,window)
XDisplay 
X  *display;
X
XWindow 
X  window;
X{
X  Atom 
X    state;
X
X  Atom 
X    type;
X
X  int 
X    format;
X
X  unsigned char 
X    *data;
X
X  unsigned long 
X    after,
X    number_items;
X
X  Window 
X    child,
X    WindowByProperty();
X
X  state=XInternAtom(display,"WM_STATE",True);
X  if (!state)
X    return(window);
X  type=None;
X  XGetWindowProperty(display,window,state,0,0,False,AnyPropertyType,&type, 
X    &format,&number_items,&after,&data);
X  if (type)
X    return(window);
X  child=WindowByProperty(display,window,state);
X  if (!child)
X    return(window);
X  return(child);
X}
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%   I s T r u e                                                               %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  Function IsTrue returns True if the boolean is "true", "on", "yes" or "1".
X%
X%  The format of the IsTrue routine is:
X%
X%      option=IsTrue(boolean)
X%
X%  A description of each parameter follows:
X%
X%    o option:  either True or False depending on the boolean parameter.
X%
X%    o boolean:  Specifies a pointer to a character array.
X%
X%
X*/
Xint IsTrue(boolean)
Xchar
X  *boolean;
X{
X  char
X    c,
X    *p;
X
X  if (!boolean)
X    return(False);
X  p=boolean;
X  for ( ; *p; p++)
X  {
X    /*
X      Convert to lower case.
X    */
X    c=(*p);
X    if (isascii(c) && isupper(c))
X      *p=tolower(c);
X  }
X  if (strcmp(boolean,"true") == 0)
X    return(True);
X  if (strcmp(boolean,"on") == 0)
X    return(True);
X  if (strcmp(boolean,"yes") == 0)
X    return(True);
X  if (strcmp(boolean,"1") == 0)
X    return(True);
X  if (strcmp(boolean,"+") == 0)
X    return(True);
X  return(False);
X}
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%   P r i n t I m a g e                                                       %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  Function PrintImage translates a MIFF image to postscript for printing.
X%
X%  The format of the PrintImage routine is:
X%
X%      status=PrintImage(image,grayscale)
X%
X%  A description of each parameter follows:
X%
X%    o status:  Function PrintImage return True if the image is printed.
X%      False is returned if the image file cannot be opened for printing.
X%
X%    o image:  The address of a structure of type Image;  returned from
X%      ReadImage.
X%
X%    o grayscale: An integer that specifies a grayscale image if non-zero.
X%
X%
X*/
Xunsigned int PrintImage(image,grayscale)
XImage
X  *image;
X
Xunsigned int
X  grayscale;
X{
X#define PointsPerInch 72.0
X#define PageBorder 0.25
X#define PageWidth  8.5
X#define PageHeight 11.0
X
X  static char
X    *commands[]=
X    {
X      "%!",
X      "%",
X      "% Display a runlength-encoded grayscale or color image.",
X      "%",
X      "/buffer 512 string def",
X      "/byte 1 string def",
X      "/color_packet 3 string def",
X      "/gray_packet 1 string def",
X      "/expanded_packet 768 string def",
X      " ",
X      "/ReadColorPacket",
X      "{",
X      "  %",
X      "  % read a runlength-encoded color packet (length red green blue).",
X      "  %",
X      "  currentfile byte readhexstring pop 0 get",
X      "  /count exch 1 add def",
X      "  /count count 3 mul def",
X      "  currentfile color_packet readhexstring pop",
X      "  0 3 count 1 sub",
X      "  {",
X      "    expanded_packet exch color_packet putinterval",
X      "  } for pop",
X      "  expanded_packet 0 count getinterval",
X      "} def",
X      " ",
X      "/DisplayColorImage",
X      "{",
X      "  %",
X      "  % display a runlength-encoded color image.",
X      "  %",
X      "  columns rows 8",
X      "  [",
X      "    columns 0 0",
X      "    rows neg 0 rows",
X      "  ]",
X      "  { ReadColorPacket } false 3 colorimage",
X      "} def",
X      " ",
X      "/ReadGrayPacket",
X      "{",
X      "  %",
X      "  % read a runlength-encoded grayscale packet (length gray).",
X      "  %",
X      "  currentfile byte readhexstring pop 0 get",
X      "  /count exch 1 add def",
X      "  currentfile gray_packet readhexstring pop",
X      "  0 1 count 1 sub",
X      "  {",
X      "    expanded_packet exch gray_packet putinterval",
X      "  } for pop",
X      "  expanded_packet 0 count getinterval",
X      "} def",
X      " ",
X      "/DisplayGrayImage",
X      "{",
X      "  %",
X      "  % display a runlength-encoded grayscale image.",
X      "  %",
X      "  columns rows 8",
X      "  [",
X      "    columns 0 0",
X      "    rows neg 0 rows",
X      "  ]",
X      "  { ReadGrayPacket } image",
X      "} def",
X      " ",
X      "/DisplayImage",
X      "{",
X      "  %",
X      "  % display a runlength-encoded grayscale or color image.",
X      "  %",
X      "  initgraphics",
X      "  gsave",
X      "  currentfile buffer readline pop",
X      "  token { /degrees exch def } { } ifelse",
X      "  degrees rotate",
X      "  currentfile buffer readline pop",
X      "  token { /x exch def } { } ifelse",
X      "  token { /y exch def } { } ifelse",
X      "  x y translate",
X      "  currentfile buffer readline pop",
X      "  token { /x exch def } { } ifelse",
X      "  token { /y exch def } { } ifelse",
X      "  x y scale",
X      "  currentfile buffer readline pop",
X      "  currentfile buffer readline pop",
X      "  token { /columns exch def } { } ifelse",
X      "  token { /rows exch def } { } ifelse",
X      "  currentfile buffer readline pop",
X      "  token { /grayscale exch def } { } ifelse",
X      "  grayscale 0 gt { DisplayGrayImage } { DisplayColorImage } ifelse",
X      "  grestore",
X      "  showpage",
X      "} def",
X      " ",
X      "%",
X      "% DisplayImage parameters:",
X      "%   degrees rotation.",
X      "%   x & y translation.",
X      "%   x & y scale.",
X      "%   image name.",
X      "%   image columns & rows.",
X      "%   grayscale.",
X      "%   hex grayscale or color runlength-encoded packets.",
X      "% ",
X      "DisplayImage",
X      NULL
X    };
X
X  char
X    **q;
X
X  double
X    delta_x,
X    delta_y,
X    image_height,
X    image_width,
X    max,
X    min,
X    rotate,
X    scale,
X    scale_x,
X    scale_y,
X    translate_x,
X    translate_y;
X
X  register RunlengthPacket
X    *p;
X
X  register int
X    i,
X    j;
X
X  register unsigned char
X    blue,
X    gray,
X    green,
X    red;
X
X  /*
X    Open output image file.
X  */
X  if (*image->filename == '-')
X    image->file=stdout;
X  else
X    image->file=fopen(image->filename,"w");
X  if (image->file == (FILE *) NULL)
X    {
X      (void) fprintf(stderr,"Can't open %s for printing\n",image->filename);
X      return(False);
X    }
X  /*
X    Compute image rotation.
X  */
X  if (((double) image->columns/(double) image->rows) > 1.0)
X    rotate=(-90.0);
X  else
X    rotate=0.0;
X  /*
X    Compute image scaling.
X  */
X  image_width=(double) image->columns/PointsPerInch;
X  image_height=(double) image->rows/PointsPerInch;
X  /*
X    Check max page sizes
X  */
X  max=image_width > image_height ? image_width : image_height;
X  if (max > (PageHeight-(2.0*PageBorder)))
X    {
X      scale=(PageHeight-(2.0*PageBorder))/max;
X      image_height*=scale;
X      image_width*=scale;
X    }
X  min=image_width > image_height ? image_height : image_width;
X  if (min > (PageWidth-(2.0*PageBorder)))
X    {
X      scale=(PageWidth-(2.0*PageBorder))/min;
X      image_width*=scale;
X      image_height*=scale;
X    }
X  scale_x=image_width*PointsPerInch;
X  scale_y=image_height*PointsPerInch;
X  translate_x=0.0;
X  translate_y=0.0;
X  if (rotate == 0.0)
X    {
X      delta_x=PageWidth-(image_width+(2.0*PageBorder));
X      delta_y=PageHeight-(image_height+(2.0*PageBorder));
X      if (delta_x >= 0.0)
X        translate_x=((delta_x/2.0+PageBorder)* PointsPerInch);
X      else
X        translate_x=PageBorder*PointsPerInch;
X      if (delta_y >= 0.0)
X        translate_y=((delta_y/2.0+PageBorder)* PointsPerInch);
X      else
X        translate_y=PageBorder*PointsPerInch;
X    }
X  else
X    {
X      delta_x=PageHeight-(image_width+(2.0*PageBorder));
X      delta_y=PageWidth-(image_height+(2.0*PageBorder));
X      if (delta_x >= 0.0)
X        translate_x=((delta_x/2.0+PageBorder-PageHeight)*PointsPerInch);
X      else
X        translate_x=(PageBorder-PageHeight)*PointsPerInch;
X      if (delta_y >= 0.0)
X        translate_y=((delta_y/2.0+PageBorder)*PointsPerInch);
X      else
X        translate_y=PageBorder*PointsPerInch;
X    }
X  /*
X    Output postscript commands.
X  */
X  for (q=commands; *q; q++)
X    (void) fprintf(image->file,"%s\n",*q);
X  /*
X    Output image data.
X  */
X  (void) fprintf(image->file,"%f\n%f %f\n%f %f\n%s\n%d %d\n%d\n",rotate,
X    translate_x,translate_y,scale_x,scale_y,image->filename,image->columns,
X    image->rows,grayscale);
X  p=image->pixels;
X  j=0;
X  for (i=0; i < image->packets; i++)
X  {
X    j++;
X    if (grayscale)
X      {
X        gray=Intensity(*p);
X        (void) fprintf(image->file,"%02x%02x ",p->length,gray);
X        if ((j % 6) == 0)
X          (void) fprintf(image->file,"\n");
X      }
X    else
X      {
X        red=p->red;
X        green=p->green;
X        blue=p->blue;
X        (void) fprintf(image->file,"%02x%02x%02x%02x ",p->length,red,green,
X          blue);
X        if ((j % 3) == 0)
X          (void) fprintf(image->file,"\n");
X      }
X    p++;
X  }
X  (void) fprintf(image->file,"\n\n");
X  if (image->file != stdin)
X    (void) fclose(image->file);
X  return(True);
X}
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%   R e a d C o l o r m a p                                                   %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  Function ReadColormap returns the colormap of the image and the
X%  number of colors in the colormap.
X%
X%  The format of the ReadColormap function is:
X%
X%      number_colors=ReadColormap(display,window_attributes,colors)
X%
X%  A description of each parameter follows:
X%
X%    o number_colors:  ReadColormap returns the number of colors in the
X%      colormap.
X%
X%    o display:  Specifies a pointer to the Display structure;  returned from
X%      XOpenDisplay.
X%
X%    o window_attributes:  Specifies a pointer to the window attributes
X%      structure;  returned from XGetWindowAttributes.
X%
X%    o colors:  Specifies a an array of XColor structures.  The colormap
X%      red, green, and blue  are returned.
X%
X%
X*/
Xint ReadColormap(display,window_attributes,colors)
XDisplay
X  *display;
X
XXWindowAttributes
X  *window_attributes;
X
XXColor
X  **colors;
X{
X  int
X    number_colors;
X
X  register int
X    i;
X
X  if (!window_attributes->colormap)
X    return(0);
X  if (window_attributes->visual->class == TrueColor)
X    return(0);
X  number_colors=window_attributes->visual->map_entries;
X  *colors=(XColor *) malloc((unsigned) (number_colors*sizeof(XColor)));
X  if (*colors == (XColor *) NULL)
X    {
X      (void) fprintf(stderr,"Can't continue, not enough memory.\n");
X      exit(1);
X    }
X  for (i=0; i < number_colors; i++)
X    if (window_attributes->visual->class != DirectColor)
X      for (i=0; i < number_colors; i++)
X      {
X        (*colors)[i].pixel=i;
X        (*colors)[i].pad=0;
X      }
X    else
X      {
X        unsigned long
X          blue,
X          blue_bit,
X          green,
X          green_bit,
X          red,
X          red_bit;
X
X        red=0;
X        green=0;
X        blue=0;
X        red_bit=window_attributes->visual->red_mask &
X          (~(window_attributes->visual->red_mask)+1);
X        green_bit=window_attributes->visual->green_mask &
X          (~(window_attributes->visual->green_mask)+1);
X        blue_bit=window_attributes->visual->blue_mask &
X          (~(window_attributes->visual->blue_mask)+1);
X        for (i=0; i < number_colors; i++)
X        {
X          (*colors)[i].pixel=red | green | blue;
X          (*colors)[i].pad=0;
X          red+=red_bit;
X          if (red > window_attributes->visual->red_mask)
X            red=0;
X          green+=green_bit;
X          if (green > window_attributes->visual->green_mask)
X            green=0;
X          blue+=blue_bit;
X          if (blue > window_attributes->visual->blue_mask)
X            blue=0;
X        }
X      }
X  XQueryColors(display,window_attributes->colormap,*colors,number_colors);
X  return(number_colors);
X}
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%   R e a d I m a g e                                                         %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  Procedure ReadImage reads an image from an X window.
X%
X%  The format of the ReadImage routine is:
X%
X%      ReadImage(display,screen,window,borders,image)
X%
X%  A description of each parameter follows:
X%
X%    o display:  Specifies a pointer to the Display structure;  returned from
X%      XOpenDisplay.
X%
X%    o screen: Specifies the screen id of the root window.
X%
X%    o window: Specifies the window id where the image resides.
X%
X%    o borders: Specifies whether borders pixels are to be saved with
X%      the image.
X%
X%    o image:  specifies a pointer to the Image structure.
X%
X%
X*/
Xstatic void ReadImage(display,screen,window,borders,image)
XDisplay
X  *display;
X
Xint
X  screen;
X
XWindow
X  window;
X
Xunsigned int
X  borders;
X
XImage
X  *image;
X{
X  int
X    display_width,
X    display_height,
X    x,
X    y;
X
X  register int 
X    i;
X
X  register RunlengthPacket
X    *p;
X
X  register unsigned int
X    pixel;
X
X  Window
X    child;
X
X  XColor
X    *colors;
X
X  XImage
X    *ximage;
X
X  XWindowAttributes
X    window_attributes;
X
X  /*
X    Inform the user not to alter the screen.
X  */
X  XBell(display,0);
X  /*
X    Get the attributes of the window being dumped.
X  */
X  if(!XGetWindowAttributes(display,window,&window_attributes))
X    {
X      (void) fprintf(stderr,
X        "Can't continue, unable to get target window attributes.\n");
X      exit(1);
X    }
X  XTranslateCoordinates(display,window,XRootWindow(display,screen),0,0,&x,&y,
X    &child);
X  window_attributes.x=x;
X  window_attributes.y=y;
X  image->columns=window_attributes.width;
X  image->rows=window_attributes.height;
X  if (borders)
X    {
X      x-=window_attributes.border_width;
X      y-=window_attributes.border_width;
X      image->columns+=2*window_attributes.border_width;
X      image->rows+=2*window_attributes.border_width;
X    }
X  /*
X    clip to window
X  */
X  if (x < 0)
X    {
X      image->columns+=x;
X      x=0;
X    }
X  if (y < 0)
X    {
X      image->rows+=y;
X      y=0;
X    }
X  display_width=DisplayWidth(display,screen);
X  display_height=DisplayHeight(display,screen);
X  if ((x+image->columns) > display_width)
X    image->columns=display_width-x;
X  if ((y+image->rows) > display_height)
X    image->rows=display_height-y;
X  /*
X    Get image from window with XGetImage.
X  */
X  x-=window_attributes.x;
X  y-=window_attributes.y;
X  ximage=XGetImage(display,window,x,y,image->columns,image->rows,AllPlanes,
X    ZPixmap);
X  if (!ximage)
X    {
X      (void) fprintf(stderr,
X        "Can't continue, unable to get image at %dx%d+%d+%d\n",image->columns,
X          image->rows,x,y);
X      exit(1);
X     }
X  image->colors=ReadColormap(display,&window_attributes,&colors);
X  XBell(display,0);
X  XBell(display,0);
X  XFlush(display);
X  /*
X    Convert image to MIFF format.
X  */
X  image->comments=(char *) NULL;
X  image->class=(ximage->depth <= 16 ? PseudoClass : DirectClass);
X  image->compression=RunlengthEncodedCompression;
X  image->scene=0;
X  image->packets=image->columns*image->rows;
X  image->pixels=(RunlengthPacket *)
X    malloc((unsigned) (image->packets*sizeof(RunlengthPacket)));
X  if (image->pixels == (RunlengthPacket *) NULL)
X    {
X      (void) fprintf(stderr,"Can't image to postscript, not enough memory.\n");
X      exit(1);
X    }
X  p=image->pixels;
X  if (image->class == PseudoClass)
X    {
X      /*
X        Image is pseudo-color.
X      */
X      image->colormap=(ColorPacket *)
X        malloc((unsigned) (image->colors*sizeof(ColorPacket)));
X      if (image->colormap == (ColorPacket *) NULL)
X        {
X          (void) fprintf(stderr,"Can't continue, not enough memory.\n");
X          exit(1);
X        }
X      for (i=0; i < image->colors; i++)
X      {
X        image->colormap[i].red=colors[i].red >> 8;
X        image->colormap[i].green=colors[i].green >> 8;
X        image->colormap[i].blue=colors[i].blue >> 8;
X      }
X      for (y=0; y < image->rows; y++)
X      {
X        for (x=0; x < image->columns; x++)
X        {
X          pixel=XGetPixel(ximage,x,y);
X          p->red=(unsigned char) (colors[pixel].red >> 8);
X          p->green=(unsigned char) (colors[pixel].green >> 8);
X          p->blue=(unsigned char) (colors[pixel].blue >> 8);
X          p->index=(short unsigned int) pixel;
X          p->length=0;
X          p++;
X        }
X      }
X    }
X  else
X    {
X      register unsigned long
X        color,
X        index;
X
X      unsigned long
X        blue_mask,
X        blue_shift,
X        green_mask,
X        green_shift,
X        red_mask,
X        red_shift;
X
X      /*
X        Determine shift and mask for red, green, and blue.
X      */
X      red_mask=window_attributes.visual->red_mask;
X      red_shift=0;
X      while (!(red_mask & 0x01))
X      {
X        red_mask>>=1;
X        red_shift++;
X      }
X      green_mask=window_attributes.visual->green_mask;
X      green_shift=0;
X      while (!(green_mask & 0x01))
X      {
X        green_mask>>=1;
X        green_shift++;
X      }
X      blue_mask=window_attributes.visual->blue_mask;
X      blue_shift=0;
X      while (!(blue_mask & 0x01))
X      {
X        blue_mask>>=1;
X        blue_shift++;
X      }
X      /*
X        Convert DirectColor or TrueColor image to DirectClass.
X      */
X      if ((image->colors > 0) && 
X          (window_attributes.visual->class == DirectColor))
X        for (y=0; y < image->rows; y++)
X        {
X          for (x=0; x < image->columns; x++)
X          {
X            pixel=XGetPixel(ximage,x,y);
X            index=(pixel >> red_shift) & red_mask;
X            p->red=(unsigned char) (colors[index].red >> 8);
X            index=(pixel >> green_shift) & green_mask;
X            p->green=(unsigned char) (colors[index].green >> 8);
X            index=(pixel >> blue_shift) & blue_mask;
X            p->blue=(unsigned char) (colors[index].blue >> 8);
X            p->index=0;
X            p->length=0;
X            p++;
X          }
X        }
X      else
X        for (y=0; y < image->rows; y++)
X        {
X          for (x=0; x < image->columns; x++)
X          {
X            pixel=XGetPixel(ximage,x,y);
X            color=(pixel >> red_shift) & red_mask;
X            p->red=(unsigned char) 
X              ((((unsigned long) color*65535)/red_mask) >> 8);
X            color=(pixel >> green_shift) & green_mask;
X            p->green=(unsigned char) 
X              ((((unsigned long) color*65535)/green_mask) >> 8);
X            color=(pixel >> blue_shift) & blue_mask;
X            p->blue=(unsigned char) 
X              ((((unsigned long) color*65535)/blue_mask) >> 8);
X            p->index=0;
X            p->length=0;
X            p++;
X          }
X        }
X    }
X  /*
X    Free image and colormap.
X  */
X  if (image->colors > 0)
X    free((char *) colors);
X  XDestroyImage(ximage);
X}
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%   S e l e c t W i n d o w                                                   %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  Function SelectWindow allows a  user to select a window using the mouse.
X%
X%  The format of the SelectWindow function is:
X%
X%      window=SelectWindow(display,screen)
X%
X%  A description of each parameter follows:
X%
X%    o window:  SelectWindow returns the window id.
X%
X%    o display:  Specifies a pointer to the Display structure;  returned from
X%      XOpenDisplay.
X%
X%    o screen: Specifies the screen id of the root window.
X%
X%
X*/
XWindow SelectWindow(display,screen)
XDisplay
X  *display;
X
Xint
X  screen;
X{
X  Cursor
X    cursor;
X
X  int
X    status;
X
X  unsigned int
X    presses;
X
X  Window
X    target_window;
X
X  XEvent
X    event;
X
X  /*
X    Make the target cursor.
X  */
X  cursor=XCreateFontCursor(display,XC_crosshair);
X  /*
X    Grab the pointer using target cursor.
X  */
X  status=XGrabPointer(display,XRootWindow(display,screen),False,
X    ButtonPressMask | ButtonReleaseMask,GrabModeSync,GrabModeAsync,
X    XRootWindow(display,screen),cursor,CurrentTime);
X  if (status != GrabSuccess)
X    {
X      (void) fprintf(stderr,"Can't continue, cannot grab the mouse.\n");
X      exit(1);
X    }
X  /*
X    Select a window.
X  */
X  target_window=None;
X  presses=0;
X  while ((target_window == None) || (presses != 0))
X  {
X    /*
X      Allow another event.
X    */
X    XAllowEvents(display,SyncPointer,CurrentTime);
X    XWindowEvent(display,XRootWindow(display,screen),ButtonPressMask |
X      ButtonReleaseMask,&event);
X    switch (event.type)
X    {
X      case ButtonPress:
X      {
X        if (target_window == None)
X          {
X            target_window=event.xbutton.subwindow;
X            if (target_window == None)
X              target_window=XRootWindow(display,screen);
X          }
X        presses++;
X        break;
X      }
X      case ButtonRelease:
X      {
X	if (presses > 0)
X  	  presses--;
X        break;
X      }
X      default:
X        break;
X    }
X  }
X  XUngrabPointer(display,CurrentTime);
X  return(target_window);
X}
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%   U s a g e                                                                 %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  Procedure Usage displays the program usage;
X%
X%  The format of the Usage routine is:
X%
X%      Usage(program_name,message)
X%
X%  A description of each parameter follows:
X%
X%    program_name:  Specifies the name of this program.
X%
X%    message:  Specifies a specific message to display to the user.
X%
X*/
Xvoid Usage(program_name,message)
Xchar
X  *message,
X  *program_name;
X{
X  char
X    **p;
X
X  static char
X    *options[]=
X    {
X      "+border        include image borders in the output image",
X      "-display name  X server to contact",
X      "+frame         include window manager frame",
X      "+grayscale     print image as gray scale colors",
X      "-id number     select window with this id",
X      "-name name     select window with this name",
X      "-root          select root window",
X      NULL
X    };
X  if (message)
X    (void) fprintf(stderr,"Can't continue, %s\n\n",message);
X  (void) fprintf(stderr,"Usage: %s [options ...] file\n",program_name);
X  (void) fprintf(stderr,"\nWhere options include:\n");
X  for (p=options; *p; p++)
X    (void) fprintf(stderr,"  %s\n",*p);
X  (void) fprintf(stderr,
X    "\nChange '+' to '-' in any option above to reverse its effect.\n");
X  (void) fprintf(stderr,
X    "For example, -borders means do not include image borders.\n");
X  (void) fprintf(stderr,"\nSpecify 'file' as '-' for standard output.\n");
X  exit(1);
X}
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%   W i n d o w B y N a m e                                                   %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  Function WindowByName locates a window with a given name on a display.
X%  If no window with the given name is found, 0 is returned. If more than
X%  one window has the given name, the first one is returned.  Only root and
X%  its children are searched.
X%
X%  The format of the WindowByName function is:
X%
X%      window=WindowByName(display,root,name)
X%
X%
X%  A description of each parameter follows:
X%
X%    o window:  WindowByName returns the window id.
X%
X%    o display:  Specifies a pointer to the Display structure;  returned from
X%      XOpenDisplay.
X%
X%    o root:  Specifies a pointer to a window.
X%
X%    o name:  Specifies the name of the window to locate.
X%
X%
X*/
XWindow WindowByName(display,root,name)
XDisplay
X  *display;
X
XWindow
X  root;
X
Xchar
X  *name;
X{
X  char
X    *window_name;
X
X  register int
X    i;
X
X  unsigned int
X    number_children;
X
X  Window
X    *children,
X    child,
X    window;
X
X  if (XFetchName(display,root,&window_name) && !strcmp(window_name,name))
X    return(root);
X  if (!XQueryTree(display,root,&child,&child,&children,&number_children))
X    return(0);
X  window=0;
X  for (i=0; i < number_children; i++)
X  {
X    /*
X      Search each child and their children.
X    */
X    window=WindowByName(display,children[i],name);
X    if (window)
X      break;
X  }
X  if (children)
X    XFree((char *) children);
X  return(window);
X}
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%   W i n d o w B y P r o p e r y                                             %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  Function WindowByProperty locates a child window with a given property.
X%  If no window with the given name is found, 0 is returned.  If more than
X%  one window has the given property, the first one is returned.  Only the 
X%  window specified and its subwindows are searched.
X%
X%  The format of the WindowByProperty function is:
X%
X%      child=WindowByName(display,window,property)
X%
X%
X%  A description of each parameter follows:
X%
X%    o child:  WindowByProperty returns the window id with the specified
X%      property.  If no windows are found, WindowByProperty returns 0.
X%
X%    o display:  Specifies a pointer to the Display structure;  returned from
X%      XOpenDisplay.
X%
X%    o property:  Specifies the property of the window to locate.
X%
X%
X*/
XWindow WindowByProperty(display,window,property)
XDisplay 
X  *display;
X
XWindow 
X  window;
X
XAtom 
X  property;
X{
X  Atom 
X    type;
X
X  int 
X    format;
X
X  unsigned char 
X    *data;
X
X  unsigned int 
X    i,
X    number_children;
X
X  unsigned long 
X    after,
X    number_items;
X
X  Window 
X    *children,
X    child,
X    parent,
X    root;
X
X  if (!XQueryTree(display,window,&root,&parent,&children,&number_children))
X    return((Window) NULL);
X  type=None;
X  child=(Window) NULL;
X  for (i=0; (i < number_children) && !child; i++) 
X  {
X    XGetWindowProperty(display,children[i],property,0,0,False,AnyPropertyType, 
X      &type,&format,&number_items,&after,&data);
X    if (type)
X      child=children[i];
X  }
X  for (i = 0; (i < number_children) && !child; i++)
X    child=WindowByProperty(display,children[i],property);
X  if (children) 
X    XFree((char *) children);
X  return(child);
X}
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%    M a i n                                                                  %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%
X*/
Xmain(argc,argv)
Xint
X  argc;
X
Xchar
X  *argv[];
X{
X  char
X    *option,
X    *program_name,
X    *server_name;
X
X  Display
X    *display;
X
X  Image
X    *image;
X
X  int
X    borders,
X    frame,
X    i,
X    screen;
X
X  unsigned int
X    grayscale,
X    PrintImage();
X
X  Window
X    target_window;
X
X  /*
X    Connect to X server.
X  */
X  program_name=argv[0];
X  server_name=(char *) NULL;
X  for (i=1; i < argc; i++)
X  {
X    /*
X      Check command line for server name.
X    */
X    option=argv[i];
X    if ((strlen(option) > 1) && ((*option == '-') || (*option == '+')))
X      if (strncmp("dis",option+1,3) == 0)
X        {
X          /*
X            User specified server name.
X          */
X          i++;
X          if (i == argc)
X            Usage(program_name,"missing server name on -display");
X          server_name=argv[i];
X          break;
X        }
X  }
X  display=XOpenDisplay(server_name);
X  if (display == (Display *) NULL)
X    {
X      (void) fprintf(stderr,"Can't continue, unable to connect to %s.\n",
X        XDisplayName(server_name));
X      exit(1);
X    }
X  screen=XDefaultScreen(display);
X  /*
X    Get X defaults.
X  */
X  option=XGetDefault(display,program_name,"borders");
X  borders=IsTrue(option);
X  option=XGetDefault(display,program_name,"frame");
X  frame=IsTrue(option);
X  option=XGetDefault(display,program_name,"grayscale");
X  grayscale=IsTrue(option);
X  /*
X    Check command syntax.
X  */
X  target_window=(Window) NULL;
X  for (i=1; i < argc-1; i++)
X  {
X    option=argv[i];
X    if ((strlen(option) > 1) && ((*option == '-') || (*option == '+')))
X      switch(*(option+1))
X      {
X        case 'b':
X        {
X          borders=(*option == '+');
X          break;
X        }
X        case 'h':
X        {
X          Usage(program_name,(char *) NULL);
X          break;
X        }
X        case 'f':
X        {
X          frame=(*option == '+');
X          break;
X        }
X        case 'g':
X        {
X          grayscale=(*option == '+');
X          break;
X        }
X        case 'i':
X        {
X          i++;
X          if (i == argc)
X            Usage(program_name,"missing id on -id");
X          option=argv[i];
X          target_window=(Window) strtol(option,(char **) NULL,0);
X          break;
X        }
X        case 'n':
X        {
X          i++;
X          if (i == argc)
X            Usage(program_name,"missing name on -name");
X          option=argv[i]; 
X          target_window=
X            WindowByName(display,XRootWindow(display,screen),option);
X          if (target_window == (Window) NULL)
X            (void) fprintf(stderr,"No window with name %s exists!\n",option);
X          break;
X        }
X        case 'r':
X        {
X          target_window=XRootWindow(display,screen);
X          break;
X        }
X        default:
X          Usage(program_name,(char *) NULL);
X      }
X  }
X  if (argc == 1)
X    Usage(program_name,(char *) NULL);
X  if (!target_window)
X    target_window=SelectWindow(display,screen);
X  if (!frame)
X    if (target_window != XRootWindow(display,screen))
X      target_window=ClientWindow(display,target_window);
X  image=(Image *) malloc(sizeof(Image));
X  (void) strcpy(image->filename,argv[argc-1]);
X  ReadImage(display,screen,target_window,(unsigned int) borders,image);
X  (void) fprintf(stderr,"%s %dx%d\n",image->filename,image->columns,
X    image->rows);
X  (void) PrintImage(image,grayscale);
X  return(True);
X}
END_OF_FILE
if test 39621 -ne `wc -c <'XtoPS.c'`; then
    echo shar: \"'XtoPS.c'\" unpacked with wrong size!
fi
chmod +x 'XtoPS.c'
# end of 'XtoPS.c'
fi
if test -f 'encode.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'encode.c'\"
else
echo shar: Extracting \"'encode.c'\" \(12432 characters\)
sed "s/^X//" >'encode.c' <<'END_OF_FILE'
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%                 EEEEE  N   N   CCCC   OOO   DDDD    EEEEE                   %
X%                 E      NN  N  C      O   O  D   D   E                       %
X%                 EEE    N N N  C      O   O  D   D   EEES                    %
X%                 E      N  NN  C      O   O  D   D   E                       %
X%                 EEEEE  N   N   CCCC   OOO   DDDD    EEEEE                   %
X%                                                                             %
X%                                                                             %
X%                  Encode or Decode Color Runlength Packets                   %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%                           Software Design                                   %
X%                             John Cristy                                     %
X%                            January  1990                                    %
X%                                                                             %
X%                                                                             %
X%  Copyright 1990 E. I. Dupont de Nemours & Company                           %
X%                                                                             %
X%  Permission to use, copy, modify, distribute, and sell this software and    %
X%  its documentation for any purpose is hereby granted without fee,           %
X%  provided that the above copyright notice appear in all copies and that     %
X%  both that copyright notice and this permission notice appear in            %
X%  supporting documentation, and that the name of E. I. Dupont de Nemours     %
X%  & Company not be used in advertising or publicity pertaining to            %
X%  distribution of the software without specific, written prior               %
X%  permission.  E. I. Dupont de Nemours & Company makes no representations    %
X%  about the suitability of this software for any purpose.  It is provided    %
X%  "as is" without express or implied warranty.                               %
X%                                                                             %
X%  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
X%  to this software, including all implied warranties of merchantability      %
X%  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
X%  liable for any special, indirect or consequential damages or any           %
X%  damages whatsoever resulting from loss of use, data or profits, whether    %
X%  in an action of contract, negligence or other tortious action, arising     %
X%  out of or in connection with the use or performance of this software.      %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%
X%
X*/
X
X#include "display.h"
X
X/*
X  Define declarations.
X*/
X#define MaxChannels  8
X
X/*
X  Typedef declarations.
X*/
Xtypedef struct ChannelDescriptor
X{
X  RunlengthPacket
X    color,
X    *packet;
X
X  unsigned int
X    color_count,
X    runlength;
X} ChannelDescriptor;
X
X/*
X  Global variables.
X*/
Xstatic ChannelDescriptor
X  channels[MaxChannels];
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%  I n i t i a l i z e C h a n n e l                                          %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  Function InitializeChannel allocates a global buffer to help keep track
X%  of reading or writing runlength packets into image memory.  An integer
X%  value is returned that specifies the channel number to read or write the
X%  run-length encoded image.
X%
X%  The format of the InitializeChannel routine is:
X%
X%      channel_number=InitializeChannel(image);
X%
X%  A description of each parameter follows.
X%
X%    o channel_number:  The InitializeChannel routine returns this integer
X%      value.  Use it as the channel parameter when invoking the ReadPacket
X%      or WritePacket routines.
X%
X%    o image:  The address of a byte (8 bits) array of the run-length
X%      encoded image.
X%
X%
X*/
Xunsigned int InitializeChannel(image)
XRunlengthPacket
X  *image;
X{
X  static unsigned char
X    channel_number = 0;
X
X  channel_number++;
X  channel_number%=MaxChannels;
X  channels[channel_number].packet=image;
X  channels[channel_number].color_count=image->length+1;
X  channels[channel_number].runlength=0;
X  return(channel_number);
X}
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%  R e a d P a c k e t                                                        %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  Function ReadPacket reads one pixel runlength packet from the image buffer.
X%  Pixel packets are read until the max_count have been read or a pixel of
X%  another color is encountered.  The integer value returned is the number of
X%  pixels read.
X%
X%  The format of the ReadPacket routine is:
X%
X%      count=ReadPacket(channel_number,max_count,&red,&green,&blue,&index)
X%
X%  A description of each parameter follows.
X%
X%    o count:  The ReadPacket routine returns this integer value.  It is
X%      the actual number of contiguous pixels read from image memory of the
X%      same red, green, and blue value.
X%
X%    o channel_number:  An integer value that specifies the channel to
X%      read the run-length encoded image.  This value is assigned by the
X%      InitializeChannel routine.
X%
X%    o max_count:  An integer value that is the maximum number of pixels
X%      to read from image memory of this combination of red, green, and
X%      blue.
X%
X%    o red:  The address of a byte value representing the measure of the
X%      red contribution.
X%
X%    o green:  The address of a byte value representing the measure of
X%      the green contribution.
X%
X%    o blue:  The address of a byte value representing the measure of the
X%      blue contribution.
X%
X%    o index:  A byte value representing the colormap index of the
X%      red, green, and blue contribution.
X%
X%
X*/
Xunsigned int ReadPacket(channel_number,max_count,red,green,blue,index)
Xregister unsigned char
X  channel_number;
X
Xregister unsigned int
X  max_count;
X
Xunsigned char
X  *red,
X  *green,
X  *blue;
X
Xunsigned short
X  *index;
X{
X  register ChannelDescriptor
X    *c;
X
X  static unsigned int
X    number_pixels;
X
X  /*
X    Read runlength packets until the maximum count or different color.
X  */
X  c=channels+channel_number;
X  while (c->runlength < max_count)
X  {
X    if (c->color_count == 0)
X      {
X        /*
X          Get next runlength packet.
X        */
X        c->packet++;
X        c->color_count=c->packet->length+1;
X      }
X    if (c->runlength == 0)
X      {
X        c->color.red=c->packet->red;
X        c->color.green=c->packet->green;
X        c->color.blue=c->packet->blue;
X        c->color.index=c->packet->index;
X        c->runlength=c->color_count;
X        c->color_count=0;
X      }
X    else
X      if ((c->color.red == c->packet->red) &&
X          (c->color.green == c->packet->green) &&
X          (c->color.blue == c->packet->blue))
X        {
X          c->runlength+=c->color_count;
X          c->color_count=0;
X        }
X      else
X        break;
X  }
X  *red=c->color.red;
X  *green=c->color.green;
X  *blue=c->color.blue;
X  *index=c->color.index;
X  number_pixels=Min(c->runlength,max_count);
X  c->runlength-=number_pixels;
X  return(number_pixels);
X}
X
X/*
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%  W r i t e P a c k e t                                                      %
X%                                                                             %
X%                                                                             %
X%                                                                             %
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X%
X%  Function WritePacket encodes RBG values into run-length packets.  The
X%  function writes the packets on the specified channel and returns the
X%  number of packets encoded.
X%
X%  The format of the WritePacket routine is:
X%
X%      number_packets=WritePacket(channel_number,red,green,blue,index,count)
X%
X%  A description of each parameter follows.
X%
X%    o number_packets:  An integer value that indicates the number of
X%      packets encoded.  Note, this value may be zero is if the current
X%      packet is only partially complete.
X%
X%    o channel_number:  An integer value that specifies the channel to
X%      write the run-length encoded image.  This value is assigned by the
X%      InitializeChannel routine.
X%
X%    o red:  A byte value representing the measure of the red
X%      contribution.
X%
X%    o green:  A byte value representing the measure of the green
X%      contribution.
X%
X%    o blue:  A byte value representing the measure of the blue
X%      contribution.
X%
X%    o index:  A byte value representing the colormap index of the 
X%      red, green, and blue contribution.
X%
X%    o count:  An integer value that is the number of pixels to write to
X%      image memory of this combination of red, green, and blue.
X%
X%
X*/
Xunsigned int WritePacket(channel_number,red,green,blue,index,count)
Xregister unsigned int
X  channel_number;
X
Xregister unsigned char
X  red,
X  green,
X  blue;
X
Xregister unsigned short
X  index;
X
Xregister unsigned int
X  count;
X{
X  register ChannelDescriptor
X    *c;
X
X  register unsigned int
X    packets;
X
X  packets=0;
X  c=channels+channel_number;
X  if (c->runlength == 0)
X    {
X      /*
X        Runlength is zero so copy pixels now.
X      */
X      c->runlength=count;
X      c->packet->red=red;
X      c->packet->green=green;
X      c->packet->blue=blue;
X      c->packet->index=index;
X      packets++;
X    }
X  else
X    if ((red == c->packet->red) &&
X        (green == c->packet->green) &&
X        (blue == c->packet->blue))
X      c->runlength+=count;
X    else
X      {
X        /*
X          Transfer new group of pixels.
X        */
X        c->packet->length=(c->runlength-1);
X        c->packet++;
X        c->runlength=count;
X        c->packet->red=red;
X        c->packet->green=green;
X        c->packet->blue=blue;
X        c->packet->index=index;
X        packets++;
X      }
X  if (c->runlength > MaxRgb)
X    {
X      /*
X        Split up pixels if the runlength exceeds MaxRgb.
X      */
X      do
X      {
X        c->runlength-=(MaxRgb+1);
X        c->packet->length=MaxRgb;
X        c->packet++;
X        c->packet->red=red;
X        c->packet->green=green;
X        c->packet->blue=blue;
X        c->packet->index=index;
X        packets++;
X      }
X      while (c->runlength > MaxRgb);
X      if (c->runlength == 0)
X        packets--;
X  }
X  c->packet->length=c->runlength-1;
X  return(packets);
X}
END_OF_FILE
if test 12432 -ne `wc -c <'encode.c'`; then
    echo shar: \"'encode.c'\" unpacked with wrong size!
fi
# end of 'encode.c'
fi
echo shar: End of shell archive.
exit 0
--
The UUCP Mailer



More information about the Alt.sources mailing list