home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-05-31 | 30.8 KB | 1,186 lines |
- Newsgroups: comp.sources.x
- From: vafaeia@pasticcio.network.com (Amir Vafaei)
- Subject: v20i008: xclipboard - Load, save and print the X clipboard, Part01/01
- Message-ID: <1993Jun1.225208.8519@sparky.imd.sterling.com>
- X-Md4-Signature: 2a2cd466cbda73dec760e6f4dc46c7a9
- Sender: chris@sparky.imd.sterling.com (Chris Olson)
- Organization: Network Systems Corporation
- Date: Tue, 1 Jun 1993 22:52:08 GMT
- Approved: chris@sparky.imd.sterling.com
-
- Submitted-by: vafaeia@pasticcio.network.com (Amir Vafaei)
- Posting-number: Volume 20, Issue 8
- Archive-name: xclipboard/part01
- Environment: X11
-
-
- Looking thru my misc directories, I noitced a copy of XClipboard which I had
- modified a few years back. I have added a Load, Save and Print feature to
- the xclipboard. It was enjoyed quite alot by co-workers at Apertus
- Technologies, so I decided to send it out. Hope it can be of use.
-
- -Amir
-
-
- ------------------------------------------------------------------------------
- #!/bin/sh
- # This is a shell archive. Remove anything before this line,
- # then unpack it by saving it in a file and typing "sh file"
- # Created Tue May 25 14:19:13 1993
- #
- # This archive contains:
- # xclipboard
- # xclipboard/CHANGES
- # xclipboard/Imakefile
- # xclipboard/Makefile
- # xclipboard/XClipboard.ad
- # xclipboard/xclipboard.c
- # xclipboard/xclipboard.man
- echo "Creating xclipboard"
- mkdir xclipboard
- echo "Creating xclipboard/CHANGES"
- cat > xclipboard/CHANGES <<"***EOF xclipboard/CHANGES***"
- The following changes have been made to this directory since R3:
-
- o removed Save to Tempfile.
- o added paging and sensitivity.
- o use CLIPBOARD_MANAGER to assert control.
- o make work with new text widget.
-
- o Added load, save and print capability. Amir Vafaei
- ***EOF xclipboard/CHANGES***
- echo "Creating xclipboard/Imakefile"
- cat > xclipboard/Imakefile <<"***EOF xclipboard/Imakefile***"
- #ifdef BandAidCompiler
- #include BandAidCompiler
- #endif
-
- SRCS1 = xclipboard.c
- OBJS1 = xclipboard.o
- SRCS2 = xcutsel.c
- OBJS2 = xcutsel.o
- PROGRAMS = xclipboard xcutsel
- DEPLIBS = XawClientDepLibs
- LOCAL_LIBRARIES = XawClientLibs
-
- ComplexProgramTarget_1(xclipboard,$(LOCAL_LIBRARIES), /**/)
- ComplexProgramTarget_2(xcutsel,$(LOCAL_LIBRARIES), /**/)
-
- InstallAppDefaults(XClipboard)
- ***EOF xclipboard/Imakefile***
- echo "Creating xclipboard/Makefile"
- cat > xclipboard/Makefile <<"***EOF xclipboard/Makefile***"
- # Makefile generated by imake - do not edit!
- # $XConsortium: imake.c,v 1.51 89/12/12 12:37:30 jim Exp $
- #
- # The cpp used on this machine replaces all newlines and multiple tabs and
- # spaces in a macro expansion with a single space. Imake tries to compensate
- # for this, but is not always successful.
- #
-
- ###########################################################################
- # Makefile generated from "Imake.tmpl" and <Imakefile>
- # $XConsortium: Imake.tmpl,v 1.77 89/12/18 17:01:37 jim Exp $
- #
- # Platform-specific parameters may be set in the appropriate .cf
- # configuration files. Site-wide parameters may be set in the file
- # site.def. Full rebuilds are recommended if any parameters are changed.
- #
- # If your C preprocessor doesn't define any unique symbols, you'll need
- # to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
- # "make Makefile", "make Makefiles", or "make World").
- #
- # If you absolutely can't get imake to work, you'll need to set the
- # variables at the top of each Makefile as well as the dependencies at the
- # bottom (makedepend will do this automatically).
- #
-
- ###########################################################################
- # platform-specific configuration parameters - edit sun.cf to change
-
- # platform: $XConsortium: sun.cf,v 1.38 89/12/23 16:10:10 jim Exp $
- # operating system: SunOS 4.0.3
-
- ###########################################################################
- # site-specific configuration parameters - edit site.def to change
-
- # site: $XConsortium: site.def,v 1.21 89/12/06 11:46:50 jim Exp $
-
- SHELL = /bin/sh
-
- TOP = ../../.
- CURRENT_DIR = ./clients/xclipboard
-
- AR = ar cq
- BOOTSTRAPCFLAGS =
- CC = cc
-
- COMPRESS = compress
- CPP = /lib/cpp $(STD_CPP_DEFINES)
- PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
- INSTALL = install
- LD = ld
- LINT = lint
- LINTLIBFLAG = -C
- LINTOPTS = -axz
- LN = ln -s
- MAKE = make
- MV = mv
- CP = cp
- RANLIB = ranlib
- RANLIBINSTFLAGS =
- RM = rm -f
- STD_INCLUDES =
- STD_CPP_DEFINES =
- STD_DEFINES =
- EXTRA_LOAD_FLAGS =
- EXTRA_LIBRARIES =
- TAGS = ctags
-
- SHAREDCODEDEF = -DSHAREDCODE
- SHLIBDEF = -DSUNSHLIB
-
- PROTO_DEFINES =
-
- INSTPGMFLAGS =
-
- INSTBINFLAGS = -m 0755
- INSTUIDFLAGS = -m 4755
- INSTLIBFLAGS = -m 0664
- INSTINCFLAGS = -m 0444
- INSTMANFLAGS = -m 0444
- INSTDATFLAGS = -m 0444
- INSTKMEMFLAGS = -m 4755
-
- DESTDIR =
-
- # TOP_INCLUDES = -I$(TOP)
- TOP_INCLUDES =
-
- CDEBUGFLAGS = -O
- CCOPTIONS =
- COMPATFLAGS =
-
- ALLINCLUDES = $(STD_INCLUDES) $(TOP_INCLUDES) $(INCLUDES) $(EXTRA_INCLUDES)
- ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(PROTO_DEFINES) $(DEFINES) $(COMPATFLAGS)
- CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
- LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
- LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
- LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS)
- LDCOMBINEFLAGS = -X -r
-
- MACROFILE = sun.cf
- RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
-
- IMAKE_DEFINES =
-
- IRULESRC = $(CONFIGSRC)
- IMAKE_CMD = $(NEWTOP)$(IMAKE) -I$(NEWTOP)$(IRULESRC) $(IMAKE_DEFINES)
-
- ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
- $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
- $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
-
- ###########################################################################
- # X Window System Build Parameters
- # $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
-
- ###########################################################################
- # X Window System make variables; this need to be coordinated with rules
- # $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
-
- PATHSEP = /
- USRLIBDIR = $(DESTDIR)/usr/lib
- BINDIR = $(DESTDIR)/usr/bin/X11
- INCROOT = $(DESTDIR)/usr/include
- BUILDINCROOT = $(TOP)
- BUILDINCDIR = $(BUILDINCROOT)/X11
- BUILDINCTOP = ..
- INCDIR = $(INCROOT)/X11
- ADMDIR = $(DESTDIR)/usr/adm
- LIBDIR = $(USRLIBDIR)/X11
- CONFIGDIR = $(LIBDIR)/config
- LINTLIBDIR = $(USRLIBDIR)/lint
-
- FONTDIR = $(LIBDIR)/fonts
- XINITDIR = $(LIBDIR)/xinit
- XDMDIR = $(LIBDIR)/xdm
- AWMDIR = $(LIBDIR)/awm
- TWMDIR = $(LIBDIR)/twm
- GWMDIR = $(LIBDIR)/gwm
- MANPATH = $(DESTDIR)/usr/man
- MANSOURCEPATH = $(MANPATH)/man
- MANDIR = $(MANSOURCEPATH)n
- LIBMANDIR = $(MANSOURCEPATH)3
- XAPPLOADDIR = $(LIBDIR)/app-defaults
-
- SOXLIBREV = 4.2
- SOXTREV = 4.0
- SOXAWREV = 4.0
- SOOLDXREV = 4.0
- SOXMUREV = 4.0
- SOXEXTREV = 4.0
-
- FONTCFLAGS = -t
-
- INSTAPPFLAGS = $(INSTDATFLAGS)
-
- IMAKE = $(IMAKESRC)/imake
- DEPEND = $(DEPENDSRC)/makedepend
- RGB = $(RGBSRC)/rgb
- FONTC = $(BDFTOSNFSRC)/bdftosnf
- MKFONTDIR = $(MKFONTDIRSRC)/mkfontdir
- MKDIRHIER = /bin/sh $(SCRIPTSRC)/mkdirhier.sh
-
- CONFIGSRC = $(TOP)/config
- CLIENTSRC = $(TOP)/clients
- DEMOSRC = $(TOP)/demos
- LIBSRC = $(TOP)/lib
- FONTSRC = $(TOP)/fonts
- INCLUDESRC = $(TOP)/X11
- SERVERSRC = $(TOP)/server
- UTILSRC = $(TOP)/util
- SCRIPTSRC = $(UTILSRC)/scripts
- EXAMPLESRC = $(TOP)/examples
- CONTRIBSRC = $(TOP)/../contrib
- DOCSRC = $(TOP)/doc
- RGBSRC = $(TOP)/rgb
- DEPENDSRC = $(UTILSRC)/makedepend
- IMAKESRC = $(CONFIGSRC)
- XAUTHSRC = $(LIBSRC)/Xau
- XLIBSRC = $(LIBSRC)/X
- XMUSRC = $(LIBSRC)/Xmu
- TOOLKITSRC = $(LIBSRC)/Xt
- AWIDGETSRC = $(LIBSRC)/Xaw
- OLDXLIBSRC = $(LIBSRC)/oldX
- XDMCPLIBSRC = $(LIBSRC)/Xdmcp
- BDFTOSNFSRC = $(FONTSRC)/bdftosnf
- MKFONTDIRSRC = $(FONTSRC)/mkfontdir
- EXTENSIONSRC = $(TOP)/extensions
-
- # DEPEXTENSIONLIB = $(EXTENSIONSRC)/lib/libXext.a
- # EXTENSIONLIB = $(DEPEXTENSIONLIB)
- DEPEXTENSIONLIB =
- EXTENSIONLIB = /usr/lib/libXext.a
-
- DEPXLIB = $(DEPEXTENSIONLIB)
- XLIB = $(EXTENSIONLIB) -L$(XLIBSRC) -lX11
-
- DEPXAUTHLIB = $(XAUTHSRC)/libXau.a
- XAUTHLIB = $(DEPXAUTHLIB)
-
- DEPXMULIB =
- XMULIB = -L$(XMUSRC) -lXmu
-
- DEPOLDXLIB =
- OLDXLIB = -L$(OLDXLIBSRC) -loldX
-
- DEPXTOOLLIB =
- XTOOLLIB = -L$(TOOLKITSRC) -lXt
-
- DEPXAWLIB =
- XAWLIB = -L$(AWIDGETSRC) -lXaw
-
- LINTEXTENSIONLIB = $(EXTENSIONSRC)/lib/llib-lXext.ln
- LINTXLIB = $(XLIBSRC)/llib-lX11.ln
- LINTXMU = $(XMUSRC)/llib-lXmu.ln
- LINTXTOOL = $(TOOLKITSRC)/llib-lXt.ln
- LINTXAW = $(AWIDGETSRC)/llib-lXaw.ln
-
- DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
-
- DEPLIBS1 = $(DEPLIBS)
- DEPLIBS2 = $(DEPLIBS)
- DEPLIBS3 = $(DEPLIBS)
-
- ###########################################################################
- # Imake rules for building libraries, programs, scripts, and data files
- # rules: $XConsortium: Imake.rules,v 1.67 89/12/18 17:14:15 jim Exp $
-
- ###########################################################################
- # start of Imakefile
-
- SRCS1 = xclipboard.c
- OBJS1 = xclipboard.o
- SRCS2 = xcutsel.c
- OBJS2 = xcutsel.o
- PROGRAMS = xclipboard
- DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
- LOCAL_LIBRARIES = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
-
- OBJS = $(OBJS1) $(OBJS2) $(OBJS3)
- SRCS = $(SRCS1) $(SRCS2) $(SRCS3)
-
- all:: $(PROGRAMS)
-
- xclipboard: $(OBJS1) $(DEPLIBS1)
- $(RM) $@
- $(CC) -o $@ $(LDOPTIONS) $(OBJS1) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
-
- install:: xclipboard
- $(INSTALL) -c $(INSTPGMFLAGS) xclipboard $(BINDIR)
-
- install.man:: xclipboard.man
- $(INSTALL) -c $(INSTMANFLAGS) xclipboard.man $(MANDIR)/xclipboard.n
-
- saber_xclipboard:
- #load $(ALLDEFINES) $(SRCS1) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
-
- osaber_xclipboard:
- #load $(ALLDEFINES) $(OBJS1) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
-
- depend:: $(DEPEND)
-
- $(DEPEND):
- @echo "checking $@ over in $(DEPENDSRC) first..."; \
- cd $(DEPENDSRC); $(MAKE); \
- echo "okay, continuing in $(CURRENT_DIR)"
-
- depend::
- $(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
-
- lint:
- $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
- lint1:
- $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
-
- clean::
- $(RM) $(PROGRAMS)
-
- xcutsel: $(OBJS2) $(DEPLIBS2)
- $(RM) $@
- $(CC) -o $@ $(LDOPTIONS) $(OBJS2) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
-
- saber_xcutsel:
- #load $(ALLDEFINES) $(SRCS2) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
-
- osaber_xcutsel:
- #load $(ALLDEFINES) $(OBJS2) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
-
- install:: xcutsel
- $(INSTALL) -c $(INSTPGMFLAGS) xcutsel $(BINDIR)
-
- install.man:: xcutsel.man
- $(INSTALL) -c $(INSTMANFLAGS) xcutsel.man $(MANDIR)/xcutsel.n
-
- install:: XClipboard.ad
- $(INSTALL) -c $(INSTAPPFLAGS) XClipboard.ad $(XAPPLOADDIR)/XClipboard
-
- ###########################################################################
- # common rules for all Makefiles - do not edit
-
- emptyrule::
-
- clean::
- $(RM_CMD) \#*
-
- Makefile:: $(IMAKE)
-
- $(IMAKE):
- @(cd $(IMAKESRC); if [ -f Makefile ]; then \
- echo "checking $@ in $(IMAKESRC) first..."; $(MAKE) all; else \
- echo "bootstrapping $@ from Makefile.ini in $(IMAKESRC) first..."; \
- $(MAKE) -f Makefile.ini BOOTSTRAPCFLAGS=$(BOOTSTRAPCFLAGS); fi; \
- echo "okay, continuing in $(CURRENT_DIR)")
-
- Makefile::
- -@if [ -f Makefile ]; then \
- echo " $(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
- $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
- else exit 0; fi
- $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
-
- tags::
- $(TAGS) -w *.[ch]
- $(TAGS) -xw *.[ch] > TAGS
-
- saber:
- #load $(ALLDEFINES) $(SRCS)
-
- osaber:
- #load $(ALLDEFINES) $(OBJS)
-
- ###########################################################################
- # empty rules for directories that do not have SUBDIRS - do not edit
-
- install::
- @echo "install in $(CURRENT_DIR) done"
-
- install.man::
- @echo "install.man in $(CURRENT_DIR) done"
-
- Makefiles::
-
- includes::
-
- ###########################################################################
- # dependencies generated by makedepend
-
- ***EOF xclipboard/Makefile***
- echo "Creating xclipboard/XClipboard.ad"
- cat > xclipboard/XClipboard.ad <<"***EOF xclipboard/XClipboard.ad***"
- XClipboard*quit.label: Quit
- XClipboard*quit.top: ChainTop
- XClipboard*quit.bottom: ChainTop
- XClipboard*quit.left: ChainLeft
- XClipboard*quit.right: ChainLeft
- XClipboard*quit.translations: #override<BtnUp>:Quit() unset()
-
- XClipboard*delete.label: Delete
- XClipboard*delete.fromHoriz: quit
- XClipboard*delete.top: ChainTop
- XClipboard*delete.bottom: ChainTop
- XClipboard*delete.left: ChainLeft
- XClipboard*delete.right: ChainLeft
- XClipboard*delete.translations: #override<BtnUp>:DeleteClip() unset()
-
- XClipboard*new.label: New
- XClipboard*new.fromHoriz: delete
- XClipboard*new.top: ChainTop
- XClipboard*new.bottom: ChainTop
- XClipboard*new.left: ChainLeft
- XClipboard*new.right: ChainLeft
- XClipboard*new.translations: #override<BtnUp>:NewClip() unset()
-
- XClipboard*load.label: Load
- XClipboard*load.fromHoriz: new
- XClipboard*load.top: ChainTop
- XClipboard*load.bottom: ChainTop
- XClipboard*load.left: ChainLeft
- XClipboard*load.right: ChainLeft
- XClipboard*load.translations: #override<BtnUp>:Load() unset()
-
- XClipboard*save.label: Save
- XClipboard*save.fromHoriz: load
- XClipboard*save.top: ChainTop
- XClipboard*save.bottom: ChainTop
- XClipboard*save.left: ChainLeft
- XClipboard*save.right: ChainLeft
- XClipboard*save.translations: #override<BtnUp>:Save() unset()
-
- XClipboard*prnt.label: Print
- XClipboard*prnt.fromHoriz: save
- XClipboard*prnt.top: ChainTop
- XClipboard*prnt.bottom: ChainTop
- XClipboard*prnt.left: ChainLeft
- XClipboard*prnt.right: ChainLeft
- XClipboard*prnt.translations: #override<BtnUp>:PrntClip() unset()
-
- XClipboard*next.label: Next
- XClipboard*next.fromHoriz: prnt
- XClipboard*next.top: ChainTop
- XClipboard*next.bottom: ChainTop
- XClipboard*next.left: ChainLeft
- XClipboard*next.right: ChainLeft
- XClipboard*next.translations: #override<BtnUp>:NextClip() unset()
-
- XClipboard*prev.label: Previous
- XClipboard*prev.fromHoriz: next
- XClipboard*prev.top: ChainTop
- XClipboard*prev.bottom: ChainTop
- XClipboard*prev.left: ChainLeft
- XClipboard*prev.right: ChainLeft
- XClipboard*prev.translations: #override<BtnUp>:PrevClip() unset()
-
- XClipboard*text.scrollVertical: WhenNeeded
- XClipboard*text.scrollHorizontal: WhenNeeded
- XClipboard*text.autoFill: on
-
- XClipboard*text.fromVert: quit
- XClipboard*text.top: ChainTop
- XClipboard*text.bottom: ChainBottom
- XClipboard*text.left: ChainLeft
- XClipboard*text.right: ChainRight
- XClipboard*text.width: 600
-
- XClipboard.geometry: 600x200
- XClipboard*ShapeStyle: oval
- XClipboard*printer_name: ps
- ***EOF xclipboard/XClipboard.ad***
- echo "Creating xclipboard/xclipboard.c"
- cat > xclipboard/xclipboard.c <<"***EOF xclipboard/xclipboard.c***"
- /*
- * $XConsortium: xclipboard.c,v 1.15 89/12/15 20:11:09 keith Exp $
- *
- * Copyright 1989 Massachusetts Institute of Technology
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. M.I.T. makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
- * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Ralph Swick, DEC/Project Athena
- * Updated for R4: Chris D. Peterson, MIT X Consortium.
- * Reauthored by: Keith Packard, MIT X Consortium.
- *
- * Enhancements: Amir H. Vafaei, Apertus Technologies Inc., Minneapolis, Minnesota.
- * Added Load, Save and Print capabilities 4/8/1992.
- */
-
- /* $XConsortium: xclipboard.c,v 1.15 89/12/15 20:11:09 keith Exp $ */
-
- #include <stdio.h>
- #include <unistd.h>
- #include <pwd.h>
- #include <sys/param.h>
-
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- #include <X11/Xatom.h>
-
- #include <X11/Xmu/Atoms.h>
- #include <X11/Xmu/StdSel.h>
-
- #include <X11/Xaw/Form.h>
- #include <X11/Xaw/Command.h>
- #include <X11/Xaw/AsciiText.h>
- #include <X11/Xaw/Cardinals.h>
-
- #define Command commandWidgetClass
- #define Text asciiTextWidgetClass
-
- #define INFINITY 10000000 /* pretty big, huh? */
-
- typedef struct _Clip {
- struct _Clip *next, *prev;
- char *clip;
- int avail;
- } ClipRec, *ClipPtr;
-
- typedef struct{
- char *pn_name;
- }TEXT_DATA, *TEXT_DATA_PTR;
-
- TEXT_DATA text_data;
-
- extern char *malloc ();
-
- static long TextLength (w)
- Widget w;
- {
- return XawTextSourceScan (XawTextGetSource (w),
- (XawTextPosition) 0,
- XawstAll, XawsdRight, 1, TRUE);
- }
-
- SaveClip (w, clip)
- Widget w;
- ClipPtr clip;
- {
- Arg args[1];
- char *data;
- int len;
- Widget source;
-
- source = XawTextGetSource (w);
- XtSetArg (args[0], XtNstring, &data);
- XtGetValues (source, args, 1);
- len = strlen (data);
- if (len >= clip->avail)
- {
- if (clip->clip)
- free (clip->clip);
- clip->clip = malloc (len + 1);
- if (!clip->clip)
- clip->avail = 0;
- else
- clip->avail = len + 1;
- }
- if (clip->avail)
- {
- strcpy (clip->clip, data);
- }
- }
-
- RestoreClip (w, clip)
- Widget w;
- ClipPtr clip;
- {
- Arg args[1];
- Widget source;
-
- source = XawTextGetSource (w);
- XtSetArg (args[0], XtNstring, clip->clip);
- XtSetValues (source, args, 1);
- }
-
- ClipPtr
- NewClip (w, old)
- Widget w;
- ClipPtr old;
- {
- ClipPtr newClip;
-
- newClip = (ClipPtr) malloc (sizeof (ClipRec));
- if (!newClip)
- return newClip;
- newClip->clip = 0;
- newClip->avail = 0;
- newClip->prev = old;
- newClip->next = NULL;
- if (old)
- {
- newClip->next = old->next;
- old->next = newClip;
- }
- return newClip;
- }
-
- DeleteClip (w, clip)
- Widget w;
- ClipPtr clip;
- {
- if (clip->prev)
- clip->prev->next = clip->next;
- if (clip->next)
- clip->next->prev = clip->prev;
- if (clip->clip)
- free (clip->clip);
- free ((char *) clip);
- }
-
- static ClipPtr currentClip;
- static Widget text, nextButton, prevButton, loadButton;
- static char saveFile[MAXPATHLEN + 1];
-
- static void set_button_state ()
- {
- Boolean prevvalid, nextvalid;
- Arg arg;
-
- prevvalid = False;
- nextvalid = False;
- if (currentClip)
- {
- prevvalid = currentClip->prev != NULL;
- nextvalid = currentClip->next != NULL;
- }
- arg.name = XtNsensitive;
- arg.value = (XtArgVal) prevvalid;
- XtSetValues (prevButton, &arg, ONE);
- arg.value = (XtArgVal) nextvalid;
- XtSetValues (nextButton, &arg, ONE);
- }
-
- static void
- NextCurrentClip ()
- {
- if (currentClip && currentClip->next)
- {
- SaveClip (text, currentClip);
- currentClip = currentClip->next;
- RestoreClip (text, currentClip);
- set_button_state ();
- }
- }
-
- static void
- PrevCurrentClip ()
- {
- if (currentClip && currentClip->prev)
- {
- SaveClip (text, currentClip);
- currentClip = currentClip->prev;
- RestoreClip (text, currentClip);
- set_button_state ();
- }
- }
-
- static void
- DeleteCurrentClip ()
- {
- ClipPtr newCurrent;
-
- if (currentClip)
- {
- if (currentClip->prev)
- {
- newCurrent = currentClip->prev;
- }
- else
- {
- newCurrent = currentClip->next;
- }
- DeleteClip (text, currentClip);
- currentClip = newCurrent;
- if (currentClip)
- RestoreClip (text, currentClip);
- else
- {
- EraseTextWidget ();
- }
- set_button_state ();
- }
- else
- EraseTextWidget();
- }
-
- static void
- Quit ()
- {
- XtCloseDisplay (XtDisplay (text));
- exit (0);
- }
-
- static void
- erase_all()
- {
- ClipPtr tempClip, headClip;
-
- tempClip = currentClip;
-
- while (tempClip){
- headClip = tempClip;
- tempClip = tempClip->prev;
- }
-
- while (headClip){
- tempClip = headClip;
- headClip = headClip->next;
- DeleteClip(text, tempClip);
- }
- }
-
- static void
- PrntClip()
- {
- Arg args[1];
- char *data;
- Widget source;
- char template[17];
- char *tmp, *mktemp();
- char buf[80];
- int tmpfd;
- int len;
-
- source = XawTextGetSource (text);
- XtSetArg (args[0], XtNstring, &data);
- XtGetValues (source, args, 1);
- if ((len = strlen(data)) <= 0)
- return;
- strcpy(template, "/tmp/oipfgXXXXXX");
- tmp = mktemp(template);
- if (template == ""){
- fprintf(stderr, "Unable to make tmp file.\n");
- return;
- }
-
- tmpfd = open(tmp, O_RDWR|O_CREAT, 0666);
- if (tmpfd < 0){
- fprintf(stderr, "Unable to create tmp file.\n");
- return;
- }
-
- write(tmpfd, data, len + 1);
- close(tmpfd);
- if (!text_data.pn_name[0])
- sprintf(buf, "lpr %s", tmp);
- else
- sprintf(buf, "lpr -P%s %s", text_data.pn_name, tmp);
- system(buf);
- unlink(tmp);
-
- }
-
- static void
- Save()
- {
- ClipPtr tempClip, headClip, saveClip;
- FILE *fp;
- long size;
- long count = 0;
-
- if (!(fp = fopen(saveFile, "w")))
- return;
-
- tempClip = currentClip;
- saveClip = (ClipPtr)0;
-
- if (!tempClip && TextLength(text))
- saveClip = tempClip = NewClip(text, (ClipPtr)0);
-
- if (tempClip){
- if (TextLength(text))
- SaveClip (text, tempClip);
- while (tempClip){
- count++;
- headClip = tempClip;
- tempClip = tempClip->prev;
- }
-
- fwrite(&count, sizeof(long), 1, fp);
-
- while (headClip){
- if (headClip->clip){
- size = strlen(headClip->clip) + 1;
- fwrite(&size, sizeof(long), 1, fp);
- fwrite(headClip->clip, 1, size, fp);
- }
- else{
- size = 0L;
- fwrite(&size, sizeof(long), 1, fp);
- }
- headClip = headClip->next;
- }
- fclose(fp);
- if (saveClip)
- DeleteClip(text, saveClip);
- }
- else{
- fclose(fp);
- unlink(saveFile);
- }
- }
-
- static void
- Load()
- {
- FILE *fp;
- ClipPtr tempClip, oldClip;
- long size, count;
-
- if (!(fp = fopen(saveFile, "r")))
- return;
-
- if (currentClip)
- erase_all();
-
-
- if (fread(&count, sizeof(long), 1, fp) <= 0)
- return;
-
- oldClip = (ClipPtr)0;
- currentClip = (ClipPtr)0;
-
- while (fread(&size, sizeof(long), 1, fp)){
- tempClip = NewClip(text, oldClip);
-
- if (tempClip){
- oldClip = tempClip;
- if (!currentClip)
- currentClip = tempClip;
-
- if (!(--count))
- currentClip = tempClip;
-
- tempClip->clip = malloc(size);
- if (tempClip->clip){
- tempClip->avail = size;
- fread(tempClip->clip, 1, size, fp);
- }
- else{
- fseek(fp, size, SEEK_CUR);
- count--;
- }
- }
- else{
- fseek(fp, size, 1);
- count--;
- }
- }
-
- fclose(fp);
- RestoreClip (text, currentClip);
- set_button_state();
- }
-
- static void
- NewCurrentClip ()
- {
- NewCurrentClipContents ("", 0);
- }
-
- NewCurrentClipContents (data, len)
- char *data;
- int len;
- {
- XawTextBlock textBlock;
- ClipPtr newCurrent;
-
- if (!currentClip && TextLength (text))
- currentClip = NewClip (text, (ClipPtr) 0);
- if (currentClip)
- SaveClip (text, currentClip);
- /* append new clips at the end */
- while (currentClip && currentClip->next)
- currentClip = currentClip->next;
- newCurrent = NewClip (text, currentClip);
-
- currentClip = newCurrent;
-
- textBlock.ptr = data;
- textBlock.firstPos = 0;
- textBlock.length = len;
- textBlock.format = FMT8BIT;
- if (XawTextReplace(text, 0, TextLength (text), &textBlock))
- XBell( XtDisplay(text), 0);
- set_button_state ();
- }
-
- EraseTextWidget ()
- {
- XawTextBlock block;
-
- block.ptr = "";
- block.length = 0;
- block.firstPos = 0;
- block.format = FMT8BIT;
-
- XawTextReplace(text, 0, INFINITY, &block);
- /* If this fails, too bad. */
- }
-
-
- XtActionsRec xclipboard_actions[] = {
- "NewClip", NewCurrentClip,
- "NextClip", NextCurrentClip,
- "PrevClip", PrevCurrentClip,
- "DeleteClip", DeleteCurrentClip,
- "Load", Load,
- "Save", Save,
- "PrntClip", PrntClip,
- "Quit", Quit,
- };
-
- static XtResource resources[] = {
- {"printer_name", "Printer_name", XtRString, sizeof(char *), XtOffset(TEXT_DATA_PTR, pn_name), XtRString, ""},
- };
-
- static XrmOptionDescRec table[] = {
- {"-w", "*text*wrap", XrmoptionNoArg, "Word"},
- {"-nw", "*text*wrap", XrmoptionNoArg, "Never"},
- {"-P", "printer_name", XrmoptionStickyArg, NULL},
- };
-
- static void LoseSelection ();
- static void InsertClipboard ();
- static Boolean ConvertSelection();
-
- static void
- InsertClipboard(w, client_data, selection, type, value, length, format)
- Widget w;
- caddr_t client_data;
- Atom *selection, *type;
- caddr_t value;
- unsigned long *length;
- int *format;
- {
- if (*type == 0 /*XT_CONVERT_FAIL*/ || *length == 0) {
- XBell( XtDisplay(w), 0 );
- return;
- }
-
- NewCurrentClipContents ((char *) value, *length);
-
- XtOwnSelection(w, XA_CLIPBOARD(XtDisplay(w)), CurrentTime,
- ConvertSelection, LoseSelection, NULL);
-
- XtFree(value);
- }
-
- static Boolean ConvertSelection(w, selection, target,
- type, value, length, format)
- Widget w;
- Atom *selection, *target, *type;
- caddr_t *value;
- unsigned long *length;
- int *format;
- {
- Display* d = XtDisplay(w);
- XSelectionRequestEvent* req =
- XtGetSelectionRequest(w, *selection, (XtRequestId)NULL);
-
- if (*target == XA_TARGETS(d)) {
- Atom* targetP;
- Atom* std_targets;
- unsigned long std_length;
- XmuConvertStandardSelection(w, req->time, selection, target, type,
- (caddr_t*)&std_targets, &std_length, format);
- *value = XtMalloc(sizeof(Atom)*(std_length + 5));
- targetP = *(Atom**)value;
- *targetP++ = XA_STRING;
- *targetP++ = XA_TEXT(d);
- *targetP++ = XA_LENGTH(d);
- *targetP++ = XA_LIST_LENGTH(d);
- *targetP++ = XA_CHARACTER_POSITION(d);
- *length = std_length + (targetP - (*(Atom **) value));
- bcopy((char*)std_targets, (char*)targetP, sizeof(Atom)*std_length);
- XtFree((char*)std_targets);
- *type = XA_ATOM;
- *format = 32;
- return True;
- }
-
- if (*target == XA_LIST_LENGTH(d) ||
- *target == XA_LENGTH(d))
- {
- long * temp;
-
- temp = (long *) XtMalloc(sizeof(long));
- if (*target == XA_LIST_LENGTH(d))
- *temp = 1L;
- else /* *target == XA_LENGTH(d) */
- *temp = (long) TextLength (w);
-
- *value = (caddr_t) temp;
- *type = XA_INTEGER;
- *length = 1L;
- *format = 32;
- return True;
- }
-
- if (*target == XA_CHARACTER_POSITION(d))
- {
- long * temp;
-
- temp = (long *) XtMalloc(2 * sizeof(long));
- temp[0] = (long) 0;
- temp[1] = TextLength (w);
- *value = (caddr_t) temp;
- *type = XA_SPAN(d);
- *length = 2L;
- *format = 32;
- return True;
- }
-
- if (*target == XA_STRING ||
- *target == XA_TEXT(d) ||
- *target == XA_COMPOUND_TEXT(d))
- {
- extern char *_XawTextGetSTRING();
- if (*target == XA_COMPOUND_TEXT(d))
- *type = *target;
- else
- *type = XA_STRING;
- *length = TextLength (w);
- *value = _XawTextGetSTRING((TextWidget) w, 0, *length);
- *format = 8;
- return True;
- }
-
- if (XmuConvertStandardSelection(w, req->time, selection, target, type,
- value, length, format))
- return True;
-
- return False;
- }
-
- static void LoseSelection(w, selection)
- Widget w;
- Atom *selection;
- {
- XtGetSelectionValue(w, *selection, XA_STRING, InsertClipboard,
- NULL, CurrentTime);
- }
-
- /*ARGSUSED*/
- static Boolean RefuseSelection(w, selection, target,
- type, value, length, format)
- Widget w;
- Atom *selection, *target, *type;
- caddr_t *value;
- unsigned long *length;
- int *format;
- {
- return False;
- }
-
- /*ARGSUSED*/
- static void LoseManager(w, selection)
- Widget w;
- Atom *selection;
- {
- XtError("another clipboard has taken over control\n");
- }
-
- static void
- get_savefile(s)
- char *s;
- {
- struct passwd *pw;
-
- if (!(pw = getpwuid(getuid())))
- return;
-
- sprintf(s, "%s/.clipper", pw->pw_dir);
- }
-
-
- void
- main(argc, argv)
- int argc;
- char **argv;
- {
- Arg args[2];
- Widget top, parent, quit, delete, new, save, prnt;
- Atom manager;
-
- top = XtInitialize( "xclipboard", "XClipboard", table, XtNumber(table),
- &argc, argv);
-
- XtGetApplicationResources(top, &text_data, resources, XtNumber(resources), NULL, 0);
-
- get_savefile(saveFile);
-
- XtAddActions (xclipboard_actions, XtNumber (xclipboard_actions));
- /* CLIPBOARD_MANAGER is a non-standard mechanism */
- manager = XInternAtom(XtDisplay(top), "CLIPBOARD_MANAGER", False);
- if (XGetSelectionOwner(XtDisplay(top), manager))
- XtError("another clipboard is already running\n");
-
- parent = XtCreateManagedWidget("form", formWidgetClass, top, NULL, ZERO);
- quit = XtCreateManagedWidget("quit", Command, parent, NULL, ZERO);
- delete = XtCreateManagedWidget("delete", Command, parent, NULL, ZERO);
- new = XtCreateManagedWidget("new", Command, parent, NULL, ZERO);
- loadButton = XtCreateManagedWidget("load", Command, parent, NULL, ZERO);
- save = XtCreateManagedWidget("save", Command, parent, NULL, ZERO);
- prnt = XtCreateManagedWidget("prnt", Command, parent, NULL, ZERO);
- nextButton = XtCreateManagedWidget("next", Command, parent, NULL, ZERO);
- prevButton = XtCreateManagedWidget("prev", Command, parent, NULL, ZERO);
-
- XtSetArg(args[0], XtNtype, XawAsciiString);
- XtSetArg(args[1], XtNeditType, XawtextEdit);
- text = XtCreateManagedWidget( "text", Text, parent, args, TWO);
-
- set_button_state ();
-
- XtRealizeWidget(top);
-
- XtOwnSelection(text, manager, CurrentTime,
- RefuseSelection, LoseManager, NULL);
- XtOwnSelection(text, XA_CLIPBOARD(XtDisplay(text)), CurrentTime,
- ConvertSelection, LoseSelection, NULL);
-
- XtMainLoop();
- }
- ***EOF xclipboard/xclipboard.c***
- echo "Creating xclipboard/xclipboard.man"
- cat > xclipboard/xclipboard.man <<"***EOF xclipboard/xclipboard.man***"
- TH XCLIPBOARD 1 "Release 4" "X Version 11"
- de Ds
- nf
- \\$1D \\$2 \\$1
- ft 1
- ps \\n(PS
- \".if \\n(VS>=40 .vs \\n(VSu
- \".if \\n(VS<=39 .vs \\n(VSp
-
- exit 0 # Just in case...
- --
- // chris@IMD.Sterling.COM | Send comp.sources.x submissions to:
- \X/ Amiga - The only way to fly! | sources-x@imd.sterling.com
- "It's intuitively obvious to the |
- most casual observer..." | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
-