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