mkid 03/11 (identifier cross reference tool)

Tom Horsley tom at ssd.csd.harris.com
Thu Dec 13 01:40:55 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 archive 3 (of 11)."
# Contents:  cannoname.c iid.help paths.c scan-text.c symfunc.el
# Wrapped by tom at hcx2 on Wed Dec 12 07:21:55 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'cannoname.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cannoname.c'\"
else
echo shar: Extracting \"'cannoname.c'\" \(3989 characters\)
sed "s/^X//" >'cannoname.c' <<'END_OF_FILE'
X/* This file contains routines which put a file name into cannonical
X * form.
X */
X
X#define NULL 0
X
X/* define special name components */
X
Xstatic char slash[]  = "/" ;
Xstatic char dot[]    = "." ;
Xstatic char dotdot[] = ".." ;
X
X/* nextc points to the next character to look at in the string or is
X * null if the end of string was reached.
X *
X * namep points to buffer that holds the components.
X */
Xstatic char * nextc = NULL ;
Xstatic char * namep ;
X
X/* lexname - Return next name component. Uses global variables initialized
X * by cannoname to figure out what it is scanning.
X */
Xstatic char *
Xlexname()
X{
X   char   c ;
X   char * d ;
X
X   if (nextc) {
X      c = *nextc++ ;
X      if (c == '\0') {
X         nextc = NULL ;
X         return(NULL) ;
X      }
X      if (c == '/') {
X         return(&slash[0]) ;
X      }
X      if (c == '.') {
X         if ((*nextc == '/') || (*nextc == '\0')) return(&dot[0]) ;
X         if (*nextc == '.' && (*(nextc+1) == '/' || *(nextc+1) == '\0')) {
X            ++nextc ;
X            return(&dotdot[0]) ;
X         }
X      }
X      d = namep;
X      *namep++ = c;
X      while ((c = *nextc) != '/') {
X         *namep++ = c ;
X         if (c == '\0') {
X            nextc = NULL ;
X            return(d) ;
X         }
X         ++nextc;
X      }
X      *namep++ = '\0' ;
X      return(d) ;
X   } else {
X      return(NULL) ;
X   }
X}
X
X/* cannoname - Put a file name in cannonical form. Looks for all the
X * whacky wonderful things a demented *ni* programmer might put
X * in a file name and reduces the name to cannonical form.
X */
Xvoid
Xcannoname(n)
X   char * n;
X{
X   char *  components[1024] ;
X   char ** cap = &components[0] ;
X   char ** cad ;
X   char *  cp ;
X   char    namebuf[2048] ;
X   char *  s ;
X
X   /* initialize scanner */
X   nextc = n ;
X   namep = &namebuf[0] ;
X
X   /* break the file name into individual components */
X   while ((cp = lexname()) != NULL) {
X      *cap++ = cp ;
X   }
X
X   /* If name is empty, leave it that way */
X   if (cap == &components[0]) return ;
X
X   /* flag end of component list */
X   *cap = NULL ;
X
X   /* remove all trailing slashes and dots */
X   while ((--cap != &components[0]) &&
X          ((*cap == &slash[0]) || (*cap == &dot[0]))) *cap = NULL ;
X
X   /* squeeze out all . / component sequences */
X   cap = &components[0] ;
X   cad = cap ;
X   while (*cap != NULL) {
X      if ((*cap == &dot[0]) && (*(cap+1) == &slash[0])) {
X         cap += 2;
X      } else {
X         *cad++ = *cap++ ;
X      }
X   }
X   *cad++ = NULL ;
X
X   /* find multiple // and use last slash as root */
X   s = NULL ;
X   cap = &components[0] ;
X   cad = cap ;
X   while (*cap != NULL) {
X      if ((s == &slash[0]) && (*cap == &slash[0])) {
X         cad = &components[0];
X      }
X      s = *cap++;
X      *cad++ = s;
X   }
X   *cad = NULL ;
X
X   /* if this is absolute name get rid of any /.. at beginning */
X   if ((components[0] == &slash[0]) && (components[1] == &dotdot[0])) {
X      cap = &components[1] ;
X      cad = cap ;
X      while (*cap == &dotdot[0]) {
X         ++cap;
X         if (*cap == NULL) break ;
X         if (*cap == &slash[0]) ++cap ;
X      }
X      while (*cap != NULL) {
X         *cad++ = *cap++ ;
X      }
X      *cad = NULL ;
X   }
X
X   /* squeeze out any name/.. sequences (but leave leading ../..) */
X   cap = &components[0] ;
X   cad = cap ;
X   while (*cap != NULL) {
X      if ((*cap == &dotdot[0]) &&
X          ((cad-2) >= &components[0]) &&
X          ((*(cad-2)) != &dotdot[0])) {
X         cad -= 2 ;
X         ++cap;
X         if (*cap != NULL) ++cap;
X      } else {
X         *cad++ = *cap++ ;
X      }
X   }
X   /* squeezing out a trailing /.. can leave unsightly trailing /s */
X   if ((cad >= &components[2]) && ((*(cad-1)) == &slash[0])) --cad ;
X   *cad = NULL ;
X   /* if it was just name/.. it now becomes . */
X   if (components[0] == NULL) {
X      components[0] = &dot[0] ;
X      components[1] = NULL ;
X   }
X
X   /* re-assemble components */
X   cap = &components[0] ;
X   while ((s = *cap++) != NULL) {
X      while (*s != NULL) *n++ = *s++;
X   }
X   *n++ = '\0' ;
X}
END_OF_FILE
if test 3989 -ne `wc -c <'cannoname.c'`; then
    echo shar: \"'cannoname.c'\" unpacked with wrong size!
