$NetBSD: patch-af,v 1.1 2000/05/20 18:41:43 kim Exp $ --- muttlib.c 2000/05/16 15:23:02 2.19 +++ muttlib.c 2000/05/20 07:46:06 @@ -33,10 +33,12 @@ #include #include #include -#include #include #include +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#define MAX(a,b) ((a) < (b) ? (b) : (a)) + BODY *mutt_new_body (void) { BODY *p = (BODY *) safe_calloc (1, sizeof (BODY)); @@ -452,6 +454,46 @@ return (s); } + +char *mutt_gecos_name (char *dest, size_t destlen, struct passwd *pw) +{ + regmatch_t pat_match[1]; + size_t pwnl; + int idx; + char *p; + + if (!pw || !pw->pw_gecos) + return NULL; + + memset (dest, 0, destlen); + + if (GecosMask.rx) + { + if (regexec (GecosMask.rx, pw->pw_gecos, 1, pat_match, 0) == 0) + strfcpy (dest, pw->pw_gecos + pat_match[0].rm_so, + MIN (pat_match[0].rm_eo - pat_match[0].rm_so + 1, destlen)); + } + else if ((p = strchr (pw->pw_gecos, ','))) + strfcpy (dest, pw->pw_gecos, MIN (destlen, p - pw->pw_gecos + 1)); + else + strfcpy (dest, pw->pw_gecos, destlen); + + pwnl = strlen (pw->pw_name); + + for (idx = 0; dest[idx]; idx++) + { + if (dest[idx] == '&') + { + memmove (&dest[idx + pwnl], &dest[idx + 1], + MAX(destlen - idx - pwnl - 1, 0)); + memcpy (&dest[idx], pw->pw_name, MIN(destlen - idx - 1, pwnl)); + dest[idx] = toupper (dest[idx]); + } + } + + return dest; +} + char *mutt_get_parameter (const char *s, PARAMETER *p) {