head.c (da52b4caaf187775f6b56a72c6b16e94ad728f7b) head.c (6d8484b0d0191b66f9bfd0dfa89c06a29647f02a)
1/*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 36 unchanged lines hidden (view full) ---

45 */
46
47/*
48 * See if the passed line buffer is a mail header.
49 * Return true if yes. Note the extreme pains to
50 * accomodate all funny formats.
51 */
52int
1/*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 36 unchanged lines hidden (view full) ---

45 */
46
47/*
48 * See if the passed line buffer is a mail header.
49 * Return true if yes. Note the extreme pains to
50 * accomodate all funny formats.
51 */
52int
53ishead(linebuf)
54 char linebuf[];
53ishead(char linebuf[])
55{
56 struct headline hl;
57 char parbuf[BUFSIZ];
58
59 if (strncmp(linebuf, "From ", 5) != 0)
60 return (0);
61 parse(linebuf, &hl, parbuf);
62 if (hl.l_date == NULL) {

--- 5 unchanged lines hidden (view full) ---

68 return (0);
69 }
70 /*
71 * I guess we got it!
72 */
73 return (1);
74}
75
54{
55 struct headline hl;
56 char parbuf[BUFSIZ];
57
58 if (strncmp(linebuf, "From ", 5) != 0)
59 return (0);
60 parse(linebuf, &hl, parbuf);
61 if (hl.l_date == NULL) {

--- 5 unchanged lines hidden (view full) ---

67 return (0);
68 }
69 /*
70 * I guess we got it!
71 */
72 return (1);
73}
74
76/*ARGSUSED*/
77void
75void
78fail(linebuf, reason)
79 const char *linebuf, *reason;
76fail(const char *linebuf __unused, const char *reason __unused)
80{
81
82 /*
83 if (value("debug") == NULL)
84 return;
85 fprintf(stderr, "\"%s\"\nnot a header because %s\n", linebuf, reason);
86 */
87}
88
89/*
90 * Split a headline into its useful components.
91 * Copy the line into dynamic string space, then set
92 * pointers into the copied line in the passed headline
93 * structure. Actually, it scans.
94 */
95void
77{
78
79 /*
80 if (value("debug") == NULL)
81 return;
82 fprintf(stderr, "\"%s\"\nnot a header because %s\n", linebuf, reason);
83 */
84}
85
86/*
87 * Split a headline into its useful components.
88 * Copy the line into dynamic string space, then set
89 * pointers into the copied line in the passed headline
90 * structure. Actually, it scans.
91 */
92void
96parse(line, hl, pbuf)
97 char line[], pbuf[];
98 struct headline *hl;
93parse(char line[], struct headline *hl, char pbuf[])
99{
100 char *cp, *sp;
101 char word[LINESIZE];
102
103 hl->l_from = NULL;
104 hl->l_tty = NULL;
105 hl->l_date = NULL;
106 cp = line;

--- 22 unchanged lines hidden (view full) ---

129
130/*
131 * Copy the string on the left into the string on the right
132 * and bump the right (reference) string pointer by the length.
133 * Thus, dynamically allocate space in the right string, copying
134 * the left string into it.
135 */
136char *
94{
95 char *cp, *sp;
96 char word[LINESIZE];
97
98 hl->l_from = NULL;
99 hl->l_tty = NULL;
100 hl->l_date = NULL;
101 cp = line;

--- 22 unchanged lines hidden (view full) ---

124
125/*
126 * Copy the string on the left into the string on the right
127 * and bump the right (reference) string pointer by the length.
128 * Thus, dynamically allocate space in the right string, copying
129 * the left string into it.
130 */
131char *
137copyin(src, space)
138 char *src;
139 char **space;
132copyin(char *src, char **space)
140{
141 char *cp, *top;
142
143 top = cp = *space;
144 while ((*cp++ = *src++) != '\0')
145 ;
146 *space = cp;
147 return (top);

--- 30 unchanged lines hidden (view full) ---

178 "Aaa Aaa O0 00:00:00 0000 p0000", /* Mon Jan 01 23:59:59 2001 -0800 */
179 "Aaa Aaa O0 00:00 0000", /* Mon Jan 01 23:59 2001 */
180 "Aaa Aaa O0 00:00 AAA 0000", /* Mon Jan 01 23:59 PST 2001 */
181 "Aaa Aaa O0 00:00 0000 p0000", /* Mon Jan 01 23:59 2001 -0800 */
182 NULL
183};
184
185int
133{
134 char *cp, *top;
135
136 top = cp = *space;
137 while ((*cp++ = *src++) != '\0')
138 ;
139 *space = cp;
140 return (top);

--- 30 unchanged lines hidden (view full) ---

171 "Aaa Aaa O0 00:00:00 0000 p0000", /* Mon Jan 01 23:59:59 2001 -0800 */
172 "Aaa Aaa O0 00:00 0000", /* Mon Jan 01 23:59 2001 */
173 "Aaa Aaa O0 00:00 AAA 0000", /* Mon Jan 01 23:59 PST 2001 */
174 "Aaa Aaa O0 00:00 0000 p0000", /* Mon Jan 01 23:59 2001 -0800 */
175 NULL
176};
177
178int
186isdate(date)
187 char date[];
179isdate(char date[])
188{
189 int i;
190
191 for(i = 0; date_formats[i] != NULL; i++) {
192 if (cmatch(date, date_formats[i]))
193 return (1);
194 }
195 return (0);
196}
197
198/*
199 * Match the given string (cp) against the given template (tp).
200 * Return 1 if they match, 0 if they don't
201 */
202int
180{
181 int i;
182
183 for(i = 0; date_formats[i] != NULL; i++) {
184 if (cmatch(date, date_formats[i]))
185 return (1);
186 }
187 return (0);
188}
189
190/*
191 * Match the given string (cp) against the given template (tp).
192 * Return 1 if they match, 0 if they don't
193 */
194int
203cmatch(cp, tp)
204 char *cp, *tp;
195cmatch(char *cp, char *tp)
205{
206
207 while (*cp != '\0' && *tp != '\0')
208 switch (*tp++) {
209 case 'a':
210 if (!islower((unsigned char)*cp++))
211 return (0);
212 break;

--- 38 unchanged lines hidden (view full) ---

251}
252
253/*
254 * Collect a liberal (space, tab delimited) word into the word buffer
255 * passed. Also, return a pointer to the next word following that,
256 * or NULL if none follow.
257 */
258char *
196{
197
198 while (*cp != '\0' && *tp != '\0')
199 switch (*tp++) {
200 case 'a':
201 if (!islower((unsigned char)*cp++))
202 return (0);
203 break;

--- 38 unchanged lines hidden (view full) ---

242}
243
244/*
245 * Collect a liberal (space, tab delimited) word into the word buffer
246 * passed. Also, return a pointer to the next word following that,
247 * or NULL if none follow.
248 */
249char *
259nextword(wp, wbuf)
260 char *wp, *wbuf;
250nextword(char *wp, char *wbuf)
261{
262 int c;
263
264 if (wp == NULL) {
265 *wbuf = '\0';
266 return (NULL);
267 }
268 while ((c = *wp++) != '\0' && c != ' ' && c != '\t') {

--- 17 unchanged lines hidden ---
251{
252 int c;
253
254 if (wp == NULL) {
255 *wbuf = '\0';
256 return (NULL);
257 }
258 while ((c = *wp++) != '\0' && c != ' ' && c != '\t') {

--- 17 unchanged lines hidden ---