From 096cb902c659b224590c2989020d437721d8e9e5 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Mon, 19 Nov 2012 12:23:16 -0500 Subject: [PATCH] Change API a bit. Rename fmt_addcomp() to fmt_addcomptext(). Create new function fmt_addcompentry(). --- h/fmt_scan.h | 21 ++++++++++++++++++++- sbr/fmt_compile.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- uip/mhlsbr.c | 2 +- uip/rcvdist.c | 2 +- 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/h/fmt_scan.h b/h/fmt_scan.h index 466a9b5..a2bff89 100644 --- a/h/fmt_scan.h +++ b/h/fmt_scan.h @@ -173,6 +173,25 @@ void fmt_free (struct format *fmt, int reset); struct comp *fmt_findcomp(char *component); /* + * Search for a component structure in the component hash table. + * + * Identical to fmd_findcomp(), but is case-INSENSITIVE. + */ + +struct comp *fmt_findcasecmp(char *component); + +/* + * Add a component entry to the component hash table + * + * component - The name of the component to add to the hash table. + * + * If the component is already in the hash table, this function will do + * nothing. Returns 1 if a component was added, 0 if it already existed. + */ + +int fmt_addcompentry(char *component); + +/* * Add a string to a component hash table entry. Arguments are: * * component - The name of the component to add text to. The component @@ -198,7 +217,7 @@ struct comp *fmt_findcomp(char *component); * in the component hash table, this function will return -1. */ -int fmt_addcomp(char *component, char *text); +int fmt_addcomptext(char *component, char *text); /* * Append to an existing component. Arguments are: diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index 6583195..148d35c 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -873,6 +873,53 @@ fmt_findcomp(char *component) } /* + * Like fmt_findcomp, but case-insensitive. + */ + +struct comp * +fmt_findcasecmp(char *component) +{ + struct comp *cm; + + for (cm = wantcomp[CHASH(component)]; cm; cm = cm->c_next) + if (mh_strcasecmp(component, cm->c_name) == 0) + break; + + return cm; +} + +/* + * Add an entry to the component hash table + * + * Returns true if the component was added, 0 if it already existed. + * + */ + +int +fmt_addcompentry(char *component) +{ + struct comp *cm; + int i; + + FINDCOMP(cm, component); + + if (cm) + return 0; + + NEWCOMP(cm, component); + + /* + * ncomp is really meant for fmt_compile() and this function is + * meant to be used outside of it. So decrement it just to be safe + * (internal callers should be using NEWCOMP()). + */ + + ncomp--; + + return 1; +} + +/* * Add a string to a component hash table entry. * * Note the special handling for components marked with CT_ADDR. The comments @@ -880,7 +927,7 @@ fmt_findcomp(char *component) */ int -fmt_addcomp(char *component, char *text) +fmt_addcomptext(char *component, char *text) { int i, found = 0, bucket = CHASH(component); struct comp *cptr = wantcomp[bucket]; diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 53b61f9..2d101d1 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -1018,7 +1018,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec) switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { case FLD: case FLDPLUS: - bucket = fmt_addcomp(name, buf); + bucket = fmt_addcomptext(name, buf); for (ip = ignores; *ip; ip++) if (!mh_strcasecmp (name, *ip)) { while (state == FLDPLUS) { diff --git a/uip/rcvdist.c b/uip/rcvdist.c index d189e8e..d3f36ca 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -196,7 +196,7 @@ rcvdistout (FILE *inb, char *form, char *addrs) switch (state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb)) { case FLD: case FLDPLUS: - i = fmt_addcomp(name, tmpbuf); + i = fmt_addcomptext(name, tmpbuf); if (i != -1) { char_read += msg_count; while (state == FLDPLUS) { -- 1.7.10.4