(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;
|
HANDLE hStdIn;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define getsose() ((void)0)
|
||||||
|
#define putso() ((void)0)
|
||||||
|
#define putse() ((void)0)
|
||||||
|
#else
|
||||||
void getsose(void);
|
void getsose(void);
|
||||||
|
void putso(void);
|
||||||
|
void putse(void);
|
||||||
|
#endif
|
||||||
int recvline(int s, char *buf);
|
int recvline(int s, char *buf);
|
||||||
int expect(int s, int match, char *buf);
|
int expect(int s, int match, char *buf);
|
||||||
int handleintr(int);
|
int handleintr(int);
|
||||||
|
|
|
@ -341,21 +341,16 @@ screen(char *buf)
|
||||||
|
|
||||||
while ((c = *buf++)) {
|
while ((c = *buf++)) {
|
||||||
if (eight_bit_clean) {
|
if (eight_bit_clean) {
|
||||||
if (c == 14) {
|
if (c == 14)
|
||||||
if (SO)
|
putso();
|
||||||
fputs(SO, stdout);
|
else if (c == 15)
|
||||||
}
|
putse();
|
||||||
else if (c == 15) {
|
else
|
||||||
if (SE)
|
putchar(c);
|
||||||
fputs(SE, stdout);
|
|
||||||
}
|
|
||||||
else putchar(c);
|
|
||||||
} else if (c & 0x80) {
|
} else if (c & 0x80) {
|
||||||
if (SO)
|
putso();
|
||||||
fputs(SO, stdout);
|
|
||||||
putchar(c & 0x7f);
|
putchar(c & 0x7f);
|
||||||
if (SE)
|
putse();
|
||||||
fputs(SE, stdout);
|
|
||||||
} else
|
} else
|
||||||
putchar(c);
|
putchar(c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,63 +32,46 @@
|
||||||
* Steve McClure, 1998
|
* Steve McClure, 1998
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
|
||||||
|
#include <curses.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <term.h>
|
||||||
#include <string.h>
|
#include <unistd.h>
|
||||||
#include <ctype.h>
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
static char *smso = 0;
|
||||||
#include <unistd.h>
|
static char *rmso = 0;
|
||||||
#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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
getsose(void)
|
getsose(void)
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
int err;
|
||||||
extern char *tgetstr(char *, char **);
|
|
||||||
char *cp;
|
|
||||||
char *term;
|
|
||||||
static char tbuf[1024];
|
|
||||||
static char cbuf[20];
|
|
||||||
|
|
||||||
memset(cbuf, 0, 20);
|
if (!isatty(fileno(stdout)))
|
||||||
term = getenv("TERM");
|
return;
|
||||||
if (term == 0) {
|
|
||||||
fprintf(stderr, "warning: no TERM environment variable\n");
|
if (setupterm(NULL, fileno(stdout), &err) != OK) {
|
||||||
|
fprintf(stderr, "Can't setup terminal, check environment variable TERM\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tgetent(tbuf, term);
|
|
||||||
cp = cbuf;
|
smso = tigetstr("smso");
|
||||||
SO = tgetstr("so", &cp);
|
rmso = tigetstr("rmso");
|
||||||
SE = tgetstr("se", &cp);
|
|
||||||
if (SO == 0) {
|
|
||||||
SO = tgetstr("us", &cp);
|
|
||||||
SE = tgetstr("ue", &cp);
|
|
||||||
}
|
}
|
||||||
if (SO != 0) {
|
|
||||||
parsedelay(SO);
|
void
|
||||||
parsedelay(SE);
|
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