* Copyright (c) 1980 Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)head.c 5.8 (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 (*cp
++ != 'F' || *cp
++ != 'r' || *cp
++ != 'o' || *cp
++ != 'm' ||
parse(linebuf
, &hl
, parbuf
);
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 (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.
register struct headline
*hl
;
* Skip over "From" first.
hl
->l_from
= copyin(word
, &sp
);
if (cp
!= NOSTR
&& cp
[0] == 't' && cp
[1] == 't' && cp
[2] == 'y') {
hl
->l_tty
= copyin(word
, &sp
);
hl
->l_date
= copyin(cp
, &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
* 'O' An optional digit or space
char ctype
[] = "Aaa Aaa O0 00:00:00 0000";
char tmztype
[] = "Aaa Aaa O0 00:00:00 AAA 0000";
return cmatch(date
, ctype
) || cmatch(date
, tmztype
);
* Match the given string (cp) against the given template (tp).
* Return 1 if they match, 0 if they don't
if (*cp
!= ' ' && !isdigit(*cp
))
* 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.
register char *wp
, *wbuf
;
while ((c
= *wp
++) && c
!= ' ' && c
!= '\t') {
while ((c
= *wp
++) && c
!= '"')
for (; c
== ' ' || c
== '\t'; c
= *wp
++)