static char sccsid
[] = "@(#)head.c 2.4 (Berkeley) %G%";
* Routines for processing and detecting headlines.
* See if the passed line buffer is a mail header.
* Return true if yes. Note the extreme pains to
* accomodate all funny formats.
if (strncmp("From ", cp
, 5) != 0)
if (hl
.l_from
== NOSTR
|| hl
.l_date
== NOSTR
) {
fail(linebuf
, "No from or date field");
if (!isdate(hl
.l_date
)) {
fail(linebuf
, "Date field not legal date");
char linebuf
[], reason
[];
if (1 /*value("debug") == NOSTR*/)
fprintf(stderr
, "\"%s\"\nnot a header because %s\n", linebuf
, reason
);
* Split a headline into its useful components.
* Copy the line into dynamic string space, then set
* pointers into the copied line in the passed headline
* structure. Actually, it scans.
* Skip the first "word" of the line, which should be "From"
hl
->l_from
= copyin(word
, &sp
);
if (strncmp(dp
, "tty", 3) == 0) {
hl
->l_tty
= copyin(word
, &sp
);
hl
->l_date
= copyin(cp
, &sp
);
hl
->l_date
= copyin(dp
, &sp
);
* Copy the string on the left into the string on the right
* and bump the right (reference) string pointer by the length.
* Thus, dynamically allocate space in the right string, copying
* the left string into it.
* Test to see if the passed string is a ctime(3) generated
* date string as documented in the manual. The template
* below is used as the criterion of correctness.
* Also, we check for a possible trailing time zone using
#define L 1 /* A lower case char */
#define S 2 /* A space */
#define D 3 /* A digit */
#define O 4 /* An optional digit or space */
#define C 5 /* A colon */
#define N 6 /* A new line */
#define U 7 /* An upper case char */
char ctypes
[] = {U
,L
,L
,S
,U
,L
,L
,S
,O
,D
,S
,D
,D
,C
,D
,D
,C
,D
,D
,S
,D
,D
,D
,D
,0};
char tmztypes
[] = {U
,L
,L
,S
,U
,L
,L
,S
,O
,D
,S
,D
,D
,C
,D
,D
,C
,D
,D
,S
,U
,U
,U
,S
,D
,D
,D
,D
,0};
return(cmatch(cp
, tmztypes
));
* Match the given string against the given template.
* Return 1 if they match, 0 if they don't
while (*cp
!= '\0' && *tp
!= 0) {
if (c
!= ' ' && !isdigit(c
))
if (*cp
!= '\0' || *tp
!= 0)
* Collect a liberal (space, tab delimited) word into the word buffer
* passed. Also, return a pointer to the next word following that,
* or NOSTR if none follow.
if ((cp
= wp
) == NOSTR
) {
while (!any(*cp
, " \t") && *cp
!= '\0')
while (*cp
!= '\0' && *cp
!= '"')
* Test to see if the character is an ascii alphabetic.
return(ch
>= 'A' && ch
<= 'Z');
* Test to see if the character is an ascii digit.
return(c
>= '0' && c
<= '9');
* Copy str1 to str2, return pointer to null in str2.
* Is ch any of the characters in str?
* Convert lower case letters to upper case.
if (c
>= 'a' && c
<= 'z')