Exemplo n.º 1
0
/*f
 * Print error message with command name and trailing newline.
 * Leading ! indicates format errno on the end.
 * The value of errno is restored on completion.
 */
void
ERRORFN(const char *fmt, va_list args)
{
	int saveerrno = errno;
	int syserr = 0;

	if (_cmdname != NULL)
		fprintf(stderr, "%s: ", _cmdname);
	fmt = m_strmsg(fmt);
	if (*fmt == '!') {
		fmt++;
		syserr++;
	}
	vfprintf(stderr, fmt, args);
	if (syserr) {
		char *str;

		/* Do eprintf-like stuff */
		str = strerror(saveerrno);
		if (*str == '\0')
			fprintf(stderr, ": errno = %d", saveerrno);
		else
			fprintf(stderr,": %s", str);
	}
	fputc('\n', stderr);
	errno = saveerrno;
	DONE;
}
Exemplo n.º 2
0
/*f
 * Initialize XCurses for use with a single terminal.  stdin and stdout
 * are used.  If a program needs an indication of error conditions,
 * so that it can continue to run in a line-oriented mode, use newterm()
 * instead.
 */
WINDOW *
initscr()
{
	WINDOW *w;
	SCREEN *sp;
	int i, n, begy;
	char *term, *err;

#ifdef M_CURSES_TRACE
	__m_trace("initscr(void)");
#endif

	errno = 0;
 	sp = newterm((char *) 0, stdout, stdin);

	if (sp == (SCREEN *) 0) {
		err = errno == ENOMEM ? nomem_msg : noterm_msg;
		goto error_1;
	}

	(void) set_term(sp);

	/* We require some form of cursor positioning and the ability to
	 * clear the end of a line.  These abilities should be sufficient
	 * to provide minimum full screen support. 
	 */
	if (1 < lines
	&& cursor_address == (char *) 0 
	&& row_address == (char *) 0
	&& (cursor_up == (char *) 0 || cursor_down == (char *) 0)
	&& (parm_up_cursor == (char *) 0 || parm_down_cursor == (char *) 0)) {
		err = dumb_msg;
		goto error_3;
	}
	
	if ((1 < lines && cursor_address == (char *) 0)
	&& column_address == (char *) 0
	&& (cursor_left == (char *) 0 || cursor_right == (char *) 0)
	&& (parm_left_cursor == (char *) 0 || parm_right_cursor == (char *)0)) {
		err = dumb_msg;
		goto error_3;
	}

	if (clr_eol == (char *) 0) {
		err = dumb_msg;
		goto error_3;
	}

	return __m_return_pointer("initscr", stdscr);
error_3:
	(void) delwin(stdscr);
error_2:
	(void) endwin();
	(void) delscreen(sp);
error_1:
	/* newterm()/setupterm() attempts to load $TERM, else if
	 * $TERM is not defined, the vendor's default terminal type.
	 */
	if ((term = getenv("TERM")) == (char *) 0)
		term = M_TERM_NAME;

	(void) fprintf(stderr, m_strmsg(err), term);
error_0:
	exit(1);
	return (0);	/* keep gcc happy */
}