-/* $Id: engine.c,v 1.11 2010/01/12 23:22:14 nicm Exp $ */
+/* $Id: engine.c,v 1.12 2010/07/16 05:22:48 lum Exp $ */
/*
* Copyright (c) 2001, 2007 Can Erkin Acar <canacar@openbsd.org>
*
#include <string.h>
#include <term.h>
#include <unistd.h>
+#include <err.h>
/* XXX These are defined in term.h and conflict with our variable names */
#ifdef columns
if (rawmode == 0)
endwin();
}
+
+int
+check_termcap(void)
+{
+ char *term_name;
+ int status;
+ static struct termios screen_settings;
+
+ if (!interactive)
+ /* pretend we have a dumb terminal */
+ return(1);
+
+ /* get the terminal name */
+ term_name = getenv("TERM");
+ if (term_name == NULL)
+ return(1);
+
+ /* now get the termcap entry */
+ if ((status = tgetent(NULL, term_name)) != 1) {
+ if (status == -1)
+ warnx("can't open termcap file");
+ else
+ warnx("no termcap entry for a `%s' terminal",
+ term_name);
+
+ /* pretend it's dumb and proceed */
+ return(1);
+ }
+
+ /* "hardcopy" immediately indicates a very stupid terminal */
+ if (tgetflag("hc"))
+ return(1);
+
+ /* get necessary capabilities */
+ if (tgetstr("cl", NULL) == NULL || tgetstr("cm", NULL) == NULL)
+ return(1);
+
+ /* if stdout is not a terminal, pretend we are a dumb terminal */
+ if (tcgetattr(STDOUT_FILENO, &screen_settings) == -1)
+ return(1);
+
+ return(0);
+}
-/* $Id: engine.h,v 1.5 2008/12/07 02:56:06 canacar Exp $ */
+/* $Id: engine.h,v 1.6 2010/07/16 05:22:48 lum Exp $ */
/*
* Copyright (c) 2001, 2007 Can Erkin Acar <canacar@openbsd.org>
*
void next_order(void);
void setup_term(int maxpr);
+int check_termcap(void);
void engine_initialize(void);
void engine_loop(int countmax);
-/* $Id: main.c,v 1.56 2010/07/02 13:30:03 lum Exp $ */
+/* $Id: main.c,v 1.57 2010/07/16 05:22:48 lum Exp $ */
/*
* Copyright (c) 2001, 2007 Can Erkin Acar
* Copyright (c) 2001 Daniel Hartmeier
return 1;
}
- if (!isatty(STDOUT_FILENO)) {
+ if (check_termcap()) {
rawmode = 1;
interactive = 0;
}