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

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: strform2.c,v 1.4 1995/06/06 13:41:18 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    strform2.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    13 Jul 1984
  9.  * Last update:
  10.  *        19 Feb 1995, prototypes
  11.  *
  12.  * Function:    Format a message into a buffer with restricted size.  The
  13.  *        message consists of tag and text portions, with a separator.
  14.  *
  15.  * Parameters:    out    = output buffer
  16.  *        maxout    = maximum length of out[], including null.
  17.  *        s1[]    = tag (or message)
  18.  *        len1    = length(s1), if > 0.
  19.  *        s2[]    = object/text portion
  20.  *        len2    = length(s2), if > 0.
  21.  */
  22.  
  23. #include <string.h>
  24.  
  25. #include "strutils.h"
  26.  
  27. void
  28. strform2 (
  29.     char    *out,    int    maxout,
  30.     char    *s1,    int    len1,
  31.     char    *s2,    int    len2)
  32. {
  33.     maxout--;    /* count one for the trailing null    */
  34.     out[0]    = '\0';
  35.     maxout    = strform1 (out,      maxout, s1, len1);
  36.     maxout    = strform1 (strnull(out), maxout, ": ", 0);
  37.     maxout    = strform1 (strnull(out), maxout, s2, len2);
  38. }
  39.  
  40. /*
  41.  * Title:    strform1
  42.  *
  43.  * Function:    Perform a restricted string-copy into the output buffer if
  44.  *        the input string is non-null, and if there is any space in
  45.  *        the output buffer.
  46.  *
  47.  * Parameters:    out[]    = output buffer
  48.  *        maxout    = space left in buffer
  49.  *        s1    = string to copy, if non-null.
  50.  *        len1    = length(s1), if > 0.  If zero, do 'strlen()' to get
  51.  *              the actual length.
  52.  *
  53.  * Returns:    the space left in 'out[]' after the copy.
  54.  */
  55.  
  56. int    strform1 (char *out, int maxout, char *s1, int len1)
  57. {
  58.     if (s1 && (maxout > 0))
  59.     {
  60.         if (len1 <= 0)        len1    = strlen(s1);
  61.         if (len1 > maxout)    len1    = maxout;
  62.         strncpy (out, s1, len1);
  63.         out[len1] = '\0';
  64.         maxout    -= len1;
  65.     }
  66.     return (maxout);    /* return the remaining space in buffer    */
  67. }
  68.