(getsose): Port from obsolete termcap to terminfo. The old code
manually stripped off padding, which is evil. The new code does nothing when the stdout is not connected to a terminal. (SO, smso, SE, rmso): Rename, static linkage. (putso, putse): New. (screen): Use it.
This commit is contained in:
parent
c3915edb54
commit
fbf9f15bbb
3 changed files with 48 additions and 62 deletions
|
@ -61,7 +61,15 @@ extern char *SE;
|
|||
HANDLE hStdIn;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define getsose() ((void)0)
|
||||
#define putso() ((void)0)
|
||||
#define putse() ((void)0)
|
||||
#else
|
||||
void getsose(void);
|
||||
void putso(void);
|
||||
void putse(void);
|
||||
#endif
|
||||
int recvline(int s, char *buf);
|
||||
int expect(int s, int match, char *buf);
|
||||
int handleintr(int);
|
||||
|
|
|
@ -341,21 +341,16 @@ screen(char *buf)
|
|||
|
||||
while ((c = *buf++)) {
|
||||
if (eight_bit_clean) {
|
||||
if (c == 14) {
|
||||
if (SO)
|
||||
fputs(SO, stdout);
|
||||
}
|
||||
else if (c == 15) {
|
||||
if (SE)
|
||||
fputs(SE, stdout);
|
||||
}
|
||||
else putchar(c);
|
||||
if (c == 14)
|
||||
putso();
|
||||
else if (c == 15)
|
||||
putse();
|
||||
else
|
||||
putchar(c);
|
||||
} else if (c & 0x80) {
|
||||
if (SO)
|
||||
fputs(SO, stdout);
|
||||
putso();
|
||||
putchar(c & 0x7f);
|
||||
if (SE)
|
||||
fputs(SE, stdout);
|
||||
putse();
|
||||
} else
|
||||
putchar(c);
|
||||
}
|
||||
|
|
|
@ -32,63 +32,46 @@
|
|||
* Steve McClure, 1998
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <curses.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <term.h>
|
||||
#include <unistd.h>
|
||||
#include "misc.h"
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
char *SO = 0;
|
||||
char *SE = 0;
|
||||
|
||||
int tgetent(char *, char *);
|
||||
|
||||
static void
|
||||
parsedelay(char *r)
|
||||
{
|
||||
char *s, *t;
|
||||
|
||||
s = r;
|
||||
while (isdigit(*s) || (*s == '*') || (*s == '.')) {
|
||||
s++;
|
||||
}
|
||||
for (t = r; *s != 0; (s++, t++)) {
|
||||
*t = *s;
|
||||
}
|
||||
*t = 0;
|
||||
}
|
||||
static char *smso = 0;
|
||||
static char *rmso = 0;
|
||||
|
||||
void
|
||||
getsose(void)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
extern char *tgetstr(char *, char **);
|
||||
char *cp;
|
||||
char *term;
|
||||
static char tbuf[1024];
|
||||
static char cbuf[20];
|
||||
int err;
|
||||
|
||||
memset(cbuf, 0, 20);
|
||||
term = getenv("TERM");
|
||||
if (term == 0) {
|
||||
fprintf(stderr, "warning: no TERM environment variable\n");
|
||||
if (!isatty(fileno(stdout)))
|
||||
return;
|
||||
|
||||
if (setupterm(NULL, fileno(stdout), &err) != OK) {
|
||||
fprintf(stderr, "Can't setup terminal, check environment variable TERM\n");
|
||||
return;
|
||||
}
|
||||
tgetent(tbuf, term);
|
||||
cp = cbuf;
|
||||
SO = tgetstr("so", &cp);
|
||||
SE = tgetstr("se", &cp);
|
||||
if (SO == 0) {
|
||||
SO = tgetstr("us", &cp);
|
||||
SE = tgetstr("ue", &cp);
|
||||
|
||||
smso = tigetstr("smso");
|
||||
rmso = tigetstr("rmso");
|
||||
}
|
||||
if (SO != 0) {
|
||||
parsedelay(SO);
|
||||
parsedelay(SE);
|
||||
|
||||
void
|
||||
putso(void)
|
||||
{
|
||||
if (smso)
|
||||
putp(smso);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
putse(void)
|
||||
{
|
||||
if (rmso)
|
||||
putp(rmso);
|
||||
}
|
||||
|
||||
#endif /* !_WIN32 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue