home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / libcs / sindex.c < prev    next >
C/C++ Source or Header  |  1990-12-11  |  3KB  |  71 lines

  1. /*
  2.  * Copyright (c) 1990 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * THE SOFTWARE IS PROVIDED "AS IS" AND CARNEGIE MELLON UNIVERSITY
  12.  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  13.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT
  14.  * SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, DIRECT,
  15.  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  17.  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  *
  20.  * Users of this software agree to return to Carnegie Mellon any
  21.  * improvements or extensions that they make and grant Carnegie the
  22.  * rights to redistribute these changes.
  23.  *
  24.  * Export of this software is permitted only after complying with the
  25.  * regulations of the U.S. Deptartment of Commerce relating to the
  26.  * Export of Technical Data.
  27.  */
  28. /*  sindex  --  find index of one string within another
  29.  *
  30.  *  Usage:  p = sindex (big,small)
  31.  *    char *p,*big,*small;
  32.  *
  33.  *  Sindex searches for a substring of big which matches small,
  34.  *  and returns a pointer to this substring.  If no matching
  35.  *  substring is found, 0 is returned.
  36.  *
  37.  * HISTORY
  38.  * $Log:    sindex.c,v $
  39.  * Revision 1.2  90/12/11  17:58:59  mja
  40.  *     Add copyright/disclaimer for distribution.
  41.  * 
  42.  * 26-Jun-81  David Smith (drs) at Carnegie-Mellon University
  43.  *    Rewritten to avoid call on strlen(), and generally speed up things.
  44.  *
  45.  * 20-Nov-79  Steven Shafer (sas) at Carnegie-Mellon University
  46.  *    Adapted for VAX from indexs() on the PDP-11 (thanx to Ralph
  47.  *    Guggenheim).  The name has changed to be more like the index()
  48.  *    and rindex() functions from Bell Labs; the return value (pointer
  49.  *    rather than integer) has changed partly for the same reason,
  50.  *    and partly due to popular usage of this function.
  51.  *
  52.  *  Originally from rjg (Ralph Guggenheim) on IUS/SUS UNIX.
  53.  */
  54.  
  55.  
  56. char *sindex (big,small) char *big,*small;
  57.     {
  58.     register char *bp, *bp1, *sp;
  59.     register char c = *small++;
  60.  
  61.     if (c==0) return(0);
  62.     for (bp=big;  *bp;  bp++)
  63.     if (*bp == c)
  64.         {
  65.         for (sp=small,bp1=bp+1;   *sp && *sp == *bp1++;  sp++)
  66.         ;
  67.         if (*sp==0) return(bp);
  68.         }
  69.     return 0;
  70.     }
  71.