home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / strvcmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-19  |  1.5 KB  |  65 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: strvcmp.c,v 1.3 1995/02/19 18:32:14 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    strvcmp.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    05 Nov 1984
  9.  * Last update:
  10.  *        19 Feb 1995, prototyped
  11.  *
  12.  * Function:    This procedure performs a string-comparison, equating
  13.  *        upper- and lowercase, and treating any sequence of "whitespace"
  14.  *        (space and carriage control, including tab) as a single
  15.  *        blank.
  16.  *
  17.  * Arguments:    ref_    => reference template (an uppercased string, with
  18.  *               no more than one blank in a row, ending with
  19.  *               a null).  (See: 'strvcpy').
  20.  *        tst_    => the string to test the template against.  It need
  21.  *               end with a null, but a null will force the end-of-
  22.  *               compare.
  23.  *        len    =  the maximum number of characters from 'tst_[]' to
  24.  *               match.
  25.  *
  26.  * Returns:    The number of characters from 'tst_[]' which resulted from the
  27.  *        match with 'ref_[]', UNLESS a mismatch was found, in this case
  28.  *        zero.
  29.  */
  30.  
  31. #include    <ctype.h>
  32.  
  33. #include    "strutils.h"
  34.  
  35. int
  36. strvcmp (char *ref_, char *tst_, int len)
  37. {
  38.     register
  39.     char    *r_    = ref_,    /* force the pointer off the stack    */
  40.         *t_    = tst_;
  41.     register
  42.     int    matched    = 0, t;
  43.  
  44.     while (len > matched && *r_)
  45.     {
  46.         if (isspace(*r_))
  47.         {
  48.             if (!isspace(*t_))    return (0);
  49.             while (isspace(*t_))    t_++, matched++;
  50.             r_++;
  51.         }
  52.         else if (*r_)
  53.         {
  54.             t = toascii(*t_);
  55.             t = _toupper(t);
  56.             if (*r_++ != t)        return (0);
  57.             t_++, matched++;
  58.         }
  59.     }
  60.     if (*r_)        return (0);
  61.  
  62.     if (matched > len)    matched = len;
  63.     return (matched);
  64. }
  65.