Text Subwindow line number

Rich Salz rsalz at bbn.com
Thu Jan 5 06:14:23 AEST 1989


This little piece of code does it...
#! /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:  line.c
# Wrapped by rsalz at fig.bbn.com on Fri Dec 23 10:19:22 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'line.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'line.c'\"
else
echo shar: Extracting \"'line.c'\" \(1144 characters\)
sed "s/^X//" >'line.c' <<'END_OF_FILE'
X/*
X*/
X#include <suntool/sunview.h>
X#include <suntool/textsw.h>
X#include <suntool/selection.h>
X#include <suntool/selection_svc.h>
X#include <suntool/selection_attributes.h>
X
Xextern Textsw	 KWICArea;
X
X/*
X**  Get the line number of the current selection, or -1 if not in the
X**  index window.
X*/
Xint
Xget_line_number()
X{
X    static int		 Saved = -1;
X    Seln_request	*Sbuffer;
X    Seln_holder		 Hold;
X    int			*p;
X
X    /* Get primary selection, see if it is in our window. */
X    Hold = seln_inquire(SELN_PRIMARY);
X    if (Hold.state == SELN_NONE || !seln_holder_same_client(&Hold, KWICArea))
X	/* Nope, get the old one. */
X	return(Saved);
X
X    /* Get the first line of the current selection. */
X    Sbuffer = seln_ask(&Hold, SELN_REQ_FAKE_LEVEL, SELN_LEVEL_LINE,
X			SELN_REQ_FIRST_UNIT, 0, 0);
X    if (Sbuffer->status == SELN_FAILED) {
X	Message("Can't get current selection!");
X	return(-1);
X    }
X
X    /* The data we asked for comes back in words. */
X    p = (int *)Sbuffer->data;
X
X    /* Make sure we got what we asked for. */
X    if (p[0] != (int)SELN_REQ_FAKE_LEVEL || p[2] != (int)SELN_REQ_FIRST_UNIT)
X	return(-1);
X
X    return(Saved = p[3]);
X}
END_OF_FILE
if test 1144 -ne `wc -c <'line.c'`; then
    echo shar: \"'line.c'\" unpacked with wrong size!
fi
# end of 'line.c'
fi
echo shar: End of shell archive.
exit 0
-- 
Please send comp.sources.unix-related mail to rsalz at uunet.uu.net.



More information about the Comp.sys.sun mailing list