Exemplo n.º 1
0
static void
editMsgLine(struct edit *edit)
{
	static int ck, havenewmail;
	if (!edit) {
		ck = 0;
		havenewmail = chkmail();
		return;
	}
	if (talkrequest) {
		talkreply();
		clear();
		edit->redrawall = 1;
	}
	if (++ck >= 10) {
		havenewmail = chkmail();
		ck = 0;
	}
	move(t_lines - 1, 0);
	prints("\033[1;33;44m【%s】",
	       havenewmail ? "\033[5;32m信\033[m\033[1;33;44m" : "  ");
	prints("【%s】",
	       have_msg_unread ? "\033[5;32mMSG\033[m\033[1;33;44m" : "   ");
	prints(" \033[31mCtrl-Q\033[33m 求救 ");
	prints
	    ("状态 [\033[32m%s\033[33m][\033[32m%d\033[33m,\033[32m%d\033[33m][\033[32m%s\033[33m][\033[32m%s\033[33m] ",
	     edit->overwrite ? "Rep" : "Ins", edit->line + 1,
	     edit->col + 1, "X", editview ? " " : "~");
	prints("时间\033[1;33;44m【\033[1;32m%16s\033[33m】     \033[m",
	       Ctime(now_t));
}
Exemplo n.º 2
0
void
cmdloop(int top)
{
	union node *n;
	struct stackmark smark;
	int inter;
	int numeof = 0;
	enum skipstate skip;

	TRACE(("cmdloop(%d) called\n", top));
	setstackmark(&smark);
	for (;;) {
		if (pendingsigs)
			dotrap();
		inter = 0;
		if (iflag == 1 && top) {
			inter = 1;
			showjobs(out2, SHOW_CHANGED);
			chkmail(0);
			flushout(&errout);
			nflag = 0;
		}
		n = parsecmd(inter);
		TRACE(("cmdloop: "); showtree(n));
		/* showtree(n); DEBUG */
		if (n == NEOF) {
			if (!top || numeof >= 50)
				break;
			if (nflag)
				break;
			if (!stoppedjobs()) {
				if (!iflag || !Iflag)
					break;
				out2str("\nUse \"exit\" to leave shell.\n");
			}
			numeof++;
		} else if (n != NULL && nflag == 0) {
			job_warning = (job_warning == 2) ? 1 : 0;
			numeof = 0;
			evaltree(n, EV_MORE);
		}
		popstackmark(&smark);
		setstackmark(&smark);

		/*
		 * Any SKIP* can occur here!  SKIP(FUNC|BREAK|CONT) occur when
		 * a dotcmd is in a loop or a function body and appropriate
		 * built-ins occurs in file scope in the sourced file.  Values
		 * other than SKIPFILE are reset by the appropriate eval*()
		 * that contained the dotcmd() call.
		 */
		skip = current_skipstate();
		if (skip != SKIPNONE) {
			if (skip == SKIPFILE)
				stop_skipping();
			break;
		}
	}
	popstackmark(&smark);
}
Exemplo n.º 3
0
Arquivo: chat.c Projeto: wyat/kbs
void call_mail(chatcontext * pthis, const char *arg)
{                               /* added by Luzi, 1997/12/22 */
    fileheader mailheader;
    FILE *fpin;
    char b2[STRLEN];
    char *t;
    char direct[PATHLEN];

    if (chkmail() == 0) {       /* check mail */
        printchatline(pthis, "\033[32m*** 没有新的信件 ***\033[m");
        return;
    }

    setmailfile(direct, getCurrentUser()->userid, DOT_DIR);
    fpin = fopen(direct, "rb");
    if (fpin == NULL)
        return;
    printchatline(pthis, "\033[32m【当前新的信件如下】\033[m");
    while (fread(&mailheader, sizeof(fileheader), 1, fpin)) {
        if ((mailheader.accessed[0] & FILE_READ) == 0) {
            strcpy(b2, mailheader.owner);
            if ((t = strchr(b2, ' ')) != NULL)
                *t = '\0';
            sprintf(genbuf, "\033[31m %-20.20s ★ %.46s \033[m", b2,
                    mailheader.title);
            printchatline(pthis, genbuf);
        }
    }
    fclose(fpin);
}
Exemplo n.º 4
0
Arquivo: var.c Projeto: 0xffea/MINIX3
void
setvareq(char *s, int flags)
{
	struct var *vp, **vpp;
	int len;

	if (aflag)
		flags |= VEXPORT;
	vpp = hashvar(s);
	for (vp = *vpp ; vp ; vp = vp->next) {
		if (varequal(s, vp->text)) {
			if (vp->flags & VREADONLY) {
				len = strchr(s, '=') - s;
				error("%.*s: is read only", len, s);
			}
			INTOFF;

			if (vp->func && (flags & VNOFUNC) == 0)
				(*vp->func)(strchr(s, '=') + 1);

			if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0)
				ckfree(vp->text);

			vp->flags &= ~(VTEXTFIXED|VSTACK|VUNSET);
			vp->flags |= flags;
			vp->text = s;

			/*
			 * We could roll this to a function, to handle it as
			 * a regular variable function callback, but why bother?
			 */
			if (vp == &vmpath || (vp == &vmail && ! mpathset()))
				chkmail(1);
			if ((vp->flags & VEXPORT) && localevar(s)) {
				putenv(s);
				(void) setlocale(LC_ALL, "");
			}
			INTON;
			return;
		}
	}
	/* not found */
	vp = ckmalloc(sizeof (*vp));
	vp->flags = flags;
	vp->text = s;
	vp->next = *vpp;
	vp->func = NULL;
	INTOFF;
	*vpp = vp;
	if ((vp->flags & VEXPORT) && localevar(s)) {
		putenv(s);
		(void) setlocale(LC_ALL, "");
	}
	INTON;
}
Exemplo n.º 5
0
static int
cmdloop(int top)
{
	union node *n;
	struct stackmark smark;
	int inter;
	int status = 0;
	int numeof = 0;

	TRACE(("cmdloop(%d) called\n", top));
#ifdef HETIO
	if(iflag && top)
		hetio_init();
#endif
	for (;;) {
		int skip;

		setstackmark(&smark);
		if (jobctl)
			showjobs(out2, SHOW_CHANGED);
		inter = 0;
		if (iflag && top) {
			inter++;
			chkmail();
		}
		n = parsecmd(inter);
		/* showtree(n); DEBUG */
		if (n == NEOF) {
			if (!top || numeof >= 50)
				break;
			if (!stoppedjobs()) {
				if (!Iflag)
					break;
				out2str("\nUse \"exit\" to leave shell.\n");
			}
			numeof++;
		} else if (nflag == 0) {
			job_warning = (job_warning == 2) ? 1 : 0;
			numeof = 0;
			evaltree(n, 0);
			status = exitstatus;
		}
		popstackmark(&smark);

		skip = evalskip;
		if (skip) {
			evalskip &= ~(SKIPFUNC | SKIPFUNCDEF);
			break;
		}
	}

	return status;
}
Exemplo n.º 6
0
Arquivo: var.c Projeto: dezelin/kBuild
void
setvareq(char *s, int flags)
{
	struct var *vp, **vpp;
	int nlen;

	if (aflag)
		flags |= VEXPORT;
	vp = find_var(s, &vpp, &nlen);
	if (vp != NULL) {
		if (vp->flags & VREADONLY)
			error("%.*s: is read only", vp->name_len, s);
		if (flags & VNOSET)
			return;
		INTOFF;

		if (vp->func && (flags & VNOFUNC) == 0)
			(*vp->func)(s + vp->name_len + 1);

		if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0)
			ckfree(vp->text);

		vp->flags &= ~(VTEXTFIXED|VSTACK|VUNSET);
		vp->flags |= flags & ~VNOFUNC;
		vp->text = s;
#ifdef PC_OS2_LIBPATHS
                if ((vp->flags & VOS2LIBPATH) && (vp->flags & VEXPORT))
                    vp->flags &= ~VEXPORT;
#endif

		/*
		 * We could roll this to a function, to handle it as
		 * a regular variable function callback, but why bother?
		 */
		if (vp == &vmpath || (vp == &vmail && ! mpathset()))
			chkmail(1);
		INTON;
		return;
	}
	/* not found */
	if (flags & VNOSET)
		return;
	vp = ckmalloc(sizeof (*vp));
	vp->flags = flags & ~VNOFUNC;
	vp->text = s;
	vp->name_len = nlen;
	vp->next = *vpp;
	vp->func = NULL;
	*vpp = vp;
}
Exemplo n.º 7
0
Arquivo: main.c Projeto: cbsd/cbsd
static void
cmdloop(int top)
{
	union node *n;
	struct stackmark smark;
	int inter;
	int numeof = 0;

	TRACE(("cmdloop(%d) called\n", top));
	setstackmark(&smark);
	for (;;) {
		if (pendingsig)
			dotrap();
		inter = 0;
		if (iflag && top) {
			inter++;
			showjobs(1, SHOWJOBS_DEFAULT);
#ifndef CBSD
			chkmail(0);
#endif
			flushout(&output);
		}
		n = parsecmd(inter);
		/* showtree(n); DEBUG */
		if (n == NEOF) {
			if (!top || numeof >= 50)
				break;
			if (!stoppedjobs()) {
				if (!Iflag)
					break;
				out2fmt_flush("\nUse \"exit\" to leave shell.\n");
			}
			numeof++;
		} else if (n != NULL && nflag == 0) {
			job_warning = (job_warning == 2) ? 1 : 0;
			numeof = 0;
			evaltree(n, 0);
		}
		popstackmark(&smark);
		setstackmark(&smark);
		if (evalskip != 0) {
			if (evalskip == SKIPRETURN)
				evalskip = 0;
			break;
		}
	}
	popstackmark(&smark);
}
Exemplo n.º 8
0
static int
backnumbertitle()
{

	if (chkmail())
		showtitle("阅读过刊", "[您有信件,请按 w 查看信件]");
	else
		showtitle("阅读过刊", MY_BBS_NAME);
	prints
	    ("离开[\033[1;32m←\033[m,\033[1;32me\033[m]  选择[\033[1;32m↑\033[m,\033[1;32m↓\033[m]  阅读"
	     "[\033[1;32m→\033[m,\033[1;32mRtn\033[m] 求助[\033[1;32mh\033[m]\033[m\n");
	prints("\033[1;44m编号   %-12s %6s  %-50s\033[m\n", "刊登者", "日期",
	       "标题");
	clrtobot();
	return 0;
}
Exemplo n.º 9
0
void
cmdloop(struct shinstance *psh, int top)
{
	union node *n;
	struct stackmark smark;
	int inter;
	int numeof = 0;

	TRACE((psh, "cmdloop(%d) called\n", top));
	setstackmark(psh, &smark);
	for (;;) {
		if (psh->pendingsigs)
			dotrap(psh);
		inter = 0;
		if (iflag(psh) && top) {
			inter = 1;
			showjobs(psh, psh->out2, SHOW_CHANGED);
			chkmail(psh, 0);
			flushout(&psh->errout);
		}
		n = parsecmd(psh, inter);
		/* showtree(n); DEBUG */
		if (n == NEOF) {
			if (!top || numeof >= 50)
				break;
			if (!stoppedjobs(psh)) {
				if (!Iflag(psh))
					break;
				out2str(psh, "\nUse \"exit\" to leave shell.\n");
			}
			numeof++;
		} else if (n != NULL && nflag(psh) == 0) {
			psh->job_warning = (psh->job_warning == 2) ? 1 : 0;
			numeof = 0;
			evaltree(psh, n, 0);
		}
		popstackmark(psh, &smark);
		setstackmark(psh, &smark);
		if (psh->evalskip == SKIPFILE) {
			psh->evalskip = 0;
			break;
		}
	}
	popstackmark(psh, &smark);
}
Exemplo n.º 10
0
void
cmdloop(int top)
{
	union node *n;
	struct stackmark smark;
	int inter;
	int numeof = 0;

	TRACE(("cmdloop(%d) called\n", top));
	setstackmark(&smark);
	for (;;) {
		if (pendingsigs)
			dotrap();
		inter = 0;
		if (iflag && top) {
			inter = 1;
			showjobs(out2, SHOW_CHANGED);
			chkmail(0);
			flushout(&errout);
		}
		n = parsecmd(inter);
		/* showtree(n); DEBUG */
		if (n == NEOF) {
			if (!top || numeof >= 50)
				break;
			if (!stoppedjobs()) {
				if (!Iflag)
					break;
				out2str("\nUse \"exit\" to leave shell.\n");
			}
			numeof++;
		} else if (n != NULL && nflag == 0) {
			job_warning = (job_warning == 2) ? 1 : 0;
			numeof = 0;
			evaltree(n, 0);
		}
		popstackmark(&smark);
		setstackmark(&smark);
		if (evalskip == SKIPFILE) {
			evalskip = 0;
			break;
		}
	}
	popstackmark(&smark);
}
Exemplo n.º 11
0
void firsttitle(const char *title)
{
	extern int mailXX; //main.c
	extern char BoardName[]; //main.c
	char middoc[30];

	if (chkmail())
		//% strcpy(middoc, strstr(title, "讨论区列表") ? "[您有信件,按 M 看新信]"
		strcpy(middoc, strstr(title, "\xcc\xd6\xc2\xdb\xc7\xf8\xc1\xd0\xb1\xed") ? "[\xc4\xfa\xd3\xd0\xd0\xc5\xbc\xfe\xa3\xac\xb0\xb4 M \xbf\xb4\xd0\xc2\xd0\xc5]"
				//% : "[您有信件]");
				: "[\xc4\xfa\xd3\xd0\xd0\xc5\xbc\xfe]");
	else if (mailXX == 1)
		//% strcpy(middoc, "[信件过量,请整理信件!]");
		strcpy(middoc, "[\xd0\xc5\xbc\xfe\xb9\xfd\xc1\xbf\xa3\xac\xc7\xeb\xd5\xfb\xc0\xed\xd0\xc5\xbc\xfe!]");
	else
		strlcpy(middoc, BoardName, sizeof(middoc));

	showtitle(title, middoc);
}
Exemplo n.º 12
0
static void show_status_line(const editor_t *editor)
{
	screen_move_clear(-1);
	if (editor->hide_status_line)
		return;

	bool mail = chkmail();

	vector_size_t x;
	text_line_size_t y;
	real_pos(editor, &x, &y);

	screen_printf("\033[1;33;44m[%s] [\033[32m%s\033[33m]"
			" [\033[32m按\033[31mCtrl-Q\033[32m求救\033[33m]"
			" [\033[32m%d\033[33m,\033[32m%d\033[33m]\033[K\033[m",
			mail ? "\033[5;32m信\033[m\033[1;33;44m" : "  ",
			format_time(fb_time(), TIME_FORMAT_UTF8_ZH) + 7,
			x, y);
}
Exemplo n.º 13
0
Arquivo: tui.c Projeto: fbbs/fbbs
void tui_header_line(const char *menu, bool check_mail)
{
	extern int mailXX; //main.c
	char title[36];

	if (check_mail && chkmail())
		strlcpy(title, strstr(menu, "讨论区列表") ? "[您有信件,按 M 看新信]"
				: "[您有信件]", sizeof(title));
	else if (check_mail && mailXX == 1)
		strlcpy(title, "[信件过量,请整理信件!]", sizeof(title));
	else
		strlcpy(title, BBSNAME_UTF8, sizeof(title));

	bool show_board = true;
	int w1 = screen_display_width(menu, true),
		w2 = screen_display_width(title, true),
		w3 = screen_display_width(currboard, true) + 2;
	int spaces = 80 - w1 - w2 - w3;
	if (spaces < 0) {
		spaces = 80 - w1 - w2;
		show_board = false;
	}

	screen_move_clear(0);
	screen_printf("\033[1;33;44m%s", menu);
	if (spaces > 0)
		tui_repeat_char(' ', spaces / 2);
	if (streq(title, BBSNAME_UTF8))
		screen_printf("\033[37m%s", title);
	else if (title[0] == '[')
		screen_printf("\033[5;36m%s\033[0;1;44m", title);
	else
		screen_printf("\033[36m%s", title);
	if (spaces > 0)
		tui_repeat_char(' ', spaces - spaces / 2);
	if (show_board)
		screen_printf("\033[33m[%s]\033[m", currboard);
	tui_update_status_line();
	screen_move(1, 0);
}
Exemplo n.º 14
0
void msgline() {
	char buf[256], buf2[STRLEN * 2];
	void display_buffer();
	extern int talkrequest;
	int tmpshow;
	time_t now;

	if (ismsgline <= 0)
		return;
	now = time(0);
	tmpshow = showansi;
	showansi = 1;
	if (talkrequest) {
		talkreply();
		clear();
		showansi = 0;
		display_buffer();
		showansi = 1;
	}
	strcpy(buf, "");
	if (chkmail())
		strcat(buf, "¡¾ÐÅ¡¿");
	else
		strcat(buf, "¡¾  ¡¿");
	strcat(buf, "ÐÅÏä [°´Ctrl-QÇó¾È] ");
	sprintf(
			buf2,
			"[%s][%4.4d,%3.3d][%d] [%2s]",
			insert_character ? "²åÈë" : "¸Äд", currln + 1, currpnt + 1,
			linelen-1, enabledbchar ? "Ë«" : "µ¥");
	strcat(buf, buf2);
	sprintf(buf2, "\033[1;33m¡¾\033[1;32m%.23s\033[33m¡¿\033[m",
			getdatestring(now, DATE_ZH) + 6);
	strcat(buf, buf2);
	move(t_lines - 1, 0);
	clrtoeol();
	prints("%s", buf);
	showansi = tmpshow;
}
Exemplo n.º 15
0
static void
exfile(int prof)
{
	time_t	mailtime = 0;	/* Must not be a register variable */
	time_t 	curtime = 0;

	/*
	 * move input
	 */
	if (input > 0) {
		Ldup(input, INIO);
		input = INIO;
	}


	setmode(prof);

	if (setjmp(errshell) && prof) {
		close(input);
		(void) endjobs(0);
		return;
	}
	/*
	 * error return here
	 */

	loopcnt = peekc = peekn = 0;
	fndef = 0;
	nohash = 0;
	iopend = 0;

	if (input >= 0)
		initf(input);
	/*
	 * command loop
	 */
	for (;;) {
		tdystak(0);
		stakchk();	/* may reduce sbrk */
		exitset();

		if ((flags & prompt) && standin->fstak == 0 && !eof) {

			if (mailp) {
				time(&curtime);

				if ((curtime - mailtime) >= mailchk) {
					chkmail();
					mailtime = curtime;
				}
			}

			/* necessary to print jobs in a timely manner */
			if (trapnote & TRAPSET)
				chktrap();

			prs(ps1nod.namval);

#ifdef TIME_OUT
			alarm(TIMEOUT);
#endif

		}

		trapnote = 0;
		peekc = readwc();
		if (eof) {
			if (endjobs(JOB_STOPPED))
				return;
			eof = 0;
		}

#ifdef TIME_OUT
		alarm(0);
#endif

		{
			struct trenod *t;
			t = cmd(NL, MTFLG);
			if (t == NULL && flags & ttyflg)
				freejobs();
			else
				execute(t, 0, eflag);
		}

		eof |= (flags & oneflg);

	}
}
Exemplo n.º 16
0
int
main(int argc, char *argv[])
{
	struct stackmark smark, smark2;
	volatile int state;
	char *shinit;

	(void) setlocale(LC_ALL, "");
	initcharset();
	state = 0;
	if (setjmp(main_handler.loc)) {
		switch (exception) {
		case EXEXEC:
			exitstatus = exerrno;
			break;

		case EXERROR:
			exitstatus = 2;
			break;

		default:
			break;
		}

		if (state == 0 || iflag == 0 || ! rootshell ||
		    exception == EXEXIT)
			exitshell(exitstatus);
		reset();
		if (exception == EXINT)
			out2fmt_flush("\n");
		popstackmark(&smark);
		FORCEINTON;				/* enable interrupts */
		if (state == 1)
			goto state1;
		else if (state == 2)
			goto state2;
		else if (state == 3)
			goto state3;
		else
			goto state4;
	}
	handler = &main_handler;
#ifdef DEBUG
	opentrace();
	trputs("Shell args:  ");  trargs(argv);
#endif
	rootpid = getpid();
	rootshell = 1;
	init();
	setstackmark(&smark);
	setstackmark(&smark2);
	procargs(argc, argv);
	pwd_init(iflag);
	if (iflag)
		chkmail(1);
	if (argv[0] && argv[0][0] == '-') {
		state = 1;
		read_profile("/etc/profile");
state1:
		state = 2;
		if (privileged == 0)
			read_profile("${HOME-}/.profile");
		else
			read_profile("/etc/suid_profile");
	}
state2:
	state = 3;
	if (!privileged && iflag) {
		if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') {
			state = 3;
			read_profile(shinit);
		}
	}
state3:
	state = 4;
	popstackmark(&smark2);
	if (minusc) {
		evalstring(minusc, sflag ? 0 : EV_EXIT);
	}
	if (sflag || minusc == NULL) {
state4:	/* XXX ??? - why isn't this before the "if" statement */
		cmdloop(1);
	}
	exitshell(exitstatus);
	/*NOTREACHED*/
	return 0;
}
Exemplo n.º 17
0
void check_register_info(void)
{
	struct userec *urec = &currentuser;
	FILE *fout;
	char buf[192], buf2[STRLEN];
	if (!(urec->userlevel & PERM_LOGIN)) {
		urec->userlevel = 0;
		return;
	}
#ifdef NEWCOMERREPORT
	if (urec->numlogins == 1) {
		screen_clear();
		file_temp_name(buf, sizeof(buf));
		if ((fout = fopen(buf, "w")) != NULL) {
			//% fprintf(fout, "大家好,\n\n");
			fprintf(fout, "\xb4\xf3\xbc\xd2\xba\xc3,\n\n");
			//% fprintf(fout, "我是 %s (%s), 来自 %s\n",
			fprintf(fout, "\xce\xd2\xca\xc7 %s (%s), \xc0\xb4\xd7\xd4 %s\n",
					currentuser.userid, urec->username, fromhost);
			//% fprintf(fout, "今天%s初来此站报到, 请大家多多指教。\n",
			fprintf(fout, "\xbd\xf1\xcc\xec%s\xb3\xf5\xc0\xb4\xb4\xcb\xd5\xbe\xb1\xa8\xb5\xbd, \xc7\xeb\xb4\xf3\xbc\xd2\xb6\xe0\xb6\xe0\xd6\xb8\xbd\xcc\xa1\xa3\n",
					//% (urec->gender == 'M') ? "小弟" : "小女子");
					(urec->gender == 'M') ? "\xd0\xa1\xb5\xdc" : "\xd0\xa1\xc5\xae\xd7\xd3");
			screen_move(2, 0);
			//% prints("非常欢迎 %s 光临本站,希望您能在本站找到属于自己的一片天空!\n\n", currentuser.userid);
			prints("\xb7\xc7\xb3\xa3\xbb\xb6\xd3\xad %s \xb9\xe2\xc1\xd9\xb1\xbe\xd5\xbe\xa3\xac\xcf\xa3\xcd\xfb\xc4\xfa\xc4\xdc\xd4\xda\xb1\xbe\xd5\xbe\xd5\xd2\xb5\xbd\xca\xf4\xd3\xda\xd7\xd4\xbc\xba\xb5\xc4\xd2\xbb\xc6\xac\xcc\xec\xbf\xd5\xa3\xa1\n\n", currentuser.userid);
			//% prints("请您作个简短的个人简介, 向本站其他使用者打个招呼\n");
			prints("\xc7\xeb\xc4\xfa\xd7\xf7\xb8\xf6\xbc\xf2\xb6\xcc\xb5\xc4\xb8\xf6\xc8\xcb\xbc\xf2\xbd\xe9, \xcf\xf2\xb1\xbe\xd5\xbe\xc6\xe4\xcb\xfb\xca\xb9\xd3\xc3\xd5\xdf\xb4\xf2\xb8\xf6\xd5\xd0\xba\xf4\n");
			//% prints("(简介最多三行, 写完可直接按 <Enter> 跳离)....");
			prints("(\xbc\xf2\xbd\xe9\xd7\xee\xb6\xe0\xc8\xfd\xd0\xd0, \xd0\xb4\xcd\xea\xbf\xc9\xd6\xb1\xbd\xd3\xb0\xb4 <Enter> \xcc\xf8\xc0\xeb)....");
			getdata(6, 0, ":", buf2, 75, DOECHO, YEA);
			if (buf2[0] != '\0') {
				//% fprintf(fout, "\n\n自我介绍:\n\n");
				fprintf(fout, "\n\n\xd7\xd4\xce\xd2\xbd\xe9\xc9\xdc:\n\n");
				fprintf(fout, "%s\n", buf2);
				getdata(7, 0, ":", buf2, 75, DOECHO, YEA);
				if (buf2[0] != '\0') {
					fprintf(fout, "%s\n", buf2);
					getdata(8, 0, ":", buf2, 75, DOECHO, YEA);
					if (buf2[0] != '\0') {
						fprintf(fout, "%s\n", buf2);
					}
				}
			}
			fclose(fout);
			//% sprintf(buf2, "新手上路: %s", urec->username);
			sprintf(buf2, "\xd0\xc2\xca\xd6\xc9\xcf\xc2\xb7: %s", urec->username);
			Postfile(buf, "newcomers", buf2, 2);
			unlink(buf);
		}
		pressanykey();
	}
#endif
#ifndef FDQUAN
	//检查邮箱
	while (!HAS_PERM(PERM_BINDMAIL)) {
		screen_clear();
		if (HAS_PERM(PERM_REGISTER)) {
			//% while (askyn("是否绑定复旦邮箱", NA, NA)== NA)
			while (askyn("\xca\xc7\xb7\xf1\xb0\xf3\xb6\xa8\xb8\xb4\xb5\xa9\xd3\xca\xcf\xe4", NA, NA)== NA)
			//add  by eefree.06.7.20
			{
				//% if (askyn("是否填写校友信息", NA, NA) == NA) {
				if (askyn("\xca\xc7\xb7\xf1\xcc\xee\xd0\xb4\xd0\xa3\xd3\xd1\xd0\xc5\xcf\xa2", NA, NA) == NA) {
					screen_clear();
					continue;
				}
				check_reg_extra();
				return;
			}
			//add end.
		}
		tui_check_reg_mail();
	}
#endif

	screen_clear();
	if (HAS_PERM(PERM_REGISTER))
		return;
#ifndef AUTOGETPERM

	if (check_register_ok()) {
#endif
		set_safe_record();
		urec->userlevel |= PERM_DEFAULT;
		substitut_record(PASSFILE, urec, sizeof(struct userec), usernum);
		return;
#ifndef AUTOGETPERM

	}
#endif

	if (!chkmail())
		fill_reg_form();
}
Exemplo n.º 18
0
Arquivo: chat.c Projeto: wyat/kbs
static int ent_chat(int chatnum)
{                               /* 进入聊天室 */
    chatcontext *pthis;
    char inbuf[128];
    int ch, cmdpos;
    int currchar;
    int modified;               /* the line is modified? -- wwj */
    int newmail;
    int page_pending = false;
    int chatting = true;
#ifdef NEW_HELP
    int oldhelpmode=helpmode;
#endif

    if (!strcmp(getCurrentUser()->userid, "guest"))
        return -1;
    pthis = (chatcontext *) malloc(sizeof(chatcontext));
    bzero(pthis, sizeof(chatcontext));
    if (!pthis)
        return -1;
    modify_user_mode(CHAT1);
    ch = ent_chat_conn(pthis, chatnum);
    if (ch != 1) {
        free(pthis);
        return ch;
    }
#ifdef NEW_HELP
    helpmode=HELP_CHAT;
#endif
    add_io(pthis->cfd, 0);
    modified = newmail = cmdpos = currchar = 0;
    /* update uinfo */
    uinfo.in_chat = true;
    strcpy(uinfo.chatid, pthis->chatid);
    UPDATE_UTMP(in_chat, uinfo);
    UPDATE_UTMP_STR(chatid, uinfo);
    /* initiate screen */
    clear();
    pthis->chatline = 2;
    move(s_lines, 0);
    outs(msg_seperator);
    move(1, 0);
    outs(msg_seperator);
    print_chatid(pthis);
    memset(inbuf, 0, 80);
    /* chat begin */
    while (chatting) {
        if (chat_checkparse(pthis) == 0)
            break;
        move(b_lines, currchar + 10);
        pthis->outputcount = 0;
        ch = igetkey();
        if (ch==KEY_TALK) {
            int talkpage = servicepage(0, pthis->buf);

            if (talkpage != page_pending) {
                bell();
                oflush();
                printchatline(pthis, pthis->buf);
                page_pending = talkpage;
            }
        }
        if (chat_checkparse(pthis) == 0)
            break;
        if (ch == I_OTHERDATA)
            continue;
        switch (ch) {
            case KEY_UP:
            case KEY_DOWN:
                if (cmdpos == pthis->cmdpos) {
                    strcpy(pthis->lastcmd[cmdpos], inbuf);
                    modified = 0;
                }
                if (ch == KEY_UP) {
                    if (cmdpos != (pthis->cmdpos + 1) % MAXLASTCMD) {
                        int i = (cmdpos + MAXLASTCMD - 1) % MAXLASTCMD;

                        if (pthis->lastcmd[i][0])
                            cmdpos = i;
                    }
                }
                if (ch == KEY_DOWN) {
                    if (cmdpos != pthis->cmdpos)
                        cmdpos = (cmdpos + 1) % MAXLASTCMD;
                }
                strcpy(inbuf, pthis->lastcmd[cmdpos]);
                if (cmdpos == pthis->cmdpos) {
                    modified = 1;
                }
                move(b_lines, 10);
                clrtoeol();
                ch = inbuf[69];
                inbuf[69] = 0;
                outs(inbuf);
                inbuf[69] = ch;
                currchar = strlen(inbuf);
                continue;
#ifdef CHINESE_CHARACTER
            case Ctrl('R'):
                SET_CHANGEDEFINE(getCurrentUser(), DEF_CHCHAR);
                continue;
#endif
            case KEY_LEFT:
                if (currchar)
                    --currchar;
#ifdef CHINESE_CHARACTER
                if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                    int i,j=0;
                    for (i=0;i<currchar;i++)
                        if (j) j=0;
                        else if (inbuf[i]<0) j=1;
                    if (j) {
                        currchar--;
                    }
                }
#endif
                continue;
            case KEY_RIGHT:
                if (inbuf[currchar])
                    ++currchar;
#ifdef CHINESE_CHARACTER
                if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                    int i,j=0;
                    for (i=0;i<currchar;i++)
                        if (j) j=0;
                        else if (inbuf[i]<0) j=1;
                    if (j) {
                        if (inbuf[currchar])
                            ++currchar;
                    }
                }
#endif
                continue;
            case KEY_ESC:
            case Ctrl('X'):
                inbuf[0] = 0;
                currchar = 0;
                move(b_lines, currchar + 10);
                clrtoeol();
                modified = 1;
                continue;
            case Ctrl('A'):
                currchar = 0;
                continue;
            case Ctrl('E'):
                currchar = strlen(inbuf);
                continue;
        }
        if (!newmail && chkmail(0)) {   /* check mail */
            newmail = 1;
            printchatline(pthis, "\033[32m*** \033[31m当!你有新信来啦...\033[m");
        }
        if (isprint2(ch)) {
            if (currchar < 126) {       /* 未满一行,print it */
                modified = 1;
                if (inbuf[currchar]) {  /* insert */
                    int i;

                    for (i = currchar; inbuf[i] && i < 127; i++);
                    inbuf[i + 1] = '\0';
                    for (; i > currchar; i--)
                        inbuf[i] = inbuf[i - 1];
                } else {        /* append */
                    inbuf[currchar + 1] = '\0';
                }
                inbuf[currchar] = ch;
                ch = inbuf[69]; /* save the end of line */
                inbuf[69] = 0;
                move(b_lines, currchar + 10);
                outs(&inbuf[currchar++]);
                inbuf[69] = ch;
            }
            continue;
        }
        if (ch == '\n' || ch == '\r') {
            if (currchar) {
                if (modified) {
                    /* add to command history */
                    ch = sizeof(pthis->lastcmd[pthis->cmdpos]) - 1;
                    strncpy(pthis->lastcmd[pthis->cmdpos], inbuf, ch);
                    pthis->lastcmd[pthis->cmdpos][ch] = 0;
                    pthis->cmdpos = (pthis->cmdpos + 1) % MAXLASTCMD;
                    cmdpos = pthis->cmdpos;
                } else {        /* use history, so can +1 */
                    cmdpos = (cmdpos + 1) % MAXLASTCMD;
                }
                if (inbuf[0] == '/' && Isspace(inbuf[1])) {     /* discard / b */
                    printchatline(pthis,
                                  "\x1b[37m*** \x1b[32m请输入正确的指令,使用/h寻求帮助\x1b[37m ***\x1b[m");
                } else {
                    chatting = chat_cmd(pthis, inbuf);  /*local命令处理 */
                    if (chatting == 0)
                        chatting = chat_send(pthis, inbuf);
                    if (inbuf[0] == '/') {
                        ch = 1;
                        while (inbuf[ch] != '\0' && inbuf[ch] != ' ')
                            ch++;
                        if (ch > 1) {
                            if (!strncasecmp(inbuf, "/bye", ch))
                                break;
                            if (!strncasecmp(inbuf, "/exit", ch))
                                break;  /*added by alex, 96.9.5 */
                        }
                    }
                }
                modified = 0;
                inbuf[0] = '\0';
                currchar = 0;
                move(b_lines, 10);
                clrtoeol();
            }
            continue;
        }
        if (ch == Ctrl('H') || ch == '\177') {  /*Backspace */
            if (currchar) {
                currchar--;
                inbuf[127] = '\0';
                memcpy(&inbuf[currchar], &inbuf[currchar + 1],
                       127 - currchar);
                move(b_lines, currchar + 10);
                clrtoeol();
                ch = inbuf[69]; /* save the end of line */
                inbuf[69] = 0;
                outs(&inbuf[currchar]);
                inbuf[69] = ch;
            }
#ifdef CHINESE_CHARACTER
            if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                int i,j=0;
                for (i=0;i<currchar;i++)
                    if (j) j=0;
                    else if (inbuf[i]<0) j=1;
                if (j) {
                    currchar--;
                    inbuf[127] = '\0';
                    memcpy(&inbuf[currchar], &inbuf[currchar + 1],
                           127 - currchar);
                    move(b_lines, currchar + 10);
                    clrtoeol();
                    ch = inbuf[69]; /* save the end of line */
                    inbuf[69] = 0;
                    outs(&inbuf[currchar]);
                    inbuf[69] = ch;
                }
            }
