Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / h / formatsbr.h
1 /* formatsbr.h - definitions for fmtscan () */
2 /* $Id: formatsbr.h,v 1.1 1992/01/23 23:14:54 jromine Exp $ */
3
4 /*
5  * This structure describes an "interesting" component.  It holds
6  * the name & text from the component (if found) and one piece of
7  * auxilary info.  The structure for a particular component is located
8  * by hashing the name and using it as an index into the ptr array
9  * "wantcomp".  All format entries that reference a particular component
10  * point to its comp struct (so we only have to do component specific
11  * processing once.  e.g., parse an address.).
12  */
13 struct comp {
14         char            *c_name;        /* component name (in lower case) */
15         struct  comp    *c_next;        /* hash chain linkage */
16         char            *c_text;        /* component text (if found) */
17         short           c_flags;        /* misc. flags (from formatsbr) */
18         short           c_type;         /* type info (from fmtcompile) */
19         union {
20                 struct tws      *c_u_tws;
21                 struct mailname *c_u_mn;
22         } c_un;
23 #define c_tws c_un.c_u_tws
24 #define c_mn c_un.c_u_mn
25 };
26
27 /* c_type bits */
28 #define CT_ADDR         1       /* referenced as address */
29 #define CT_DATE         2       /* referenced as date */
30 #define CT_MYMBOX       4       /* "mymbox" test being done */
31 #define CT_ADDRPARSE    8       /* address parse being done */
32
33 extern int fmt_norm;
34
35 struct  comp    *wantcomp[128]; /* hash table for deciding if a
36                                  * component is "interesting" */
37
38 /* 
39  * Hash function for component name.  The function should be
40  * case independent and probably shouldn't involve a routine
41  * call.  This function is pretty good but will not work on
42  * single character component names.  
43  */
44 #define CHASH(nm)       (((((nm)[0]) - ((nm)[1])) & 0x1f) + (((nm)[2]) & 0x5f))
45
46 #ifdef  GOULD_PN
47 /* bug in the Gould PowerNode compiler: need a local pointer to name... */
48 #define FINDCOMP(comp,name1) \
49         { \
50         char *name = (name1); \
51         for (comp = wantcomp[CHASH(name)]; \
52                 comp && strcmp(comp->c_name,name); \
53                 comp = comp->c_next) ; \
54         }
55 #else
56 #define FINDCOMP(comp,name) \
57                 for (comp = wantcomp[CHASH(name)]; \
58                      comp && strcmp(comp->c_name,name); \
59                      comp = comp->c_next) ;
60 #endif
61
62 /*
63  * This structure defines one formatting instruction.
64  */
65 struct format {
66         unsigned char   f_type;
67         char            f_fill;
68         short           f_width;        /* output field width */
69 #define f_skip f_width                  /* instr to skip (false "if") */
70         union {
71                 struct comp     *f_u_comp;      /* associated component */
72                 char            *f_u_text;      /* literal text */
73                 char            f_u_char;       /* literal character */
74                 int             f_u_value;      /* literal value */
75         } f_un;
76 #define f_comp f_un.f_u_comp
77 #define f_text f_un.f_u_text
78 #define f_char f_un.f_u_char
79 #define f_value f_un.f_u_value
80 };
81
82 struct format *fmtscan ();
83 char   *new_fs ();