1N/A/*
1N/A * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
1N/A * All rights reserved.
1N/A * Copyright (c) 1997 Eric P. Allman. All rights reserved.
1N/A * Copyright (c) 1988, 1993
1N/A * The Regents of the University of California. All rights reserved.
1N/A *
1N/A * By using this file, you agree to the terms and conditions set
1N/A * forth in the LICENSE file which can be found at the top level of
1N/A * the sendmail distribution.
1N/A *
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#include <sendmail.h>
1N/A
1N/ASM_RCSID("@(#)$Id: snprintf.c,v 8.41 2001/08/28 23:07:01 gshapiro Exp $")
1N/A
1N/A /*
1N/A** SHORTENSTRING -- return short version of a string
1N/A**
1N/A** If the string is already short, just return it. If it is too
1N/A** long, return the head and tail of the string.
1N/A**
1N/A** Parameters:
1N/A** s -- the string to shorten.
1N/A** m -- the max length of the string (strlen()).
1N/A**
1N/A** Returns:
1N/A** Either s or a short version of s.
1N/A*/
1N/A
1N/Achar *
1N/Ashortenstring(s, m)
1N/A register const char *s;
1N/A size_t m;
1N/A{
1N/A size_t l;
1N/A static char buf[MAXSHORTSTR + 1];
1N/A
1N/A l = strlen(s);
1N/A if (l < m)
1N/A return (char *) s;
1N/A if (m > MAXSHORTSTR)
1N/A m = MAXSHORTSTR;
1N/A else if (m < 10)
1N/A {
1N/A if (m < 5)
1N/A {
1N/A (void) sm_strlcpy(buf, s, m + 1);
1N/A return buf;
1N/A }
1N/A (void) sm_strlcpy(buf, s, m - 2);
1N/A (void) sm_strlcat(buf, "...", sizeof buf);
1N/A return buf;
1N/A }
1N/A m = (m - 3) / 2;
1N/A (void) sm_strlcpy(buf, s, m + 1);
1N/A (void) sm_strlcat2(buf, "...", s + l - m, sizeof buf);
1N/A return buf;
1N/A}