#endif
            continue;
        }
        if (ch == Ctrl('Z')) {
            r_lastmsg();        /* Leeward 98.07.30 support msgX */
            inbuf[0] = '\0';
            currchar = 0;
            move(b_lines, 10);
            clrtoeol();
            continue;
        }
        if (ch == Ctrl('C') /*|| ch == Ctrl('D') */) {  /* ^C 退出 */
            chat_send(pthis, "/b");
            if (pthis->rec)
                set_rec(pthis,NULL);
            break;
        }
    }
    /* chat end */
    if (pthis->rec)set_rec(pthis,NULL);
    close(pthis->cfd);
    add_io(0, 0);
    uinfo.in_chat = false;
    uinfo.chatid[0] = '\0';
    UPDATE_UTMP(in_chat, uinfo);
    UPDATE_UTMP(chatid[0], uinfo);
    clear();
    free(pthis);
#ifdef NEW_HELP
    helpmode=oldhelpmode;
#endif
    return 0;
}
Exemplo n.º 19
0
static void
hit_alarm_clock()
{
  static int stay_time = 0;
  static int idle_time = 0;

  time_t now = time(0);
  char buf[100]="\0";

  if(currutmp->pid != currpid)
    setup_utmp(XMODE);   /* 重新配置 shm */

#ifdef  DOTIMEOUT
  if((idle_time = now - currutmp->lastact) > IDLE_TIMEOUT && !HAS_PERM(PERM_RESEARCH))
#else
  if((idle_time = now - currutmp->lastact) > !HAS_PERM(PERM_RESEARCH))
#endif
  {
    outmsg("超過閒置時間!踢出去囉……");
    abort_bbs();
  }

  if (HAS_HABIT(HABIT_MOVIE) && (currstat && (currstat < CLASS || currstat == MAILALL)))
    movie(0);

  alarm(MOVIE_INT);
  stay_time += MOVIE_INT;

#ifdef  DOTIMEOUT
  if(idle_time > IDLE_TIMEOUT - 60 && !HAS_PERM(PERM_RESEARCH)) 
#else
  if(idle_time > 60 && !HAS_PERM(PERM_RESEARCH))
#endif
    sprintf(buf, "警告:您已閒置過久,若無回應,系統即將切離!!");
  else if(stay_time > 10 * 60 && chkmail(0)) 
  {
    sprintf(buf, "\033[1;33;41m[%s] 信箱�媮晹釣S看過的信唷\033[m",
      Etime(&now));
    stay_time = 0 ;
  }
  else if(stay_time > STAY_TIMEOUT && HAS_HABIT(HABIT_ALARM))
  {
    /* 在這裡提示 user 休息一下 */
    char *msg[10] = {
    "伸伸腰, 揉揉眼, 喝口茶....喘口氣...再繼續...!",
    "一邊是友情 一邊是愛情 左右的故事為難著自己...",
    "是否有人瞭解您內心的孤寂? 大家來talk talk吧.. ",
    "左三圈,右三圈,脖子扭扭屁股扭扭 大家來作運動唷~",
    "我灌..我灌..我灌灌灌! 灌到硬碟爆掉...",
    "用•功\•唸•書",
    "書念完了沒啊....^.^",
    "明天有沒有考試啊...念書重要唷...!",
    "看∼流星!",
    "•書在心中氣自皇•讀書去•"};
    int i = rand() % 10;

    sprintf(buf, "[%s] %s", Etime(&now), msg[i]);
    stay_time = 0 ;
  }

  if(buf[0]) 
  {
    outmsg(buf);
    bell();
  }
}
Exemplo n.º 20
0
void check_register_info() {
	struct userec *urec = &currentuser;
	FILE *fout;
	char buf[192], buf2[STRLEN];
#ifdef MAILCHECK

	char ans[4];
#ifdef CODE_VALID

	int i;
#endif
#endif

	if (!(urec->userlevel & PERM_LOGIN)) {
		urec->userlevel = 0;
		return;
	}
#ifdef NEWCOMERREPORT
	if (urec->numlogins == 1) {
		clear();
		sprintf(buf, "tmp/newcomer.%s", currentuser.userid);
		if ((fout = fopen(buf, "w")) != NULL) {
			fprintf(fout, "��Һ�,\n\n");
			fprintf(fout, "���� %s (%s), ���� %s\n",
					currentuser.userid, urec->username, fromhost);
			fprintf(fout, "����%s������վ����, ���Ҷ��ָ�̡�\n",
					(urec->gender == 'M') ? "С��" : "СŮ��");
			move(2, 0);
			prints("�dz���ӭ %s ���ٱ�վ��ϣ�������ڱ�վ�ҵ������Լ���һƬ��գ�\n\n", currentuser.userid);
			prints("����������̵ĸ��˼��, ��վ����ʹ���ߴ���к�\n");
			prints("(����������, д���ֱ�Ӱ� <Enter> ����)....");
			getdata(6, 0, ":", buf2, 75, DOECHO, YEA);
			if (buf2[0] != '\0') {
				fprintf(fout, "\n\n���ҽ���:\n\n");
				fprintf(fout, "%s\n", buf2);
				getdata(7, 0, ":", buf2, 75, DOECHO, YEA);
				if (buf2[0] != '\0') {
					fprintf(fout, "%s\n", buf2);
					getdata(8, 0, ":", buf2, 75, DOECHO, YEA);
					if (buf2[0] != '\0') {
						fprintf(fout, "%s\n", buf2);
					}
				}
			}
			fclose(fout);
			sprintf(buf2, "������·: %s", urec->username);
			Postfile(buf, "newcomers", buf2, 2);
			unlink(buf);
		}
		pressanykey();
	}
#endif
#ifdef PASSAFTERTHREEDAYS
	if (urec->lastlogin - urec->firstlogin < 3 * 86400) {
		if (!HAS_PERM(PERM_SYSOP)) {
			set_safe_record();
			urec->userlevel &= ~(PERM_DEFAULT);
			urec->userlevel |= PERM_LOGIN;
			substitut_record(PASSFILE, urec, sizeof(struct userec), usernum);
			ansimore("etc/newregister", YEA);
			return;
		}
	}
#endif
#ifndef FDQUAN
	//�������
	while (!HAS_PERM(PERM_BINDMAIL)) {
		clear();
		if (HAS_PERM(PERM_REGISTER)) {
			while (askyn("�Ƿ�󶨸�������", NA, NA)== NA)
			//add  by eefree.06.7.20
			{
				if (askyn("�Ƿ���дУ����Ϣ", NA, NA) == NA) {
					clear();
					continue;
				}
				check_reg_extra();
				return;
			}
			//add end.
		}
		check_reg_mail();
	}

#endif

	clear();
	if (HAS_PERM(PERM_REGISTER))
		return;
#ifndef AUTOGETPERM

	if (check_register_ok()) {
#endif
		set_safe_record();
		urec->userlevel |= PERM_DEFAULT;
		substitut_record(PASSFILE, urec, sizeof(struct userec), usernum);
		return;
#ifndef AUTOGETPERM

	}
#endif

#ifdef MAILCHECK
#ifdef CODE_VALID
	sethomefile(buf, currentuser.userid, ".regpass");
	if (dashf(buf)) {
		move(13, 0);
		prints("����δͨ�����ȷ��... \n");
		prints("�����ڱ�������ע��ȷ������, \"��֤����\"����Ϊ���ȷ��\n");
		prints("һ���� %d ���ַ�, ��Сд���в���, ��ע��.\n", RNDPASSLEN);
		prints("����ȡ�������������� [Enter] ��.\n");
		prints("��ע��, ����������һ����֤�������������������룡\n");
		if ((fout = fopen(buf, "r")) != NULL) {
			fscanf(fout, "%s", buf2);
			fclose(fout);
			for (i = 0; i < 3; i++) {
				move(18, 0);
				prints("������ %d ���\n", 3 - i);
				getdata(19,0,"��������֤����: ",genbuf,(RNDPASSLEN+1),DOECHO,YEA);
				if (strcmp(genbuf, "") != 0) {
					if (strcmp(genbuf, buf2) != 0)
					continue;
					else
					break;
				}
			}
		} else
		i = 3;
		if (i == 3) {
			prints("������֤ʧ��! ����Ҫ��дע�ᵥ�����ȷ������ȷ���������\n");
			getdata(22,0,"��ѡ��1.��ע�ᵥ 2.����ȷ���� [1]:",ans,2,DOECHO,YEA);
			if(ans[0] == '2') {
				send_regmail(&currentuser);
				pressanykey();
			} else
			x_fillform();
		} else {
			set_safe_record();
			urec->userlevel |= PERM_DEFAULT;
			substitut_record(PASSFILE, urec,sizeof(struct userec), usernum);
			prints("������!! ����˳����ɱ�վ��ʹ����ע������,\n");
			prints("������������ӵ��һ��ʹ���ߵ�Ȩ��������...\n");
			unlink(buf);
			mail_file("etc/smail", "SYSOP", "��ӭ���뱾վ����");
			pressanykey();
		}
		return;
	}
#endif
	if ( (!strstr(urec->email, BBSHOST)) && (!invalidaddr(urec->email)) &&
			(!invalid_email(urec->email))) {
		move(13, 0);
		prints("���ĵ������� ����ͨ��������֤...  \n");
		prints("    ��վ�����ϼ�һ����֤�Ÿ���,\n");
		prints("    ��ֻҪ�� %s ����, �Ϳ��Գ�Ϊ��վ�ϸ���.\n\n", urec->email);
		prints("    ��Ϊ��վ�ϸ���, �������и����Ȩ���!\n");
		prints("    ��Ҳ����ֱ����дע�ᵥ��Ȼ��ȴ�վ�����ֹ���֤��\n");
		getdata(21,0,"��ѡ��1.��ע�ᵥ 2.��ȷ���� [1]: ",ans,2,DOECHO,YEA);
		if(ans[0] == '2') {
			send_regmail(&currentuser);
			getdata(21,0,"ȷ�����Ѽij�, ��������Ŷ!! ",ans, 2, DOECHO, YEA);
			return;
		}
	}
#endif
	/* Following line modified by Amigo 2002.04.23. Fill form only when no new letter. */
	/*   x_fillform();*/
	if (!chkmail())
		x_fillform();
}
Exemplo n.º 21
0
Arquivo: var.c Projeto: dezelin/kBuild
void
setvareq(shinstance *psh, char *s, int flags)
{
    struct var *vp, **vpp;
    int nlen;

    if (aflag(psh))
        flags |= VEXPORT;
    vp = find_var(psh, s, &vpp, &nlen);
    if (vp != NULL) {
        if (vp->flags & VREADONLY)
            error(psh, "%.*s: is read only", vp->name_len, s);
        if (flags & VNOSET)
            return;
        INTOFF;

        if (vp->func && (flags & VNOFUNC) == 0)
            (*vp->func)(psh, s + vp->name_len + 1);

        if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0)
            ckfree(psh, vp->text);

        vp->flags &= ~(VTEXTFIXED|VSTACK|VUNSET);
        vp->flags |= flags & ~VNOFUNC;
        vp->text = s;
#ifdef PC_OS2_LIBPATHS
        if ((vp->flags & VOS2LIBPATH) && (vp->flags & VEXPORT))
            vp->flags &= ~VEXPORT;
#endif

        /*
         * We could roll this to a function, to handle it as
         * a regular variable function callback, but why bother?
         */
        if (vp == &psh->vmpath || (vp == &psh->vmail && ! mpathset(psh)))
            chkmail(psh, 1);
        INTON;
        return;
    }
    /* not found */
    if (flags & VNOSET)
        return;

