X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=h%2Ffmt_scan.h;h=8de6f23d3760e6a5725d7383b04bc0b5f9225970;hb=a814e2957bf53b2ecef28593f325cd082122ba52;hp=db10c171b3ad01ac73c7a1a5655006b157501735;hpb=fe89a5c2fd062e9893b1d9d22d909a6368c53217;p=mmh diff --git a/h/fmt_scan.h b/h/fmt_scan.h index db10c17..8de6f23 100644 --- a/h/fmt_scan.h +++ b/h/fmt_scan.h @@ -47,23 +47,6 @@ struct comp { extern int fmt_norm; -/* - * Hash function for component name. The function should be - * case independent and probably shouldn't involve a routine - * call. This function is pretty good but will not work on - * single character component names. - */ -#define CHASH(nm) (((((nm)[0]) - ((nm)[1])) & 0x1f) + (((nm)[2]) & 0x5f)) - -/* - * Find a component in the hash table. - */ -#define FINDCOMP(comp,name) \ - for (comp = wantcomp[CHASH(name)]; \ - comp && strcmp(comp->c_name,name); \ - comp = comp->c_next) \ - ; - /* * This structure defines one formatting instruction. */ @@ -77,6 +60,7 @@ struct format { char f_u_char; /* literal character */ int f_u_value; /* literal value */ } f_un; + short f_flags; /* misc. flags */ }; #define f_skip f_width /* instr to skip (false "if") */ @@ -87,6 +71,13 @@ struct format { #define f_value f_un.f_u_value /* + * f_flags bits + */ + +#define FF_STRALLOC (1<<0) /* String has been allocated */ +#define FF_COMPREF (1<<1) /* Component reference */ + +/* * prototypes used by the format engine */ @@ -120,7 +111,8 @@ char *new_fs (char *form, char *format, char *default_fs); * strings that you want to compile and operate on the * same message, this should be set to false. * - * Returns the number of components referenced by the format instructions. + * Returns the total number of components referenced by all format instructions + * since the last reset of the hash table. */ int fmt_compile (char *fstring, struct format **fmt, int reset); @@ -181,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_findcasecomp(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 @@ -202,16 +213,18 @@ struct comp *fmt_findcomp(char *component); * * This function is designed to be called when you start processing a new * component. The function returns the integer value of the hash table - * bucket corresponding to this component. + * bucket corresponding to this component. If there was no entry found + * 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: * * bucket - The hash table bucket corresponding to this component, - * as returned by fmt_addcomp(). + * as returned by fmt_addcomp(). If -1, this function will + * return with no actions performed. * component - The component to append text to. Like fmt_addcomp, the * component is searched case-INSENSITIVELY. * text - The text to append to the component. No special processing