home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / c / string.arc / STRPACK.C < prev    next >
Text File  |  1984-12-31  |  1KB  |  40 lines

  1. /*  File   : strpack.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 20 April 1984
  4.     Defines: strpack()
  5.  
  6.     strpack(dst, src, set, c)
  7.     copies characters from src to dst, stopping when it finds a NUL.  If
  8.     c is NUL, characters in set are not copied to dst.  If c is not NUL,
  9.     sequences of characters from set are copied as a single c.
  10.     strpack(d, s, " \t", ' ') can be used to compress white space,
  11.     strpack(d, s, " \t", NUL) to eliminate it.  To translate  characters
  12.     in  set to c without compressing runs, see strtrans(). The result is
  13.     the address of the NUL byte now terminating dst.  Note that dst  may
  14.     safely be the same as src.
  15. */
  16.  
  17. #include "strings.h"
  18. #include "_str2set.h"
  19.  
  20. char *strpack(dst, src, set, c)
  21.     register _char_ *dst, *src;
  22.     char *set;
  23.     register int c;
  24.     {
  25.     register int chr;
  26.  
  27.     _str2set(set);
  28.     while (chr = *src++) {
  29.         if (_set_vec[chr] == _set_ctr) {
  30.         while ((chr = *src++) && _set_vec[chr] == _set_ctr) ;
  31.         if (c) *dst++ = c;    /* 1. If you don't want trailing */
  32.         if (!chr) break;    /* 2. things turned into "c", swap */
  33.         }                /* lines 1 and 2. */
  34.         *dst++ = chr;
  35.     }
  36.     *dst = 0;
  37.     return dst;
  38.     }
  39.