#ifdef PC_MIXED_PATH_VAR_NAME
    if (   nlen == 4
            && (s[0] == 'p' || s[0] == 'P')
            && (s[1] == 'a' || s[1] == 'A')
            && (s[2] == 't' || s[2] == 'T')
            && (s[3] == 'h' || s[3] == 'H') ) {
        s[0] = 'P';
        s[1] = 'A';
        s[2] = 'T';
        s[3] = 'H';
    }
#endif

    vp = ckmalloc(psh, sizeof (*vp));
    vp->flags = flags & ~VNOFUNC;
    vp->text = s;
    vp->name_len = nlen;
    vp->next = *vpp;
    vp->func = NULL;
    *vpp = vp;
}
Exemplo n.º 22
0
Arquivo: main.c Projeto: cbsd/cbsd
int
main(int argc, char *argv[])
{
	struct stackmark smark, smark2;
	volatile int state;
	char *shinit;

#ifdef CBSD
	char *MY_APP = NULL;
	char *cbsdpath = NULL;
	char *workdir = NULL;
	char *cbsd_disable_history = NULL; //getenv
	chdir("/var/empty");
	/* Only use history when stdin is a tty. */
	if ( isatty(0) && isatty(1) ) {
		cbsd_enable_history = 1;
	}
#endif

	(void) setlocale(LC_ALL, "");
	initcharset();
	state = 0;
	if (setjmp(main_handler.loc)) {
		switch (exception) {
		case EXEXEC:
			exitstatus = exerrno;
			break;

		case EXERROR:
			exitstatus = 2;
			break;

		default:
			break;
		}

		if (state == 0 || iflag == 0 || ! rootshell ||
		    exception == EXEXIT)
			exitshell(exitstatus);
		reset();
		if (exception == EXINT)
			out2fmt_flush("\n");
		popstackmark(&smark);
		FORCEINTON;				/* enable interrupts */
		if (state == 1)
			goto state1;
		else if (state == 2)
			goto state2;
		else if (state == 3)
			goto state3;
		else
			goto state4;
	}
	handler = &main_handler;
#ifdef DEBUG
	opentrace();
	trputs("Shell args:  ");  trargs(argv);
#endif
	rootpid = getpid();
	rootshell = 1;
	INTOFF;
	initvar();
	setstackmark(&smark);
	setstackmark(&smark2);

#ifdef CBSD
	if (argc>1) {
		if (!strcmp(argv[1],"--help")) {
			system("/usr/local/bin/cbsd help");
			exit(0);
		} else {
			if (!strcmp(argv[1],"version")) {
				printf("%s\n",VERSION);
				exit(0);
			}
		}
	}

	cbsd_disable_history=lookupvar("NO_CBSD_HISTORY");

	if ( cbsd_disable_history != NULL ) cbsd_enable_history=0;

	workdir=lookupvar("workdir");

	if ( workdir == NULL )  {
		read_profile("/etc/rc.conf");
		setvarsafe("workdir", lookupvar("cbsd_workdir"), 0);
	}

	workdir=lookupvar("workdir");
	if ( workdir == NULL ) {
		out2fmt_flush("cbsd: no workdir defined\n");
		exitshell(1);
	}

	setvarsafe("PS1","cbsd@\\h> ",1);
	setvarsafe("workdir",workdir,1);
	workdir=lookupvar("workdir"); //  ^^ after "setsave*" original is free
	cbsdpath = calloc(MAXPATHLEN, sizeof(char *));

	if (argv[1]) {
		setvarsafe("CBSD_APP",basename(argv[1]),1);
	}

	if (cbsdpath == NULL) {
		out2fmt_flush("cbsd: out of memory for cbsdpath\n");
		exitshell(1);
	}

	// %s/modules must be first for opportunity to have a module commands greater priority than the original CBSD command.
	// This makes it possible to write a 3rd party modules with altered functionality of the original code.
	sprintf(cbsdpath,"%s/modules:%s/bin:%s/sbin:%s/tools:%s/jailctl:%s/nodectl:%s/system:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin",workdir,cbsd_distdir,cbsd_distdir,cbsd_distdir,cbsd_distdir,cbsd_distdir,cbsd_distdir);
	setvarsafe("PATH",cbsdpath,1);
	ckfree(cbsdpath);

	// read global params first (disable/enable colors, repos etc..)
	read_profile("${workdir}/etc/defaults/global.conf");
	read_profile("${workdir}/etc/global.conf");

	if (lookupvar("NOCOLOR") != NULL ) {
		putenv("NOCOLOR=1");
	}

	// non-interactive global env
	if (lookupvar("NOINTER") != NULL ) {
		setvarsafe("inter","1",1);
		putenv("inter=0");
	}

	read_profile("/usr/local/cbsd/cbsd.conf");
	read_profile("${workdir}/etc/defaults/logger.conf");
	read_profile("${workdir}/etc/logger.conf");

	if (cbsd_enable_history==1) {
		cbsd_history_file=calloc(MAXPATHLEN, sizeof(char *));
		sprintf(cbsd_history_file,"%s/%s",workdir,CBSD_HISTORYFILE);
	}

#endif

	procargs(argc, argv);
	pwd_init(iflag);
	INTON;
#ifndef CBSD
	if (iflag)
		chkmail(1);
#endif
	if (argv[0] && argv[0][0] == '-') {
		state = 1;
		read_profile("/etc/profile");
state1:
		state = 2;
		if (privileged == 0)
			read_profile("${HOME-}/.profile");
		else
			read_profile("/etc/suid_profile");
	}
state2:
	state = 3;
	if (!privileged && iflag) {
		if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') {
			state = 3;
			read_profile(shinit);
		}
	}
state3:
	state = 4;
	popstackmark(&smark2);
	if (minusc) {
		evalstring(minusc, sflag ? 0 : EV_EXIT);
	}
state4:
	if (sflag || minusc == NULL) {
		cmdloop(1);
	}
	exitshell(exitstatus);
	/*NOTREACHED*/
	return 0;
}