示例#1
0
文件: syntax.c 项目: hagenkaye/ne
int syntax_match(struct high_syntax *syntax, unsigned char *name, unsigned char *subr, struct high_param *params)
{
    struct high_param *syntax_params;
    if (zcmp(syntax->name, name))
    {
        return 0;
    }
    if (!syntax->subr ^ !subr)
    {
        return 0;
    }
    if (subr && zcmp(syntax->subr, subr))
    {
        return 0;
    }
    syntax_params = syntax->params;
    while (syntax_params && params)
    {
        if (zcmp(syntax_params->name, params->name))
        {
            return 0;
        }
        syntax_params = syntax_params->next;
        params = params->next;
    }
    return syntax_params == params;
}
示例#2
0
文件: syntax.c 项目: hagenkaye/ne
struct high_color *find_color(struct high_color *colors, unsigned char *name, unsigned char *syn)
{
    unsigned char bf[256];
    struct high_color *color;
    joe_snprintf_2(bf, sizeof(bf), "%s.%s", syn, name);
    for (color = colors; color; color = color->next)
    {
        if (!zcmp(color->name, bf))
        {
            break;
        }
    }
    if (color)
    {
        return color;
    }
    for (color = colors; color; color = color->next)
    {
        if (!zcmp(color->name, name))
        {
            break;
        }
    }
    return color;
}
示例#3
0
B *beafter(B *b)
{
	ERROR *e;
	unsigned char *name = b->name;
	if (!name) name = USTR "";
	for (e = errors.link.next; e != &errors; e = e->link.next)
		if (!zcmp(name, e->file))
			break;
	if (e == &errors) {
		/* Given buffer is not in list?  Return first buffer in list. */
		e = errors.link.next;
	}
	while (e != &errors && !zcmp(name, e->file))
		e = e->link.next;
	berror = 0;
	if (e != &errors) {
		B *b = bfind_incref(e->file);
		/* bfind_incref() bumps refcount, so we have to unbump it. */
		if (b->count == 1)
			b->orphan = 1; /* Oops */
		else
			--b->count;
		return b;
	}
	return 0;
}
示例#4
0
int zmcmp(unsigned char *a, unsigned char *b)
{
	int x = zlen(a);
	do {
		if (a[x] == ':' && a[x + 1] == ':')
			if ((b[0] == ':' && !zcmp(a + x, b)) || !zcmp(a + x + 2, b))
				return 0;
	} while (x--);
	return zcmp(a, b);
}
示例#5
0
static int dobknd(BW *bw, int vt)
{
	unsigned char **a;
	unsigned char *s;
        unsigned char *sh;
	unsigned char start_sh[] = ". " JOERC "shell.sh\n";
	unsigned char start_csh[] = "source " JOERC "shell.csh\n";

        if (!modify_logic(bw,bw->b))
        	return -1;

        sh=(unsigned char *)getenv("SHELL");

        if (file_exists(sh) && zcmp(sh,USTR "/bin/sh")) goto ok;
        if (file_exists(sh=USTR "/bin/bash")) goto ok;
        if (file_exists(sh=USTR "/usr/bin/bash")) goto ok;
        if (file_exists(sh=USTR "/bin/sh")) goto ok;

        msgnw(bw->parent, joe_gettext(_("\"SHELL\" environment variable not defined or exported")));
        return -1;

        ok:
	a = vamk(3);
	s = vsncpy(NULL, 0, sz(sh));
	a = vaadd(a, s);
	s = vsncpy(NULL, 0, sc("-i"));
	a = vaadd(a, s);
	return cstart(bw, sh, a, NULL, NULL, 0, 0, (vt ? (zstr(sh, USTR "csh") ? start_csh : start_sh) : NULL), vt);
}
示例#6
0
void load_yank(FILE *f)
{
	UNDOREC *rec;
	unsigned char buf[SMALL*4+80];
	unsigned char bf[SMALL+1];
	while(fgets((char *)buf,sizeof(buf)-1,f) && zcmp(buf,USTR "done\n")) {
		unsigned char *p = buf;
		int len;
		parse_ws(&p,'#');
		len = parse_string(&p,bf,sizeof(bf));
		if (len>0 && len<=SMALL) {
			if (++nyanked == MAX_YANK) {
				frrec(deque_f(UNDOREC, link, yanked.link.next));
				--nyanked;
			}
			rec = alrec();
			rec->small = (unsigned char *) joe_malloc(len);
			memcpy(rec->small,bf,len);
			rec->where = -1;
			rec->len = len;
			rec->del = 1;
			enqueb(UNDOREC, link, &yanked, rec);
		}
	}
}
示例#7
0
int ubknd(BW *bw)
{
	unsigned char **a;
	unsigned char *s;
        unsigned char *sh;

        if (!modify_logic(bw,bw->b))
        	return -1;

        sh=(unsigned char *)getenv("SHELL");

        if (file_exists(sh) && zcmp(sh,USTR "/bin/sh")) goto ok;
        if (file_exists(sh=USTR "/bin/bash")) goto ok;
        if (file_exists(sh=USTR "/usr/bin/bash")) goto ok;
        if (file_exists(sh=USTR "/bin/sh")) goto ok;

        msgnw(bw->parent, joe_gettext(_("\"SHELL\" environment variable not defined or exported")));
        return -1;

        ok:
	a = vamk(3);
	s = vsncpy(NULL, 0, sz(sh));
	a = vaadd(a, s);
	s = vsncpy(NULL, 0, sc("-i"));
	a = vaadd(a, s);
	return cstart(bw, sh, a, NULL, NULL, 0, 0);
}
示例#8
0
JFILE *jfopen(unsigned char *name, char *mode)
{
	if (name[0] == '*') {
		int x;
		for (x = 0; builtins[x]; x += 2) {
			if (!zcmp(builtins[x], name + 1)) {
				JFILE *j = (JFILE *)joe_malloc(sizeof(JFILE));
				j->f = 0;
				j->p = builtins[x + 1];
				return j;
			}
		}
		return 0;
	} else {
		FILE *f = fopen((char *)name, (char *)mode);
		if (f) {
			JFILE *j = (JFILE *)joe_malloc(sizeof(JFILE));
			j->f = f;
			j->p = 0;
			return j;
		} else {
			return 0;
		}
	}
}
示例#9
0
文件: kbd.c 项目: jhallen/joe-editor
KMAP *ngetcontext(unsigned char *name)
{
    struct context *c;
    for(c=contexts; c; c=c->next)
        if(!zcmp(c->name,name))
            return c->kmap;
    return 0;
}
示例#10
0
void saverr(unsigned char *name)
{
	ERROR *e;

	if (name)
		for (e = errors.link.next; e != &errors; e = e->link.next)
			if (!zcmp(e->file, name))
				e->org = e->line;
}
示例#11
0
static ERROR *srcherr(unsigned char *file, long line)
{
	ERROR *p;
	for (p = errors.link.next; p != &errors; p=p->link.next) {
		if (!zcmp(p->file,file) && p->org == line) {
			return p;
		}
	}
	return NULL;
}
示例#12
0
文件: help.c 项目: Distrotech/joe
struct help *find_context_help(unsigned char *name)
{
	struct help *tmp = help_actual;

	while (tmp->prev != NULL)	/* find the first help entry */
		tmp = tmp->prev;

	while (tmp != NULL && zcmp(tmp->name, name) != 0)
		tmp = tmp->next;

