Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!mailrus!cornell!uw-beaver!rice!sun-spots-request From: rsalz@bbn.com (Rich Salz) Newsgroups: comp.sys.sun Subject: Re: Text Subwindow line number Message-ID: <1322@fig.bbn.com> Date: 4 Jan 89 20:14:23 GMT References: <8812151804.AA06341@MATH.Tau.Ac.IL> Sender: usenet@rice.edu Organization: Sun-Spots Lines: 71 Approved: Sun-Spots@rice.edu Original-Date: 23 Dec 88 15:21:02 GMT X-Sun-Spots-Digest: Volume 7, Issue 88, message 2 of 9 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 'line.c' <<'END_OF_FILE' X/* X*/ X#include X#include X#include X#include X#include 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@uunet.uu.net.