Initial commit
[cgperf.git] / tests / smtp.gperf
blobda6ec7d2c7dfbc61ccbd51c437c9491b49221493
1 %{
2 /* gperf --struct-type --readonly-table --enum --global -K field_name -N header_entry --ignore-case */
3 /* Contributed by Bruce Lilly
4    derived from http://users.erols.com/blilly/mailparse/fields.gperf */
6 #include <string.h>
8 %}
9 struct header_state { const char *field_name; };
11 Accept-Language
12 Action
13 Alternate-Recipient
14 Approved
15 Archive
16 Arrival-Date
17 Autoforwarded
18 Autosubmitted
19 Bcc
21 Comments
22 Complaints-To
23 Content-alternative
24 Content-Base
25 Content-Description
26 Content-Disposition
27 Content-Duration
28 Content-Features
29 Content-ID
30 Content-Language
31 Content-Location
32 Content-MD5
33 Content-Transfer-Encoding
34 Content-Type
35 Control
36 Conversion
37 Conversion-With-Loss
38 DL-Expansion-History
39 DSN-Gateway
40 Date
41 Deferred-Delivery
42 Delivery-Date
43 Diagnostic-Code
44 Discarded-X400-IPMS-Extensions
45 Discarded-X400-MTS-Extensions
46 Disclose-Recipients
47 Disposition
48 Disposition-Notification-Options
49 Disposition-Notification-To
50 Distribution
51 Encrypted
52 Error
53 Expires
54 Failure
55 Final-Log-ID
56 Final-Recipient
57 Followup-To
58 From
59 Generate-Delivery-Report
60 Importance
61 In-Reply-To
62 Incomplete-Copy
63 Injector-Info
64 Keywords
65 Last-Attempt-Date
66 Latest-Delivery-Time
67 Lines
68 List-Archive
69 List-Help
70 List-ID
71 List-Post
72 List-Owner
73 List-Subscribe
74 List-Unsubscribe
75 MDN-Gateway
76 Media-Accept-Features
77 MIME-Version
78 Mail-Copies-To
79 Message-ID
80 Message-Type
81 Newsgroups
82 Organization
83 Original-Encoded-Information-Types
84 Original-Envelope-ID
85 Original-Message-ID
86 Original-Recipient
87 Originator-Return-Address
88 Path
89 Posted-And-Mailed
90 Prevent-Nondelivery-Report
91 Priority
92 Received
93 Received-content-MIC
94 Received-From-MTA
95 References
96 Remote-MTA
97 Reply-By
98 Reply-To
99 Reporting-MTA
100 Reporting-UA
101 Return-Path
102 Sender
103 Sensitivity
104 Status
105 Subject
106 Summary
107 Supersedes
109 User-Agent
110 Warning
111 Will-Retry-Until
112 X400-Content-Identifier
113 X400-Content-Return
114 X400-Content-Type
115 X400-MTS-Identifier
116 X400-Originator
117 X400-Received
118 X400-Recipients
119 Xref
122 #include <stdio.h>
123 #include <stdlib.h>
124 #include <ctype.h>
126 static int
127 my_case_strcmp (s1, s2)
128      register const char *s1;
129      register const char *s2;
131   for (;;)
132     {
133       unsigned char c1 = *s1++;
134       unsigned char c2 = *s2++;
135       if (c1 >= 'A' && c1 <= 'Z')
136         c1 += 'a' - 'A';
137       if (c2 >= 'A' && c2 <= 'Z')
138         c2 += 'a' - 'A';
139       if (c1 != 0 && c1 == c2)
140         continue;
141       return (int)c1 - (int)c2;
142     }
146 main (argc, argv)
147      int argc;
148      char *argv[];
150   int i, j, k, n, exitcode;
151   size_t len;
152   const struct header_state *hs;
154   n = 1;
155   if (argc > 1)
156     n = atoi (argv[1]);
157   if (n < 1)
158     n = 1;
160   exitcode = 0;
161   for (i = 0; i < n; i++)
162     {
163       for (j = 0; j <= MAX_HASH_VALUE; j++)
164         {
165           const char *s = wordlist[j].field_name;
166           len = strlen (s);
167           if (len)
168             {
169               hs = header_entry (s, len);
170               if (!(hs && strcmp (hs->field_name, s) == 0))
171                 {
172                   fprintf (stderr, "%s != %s\n", s, hs ? hs->field_name : "(null)");
173                   exitcode = 1;
174                 }
175             }
176         }
177       for (j = 0; j <= MAX_HASH_VALUE; j++)
178         {
179           char s[MAX_WORD_LENGTH+1];
180           /* expensive copy with case conversion (for testing) */
181           strcpy (s, wordlist[j].field_name);
182           len = strlen (s);
183           if (len)
184             {
185               for (k = 0; k < len; k++)
186                 if (isupper ((unsigned char) s[k]))
187                   s[k] = tolower ((unsigned char) s[k]);
188                 else if (islower ((unsigned char) s[k]))
189                   s[k] = toupper ((unsigned char) s[k]);
190               hs = header_entry (s, len);
191               if (!(hs && my_case_strcmp (hs->field_name, s) == 0))
192                 {
193                   fprintf (stderr, "%s != %s\n", s, hs ? hs->field_name : "(null)");
194                   exitcode = 1;
195                 }
196             }
197         }
198       hs = header_entry ("Dave", 4);
199       if (hs)
200         {
201           fprintf (stderr, "Dave == %s\n", hs->field_name);
202           exitcode = 1;
203         }
204     }
205   return exitcode;