fi
# end of 'cannoname.c'
fi
if test -f 'iid.help' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'iid.help'\"
else
echo shar: Extracting \"'iid.help'\" \(3455 characters\)
sed "s/^X//" >'iid.help' <<'END_OF_FILE'
XThe iid program is an interactive shell on  top of the  mkid, lid, aid
Xdatabase programs. It allows interactive queries of  an ID database in
Xa fashion similar to a DIALOG session. Iid remembers the sets of files
Xthat were reported by any  lid or aid request.  These sets are refered
Xto by set numbers. The commands available are:
X
XBEGIN <directory>    cd to directory (presumably containing an ID file).
XB                    short for BEGIN
XSS <query>           run query displaying the sets generated
XFILES <query>        run query listing the files in the final set
XF                    short for FILES
XSHOW <set number>    run pager program on files in set
XP                    short for SHOW
XSETS                 show currently defined sets
XHELP                 run pager on this file
X? or H               short commands for HELP
XOFF                  exit iid
X<cmd>                run a shell command as a file name query
X!<cmd>               run a shell command
X
XA <set number> is the letter 's' (or 'S')  followed (with no space) by
Xa number. Set numbers may be used as terms in a query.
X
XA <query> is:
X   <set number>
X   <identifier>
X   lid <identifier list>
X   aid <identifier list>
X   match <wild card list>
X   <query> or <query>
X   <query> and <query>
X
XThe words  "lid", "aid", "match",  "or", and "and" are keywords, along
Xwith any word that looks like a set number. If you  have to use one of
Xthese (or in arguments to lid, aid  or match, shell escape characters)
Xthen quote the name.
X
XThe  "match" operator constructs a set  of  files by running the "pid"
Xprogram with the wild card  pattern as  an argument. This  is the only
Xoperator    which constructs sets   based  on file  names rather  than
Xcontents.
X
XAn identifier by itself is  simply shorthand for "lid identifier". (If
Xthe -a  option was used  to invoke iid,  then  a simple  identifier is
Xshorthand for "aid identifier").
X
XExample run:
X
X===> iid
X===> ss lid "^get" or lid "Arg$"
X   S0     14  lid -kmn "^get"
X   S1      3  lid -kmn "Arg$"
X   S2     15  (lid -kmn "^get") OR (lid -kmn "Arg$")
X===> f s1
Xlid.c
Xpaths.c
Xinit.c
X===> ls *.c
X   S3     28  ls *.c
X===> ls s*
X   S4      9  ls s*
X===> ss s3 and s4
X   S5      4  (ls *.c) AND (ls s*)
X===> !grep vhil s5
Xscan-c.c:				setCArgs("vhil",'+',"v");
Xscan-c.c:			setCArgs("vhil",'+',"v");
X===> off
X
XIn  this example  the 'ss' command  displays  the sets it creats as it
Xdoes the parts of the  query. In this case  3 sets are created, set S0
Xhas 14 files in it, set S1 has 3 files and the  union of the two sets,
XS2, has 15 files.  A description of the  query that created any  given
Xset is kept along with the set and displayed when sets are printed.
X
XThe 'f s1' command says list the files in set S1, and  the three files
Xin the set are displayed.
X
XThe 'ls'  commands are examples of using  arbitrary  shell commands to
Xgenerate lists  of files. In  this case the  'ls' command. (This could
Xhave been done as part of another query using the 'match' operator).
X
XThe '!grep vhil s5' command runs  the 'grep'  shell command passing as
Xarguments 'vhil' and the names of all the files in s5.
X
XThe 'off' command terminated the example session.
X
XKeywords, commands, and set numbers are recognized  regardless of case
X(and is And is aNd). Other parameters are case sensitive.
X
XThe iid program can  also be run in a  batch mode using the -c option.
XFor more information on command line options, run "iid -H", or use the
XUnix 'man' command.
END_OF_FILE
if test 3455 -ne `wc -c <'iid.help'`; then
    echo shar: \"'iid.help'\" unpacked with wrong size!
