2000-08-12 21:55:49 +00:00
|
|
|
/*
|
2001-08-01 01:33:27 +00:00
|
|
|
* Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
|
2000-08-12 21:55:49 +00:00
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 1997 Eric P. Allman. All rights reserved.
|
|
|
|
* Copyright (c) 1988, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* By using this file, you agree to the terms and conditions set
|
|
|
|
* forth in the LICENSE file which can be found at the top level of
|
|
|
|
* the sendmail distribution.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sendmail.h>
|
|
|
|
|
2002-06-11 21:12:04 +00:00
|
|
|
SM_RCSID("@(#)$Id: snprintf.c,v 8.44 2001/09/11 04:04:56 gshapiro Exp $")
|
2000-08-12 21:55:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** SHORTENSTRING -- return short version of a string
|
|
|
|
**
|
|
|
|
** If the string is already short, just return it. If it is too
|
|
|
|
** long, return the head and tail of the string.
|
|
|
|
**
|
|
|
|
** Parameters:
|
|
|
|
** s -- the string to shorten.
|
|
|
|
** m -- the max length of the string (strlen()).
|
|
|
|
**
|
|
|
|
** Returns:
|
|
|
|
** Either s or a short version of s.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *
|
|
|
|
shortenstring(s, m)
|
|
|
|
register const char *s;
|
2002-02-17 21:56:45 +00:00
|
|
|
size_t m;
|
2000-08-12 21:55:49 +00:00
|
|
|
{
|
2002-02-17 21:56:45 +00:00
|
|
|
size_t l;
|
2000-08-12 21:55:49 +00:00
|
|
|
static char buf[MAXSHORTSTR + 1];
|
|
|
|
|
|
|
|
l = strlen(s);
|
|
|
|
if (l < m)
|
|
|
|
return (char *) s;
|
|
|
|
if (m > MAXSHORTSTR)
|
|
|
|
m = MAXSHORTSTR;
|
|
|
|
else if (m < 10)
|
|
|
|
{
|
|
|
|
if (m < 5)
|
|
|
|
{
|
2002-02-17 21:56:45 +00:00
|
|
|
(void) sm_strlcpy(buf, s, m + 1);
|
2000-08-12 21:55:49 +00:00
|
|
|
return buf;
|
|
|
|
}
|
2002-02-17 21:56:45 +00:00
|
|
|
(void) sm_strlcpy(buf, s, m - 2);
|
|
|
|
(void) sm_strlcat(buf, "...", sizeof buf);
|
2000-08-12 21:55:49 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
m = (m - 3) / 2;
|
2002-02-17 21:56:45 +00:00
|
|
|
(void) sm_strlcpy(buf, s, m + 1);
|
|
|
|
(void) sm_strlcat2(buf, "...", s + l - m, sizeof buf);
|
2000-08-12 21:55:49 +00:00
|
|
|
return buf;
|
|
|
|
}
|