home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / elm-2.4-pl20.tar.Z / elm-2.4-pl20.tar / lib / len_next.c < prev    next >
C/C++ Source or Header  |  1992-10-03  |  2KB  |  76 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: len_next.c,v 5.1 1992/10/03 22:41:36 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1992 USENET Community Trust
  8.  *******************************************************************************
  9.  * Bug reports, patches, comments, suggestions should be sent to:
  10.  *
  11.  *    Syd Weinstein, Elm Coordinator
  12.  *    elm@DSI.COM            dsinc!elm
  13.  *
  14.  *******************************************************************************
  15.  * $Log: len_next.c,v $
  16.  * Revision 5.1  1992/10/03  22:41:36  syd
  17.  * Initial checkin as of 2.4 Release at PL0
  18.  *
  19.  *
  20.  ******************************************************************************/
  21.  
  22. /** get the length of the next part of the address/data field
  23.  
  24.     This code returns the length of the next part of the
  25.   string field containing address/data.  It takes into account
  26.   quoting via " as well as \ escapes.
  27.   Quoting via ' is not taken into account, as RFC-822 does not
  28.   consider a ' character a valid 'quoting character'
  29.  
  30.   A 1 is returned for a single character unless:
  31.  
  32.   A 0 is returned at end of string.
  33.  
  34.   A 2 is returned for strings that start \
  35.  
  36.   The length of quoted sections is returned for quoted fields
  37.  
  38. **/
  39.  
  40. #include <ctype.h>
  41.  
  42.  
  43. int
  44. len_next_part(s)
  45. register char *s;
  46. {
  47.     register char *c, quot;
  48.  
  49.     quot = *s;
  50.  
  51.     if (quot == '\0')
  52.       return(0);
  53.  
  54.     if (quot == '\\') {
  55.       if (*s++)
  56.         return(2);
  57.       else
  58.         return(1);
  59.     }
  60.  
  61.     if (quot != '"')
  62.       return(1);
  63.  
  64.     for (c = s + 1; *c; c++) {
  65.       if (*c == quot)
  66.         return(1 + c - s);
  67.  
  68.           if (*c == '\\') {
  69.         if (*c++)
  70.           c++;
  71.       }
  72.     }
  73.  
  74.     return(c - s);
  75. }
  76.