home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume26
/
mytinfo
/
part01
/
terminfo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-26
|
2KB
|
125 lines
/*
* terminfo.c
*
* By Ross Ridge
* Public Domain
* 92/02/01 07:30:30
*
* terminfo compatible libary functions
*
*/
#include "defs.h"
#include "term.h"
static const char SCCSid[] = "@(#) mytinfo terminfo.c 3.2 92/02/01 public domain, By Ross Ridge";
extern char _mytinfo_version[];
static char *force = _mytinfo_version;
#ifdef USE_FAKE_STDIO
#ifdef __GNUC__
__inline__
#endif
static int
printerr(msg)
char *msg; {
return write(2, msg, strlen(msg));
}
#define RETERR(e, msg) { (err == NULL ? (printerr(msg), exit(1), 0) \
: (*err = e)); return ERR; }
#else
#define RETERR(e, msg) { (err == NULL ? (fprintf(stderr, msg), exit(1), 0) \
: (*err = e)); return ERR; }
#endif
int
setupterm(term, fd, err)
char *term;
int fd;
int *err; {
struct term_path *path;
char *s;
int r = -1;
char buf[MAX_BUF];
if (term == NULL)
term = getenv("TERM");
if (term == NULL)
RETERR(0, "TERM not set\n")
path = _buildpath("$MYTERMINFO", 2,
"$TERMINFO", 2,
"$TERMCAP", 1,
#ifdef TERMINFODIR
TERMINFODIR, 0,
#endif
#ifdef TERMCAPFILE
TERMCAPFILE, 0,
#endif
#ifdef TERMINFOSRC
TERMINFOSRC, 0,
#endif
NULL, -1);
if (path == NULL)
RETERR(0, "malloc error\n");
r = _fillterm(term, path, buf);
_delpath(path);
switch(r) {
case -3:
RETERR(0, "malloc error\n");
case -2:
RETERR(-1, "bad format\n");
case -1:
RETERR(-1, "database not found\n");
case 0:
RETERR(0, "terminal not found\n");
case 1:
case 2:
case 3:
cur_term->fd = fd;
_term_buf.fd = fd;
if (_init_tty() == ERR)
RETERR(0, "problem initializing tty\n");
if ((s = getenv("LINES")) != NULL && atoi(s) > 0)
lines = atoi(s);
if ((s = getenv("COLUMNS")) != NULL && atoi(s) > 0)
columns = atoi(s);
if (err != NULL)
*err = 1;
return OK;
default:
RETERR(0, "oops...\n");
}
}
int
set_curterm(p)
TERMINAL *p; {
cur_term = p;
if (_init_tty() == ERR)
return ERR;
if (_check_tty() == ERR)
return ERR;
return OK;
}
int
del_curterm(p)
TERMINAL *p; {
_del_strs(p);
free((anyptr) p);
return OK;
}