fi
# end of 'iid.help'
fi
if test -f 'paths.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'paths.c'\"
else
echo shar: Extracting \"'paths.c'\" \(5284 characters\)
sed "s/^X//" >'paths.c' <<'END_OF_FILE'
X/* Copyright (c) 1986, Greg McGary */
Xstatic char sccsid[] = "@(#)paths.c	1.1 86/10/09";
X
X#include	<bool.h>
X#include	<stdio.h>
X#include	<string.h>
X
Xbool canCrunch();
Xchar *rootName();
Xchar *spanPath();
Xchar *suffName();
Xvoid cannoname();
X
X/* relPath takes two arguments:
X * 1) an absolute path name for a directory.
X *    (This name MUST have a trailing /).
X * 2) an absolute path name for a file.
X *
X * It looks for common components at the front of the file and
X * directory names and generates a relative path name for the file
X * (relative to the specified directory).
X *
X * This may result in a huge number of ../s if the names
X * have no components in common.
X *
X * The output from this concatenated with the input directory name
X * and run through spanPath should result in the original input
X * absolute path name of the file.
X *
X * Examples:
X *  dir      arg                  return value
X *  /x/y/z/  /x/y/q/file      ->  ../q/file
X *  /x/y/z/  /q/t/p/file      ->  ../../../q/t/p/file
X *  /x/y/z/  /x/y/z/file      ->  file
X */
Xchar *
XrelPath(dir, arg)
X	char		*dir;
X	char		*arg;
X{
X	char *		a;
X	char *		d;
X	char *		lasta;
X	char *		lastd;
X	static char	pathBuf[BUFSIZ];
X
X	lasta = a = arg;
X	lastd = d = dir;
X	while (*a == *d) {
X	   if (*a == '/') {
X	      lasta = a;
X	      lastd = d;
X	   }
X	   ++a;
X	   ++d;
X	}
X	/* lasta and lastd now point to the last / in each
X	 * file name where the leading file components were
X	 * identical.
X	 */
X	++lasta;
X	++lastd;
X	/* copy a ../ into the buffer for each component of
X	 * the directory that remains.
X	 */
X	d = pathBuf;
X	while (*lastd != '\0') {
X		if (*lastd == '/') {
X			strcpy(d, "../");
X			d += 3;
X		}
X		++lastd;
X	}
X	/* now tack on remainder of arg */
X	strcpy(d, lasta);
X	return(pathBuf);
X}
X
X/* spanPath accepts a directory name and a file name and returns
X * a cannonical form of the full file name within that directory.
X * It gets rid of ./ and things like that.
X *
X * If the file is an absolute name then the directory is ignored.
X */
Xchar *
XspanPath(dir, arg)
X	char		*dir;
X	char		*arg;
X{
X	char *          argptr;
X	static char	pathBuf[BUFSIZ];
X
X	/* reduce directory to cannonical form */
X	strcpy(pathBuf, dir);
X	cannoname(pathBuf);
X	/* tack the obilgatory / on the end */
X	strcat(pathBuf, "/");
X	/* stick file name in buffer after directory */
X	argptr = pathBuf + strlen(pathBuf);
X	strcpy(argptr, arg);
X	/* and reduce it to cannonical form also */
X	cannoname(argptr);
X	/* If it is an absolute name, just return it */
X	if (*argptr == '/') return(argptr);
X	/* otherwise, combine the names to cannonical form */
X	cannoname(pathBuf);
X	return(pathBuf);
X}
X
X/* rootName returns the base name of the file with any leading
X * directory information or trailing suffix stripped off. Examples:
X *
X *   /usr/include/stdio.h   ->   stdio
X *   fred                   ->   fred
X *   barney.c               ->   barney
X *   bill/bob               ->   bob
X *   /                      ->   < null string >
X */
Xchar *
XrootName(path)
X	char		*path;
X{
X	static char	pathBuf[BUFSIZ];
X	char		*root;
X	char		*dot;
X
X	if ((root = strrchr(path, '/')) == NULL)
X		root = path;
X	else
X		root++;
X	
X	if ((dot = strrchr(root, '.')) == NULL)
X		strcpy(pathBuf, root);
X	else {
X		strncpy(pathBuf, root, dot - root);
X		pathBuf[dot - root] = '\0';
X	}
X	return pathBuf;
X}
X
X/* suffName returns the suffix (including the dot) or a null string
X * if there is no suffix. Examples:
X *
X *   /usr/include/stdio.h   ->   .h
X *   fred                   ->   < null string >
X *   barney.c               ->   .c
X *   bill/bob               ->   < null string >
X *   /                      ->   < null string >
X */
Xchar *
XsuffName(path)
X	char		*path;
X{
X	char		*dot;
X
X	if ((dot = strrchr(path, '.')) == NULL)
X		return "";
X	return dot;
X}
X
Xbool
XcanCrunch(path1, path2)
X	char		*path1;
X	char		*path2;
X{
X	char		*slash1;
X	char		*slash2;
X
X	slash1 = strrchr(path1, '/');
X	slash2 = strrchr(path2, '/');
X
X	if (slash1 == NULL && slash2 == NULL)
X		return strequ(suffName(path1), suffName(path2));
X	if ((slash1 - path1) != (slash2 - path2))
X		return FALSE;
X	if (!strnequ(path1, path2, slash1 - path1))
X		return FALSE;
X	return strequ(suffName(slash1), suffName(slash2));
X}
X#include	<sys/types.h>
X#include	<sys/stat.h>
X
X/* LookUp adds ../s to the beginning of a file name until it finds
X * the one that really exists. Returns NULL if it gets all the way
X * to / and never finds it.
X *
X * If the file name starts with /, just return it as is.
X *
X * This routine is used to locate the ID database file.
X */
Xchar *
XLookUp(arg)
X	char *		arg;
X{
X	char *		p;
X	static char	pathBuf[BUFSIZ];
X	struct stat	rootb;
X	struct stat	statb;
X
X	/* if we got absolute name, just use it. */
X	if (arg[0] == '/') return(arg);
X	/* if the name we were give exists, don't bother searching */
X	if (stat(arg, &statb) == 0) return(arg);
X	/* search up the tree until we find a directory where this
X	 * relative file name is visible.
X	 * (or we run out of tree to search by hitting root).
X	 */
X	p = pathBuf;
X	if (stat("/", &rootb) != 0) return(NULL);
X	do {
X		strcpy(p, "../");
X		p += 3;
X		strcpy(p, arg);
X		if (stat(pathBuf, &statb) == 0) return(pathBuf);
X		*p = '\0';
X		if (stat(pathBuf, &statb) != 0) return(NULL);
X	} while (! ((statb.st_ino == rootb.st_ino) ||
X                    (statb.st_dev == rootb.st_dev)));
X	return(NULL);
X}
END_OF_FILE
if test 5284 -ne `wc -c <'paths.c'`; then
    echo shar: \"'paths.c'\" unpacked with wrong size!
