Added argument to fmt_scan() to specify the buffer size.
[mmh] / h / fmt_scan.h
1
2 /*
3  * fmt_scan.h -- definitions for fmt_scan()
4  */
5
6 /*
7  * This structure describes an "interesting" component.  It holds
8  * the name & text from the component (if found) and one piece of
9  * auxilary info.  The structure for a particular component is located
10  * by (open) hashing the name and using it as an index into the ptr array
11  * "wantcomp".  All format entries that reference a particular component
12  * point to its comp struct (so we only have to do component specific
13  * processing once.  e.g., parse an address.).
14  */
15 struct comp {
16     char        *c_name;        /* component name (in lower case) */
17     char        *c_text;        /* component text (if found)      */
18     struct comp *c_next;        /* hash chain linkage             */
19     short        c_flags;       /* misc. flags (from fmt_scan)    */
20     short        c_type;        /* type info   (from fmt_compile) */
21     union {
22         struct tws *c_u_tws;
23         struct mailname *c_u_mn;
24     } c_un;
25 };
26
27 #define c_tws c_un.c_u_tws
28 #define c_mn  c_un.c_u_mn
29
30 /*
31  * c_type bits
32  */
33 #define CT_ADDR       (1<<0)    /* referenced as address    */
34 #define CT_DATE       (1<<1)    /* referenced as date       */
35
36 /*
37  * c_flags bits
38  */
39 #define CF_TRUE       (1<<0)    /* usually means component is present */
40 #define CF_PARSED     (1<<1)    /* address/date has been parsed */
41 #define CF_DATEFAB    (1<<2)    /* datefield fabricated */
42 #define CF_TRIMMED    (1<<3)    /* Component has been trimmed */
43
44 extern int fmt_norm;
45
46 /*
47  * Hash table for deciding if a component is "interesting".
48  */
49 extern struct comp *wantcomp[128];
50
51 /* 
52  * Hash function for component name.  The function should be
53  * case independent and probably shouldn't involve a routine
54  * call.  This function is pretty good but will not work on
55  * single character component names.  
56  */
57 #define CHASH(nm) (((((nm)[0]) - ((nm)[1])) & 0x1f) + (((nm)[2]) & 0x5f))
58
59 /*
60  * Find a component in the hash table.
61  */
62 #define FINDCOMP(comp,name) \
63                 for (comp = wantcomp[CHASH(name)]; \
64                      comp && strcmp(comp->c_name,name); \
65                      comp = comp->c_next) \
66                 ;
67
68 /*
69  * This structure defines one formatting instruction.
70  */
71 struct format {
72     unsigned char f_type;
73     char          f_fill;
74     short         f_width;      /* output field width   */
75     union {
76         struct comp *f_u_comp;  /* associated component */
77         char        *f_u_text;  /* literal text         */
78         char         f_u_char;  /* literal character    */
79         int          f_u_value; /* literal value        */
80     } f_un;
81 };
82
83 #define f_skip f_width          /* instr to skip (false "if") */
84
85 #define f_comp  f_un.f_u_comp
86 #define f_text  f_un.f_u_text
87 #define f_char  f_un.f_u_char
88 #define f_value f_un.f_u_value
89
90 /*
91  * prototypes
92  */
93 struct format *fmt_scan (struct format *, char *, size_t, int, int *);
94 char *new_fs (char *, char *, char *);
95 int fmt_compile (char *, struct format **);
96 char *formataddr(char *, char *);
97 char *concataddr(char *, char *);
98 extern char *format_string;