home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / format / rfctxtfold.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.6 KB  |  93 lines

  1. /* rfctxtfold.c - does simple folding for a string */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/format/RCS/rfctxtfold.c,v 6.0 1991/12/18 20:22:06 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/format/RCS/rfctxtfold.c,v 6.0 1991/12/18 20:22:06 jpo Rel $
  9.  *
  10.  * $Log: rfctxtfold.c,v $
  11.  * Revision 6.0  1991/12/18  20:22:06  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19.  
  20.  
  21.  
  22. /* -------------  Begin  Routines  ---------------------------------------- */
  23.  
  24.  
  25.  
  26.  
  27. void rfctxtfold (input, output, linelen)
  28. char    *input;
  29. char    *output;
  30. int     linelen;
  31. {
  32.     int     n       = 0,
  33.         nsav    = 0;
  34.     char    *insav  = NULLCP,
  35.         *outsav = NULLCP;
  36.  
  37.  
  38.     *output = NULL;
  39.     if (input == NULLCP)      return;
  40.  
  41.     while (*input) {
  42.         switch (*input) {
  43.  
  44.             case '\t':
  45.             n += 7;
  46.  
  47.             case ' ':
  48.             if (n == linelen && *(input+1)) {
  49.                 /* -- max len reached & more to come -- */
  50.                 input++;
  51.                 *output ++ = '\n';
  52.                 *output ++ = '\t';
  53.                 n = 8;
  54.                 break;
  55.             }
  56.             else if (n > linelen && *(input+1)) {
  57.                 /* -- max len exceeded & more to come -- */
  58.                 if (nsav && insav) {
  59.                     /* --- *** ---
  60.                     if values have been previously saved
  61.                     then go back to the previous spaces
  62.                     --- *** --- */
  63.                     n = 8;
  64.                     input = ++insav;
  65.                     *outsav ++ = '\n';
  66.                     *outsav ++ = '\t';
  67.                     output = outsav;
  68.                     nsav = 0;
  69.                     insav = outsav = NULLCP;
  70.                 }
  71.                 else
  72.                     goto rfctxtfold_save;
  73.             }
  74.             else {
  75. rfctxtfold_save:;
  76.                 /* -- save info and then fall -- */
  77.                 nsav = n;
  78.                 insav = input;
  79.                 outsav = output;
  80.             }
  81.  
  82.             default:
  83.             *output ++ = *input ++;
  84.             n ++;
  85.             break;
  86.         }
  87.     }
  88.  
  89.     if (n > 0 && *(output - 1) != '\n')
  90.         *output ++ = '\n';
  91.     *output = NULL;
  92. }
  93.