fi
# end of 'paths.c'
fi
if test -f 'scan-text.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'scan-text.c'\"
else
echo shar: Extracting \"'scan-text.c'\" \(4062 characters\)
sed "s/^X//" >'scan-text.c' <<'END_OF_FILE'
X/* Copyright (c) 1986, Greg McGary */
X/* Assembler scanner hacked into a Text scanner by Tom Horsley 1988 */
X
X#include	<bool.h>
X#include	<stdio.h>
X#include	<string.h>
X#include	<ctype.h>
X#include	<id.h>
X
Xchar *getTextId();
Xvoid setTextArgs();
X
Xstatic void clrCtype();
Xstatic void setCtype();
X
X#define	I1	0x01	/* 1st char of an identifier [a-zA-Z_] */
X#define	NM	0x02	/* digit [0-9a-fA-FxX] */
X#define SQ	0x04	/* squeeze these out (.,',-) */
X#define	EF	0x80	/* EOF */
X
X/* Text character classes */
X#define	ISID1ST(c)	((rct)[c]&(I1))
X#define	ISIDREST(c)	((rct)[c]&(I1|NM|SQ))
X#define	ISNUMBER(c)	((rct)[c]&(NM))
X#define	ISEOF(c)	((rct)[c]&(EF))
X#define	ISBORING(c)	(!((rct)[c]&(I1|NM|EF)))
X#define ISIDSQUEEZE(c)	((rct)[c]&(SQ))
X
Xstatic char idctype[] = {
X
X	EF,
X
X	/*      0       1       2       3       4       5       6       7   */
X	/*    -----   -----   -----   -----   -----   -----   -----   ----- */
X
X	/*000*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*010*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*020*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*030*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*040*/	0,	0,	0,	0,	0,	0,	0,	SQ,
X	/*050*/	0,	0,	0,	0,	0,	SQ,	SQ,	0,
X	/*060*/	NM,	NM,	NM,	NM,	NM,	NM,	NM,	NM,	
X	/*070*/	NM,	NM,	0,	0,	0,	0,	0,	0,
X	/*100*/	0,	I1|NM,	I1|NM,	I1|NM,	I1|NM,	I1|NM,	I1|NM,	I1,
X	/*110*/	I1,	I1,	I1,	I1,	I1|NM,	I1,	I1,	I1,
X	/*120*/	I1,	I1,	I1,	I1,	I1,	I1,	I1,	I1,
X	/*130*/	I1|NM,	I1,	I1,	0,	0,	0,	0,	I1,
X	/*140*/	0,	I1|NM,	I1|NM,	I1|NM,	I1|NM,	I1|NM,	I1|NM,	I1,
X	/*150*/	I1,	I1,	I1,	I1,	I1|NM,	I1,	I1,	I1,
X	/*160*/	I1,	I1,	I1,	I1,	I1,	I1,	I1,	I1,
X	/*170*/	I1|NM,	I1,	I1,	0,	0,	0,	0,	0,
X
X	/*200*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*210*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*220*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*230*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*240*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*250*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*260*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*270*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*300*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*310*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*320*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*330*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*340*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*350*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*360*/	0,	0,	0,	0,	0,	0,	0,	0,
X	/*370*/	0,	0,	0,	0,	0,	0,	0,	0,
X
X};
X
X/* 
X        Grab the next identifier the text source file opened with the
X	handle `inFILE'.  This state machine is built for speed, not
X	elegance.
X*/
Xchar *
XgetTextId(inFILE, flagP)
X	FILE		*inFILE;
X	int		*flagP;
X{
X	static char	idBuf[BUFSIZ];
X	register char	*rct = &idctype[1];
X	register int	c;
X	register char	*id = idBuf;
X
Xtop:
X	c = getc(inFILE);
X	while (ISBORING(c))
X		c = getc(inFILE);
X	if (ISEOF(c)) {
X		return NULL;
X	}
X	id = idBuf;
X	*id++ = c;
X	if (ISID1ST(c)) {
X		*flagP = IDN_NAME;
X		while (ISIDREST(c = getc(inFILE)))
X			if (! ISIDSQUEEZE(c)) *id++ = c;
X	} else if (ISNUMBER(c)) {
X		*flagP = IDN_NUMBER;
X		while (ISNUMBER(c = getc(inFILE)))
X			*id++ = c;
X	} else {
X		if (isprint(c))
X			fprintf(stderr, "junk: `%c'", c);
X		else
X			fprintf(stderr, "junk: `\\%03o'", c);
X		goto top;
X	}
X
X	*id = '\0';
X	ungetc(c, inFILE);
X	*flagP |= IDN_LITERAL;
X	return idBuf;
X}
X
Xstatic void
XsetCtype(chars, type)
X	char		*chars;
X	int		type;
X{
X	char		*rct = &idctype[1];
X
X	while (*chars)
X		rct[*chars++] |= type;
X}
Xstatic void
XclrCtype(chars, type)
X	char		*chars;
X	int		type;
X{
X	char		*rct = &idctype[1];
X
X	while (*chars)
X		rct[*chars++] &= ~type;
X}
X
Xextern char	*MyName;
Xstatic void
Xusage(lang)
X	char		*lang;
X{
X	fprintf(stderr, "Usage: %s -S%s([(+|-)a<cc>] [(+|-)s<cc>]\n", MyName, lang);
X	exit(1);
X}
Xstatic char *textDocument[] =
X{
X"The Text scanner arguments take the form -Stext<arg>, where",
X"<arg> is one of the following: (<cc> denotes one or more characters)",
X"  (+|-)a<cc> . . Include (or exculde) <cc> in ids.",
X"  (+|-)s<cc> . . Squeeze (or don't squeeze) <cc> out of ids.",
XNULL
X};
Xvoid
XsetTextArgs(lang, op, arg)
X	char		*lang;
X	int		op;
X	char		*arg;
X{
X	if (op == '?') {
X		document(textDocument);
X		return;
X	}
X	switch (*arg++)
X	{
X	case 'a':
X		if (op == '+') {
X			setCtype(arg, I1) ;
X		} else {
X			clrCtype(arg, I1) ;
X		}
X		break;
X	case 's':
X		if (op == '+') {
X			setCtype(arg, SQ) ;
X		} else {
X			clrCtype(arg, SQ) ;
X		}
X		break;
X	default:
X		if (lang)
X			usage(lang);
X		break;
X	}
X}
END_OF_FILE
if test 4062 -ne `wc -c <'scan-text.c'`; then
    echo shar: \"'scan-text.c'\" unpacked with wrong size!
