v01i016: xipr: dumps an X window to an Imagen Printer, Part01/01
Mike Wexler
mikew at wyse.wyse.com
Wed Aug 31 02:59:49 AEST 1988
Submitted-by: dana at thumper.bellcore.com (Dana A. Chee)
Posting-number: Volume 1, Issue 16
Archive-name: xipr/part01
[I ran this program and it didn't fail. I don't know if the output
really works on an imagen or not.]
#! /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 archive 1 (of 1)."
# Contents: Imakefile Makefile bitimp.c bitimp.man newimPcodes.h
# rasterfile.h readump.c swap.c xipr.man xipr.sh
# Wrapped by dana at dino on Mon Aug 15 15:56:14 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Imakefile' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Imakefile'\"
else
echo shar: Extracting \"'Imakefile'\" \(196 characters\)
sed "s/^X//" >'Imakefile' <<'END_OF_FILE'
XLOCAL_LIBRARIES = $(XLIB)
XOBJS = bitimp.o readump.o swap.o
X
XComplexProgramTarget(bitimp)
X
Xall:: xipr
X
Xxipr: xipr.sh
X cp xipr.sh xipr
X
XInstallProgram(xipr,$(BINDIR))
XInstallManPage(xipr,$(MANDIR))
END_OF_FILE
if test 196 -ne `wc -c <'Imakefile'`; then
echo shar: \"'Imakefile'\" unpacked with wrong size!
fi
# 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'\" \(4110 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X#
X# Warning: the cpp used on this machine replaces
X# all newlines and multiple tabs/spaces in a macro
X# expansion with a single space. Imake tries to
X# compensate for this, but is not always
X# successful.
X#
X
X#
X# This makefile is automatically generated by imake... do not modify
X# or you may lose your changes when imake generates makefiles again.
X# Ignore this message if you are not using imake.
X#
X
X TOP = ./../..
X AS = as
X CC = cc
X CPP = /lib/cpp
X LD = ld
X LINT = lint
X INSTALL = install
X TAGS = ctags
X RM = rm -f
X MV = mv
X LN = ln -s
X RANLIB = ranlib
X AR = ar clq
X LS = ls
X LINTOPTS = -axz
X LINTLIBFLAG = -C
X MAKE = make
X STD_DEFINES =
X CDEBUGFLAGS = -O
X DESTDIR = /usr/local/pkg/X11/
X
X PATHSEP = /
X DEPEND = $(DEPENDSRC)/makedepend
X IMAKE = $(IMAKESRC)/imake
X RGB = $(RGBSRC)/rgb
X CFLAGS = $(CDEBUGFLAGS) $(INCLUDES) $(STD_DEFINES) $(DEFINES)
X LINTFLAGS = $(LINTOPTS) $(INCLUDES) $(STD_DEFINES) $(DEFINES) -DLINT
X LDFLAGS = $(CDEBUGFLAGS) $(SYS_LIBRARIES) $(SYSAUX_LIBRARIES)
X INSTUIDFLAGS = -m 0755
X INSTLIBFLAGS = -m 0644
X INSTINCFLAGS = -m 0444
X INSTMANFLAGS = -m 0444
X INSTAPPFLAGS = -m 0444
X
X USRLIBDIR = $(DESTDIR)/lib
X BINDIR = $(DESTDIR)/bin
X LIBDIR = $(DESTDIR)/Xlib
X LINTLIBDIR = $(USRLIBDIR)/lint
X INCDIR = $(DESTDIR)/include/X11
X FONTDIR = $(LIBDIR)/fonts
X UWMDIR = $(LIBDIR)/uwm
X MANDIR = $(DESTDIR)/man/man1
X XAPPLOADDIR = $(LIBDIR)/app-defaults
X ADMDIR = $(DESTDIR)/adm
X
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 EXAMPLESRC = $(TOP)/examples
X CONTRIBSRC = $(TOP)/contrib
X DOCSRC = $(TOP)/doc
X DEPENDSRC = $(UTILSRC)/makedepend
X IMAKESRC = $(UTILSRC)/imake
X IRULESRC = $(UTILSRC)/imake.includes
X RGBSRC = $(UTILSRC)/rgb
X XLIBSRC = $(LIBSRC)/X
X TOOLKITSRC = $(LIBSRC)/Xt
X AWIDGETSRC = $(LIBSRC)/Xaw
X OLDXLIBSRC = $(LIBSRC)/oldX
X EXTENSIONSRC = $(TOP)/extensions
X XMANSRC = $(DOCSRC)/Xlib/Xman
X EXTENSIONLIB = $(EXTENSIONSRC)/lib/libXext.a
X XLIB = $(XLIBSRC)/libX11.a
X OLDXLIB = $(OLDXLIBSRC)/liboldX.a
X XTOOLLIB = $(TOOLKITSRC)/libXt.a
X XAWLIB = $(AWIDGETSRC)/libXaw.a
X LINTXLIB = $(XLIBSRC)/llib-lX11.ln
X LINTXTOOL = $(TOOLKITSRC)/llib-lXt.ln
X LINTXAW = $(AWIDGETSRC)/llib-lXaw.ln
X INCLUDES = -I$(TOP)
X MACROFILE = Sun.macros
X IMAKE_CMD = $(NEWTOP)$(IMAKE) -TImake.tmpl \
X -I$(NEWTOP)$(IRULESRC) \
X -s Makefile
X RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a \
X tags TAGS make.log
X
XLOCAL_LIBRARIES = $(XLIB)
XOBJS = bitimp.o readump.o swap.o
X
X PROGRAM = bitimp
X
Xall:: bitimp
X
Xbitimp: $(OBJS) $(LOCAL_LIBRARIES)
X $(RM) $@
X $(CC) -o $@ $(OBJS) $(LOCAL_LIBRARIES) $(LDFLAGS)
X
Xrelink::
X $(RM) $(PROGRAM)
X $(MAKE) $(MFLAGS) $(PROGRAM)
X
Xinstall:: bitimp
X $(INSTALL) -c $(INSTALLFLAGS) bitimp $(BINDIR)
X
Xinstall:: bitimp.man
X $(INSTALL) -c $(INSTMANFLAGS) bitimp.man $(MANDIR)/bitimp.1
X
Xdepend:: $(DEPEND)
X
Xdepend::
X $(DEPEND) -s "# DO NOT DELETE" $(CFLAGS) $(SRCS)
X
X$(DEPEND):
X @echo "making $(DEPENDSRC)"; \
X cd $(DEPENDSRC); $(MAKE)
X
Xclean::
X $(RM) $(PROGRAM)
X
Xall:: xipr
X
Xxipr: xipr.sh
X cp xipr.sh xipr
X
Xinstall:: xipr
X $(INSTALL) -c $(INSTALLFLAGS) xipr $(BINDIR)
X
Xinstall:: xipr.man
X $(INSTALL) -c $(INSTMANFLAGS) xipr.man $(MANDIR)/xipr.1
X
Xclean::
X $(RM_CMD) \#*
X
XMakefile:: $(IMAKE)
X
XMakefile:: Imakefile \
X $(IRULESRC)/Imake.tmpl \
X $(IRULESRC)/Imake.rules \
X $(IRULESRC)/$(MACROFILE)
X -$(RM) Makefile.bak; $(MV) Makefile Makefile.bak
X $(IMAKE_CMD) -DTOPDIR=$(TOP)
X
X$(IMAKE):
X @echo "making $(IMAKESRC)"; \
X cd $(IMAKESRC); $(MAKE)
X
Xtags::
X $(TAGS) -w *.[ch]
X $(TAGS) -xw *.[ch] > TAGS
X
Xinstall::
X @echo "install done"
X
XMakefiles::
X
END_OF_FILE
if test 4110 -ne `wc -c <'Makefile'`; then
echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'bitimp.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'bitimp.c'\"
else
echo shar: Extracting \"'bitimp.c'\" \(15224 characters\)
sed "s/^X//" >'bitimp.c' <<'END_OF_FILE'
X/* bitimp.c - generic bitmap to imPress program */
X
X/* Based (loosely) on Dan Winkler's <winkler at harvard> version for
X UNIX, based on Ed Pattermann's (at Stanford) version for TOPS20.
X
X Also based on Walter Underwood's <wunder at ford-wdl1> program called
X sunimp, which was based on Winkler's macimp.
X*/
X
X
X#include <signal.h>
X#include <stdio.h>
X#include <strings.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include "newimPcodes.h"
X
X
X#define NOTOK (-1)
X#define OK 0
X
X
X#define NULLCP ((char *) 0)
X
X#define istr(s) ((s) && *(s))
X
X/* */
X
X#define WHITE 0 /* should be in newimPcodes.h */
X#define SHADE 3
X#define OR 7
X#define BLACK 15
X
X
X#define RESOLUTION 300
X
X
X#define GenH 512
X#define GenV 512
X#define GenS 8
X
X#define MagMin 0
X#define MagM 1
X#define MagMax 2
X
X
X#define BitRd1() Rd1 (BitIn)
X#define BitRd4() Rd4 (BitIn)
X
X
X#define Rd1(f) getc (f) /* nothing fancy here... */
X
X
X#define ImWrt1(s) Wrt1 (ImOut, s)
X#define ImWrt2(s) Wrt2 (ImOut, s)
X#define ImWrtS(adr,len) WrtS (ImOut, adr, len, verbose ? VbOut : NULL)
X
X#define ImWrtC(s) { \
X static char buffer[] = s; \
X ImWrtS (buffer, sizeof buffer - 1); \
X }
X#define ImWrtD(s) ImWrtS (s, strlen (s))
X
X
X#define Wrt1(f,c) putc (c & 0xff, f)
X
X/* */
X
Xtypedef int (*IFP) ();
X
X#ifdef is68k
Xint ISwork ();
X#endif
Xint MACwork (), SUNwork (), XWDwork (), GENwork ();
X
Xstruct symbol {
X char *sy_name;
X IFP sy_fnx;
X} symbols[] = {
X "genimp", GENwork,
X#ifdef is68k
X "isimp", ISwork,
X#endif
X "macimp", MACwork,
X "sunimp", SUNwork,
X "xwdimp", XWDwork,
X NULL, XWDwork
X};
X
Xstruct symbol *sy;
X
X/* */
X
Xint debug = 0;
Xint gensplit = GenS;
Xint genheight = GenV;
Xint genwidth = GenH;
Xint landscape = 0;
Xint magnification = MagM;
Xint operation = SHADE;
Xint pageno = 0;
Xint PixPerIn = RESOLUTION;
Xint PixPerInX = RESOLUTION;
Xint PixPerInY = RESOLUTION;
Xint print = 1;
Xint remove = 0;
Xint reverse = 0;
Xint StdOutput = 0;
Xint temporary = 0;
Xint verbose = 0;
X
Xchar *myname = "bitimp";
Xchar *banner = NULL;
Xchar *copies = NULL;
Xchar *document = NULL;
Xchar *filename = NULL;
Xchar *header = "on";
Xchar *host = NULL;
Xchar *infile = NULL;
Xchar *jobname = NULL;
Xchar *outfile = NULL;
Xchar *printer = NULL;
Xchar *user = NULL;
X
X
XFILE *BitIn;
XFILE *ImOut;
XFILE *VbOut = stderr;
X
Xint sigser ();
X
X
Xchar *calloc (), *mktemp ();
X
X/* */
X
X/* ARGSUSED */
X
Xmain (argc, argv, envp)
Xint argc;
Xchar **argv,
X **envp;
X{
X arginit (argv);
X siginit ();
X
X BitJob ();
X imPjob ();
X
X (*sy -> sy_fnx) ();
X
X BitFin ();
X imPfin ();
X
X exit (0);
X}
X
X/* ARGS */
X
Xarginit (vec)
Xchar **vec;
X{
X char *cp;
X struct symbol *sp;
X
X if (myname = rindex (*vec, '/'))
X myname++;
X if (myname == NULL || *myname == NULL)
X myname = *vec;
X
X StdOutput = !isatty (fileno (stdout));
X
X for (sy = symbols; sy -> sy_name; sy++)
X if (strcmp (sy -> sy_name, myname) == 0)
X break;
X
X for (vec++; *vec; vec++)
X if (*(cp = *vec) == '-')
X switch (*++cp) {
X case 'a':
X if (!*++cp)
X cp = *++vec;
X for (sp = symbols; sp -> sy_name; sp++)
X if (strncmp (sp -> sy_name, cp, strlen (cp)) == 0)
X break;
X if (sp -> sy_name)
X sy = sp;
X break;
X
X case 'b':
X banner = *++cp ? cp : *++vec;
X break;
X
X case 'c':
X copies = *++cp ? cp : *++vec;
X break;
X
X case 'd':
X debug = 1;
X break;
X
X case 'f':
X filename = *++cp ? cp : *++vec;
X break;
X
X case 'g':
X switch (*++cp) {
X case 's':
X gensplit = atoi (*++cp ? cp : *++vec);
X if (gensplit != GenS || gensplit != 0)
X adios (NULLCP, "bad value to -gs");
X break;
X
X case 'h':
X case 'x':
X genwidth = atoi (*++cp ? cp : *++vec);
X break;
X
X case 'v':
X case 'y':
X genheight = atoi (*++cp ? cp : *++vec);
X break;
X
X default:
X genheight = genwidth = atoi (*++cp ? cp : *++vec);
X break;
X }
X break;
X
X case 'h':
X header = "off";
X break;
X
X case 'i':
X outfile = *++cp ? cp : *++vec;
X print = StdOutput = 0;
X break;
X
X case 'l':
X landscape++;
X break;
X
X case 'p':
X print = 1;
X StdOutput = 0;
X break;
X
X case 'r':
X remove = 1;
X break;
X
X case 's':
X StdOutput = 1;
X print = 0;
X break;
X
X case 't':
X reverse = !reverse;
X break;
X
X case 'v':
X verbose = 1;
X break;
X
X case 'D':
X document = ++cp;
X break;
X
X case 'H':
X host = ++cp;
X break;
X
X case 'J':
X jobname = ++cp;
X break;
X
X case 'M':
X magnification = atoi (++cp);
X if (magnification < MagMin || magnification > MagMax)
X adios (NULLCP, "bad value to -M");
X break;
X
X case 'P':
X printer = *++cp ? cp : *++vec;
X break;
X
X case 'R':
X PixPerIn = atoi (++cp);
X break;
X
X case 'U':
X user = ++cp;
X break;
X
X default:
X adios (NULLCP, "unknown switch \"%s\"", *vec);
X }
X else
X if (infile)
X adios (NULLCP, "too many input files (starting with %s)", *vec);
X else
X infile = *vec;
X
X if (!sy -> sy_name) {
X for (sp = symbols; sp -> sy_name; sp++)
X if (sp -> sy_fnx == sy -> sy_fnx)
X break;
X if (!sp -> sy_name)
X adios (NULLCP, "chaos at symbols[%d]", sy - symbols);
X sy = sp;
X }
X
X if (verbose)
X fprintf (VbOut, "Mode=%s Magnification=%d PixPerIn=%d\n",
X sy -> sy_name, magnification, PixPerIn);
X}
X
X/* Bit */
X
XBitJob () {
X if (!istr (infile) || !strcmp (infile, "-")) {
X if (!istr (banner))
X banner = "(stdin)";
X BitIn = stdin;
X if (verbose)
X fprintf (VbOut, "Input file is (stdin)\n");
X }
X else
X if ((BitIn = fopen (infile, "r")) == NULL)
X adios (infile, "unable to read");
X else
X if (verbose)
X fprintf (VbOut, "Input file is %s\n", infile);
X}
X
XBitFin () {
X struct stat st;
X
X if (remove
X && BitIn != stdin
X && stat (infile, &st) != NOTOK
X && (st.st_mode & S_IFMT) == S_IFREG)
X (void) unlink (infile);
X}
X
X/* imP */
X
XimPjob () {
X static char tmpfile[BUFSIZ];
X
X if (StdOutput)
X outfile = "-";
X else
X if (!istr (outfile)) {
X outfile = mktemp (sprintf (tmpfile, "/tmp/%sXXXXXX", myname));
X temporary = 1;
X }
X if (!strcmp (outfile, "-")) {
X ImOut = stdout;
X if (verbose)
X fprintf (VbOut, "Output file is (stdout)\n");
X }
X else
X if ((ImOut = fopen (outfile, "w")) == NULL)
X adios (outfile, "unable to write");
X else
X if (verbose)
X fprintf (VbOut, "Output file is %s%s\n",
X outfile, print ? " (spool)" : "");
X
X ImWrtC ("@document(language imPress, jobheader ");
X ImWrtD (header);
X ImWrtC (", name \"");
X if (istr (jobname))
X ImWrtD (jobname);
X else
X if (istr (filename))
X ImWrtD (filename);
X else
X if (istr (infile))
X ImWrtD (infile);
X else
X if (istr (banner))
X ImWrtD (banner);
X else
X ImWrtC ("(stdin)");
X ImWrtC ("\"");
X
X/* */
X
X if (istr (document)) {
X ImWrtC (", ");
X ImWrtD (document);
X }
X if (istr (user)) {
X ImWrtC (", owner ");
X ImWrtD (user);
X }
X if (istr (host)) {
X ImWrtC (" at ");
X ImWrtD (host);
X ImWrtC (", site ");
X ImWrtD (host);
X }
X if (istr (copies)) {
X ImWrtC (", copies ");
X ImWrtD (copies);
X ImWrtC (", pagecollation");
X }
X if (reverse)
X ImWrtC (", pagereversal");
X ImWrtC (")");
X if (verbose)
X fprintf (VbOut, "\n");
X}
X
X/* */
X
XimPfin () {
X int vecp;
X char *vec[10];
X
X if (verbose && pageno > 0)
X fprintf (VbOut, "\n");
X
X ImWrt1 (imP_EOF);
X
X if (ImOut != stdout && fclose (ImOut))
X adios (outfile, "output error");
X
X if (print && ImOut != stdout) {
X vecp = 0;
X vec[vecp++] = "lpr";
X vec[vecp++] = "-v";
X if (istr (printer))
X vec[vecp++] = "-P", vec[vecp++] = printer;
X if (temporary)
X vec[vecp++] = "-r";
X vec[vecp++] = outfile;
X vec[vecp] = NULL;
X execvp ("lpr", vec);
X adios ("lpr", "unable to exec");
X }
X}
X
X/* imPress */
X
X#define PSIZE 32
X#define PBYTES 4
X
Xtypedef char patch[PSIZE][PBYTES];
X
Xint patchH;
Xint patchV;
Xint patchP;
X
Xpatch *patches;
X
X
XimPbegin (pixperinx, pixperiny, width, height)
Xint pixperinx,
X pixperiny,
X width,
X height;
X{
X PixPerInX = pixperinx;
X PixPerInY = pixperiny;
X if (verbose)
X fprintf (VbOut, "PixPerInX=%d PixPerInY=%d height=%d width=%d\n",
X PixPerInX, PixPerInY, height, width);
X
X if (width % PSIZE)
X adios (NULLCP, "bitmap width %d not a multiple of %d", width, PSIZE);
X
X patchH = (width + (PSIZE - 1)) / PSIZE;
X patchV = (height + (PSIZE - 1)) / PSIZE;
X patchP = (patchH * PBYTES) * (patchV * PSIZE) - (patchH * PBYTES) * height;
X if (verbose)
X fprintf (VbOut, "patchH=%d patchV=%d patchP=%d\n",
X patchH, patchV, patchP);
X
X imPbop ();
X
X if ((patches = (patch *) calloc ((unsigned) patchH, sizeof (patch)))
X == NULL)
X adios (NULLCP, "insufficient memory for patch array");
X}
X
X/* */
X
XimPbop () {
X if (landscape)
X ImWrt1 (imP_SET_HV_SYSTEM), ImWrt1 (0105);
X
X ImWrt1 (imP_SET_ABS_H), ImWrt2 (PixPerInX);
X
X ImWrt1 (imP_SET_ABS_V), ImWrt2 (PixPerInY);
X
X ImWrt1 (imP_SET_MAGN), ImWrt1 (magnification);
X
X ImWrt1 (imP_BITMAP), ImWrt1 (operation), ImWrt1 (patchH), ImWrt1 (patchV);
X}
X
X
X#define imPeop imPend
X
XimPend () {
X register int i;
X
X for (i = 0; i < patchP; i++)
X imPmap ((unsigned char) 0x00);
X
X ImWrt1 (imP_ENDPAGE);
X
X pageno++;
X if (verbose)
X fprintf (VbOut, "%s[%d]%s", pageno % 10 != 1 ? " " : "", pageno,
X pageno % 10 == 0 ? "\n" : "");
X}
X
X/* */
X
XimPmap (c)
Xunsigned char c;
X{
X register int i,
X j,
X k;
X static int n,
X row,
X col;
X
X patches[n][row][col] = c;
X
X if (++col >= PBYTES) {
X col = 0;
X if (++n >= patchH) {
X n = 0;
X if (++row >= PSIZE) {
X row = 0;
X for (i = 0; i < patchH; i++)
X for (j = 0; j < PSIZE; j++)
X for (k = 0; k < PBYTES; k++)
X ImWrt1 (patches[i][j][k]);
X }
X }
X }
X}
X
X/* GEN */
X
XGENwork () {
X int c,
X i,
X j;
X
X imPbegin (PixPerIn, PixPerIn, genwidth, genheight);
X
X if (patchP)
X gensplit = 0;
X if (gensplit) {
X i = 0;
X j = (genwidth * genheight) / gensplit;
X }
X
X while ((c = BitRd1 ()) != EOF) {
X imPmap ((unsigned char) c);
X if (gensplit && ++i == j)
X i = 0, imPeop (), imPbop ();
X }
X
X if (gensplit || i)
X imPend ();
X}
X
X/* IS68K */
X
X#ifdef is68k
X#include <bitmap.h>
X
X
XISwork () {
X register int c,
X i,
X j,
X k,
X slop;
X struct bitmap bm;
X
X if (fread ((char *) &bm, sizeof bm, 1, BitIn) != 1)
X adios (NULLCP, "eof reading bitmap header");
X if (bm.b_magic != BMAGIC)
X advise (NULLCP, "bad IS68K magic number 0x%x, expecting 0x%x",
X bm.b_magic, BMAGIC);
X
X slop = (i = bm.b_width % PSIZE) ? PSIZE - i : 0;
X
X imPbegin (bm.b_hres, bm.b_vres, bm.b_width + slop, bm.b_height);
X
X k = ((bm.b_width - 1) / 8) + 1;
X if (slop)
X slop = (bm.b_width + slop) / 8 - k;
X
X for (i = bm.b_height; i > 0; i--) {
X for (j = k; j > 0; j--)
X if ((c = BitRd1 ()) != EOF)
X imPmap ((unsigned char) (c ^ 0xff));
X else
X adios (NULLCP, "eof reading raster");
X
X if (k % 2) /* IS pads to short boundaries */
X (void) BitRd1 ();
X
X for (j = slop; j > 0; j--) /* Imagen pads to PSIZE boundaries */
X imPmap ((unsigned char) 0x00);
X }
X
X imPend ();
X}
X#endif
X
X/* MAC */
X
X#define MacHdrSize 512
X
X#define MacH 576
X#define MacV 720
X
X
XMACwork () {
X register int c,
X i,
X n;
X
X for (i = 0; i < MacHdrSize; i++)
X (void) BitRd1 ();
X
X imPbegin (PixPerIn, PixPerIn, MacH, MacV);
X
X while ((c = BitRd1 ()) != EOF)
X if (c > 127)
X for (i = 0, n = 256 - c + 1, c = BitRd1 (); i < n; i++)
X imPmap ((unsigned char) c);
X else
X for (i = 0, n = c + 1; i < n; i++)
X imPmap ((unsigned char) BitRd1 ());
X
X imPend ();
X}
X
X/* SUN */
X
X#include "rasterfile.h"
X
X
XSUNwork () {
X register int c,
X i;
X struct rasterfile rf;
X
X rf.ras_magic = BitRd4 ();
X if (feof (BitIn))
X exit (0);
X if (rf.ras_magic != RAS_MAGIC)
X advise (NULLCP, "bad SUN magic number 0x%x, expecting",
X rf.ras_magic, RAS_MAGIC);
X rf.ras_width = BitRd4 ();
X rf.ras_height = BitRd4 ();
X if ((rf.ras_depth = BitRd4 ()) != 1)
X adios (NULLCP, "pixel depth too deep (%d)", rf.ras_depth);
X if ((rf.ras_encoding = BitRd4 ()) != 0)
X adios (NULLCP, "bitmap not encoded raw (%d)", rf.ras_encoding);
X if ((rf.ras_type = BitRd4 ()) != 0)
X advise (NULLCP, "bitmap type non-zero (%d)", rf.ras_type);
X rf.ras_maptype = BitRd4 ();
X rf.ras_maplength = BitRd4 ();
X for (i = 0; i < rf.ras_maplength; i++)
X (void) BitRd1 ();
X
X imPbegin (PixPerIn / 4, PixPerIn, rf.ras_width, rf.ras_height);
X
X while ((c = BitRd1 ()) != EOF)
X imPmap ((unsigned char) c);
X
X imPend ();
X}
X
X/* XWD */
X
X#include <X11/Xlib.h>
X#include <X11/XWDFile.h>
X
X
XXWDwork () {
X int i,
X j,
X k,
X slop;
X unsigned nbytes;
X register char *cp;
X char *raster;
X XWDFileHeader xwd;
X
X if ((i = XReadDumpFP (BitIn, &xwd, (char **) 0, &raster)) <= 0)
X adios (NULLCP, "window dump file is in bad format");
X
X slop = (i = xwd.pixmap_width % PSIZE) ? PSIZE - i : 0;
X
X imPbegin (PixPerIn, PixPerIn, xwd.pixmap_width + slop, xwd.pixmap_height);
X
X k = xwd.bytes_per_line;
X
X if (slop)
X slop = (xwd.pixmap_width + slop) / 8 - k;
X
X cp = raster;
X for (i = xwd.pixmap_height; i > 0; i--) {
X for (j = k; j > 0; j--)
X imPmap ((unsigned char) (*cp++));
X
X for (j = slop; j > 0; j--) /* Imagen pads to PSIZE boundaries */
X imPmap ((unsigned char) 0x00);
X }
X
X imPend ();
X
X free ((char *) raster);
X}
X
X/* I/O */
X
Xint Rd2 (stream)
XFILE *stream;
X{
X register int value;
X
X value = Rd1 (stream) << 8;
X value |= Rd1 (stream) & 0xff;
X return value;
X}
X
X
Xint Rd4 (stream)
XFILE *stream;
X{
X register int value;
X
X value = Rd2 (stream) << 16;
X value |= Rd2 (stream) & 0xffff;
X return value;
X}
X
X/* */
X
XWrtS (stream, s, n, aux)
XFILE *stream,
X *aux;
Xchar *s;
Xint n;
X{
X if (n <= 0)
X return;
X
X if (aux)
X (void) fwrite (s, 1, n, aux);
X if (fwrite (s, 1, n, stream) != n)
X adios (NULLCP, "output error");
X}
X
X
XWrt2 (stream, c)
XFILE *stream;
Xint c;
X{
X Wrt1 (stream, (c >> 8) & 0xff);
X Wrt1 (stream, c & 0xff);
X}
X
X/* SIGNALS */
X
Xsiginit () {
X if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
X (void) signal (SIGHUP, sigser);
X if (signal (SIGQUIT, SIG_IGN) != SIG_IGN)
X (void) signal (SIGQUIT, sigser);
X if (signal (SIGINT, SIG_IGN) != SIG_IGN)
X (void) signal (SIGINT, sigser);
X}
X
X
X/* ARGSUSED */
X
Xsigser (sig, code, sc)
Xint sig;
Xlong code;
Xstruct sigcontext *sc;
X{
X exit (1);
X}
X
X/* ERROR HANDLING */
X
X/* VARARGS2 */
X
Xadvise (what, fmt, a, b, c, d)
Xchar *what,
X *fmt,
X *a,
X *b,
X *c,
X *d;
X{
X (void) fflush (stdout);
X
X fprintf (stderr, "%s: ", myname);
X fprintf (stderr, fmt, a, b, c, d);
X if (what)
X (void) putc (' ', stderr), perror (what);
X else
X (void) putc ('\n', stderr);
X (void) fflush (stderr);
X}
X
X
X/* VARARGS2 */
X
Xadios (what, fmt, a, b, c, d)
Xchar *what,
X *fmt,
X *a,
X *b,
X *c,
X *d;
X{
X advise (what, fmt, a, b, c, d);
X exit (1);
X}
END_OF_FILE
if test 15224 -ne `wc -c <'bitimp.c'`; then
echo shar: \"'bitimp.c'\" unpacked with wrong size!
fi
# end of 'bitimp.c'
fi
if test -f 'bitimp.man' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'bitimp.man'\"
else
echo shar: Extracting \"'bitimp.man'\" \(2803 characters\)
sed "s/^X//" >'bitimp.man' <<'END_OF_FILE'
X.TH BITIMP 1 LOCAL
X.SH NAME
Xbitimp \- generic bitmap to imPress program
X.SH SYNOPSIS
X\fBbitimp\fR
X\%[options]
X\%[Ifile]
X.SH DESCRIPTION
X\fIbitimp\fR converts a bitmap \fIfile\fR
Xto imPress format for printing on an IMAGEN printer.
X.PP
XThe options are:
X.TP
X.BI \-a\0 mode
XSets \fIbitimp's\fR mode of operation to \fImode\fR,
Xwhich may be one of \fIgenimp\fR,
X\fIisimp\fR, \fImacimp\fR, \fIsunimp\fR or \fIxwdimp\fR,
X(default taken from the invocation line if possible,
Xotherwise the default is \fIxwdimp\fR.)
X.TP
X.BI \-b\0 string
XSets the banner string for the job.
X.TP
X.BI \-c\0 n
XPrints \fIn\fR copies.
XSince this is done via the Imagen DCL,
Xthis switch is meaningful even if the output is not to be immediately printed.
X.TP
X.B \-d
XTurns on debugging.
X.TP
X.BI \-f\0 string
XIdentifies \fIstring\fR as the value of the variable \fBfile\fR in the DCL.
X.TP
X.BI \-gs\0 num
XFor \fIgenimp\fR mode,
Xindicates that \fInum\fR bitmaps are in the input stream.
X(default 8)
X.TP
X.BI \-gh\0 num
XFor \fIgenimp\fR mode,
Xindicates that each bitmap is \fInum\fR bits wide.
X(default 512)
X.TP
X.BI \-gv\0 num
XFor \fIgenimp\fR mode,
Xindicates that each bitmap is \fInum\fR bits tall.
X(default 512)
X.TP
X.BI \-g\0 num
XFor \fIgenimp\fR mode,
Xindicates that each bitmap is \fInum\fR bits wide and tall.
X(default 512)
X.TP
X.B \-h
XPrevents a banner page for being printed for this job.
X.TP
X.BI \-i\0 file
XDirects \fIbitimp\fR to send its output to the named file.
XThis disables the \fI\-p\fR and \fI\-s\fR switches.
X.TP
X.B \-l
XPrint in landscape mode.
X.TP
X.B \-p
XDirects \fIbitimp\fR to spool its output for printing.
XThis disables the \fI\-s\fR switch.
X(default OFF unless stdout is a tty)
X.TP
X.B \-r
XDirects \fIbitimp\fR to remove its input file if everything goes well.
X.TP
X.B \-s
XDirects \fIbitimp\fR to send its output to the standard output.
XThis diables the \fI\-i\fR and \fI\-p\fR switches.
X(default ON unless stdout is a tty)
X.TP
X.B \-t
XToggles page reversal for the job.
XIf the job is to be sent to an Imagen 12/300,
Xpagereversal actually does the wrong thing.
X.TP
X.B \-v
XTurns on verbose output to the diagnostic output.
X.TP
X.BI \-D\0 string
XIdentifies \fIstring\fR to be appended to the DCL for the job.
X.TP
X.BI \-H\0 host
XIdentifies the \fIhost\fR of the user spooling the job.
X.TP
X.BI \-J\0 string
XIdentifies \fIstring\fR as the name of this job.
X.TP
X.BI \-M\0 num
XSets the bitmap magnification to two raised to the \fInum\fR.
X\fInum\fR may be 0, 1, or 2.
X(default 1)
X.TP
X.BI \-P\0 printer
XSets the printer for this job.
X.TP
X.BI \-R\0 resolution
XSets the resolution of the printer for this job.
X(default 300)
X.TP
X.BI \-U\0 user
XIdentifies the \fIuser\fR spooling the job.
X.SH "SEE ALSO"
Xiprint(1), catimp(1), dviimp(1)
X.SH DIAGNOSTICS
XObvious.
X.SH BUGS
XFor \fIxwdimp\fR,
Xonly XY pixmaps of a single plane are handled.
END_OF_FILE
if test 2803 -ne `wc -c <'bitimp.man'`; then
echo shar: \"'bitimp.man'\" unpacked with wrong size!
fi
# end of 'bitimp.man'
fi
if test -f 'newimPcodes.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'newimPcodes.h'\"
else
echo shar: Extracting \"'newimPcodes.h'\" \(1279 characters\)
sed "s/^X//" >'newimPcodes.h' <<'END_OF_FILE'
X
X
X#define imP_SP 128
X#define imP_SP1 129
X#define imP_OLD_MMOVE 130
X#define imP_MPLUS 131
X#define imP_MMINUS 132
X#define imP_MMOVE 133
X#define imP_SMOVE 134
X
X#define imP_SET_ABS_H 135
X#define imP_SET_REL_H 136
X#define imP_SET_ABS_V 137
X#define imP_SET_REL_V 138
X
X#define imP_SRULE 192
X#define imP_BRULE 193
X
X#define imP_SET_HPOS 195
X#define imP_SET_VPOS 196
X#define imP_CRLF 197
X#define imP_SGLY 198
X#define imP_BGLY 199
X#define imP_DELG 200
X#define imP_DELC 201
X#define imP_DELF 202
X
X#define imP_SET_HV_SYSTEM 205
X#define imP_SET_ADV_DIRS 206
X#define imP_SET_FAMILY 207
X#define imP_SET_IL 208
X#define imP_SET_BOL 209
X#define imP_SET_SP 210
X#define imP_PUSH 211
X#define imP_POP 212
X#define imP_PAGE 213
X#define imP_SET_PUSH_MASK 214
X#define imP_ENDPAGE 219
X
X#define imP_CREATE_FAMILY_TABLE 221
X#define imP_CREATE_MAP 222
X
X#define imP_CREATE_PATH 230
X#define imP_SET_TEXTURE 231
X#define imP_SET_PEN 232
X#define imP_FILL_PATH 233
X#define imP_DRAW_PATH 234
X#define imP_BITMAP 235
X#define imP_SET_MAGN 236
X
X
X#ifdef UCI /* imPress opcodes for v1.9 and later systems */
X#define imP_CIRC_ARC 150
X#define imP_CIRC_SEGM 160
X#define imP_ELLIPSE_ARC 151
X#define imP_SET_PUM 225
X#endif UCI
X
X#ifdef UCI
X#define imP_DEFINE_MACRO 242
X#define imP_EXEC_MACRO 243
X#endif UCI
X
X#define imP_EOF 255
END_OF_FILE
if test 1279 -ne `wc -c <'newimPcodes.h'`; then
echo shar: \"'newimPcodes.h'\" unpacked with wrong size!
fi
# end of 'newimPcodes.h'
fi
if test -f 'rasterfile.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rasterfile.h'\"
else
echo shar: Extracting \"'rasterfile.h'\" \(912 characters\)
sed "s/^X//" >'rasterfile.h' <<'END_OF_FILE'
X/* @(#)rasterfile.h 1.3 84/01/06 SMI */
X
X/*
X * Description of header for files containing raster images
X */
Xstruct rasterfile {
X int ras_magic; /* magic number */
X int ras_width; /* width (pixels) of image */
X int ras_height; /* height (pixels) of image */
X int ras_depth; /* depth (1, 8, or 24 bits) of pixel */
X int ras_encoding; /* raw (0), run-length (1) */
X int ras_type; /* should be set to 0 for now */
X int ras_maptype; /* type of colormap */
X /* 1 = red[ras_maplength/3],green[...*/
X int ras_maplength; /* length (bytes) of following map */
X /* color map follows for ras_maplength bytes, followed by image */
X};
X#define RAS_MAGIC 0x59a66a95
X
X/*
X * NOTE: Each line of the image is rounded out to a multiple
X * of 16-bits. This corresponds to the rounding convention
X * used by the memory pixrect package (/usr/include/pixrect/memvar.h)
X * of the SunWindows system.
X */
END_OF_FILE
if test 912 -ne `wc -c <'rasterfile.h'`; then
echo shar: \"'rasterfile.h'\" unpacked with wrong size!
fi
# end of 'rasterfile.h'
fi
if test -f 'readump.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'readump.c'\"
else
echo shar: Extracting \"'readump.c'\" \(1988 characters\)
sed "s/^X//" >'readump.c' <<'END_OF_FILE'
X/* readump.c - read an XWD file */
X
X#include <stdio.h>
X#include <X11/X.h>
X#include <X11/Xlib.h>
X#include <X11/XWDFile.h>
X
X
Xchar *calloc ();
X
X/* */
X
X/* Reads in XWDFileHeader, window name, and possibly raster
X only supports XYFormat and one plane for now... */
X
X
Xint XReadDumpFile (filename, xwd, name, raster)
Xchar *filename;
XXWDFileHeader *xwd;
Xchar **name;
Xshort **raster;
X{
X int i;
X FILE *fp;
X
X if ((fp = fopen (filename, "r")) == NULL)
X return 0;
X
X i = XReadDumpFP (fp, xwd, name, raster);
X
X fclose (fp);
X
X return i;
X}
X
X/* */
X
Xint XReadDumpFP (fp, xwd, name, raster)
XFILE *fp;
XXWDFileHeader *xwd;
Xchar **name;
Xchar **raster;
X{
X int i;
X char *cp,
X *np;
X XColor *colors;
X
X if (fread ((char *) xwd, sizeof *xwd, 1, fp) != 1)
X return (-1);
X
X if (xwd -> file_version != XWD_FILE_VERSION
X && (xwd -> file_version != 7 || xwd -> pixmap_depth != 1))
X return (-2);
X
X if ((i = xwd -> header_size - sizeof *xwd) < 0)
X i = -i;
X if (name == NULL)
X name = &np;
X if ((*name = calloc ((unsigned) i, sizeof **name)) == NULL)
X return (-3);
X if (fread (*name, sizeof **name, i, fp) != i) {
X free (*name);
X return (-4);
X }
X
X if (raster == NULL)
X goto done;
X
X if (xwd -> pixmap_format != XYPixmap
X || xwd -> pixmap_depth != 1
X || xwd -> ncolors != 2) {
X free (*name);
X return (-5);
X }
X
X i = xwd->ncolors * sizeof(XColor);
X colors = (XColor *)malloc((unsigned)(i));
X
X if( colors == NULL )
X {
X free (*name);
X return (-6);
X }
X if (fread ((char *)colors, sizeof (char), i, fp) != i) {
X free (colors);
X free (*name);
X return (-7);
X }
X
X i = xwd->bytes_per_line * xwd->pixmap_height;
X cp = (char *)malloc(i);
X
X if( cp == NULL )
X {
X free(*name);
X free(colors);
X return(-8);
X }
X if( fread(cp, sizeof(char), i, fp) != i )
X {
X free(*name);
X free(colors);
X free(cp);
X return(-9);
X }
X *raster = cp;
X
Xdone: ;
X if (name == &np)
X free (*name);
X return (1);
X}
END_OF_FILE
if test 1988 -ne `wc -c <'readump.c'`; then
echo shar: \"'readump.c'\" unpacked with wrong size!
fi
# end of 'readump.c'
fi
if test -f 'swap.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'swap.c'\"
else
echo shar: Extracting \"'swap.c'\" \(2379 characters\)
sed "s/^X//" >'swap.c' <<'END_OF_FILE'
X/* lifted from libis for X... */
X
X/*
X * bit reverse array used by bit swapping routines
X */
Xstatic unsigned char bitrev[] = {
X 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
X 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
X 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
X 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
X 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
X 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
X 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
X 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
X 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
X 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
X 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
X 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
X 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
X 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
X 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
X 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
X 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
X 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
X 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
X 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
X 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
X 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
X 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
X 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
X 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
X 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
X 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
X 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
X 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
X 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
X 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
X 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
X};
X
XSwapShorts(wordp, bytecnt)
Xshort *wordp;
Xint bytecnt;
X{
X register unsigned char *p = (unsigned char *)wordp;
X register int cnt = bytecnt >> 1;
X while (cnt--) {
X register unsigned char tmp = *p;
X *p = *(p+1);
X *(p+1) = tmp;
X p += sizeof(short);
X }
X}
X
X/*
X * SwapBits - slow 'C' version
X *
X * swap bit 0 and bit 15, swap bit 1 and bit 14, etc.
X */
XSwapBits(wordp, bytecnt)
Xregister short *wordp;
Xint bytecnt;
X{
X register int cnt = bytecnt >> 1;
X while (cnt--) {
X *wordp = (bitrev[(unsigned char)((*wordp)>>8)]<<8) |
X (bitrev[(unsigned char)*wordp]);
X wordp++;
X }
X}
END_OF_FILE
if test 2379 -ne `wc -c <'swap.c'`; then
echo shar: \"'swap.c'\" unpacked with wrong size!
fi
# end of 'swap.c'
fi
if test -f 'xipr.man' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xipr.man'\"
else
echo shar: Extracting \"'xipr.man'\" \(639 characters\)
sed "s/^X//" >'xipr.man' <<'END_OF_FILE'
X.TH XIPR 1 "X WINDOWS"
X.SH NAME
Xxipr \- dump an X window directly to the printer
X.SH SYNOPSIS
X.in +.5i
X.ti -.5i
X.B xipr
X\%[options for \fIxwdimp\fR]
X\%[\-nobdrs]
X\%[host:display]
X.in -.5i
X.SH DESCRIPTION
X\fIXipr\fP runs \fIxwd\fR and \fIxwdimp\fR
Xto dump an X window,
Xprocess it for the Imagen laser printer,
Xand print it out.
X.SH OPTIONS
XThe `\-nobdrs' option (along with the display specification)
Xis given to \fIxwd\fR,
Xall other options are given to \fIxwdimp\fR
X.SH ENVIRONMENT
XDISPLAY \- the default host and display number
X.SH "SEE ALSO"
Xxwd(1), xdpr(1), xwud(1)
X.SH AUTHOR
XMarshall T. Rose, Northrop Research and Technology Center
END_OF_FILE
if test 639 -ne `wc -c <'xipr.man'`; then
echo shar: \"'xipr.man'\" unpacked with wrong size!
fi
# end of 'xipr.man'
fi
if test -f 'xipr.sh' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xipr.sh'\"
else
echo shar: Extracting \"'xipr.sh'\" \(434 characters\)
sed "s/^X//" >'xipr.sh' <<'END_OF_FILE'
X#! /bin/csh -f
Xset flags=() xflags=() noglob
Xunset display
Xunsetenv display
Xset display=$DISPLAY
X
Xtop:
Xif ($#argv > 0) then
X switch ($argv[1])
X case "*:*":
X set display=$argv[1]
X shift argv
X goto top
X
X case -nobdrs:
X set xflags = ($xflags $argv[1])
X shift argv
X goto top
X
X case -*:
X set flags = ($flags $argv[1])
X shift argv
X goto top
X
X endsw
Xendif
X
Xxwd -xy -display $display | bitimp $flags
END_OF_FILE
if test 434 -ne `wc -c <'xipr.sh'`; then
echo shar: \"'xipr.sh'\" unpacked with wrong size!
fi
chmod +x 'xipr.sh'
# end of 'xipr.sh'
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have the archive.
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
--
Mike Wexler(wyse!mikew) Phone: (408)433-1000 x1330
More information about the Comp.sources.x
mailing list