	return tmp;
}
示例#13
0
文件: kbd.c 项目: jhallen/joe-editor
KMAP *kmap_getcontext(unsigned char *name)
{
    struct context *c;

    for (c = contexts; c; c = c->next)
        if (!zcmp(c->name, name))
            return c->kmap;
    c = (struct context *) joe_malloc(sizeof(struct context));

    c->next = contexts;
    c->name = zdup(name);
    contexts = c;
    return c->kmap = mkkmap();
}
示例#14
0
int
copy_security_context(const char *from_file, const char *to_file)
{
	int status = 0;
#ifdef WITH_SELINUX
	security_context_t from_context;
	security_context_t to_context;

	if (selinux_enabled == -1)
		selinux_enabled = (is_selinux_enabled() > 0);

	if (!selinux_enabled)
		return 0;

	if (getfilecon(from_file, &from_context) < 0) {
		/*
		 * If the filesystem doesn't support extended
		 * attributes, the original had no special security
		 * context and the target cannot have one either.
		 */
		if (errno == EOPNOTSUPP)
			return 0;

		error(0, errno, joe_gettext(_("Could not get security context for %s")),
		      from_file);
		return 1;
	}

	if (getfilecon(to_file, &to_context) < 0) {
		MSG_PUTS(_(joe_gettext(_("\nCould not get security context for "))));
		msg_outtrans(to_file);
		msg_putchar('\n');
		freecon(from_context);
		return 1;
	}

	if (zcmp(from_context, to_context) != 0) {
		if (setfilecon(to_file, from_context) < 0) {
			error(0, errno,
			      joe_gettext(_("Could not set security context for %s")),
			      to_file);
			status = 1;
		}
	}

	freecon(to_context);
	freecon(from_context);
#endif
	return status;
}
示例#15
0
int jump_to_file_line(BW *bw,unsigned char *file,int line,unsigned char *msg)
{
	int omid;
	if (!bw->b->name || zcmp(file, bw->b->name)) {
		if (doswitch(bw, vsdup(file), NULL, NULL))
			return -1;
		bw = (BW *) maint->curwin->object;
	}
	omid = mid;
	mid = 1;
	pline(bw->cursor, line);
	dofollows();
	mid = omid;
	bw->cursor->xcol = piscol(bw->cursor);
	msgnw(bw->parent, msg);
	return 0;
}
示例#16
0
void inserr(unsigned char *name, long int where, long int n, int bol)
{
	ERROR *e;

	if (!n)
		return;

	if (name) {
		for (e = errors.link.next; e != &errors; e = e->link.next) {
			if (!zcmp(e->file, name)) {
				if (e->line > where)
					e->line += n;
				else if (e->line == where && bol)
					e->line += n;
			}
		}
	}
}
示例#17
0
void delerr(unsigned char *name, long int where, long int n)
{
	ERROR *e;

	if (!n)
		return;

	if (name) {
		for (e = errors.link.next; e != &errors; e = e->link.next) {
			if (!zcmp(e->file, name)) {
				if (e->line > where + n)
					e->line -= n;
				else if (e->line > where)
					e->line = where;
			}
		}
	}
}
示例#18
0
文件: test.c 项目: maandree/libzahl
int
main(void)
{
	/* static because otherwise it would have to be volatile yeilding a lot of stupid
	 * warnings. auto variables are not guaranteed to be readable after a long jump. */
	static z_t a, b, c, d, _0, _1, _2, _3;
	static char buf[2000];
	static int ret = 0;
	static jmp_buf env, env2;
	static size_t n;

#define BUF_N (sizeof(buf) - 1)

	if (setjmp(env)) {
		zperror(0);
		ret = 2;
		goto done;
	}

	zsetup(env);
	zinit(a), zinit(b), zinit(c), zinit(d), zinit(_0), zinit(_1), zinit(_2), zinit(_3);

	zsetu(_0, 0);
	zsetu(_1, 1);
	zsetu(_2, 2);
	zsetu(_3, 3);

	assert(zeven(_0), == 1);
	assert(zodd(_0), == 0);
	assert(zzero(_0), == 1);
	assert(zsignum(_0), == 0);
	assert(zeven(_1), == 0);
	assert(zodd(_1), == 1);
	assert(zzero(_1), == 0);
	assert(zsignum(_1), == 1);
	assert(zeven(_2), == 1);
	assert(zodd(_2), == 0);
	assert(zzero(_2), == 0);
	assert(zsignum(_2), == 1);

	zswap(_1, _2);
	assert(zeven(_2), == 0);
	assert(zodd(_2), == 1);
	assert(zzero(_2), == 0);
	assert(zsignum(_2), == 1);
	assert(zeven(_1), == 1);
	assert(zodd(_1), == 0);
	assert(zzero(_1), == 0);
	assert(zsignum(_1), == 1);
	zswap(_2, _1);
	assert(zeven(_1), == 0);
	assert(zodd(_1), == 1);
	assert(zzero(_1), == 0);
	assert(zsignum(_1), == 1);
	assert(zeven(_2), == 1);
	assert(zodd(_2), == 0);
	assert(zzero(_2), == 0);
	assert(zsignum(_2), == 1);

	assert((zneg(_2, _2), zsignum(_2)), == -1); zneg(_2, _2);
	assert(zsignum(_2), == 1);

	assert(zcmp(_0, _0), == 0);
	assert(zcmp(_1, _1), == 0);
	assert(zcmp(_0, _1), < 0);
	assert(zcmp(_1, _0), > 0);
	assert(zcmp(_1, _2), < 0);
	assert(zcmp(_2, _1), > 0);
	assert(zcmp(_0, _2), < 0);
	assert(zcmp(_2, _0), > 0);

	zbset(a, _0, 0, 1);
	assert(zcmp(a, _1), == 0);
	zbset(a, a, 1, 1);
	assert(zcmp(a, _3), == 0);
	zbset(a, a, 0, 0);
	assert(zcmp(a, _2), == 0);
	zbset(a, a, 0, 0);
	assert(zcmp(a, _2), == 0);
	zbset(a, a, 0, -1);
	assert(zcmp(a, _3), == 0);
	zbset(a, a, 0, -1);
	assert(zcmp(a, _2), == 0);

	zadd(a, _0, _1);
	assert(zsignum(a), == 1);
	assert(zcmp(a, _1), == 0);
	assert(zcmpi(a, 1), == 0);
	assert(zcmpu(a, 1), == 0);
	zneg(a, a);
	assert(zsignum(a), == -1);
	assert(zcmp(a, _1), < 0);
	assert(zcmpi(a, 1), < 0);
	assert(zcmpu(a, 1), < 0);
	zadd(a, _2, _0);
	assert(zsignum(a), == 1);
	assert(zcmp(a, _2), == 0);
	assert(zcmpi(a, 2), == 0);
	assert(zcmpu(a, 2), == 0);
	zneg(a, a);
	assert(zsignum(a), == -1);
	assert(zcmp(a, _2), < 0);
	assert(zcmpi(a, 2), < 0);
	assert(zcmpu(a, 2), < 0);
	assert(zsignum(_1), == 1);
	zadd(a, _1, _1);
	assert(zsignum(a), == 1);
	assert(zcmp(a, _2), == 0);
	assert(zcmpi(a, 2), == 0);
	assert(zcmpu(a, 2), == 0);
	zset(b, _1);
	zadd(a, b, _1);
	assert(zsignum(a), == 1);
	assert(zcmp(a, _2), == 0);
	assert(zcmpi(a, 2), == 0);
	assert(zcmpu(a, 2), == 0);
	zneg(a, a);
	zset(b, _2);
	zneg(b, b);
	assert(zsignum(a), == -1);
	assert(zcmp(a, b), == 0);
	assert(zcmp(a, _2), < 0);
	assert(zcmpmag(a, b), == 0);
	assert(zcmpmag(a, _2), == 0);
	assert(zcmpi(a, 2), < 0);
	assert(zcmpu(a, 2), < 0);
	assert(zcmpi(a, -2), == 0);
	assert((zneg(_2, _2), zcmp(a, _2)), == 0); zneg(_2, _2);
	zadd(a, _1, _2);
	assert(zsignum(a), == 1);
	assert(zcmp(a, _2), > 0);
	assert(zcmpi(a, 2), > 0);
	assert(zcmpu(a, 2), > 0);
	zneg(a, a);
	zset(b, _2);
	zneg(b, b);
	assert(zsignum(a), == -1);
	assert(zcmpmag(a, _2), > 0);
	assert(zcmpmag(a, b), > 0);
	assert(zcmp(a, b), < 0);
	assert(zcmp(a, _2), < 0);
	assert(zcmpi(a, 2), < 0);
	assert(zcmpu(a, 2), < 0);
	assert(zcmpi(a, -2), < 0);
	assert((zneg(_2, _2), zcmp(a, _2)), < 0); zneg(_2, _2);
	zneg(b, _3);
	assert(zcmp(a, b), == 0);

	zunsetup();
	zsetup(env);

	zsub(a, _2, _1);
	assert(zcmpmag(_2, _1), > 0);
	assert(zcmpmag(_2, _0), > 0);
	assert(zcmpmag(_1, _0), > 0);
	zsub(b, _1, _2);
	assert(zcmpmag(_2, _0), > 0);
	assert(zcmpmag(_1, _0), > 0);
	assert(zcmpmag(_2, _1), > 0);
	assert(zcmpmag(a, b), == 0);
	assert(zcmpmag(a, _1), == 0);
	assert(zcmp(a, b), > 0);
	assert(zcmp(a, _1), == 0);
	assert(zcmp(b, _1), < 0);
	zsub(a, _1, _1);
	assert(zcmp(a, _0), == 0);
	zseti(b, 0);
	zsetu(c, 0);
	zsub(a, b, c);
	assert(zcmp(a, _0), == 0);
	assert(zcmpmag(_2, _1), > 0);
	assert(zcmp(_2, _1), > 0);
	zsub(a, _2, _1);
	assert(zsignum(a), == 1);
	assert(zcmpmag(a, _1), == 0);
	assert(zcmp(a, _1), == 0);
	zsub(a, a, _1);
	assert(zcmp(a, _0), == 0);
	zsub(a, a, _0);
	assert(zcmp(a, _0), == 0);
	zsub(a, _1, _2);
	assert(zcmp(a, _1), < 0);
	assert(zcmpmag(a, _1), == 0);
	zabs(a, a);
	assert(zcmp(a, _1), == 0);
	zabs(a, a);
	assert(zcmp(a, _1), == 0);
	zabs(a, _1);
	assert(zcmp(a, _1), == 0);
	zabs(a, _0);
	assert(zcmp(a, _0), == 0);

	zseti(b, -1);
	zseti(c, -2);
	zadd(a, _0, b);
	assert(zcmp(a, _0), < 0);
	assert(zcmpi(a, -1), == 0);
	assert(zcmpmag(a, _1), == 0);
	assert(zcmp(a, _1), < 0);
	zadd(a, b, _0);
	assert(zcmp(a, _0), < 0);
	assert(zcmpi(a, -1), == 0);
	assert(zcmpmag(a, _1), == 0);
	assert(zcmp(a, _1), < 0);
	zadd(a, b, c);
	assert(zcmp(a, c), < 0);
	assert(zcmpmag(a, _2), > 0);
	zadd(a, c, b);
	assert(zcmp(a, c), < 0);
	assert(zcmpmag(a, _2), > 0);
	zadd(a, b, _1);
	assert(zcmp(a, _0), == 0);
	assert(zcmpmag(a, _0), == 0);
	zadd(a, _1, b);
	assert(zcmp(a, _0), == 0);
	assert(zcmpmag(a, _0), == 0);

	zneg(b, _1);
	zneg(c, _2);
	zsub(a, _0, b);
	assert(zcmp(a, _1), == 0);
	zsub(a, b, _0);
	assert(zcmpmag(a, _1), == 0);
	assert(zcmp(a, _1), < 0);
	zsub(a, b, c);
	assert(zcmpmag(a, _1), == 0);
	assert(zcmp(a, _1), == 0);
	zsub(a, c, b);
	assert(zcmpmag(a, _1), == 0);
	assert(zcmp(a, _1), < 0);
	zsub(a, b, _1);
	assert(zcmpmag(a, _2), == 0);
	assert(zcmp(a, _2), < 0);
	assert(zcmp(a, c), == 0);
	zsub(a, _1, b);
	assert(zcmp(b, _1), < 0);
	assert(zcmpmag(b, _1), == 0);
	assert(zcmp(a, _2), == 0);

	zsetu(a, 1000);
	zsetu(b, 0);
	assert(zcmp(a, b), != 0);
	n = zsave(a, buf);
	assert(n > 0, > 0);
	assert_zu(zload(b, buf), n);
	assert(zcmp(a, b), == 0);

	zneg(b, _1);
	zneg(c, _2);

	assert((zadd_unsigned(a, _1, _2), zcmp(a, _3)), == 0);
	assert((zadd_unsigned(a, b, c), zcmp(a, _3)), == 0);
	assert((zadd_unsigned(a, b, _2), zcmp(a, _3)), == 0);
	assert((zadd_unsigned(a, _1, c), zcmp(a, _3)), == 0);

	assert((zadd_unsigned(a, _0, _0), zcmp(a, _0)), == 0);
	assert((zadd_unsigned(a, _0, _1), zcmp(a, _1)), == 0);
	assert((zadd_unsigned(a, _1, _1), zcmp(a, _2)), == 0);
	assert((zadd_unsigned(a, _1, _0), zcmp(a, _1)), == 0);
	zneg(_1, _1);
	assert((zadd_unsigned(a, _0, _0), zcmp(a, _0)), == 0);
	assert((zadd_unsigned(a, _0, _1), zcmp(a, _1)), != 0);
	assert((zadd_unsigned(a, _0, _1), zcmpmag(a, _1)), == 0);
	assert((zadd_unsigned(a, _1, _1), zcmp(a, _2)), == 0);
	assert((zadd_unsigned(a, _1, _0), zcmp(a, _1)), != 0);
	assert((zadd_unsigned(a, _1, _0), zcmpmag(a, _1)), == 0);
	zneg(_1, _1);

	assert((zsub_unsigned(a, _2, _1), zcmp(a, _1)), == 0);
	assert((zsub_unsigned(a, _2, b), zcmp(a, _1)), == 0);
	assert((zsub_unsigned(a, c, _1), zcmp(a, _1)), == 0);
	assert((zsub_unsigned(a, c, b), zcmp(a, _1)), == 0);

	assert((zsub_unsigned(a, _1, _2), zcmp(a, b)), == 0);
	assert((zsub_unsigned(a, b, _2), zcmp(a, b)), == 0);
	assert((zsub_unsigned(a, _1, c), zcmp(a, b)), == 0);
	assert((zsub_unsigned(a, b, c), zcmp(a, b)), == 0);

	assert_zu(zbits(_0), 1);
	assert_zu(zbits(_1), 1);
	assert_zu(zbits(_2), 2);
	assert_zu(zbits(_3), 2);

	assert_zu(zlsb(_0), SIZE_MAX);
	assert_zu(zlsb(_1), 0);
	assert_zu(zlsb(_2), 1);
	assert_zu(zlsb(_3), 0);

	assert((zand(a, _0, _0), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zand(a, _0, _1), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zand(a, _0, _2), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zand(a, _0, _3), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zand(a, _1, _1), zcmp(a, _1)), == 0);
	assert((zand(a, _1, _2), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zand(a, _1, _3), zcmp(a, _1)), == 0);
	assert((zand(a, _2, _2), zcmp(a, _2)), == 0);
	assert((zand(a, _2, _3), zcmp(a, _2)), == 0);
	assert((zand(a, _3, _3), zcmp(a, _3)), == 0);

	assert((zor(a, _0, _0), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zor(a, _0, _1), zcmp(a, _1)), == 0);
	assert((zor(a, _0, _2), zcmp(a, _2)), == 0);
	assert((zor(a, _0, _3), zcmp(a, _3)), == 0);
	assert((zor(a, _1, _1), zcmp(a, _1)), == 0);
	assert((zor(a, _1, _2), zcmp(a, _3)), == 0);
	assert((zor(a, _1, _3), zcmp(a, _3)), == 0);
	assert((zor(a, _2, _2), zcmp(a, _2)), == 0);
	assert((zor(a, _2, _3), zcmp(a, _3)), == 0);
	assert((zor(a, _3, _3), zcmp(a, _3)), == 0);

	assert((zxor(a, _0, _0), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zxor(a, _0, _1), zcmp(a, _1)), == 0);
	assert((zxor(a, _0, _2), zcmp(a, _2)), == 0);
	assert((zxor(a, _0, _3), zcmp(a, _3)), == 0);
	assert((zxor(a, _1, _1), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zxor(a, _1, _2), zcmp(a, _3)), == 0);
	assert((zxor(a, _1, _3), zcmp(a, _2)), == 0);
	assert((zxor(a, _2, _2), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zxor(a, _2, _3), zcmp(a, _1)), == 0);
	assert((zxor(a, _3, _3), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);

	zneg(b, _1);
	zneg(c, _3);
	zneg(_1, _1);
	zand(a, b, c);
	assert(zcmpmag(a, _1), == 0);
	assert(zcmp(a, _1), == 0);
	zneg(_1, _1);
	assert((zand(a, b, _3), zcmp(a, _1)), == 0);
	assert((zand(a, _1, c), zcmp(a, _1)), == 0);
	assert((zand(a, _0, c), zcmp(a, _0)), == 0);
	assert((zand(a, b, _0), zcmp(a, _0)), == 0);

	zneg(b, _1);
	zneg(c, _2);
	zneg(_3, _3);
	zor(a, b, c);
	assert(zcmpmag(a, _3), == 0);
	assert(zcmp(a, _3), == 0);
	zor(a, b, _2);
	assert(zcmpmag(a, _3), == 0);
	assert(zcmp(a, _3), == 0);
	zor(a, _1, c);
	assert((zcmpmag(a, _3)), == 0);
	assert((zcmp(a, _3)), == 0);
	assert((zor(a, _0, c), zcmp(a, c)), == 0);
	assert((zor(a, b, _0), zcmp(a, b)), == 0);
	zneg(_3, _3);

	zneg(b, _1);
	zneg(c, _2);
	zxor(a, b, c);
	assert(zcmpmag(a, _3), == 0);
	assert(zcmp(a, _3), == 0);
	zneg(_3, _3);
	zxor(a, b, _2);
	assert(zcmpmag(a, _3), == 0);
	assert(zcmp(a, _3), == 0);
	zxor(a, _1, c);
	assert(zcmpmag(a, _3), == 0);
	assert(zcmp(a, _3), == 0);
	zxor(a, b, _0);
	assert(zcmpmag(a, b), == 0);
	assert(zcmp(a, b), == 0);
	zxor(a, _0, c);
	assert(zcmpmag(a, c), == 0);
	assert(zcmp(a, c), == 0);
	zneg(_3, _3);

	assert((zlsh(a, _0, 0), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zlsh(a, _0, 1), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zlsh(a, _1, 0), zcmp(a, _1)), == 0);
	assert((zlsh(a, _1, 1), zcmp(a, _2)), == 0);
	assert((zlsh(a, _1, 2), zcmp(a, _2)), > 0);
	assert((zlsh(a, _2, 0), zcmp(a, _2)), == 0);
	assert((zlsh(a, _2, 1), zcmp(a, _2)), > 0);

	zset(a, _0);
	assert((zlsh(a, a, 0), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zlsh(a, a, 1), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	zset(a, _1);
	assert((zlsh(a, a, 0), zcmp(a, _1)), == 0);
	assert((zlsh(a, a, 1), zcmp(a, _2)), == 0);
	assert((zlsh(a, a, 2), zcmp(a, _2)), > 0);
	zset(a, _2);
	assert((zlsh(a, a, 0), zcmp(a, _2)), == 0);
	assert((zlsh(a, a, 1), zcmp(a, _2)), > 0);

	assert((zrsh(a, _0, 0), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zrsh(a, _0, 1), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zrsh(a, _1, 0), zcmp(a, _1)), == 0);
	assert((zrsh(a, _1, 1), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zrsh(a, _1, 2), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zrsh(a, _2, 0), zcmp(a, _2)), == 0);
	assert((zrsh(a, _2, 1), zcmp(a, _1)), == 0);
	assert((zrsh(a, _2, 2), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);

	zset(a, _0);
	assert((zrsh(a, a, 0), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zrsh(a, a, 1), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	zset(a, _1);
	assert((zrsh(a, a, 0), zcmp(a, _1)), == 0);
	assert((zrsh(a, a, 1), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	assert((zrsh(a, a, 2), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);
	zset(a, _2);
	assert((zrsh(a, a, 0), zcmp(a, _2)), == 0);
	assert((zrsh(a, a, 1), zcmp(a, _1)), == 0);
	assert((zrsh(a, a, 2), zcmp(a, _0)), == 0);
	assert(zzero(a), == 1);

	assert(zbtest(_0, 0), == 0);
	assert(zbtest(_1, 0), == 1);
	assert(zbtest(_2, 0), == 0);
	assert(zbtest(_3, 0), == 1);
	assert(zbtest(_0, 1), == 0);
	assert(zbtest(_1, 1), == 0);
	assert(zbtest(_2, 1), == 1);
	assert(zbtest(_3, 1), == 1);
	assert(zbtest(_0, 2), == 0);
	assert(zbtest(_1, 2), == 0);
	assert(zbtest(_2, 2), == 0);
	assert(zbtest(_3, 2), == 0);

	znot(a, _2);
	assert(zcmpmag(a, _1), == 0);
	assert(zcmp(a, _1), != 0);
	znot(a, a);
	assert(zcmp(a, _0), == 0);

	zsetu(a, 0x1234);
	zsetu(c, 0x234);
	ztrunc(a, a, 12);
	assert(zcmp(a, c), == 0);

	zsetu(a, 0xEEFF);
	zsetu(c, 0xEE);
	zsetu(d, 0xFF);
	zsplit(a, b, a, 8);
	assert(zcmpmag(a, c), == 0);
	assert(zcmpmag(b, d), == 0);
	zsetu(a, 0xEEFF);
	zsplit(b, a, a, 8);
	assert(zcmpmag(b, c), == 0);
	assert(zcmpmag(a, d), == 0);

	zmul(a, _2, _3);
	assert(zcmpi(a, 6), == 0);
	zneg(_3, _3);
	zmul(a, _2, _3);
	assert(zcmpi(a, -6), == 0);
	zneg(_3, _3);
	zneg(_2, _2);
	zmul(a, _2, _3);
	assert(zcmpi(a, -6), == 0);
	zneg(_3, _3);
	zmul(a, _2, _3);
	assert(zcmpi(a, 6), == 0);
	zneg(_3, _3);
	zneg(_2, _2);

	zmul(a, _3, _3);
	assert(zcmpi(a, 9), == 0);
	zsqr(a, _3);
	assert(zcmpi(a, 9), == 0);
	zneg(_3, _3);
	zmul(a, _3, _3);
	assert(zcmpi(a, 9), == 0);
	zsqr(a, _3);
	assert(zcmpi(a, 9), == 0);
	zneg(_3, _3);

	zseti(a, 8);
	zseti(b, 2);
	zdiv(c, a, b);
	assert(zcmpi(c, 4), == 0);
	zseti(b, -2);
	zdiv(c, a, b);
	assert(zcmpi(c, -4), == 0);
	zseti(a, -8);
	zseti(b, 2);
	zdiv(c, a, b);
	assert(zcmpi(c, -4), == 0);
	zseti(b, -2);
	zdiv(c, a, b);
	assert(zcmpi(c, 4), == 0);

	zseti(a, 1000);
	zseti(b, 10);
	zdiv(c, a, b);
	assert(zcmpi(c, 100), == 0);
	zseti(b, -10);
	zdiv(c, a, b);
	assert(zcmpi(c, -100), == 0);
	zseti(a, -1000);
	zseti(b, 10);
	zdiv(c, a, b);
	assert(zcmpi(c, -100), == 0);
	zseti(b, -10);
	zdiv(c, a, b);
	assert(zcmpi(c, 100), == 0);

	zseti(a, 7);
	zseti(b, 3);
	zmod(c, a, b);
	assert(zcmpi(c, 1), == 0);
	zseti(b, -3);
	zmod(c, a, b);
	assert(zcmpi(c, 1), == 0);
	zseti(a, -7);
	zseti(b, 3);
	zmod(c, a, b);
	assert(zcmpi(c, -1), == 0);
	zseti(b, -3);
	zmod(c, a, b);
	assert(zcmpi(c, -1), == 0);

	zseti(a, 7);
	zseti(b, 3);
	zdivmod(d, c, a, b);
	assert(zcmpi(d, 2), == 0);
	assert(zcmpi(c, 1), == 0);
	zseti(b, -3);
	zdivmod(d, c, a, b);
	assert(zcmpi(d, -2), == 0);
	assert(zcmpi(c, 1), == 0);
	zseti(a, -7);
	zseti(b, 3);
	zdivmod(d, c, a, b);
	assert(zcmpi(d, -2), == 0);
	assert(zcmpi(c, -1), == 0);
	zseti(b, -3);
	zdivmod(d, c, a, b);
	assert(zcmpi(d, 2), == 0);
	assert(zcmpi(c, -1), == 0);

	zseti(a, 10);
	zseti(b, -1);
	zpow(a, a, b);
	assert(zcmp(a, _0), == 0);

	zseti(a, 10);
	zseti(b, -1);
	zseti(a, 20);
	zmodpow(a, a, b, c);
	assert(zcmp(a, _0), == 0);

	zseti(a, 10);
	zseti(c, 100000L);
	zpowu(a, a, 5);
	assert(zcmpmag(a, c), == 0);
	assert(zcmp(a, c), == 0);

	zseti(a, -10);
	zseti(c, -100000L);
	zpowu(a, a, 5);
	assert(zcmpmag(a, c), == 0);
	assert(zcmp(a, c), == 0);

	zseti(a, -10);
	zseti(c, 10000L);
	zpowu(a, a, 4);
	assert(zcmpmag(a, c), == 0);
	assert(zcmp(a, c), == 0);

	zseti(a, 10);
	zseti(c, 3);
	zmodpowu(a, a, 5, c);
	assert(zcmpmag(a, _1), == 0);
	assert(zcmp(a, _1), == 0);

	zseti(a, 10);
	zseti(b, 5);
	zseti(c, 100000L);
	zpow(a, a, b);
	assert(zcmpmag(a, c), == 0);
	assert(zcmp(a, c), == 0);

	zseti(a, -10);
	zseti(b, 5);
	zseti(c, -100000L);
	zpow(a, a, b);
	assert(zcmpmag(a, c), == 0);
	assert(zcmp(a, c), == 0);

	zseti(a, -10);
	zseti(b, 4);
	zseti(c, 10000L);
	zpow(a, a, b);
	assert(zcmpmag(a, c), == 0);
	assert(zcmp(a, c), == 0);

	zseti(a, 10);
	zseti(b, 5);
	zseti(c, 3);
	zmodpow(a, a, b, c);
	assert(zcmpmag(a, _1), == 0);
	assert(zcmp(a, _1), == 0);

	zseti(a, 102);
	zseti(b, 501);
	zseti(c, 5);
	zmodmul(a, a, b, c);
	assert(zcmp(a, _2), == 0);

	zseti(b, 2 * 3 * 3 * 7);
	zseti(c, 3 * 7 * 11);
	zseti(d, 3 * 7);
	assert((zgcd(a, _0, _0), zcmp(a, _0)), == 0);
	assert((zgcd(a, b, _0), zcmp(a, b)), == 0);
	assert((zgcd(a, _0, c), zcmp(a, c)), == 0);
	assert((zgcd(a, b, b), zcmp(a, b)), == 0);
	assert((zgcd(a, b, _2), zcmp(a, _2)), == 0);
	assert((zgcd(a, _2, b), zcmp(a, _2)), == 0);
	assert((zgcd(a, _2, _2), zcmp(a, _2)), == 0);
	assert((zgcd(a, c, _2), zcmp(a, _1)), == 0);
	assert((zgcd(a, _2, c), zcmp(a, _1)), == 0);
	assert((zgcd(a, b, _1), zcmp(a, _1)), == 0);
	assert((zgcd(a, _1, c), zcmp(a, _1)), == 0);
	assert((zgcd(a, _1, _1), zcmp(a, _1)), == 0);
	assert((zgcd(a, b, c), zcmp(a, d)), == 0);
	assert((zgcd(a, c, b), zcmp(a, d)), == 0);

	zsets(a, "1234");
	assert(zcmpi(a, 1234), == 0);
	zsets(b, "+1234");
	assert(zcmp(a, b), == 0);
	assert_zu(zstr_length(_0, 10), 1);
	assert_zu(zstr_length(_1, 10), 1);
	assert_zu(zstr_length(_2, 10), 1);
	assert_zu(zstr_length(_3, 10), 1);
	zneg(_2, _2);
	assert_zu(zstr_length(_2, 10), 2);
	zneg(_2, _2);
	assert_zu(zstr_length(a, 10), 4);
	zstr(a, buf, 0);
	assert_s(buf, "1234");
	zsets(a, "-1234");
	zseti(b, -1234);
	zseti(c, 1234);
	assert(zcmp(a, _0), < 0);
	assert(zcmp(a, b), == 0);
	assert(zcmpmag(a, c), == 0);
	assert(zcmp(a, c), < 0);
	zstr(a, buf, 0);
	assert_s(buf, "-1234");
	assert_s(zstr(a, buf, 0), "-1234");

	zsetu(d, 100000UL);
	zrand(a, FAST_RANDOM, UNIFORM, d);
	assert(zcmp(a, _0), >= 0);
	assert(zcmp(a, d), <= 0);
	zrand(b, SECURE_RANDOM, UNIFORM, d);
	assert(zcmp(b, _0), >= 0);
	assert(zcmp(b, d), <= 0);
	zrand(c, FASTEST_RANDOM, UNIFORM, d);
	assert(zcmp(c, _0), >= 0);
	assert(zcmp(c, d), <= 0);
	assert(zcmp(a, b), != 0);
	assert(zcmp(a, c), != 0);
	assert(zcmp(b, c), != 0);

	zsetu(d, 100000UL);
	zrand(a, DEFAULT_RANDOM, QUASIUNIFORM, d);
	assert(zcmp(a, _0), >= 0);
	assert(zcmp(a, d), <= 0);
	zrand(b, DEFAULT_RANDOM, QUASIUNIFORM, d);
	assert(zcmp(b, _0), >= 0);
	assert(zcmp(b, d), <= 0);
	zrand(c, DEFAULT_RANDOM, QUASIUNIFORM, d);
	assert(zcmp(c, _0), >= 0);
	assert(zcmp(c, d), <= 0);
	assert(zcmp(a, b), != 0);
	assert(zcmp(a, c), != 0);
	assert(zcmp(b, c), != 0);

	zsetu(d, 100000UL);
	zrand(a, DEFAULT_RANDOM, MODUNIFORM, d);
	assert(zcmp(a, _0), >= 0);
	assert(zcmp(a, d), <= 0);
	zrand(b, DEFAULT_RANDOM, MODUNIFORM, d);
	assert(zcmp(b, _0), >= 0);
	assert(zcmp(b, d), <= 0);
	zrand(c, DEFAULT_RANDOM, MODUNIFORM, d);
	assert(zcmp(c, _0), >= 0);
	assert(zcmp(c, d), <= 0);
	assert(zcmp(a, b), != 0);
	assert(zcmp(a, c), != 0);
	assert(zcmp(b, c), != 0);

	assert((zseti(a, -5), zptest(0, a, 100)), == NONPRIME);
	assert((zseti(a, -4), zptest(0, a, 100)), == NONPRIME);
	assert((zseti(a, -3), zptest(0, a, 100)), == NONPRIME);
	assert((zseti(a, -2), zptest(0, a, 100)), == NONPRIME);
	assert((zseti(a, -1), zptest(0, a, 100)), == NONPRIME);
	assert((zseti(a, 0), zptest(0, a, 100)), == NONPRIME);
	assert((zseti(a, 1), zptest(0, a, 100)), == NONPRIME);
	assert((zseti(a, 2), zptest(0, a, 100)), == PRIME);
	assert((zseti(a, 3), zptest(0, a, 100)), == PRIME);
	assert((zseti(a, 4), zptest(0, a, 100)), == NONPRIME);
	assert((zseti(a, 5), zptest(0, a, 100)), != NONPRIME);
	assert((zseti(a, 6), zptest(0, a, 100)), == NONPRIME);
	assert((zseti(a, 7), zptest(0, a, 100)), != NONPRIME);
	assert((zseti(a, 8), zptest(0, a, 100)), == NONPRIME);
	assert((zseti(a, 9), zptest(0, a, 100)), == NONPRIME);
	assert((zseti(a, 10), zptest(0, a, 100)), == NONPRIME);
	assert((zseti(a, 11), zptest(0, a, 100)), != NONPRIME);
	assert((zseti(a, 101), zptest(0, a, 100)), != NONPRIME);

#if defined(ZAHL_UNSAFE)
	(void) env2;
#else
	assert_nr(zdivmod(a, b, _0, _0));
	assert_nr(zdivmod(a, b, _1, _0));
	zdivmod(a, b, _0, _1);
	zdivmod(a, b, _1, _1);
	assert_nr(zdiv(a, _0, _0));
	assert_nr(zdiv(a, _1, _0));
	zdiv(a, _0, _1);
	zdiv(a, _1, _1);
	assert_nr(zmod(a, _0, _0));
	assert_nr(zmod(a, _1, _0));
	zmod(a, _0, _1);
	zmod(a, _1, _1);
	assert_nr(zpow(a, _0, _0));
	assert_nr((zneg(_1, _1), zpow(a, _0, _1))); zneg(_1, _1);
	zpow(a, _0, _1);
	zpow(a, _1, _0);
	zneg(_1, _1), zpow(a, _1, _0), zneg(_1, _1);
	assert_nr(zmodmul(a, _1, _1, _0));
	assert_nr(zmodpow(a, _0, _0, _1));
	assert_nr((zneg(_1, _1), zmodpow(a, _0, _1, _1))); zneg(_1, _1);
	zmodpow(a, _0, _1, _1);
	zmodpow(a, _1, _0, _1);
	zneg(_1, _1), zmodpow(a, _1, _0, _1), zneg(_1, _1);
	assert_nr(zmodpow(a, _0, _0, _0));
	assert_nr((zneg(_1, _1), zmodpow(a, _0, _1, _0))); zneg(_1, _1);
	assert_nr(zmodpow(a, _0, _1, _0));
	assert_nr(zmodpow(a, _1, _0, _0));
	assert_nr((zneg(_1, _1), zmodpow(a, _1, _0, _0))); zneg(_1, _1);
	assert_nr(zpowu(a, _0, 0));
	zpowu(a, _0, 1);
	zpowu(a, _1, 0);
	zneg(_1, _1), zpowu(a, _1, 0), zneg(_1, _1);
	assert_nr(zmodpowu(a, _0, 0, _1));
	zmodpowu(a, _0, 1, _1);
	zmodpowu(a, _1, 0, _1);
	zneg(_1, _1), zmodpowu(a, _1, 0, _1), zneg(_1, _1);
	assert_nr(zmodpowu(a, _0, 0, _0));
	assert_nr((zneg(_1, _1), zmodpowu(a, _0, 1, _0))); zneg(_1, _1);
	assert_nr(zmodpowu(a, _0, 1, _0));
	assert_nr(zmodpowu(a, _1, 0, _0));
	assert_nr((zneg(_1, _1), zmodpowu(a, _1, 0, _0))); zneg(_1, _1);
	assert_nr(zstr_length(a, 0));
	assert_nr(zstr_length(a, 1));
	zstr_length(a, 2);
	zstr_length(a, 3);
#endif

	zsetu(a, 1LL);
	assert_s(zstr(a, buf, 1), "1");
	zsetu(a, 10LL);
	assert_s(zstr(a, buf, 2), "10");
	zsetu(a, 100LL);
	assert_s(zstr(a, buf, 3), "100");
	zsetu(a, 1000LL);
	assert_s(zstr(a, buf, 4), "1000");
	zsetu(a, 10000LL);
	assert_s(zstr(a, buf, BUF_N), "10000");
	zsetu(a, 100000LL);
	assert_s(zstr(a, buf, BUF_N), "100000");
	zsetu(a, 1000000LL);
	assert_s(zstr(a, buf, BUF_N), "1000000");
	zsetu(a, 10000000LL);
	assert_s(zstr(a, buf, BUF_N), "10000000");
	zsetu(a, 100000000LL);
	assert_s(zstr(a, buf, BUF_N), "100000000");
	zsetu(a, 999999999LL);
	assert_s(zstr(a, buf, BUF_N), "999999999");
	zsetu(a, 1000000000LL);
	assert_s(zstr(a, buf, BUF_N), "1000000000");
	zsetu(a, 1000000001LL);
	assert_s(zstr(a, buf, BUF_N), "1000000001");
	zsetu(a, 2000000000LL);
	assert_s(zstr(a, buf, BUF_N), "2000000000");
	zsetu(a, 2050000000LL);
	assert_s(zstr(a, buf, BUF_N), "2050000000");
	zsetu(a, 2100000000LL);
	assert_s(zstr(a, buf, BUF_N), "2100000000");
	zsetu(a, 2140000000LL);
	assert_s(zstr(a, buf, BUF_N), "2140000000");
	zsetu(a, 2147000000LL);
	assert_s(zstr(a, buf, BUF_N), "2147000000");
	zsetu(a, 2147483000LL);
	assert_s(zstr(a, buf, BUF_N), "2147483000");
	zsetu(a, 2147483640LL);
	assert_s(zstr(a, buf, BUF_N), "2147483640");
	zsetu(a, 2147483646LL);
	assert_s(zstr(a, buf, BUF_N), "2147483646");

	zseti(a, 2147483647LL);
	assert_s(zstr(a, buf, BUF_N), "2147483647");
	zseti(a, -2147483647LL);
	assert_s(zstr(a, buf, BUF_N), "-2147483647");
	zseti(a, -2147483647LL - 1LL);
	assert_s(zstr(a, buf, BUF_N), "-2147483648");

	zsetu(a, 2147483647ULL);
	assert_s(zstr(a, buf, BUF_N), "2147483647");
	zsetu(a, 2147483648ULL);
	assert_s(zstr(a, buf, BUF_N), "2147483648");
	zsetu(a, 2147483649ULL);
	assert_s(zstr(a, buf, BUF_N), "2147483649");

	zsetu(a, 3000000000ULL);
	assert_s(zstr(a, buf, BUF_N), "3000000000");
	zsetu(a, 3100000000ULL);
	assert_s(zstr(a, buf, BUF_N), "3100000000");
	zsetu(a, 3200000000ULL);
	assert_s(zstr(a, buf, BUF_N), "3200000000");
	zsetu(a, 3300000000ULL);
	assert_s(zstr(a, buf, BUF_N), "3300000000");
	zsetu(a, 3400000000ULL);
	assert_s(zstr(a, buf, BUF_N), "3400000000");
	zsetu(a, 3500000000ULL);
	assert_s(zstr(a, buf, BUF_N), "3500000000");
	zsetu(a, 3600000000ULL);
	assert_s(zstr(a, buf, BUF_N), "3600000000");
	zsetu(a, 3700000000ULL);
	assert_s(zstr(a, buf, BUF_N), "3700000000");
	zsetu(a, 3800000000ULL);
	assert_s(zstr(a, buf, BUF_N), "3800000000");
	zsetu(a, 3900000000ULL);
	assert_s(zstr(a, buf, BUF_N), "3900000000");
	zsetu(a, 3999999999ULL);
	assert_s(zstr(a, buf, BUF_N), "3999999999");
	zsetu(a, 4000000000ULL);
	assert_s(zstr(a, buf, BUF_N), "4000000000");
	zsetu(a, 4000000001ULL);
	assert_zu(zstr_length(a, 10), 10);
	assert_s(zstr(a, buf, BUF_N), "4000000001");

	zsetu(a, 4000000000ULL);
	zsetu(b, 4000000000ULL);
	zadd(c, a, a);
	zsets(d, "8000000000");
	assert(zcmp(c, d), == 0);
	zadd(c, a, b);
	assert(zcmp(c, d), == 0);
	zadd(c, c, a);
	zsets(d, "12000000000");
	assert(zcmp(c, d), == 0);
	zsub(c, c, a);
	zsets(d, "8000000000");
	assert(zcmp(c, d), == 0);
	zsub(c, c, a);
	zsets(d, "4000000000");
	assert(zcmp(c, d), == 0);
	zsets(d, "8000000000");
	zrsh(d, d, 1);
	assert(zcmp(c, d), == 0);
	zsets(a, "6234216714");
	zsets(b, "9424614147");
	zsets(d, "830476546");
	zand(c, a, b);
	assert(zcmp(c, d), == 0);
	zsets(a, "234216714");
	zsets(b, "9424614147");
	zsets(d, "9629466379");
	zor(c, a, b);
	assert(zcmp(c, d), == 0);
	zsets(a, "6234216714");
	zsets(b, "9424614147");
	zsets(d, "13997877769");
	zxor(c, a, b);
	assert(zcmp(c, d), == 0);
	zsets(a, "34216714");
	zsets(b, "9424614147");
	zsets(d, "9458821129");
	zxor(c, a, b);
	assert(zcmp(c, d), == 0);
	zsetu(a, 1000000000ULL);
	zsets(d, "1000000000000000000");
	zmul(c, a, a);
	assert(zcmp(c, d), == 0);
	zdiv(c, c, a);
	assert(zcmp(c, a), == 0);
	zsetu(a, 1000000000ULL);
	zsets(d, "1000000000000000000");
	zsqr(c, a);
	assert(zcmp(c, d), == 0);
	zsetu(a, 1000000000ULL);
	zmodpowu(c, a, 5, _3);
	assert(zcmpu(c, 1), == 0);
	zsetu(a, 1000000000ULL);
	zsets(d, "1");
	zpowu(c, a, 0);
	assert(zcmp(c, d), == 0);
	zsetu(a, 1000000000ULL);
	zsets(d, "1000000000");
	zpowu(c, a, 1);
	assert(zcmp(c, d), == 0);
	zsetu(a, 1000000000ULL);
	zsets(d, "1000000000000000000");
	zpowu(c, a, 2);
	assert(zcmp(c, d), == 0);
	zsetu(a, 1000000000ULL);
	zsets(b, "1000000000000000000");
	zsets(d, "1000000000000000000000000000");
	zmul(c, a, b);
	assert(zcmp(c, d), == 0);
	zsetu(a, 1000000000ULL);
	zsets(d, "1000000000000000000000000000");
	zmul(b, a, a);
	zmul(b, b, a);
	assert(zcmp(c, d), == 0);
	zsetu(a, 1000000000ULL);
	zsets(d, "1000000000000000000000000000");
	zpowu(c, a, 3);
	assert(zcmp(c, d), == 0);
	zsetu(a, 1000000000ULL);
	zsets(d, "1000000000000000000000000000000000000");
	zpowu(c, a, 4);
	assert(zcmp(c, d), == 0);
	zsetu(a, 1000000000ULL);
	zsets(d, "1000000000000000000000000000000000000000000000");
	zpowu(c, a, 5);
	assert(zcmp(c, d), == 0);

	zsetu(a, 4294967294ULL);
	assert_s(zstr(a, buf, BUF_N), "4294967294");
	zsetu(a, 4294967295ULL);
	assert_s(zstr(a, buf, BUF_N), "4294967295");
	zsetu(a, 4294967296ULL);
	assert_s(zstr(a, buf, BUF_N), "4294967296");
	zsetu(a, 4294967297ULL);
	assert_s(zstr(a, buf, BUF_N), "4294967297");

	zseti(a, 9223372036854775807LL);
	assert_s(zstr(a, buf, BUF_N), "9223372036854775807");
	zseti(a, -9223372036854775807LL);
	assert_s(zstr(a, buf, BUF_N), "-9223372036854775807");
	zseti(a, -9223372036854775807LL - 1LL);
	assert_s(zstr(a, buf, BUF_N), "-9223372036854775808");

	zsetu(a, 18446744073709551614ULL);
	assert_s(zstr(a, buf, BUF_N), "18446744073709551614");
	zsetu(a, 18446744073709551615ULL);
	assert_s(zstr(a, buf, BUF_N), "18446744073709551615");
	zadd(a, a, _1);
	assert_s(zstr(a, buf, BUF_N), "18446744073709551616");
	zadd(a, a, _1);
	assert_s(zstr(a, buf, BUF_N), "18446744073709551617");

	zsets(a, "1000000000000000000000000000000");
	assert_s(zstr(a, buf, BUF_N), "1000000000000000000000000000000");
	zsets(a, "+1000000000000000000000000000000");
	assert_s(zstr(a, buf, BUF_N), "1000000000000000000000000000000");
	zsets(a, "-1000000000000000000000000000000");
	assert_s(zstr(a, buf, BUF_N), "-1000000000000000000000000000000");

	zsetu(a, 1000000000000000ULL);
	zsqr(a, a);
	assert_s(zstr(a, buf, BUF_N), "1000000000000000000000000000000");

#include "test-random.c"

done:
	zfree(a), zfree(b), zfree(c), zfree(d), zfree(_0), zfree(_1), zfree(_2), zfree(_3);
	zunsetup();
	return ret;
}
示例#19
0
文件: syntax.c 项目: hagenkaye/ne
struct high_state *load_dfa(struct high_syntax *syntax)
{
    unsigned char name[1024];
    unsigned char buf[1024];
    unsigned char bf[256];
    int clist[256];
    unsigned char *p;
    int c;
    FILE *f = NULL;
    struct ifstack *stack = 0;
    struct high_state *state = 0; /* Current state */
    struct high_state *first = 0; /* First state */
    int line = 0;
    int this_one = 0;
    int inside_subr = 0;

    /* Load it */

    if ((p = (unsigned char *)exists_prefs_dir()) && strlen((const char *)p) + 2 + strlen(SYNTAX_DIR) + strlen(SYNTAX_EXT) + strlen((const char *)syntax->name) < sizeof name)
    {
        strcat(strcat(strcat(strcat(strcpy((char *)name, (const char *)p), SYNTAX_DIR), "/"), (const char *)syntax->name), SYNTAX_EXT);
        f = fopen((char *)name, "r");
    }

    if (!f && (p = (unsigned char *)exists_gprefs_dir()) && strlen((const char *)p) + 2 + strlen(SYNTAX_DIR) + strlen(SYNTAX_EXT) + strlen((const char *)syntax->name) < sizeof name)
    {
        strcat(strcat(strcat(strcat(strcpy((char *)name, (const char *)p), SYNTAX_DIR), "/"), (const char *)syntax->name), SYNTAX_EXT);
        f = fopen((char *)name, "r");
    }

    if (!f)
    {
        return 0;
    }

    /* Parse file */
    while (fgets((char *)buf, 1023, f))
    {
        ++line;
        p = buf;
        c = parse_ws(&p, '#');
        if (!parse_char(&p, '.'))
        {
            if (!parse_ident(&p, bf, sizeof(bf)))
            {
                if (!zcmp(bf, USTR "ifdef"))
                {
                    struct ifstack *st = joe_malloc(sizeof(struct ifstack));
                    st->next = stack;
                    st->else_part = 0;
                    st->ignore = 1;
                    st->skip = 1;
                    st->line = line;
                    if (!stack || !stack->ignore)
                    {
                        parse_ws(&p, '#');
                        if (!parse_ident(&p, bf, sizeof(bf)))
                        {
                            struct high_param *param;
                            for (param = syntax->params; param; param = param->next)
                                if (!zcmp(param->name, bf))
                                {
                                    st->ignore = 0;
                                    break;
                                }
                            st->skip = 0;
                        }
                        else
                        {
                            i_printf_2((char *)joe_gettext(_("%s %d: missing parameter for ifdef\n")), name, line);
                        }
                    }
                    stack = st;
                }
                else if (!zcmp(bf, USTR "else"))
                {
                    if (stack && !stack->else_part)
                    {
                        stack->else_part = 1;
                        if (!stack->skip)
                        {
                            stack->ignore = !stack->ignore;
                        }
                    }
                    else
                    {
                        i_printf_2((char *)joe_gettext(_("%s %d: else with no matching if\n")), name, line);
                    }
                }
                else if (!zcmp(bf, USTR "endif"))
                {
                    if (stack)
                    {
                        struct ifstack *st = stack;
                        stack = st->next;
                        joe_free(st);
                    }
                    else
                    {
                        i_printf_2((char *)joe_gettext(_("%s %d: endif with no matching if\n")), name, line);
                    }
                }
                else if (!zcmp(bf, USTR "subr"))
                {
                    parse_ws(&p, '#');
                    if (parse_ident(&p, bf, sizeof(bf)))
                    {
                        i_printf_2((char *)joe_gettext(_("%s %d: Missing subroutine name\n")), name, line);
                    }
                    else
                    {
                        if (!stack || !stack->ignore)
                        {
                            inside_subr = 1;
                            this_one = 0;
                            if (syntax->subr && !zcmp(bf, syntax->subr))
                            {
                                this_one = 1;
                            }
                        }
                    }
                }
                else if (!zcmp(bf, USTR "end"))
                {
                    if (!stack || !stack->ignore)
                    {
                        this_one = 0;
                        inside_subr = 0;
                    }
                }
                else
                {
                    i_printf_2((char *)joe_gettext(_("%s %d: Unknown control statement\n")), name, line);
                }
            }
            else
            {
                i_printf_2((char *)joe_gettext(_("%s %d: Missing control statement name\n")), name, line);
            }
        }
        else if (stack && stack->ignore)
        {
            /* Ignore this line because of ifdef */
        }
        else if (!parse_char(&p, '='))
        {
            /* Parse color */
            parse_color_def(&syntax->color, p, name, line);
        }
        else if ((syntax->subr && !this_one) || (!syntax->subr && inside_subr))
        {
            /* Ignore this line because it's not the code we want */
        }
        else if (!parse_char(&p, ':'))
        {
            if (!parse_ident(&p, bf, sizeof(bf)))
            {

                state = find_state(syntax, bf);

                if (!first)
                {
                    first = state;
                }

                parse_ws(&p, '#');
                if (!parse_tows(&p, bf))
                {
                    struct high_color *color;
                    for (color = syntax->color; color; color = color->next)
                        if (!zcmp(color->name, bf))
                        {
                            break;
                        }
                    if (color)
                    {
                        state->color = color->color;
                    }
                    else
                    {
                        state->color = 0;
                        i_printf_2((char *)joe_gettext(_("%s %d: Unknown class\n")), name, line);
                    }
                }
                else
                {
                    i_printf_2((char *)joe_gettext(_("%s %d: Missing color for state definition\n")), name, line);
                }
            }
            else
            {
                i_printf_2((char *)joe_gettext(_("%s %d: Missing state name\n")), name, line);
            }
        }
        else if (!parse_char(&p, '-'))
        {
            /* No. sync lines ignored */
        }
        else
        {
            c = parse_ws(&p, '#');

            if (!c)
            {
            }
            else if (c == '"' || c == '*' || c == '&')
            {
                if (state)
                {
                    struct high_cmd *cmd;
                    int delim = 0;
                    if (!parse_field(&p, USTR "*"))
                    {
                        int z;
                        for (z = 0; z != 256; ++z)
                        {
                            clist[z] = 1;
                        }
                    }
                    else if (!parse_field(&p, USTR "&"))
                    {
                        delim = 1;
                    }
                    else
                    {
                        c = parse_string(&p, bf, sizeof(bf));
                        if (c < 0)
                        {
                            i_printf_2((char *)joe_gettext(_("%s %d: Bad string\n")), name, line);
                        }
                        else
                        {
                            int z;
                            int first, second;
                            unsigned char *t = bf;
                            for (z = 0; z != 256; ++z)
                            {
                                clist[z] = 0;
                            }
                            while (!parse_range(&t, &first, &second))
                            {
                                if (first > second)
                                {
                                    second = first;
                                }
                                while (first <= second)
                                {
                                    clist[first++] = 1;
                                }
                            }
                        }
                    }
                    /* Create command */
                    cmd = mkcmd();
                    parse_ws(&p, '#');
                    if (!parse_ident(&p, bf, sizeof(bf)))
                    {
                        int z;
                        cmd->new_state = find_state(syntax, bf);
                        parse_options(syntax, cmd, f, p, 0, name, line);

                        /* Install command */
                        if (delim)
                        {
                            state->delim = cmd;
                        }
                        else for (z = 0; z != 256; ++z)
                                if (clist[z])
                                {
                                    state->cmd[z] = cmd;
                                }
                    }
                    else
                    {
                        i_printf_2((char *)joe_gettext(_("%s %d: Missing jump\n")), name, line);
                    }
                }
                else
                {
                    i_printf_2((char *)joe_gettext(_("%s %d: No state\n")), name, line);
                }
            }
            else
            {
                i_printf_2((char *)joe_gettext(_("%s %d: Unknown character\n")), name, line);
            }
        }
    }

    while (stack)
    {
        struct ifstack *st = stack;
        stack = st->next;
        i_printf_2((char *)joe_gettext(_("%s %d: ifdef with no matching endif\n")), name, st->line);
        joe_free(st);
    }

    fclose(f);

    return first;
}
示例#20
0
文件: syntax.c 项目: hagenkaye/ne
void parse_options(struct high_syntax *syntax, struct high_cmd *cmd, FILE *f, unsigned char *p, int parsing_strings, unsigned char *name, int line)
{
    unsigned char buf[1024];
    unsigned char bf[256];
    unsigned char bf1[256];

    while (parse_ws(&p, '#'), !parse_ident(&p, bf, sizeof(bf)))
    {
        if (!zcmp(bf, USTR "buffer"))
        {
            cmd->start_buffering = 1;
        }
        else if (!zcmp(bf, USTR "hold"))
        {
            cmd->stop_buffering = 1;
        }
        else if (!zcmp(bf, USTR "save_c"))
        {
            cmd->save_c = 1;
        }
        else if (!zcmp(bf, USTR "save_s"))
        {
            cmd->save_s = 1;
        }
        else if (!zcmp(bf, USTR "recolor"))
        {
            parse_ws(&p, '#');
            if (!parse_char(&p, '='))
            {
                parse_ws(&p, '#');
                if (parse_int(&p, &cmd->recolor))
                {
                    i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")), name, line);
                }
            }
            else
            {
                i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")), name, line);
            }
        }
        else if (!zcmp(bf, USTR "call"))
        {
            parse_ws(&p, '#');
            if (!parse_char(&p, '='))
            {
                parse_ws(&p, '#');
                if (!parse_char(&p, '.'))
                {
                    zcpy(bf, syntax->name);
                    goto subr;
                }
                else if (parse_ident(&p, bf, sizeof(bf)))
                {
                    i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")), name, line);
                }
                else
                {
                    if (!parse_char(&p, '.'))
                    {
subr:
                        if (parse_ident(&p, bf1, sizeof(bf1)))
                        {
                            i_printf_2((char *)joe_gettext(_("%s %d: Missing subroutine name\n")), name, line);
                        }
                        cmd->call = load_syntax_subr(bf, bf1, parse_params(syntax->params, &p, name, line));
                    }
                    else
                    {
                        cmd->call = load_syntax_subr(bf, 0, parse_params(syntax->params, &p, name, line));
                    }
                }
            }
            else
            {
                i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")), name, line);
            }
        }
        else if (!zcmp(bf, USTR "return"))
        {
            cmd->rtn = 1;
        }
        else if (!zcmp(bf, USTR "reset"))
        {
            cmd->reset = 1;
        }
        else if (!parsing_strings && (!zcmp(bf, USTR "strings") || !zcmp(bf, USTR "istrings")))
        {
            if (bf[0] == 'i')
            {
                cmd->ignore = 1;
            }
            while (fgets((char *)buf, 1023, f))
            {
                ++line;
                p = buf;
                parse_ws(&p, '#');
                if (*p)
                {
                    if (!parse_field(&p, USTR "done"))
                    {
                        break;
                    }
                    if (parse_string(&p, bf, sizeof(bf)) >= 0)
                    {
                        parse_ws(&p, '#');
                        if (cmd->ignore)
                        {
                            lowerize(bf);
                        }
                        if (!parse_ident(&p, bf1, sizeof(bf1)))
                        {
                            struct high_cmd *kw_cmd = mkcmd();
                            kw_cmd->noeat = 1;
                            kw_cmd->new_state = find_state(syntax, bf1);
                            if (!zcmp(bf, USTR "&"))
                            {
                                cmd->delim = kw_cmd;
                            }
                            else
                            {
                                if (!cmd->keywords)
                                {
                                    cmd->keywords = htmk(64);
                                }
                                htadd(cmd->keywords, zdup(bf), kw_cmd);
                            }
                            parse_options(syntax, kw_cmd, f, p, 1, name, line);
                        }
                        else
                        {
                            i_printf_2((char *)joe_gettext(_("%s %d: Missing state name\n")), name, line);
                        }
                    }
                    else
                    {
                        i_printf_2((char *)joe_gettext(_("%s %d: Missing string\n")), name, line);
                    }
                }
            }
        }
        else if (!zcmp(bf, USTR "noeat"))
        {
            cmd->noeat = 1;
        }
        else if (!zcmp(bf, USTR "mark"))
        {
            cmd->start_mark = 1;
        }
        else if (!zcmp(bf, USTR "markend"))
        {
            cmd->stop_mark = 1;
        }
        else if (!zcmp(bf, USTR "recolormark"))
        {
            cmd->recolor_mark = 1;
        }
        else
        {
            i_printf_2((char *)joe_gettext(_("%s %d: Unknown option\n")), name, line);
        }
    }
}
示例#21
0
文件: syntax.c 项目: hagenkaye/ne
struct high_param *parse_params(struct high_param *current_params, unsigned char **ptr, unsigned char *name, int line)
{
    unsigned char *p = *ptr;
    unsigned char bf[256];
    struct high_param *params;
    struct high_param **param_ptr;

    /* Propagate currently defined parameters */
    param_ptr = &params;
    while (current_params)
    {
        *param_ptr = joe_malloc(sizeof(struct high_param));
        (*param_ptr)->name = zdup(current_params->name);
        param_ptr = &(*param_ptr)->next;
        current_params = current_params->next;
    }
    *param_ptr = 0;

    parse_ws(&p, '#');
    if (!parse_char(&p, '('))
    {
        for (;;)
        {
            parse_ws(&p, '#');
            if (!parse_char(&p, ')'))
            {
                break;
            }
            else if (!parse_char(&p, '-'))
            {
                if (!parse_ident(&p, bf, sizeof(bf)))
                {
                    int cmp = 0;
                    param_ptr = &params;
                    /* Parameters are sorted */
                    while (*param_ptr && (cmp = zcmp(bf, (*param_ptr)->name)) > 0)
                    {
                        param_ptr = &(*param_ptr)->next;
                    }
                    if (*param_ptr && !cmp)
                    {
                        /* Remove this parameter */
                        struct high_param *param = *param_ptr;
                        *param_ptr = param->next;
                        joe_free(param);
                    }
                }
                else
                {
                    i_printf_2((char *)joe_gettext(_("%s %d: Missing parameter name\n")), name, line);
                }
            }
            else if (!parse_ident(&p, bf, sizeof(bf)))
            {
                int cmp = 0;
                param_ptr = &params;
                /* Keep parameters sorted */
                while (*param_ptr && (cmp = zcmp(bf, (*param_ptr)->name)) > 0)
                {
                    param_ptr = &(*param_ptr)->next;
                }
                /* Discard duplicates */
                if (!*param_ptr || cmp)
                {
                    struct high_param *param = joe_malloc(sizeof(struct high_param));
                    param->name = zdup(bf);
                    param->next = *param_ptr;
                    *param_ptr = param;
                }
            }
            else
            {
                i_printf_2((char *)joe_gettext(_("%s %d: Missing )\n")), name, line);
                break;
            }
        }
    }

    *ptr = p;
    return params;
}
示例#22
0
文件: kbd.c 项目: jhallen/joe-editor
static KMAP *kbuild(CAP *cap, KMAP *kmap, unsigned char *seq, void *bind, int *err, unsigned char *capseq, int seql)
{
    int v, w;

    if (!seql && seq[0] == '.' && seq[1]) {
        int x, c;
        unsigned char *s;

        for (x = 0; seq[x] && seq[x] != ' '; ++x) ;
        c = seq[x];
        seq[x] = 0;
#ifdef __MSDOS__
        if (!zcmp(seq + 1, "ku")) {
            capseq = "\0H";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "kd")) {
            capseq = "\0P";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "kl")) {
            capseq = "\0K";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "kr")) {
            capseq = "\0M";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "kI")) {
            capseq = "\0R";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "kD")) {
            capseq = "\0S";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "kh")) {
            capseq = "\0G";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "kH")) {
            capseq = "\0O";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "kP")) {
            capseq = "\0I";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "kN")) {
            capseq = "\0Q";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "k1")) {
            capseq = "\0;";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "k2")) {
            capseq = "\0<";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "k3")) {
            capseq = "\0=";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "k4")) {
            capseq = "\0>";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "k5")) {
            capseq = "\0?";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "k6")) {
            capseq = "\0@";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "k7")) {
            capseq = "\0A";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "k8")) {
            capseq = "\0B";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "k9")) {
            capseq = "\0C";
            seql = 2;
        } else if (!zcmp(seq + 1, USTR "k0")) {
            capseq = "\0D";
            seql = 2;
        }
        seq[x] = c;
        if (seql) {
            for (seq += x; *seq == ' '; ++seq) ;
        }
#else
        s = jgetstr(cap, seq + 1);
        seq[x] = c;
        if (s && (s = tcompile(cap, s, 0, 0, 0, 0))
                && (sLEN(s) > 1 || (signed char)s[0] < 0)) {
            capseq = s;
            seql = sLEN(s);
            for (seq += x; *seq == ' '; ++seq) ;
        }
#endif
        else {
            *err = -2;
            return kmap;
        }
    }

    if (seql) {
        v = w = (unsigned char) *capseq++;
        --seql;
    } else {
        seq = range(seq, &v, &w);
        if (!seq) {
            *err = -1;
            return kmap;
        }
    }

    if (!kmap)
        kmap = mkkmap();	/* Create new keymap if 'kmap' was NULL */

    /* Make bindings between v and w */
    while (v <= w) {
        if (*seq || seql) {
            if (kmap->keys[v].k == 0)
                kmap->keys[v].value.submap = NULL;
            kmap->keys[v].k = 1;
            kmap->keys[v].value.submap = kbuild(cap, kmap->keys[v].value.submap, seq, bind, err, capseq, seql);
            if (!kmap->keys[v].value.submap) {
                /* Error during recursion. Prevent crash later. */
                kmap->keys[v].k = 0;
            }
        } else {
            if (kmap->keys[v].k == 1)
                rmkmap(kmap->keys[v].value.submap);
            kmap->keys[v].k = 0;
            kmap->keys[v].value.bind =
                /* This bit of code sticks the key value in the macro */
                (v == w ? macstk(bind, v) : dupmacro(macstk(bind, v)));
        }
        ++v;
    }
    return kmap;
}
示例#23
0
文件: syntax.c 项目: hagenkaye/ne
uint32_t meta_color_single(unsigned char *s)
{
    if (!zcmp(s, USTR "inverse"))
    {
        return INVERSE;
    }
    else if (!zcmp(s, USTR "underline"))
    {
        return UNDERLINE;
    }
    else if (!zcmp(s, USTR "bold"))
    {
        return BOLD;
    }
    else if (!zcmp(s, USTR "blink"))
    {
        return BLINK;
    }
    else if (!zcmp(s, USTR "dim"))
    {
        return DIM;
    }

    /* ISO colors */
    else if (!zcmp(s, USTR "white"))
    {
        return FG_WHITE;
    }
    else if (!zcmp(s, USTR "cyan"))
    {
        return FG_CYAN;
    }
    else if (!zcmp(s, USTR "magenta"))
    {
        return FG_MAGENTA;
    }
    else if (!zcmp(s, USTR "blue"))
    {
        return FG_BLUE;
    }
    else if (!zcmp(s, USTR "yellow"))
    {
        return FG_YELLOW;
    }
    else if (!zcmp(s, USTR "green"))
    {
        return FG_GREEN;
    }
    else if (!zcmp(s, USTR "red"))
    {
        return FG_RED;
    }
    else if (!zcmp(s, USTR "black"))
    {
        return FG_BLACK;
    }
    else if (!zcmp(s, USTR "bg_white"))
    {
        return BG_WHITE;
    }
    else if (!zcmp(s, USTR "bg_cyan"))
    {
        return BG_CYAN;
    }
    else if (!zcmp(s, USTR "bg_magenta"))
    {
        return BG_MAGENTA;
    }
    else if (!zcmp(s, USTR "bg_blue"))
    {
        return BG_BLUE;
    }
    else if (!zcmp(s, USTR "bg_yellow"))
    {
        return BG_YELLOW;
    }
    else if (!zcmp(s, USTR "bg_green"))
    {
        return BG_GREEN;
    }
    else if (!zcmp(s, USTR "bg_red"))
    {
        return BG_RED;
    }
    else if (!zcmp(s, USTR "bg_black"))
    {
        return BG_BLACK;
    }

    /* 16 color xterm support: codes 8 - 15 are brighter versions of above */
    else if (!zcmp(s, USTR "WHITE"))
    {
        return FG_BWHITE;
    }
    else if (!zcmp(s, USTR "CYAN"))
    {
        return FG_BCYAN;
    }
    else if (!zcmp(s, USTR "MAGENTA"))
    {
        return FG_BMAGENTA;
    }
    else if (!zcmp(s, USTR "BLUE"))
    {
        return FG_BBLUE;
    }
    else if (!zcmp(s, USTR "YELLOW"))
    {
        return FG_BYELLOW;
    }
    else if (!zcmp(s, USTR "GREEN"))
    {
        return FG_BGREEN;
    }
    else if (!zcmp(s, USTR "RED"))
    {
        return FG_BRED;
    }
    else if (!zcmp(s, USTR "BLACK"))
    {
        return FG_BBLACK;
    }
    else if (!zcmp(s, USTR "bg_WHITE"))
    {
        return BG_BWHITE;
    }
    else if (!zcmp(s, USTR "bg_CYAN"))
    {
        return BG_BCYAN;
    }
    else if (!zcmp(s, USTR "bg_MAGENTA"))
    {
        return BG_BMAGENTA;
    }
    else if (!zcmp(s, USTR "bg_BLUE"))
    {
        return BG_BBLUE;
    }
    else if (!zcmp(s, USTR "bg_YELLOW"))
    {
        return BG_BYELLOW;
    }
    else if (!zcmp(s, USTR "bg_GREEN"))
    {
        return BG_BGREEN;
    }
    else if (!zcmp(s, USTR "bg_RED"))
    {
        return BG_BRED;
    }
    else if (!zcmp(s, USTR "bg_BLACK"))
    {
        return BG_BBLACK;
    }

    /*  Look at the "256colres.pl" PERL script in the xterm source
        distribution to see how these work. */

    /* 256 color xterm support: bg_RGB and fg_RGB, where R, G, and B range from 0 - 5 */
    /* Codes 16 - 231 are a 6x6x6 color cube */
    else if (s[0] == 'f' && s[1] == 'g' && s[2] == '_' &&
             s[3] >= '0' && s[3] <= '5' &&
             s[4] >= '0' && s[4] <= '5' &&
             s[5] >= '0' && s[5] <= '5' && !s[6])
    {
        return FG_NOT_DEFAULT | ((16 + (s[3] - '0') * 6 * 6 + (s[4] - '0') * 6 + (s[5] - '0')) << FG_SHIFT);
    }

    else if (s[0] == 'b' && s[1] == 'g' && s[2] == '_' &&
             s[3] >= '0' && s[3] <= '5' &&
             s[4] >= '0' && s[4] <= '5' &&
             s[5] >= '0' && s[5] <= '5' && !s[6])
    {
        return BG_NOT_DEFAULT | ((16 + (s[3] - '0') * 6 * 6 + (s[4] - '0') * 6 + (s[5] - '0')) << BG_SHIFT);
    }

    /* 256 color xterm support: shades of grey */
    /* Codes 232 - 255 are shades of grey */
    else if (s[0] == 'f' && s[1] == 'g' && s[2] == '_' && atoi((char *)(s + 3)) >= 0 && atoi((char *)(s + 3)) <= 23)
    {
        return FG_NOT_DEFAULT | (232 + (atoi((char *)(s + 3)) << FG_SHIFT));
    }

    else if (s[0] == 'b' && s[1] == 'g' && s[2] == '_' && atoi((char *)(s + 3)) >= 0 && atoi((char *)(s + 3)) <= 23)
    {
        return BG_NOT_DEFAULT | (232 + (atoi((char *)(s + 3)) << BG_SHIFT));
    }

    else
    {
        return 0;
    }
}
示例#24
0
文件: syntax.c 项目: hagenkaye/ne
HIGHLIGHT_STATE parse(struct high_syntax *const syntax, line_desc *const ld, HIGHLIGHT_STATE h_state, const bool utf8)
{
    struct high_frame *stack = h_state.stack;

    struct high_state *h = (stack ? stack->syntax : syntax)->states[h_state.state];

    /* Current state */

    unsigned char buf[24];          /* Name buffer (trunc after 23 characters) */
    unsigned char lbuf[24];         /* Lower case version of name buffer */
    unsigned char lsaved_s[24];     /* Lower case version of delimiter match buffer */
    int buf_idx = 0;            /* Index into buffer */
    int c;                  /* Current character */
    int c_len;              /* Character length in bytes */
    uint32_t *attr = attr_buf;
    uint32_t *attr_end = attr_buf + attr_size;
    int buf_en = 0;             /* Set for name buffering */
    int ofst = 0;               /* record offset after we've stopped buffering */
    int mark1 = 0;              /* offset to mark start from current pos */
    int mark2 = 0;              /* offset to mark end from current pos */
    int mark_en = 0;            /* set if marking */
    int recolor_delimiter_or_keyword;

    const unsigned char *p = (const unsigned char *)ld->line;
    unsigned char *q = (unsigned char *)(ld->line  + ld->line_len);

    buf[0] = 0;             /* Forgot this originally... took 5 months to fix! */


    /* Get next character */
    /* Una iterazione in più: aggiungo '\n' come ultimo carattere. */
    while (p <= q)    /* On the last itteration, process the virtual '\n' character. */
    {
        struct high_cmd *cmd;
        struct high_cmd *kw_cmd;
        int x;

        if (p == q)
        {
            c = '\n';
        }
        else
        {
            c = utf8 ? get_char((const char *)p, ENC_UTF8) : *p;
        }

        c_len = utf8 ? utf8seqlen(c) : 1;
        p += c_len;

        /* Hack so we can have UTF-8 characters without crashing */
        if (c < 0 || c > 255)
        {
            c = 0x1F;
        }

        /* Create or expand attribute array if necessary */
        if (attr == attr_end)
        {
            if (!attr_buf)
            {
                attr_size = 1024;
                attr_buf = joe_malloc(sizeof(int) * attr_size);
                attr = attr_buf;
            }
            else
            {
                attr_buf = joe_realloc(attr_buf, sizeof(int) * (attr_size * 2));
                attr = attr_buf + attr_size;
                attr_size *= 2;
            }
            attr_end = attr_buf + attr_size;
        }

        /* Advance to next attribute position (note attr[-1] below) */
        attr++;

        /* Loop while noeat */
        do
        {
            /* Color with current state */
            attr[-1] = h->color;

            /* Get command for this character */
            if (h->delim && c == h_state.saved_s[0] && h_state.saved_s[1] == 0)
            {
                cmd = h->delim;
            }
            else
            {
                cmd = h->cmd[c];
            }

            /* Lowerize strings for case-insensitive matching */
            if (cmd->ignore)
            {
                zcpy(lbuf, buf);
                lowerize(lbuf);
                if (cmd->delim)
                {
                    zcpy(lsaved_s, h_state.saved_s);
                    lowerize(lsaved_s);
                }
            }

            /* Check for delimiter or keyword matches */
            recolor_delimiter_or_keyword = 0;
            if (cmd->delim && (cmd->ignore ? !zcmp(lsaved_s, lbuf) : !zcmp(h_state.saved_s, buf)))
            {
                cmd = cmd->delim;
                recolor_delimiter_or_keyword = 1;
            }
            else if (cmd->keywords && (cmd->ignore ? (kw_cmd = htfind(cmd->keywords, lbuf)) : (kw_cmd = htfind(cmd->keywords, buf))))
            {
                cmd = kw_cmd;
                recolor_delimiter_or_keyword = 1;
            }

            /* Determine new state */
            if (cmd->call)
            {
                /* Call */
                struct high_frame **frame_ptr = stack ? &stack->child : &syntax->stack_base;
                /* Search for an existing stack frame for this call */
                while (*frame_ptr && !((*frame_ptr)->syntax == cmd->call && (*frame_ptr)->return_state == cmd->new_state))
                {
                    frame_ptr = &(*frame_ptr)->sibling;
                }
                if (*frame_ptr)
                {
                    stack = *frame_ptr;
                }
                else
                {
                    struct high_frame *frame = joe_malloc(sizeof(struct high_frame));
                    frame->parent = stack;
                    frame->child = 0;
                    frame->sibling = 0;
                    frame->syntax = cmd->call;
                    frame->return_state = cmd->new_state;
                    *frame_ptr = frame;
                    stack = frame;
                    ++stack_count;
                }
                h = stack->syntax->states[0];
            }
            else if (cmd->rtn)
            {
                /* Return */
                if (stack)
                {
                    h = stack->return_state;
                    stack = stack->parent;
                }
                else
                    /* Not in a subroutine, so ignore the return */
                {
                    h = cmd->new_state;
                }
            }
            else if (cmd->reset)
            {
                /* Reset the state and call stack */
                h = syntax->states[0];
                stack = syntax->stack_base;
            }
            else
            {
                /* Normal edge */
                h = cmd->new_state;
            }

            /* Recolor if necessary */
            if (recolor_delimiter_or_keyword)
                for (x = -(buf_idx + 1); x < -1; ++x)
                {
                    attr[x - ofst] = h->color;
                }
            for (x = cmd->recolor; x < 0; ++x)
                if (attr + x >= attr_buf)
                {
                    attr[x] = h->color;
                }

            /* Mark recoloring */
            if (cmd->recolor_mark)
                for (x = -mark1; x < -mark2; ++x)
                {
                    attr[x] = h->color;
                }

            /* Save string? */
            if (cmd->save_s)
            {
                zcpy(h_state.saved_s, buf);
            }

            /* Save character? */
            if (cmd->save_c)
            {
                h_state.saved_s[1] = 0;
                if (c == '<')
                {
                    h_state.saved_s[0] = '>';
                }
                else if (c == '(')
                {
                    h_state.saved_s[0] = ')';
                }
                else if (c == '[')
                {
                    h_state.saved_s[0] = ']';
                }
                else if (c == '{')
                {
                    h_state.saved_s[0] = '}';
                }
                else if (c == '`')
                {
                    h_state.saved_s[0] = '\'';
                }
                else
                {
                    h_state.saved_s[0] = c;
                }
            }

            /* Start buffering? */
            if (cmd->start_buffering)
            {
                buf_idx = 0;
                buf_en = 1;
                ofst = 0;
            }

            /* Stop buffering? */
            if (cmd->stop_buffering)
            {
                buf_en = 0;
            }

            /* Set mark begin? */
            if (cmd->start_mark)
            {
                mark2 = 1;
                mark1 = 1;
                mark_en = 1;
            }

            /* Set mark end? */
            if (cmd->stop_mark)
            {
                mark_en = 0;
                mark2 = 1;
            }
        }
        while (cmd->noeat);

        /* Save character in buffer */
        if (buf_idx < 23 && buf_en)
        {
            buf[buf_idx++] = c;
        }
        if (!buf_en)
        {
            ++ofst;
        }
        buf[buf_idx] = 0;

        /* Update mark pointers */
        ++mark1;
        if (!mark_en)
        {
            ++mark2;
        }

        /*  if(c=='\n')
            break;*/
    }
    /* Return new state */
    h_state.stack = stack;
    h_state.state = h->no;
    attr_len = attr - attr_buf - 1; /* -1 because of the fake newline. */
    return h_state;
}
示例#25
0
文件: kbd.c 项目: jhallen/joe-editor
static int keyval(unsigned char *s)
{
    if (s[0] == '^' && s[1] && !s[2])
        switch (s[1])
        {
        case '?':
            return 127;
        case '#':
            return 0x9B;
        default:
            return s[1] & 0x1F;
        }
    else if ((s[0] == 'S' || s[0] == 's')
             && (s[1] == 'P' || s[1] == 'p') && !s[2])
        return ' ';
    else if((s[0]=='M'||s[0]=='m') && s[1]) {
        if(!zcmp(s,USTR "MDOWN")) return KEY_MDOWN;
        else if(!zcmp(s,USTR "MWDOWN")) return KEY_MWDOWN;
        else if(!zcmp(s,USTR "MWUP")) return KEY_MWUP;
        else if(!zcmp(s,USTR "MUP")) return KEY_MUP;
        else if(!zcmp(s,USTR "MDRAG")) return KEY_MDRAG;
        else if(!zcmp(s,USTR "M2DOWN")) return KEY_M2DOWN;
        else if(!zcmp(s,USTR "M2UP")) return KEY_M2UP;
        else if(!zcmp(s,USTR "M2DRAG")) return KEY_M2DRAG;
        else if(!zcmp(s,USTR "M3DOWN")) return KEY_M3DOWN;
        else if(!zcmp(s,USTR "M3UP")) return KEY_M3UP;
        else if(!zcmp(s,USTR "M3DRAG")) return KEY_M3DRAG;
        else return s[0];
    } else if (s[1] || !s[0])
        return -1;
    else
        return (unsigned char) s[0];
}
示例#26
0
int main(int argc, char **real_argv, char **envv)
{
	CAP *cap;
	unsigned char **argv = (unsigned char **)real_argv;
	struct stat sbuf;
	unsigned char *s;
	unsigned char *t;
	long time_rc;
	unsigned char *run;
#ifdef __MSDOS__
	unsigned char *rundir;
#endif
	SCRN *n;
	int opened = 0;
	int omid;
	int backopt;
	int c;

	init_bufs();

	for (c = 1; argv[c] != NULL; ++c) {
		if (0 == zcmp((unsigned char*)argv[c], USTR "-nosys")) {
			read_sys_configs = 0;
		} else if (0 == zcmp((unsigned char*)argv[c], USTR "-nouser")) {
			read_user_configs = 0;
		} else {
			argv[--c] = argv[0];
			argv += c;
			argc -= c;
			break;
		}
	}

	if (read_user_configs) {
		s = (unsigned char *)getenv("HOME");
		if (s) {
			s = vsncpy(NULL, 0, sz(s));
			s = vsncpy(sv(s), sc("/.joe-p37/only.rc"));
			if (!stat((char*)s, &sbuf)) read_sys_configs = 0;
			vsrm(s);
		}
	}

	joe_locale();

	mainenv = (unsigned char **)envv;

#ifdef __MSDOS__
	_fmode = O_BINARY;
	zcpy(stdbuf, argv[0]);
	joesep(stdbuf);
	run = namprt(stdbuf);
	rundir = dirprt(stdbuf);
	for (c = 0; run[c]; ++c)
		if (run[c] == '.') {
			run = vstrunc(run, c);
			break;
		}
#else
	run = namprt(argv[0]);
#endif

	env_lines = 0;
	if ((s = (unsigned char *)getenv("LINES")) != NULL &&
	    sscanf((char *)s, "%d", &env_lines) != 1)
		env_lines = 0;
	env_columns = 0;
	if ((s = (unsigned char *)getenv("COLUMNS")) != NULL &&
	    sscanf((char *)s, "%d", &env_columns) != 1)
		env_columns = 0;
	if ((s = (unsigned char *)getenv("BAUD")) != NULL)
		sscanf((char *)s, "%u", (unsigned *)&Baud);
	if (getenv("DOPADDING"))
		dopadding = 1;
	if (getenv("NOXON"))
		noxon = 1;
	if ((s = (unsigned char *)getenv("JOETERM")) != NULL)
		joeterm = s;

#ifndef __MSDOS__
	if (!(cap = my_getcap(NULL, 9600, NULL, NULL))) {
		fprintf(stderr, (char *)joe_gettext(_("Couldn't load termcap/terminfo entry\n")));
		return 1;
	}
#endif

#ifdef __MSDOS__

	s = vsncpy(NULL, 0, sv(run));
	s = vsncpy(sv(s), sc("rc"));
	c = procrc(cap, s);
	if (c == 0)
		goto donerc;
	if (c == 1) {
		unsigned char buf[8];

		fprintf(stderr, (char *)joe_gettext(_("There were errors in '%s'.  Use it anyway?")), s);
		fflush(stderr);
		if (NULL == fgets(buf, 8, stdin) || yn_checks(yes_key, buf))
			goto donerc;
	}

	vsrm(s);
	s = vsncpy(NULL, 0, sv(rundir));
	s = vsncpy(sv(s), sv(run));
	s = vsncpy(sv(s), sc("rc"));
	c = procrc(cap, s);
	if (c != 0 && c != 1) {
		/* If built-in *fancyjoerc not present, process builtin *joerc,
		 * which is always present.
		 */
		s = vstrunc(s, 0);
		s = vsncpy(sv(s), sc("*joerc"));
		c = procrc(cap, s);
	}
	if (c == 0)
		goto donerc;
	if (c == 1) {
		unsigned char buf[8];

		fprintf(stderr, (char *)joe_gettext(_("There were errors in '%s'.  Use it anyway?")), s);
		fflush(stderr);
		if (NULL == fgets(buf, 8, stdin) || yn_checks(yes_key, buf))
			goto donerc;
	}
#else

	/* Name of system joerc file.  Try to find one with matching language... */
	
	/* Try full language: like joerc.de_DE */
	time_rc = 0;
        if (!read_sys_configs) { t = NULL; goto skip_joerc; }
        t = vsncpy(NULL, 0, sc(JOERC));
	t = vsncpy(sv(t), sv(run));
	t = vsncpy(sv(t), sc("rc."));
	t = vsncpy(sv(t), sz(locale_msgs));
	if (!stat((char *)t,&sbuf))
		time_rc = sbuf.st_mtime;
	else {
		/* Try generic language: like joerc.de */
		if (locale_msgs[0] && locale_msgs[1] && locale_msgs[2]=='_') {
			vsrm(t);
			t = vsncpy(NULL, 0, sc(JOERC));
			t = vsncpy(sv(t), sv(run));
			t = vsncpy(sv(t), sc("rc."));
			t = vsncpy(sv(t), locale_msgs, 2);
			if (!stat((char *)t,&sbuf))
				time_rc = sbuf.st_mtime;
			else
				goto nope;
		} else {
			nope:
			vsrm(t);
			/* Try Joe's bad english */
			t = vsncpy(NULL, 0, sc(JOERC));
			t = vsncpy(sv(t), sv(run));
			t = vsncpy(sv(t), sc("rc"));
			if (!stat((char *)t,&sbuf))
				time_rc = sbuf.st_mtime;
			else {
				/* If built-in *fancyjoerc not present, process builtin *joerc,
				 * which is always present.
				 */
				t = vstrunc(s, 0);
				t = vsncpy(sv(s), sc("*joerc"));
				time_rc = stat((char *)t,&sbuf) ? 0 : sbuf.st_mtime;
			}
		}
	}
	skip_joerc:

	/* User's joerc file */
	s = (unsigned char *)getenv("HOME");
	if (s && !read_sys_configs) {
		if (read_user_configs) {  /* TODO(pts): Don't read /dev/null */
			s = vsncpy(NULL, 0, sz(s));
			s = vsncpy(sv(s), sc("/.joe-p37/rc"));
		} else {
			s = vsncpy(NULL, 0, sc("/dev/null/missing"));
		}
		goto process_user_rc;
	} else if (!read_user_configs) {
		s = vsncpy(NULL, 0, sc("/dev/null/missing"));
		goto process_user_rc;
	} else if (s) {
		unsigned char buf[8];

		s = vsncpy(NULL, 0, sz(s));
		s = vsncpy(sv(s), sc("/."));
		s = vsncpy(sv(s), sv(run));
		s = vsncpy(sv(s), sc("rc"));

		if (!stat((char *)s,&sbuf)) {
			if (sbuf.st_mtime < time_rc) {
				fprintf(stderr,(char *)joe_gettext(_("Warning: %s is newer than your %s.\n")),t,s);
				fprintf(stderr,(char *)joe_gettext(_("You should update or delete %s\n")),s);
				fprintf(stderr,(char *)joe_gettext(_("Hit enter to continue with %s ")),t);
				fflush(stderr);
				(void)!fgets((char *)buf, 8, stdin);
				goto use_sys;
			}
		}

	      process_user_rc:
		c = procrc(cap, s);
		if (c == 0) {
			vsrm(t);
			goto donerc;
		}
		if (c == 1) {
			fprintf(stderr,(char *)joe_gettext(_("There were errors in '%s'.  Use it anyway (y,n)? ")), s);
			fflush(stderr);
			if (NULL == fgets((char *)buf, 8, stdin) || ynchecks(yes_key, buf)) {
				vsrm(t);
				goto donerc;
			}
		}
	}

	use_sys:
	vsrm(s);
	s = t;
	c = s ? procrc(cap, s) : -1;
	if (c == 0)
		goto donerc;
	if (c == 1) {
		unsigned char buf[8];

		fprintf(stderr,(char *)joe_gettext(_("There were errors in '%s'.  Use it anyway (y,n)? ")), s);
		fflush(stderr);
		if (NULL == fgets((char *)buf, 8, stdin) || ynchecks(yes_key, buf))
			goto donerc;
	}

	/* Try built-in *fancyjoerc, e.g. "*joe-p37rc" */
	vsrm(s);
	s = vsncpy(NULL, 0, sc("*"));
	s = vsncpy(sv(s), sv(run));
	s = vsncpy(sv(s), sc("rc"));
	c = procrc(cap, s);
	if (c != 0 && c != 1) {
		/* If built-in *fancyjoerc not present, process builtin "*joerc",
		 * which is always present.
		 */
		s = vstrunc(s, 0);
		s = vsncpy(sv(s), sc("*joerc"));
		c = procrc(cap, s);
	}
	if (c == 0)
		goto donerc;
	if (c == 1) {
		unsigned char buf[8];

		fprintf(stderr,(char *)joe_gettext(_("There were errors in '%s'.  Use it anyway (y,n)? ")), s);
		fflush(stderr);
		if (NULL == fgets((char *)buf, 8, stdin) || ynchecks(yes_key, buf))
			goto donerc;
	}
#endif

	fprintf(stderr,(char *)joe_gettext(_("Couldn't open '%s'\n")), s);
	vsrm(s);
	return 1;

	donerc:
	vsrm(s);

	if (validate_rc()) {
		fprintf(stderr,(char *)joe_gettext(_("rc file has no :main key binding section or no bindings.  Bye.\n")));
		return 1;
	}


	if (!isatty(fileno(stdin)))
		idleout = 0;

	for (c = 1; argv[c]; ++c) {
		if (argv[c][0] == '-') {
			if (argv[c][1])
				switch (glopt(argv[c] + 1, argv[c + 1], NULL, 1)) {
				case 0:
					fprintf(stderr,(char *)joe_gettext(_("Unknown option '%s'\n")), argv[c]);
					break;
				case 1:
					break;
				case 2:
					++c;
					break;
			} else
				idleout = 0;
		}
	}
	if (!dspasis) {  /* Open all files as ASCII by default if `joe --asis' is specified. This is to avoid writing control characters to the UTF-8 terminal. */
		fdefault.charmap = pdefault.charmap = find_charmap(USTR "ascii");
		fdefault.map_name = pdefault.map_name = USTR "ascii";
	}


	/* initialize mouse support */
	if (xmouse && (s=(unsigned char *)getenv("TERM")) && strstr((char *)s,"xterm"))
		usexmouse=1;

	if (!(n = nopen(cap)))
		return 1;
	maint = screate(n);
	vmem = vtmp();

	startup_log = bfind_scratch_incref(USTR "* Startup Log *");
	startup_log->internal = 1;

	load_state();

	/* It would be better if this ran uedit() to load files */

	/* The business with backopt is to load the file first, then apply file
	 * local options afterwords */

	/* orphan is not compatible with exemac()- macros need a window to exist */
	for (c = 1, backopt = 0; argv[c]; ++c)
		if (argv[c][0] == '+' && argv[c][1]>='0' && argv[c][1]<='9') {
			if (!backopt)
				backopt = c;
		} else if (argv[c][0] == '-' && argv[c][1]) {
			if (!backopt)
				backopt = c;
			if (glopt(argv[c] + 1, argv[c + 1], NULL, 0) == 2)
				++c;
		} else {
			B *b = bfind_incref(argv[c]);
			BW *bw = NULL;
			int er = berror;

			/* This is too annoying */
			/* set_current_dir(argv[c],1); */

			setup_history(&filehist);
			append_history(filehist,sz(argv[c]));

			/* wmktw_takeref() inserts the window before maint->curwin */
			if (!orphan || !opened) {
				bw = wmktw_takeref(maint, b);
				if (er)
					msgnwt(bw->parent, joe_gettext(msgs[-er]));
			} else {
				long line;
				b->orphan = 1;
				b->oldcur = pdup(b->bof, USTR "main");
				pline(b->oldcur, get_file_pos(b->name));
				line = b->oldcur->line - (maint->h - 1) / 2;
				if (line < 0)
					line = 0;
				b->oldtop = pdup(b->oldcur, USTR "main");
				pline(b->oldtop, line);
				p_goto_bol(b->oldtop);
			}
			if (bw) {
				long lnum = 0;

				bw->o.readonly = bw->b->rdonly;
				if (backopt) {
					while (backopt != c) {
						if (argv[backopt][0] == '+') {
							sscanf((char *)(argv[backopt] + 1), "%ld", &lnum);
							++backopt;
						} else {
							if (glopt(argv[backopt] + 1, argv[backopt + 1], &bw->o, 0) == 2)
								backopt += 2;
							else
								backopt += 1;
							lazy_opts(bw->b, &bw->o);
						}
					}
				}
				bw->b->o = bw->o;
				bw->b->rdonly = bw->o.readonly;
				/* Put cursor in window, so macros work properly */
				maint->curwin = bw->parent;
				/* Execute macro */
				if (er == -1 && bw->o.mnew)
					exmacro(bw->o.mnew,1);
				if (er == 0 && bw->o.mold)
					exmacro(bw->o.mold,1);
				/* Hmm... window might not exist any more... depends on what macro does... */
				if (lnum > 0)
					pline(bw->cursor, lnum - 1);
				else
					pline(bw->cursor, get_file_pos(bw->b->name));
				p_goto_bol(bw->cursor);
				/* Go back to first window so windows are in same order as command line  */
				if (opened)
					wnext(maint);
				
			}
			opened = 1;
			backopt = 0;
		}

	

	if (opened) {
		wshowall(maint);
		omid = mid;
		mid = 1;
		dofollows();
		mid = omid;
	} else {
		BW *bw = wmktw_takeref(maint, bfind_incref(USTR ""));

		if (bw->o.mnew)
			exmacro(bw->o.mnew,1);
	}
	maint->curwin = maint->topwin;

	if (startup_log->eof->byte) {
		BW *bw = wmktw_takeref(maint, startup_log);
		startup_log = NULL;
		maint->curwin = bw->parent;
		wshowall(maint);
		uparserr(bw);
	}

	if (help) {
		help_on(maint);
	}
	if (!nonotice) {
		joe_snprintf_3(msgbuf,JOE_MSGBUFSIZE,joe_gettext(_("\\i** Joe's Own Editor v%s ** (%s) ** Copyright %s 2008 **\\i")),VERSION,locale_map->name,(locale_map->type ? "©" : "(C)"));

		msgnw(((BASE *)lastw(maint)->object)->parent, msgbuf);
	}

	if (!idleout) {
		if (!isatty(fileno(stdin)) && modify_logic(maint->curwin->object, ((BW *)maint->curwin->object)->b)) {
			/* Start shell going in first window */
			unsigned char **a;
			unsigned char *cmd;

			a = vamk(10);
			cmd = vsncpy(NULL, 0, sc("/bin/sh"));
			a = vaadd(a, cmd);
			cmd = vsncpy(NULL, 0, sc("-c"));
			a = vaadd(a, cmd);
			cmd = vsncpy(NULL, 0, sc("/bin/cat"));
			a = vaadd(a, cmd);
			
			cstart (maint->curwin->object, USTR "/bin/sh", a, NULL, NULL, 0, 1);
		}
	}

	edloop(0);

	save_state();

	/* Delete all buffer so left over locks get eliminated */
	brmall();

	vclose(vmem);
	nclose(n);

	if (exmsg)
		fprintf(stderr, "\n%s\n", exmsg);
	return 0;
}