+ OutputTermStr(term_ve, 1);
+}
+
+ExtFunc void GetTermcapInfo(void)
+{
+ char *term, *buf, *data;
+ int bufSize = 10240;
+
+ if (!(term = getenv("TERM")))
+ return;
+ if (tgetent(scratch, term) == 1) {
+ /*
+ * Make the buffer HUGE, since tgetstr is unsafe.
+ * Allocate it on the heap too.
+ */
+ data = buf = malloc(bufSize);
+
+ /*
+ * There is no standard include file for tgetstr, no prototype
+ * definitions. I like casting better than using my own prototypes
+ * because if I guess the prototype, I might be wrong, especially
+ * with regards to "const".
+ */
+ term_vi = (char *)tgetstr("vi", &data);
+ term_ve = (char *)tgetstr("ve", &data);
+
+ /* Okay, so I'm paranoid; I just don't like unsafe routines */
+ if (data > buf + bufSize)
+ fatal("tgetstr overflow, you must have a very sick termcap");
+
+ /* Trim off the unused portion of buffer */
+ buf = realloc(buf, data - buf);
+ }
+
+ /*
+ * If that fails, use hardcoded vt220 codes.
+ * They don't seem to do anything bad on vt100's, so
+ * we'll try them just in case they work.
+ */
+ if (!term_vi || !term_ve) {
+ static char *vts[] = {
+ "vt100", "vt101", "vt102",
+ "vt200", "vt220", "vt300",
+ "vt320", "vt400", "vt420",
+ "screen", "xterm", NULL };
+ int i;
+
+ for (i = 0; vts[i]; i++)
+ if (!strcmp(term, vts[i]))
+ {
+ term_vi = "\033[?25l";
+ term_ve = "\033[?25h";
+ break;
+ }
+ }
+ if (!term_vi || !term_ve)
+ term_vi = term_ve = NULL;
+}
+
+ExtFunc void OutputTermStr(char *str, int flush)
+{
+ if (str) {
+ fputs(str, stdout);
+ if (flush)
+ fflush(stdout);
+ }