Exemple #1
0
static void msg(gender_s gender, char* result, const char* text_male, const char* text_female, const char* text_pluar) {
	if(gender == Female) {
		if(text_female)
			zcpy(result, text_female);
	} else {
		if(text_male)
			zcpy(result, text_male);
	}
}
Exemple #2
0
static unsigned char *getpty(int *ptyfd)
{
	int x, fd;
	unsigned char *orgpwd = pwd();
	static unsigned char **ptys = NULL;
	static unsigned char *ttydir;
	static unsigned char *ptydir;
	static unsigned char ttyname[32];

	if (!ptys) {
		ttydir = USTR "/dev/pty/";
		ptydir = USTR "/dev/ptym/";	/* HPUX systems */
		if (chpwd(ptydir) || !(ptys = rexpnd(USTR "pty*")))
			if (!ptys) {
				ttydir = ptydir = USTR "/dev/";	/* Everyone else */
				if (!chpwd(ptydir))
					ptys = rexpnd(USTR "pty*");
			}
	}
	chpwd(orgpwd);

	if (ptys)
		for (fd = 0; ptys[fd]; ++fd) {
			zcpy(ttyname, ptydir);
			zcat(ttyname, ptys[fd]);
			if ((*ptyfd = open((char *)ttyname, O_RDWR)) >= 0) {
				ptys[fd][0] = 't';
				zcpy(ttyname, ttydir);
				zcat(ttyname, ptys[fd]);
				ptys[fd][0] = 'p';
				x = open((char *)ttyname, O_RDWR);
				if (x >= 0) {
					close(x);
					close(*ptyfd);
					zcpy(ttyname, ptydir);
					zcat(ttyname, ptys[fd]);
					*ptyfd = open((char *)ttyname, O_RDWR);
					ptys[fd][0] = 't';
					zcpy(ttyname, ttydir);
					zcat(ttyname, ptys[fd]);
					ptys[fd][0] = 'p';
					return ttyname;
				} else
					close(*ptyfd);
			}
		}
	return NULL;
}
Exemple #3
0
/**** message which is shown after closing joe (CTRL+x; CTRL+k) *****/
void genexmsg(BW *bw, int saved, char *name)
{
	const char *s;

	if (bw->b->name && bw->b->name[0]) {
		s = bw->b->name;
	} else {
		s = joe_gettext(_("(Unnamed)"));
	}

	if (name) {
		if (saved) {
			joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s saved")), name);
		} else {
			joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s not saved")), name);
		}
	} else if (bw->b->changed && bw->b->count == 1) {
		joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s not saved")), s);
	} else if (saved) {
		joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s saved")), s);
	} else {
		joe_snprintf_1(msgbuf, JOE_MSGBUFSIZE, joe_gettext(_("File %s not changed so no update needed")), s);
	}
	if (exmsg)
		vsrm(exmsg);

	exmsg = vsncpy(NULL,0,sz(msgbuf));
	if (!noexmsg) {
		/* duplicate backslashes in file names because msgnw interprets escape sequences */
		char *t = duplicate_backslashes(sz(msgbuf));
		zcpy(msgbuf, t);
		vsrm(t);
		msgnw(bw->parent, msgbuf);
	}
}
Exemple #4
0
int help_init(JFILE *fd,unsigned char *bf,int line)
{
	unsigned char buf[1024];			/* input buffer */

	struct help *tmp;
	unsigned int bfl;				/* buffer length */
	unsigned int hlpsiz, hlpbsz;			/* number of used/allocated bytes for tmp->text */
	unsigned char *tempbuf;

	if (bf[0] == '{') {			/* start of help screen */
		tmp = (struct help *) joe_malloc(sizeof(struct help));

		tmp->text = NULL;
		tmp->lines = 0;
		hlpsiz = 0;
		hlpbsz = 0;
		tmp->name = vsncpy(NULL, 0, sz(bf + 1) - 1); /* -1 kill the \n */

		while ((jfgets(buf, sizeof(buf), fd)) && (buf[0] != '}')) {
			++line;
			bfl = zlen(buf);
			if (hlpsiz + bfl > hlpbsz) {
				if (tmp->text) {
					tempbuf = (unsigned char *) joe_realloc(tmp->text, hlpbsz + bfl + 1024);
					tmp->text = tempbuf;
				} else {
					tmp->text = (unsigned char *) joe_malloc(bfl + 1024);
					tmp->text[0] = 0;
				}
				hlpbsz += bfl + 1024;
			}
			zcpy(tmp->text + hlpsiz, buf);
			hlpsiz += bfl;
			++tmp->lines;
		}
		tmp->prev = help_ptr;
		tmp->next = NULL;
		if (help_ptr) {
			help_ptr->next = tmp;
		} else {
			help_actual = tmp;
		}
		help_ptr = tmp;
		if (buf[0] == '}') {		/* set new help screen as actual one */
			++line;
		} else {
			fprintf(stderr, (char *)joe_gettext(_("\n%d: EOF before end of help text\n")),line);
		}
	}
	return line;
}
Exemple #5
0
void logs::driver::parseidentifier(char* result, const char* result_max, const char* identifier) {
	if(strcmp(identifier, "герой") == 0)
		zcpy(result, name);
	else if(strcmp(identifier, "героя") == 0)
		grammar::of(result, name);
	else if(strcmp(identifier, "оппонент") == 0)
		zcpy(result, opponent_name);
	else if(strcmp(identifier, "оппонента") == 0)
		grammar::of(result, opponent_name);
	else if(strcmp(identifier, "ась") == 0)
		msg(gender, result, "ся", identifier, "ись");
	else if(strcmp(identifier, "а") == 0)
		msg(gender, result, "", identifier, "и");
	else if(strcmp(identifier, "А") == 0)
		msg(opponent_gender, result, "", "а", "и");
	else if(strcmp(identifier, "ла") == 0)
		msg(gender, result, "", identifier, "ли");
	else if(strcmp(identifier, "ЛА") == 0)
		msg(opponent_gender, result, "", "ла", "ли");
	else if(strcmp(identifier, "она") == 0)
		msg(gender, result, "он", identifier, "они");
	else if(strcmp(identifier, "ОНА") == 0)
		msg(opponent_gender, result, "он", "она", "они");
	else if(strcmp(identifier, "ее") == 0)
		msg(gender, result, "его", identifier, "их");
	else if(strcmp(identifier, "ЕЕ") == 0)
		msg(opponent_gender, result, "его", "ее", "их");
	else if(strcmp(identifier, "ей") == 0)
		msg(gender, result, "ему", identifier, "им");
	else if(strcmp(identifier, "нее") == 0)
		msg(gender, result, "него", identifier, "них");
	else {
		zcat(result, "[-");
		zcat(result, identifier);
		zcat(result, "]");
	}
}
Exemple #6
0
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);
        }
    }
}
Exemple #7
0
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;
}
Exemple #8
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;
}