| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

wordwrapstr

#include "sflstr.h"
char *
wordwrapstr (
    char *strbuff,
    int iwid)

Synopsis

Function that does word wraping of a string at or less than iwid. Breaks up a string on word boundaries by placing '\n' in the string. Returns a pointer to head of the return buffer. Submitted by Scott Beasley jscottb@infoave.com

Source Code - (sflstr.c)

{
   char *strtmp = strbuff;
   int icnt = 0;

   ASSERT (strbuff);

   replacechrswith (strbuff, "\n", ' ');
   while (*strtmp)
     {
       if ((int)strlen (strtmp) > (int)iwid)
         {
           icnt = iwid;
           while (*(strtmp + icnt))
             {
               if (strchr (" .?;!,", *(strtmp + icnt)))
                 {
                   ltrim ((strtmp + icnt));
                   insertchar (strtmp, '\n', icnt);
                   strtmp += icnt + 1;
                   break;
                 }
               icnt--;

               if (!icnt)
                 {
                   if (strchr (" .?;!,", *(strtmp + icnt)))
                     {
                       ltrim ((strtmp + iwid));
                       insertchar (strtmp, '\n', iwid);
                       strtmp += iwid + 1;
                       break;
                     }
                 }
             }
         }
       else
           break;
   }

   return strbuff;
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation