Example #1
0
/*
 * Extract a list of names from a line,
 * and make a list of names from it.
 */
void
extract(struct header* hp, unsigned long flags, register char* s)
{
	register struct name*	np;
	register int		n;
	register struct list*	x;
	char			buf[LINESIZE];

	if (s) {
		note(DEBUG, "extract type=0x%08x data=\"%s\"%s", flags, s, (hp->h_clear & flags) ? " [clear]" : "");
		if (flags & GNAME) {
			if (hp->h_clear & flags) {
				hp->h_clear &= ~flags;
				dictwalk(&hp->h_names, clear, &flags);
			}
			while (s = yankword(s, buf))
				if (np = dictsearch(&hp->h_names, buf, INSERT|IGNORECASE|STACK)) {
					np->flags = flags;
					hp->h_flags |= flags;
					if (!hp->h_first && (flags & GTO) || (flags & GFIRST)) {
						flags &= ~GFIRST;
						hp->h_first = np->name;
					}
				}
		}
		else if (flags & GSUB) {
			hp->h_clear &= ~flags;
			if (!*s) {
				hp->h_flags &= ~flags;
				hp->h_subject = 0;
			}
			else if (!hp->h_subject || !streq(hp->h_subject, s)) {
				hp->h_flags |= flags;
				hp->h_subject = savestr(s);
			}
		}
		else if (flags & GMISC) {
			if (hp->h_clear & flags) {
				hp->h_clear &= ~flags;
				hp->h_misc.head = hp->h_misc.tail = 0;
			}
			if (*s) {
				if ((n = strlen(s)) > 0 && s[n - 1] == '\n')
					s[--n] = 0;
				for (x = hp->h_misc.head; x; x = x->next)
					if (streq(x->name, s))
						return;
				hp->h_flags |= flags;
				x = (struct list*)salloc(sizeof(struct list) + n + 1);
				strcpy(x->name, s);
				x->next = 0;
				if (hp->h_misc.tail)
					hp->h_misc.tail->next = x;
				else
					hp->h_misc.head = x;
				hp->h_misc.tail = x;
			}
		}
	}
}
Example #2
0
/*
 * Format the given text to not exceed 78 characters.
 */
static void
fmt(register char *str, register FILE *fo)
{
	register int col = 4;
	char name[256];
	int len;

	str = strcpy((char *)salloc(strlen(str)+1), str);
	while (str = yankword(str, name, sizeof (name), 1)) {
		len = strlen(name);
		if (col > 4) {
			if (col + len > 76) {
				fputs(",\n    ", fo);
				col = 4;
			} else {
				fputs(", ", fo);
				col += 2;
			}
		}
		fputs(name, fo);
		col += len;
	}
	putc('\n', fo);
}