Ejemplo n.º 1
0
Archivo: tree.c Proyecto: aalm/obsd-src
static void
tputC(int c, struct shf *shf)
{
	if ((c&0x60) == 0) {		/* C0|C1 */
		tputc((c&0x80) ? '$' : '^', shf);
		tputc(((c&0x7F)|0x40), shf);
	} else if ((c&0x7F) == 0x7F) {	/* DEL */
		tputc((c&0x80) ? '$' : '^', shf);
		tputc('?', shf);
	} else
		tputc(c, shf);
}
Ejemplo n.º 2
0
Archivo: RT1.C Proyecto: g8bpq/BPQ32
static int rtstat ()
{
	LINK    *link;
	NODE    *node;
	CN      *cn;
	CIRCUIT *circuit;
	TOPIC   *topic;
	USER    *user;

	for (link = link_hd; link; link = link->next)
		tprintf("Link %s:%s %x\n", link->alias, link->call, link->flags);

	for (user = user_hd; user; user = user->next)
		tprintf("User %s @ %s\n", user->call, user->node->alias);

	for (circuit = circuit_hd; circuit; circuit = circuit->next)
		if (circuit->flags & p_linked)
	{
		tprintf("From %s:", circuit->u.link->alias);
		for (cn = circuit->hnode; cn; cn = cn->next)
	  	tprintf(" %s/%u", cn->node->alias, cn->refcnt);
		tputc('\n');
	}

	for (node = node_hd;  node; node = node->next)
		tprintf("Node %s %u\n", node->alias, node->refcnt);

	for (topic = topic_hd; topic; topic = topic->next)
		tprintf("Topic %s %u\n", topic->name, topic->refcnt);

	return cmd_ok;
}
Ejemplo n.º 3
0
static void
wimlib_vmsg(const tchar *tag, const tchar *format,
	    va_list va, bool perror)
{
#if !defined(ENABLE_DEBUG)
	if (wimlib_print_errors)
#endif
	{
		int errno_save = errno;
		fflush(stdout);
		tfputs(tag, wimlib_error_file);
		tvfprintf(wimlib_error_file, format, va);
		if (perror && errno_save != 0) {
			tchar buf[64];
			int res;
			res = tstrerror_r(errno_save, buf, ARRAY_LEN(buf));
			if (res) {
				tsprintf(buf,
					 T("unknown error (errno=%d)"),
					 errno_save);
			}
		#ifdef WIN32
			if (errno_save == EBUSY)
				tstrcpy(buf, T("Resource busy"));
		#endif
			tfprintf(wimlib_error_file, T(": %"TS), buf);
		}
		tputc(T('\n'), wimlib_error_file);
		fflush(wimlib_error_file);
		errno = errno_save;
	}
}
Ejemplo n.º 4
0
int
_write(int fd, char *ptr, int len)
{
  int rv = len;

  if (!initted)
    init_uart0 ();

  while (len != 0)
    {
      if (*ptr == '\n')
	tputc ('\r');
      tputc (*ptr);
      ptr ++;
      len --;
    }
  return rv;
}
Ejemplo n.º 5
0
Archivo: RT1.C Proyecto: g8bpq/BPQ32
static void show_circuits(void)
{
	CIRCUIT *circuit;
	NODE    *node;
	int     len;

	tprintf("Here %-6.6s <- ", Node->aliass);
	len = 0;

	for (node = node_hd; node; node = node->next) if (node->refcnt)
	{
		len += strlen(node->alias) + 1;
		if (len > 60) { len = strlen(node->alias) + 1; tputs(xxx); }
		tputs(node->alias);
		tputc(' ');
	}

	tputc('\n');

	for (circuit = circuit_hd; circuit; circuit = circuit->next)
	if (circuit->flags & p_linked)
	{
		tprintf("Link %-6.6s <- ", circuit->u.link->alias);
		len = 0;

		for (node = node_hd; node; node = node->next)
		if (node->refcnt && !cn_find(circuit, node))
		{
			len += strlen(node->alias) + 1;
			if (len > 60) { len = strlen(node->alias) + 1; tputs(xxx); }
			tputs(node->alias);
			tputc(' ');
		}

		tputc('\n');
	}
	else if (circuit->flags & p_user)
		tprintf("User %-6.6s\n", circuit->u.user->call);
	else if (circuit->flags & p_linkini)
		tprintf("Link %-6.6s (setup)\n", circuit->u.link->alias);
}
Ejemplo n.º 6
0
int
_write(int fd, char *ptr, int len)
{
  int rv = len;

  if (_open_present && fd > 2)
    return _SYS_write (fd, ptr, len);

  if (!initted)
    init_uart0 ();

  while (len != 0)
    {
      if (*ptr == '\n')
	tputc ('\r');
      tputc (*ptr);
      ptr ++;
      len --;
    }
  return rv;
}
Ejemplo n.º 7
0
Archivo: tree.c Proyecto: aalm/obsd-src
static void
pioact(struct shf *shf, int indent, struct ioword *iop)
{
	int flag = iop->flag;
	int type = flag & IOTYPE;
	int expected;

	expected = (type == IOREAD || type == IORDWR || type == IOHERE) ? 0 :
	    (type == IOCAT || type == IOWRITE) ? 1 :
	    (type == IODUP && (iop->unit == !(flag & IORDUP))) ? iop->unit :
	    iop->unit + 1;
	if (iop->unit != expected)
		tputc('0' + iop->unit, shf);

	switch (type) {
	case IOREAD:
		fptreef(shf, indent, "< ");
		break;
	case IOHERE:
		if (flag&IOSKIP)
			fptreef(shf, indent, "<<- ");
		else
			fptreef(shf, indent, "<< ");
		break;
	case IOCAT:
		fptreef(shf, indent, ">> ");
		break;
	case IOWRITE:
		if (flag&IOCLOB)
			fptreef(shf, indent, ">| ");
		else
			fptreef(shf, indent, "> ");
		break;
	case IORDWR:
		fptreef(shf, indent, "<> ");
		break;
	case IODUP:
		if (flag & IORDUP)
			fptreef(shf, indent, "<&");
		else
			fptreef(shf, indent, ">&");
		break;
	}
	/* name/delim are 0 when printing syntax errors */
	if (type == IOHERE) {
		if (iop->delim)
			fptreef(shf, indent, "%S ", iop->delim);
	} else if (iop->name)
		fptreef(shf, indent, (iop->flag & IONAMEXP) ? "%s " : "%S ",
		    iop->name);
}
Ejemplo n.º 8
0
Archivo: RT1.C Proyecto: g8bpq/BPQ32
static void show_topics(void)
{
	TOPIC *topic;
	USER  *user;

	tputs("Topics in the RoundTable are:\n");

	for (topic = topic_hd; topic; topic = topic->next)
	{
		tprintf("%s\n", topic->name);

		if (topic->refcnt)
		{
			tputs("  ");
			for (user = user_hd; user; user = user->next)
				if (user->topic is topic) tprintf(" %s", user->call);
			tputc('\n');
		}
	}
}
Ejemplo n.º 9
0
Archivo: tree.c Proyecto: aalm/obsd-src
static void
vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
{
	int c;

	while ((c = *fmt++)) {
		if (c == '%') {
			long n;
			char *p;
			int neg;

			switch ((c = *fmt++)) {
			case 'c':
				tputc(va_arg(va, int), shf);
				break;
			case 's':
				p = va_arg(va, char *);
				while (*p)
					tputc(*p++, shf);
				break;
			case 'S':	/* word */
				p = va_arg(va, char *);
				tputS(p, shf);
				break;
			case 'd': case 'u': /* decimal */
				n = (c == 'd') ? va_arg(va, int) :
				    va_arg(va, unsigned int);
				neg = c=='d' && n<0;
				p = ulton((neg) ? -n : n, 10);
				if (neg)
					*--p = '-';
				while (*p)
					tputc(*p++, shf);
				break;
			case 'T':	/* format tree */
				ptree(va_arg(va, struct op *), indent, shf);
				break;
			case ';':	/* newline or ; */
			case 'N':	/* newline or space */
				if (shf->flags & SHF_STRING) {
					if (c == ';')
						tputc(';', shf);
					tputc(' ', shf);
				} else {
					int i;

					tputc('\n', shf);
					for (i = indent; i >= 8; i -= 8)
						tputc('\t', shf);
					for (; i > 0; --i)
						tputc(' ', shf);
				}
				break;
			case 'R':
				pioact(shf, indent, va_arg(va, struct ioword *));
				break;
			default:
				tputc(c, shf);
				break;
			}
		} else
Ejemplo n.º 10
0
Archivo: tree.c Proyecto: aalm/obsd-src
static void
tputS(char *wp, struct shf *shf)
{
	int c, quoted=0;

	/* problems:
	 *	`...` -> $(...)
	 *	'foo' -> "foo"
	 * could change encoding to:
	 *	OQUOTE ["'] ... CQUOTE ["']
	 *	COMSUB [(`] ...\0	(handle $ ` \ and maybe " in `...` case)
	 */
	while (1)
		switch ((c = *wp++)) {
		case EOS:
			return;
		case CHAR:
			tputC(*wp++, shf);
			break;
		case QCHAR:
			c = *wp++;
			if (!quoted || (c == '"' || c == '`' || c == '$'))
				tputc('\\', shf);
			tputC(c, shf);
			break;
		case COMSUB:
			tputc('$', shf);
			tputc('(', shf);
			while (*wp != 0)
				tputC(*wp++, shf);
			tputc(')', shf);
			wp++;
			break;
		case EXPRSUB:
			tputc('$', shf);
			tputc('(', shf);
			tputc('(', shf);
			while (*wp != 0)
				tputC(*wp++, shf);
			tputc(')', shf);
			tputc(')', shf);
			wp++;
			break;
		case OQUOTE:
			quoted = 1;
			tputc('"', shf);
			break;
		case CQUOTE:
			quoted = 0;
			tputc('"', shf);
			break;
		case OSUBST:
			tputc('$', shf);
			if (*wp++ == '{')
				tputc('{', shf);
			while ((c = *wp++) != 0)
				tputC(c, shf);
			break;
		case CSUBST:
			if (*wp++ == '}')
				tputc('}', shf);
			break;
		case OPAT:
			tputc(*wp++, shf);
			tputc('(', shf);
			break;
		case SPAT:
			tputc('|', shf);
			break;
		case CPAT:
			tputc(')', shf);
			break;
		}
}
Ejemplo n.º 11
0
Archivo: tree.c Proyecto: aalm/obsd-src
static void
ptree(struct op *t, int indent, struct shf *shf)
{
	char **w;
	struct ioword **ioact;
	struct op *t1;

 Chain:
	if (t == NULL)
		return;
	switch (t->type) {
	case TCOM:
		if (t->vars)
			for (w = t->vars; *w != NULL; )
				fptreef(shf, indent, "%S ", *w++);
		else
			fptreef(shf, indent, "#no-vars# ");
		if (t->args)
			for (w = t->args; *w != NULL; )
				fptreef(shf, indent, "%S ", *w++);
		else
			fptreef(shf, indent, "#no-args# ");
		break;
	case TEXEC:
#if 0 /* ?not useful - can't be called? */
		/* Print original vars */
		if (t->left->vars)
			for (w = t->left->vars; *w != NULL; )
				fptreef(shf, indent, "%S ", *w++);
		else
			fptreef(shf, indent, "#no-vars# ");
		/* Print expanded vars */
		if (t->args)
			for (w = t->args; *w != NULL; )
				fptreef(shf, indent, "%s ", *w++);
		else
			fptreef(shf, indent, "#no-args# ");
		/* Print original io */
		t = t->left;
#else
		t = t->left;
		goto Chain;
#endif
	case TPAREN:
		fptreef(shf, indent + 2, "( %T) ", t->left);
		break;
	case TPIPE:
		fptreef(shf, indent, "%T| ", t->left);
		t = t->right;
		goto Chain;
	case TLIST:
		fptreef(shf, indent, "%T%;", t->left);
		t = t->right;
		goto Chain;
	case TOR:
	case TAND:
		fptreef(shf, indent, "%T%s %T",
		    t->left, (t->type==TOR) ? "||" : "&&", t->right);
		break;
	case TBANG:
		fptreef(shf, indent, "! ");
		t = t->right;
		goto Chain;
	case TDBRACKET:
	  {
		int i;

		fptreef(shf, indent, "[[");
		for (i = 0; t->args[i]; i++)
			fptreef(shf, indent, " %S", t->args[i]);
		fptreef(shf, indent, " ]] ");
		break;
	  }
	case TSELECT:
		fptreef(shf, indent, "select %s ", t->str);
		/* FALLTHROUGH */
	case TFOR:
		if (t->type == TFOR)
			fptreef(shf, indent, "for %s ", t->str);
		if (t->vars != NULL) {
			fptreef(shf, indent, "in ");
			for (w = t->vars; *w; )
				fptreef(shf, indent, "%S ", *w++);
			fptreef(shf, indent, "%;");
		}
		fptreef(shf, indent + INDENT, "do%N%T", t->left);
		fptreef(shf, indent, "%;done ");
		break;
	case TCASE:
		fptreef(shf, indent, "case %S in", t->str);
		for (t1 = t->left; t1 != NULL; t1 = t1->right) {
			fptreef(shf, indent, "%N(");
			for (w = t1->vars; *w != NULL; w++)
				fptreef(shf, indent, "%S%c", *w,
				    (w[1] != NULL) ? '|' : ')');
			fptreef(shf, indent + INDENT, "%;%T%N;;", t1->left);
		}
		fptreef(shf, indent, "%Nesac ");
		break;
	case TIF:
	case TELIF:
		/* 3 == strlen("if ") */
		fptreef(shf, indent + 3, "if %T", t->left);
		for (;;) {
			t = t->right;
			if (t->left != NULL) {
				fptreef(shf, indent, "%;");
				fptreef(shf, indent + INDENT, "then%N%T",
				    t->left);
			}
			if (t->right == NULL || t->right->type != TELIF)
				break;
			t = t->right;
			fptreef(shf, indent, "%;");
			/* 5 == strlen("elif ") */
			fptreef(shf, indent + 5, "elif %T", t->left);
		}
		if (t->right != NULL) {
			fptreef(shf, indent, "%;");
			fptreef(shf, indent + INDENT, "else%;%T", t->right);
		}
		fptreef(shf, indent, "%;fi ");
		break;
	case TWHILE:
	case TUNTIL:
		/* 6 == strlen("while"/"until") */
		fptreef(shf, indent + 6, "%s %T",
		    (t->type==TWHILE) ? "while" : "until",
		    t->left);
		fptreef(shf, indent, "%;do");
		fptreef(shf, indent + INDENT, "%;%T", t->right);
		fptreef(shf, indent, "%;done ");
		break;
	case TBRACE:
		fptreef(shf, indent + INDENT, "{%;%T", t->left);
		fptreef(shf, indent, "%;} ");
		break;
	case TCOPROC:
		fptreef(shf, indent, "%T|& ", t->left);
		break;
	case TASYNC:
		fptreef(shf, indent, "%T& ", t->left);
		break;
	case TFUNCT:
		fptreef(shf, indent,
		    t->u.ksh_func ? "function %s %T" : "%s() %T",
		    t->str, t->left);
		break;
	case TTIME:
		fptreef(shf, indent, "time %T", t->left);
		break;
	default:
		fptreef(shf, indent, "<botch>");
		break;
	}
	if ((ioact = t->ioact) != NULL) {
		int	need_nl = 0;

		while (*ioact != NULL)
			pioact(shf, indent, *ioact++);
		/* Print here documents after everything else... */
		for (ioact = t->ioact; *ioact != NULL; ) {
			struct ioword *iop = *ioact++;

			/* heredoc is 0 when tracing (set -x) */
			if ((iop->flag & IOTYPE) == IOHERE && iop->heredoc) {
				tputc('\n', shf);
				shf_puts(iop->heredoc, shf);
				fptreef(shf, indent, "%s",
				    evalstr(iop->delim, 0));
				need_nl = 1;
			}
		}
		/* Last delimiter must be followed by a newline (this often
		 * leads to an extra blank line, but its not worth worrying
		 * about)
		 */
		if (need_nl)
			tputc('\n', shf);
	}
}
Ejemplo n.º 12
0
void dxp_machine (int dev, HFDD_PARAMS *hfddp)
{
	int c, bbs_mode = 0;

	hfdd_state = init;

	hfdd_conn_flag = 0;	/* default no connected */ 
 
	/* 19Feb2005, Maiko, Okay DXP now has bbs mode as well */
	if (!memcmp ("bbs", hfddp->call, 3))
		bbs_mode = 1;

    while (hfdd_state != finished)
	{
		if (pwait (NULL))
			break;

		/* move init and connect into the machine now */
		switch (hfdd_state)
		{
			case init:
				dxp_init (dev, hfddp->pactor);
				hfdd_state = call;
				break;

			case call:
			/* 19Feb2005, Maiko, Okay DXP now has bbs mode as well */
				if (!bbs_mode)
					dxp_connect (dev, hfddp->call, hfddp->pactor);
				hfdd_state = called;	
				break;

			case idle:
			case called:
			case connected:
			case finished:
				break;
		}

		if ((c = get_asy (dev)) == -1)
			break;

		if (c == 0x80)
		{
#ifdef	DEBUG
			log_flush ();
#endif
    		if ((c = get_asy (dev)) == -1)
				break;

			/* 04Oct2006, Maiko, More restructuring, etc */

			if (c == 0x7a)
			{
				if (dxp_fsk_status (dev) == -1)
					break;

				continue;
			}

			if (dxp_status (dev, c) == -1)
				break;

			if (c == 0x23 || c == 0x24)
			{
				if (dxp_eat_the_END (dev) == -1)
					break;

				if (hfddp->keyboard)
				{
					if (c == 0x23)
						tprintf ("*** disconnected from %s\n", hfddp->call);
					else
						tprintf ("*** failure with %s\n", hfddp->call);
				}

				hfdd_state = finished;

				break;
			}
			/* 22Jan2005, Maiko, Stumbled across this new one */
			else if (c == 0x09)
			{
				if (hfddp->keyboard)
					tprintf ("*** modem reset\n");

				hfdd_state = finished;

				break;
			}
			/*
			 * 21Jan2005, Maiko, Added 'signal lost' conditional
			 * 14Feb2005, Maiko, Oops, HalComm says I should ignore this,
			 * since the modem will send me the link failed status (8024)
			 * when the link actually fails !!! I should NOT be terminating
			 * session on 'signal lost' conditions. Just warn the user !
			 */
			else if (c == 0x25)
			{
				if (dxp_eat_the_END (dev) == -1)
					break;

				if (hfddp->keyboard)
					tprintf ("*** signal lost with %s\n", hfddp->call);

				break;
			}
			else if (bbs_mode || (hfdd_state == call) || (hfdd_state == called))
			{
				if (c == 0x10)
				{
					if (hfddp->keyboard)
						j2tputs ("Trying... Escape sequence is: +++<CR>\n");
				}
				/* 16Feb2005, Maiko, Added P-Mode connected flag */
				else if ((c == 0x20) || (c == 0x2b))
				{
					if (bbs_mode)
					{
						/* 05Mar2005, Maiko, Get incoming callsign */
						if (dxp_get_incall (dev, hfddp->call) == -1)
						{
							log (-1, "dxp_get_incall () failed !!!");
							hfdd_state = finished;
							break;
						}

						/* 09Oct2006, Maiko, Lower case the call */
	                    strlwr (hfddp->call);

						/* 06Mar2005, Maiko, Now a generic function */
   						hfdd_mbox (dev, mbxs,
							(void*)TTY_LINK, (void*)(hfddp->call));
					}
					else
					{
						if (hfddp->keyboard)
							tprintf ("*** connected to %s\n", hfddp->call);

						hfdd_state = connected;
					}

					/* 18Jan2005, Maiko, integrated into fwding now */
					/* 28Feb2005, Maiko, Set this either way !! */
					hfdd_conn_flag = 1;
				}
			}

#ifdef	DONT_COMPILE
			if (hfddp->keyboard)
				usflush (Curproc->output);
#endif
			continue;
		}

		/*
		 * 04Oct2006, Maiko, Forgot about the *other* ESC character. If we
		 * get one of these, then the byte that follows is actual DATA !!!
		 */
		if (c == 0x81)
		{
			log (-1, "escape character");

    		if ((c = get_asy (dev)) == -1)
				break;
		}
		
#ifdef	DEBUG
		log_data (c);
#endif
		/* 18Jan2005, Maiko, Now doing fwd support for Halcomm */

		if (hfdd_fwdsock != -1)
		{
			usputc (hfdd_fwdsock, c);

			usflush (hfdd_fwdsock);
		}
		else if (bbs_mode)
		{
            usputc (mbxs[0], c);

			usflush (mbxs[0]);
		}
		else
		{
			if (hfddp->keyboard)
			{
				/* Map to NL or else we loose data when we display it */
				if (c == 0x0d)
					c = '\n';

				tputc (c); /* assuming this is actual data (for now) */

    			tflush ();
			}
		}
	}

	if (hfddp->keyboard)
		usflush (Curproc->output);
}
Ejemplo n.º 13
0
Archivo: kill.c Proyecto: jheiss/nn
static int
compile_kill_file(void)
{
    FILE           *killf, *compf, *patternf, *dropf;
    comp_kill_header header;
    comp_kill_entry entry;
    time_t          now, age;
    long            cur_line_start;
    char            line[512];
    register char  *cp, *np;
    register int    c;
    group_header   *gh;
    flag_type       flag, fields[10];
    int             any_errors, nfield, nf, len;

    any_errors = 0;
    header.ckh_entries = header.ckh_regexp_size = 0;

    killf = open_file(relative(nn_directory, KILL_FILE),
                      OPEN_READ | DONT_CREATE);
    if (killf == NULL)
        return 0;

    dropf = NULL;

    compf = open_file(relative(nn_directory, COMPILED_KILL), OPEN_CREATE);
    if (compf == NULL)
        goto err1;

    new_temp_file();
    if ((patternf = open_file(temp_file, OPEN_CREATE)) == NULL)
        goto err2;

    msg("Compiling kill file");

    fseek(compf, sizeof(header), 0);

    now = cur_time();

next_entry:

    for (;;) {
        cur_line_start = ftell(killf);

        if (fgets(line, 512, killf) == NULL)
            break;

        cp = line;
        while (*cp && isascii(*cp) && isspace(*cp))
            cp++;
        if (*cp == NUL || *cp == '#' || !isascii(*cp))
            continue;

        if ((np = strchr(cp, ':')) == NULL)
            goto bad_entry;

        /* optional "age:" */

        if (np != cp && isdigit(*cp)) {
            *np++ = NUL;
            age = (time_t) atol(cp);
            if (age < now)
                goto drop_entry;
            cp = np;
            if ((np = strchr(cp, ':')) == NULL)
                goto bad_entry;
        }
        /* "group-name:"  or "/regexp:" or ":" for all groups */

        flag = COMP_KILL_ENTRY;

        if (np == cp) {
            entry.ck_group = -1;
            np++;
        } else {
            *np++ = NUL;
            if (*cp == '/') {
                entry.ck_group = (long) ftell(patternf);
                cp++;
                len = strlen(cp) + 1;
                if (fwrite(cp, sizeof(char), len, patternf) != len)
                    goto err3;
                flag |= GROUP_REGEXP | GROUP_REGEXP_HDR;
            } else {
                if ((gh = lookup(cp)) == NULL || (gh->master_flag & M_IGNORE_GROUP)) {
                    tprintf("Unknown/ignored group in kill file: %s\n", cp);
                    any_errors++;
                    goto drop_entry;
                }
                entry.ck_group = gh->group_num;
            }
        }

        /* flags */

        cp = np;
        nfield = 0;

        for (;;) {
            switch (*cp++) {
            case EXT_AND_MATCH:
            case EXT_OR_MATCH:
                fields[nfield++] = flag;
                flag &= ~(AND_MATCH | ON_SUBJECT | ON_SENDER |
                          KILL_CASE_MATCH | KILL_ON_REGEXP |
                          GROUP_REGEXP_HDR);
                flag |= (cp[-1] == EXT_AND_MATCH) ? AND_MATCH : OR_MATCH;
                continue;
            case EXT_AUTO_KILL:
                flag |= AUTO_KILL;
                continue;
            case EXT_AUTO_SELECT:
                flag |= AUTO_SELECT;
                continue;
            case EXT_ON_FOLLOW_UP:
                flag |= ON_FOLLOW_UP;
                continue;
            case EXT_ON_NOT_FOLLOW_UP:
                flag |= ON_NOT_FOLLOW_UP;
                continue;
            case EXT_ON_ANY_REFERENCES:
                flag |= ON_ANY_REFERENCES;
                continue;
            case EXT_ON_SUBJECT:
                flag |= ON_SUBJECT;
                continue;
            case EXT_ON_SENDER:
                flag |= ON_SENDER;
                continue;
            case EXT_KILL_CASE_MATCH:
                flag |= KILL_CASE_MATCH;
                continue;
            case EXT_KILL_UNLESS_MATCH:
                flag |= KILL_UNLESS_MATCH;
                continue;
            case EXT_KILL_ON_REGEXP:
                flag |= KILL_ON_REGEXP;
                continue;
            case ':':
                break;
            case NL:
                goto bad_entry;
            default:
                tprintf("Ignored flag '%c' in kill file\n", cp[-1]);
                any_errors++;
                continue;
            }
            break;
        }

        fields[nfield++] = flag;

        for (nf = 0; --nfield >= 0; nf++) {
            entry.ck_flag = flag = fields[nf];
            np = cp;
            if ((cp = get_pattern(np, &len, nfield)) == NULL)
                goto bad_entry;

            if ((flag & KILL_CASE_MATCH) == 0)
                fold_string(np);

            entry.ck_pattern_index = ftell(patternf);

            if (fwrite((char *) &entry, sizeof(entry), 1, compf) != 1)
                goto err3;

            if (fwrite(np, sizeof(char), len, patternf) != len)
                goto err3;

            header.ckh_entries++;
            if (flag & GROUP_REGEXP)
                header.ckh_regexp_size++;
        }
    }

    header.ckh_pattern_size = ftell(patternf);

    fclose(patternf);
    patternf = open_file(temp_file, OPEN_READ | OPEN_UNLINK);
    if (patternf == NULL)
        goto err2;

    header.ckh_pattern_offset = ftell(compf);

    while ((c = getc(patternf)) != EOF)
        putc(c, compf);

    fclose(patternf);

    rewind(compf);

    header.ckh_magic = COMP_KILL_MAGIC;
    header.ckh_db_check = master.db_created;

    if (fwrite((char *) &header, sizeof(header), 1, compf) != 1)
        goto err2;

    fclose(compf);
    fclose(killf);
    if (dropf != NULL)
        fclose(dropf);

    if (any_errors) {
        tputc(NL);
        any_key(0);
    }
    return 1;

bad_entry:
    tprintf("Incomplete kill file entry:\n%s", line);
    fl;
    any_errors++;

drop_entry:
    if (dropf == NULL) {
        dropf = open_file(relative(nn_directory, KILL_FILE),
                          OPEN_UPDATE | DONT_CREATE);
        if (dropf == NULL)
            goto next_entry;
    }
    fseek(dropf, cur_line_start, 0);
    fwrite("# ", sizeof(char), 2, dropf);
    goto next_entry;

err3:
    fclose(patternf);
    unlink(temp_file);
err2:
    fclose(compf);
    rm_kill_file();
err1:
    fclose(killf);
    if (dropf != NULL)
        fclose(dropf);

    msg("cannot compile kill file");
    return 0;
}