DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T s

⟦47b6c3153⟧ TextFile

    Length: 2052 (0x804)
    Types: TextFile
    Names: »scanheaders.c«

Derivation

└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
    └─ ⟦this⟧ »EUUGD11/euug-87hel/sec1/news/misc/search/lib/scanheaders.c« 

TextFile

/* Scan the headers of a mail/news article, calling a given function for
   each header line.
   The function has three string parameters: keyword, value, filename,
   and a boolean which is FALSE for continuation lines.
   When this function returns TRUE, abandon the scan and return 1.
   Otherwise, return 0 if the headers have the correct format,
   or a negative error code if not. */

#include "defs.h"
#include "scanheaders.h"

int
scanheaders(fp, name, match)
	FILE *fp;
	char *name;
	funcptr match;
{
	char linebuf[BUFSIZ];
	char *p;
	int c;
	int count= 0;
	
	while (safegets(linebuf, BUFSIZ, fp) != NULL) {
		p= linebuf;
		if (*p == '\n')
			break; /* End of headers */
		/* Check for header line: */
		while (iskwchar(*p))
			++p; /* Skip keyword */
		if (p[0] != ':' || !isspace(p[1])) {
			if (count == 0)
				return BAD_HEADER;
			else
				return BAD_LINE;
		}
		*p++ = EOS; /* Turn keyword into a separate string */
		if ((*match)(linebuf, p, name, TRUE))
			return FOUND_MATCH;
		for (;;) {
			++count;
			/* Check for continuation line. */
			c= getc(fp);
			(void) ungetc(c, fp);
			if (c == '\n' || !isspace(c))
				break;
			(void) safegets(p, BUFSIZ-(p-linebuf), fp);
			if ((*match)(linebuf, p, name, FALSE))
				return FOUND_MATCH;
		}
		++count;
	}
	if (count == 0) {
		if (ftell(fp) == 0)
			return EMPTY_FILE;
		else
			return NO_HEADERS;
	}
	else
		return NO_MATCH;
}

/* A header line consists of a keyword immediately followed by a colon
   and whitespace; keywords can contain letters, digits, '-' and '.'.
   (These rules are stricter than those for ARPANET-mail headers, where
   keywords can contain any printable characters except colon and space,
   and no whitespace is required after the colon; however, they conform
   to observed practice in USENET mail.)
   A header line can be followed by any number of continuation lines;
   a continuation line starts with a space or tab.
   A file is considered to have an error if there are no header lines
   or if the last header line is not followed by a blank line.
*/