fi
# end of 'scan-text.c'
fi
if test -f 'symfunc.el' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'symfunc.el'\"
else
echo shar: Extracting \"'symfunc.el'\" \(3162 characters\)
sed "s/^X//" >'symfunc.el' <<'END_OF_FILE'
X;; This file provides functions for symbols, that is, things consisting only
X;; of characters matching the regular expression \(\w\|\s_\).  The functions
X;; are similar to those provided for words (e.g., symbol-around-point is
X;; just like word-around-point).
X
X(provide 'symfunc)
X
X(defvar symbol-char-re "\\(\\w\\|\\s_\\)"
X"The regular expression that matches a character belonging to a symbol.")
X
X(defun symbol-around-point ()
X  "return the symbol around the point as a string"
X  (save-excursion
X    (let (beg)
X      (if (not (at-beginning-of-symbol))
X	  (forward-symbol -1))
X      (setq beg (point))
X      (forward-symbol 1)
X      (buffer-substring beg (point))
X    )
X  )
X)
X
X(defun at-beginning-of-symbol ()
X"Return t if point is currently positioned at the beginning of
Xa symbol."
X   (and
X      (looking-at symbol-char-re)
X      (not (looking-back symbol-char-re))
X   )
X)
X
X(defun forward-symbol (arg)
X"Move point forward ARG symbols (backward if ARG is negative).
XNormally returns t.
XIf an edge of the buffer is reached, point is left there
Xand nil is returned.
XIt is faster to call backward-symbol than to call forward-symbol
Xwith a negative argument."
X   (interactive "p")
X   (if (null arg)
X      (setq arg 1)
X   )
X   (if (< arg 0)
X      (backward-symbol (- arg))
X      (progn
X         (while (> arg 0)
X            (condition-case ()
X               (progn
X                  (while (not (looking-at symbol-char-re))
X                     (forward-char 1)
X                  )
X                  (while (looking-at symbol-char-re)
X                     (forward-char 1)
X                  )
X                  t
X               )
X               (error nil)          ;; Return nil if error
X            )
X            (setq arg (1- arg))
X         )
X      )
X   )
X)
X
X(defun backward-symbol (arg)
X"Move backward until encountering the end of a symbol.
XWith argument, do this that many times.
XIn programs, it is faster to call forward-symbol
Xthan to call backward-symbol with a negative arg."
X   (interactive "p")
X   (if (null arg)
X      (setq arg 1)
X   )
X   (if (< arg 0)
X      (forward-symbol (- arg))
X      (progn
X         (while (> arg 0)
X            (condition-case ()
X               (progn
X                  (while (not (looking-back symbol-char-re))
X                     (forward-char -1)
X                  )
X                  (while (looking-back symbol-char-re)
X                     (forward-char -1)
X                  )
X                  t
X               )
X               (error nil)          ;; Return nil if error
X            )
X            (setq arg (1- arg))
X         )
X      )
X   )
X)
X
X;; Additional word-oriented functions.
X
X(defun word-around-point ()
X  "return the word around the point as a string"
X  (save-excursion
X    (let (beg)
X      (if (not (looking-at "\\<"))
X	  (forward-word -1))
X      (setq beg (point))
X      (forward-word 1)
X      (buffer-substring beg (point)))))
X
X;; The looking-back function used to exist in Emacs distribution, but
X;; it disappeared in 18.52.
X
X(defun looking-back (str)
X  "returns t if looking back reg-exp STR before point."
X  (and
X     (save-excursion (re-search-backward str nil t))
X     (= (point) (match-end 0))
X  )
X)
END_OF_FILE
if test 3162 -ne `wc -c <'symfunc.el'`; then
    echo shar: \"'symfunc.el'\" unpacked with wrong size!
fi
# end of 'symfunc.el'
fi
echo shar: End of archive 3 \(of 11\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 11 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
--
======================================================================
domain: tahorsley at csd.harris.com       USMail: Tom Horsley
  uucp: ...!uunet!hcx1!tahorsley               511 Kingbird Circle
                                               Delray Beach, FL  33444
+==== Censorship is the only form of Obscenity ======================+
|     (Wait, I forgot government tobacco subsidies...)               |
+====================================================================+



More information about the Alt.sources mailing list