Esempio n. 1
0
/*
 * Determine the erase, interrupt, and kill characters from the termcap
 * entry and command line and update their values in 'mode'.
 */
void
set_control_chars(void)
{
	char *bp, *p, bs_char, buf[1024];

	bp = buf;
	p = tgetstr("kb", &bp);
	if (p == NULL || p[1] != '\0')
		p = tgetstr("bc", &bp);
	if (p != NULL && p[1] == '\0')
		bs_char = p[0];
	else if (tgetflag("bs"))
		bs_char = CTRL('h');
	else
		bs_char = 0;

	if (erasech == 0 && bs_char != 0 && !tgetflag("os"))
		erasech = -1;
	if (erasech < 0)
		erasech = (bs_char != 0) ? bs_char : CTRL('h');

	if (mode.c_cc[VERASE] == 0 || erasech != 0)
		mode.c_cc[VERASE] = erasech ? erasech : CERASE;

	if (mode.c_cc[VINTR] == 0 || intrchar != 0)
		 mode.c_cc[VINTR] = intrchar ? intrchar : CINTR;

	if (mode.c_cc[VKILL] == 0 || killch != 0)
		mode.c_cc[VKILL] = killch ? killch : CKILL;
}
InitScreen()
{
	/* Set up all this fun stuff: returns zero if all okay, or;
        -1 indicating no terminal name associated with this shell,
        -2..-n  No termcap for this terminal type known
   */

	int  tgetent(),      /* get termcap entry */
	     err;
	char termname[40];
	char *termenv;
	
	if ((termenv = getenv("TERM")) == NULL) return(-1);

	if (strcpy(termname, termenv) == NULL)
		return(-1);

	if ((err = tgetent(_terminal, termname)) != 1)
		return(err-2);

	_line  =  0;		/* where are we right now?? */
	_col   =  0;		/* assume zero, zero...     */

	/* load in all those pesky values */
	_clearscreen       = tgetstr("cl", &ptr);
	_moveto            = tgetstr("cm", &ptr);
	_up                = tgetstr("up", &ptr);
	_down              = tgetstr("do", &ptr);
	_right             = tgetstr("nd", &ptr);
	_left              = tgetstr("bc", &ptr);
	_setbold           = tgetstr("so", &ptr);
	_clearbold         = tgetstr("se", &ptr);
	_setunderline      = tgetstr("us", &ptr);
	_clearunderline    = tgetstr("ue", &ptr);
	_setinverse        = tgetstr("so", &ptr);
	_clearinverse      = tgetstr("se", &ptr);
	_sethalfbright     = tgetstr("hs", &ptr);
	_clearhalfbright   = tgetstr("he", &ptr);
	_cleartoeoln       = tgetstr("ce", &ptr);
	_cleartoeos        = tgetstr("cd", &ptr);
	_lines	      	   = tgetnum("li");
	_columns	   = tgetnum("co");
	tabspacing	   = ((tabspacing=tgetnum("it"))<= 0 ? 8 : tabspacing);
	_automargin	   = tgetflag("am");
	_eatnewlineglitch   = tgetflag("xn");
	_transmit_on	   = tgetstr("ks", &ptr);
	_transmit_off      = tgetstr("ke", &ptr);
	_set_memlock	   = tgetstr("ml", &ptr);
	_clear_memlock	   = tgetstr("mu", &ptr);
	_start_termcap	   = tgetstr("ti", &ptr);
	_end_termcap	   = tgetstr("te", &ptr);


	if (!_left) {
		_left = "\b";
	}

	return(0);
}
Esempio n. 3
0
void
startup(void)
{
	char *term;
	char *tptr;
	char *tbufptr, *pc;

	tptr = (char *) alloc(1024);

	tbufptr = tbuf;
	if(!(term = getenv("TERM")))
		error("Can't get TERM.");
	if(!strncmp(term, "5620", 4))
		flags.nonull = 1;	/* this should be a termcap flag */
	if(tgetent(tptr, term) < 1)
		error("Unknown terminal type: %s.", term);
	if ((pc = tgetstr("pc", &tbufptr)))
		PC = *pc;
	if(!(BC = tgetstr("le", &tbufptr))) {	
		if(!tgetflag("bs"))
			error("Terminal must backspace.");
		BC = tbufptr;
		tbufptr += 2;
		*BC = '\b';
	}
	HO = tgetstr("ho", &tbufptr);
	CO = tgetnum("co");
	LI = tgetnum("li");
	if(CO < COLNO || LI < ROWNO+2)
		setclipped();
	if(!(CL = tgetstr("cl", &tbufptr)))
		error("Hack needs CL.");
	ND = tgetstr("nd", &tbufptr);
	if(tgetflag("os"))
		error("Hack can't have OS.");
	CE = tgetstr("ce", &tbufptr);
	UP = tgetstr("up", &tbufptr);
	/* It seems that xd is no longer supported, and we should use
	   a linefeed instead; unfortunately this requires resetting
	   CRMOD, and many output routines will have to be modified
	   slightly. Let's leave that till the next release. */
	XD = tgetstr("xd", &tbufptr);
/* not: 		XD = tgetstr("do", &tbufptr); */
	if(!(CM = tgetstr("cm", &tbufptr))) {
		if(!UP && !HO)
			error("Hack needs CM or UP or HO.");
		printf("Playing hack on terminals without cm is suspect...\n");
		getret();
	}
	SO = tgetstr("so", &tbufptr);
	SE = tgetstr("se", &tbufptr);
	SG = tgetnum("sg");	/* -1: not fnd; else # of spaces left by so */
	if(!SO || !SE || (SG > 0)) SO = SE = 0;
	CD = tgetstr("cd", &tbufptr);
	set_whole_screen();		/* uses LI and CD */
	if(tbufptr-tbuf > sizeof(tbuf)) error("TERMCAP entry too big...\n");
	free(tptr);
}
Esempio n. 4
0
int
main(int argc, char **argv)
{
	int c;
	const char *termtype;
	FILE *f;
	char termcap[1024];

	setlocale(LC_ALL, "");

	termtype = getenv("TERM");
	if (termtype == NULL || (argv[0][0] == 'c' && !isatty(1)))
		termtype = "lpr";
	while ((c=getopt(argc, argv, "it:T:")) != -1)
		switch(c) {

		case 't':
		case 'T': /* for nroff compatibility */
			termtype = optarg;
			break;
		case 'i':
			iflag = 1;
			break;
		default:
			usage();
		}

	switch(tgetent(termcap, termtype)) {

	case 1:
		break;

	default:
		warnx("trouble reading termcap");
		/* FALLTHROUGH */

	case 0:
		/* No such terminal type - assume dumb */
		(void)strcpy(termcap, "dumb:os:col#80:cr=^M:sf=^J:am:");
		break;
	}
	initcap();
	if (    (tgetflag("os") && ENTER_BOLD==NULL ) ||
		(tgetflag("ul") && ENTER_UNDERLINE==NULL && UNDER_CHAR==NULL))
			must_overstrike = 1;
	initbuf();
	if (optind == argc)
		filter(stdin);
	else for (; optind<argc; optind++) {
		f = fopen(argv[optind],"r");
		if (f == NULL)
			err(1, "%s", argv[optind]);
		else
			filter(f);
	}
	exit(0);
}
Esempio n. 5
0
int
main (int argc, char **argv)
{
  char *term;
  char *buf;

  term = argv[1];
  printf ("TERM: %s\n", term);

  buf = (char *) tgetent (0, term);
  if ((int) buf <= 0)
    {
      printf ("No entry.\n");
      return 0;
    }

  printf ("Entry: %s\n", buf);

  tprint ("cm");
  tprint ("AL");

  printf ("co: %d\n", tgetnum ("co"));
  printf ("am: %d\n", tgetflag ("am"));

  return 0;
}
Esempio n. 6
0
File: ex_tty.c Progetto: atsb/ex
void
zap(void)
{
	register char *namp;
	register bool **fp;
	register char ***sp;
	int flag;
	char *string;

#ifndef	UCVISUAL
	namp = "ambsdadbeohcinmincnsosulxbxnxtxx";
#else
	namp = "ambsdadbeohchzinmincnsosulxbxnxtxx";
#endif
	fp = sflags;
	do {
		flag = tgetflag(namp);
		*(*fp++) = flag;
		namp += 2;
	} while (*namp);
	namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullndnlpcrcscsesfsosrtatetiupvbvsveALDLUPDOLERI";
	sp = sstrs;
	do {
		string = tgetstr(namp, &aoftspace);
		*(*sp++) = string;
		namp += 2;
	} while (*namp);
}
Esempio n. 7
0
/*
 * Get a particular flag capability.
 */
static int GetFlagCap(const char *termcapName, const char *terminfoName)
{
#ifdef IL_USE_TERMCAP
	return tgetflag((char *)termcapName);
#else
	return (tigetflag((char *)terminfoName) > 0);
#endif
}
Esempio n. 8
0
int
main(int argc, char **argv)
{
	int ch, exitval, n;
	char *cptr, *term, buf[1024], tbuf[1024];
	const char *p;

	term = NULL;
	while ((ch = getopt(argc, argv, "T:")) != -1)
		switch(ch) {
		case 'T':
			term = optarg;
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc < 1)
		usage();

	if (!term && !(term = getenv("TERM")))
errx(2, "no terminal type specified and no TERM environmental variable.");
	if (tgetent(tbuf, term) != 1)
		err(3, "tgetent failure");
	for (exitval = 0; (p = *argv) != NULL; ++argv) {
		switch (*p) {
		case 'c':
			if (!strcmp(p, "clear"))
				p = "cl";
			break;
		case 'i':
			if (!strcmp(p, "init"))
				p = "is";
			break;
		case 'l':
			if (!strcmp(p, "longname")) {
				prlongname(tbuf);
				continue;
			}
			break;
		case 'r':
			if (!strcmp(p, "reset"))
				p = "rs";
			break;
		}
		cptr = buf;
		if (tgetstr(p, &cptr))
			argv = process(p, buf, argv);
		else if ((n = tgetnum(p)) != -1)
			(void)printf("%d\n", n);
		else
			exitval = !tgetflag(p);
	}
	exit(exitval);
}
Esempio n. 9
0
static void
initcap(void)
{
	static char	tcapbuf[2048];
	char	*bp = tcapbuf;

	cursor_right = tgetstr("ri", &bp);
	if (cursor_right == NULL)
		cursor_right = tgetstr("nd", &bp);
	cursor_up = tgetstr("up", &bp);
	cursor_left = tgetstr("le", &bp);
	if (cursor_left == NULL)
		cursor_left = tgetstr("bc", &bp);
	underline_char = tgetstr("uc", &bp);
	exit_underline_mode = tgetstr("ue", &bp);
	exit_attribute_mode = tgetstr("me", &bp);
	exit_standout_mode = tgetstr("se", &bp);
	enter_reverse_mode = tgetstr("mr", &bp);
	enter_underline_mode = tgetstr("us", &bp);
	enter_dim_mode = tgetstr("mh", &bp);
	enter_bold_mode = tgetstr("md", &bp);
	enter_standout_mode = tgetstr("se", &bp);

	if (!enter_bold_mode && enter_reverse_mode)
		enter_bold_mode = enter_reverse_mode;
	if (!!enter_bold_mode && enter_standout_mode)
		enter_bold_mode = enter_standout_mode;
	if (!enter_underline_mode && enter_standout_mode) {
		enter_underline_mode = enter_standout_mode;
		exit_underline_mode =  exit_standout_mode;
	}
	if (!enter_dim_mode && enter_standout_mode)
		enter_dim_mode = enter_standout_mode;
	if (!enter_reverse_mode && enter_standout_mode)
		enter_reverse_mode = enter_standout_mode;
	if (!exit_attribute_mode && exit_standout_mode)
		exit_attribute_mode = exit_standout_mode;

	must_use_uc = under_char && !enter_underline_mode;
	over_strike = tgetflag("os");
	transparent_underline = tgetflag("ul");
}
Esempio n. 10
0
static void
initcap(void)
{
	static char tcapbuf[512];
	char *bp = tcapbuf;

	/* This nonsense attempts to work with both old and new termcap */
	CURS_UP =		tgetstr("up", &bp);
	CURS_RIGHT =		tgetstr("ri", &bp);
	if (CURS_RIGHT == NULL)
		CURS_RIGHT =	tgetstr("nd", &bp);
	CURS_LEFT =		tgetstr("le", &bp);
	if (CURS_LEFT == NULL)
		CURS_LEFT =	tgetstr("bc", &bp);
	if (CURS_LEFT == NULL && tgetflag("bs"))
		CURS_LEFT =	"\b";

	ENTER_STANDOUT =	tgetstr("so", &bp);
	EXIT_STANDOUT =		tgetstr("se", &bp);
	ENTER_UNDERLINE =	tgetstr("us", &bp);
	EXIT_UNDERLINE =	tgetstr("ue", &bp);
	ENTER_DIM =		tgetstr("mh", &bp);
	ENTER_BOLD =		tgetstr("md", &bp);
	ENTER_REVERSE =		tgetstr("mr", &bp);
	EXIT_ATTRIBUTES =	tgetstr("me", &bp);

	if (!ENTER_BOLD && ENTER_REVERSE)
		ENTER_BOLD = ENTER_REVERSE;
	if (!ENTER_BOLD && ENTER_STANDOUT)
		ENTER_BOLD = ENTER_STANDOUT;
	if (!ENTER_UNDERLINE && ENTER_STANDOUT) {
		ENTER_UNDERLINE = ENTER_STANDOUT;
		EXIT_UNDERLINE = EXIT_STANDOUT;
	}
	if (!ENTER_DIM && ENTER_STANDOUT)
		ENTER_DIM = ENTER_STANDOUT;
	if (!ENTER_REVERSE && ENTER_STANDOUT)
		ENTER_REVERSE = ENTER_STANDOUT;
	if (!EXIT_ATTRIBUTES && EXIT_STANDOUT)
		EXIT_ATTRIBUTES = EXIT_STANDOUT;

	/*
	 * Note that we use REVERSE for the alternate character set,
	 * not the as/ae capabilities.  This is because we are modelling
	 * the model 37 teletype (since that's what nroff outputs) and
	 * the typical as/ae is more of a graphics set, not the greek
	 * letters the 37 has.
	 */

	UNDER_CHAR =		tgetstr("uc", &bp);
	must_use_uc = (UNDER_CHAR && !ENTER_UNDERLINE);
}
Esempio n. 11
0
int main(int argc, char *argv[])
{
    char *op = output;
    char *rp = result;
    const char *t = getenv("TERM");

    char *prop, *pe;
    int n;

    if (argc != 2) {
        fprintf(stderr, "%s [props]\n", argv[0]);
        exit(1);
    }

    if (t == NULL)
        t = "dumb";
    if ((n = tgetent(buf, t)) != 1) {
        fprintf(stderr, "%s is not a known terminal type\n", t);
        putw(0, stdout);
        exit(1);
    }
    prop = argv[1];
    pe = prop + strlen(prop) - 2;
    while(prop < pe) {
        id[0] = *prop++;
        id[1] = *prop++;
        if (*prop == '$') {
            char *r = tgetstr(id, &op);
            if (r) {
                size_t l = strlen(r);
                memcpy(rp, r, l);
                rp += l;
            }
            *rp++= 0;
            prop++;
            continue;
        }
        if (*prop == '#') {
            n = tgetnum(id);
            prop++;
        } else
            n = tgetflag(id);
        /* Intentionally native type and endian */
        memcpy(rp, &n, sizeof(n));
        rp += sizeof(n);
    }
    putw(rp - result, stdout);
    fwrite(result, rp - result, 1, stdout);
    return 0;
}
Esempio n. 12
0
/*
 * This routine gets all the terminal flags from the termcap database
 */
static void
zap()
{
	register char	*namp;
	register bool	**fp;
	register char	***sp;
#ifdef	DEBUG
	register char	*cp;
#endif

	namp = "ambsdadbeohchzinmimsncnsosulxbxnxtxsxx";
	fp = sflags;
	do {
		*(*fp++) = tgetflag(namp);
#ifdef DEBUG
		fprintf(outf, "%2.2s = %s\n", namp, *fp[-1] ? "TRUE" : "FALSE");
#endif
		namp += 2;
	} while (*namp);
	namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmandnlpcrcscsesfsosrtatetiucueupusvbvsveALDLUPDOLERI";
	sp = sstrs;
	do {
		*(*sp++) = tgetstr(namp, &aoftspace);
#ifdef DEBUG
		fprintf(outf, "%2.2s = %s", namp, *sp[-1] == NULL ? "NULL\n" : "\"");
		if (*sp[-1] != NULL) {
			for (cp = *sp[-1]; *cp; cp++)
				fprintf(outf, "%s", unctrl(*cp));
			fprintf(outf, "\"\n");
		}
#endif
		namp += 2;
	} while (*namp);
	if (XS)
		SO = SE = NULL;
	else {
		if (tgetnum("sg") > 0)
			SO = NULL;
		if (tgetnum("ug") > 0)
			US = NULL;
		if (!SO && US) {
			SO = US;
			SE = UE;
		}
	}
	if (DO && !NL)
	        NL = DO;
}
Esempio n. 13
0
SCM
gucu_tget (SCM id)
{
  SCM_ASSERT (scm_is_string (id), id, SCM_ARG1, "tget");

  int ret;
  char *c_str;

  c_str = scm_to_locale_string (id);
  ret = tgetnum (id);
  if (id != -1)
    return scm_from_int (ret);

  ret = tgetflag (id);
  if (id == 0)
    return SCM_BOOL_T;
}
Esempio n. 14
0
static TACommandVerdict tgetflag_cmd(TAThread thread, TAInputStream stream)
{
    char* id;
    int res;

    // Prepare
    id = readString(&stream);

    START_TARGET_OPERATION(thread);

    // Execute
    res = tgetflag(id);

    END_TARGET_OPERATION(thread);

    // Response
    writeInt(thread, res);
    sendResponse(thread);

    return taDefaultVerdict;
}
Esempio n. 15
0
static void
zap(void)
{
	int tgetflag(char *id);
	register char *namp;
	register bool **fp;
	register char ***sp;

	namp = "ambsdadbeohchzinmincnsosulxbxnxtxx";
	fp = sflags;
	do {
		*(*fp++) = tgetflag(namp);
		namp += 2;
	} while (*namp);
	namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullndnlpcrcscsesfsosrtatetiupvbvsveALDLUPDOLERI";
	sp = sstrs;
	do {
		*(*sp++) = tgetstr(namp, &aoftspace);
		namp += 2;
	} while (*namp);
}
Esempio n. 16
0
/*
 * Set up various conversions in 'mode', including parity, tabs, returns,
 * echo, and case, according to the termcap entry.  If the program we're
 * running was named with a leading upper-case character, map external
 * uppercase to internal lowercase.
 */
void
set_conversions(int usingupper)
{
	if (tgetflag("UC") || usingupper) {
#ifdef IUCLC
		mode.c_iflag |= IUCLC;
		mode.c_oflag |= OLCUC;
#endif
	} else if (tgetflag("LC")) {
#ifdef IUCLC
		mode.c_iflag &= ~IUCLC;
		mode.c_oflag &= ~OLCUC;
#endif
	}
	mode.c_iflag &= ~(PARMRK | INPCK);
	mode.c_lflag |= ICANON;
	if (tgetflag("EP")) {
		mode.c_cflag |= PARENB;
		mode.c_cflag &= ~PARODD;
	}
	if (tgetflag("OP")) {
		mode.c_cflag |= PARENB;
		mode.c_cflag |= PARODD;
	}

#ifdef ONLCR
	mode.c_oflag |= ONLCR;
#endif
	mode.c_iflag |= ICRNL;
	mode.c_lflag |= ECHO;
	mode.c_oflag |= OXTABS;
	if (tgetflag("NL")) {			/* Newline, not linefeed. */
#ifdef ONLCR
		mode.c_oflag &= ~ONLCR;
#endif
		mode.c_iflag &= ~ICRNL;
	}
	if (tgetflag("HD"))			/* Half duplex. */
		mode.c_lflag &= ~ECHO;
	if (tgetflag("pt"))			/* Print tabs. */
		mode.c_oflag &= ~OXTABS;
	mode.c_lflag |= (ECHOE | ECHOK);
}
Esempio n. 17
0
t_bool			ft_tinit(t_term *term)
{
	struct termios	tc;

	if ((term->name = ft_getenv("TERM")) == NULL
		|| tgetent(NULL, term->name) <= 0)
		term->name = DEFAULT_TERM;
	if (tgetent(NULL, term->name) <= 0)
		return (false);
	if (tcgetattr(0, &tc) < 0)
		return (false);
	ft_memcpy(&(term->save), &tc, sizeof(struct termios));
	tc.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON);
	tc.c_cc[VMIN] = 1;
	tc.c_cc[VTIME] = 0;
	if (tcsetattr(0, TCSADRAIN, &tc) < 0)
		return (false);
	term->save_am = (tgetflag("am")) ? true : false;
	TPS("ti"), TPS("vi"), TPS("RA");
	ft_tupdate(term);
	return (true);
}
Esempio n. 18
0
static int
ztgetflag(char *s)
{
    char **b;

    /* ncurses can tell if an existing boolean capability is *
     * off, but other curses variants can't, so we fudge it. *
     * This feature of ncurses appears to have gone away as  *
     * of NCURSES_MAJOR_VERSION == 5, so don't rely on it.   */
    switch (tgetflag(s)) {
    case -1:
	break;
    case 0:
	for (b = (char **)boolcodes; *b; ++b)
	    if (s[0] == (*b)[0] && s[1] == (*b)[1])
		return 0;
	break;
    default:
	return 1;
    }
    return -1;
}
void set_title (char *s)
{
#if defined(USE_NCURSES) || defined (USE_NCURSES_W)
   if (tgetflag ("hs")) { // terminal has status line support
      char buf[255] = {0};
      char *p = buf; // tgetstr modifies its second argument, let buf keep pointing to the beginning
      char *ok; // tgetstr's return value is apparently undocumented, except that it's NULL on errors

      ok = tgetstr ("tsl", &p); // "to status line"
      if (ok == NULL) return;
      strcpy (p - 1, s); // tgetstr leaves us *after* the null, so skip back a bit
      p += strlen (s) - 1; // same here

      ok = tgetstr ("fsl", &p); // "from status line"
      if (ok == NULL) return;

      putp (buf);
   }
#else // assume pdcurses
   PDC_set_title(s);
#endif
}
Esempio n. 20
0
int tcutil_init (void) {
  char *termtype, *p, *bp;

  int a, rv;

  /* Check we have a real terminal */
  if(!isatty(0))
    return(0);

  /* Get terminal type */
  termtype = getenv("TERM");
  if(!termtype)
    return(0);

  /* Get termcap */
  rv = tgetent(termcapbuf, termtype);
  if(rv != 1)
    return(0);

  bp = termentbuf;

  /* Look up padding */
  p = tgetstr("pc", &bp);
  if(p)
    PC = *p;
  else
    PC = 0;

  /* Can the terminal backspace?  We may need this. */
  can_bs = tgetflag("bs");

  /* Set BC and UP to NULL so we can use tgoto to emit other caps
     needing arguments. */
  BC = (char *) NULL;
  UP = (char *) NULL;

  /* Look up operations */
  for(a = 0; a < NUM_OPS; a++) {
    p = tgetstr(ops_tc[a], &bp);
    if(p)
      ops[a] = p;
    else
      ops[a] = (char *) NULL;
  }

  /* Look up attributes */
  for(a = 0; a < NUM_ATTR; a++) {
    p = tgetstr(attr_tc[a], &bp);
    if(p)
      attr[a] = p;
    else
      attr[a] = (char *) NULL;
  }

  /* Turn off buffering */
  setvbuf(stdout, (char *) NULL, _IONBF, 0);

  /* Should really turn off output processing
   * and arrange for restoration on exit, but that
   * would mean we have to handle all the other
   * stuff (like newlines) ourselves too.
   */

  /* Success! */
  return(1);
}
Esempio n. 21
0
/*
 * Read termcap and set some global variables. Initialize input trie to
 * decode escape sequences.
 */
static int
tcapterminalinfo(int termcap_wins)
{
    char   *p, *tgetstr();
    char    tcbuf[2*1024];
    char   *tv_stype;
    char    err_str[72];
    int     err;
    char   *_ku, *_kd, *_kl, *_kr,
	   *_kppu, *_kppd, *_kphome, *_kpend, *_kpdel,
	   *_kf1, *_kf2, *_kf3, *_kf4, *_kf5, *_kf6,
	   *_kf7, *_kf8, *_kf9, *_kf10, *_kf11, *_kf12;

    if (!(tv_stype = getenv("TERM")) || !strncpy(term_name, tv_stype, sizeof(term_name))){
	if(Pmaster){
	    return(-1);
	}
	else{
	    puts("Environment variable TERM not defined!");
	    exit(1);
	}
    }

    term_name[sizeof(term_name)-1] = '\0';

    if((err = tgetent(tcbuf, tv_stype)) != 1){
	if(Pmaster){
	    return(err - 2);
	}
	else{
	    snprintf(err_str, sizeof(err_str), "Unknown terminal type %s!", tv_stype);
	    puts(err_str);
	    exit(1);
	}
    }

    p = tcapbuf;

    _clearscreen	= tgetstr("cl", &p);
    _moveto		= tgetstr("cm", &p);
    _up			= tgetstr("up", &p);
    _down		= tgetstr("do", &p);
    _right		= tgetstr("nd", &p);
    _left		= tgetstr("bs", &p);
    _setinverse		= tgetstr("so", &p);
    _clearinverse	= tgetstr("se", &p);
    _setunderline	= tgetstr("us", &p);
    _clearunderline	= tgetstr("ue", &p);
    _setbold		= tgetstr("md", &p);
    _clearallattr	= tgetstr("me", &p);
    _cleartoeoln	= tgetstr("ce", &p);
    _cleartoeos		= tgetstr("cd", &p);
    _deletechar		= tgetstr("dc", &p);
    _insertchar		= tgetstr("ic", &p);
    _startinsert	= tgetstr("im", &p);
    _endinsert		= tgetstr("ei", &p);
    _deleteline		= tgetstr("dl", &p);
    _insertline		= tgetstr("al", &p);
    _scrollregion	= tgetstr("cs", &p);
    _scrolldown		= tgetstr("sf", &p);
    _scrollup		= tgetstr("sr", &p);
    _termcap_init	= tgetstr("ti", &p);
    _termcap_end	= tgetstr("te", &p);
    _startdelete	= tgetstr("dm", &p);
    _enddelete		= tgetstr("ed", &p);
    _ku			= tgetstr("ku", &p);
    _kd			= tgetstr("kd", &p);
    _kl			= tgetstr("kl", &p);
    _kr			= tgetstr("kr", &p);
    _kppu		= tgetstr("kP", &p);
    _kppd		= tgetstr("kN", &p);
    _kphome		= tgetstr("kh", &p);
    _kpend		= tgetstr("kH", &p);
    _kpdel		= tgetstr("kD", &p);
    _kf1		= tgetstr("k1", &p);
    _kf2		= tgetstr("k2", &p);
    _kf3		= tgetstr("k3", &p);
    _kf4		= tgetstr("k4", &p);
    _kf5		= tgetstr("k5", &p);
    _kf6		= tgetstr("k6", &p);
    _kf7		= tgetstr("k7", &p);
    _kf8		= tgetstr("k8", &p);
    _kf9		= tgetstr("k9", &p);
    if((_kf10		= tgetstr("k;", &p)) == NULL)
      _kf10		= tgetstr("k0", &p);
    _kf11		= tgetstr("F1", &p);
    _kf12		= tgetstr("F2", &p);

    _colors		= tgetnum("Co");
    _pairs		= tgetnum("pa");
    _setaf		= tgetstr("AF", &p);
    _setab		= tgetstr("AB", &p);
    _setf		= tgetstr("Sf", &p);
    _setb		= tgetstr("Sb", &p);
    _scp		= tgetstr("sp", &p);
    _op			= tgetstr("op", &p);
    _oc			= tgetstr("oc", &p);
    _bce		= tgetflag("ut");

    if (p >= &tcapbuf[TCAPSLEN]){
	puts("Terminal description too big!\n");
	if(Pmaster)
	  return(-3);
	else
	  exit(1);
    }

    _tlines = tgetnum("li");
    if(_tlines == -1){
	char *er;
	int   rr;

	/* tgetnum failed, try $LINES */
	er = getenv("LINES");
	if(er && (rr = atoi(er)) > 0)
	  _tlines = rr;
    }

    _tcolumns = tgetnum("co");
    if(_tcolumns == -1){
	char *ec;
	int   cc;

	/* tgetnum failed, try $COLUMNS */
	ec = getenv("COLUMNS");
	if(ec && (cc = atoi(ec)) > 0)
	  _tcolumns = cc;
    }

    /*
     * Add default keypad sequences to the trie.
     * Since these come first, they will override any conflicting termcap
     * or terminfo escape sequences defined below.  An escape sequence is
     * considered conflicting if one is a prefix of the other.
     * So, without TERMCAP_WINS, there will likely be some termcap/terminfo
     * escape sequences that don't work, because they conflict with default
     * sequences defined here.
     */
    if(!termcap_wins)
      setup_dflt_esc_seq();

    /*
     * add termcap/info escape sequences to the trie...
     */

    if(_ku != NULL && _kd != NULL && _kl != NULL && _kr != NULL){
	kpinsert(_ku, KEY_UP, termcap_wins);
	kpinsert(_kd, KEY_DOWN, termcap_wins);
	kpinsert(_kl, KEY_LEFT, termcap_wins);
	kpinsert(_kr, KEY_RIGHT, termcap_wins);
    }

    if(_kppu != NULL && _kppd != NULL){
	kpinsert(_kppu, KEY_PGUP, termcap_wins);
	kpinsert(_kppd, KEY_PGDN, termcap_wins);
    }

    kpinsert(_kphome, KEY_HOME, termcap_wins);
    kpinsert(_kpend,  KEY_END, termcap_wins);
    kpinsert(_kpdel,  KEY_DEL, termcap_wins);

    kpinsert(_kf1,  F1, termcap_wins);
    kpinsert(_kf2,  F2, termcap_wins);
    kpinsert(_kf3,  F3, termcap_wins);
    kpinsert(_kf4,  F4, termcap_wins);
    kpinsert(_kf5,  F5, termcap_wins);
    kpinsert(_kf6,  F6, termcap_wins);
    kpinsert(_kf7,  F7, termcap_wins);
    kpinsert(_kf8,  F8, termcap_wins);
    kpinsert(_kf9,  F9, termcap_wins);
    kpinsert(_kf10, F10, termcap_wins);
    kpinsert(_kf11, F11, termcap_wins);
    kpinsert(_kf12, F12, termcap_wins);

    /*
     * Add default keypad sequences to the trie.
     * Since these come after the termcap/terminfo escape sequences above,
     * the termcap/info sequences will override any conflicting default
     * escape sequences defined here.
     * So, with TERMCAP_WINS, some of the default sequences will be missing.
     * This means that you'd better get all of your termcap/terminfo entries
     * correct if you define TERMCAP_WINS.
     */
    if(termcap_wins)
      setup_dflt_esc_seq();

    if(Pmaster)
      return(0);
    else
      return(TRUE);
}
Esempio n. 22
0
int 
main(int ac, char **av)
{
	int skip;
	char *cp;

	if (ac < 3) {
		fprintf(stderr, "usage: %s str1 str2 [ -w -! -noask -go -f file -F file ]\n",
		    __progname);
		exit(1);
	}
	cp = getenv("TERM");
	if (cp == 0) {
		beginul = nullstr;
		endul = nullstr;
	} else {
		if (tgetent(tcp_buf, cp) != 1) {
			beginul = nullstr;
			endul = nullstr;
		} else {
			cp = cap_buf;
			if (tgetflag("os") || tgetflag("ul")) {
				ul_ = 1;
			} else {
				ul_ = 0;
				beginul = tgetstr("us", &cp);
				if (beginul == 0) {
					beginul = tgetstr("so", &cp);
					if (beginul == 0) {
						beginul = nullstr;
						endul = nullstr;
					} else {
						endul = tgetstr("se", &cp);
					}
				} else {
					endul = tgetstr("ue", &cp);
				}
			}
		}
	}
	{
		static char tmp[] = "/tmp/qsubst.XXXXXX";
		int fd;
		fd = mkstemp(&tmp[0]);
		if (fd < 0) {
			fprintf(stderr, "%s: cannot create temp file: %s\n",
			    __progname, strerror(errno));
			exit(1);
		}
		tempf = fdopen(fd, "w+");
	}
	if ((access(av[1], R_OK | W_OK) == 0) &&
	    (access(av[ac - 1], R_OK | W_OK) < 0) &&
	    (access(av[ac - 2], R_OK | W_OK) < 0)) {
		fprintf(stderr, "%s: argument order has changed, it's now: str1 str2 files...\n", __progname);
	}
	str1 = av[1];
	str2 = av[2];
	av += 2;
	ac -= 2;
	s1l = strlen(str1);
	s2l = strlen(str2);
	if (s1l > BUF_SIZ) {
		fprintf(stderr, "%s: search string too long (max %d chars)\n",
		    __progname, BUF_SIZ);
		exit(1);
	}
	tcgetattr(0, &orig_tio);
	signal(SIGTSTP, sigtstp);
	allfly = 0;
	cabove = 2;
	cbelow = 2;
	skip = 0;
	for (ac--, av++; ac; ac--, av++) {
		if (skip > 0) {
			skip--;
			continue;
		}
		if (**av == '-') {
			++*av;
			if (!strcmp(*av, "debug")) {
				debugging++;
			} else if (!strcmp(*av, "w")) {
				wordmode = !wordmode;
			} else if ((strcmp(*av, "!") == 0) ||
				    (strcmp(*av, "go") == 0) ||
			    (strcmp(*av, "noask") == 0)) {
				allfly = 1;
			} else if ((strcmp(*av, "nogo") == 0) ||
			    (strcmp(*av, "ask") == 0)) {
				allfly = 0;
			} else if (**av == 'c') {
				cabove = atoi(++*av);
				cbelow = cabove;
				limit_above_below();
			} else if (**av == 'C') {
				++*av;
				if (**av == 'A') {
					cabove = atoi(++*av);
					limit_above_below();
				} else if (**av == 'B') {
					cbelow = atoi(++*av);
					limit_above_below();
				} else {
					fprintf(stderr, "%s: -C must be -CA or -CB\n", __progname);
				}
			} else if ((strcmp(*av, "f") == 0) ||
			    (strcmp(*av, "F") == 0)) {
				if (++skip >= ac) {
					fprintf(stderr, "%s: -%s what?\n",
					    __progname, *av);
				} else {
					if (**av == 'f') {
						process_file(av[skip]);
					} else {
						process_indir_file(av[skip]);
					}
				}
			}
		} else {
			process_file(*av);
		}
	}
	exit(0);
}
Esempio n. 23
0
File: screen.c Progetto: xrg/pg_top
void
init_termcap(int interactive)

{
	char	   *bufptr;
	char	   *PCptr;
	char	   *term_name;
	char	   *getenv();
	int			status;

	/* set defaults in case we aren't smart */
	screen_width = MAX_COLS;
	screen_length = 0;

	if (!interactive)
	{
		/* pretend we have a dumb terminal */
		smart_terminal = No;
		return;
	}

	/* assume we have a smart terminal until proven otherwise */
	smart_terminal = Yes;

	/* get the terminal name */
	term_name = getenv("TERM");

	/* if there is no TERM, assume it's a dumb terminal */
	/* patch courtesy of Sam Horrocks at telegraph.ics.uci.edu */
	if (term_name == NULL)
	{
		smart_terminal = No;
		return;
	}

	/* now get the termcap entry */
	if ((status = tgetent(termcap_buf, term_name)) != 1)
	{
		if (status == -1)
		{
			fprintf(stderr, "%s: can't open termcap file\n", myname);
		}
		else
		{
			fprintf(stderr, "%s: no termcap entry for a `%s' terminal\n",
					myname, term_name);
		}

		/* pretend it's dumb and proceed */
		smart_terminal = No;
		return;
	}

	/* "hardcopy" immediately indicates a very stupid terminal */
	if (tgetflag("hc"))
	{
		smart_terminal = No;
		return;
	}

	/* set up common terminal capabilities */
	if ((screen_length = tgetnum("li")) <= 0)
	{
		screen_length = smart_terminal = 0;
		return;
	}

	/* screen_width is a little different */
	if ((screen_width = tgetnum("co")) == -1)
	{
		screen_width = 79;
	}
	else
	{
		screen_width -= 1;
	}

	/* terminals that overstrike need special attention */
	overstrike = tgetflag("os");

	/* initialize the pointer into the termcap string buffer */
	bufptr = string_buffer;

	/* get "ce", clear to end */
	if (!overstrike)
	{
		clear_line = tgetstr("ce", &bufptr);
	}

	/* get necessary capabilities */
	if ((clear_screen = tgetstr("cl", &bufptr)) == NULL ||
		(cursor_motion = tgetstr("cm", &bufptr)) == NULL)
	{
		smart_terminal = No;
		return;
	}

	/* get some more sophisticated stuff -- these are optional */
	clear_to_end = tgetstr("cd", &bufptr);
	terminal_init = tgetstr("ti", &bufptr);
	terminal_end = tgetstr("te", &bufptr);
	start_standout = tgetstr("so", &bufptr);
	end_standout = tgetstr("se", &bufptr);

	/* pad character */
	PC = (PCptr = tgetstr("pc", &bufptr)) ? *PCptr : 0;

	/* set convenience strings */
	(void) strcpy(home, tgoto(cursor_motion, 0, 0));
	/* (lower_left is set in get_screensize) */

	/* get the actual screen size with an ioctl, if needed */

	/*
	 * This may change screen_width and screen_length, and it always sets
	 * lower_left.
	 */
	get_screensize();

	/* if stdout is not a terminal, pretend we are a dumb terminal */
#ifdef SGTTY
	if (ioctl(STDOUT, TIOCGETP, &old_settings) == -1)
	{
		smart_terminal = No;
	}
#endif
#ifdef TERMIO
	if (ioctl(STDOUT, TCGETA, &old_settings) == -1)
	{
		smart_terminal = No;
	}
#endif
#ifdef TERMIOS
	if (tcgetattr(STDOUT, &old_settings) == -1)
	{
		smart_terminal = No;
	}
#endif
}
Esempio n. 24
0
/* Initialize the terminal which is known as TERMINAL_NAME.  If this
   terminal doesn't have cursor addressability, `terminal_is_dumb_p'
   becomes nonzero.  The variables SCREENHEIGHT and SCREENWIDTH are set
   to the dimensions that this terminal actually has.  The variable
   TERMINAL_HAS_META_P becomes nonzero if this terminal supports a Meta
   key.  Finally, the terminal screen is cleared. */
void
terminal_initialize_terminal (char *terminal_name)
{
  char *buffer;

  terminal_is_dumb_p = 0;

  if (terminal_initialize_terminal_hook)
    {
      (*terminal_initialize_terminal_hook) (terminal_name);
      return;
    }

  term_name = terminal_name ? terminal_name : getenv ("TERM");
  if (!term_name)
    term_name = "dumb";

  if (!term_string_buffer)
    term_string_buffer = xmalloc (2048);

  if (!term_buffer)
    term_buffer = xmalloc (2048);

  buffer = term_string_buffer;

  term_clrpag = term_cr = term_clreol = NULL;

  /* HP-UX 11.x returns 0 for OK [email protected].  */
  if (tgetent (term_buffer, term_name) < 0)
    {
      terminal_is_dumb_p = 1;
      screenwidth = 80;
      screenheight = 24;
      term_cr = "\r";
      term_up = term_dn = audible_bell = visible_bell = NULL;
      term_ku = term_kd = term_kl = term_kr = NULL;
      term_kP = term_kN = NULL;
      term_kh = term_ke = NULL;
      term_kD = NULL;
      return;
    }

  BC = tgetstr ("pc", &buffer);
  PC = BC ? *BC : 0;

#if defined (HAVE_TERMIOS_H)
  {
    struct termios ti;
    if (tcgetattr (fileno(stdout), &ti) != -1)
      ospeed = cfgetospeed (&ti);
    else
      ospeed = B9600;
  }
#else
# if defined (TIOCGETP)
  {
    struct sgttyb sg;

    if (ioctl (fileno (stdout), TIOCGETP, &sg) != -1)
      ospeed = sg.sg_ospeed;
    else
      ospeed = B9600;
  }
# else
  ospeed = B9600;
# endif /* !TIOCGETP */
#endif

  term_cr = tgetstr ("cr", &buffer);
  term_clreol = tgetstr ("ce", &buffer);
  term_clrpag = tgetstr ("cl", &buffer);
  term_goto = tgetstr ("cm", &buffer);

  /* Find out about this terminal's scrolling capability. */
  term_AL = tgetstr ("AL", &buffer);
  term_DL = tgetstr ("DL", &buffer);
  term_al = tgetstr ("al", &buffer);
  term_dl = tgetstr ("dl", &buffer);

  terminal_can_scroll = ((term_AL || term_al) && (term_DL || term_dl));

  term_invbeg = tgetstr ("mr", &buffer);
  if (term_invbeg)
    term_invend = tgetstr ("me", &buffer);
  else
    term_invend = NULL;

  if (!term_cr)
    term_cr =  "\r";

  terminal_get_screen_size ();

  term_up = tgetstr ("up", &buffer);
  term_dn = tgetstr ("dn", &buffer);
  visible_bell = tgetstr ("vb", &buffer);
  terminal_has_visible_bell_p = (visible_bell != NULL);
  audible_bell = tgetstr ("bl", &buffer);
  if (!audible_bell)
    audible_bell = "\007";
  term_begin_use = tgetstr ("ti", &buffer);
  term_end_use = tgetstr ("te", &buffer);

  term_keypad_on = tgetstr ("ks", &buffer);
  term_keypad_off = tgetstr ("ke", &buffer);

  /* Check to see if this terminal has a meta key. */
  terminal_has_meta_p = (tgetflag ("km") || tgetflag ("MT"));
  if (terminal_has_meta_p)
    {
      term_mm = tgetstr ("mm", &buffer);
    }
  else
    {
      term_mm = NULL;
    }

  /* Attempt to find the arrow keys.  */
  term_ku = tgetstr ("ku", &buffer);
  term_kd = tgetstr ("kd", &buffer);
  term_kr = tgetstr ("kr", &buffer);
  term_kl = tgetstr ("kl", &buffer);

  term_kP = tgetstr ("kP", &buffer);
  term_kN = tgetstr ("kN", &buffer);

#if defined(INFOKEY)
  term_kh = tgetstr ("kh", &buffer);
  term_ke = tgetstr ("@7", &buffer);
  term_ki = tgetstr ("kI", &buffer);
  term_kx = tgetstr ("kD", &buffer);
#endif /* defined(INFOKEY) */

  /* Home and end keys. */
  term_kh = tgetstr ("kh", &buffer);
  term_ke = tgetstr ("@7", &buffer);

  term_kD = tgetstr ("kD", &buffer);

  /* If this terminal is not cursor addressable, then it is really dumb. */
  if (!term_goto)
    terminal_is_dumb_p = 1;
}
Esempio n. 25
0
/*
 * term_init: does all terminal initialization... reads termcap info, sets
 * the terminal to CBREAK, no ECHO mode.   Chooses the best of the terminal
 * attributes to use ..  for the version of this function that is called for
 * wserv, we set the termial to RAW, no ECHO, so that all the signals are
 * ignored.. fixes quite a few problems...  -phone, jan 1993..
 */
void
term_init(void)
{
#ifndef	STTY_ONLY
	char	bp[TGETENT_BUFSIZ],
		*term,
		*ptr;

	if ((term = getenv("TERM")) == NULL)
	{
		fprintf(stderr, "irc: No TERM variable set!\n");
		fprintf(stderr,"irc: You may still run irc by using the -d switch\n");
		exit(1);
	}
	if (tgetent(bp, term) < 1)
	{
		fprintf(stderr, "irc: No termcap entry for %s.\n", term);
		fprintf(stderr,"irc: You may still run irc by using the -d switch\n");
		exit(1);
	}

	if ((co = tgetnum("co")) == -1)
		co = 80;
	if ((li = tgetnum("li")) == -1)
		li = 24;
	ptr = termcap;

	/*
	 * Thanks to Max Bell ([email protected]) for info about TVI
	 * terminals and the sg terminal capability
	 */
	SG = tgetnum("sg");
	CM = tgetstr("cm", &ptr);
	CL = tgetstr("cl", &ptr);
	if ((CM == NULL) ||
	    (CL == NULL))
	{
		fprintf(stderr, "This terminal does not have the necessary "
				 "capabilities to run IRCII\n"
				 "in full screen mode. You may still run "
				 "irc by using the -d switch\n");
		exit(1);
	}
	if ((CR = tgetstr("cr", &ptr)) == NULL)
		CR = "\r";
	if ((NL = tgetstr("nl", &ptr)) == NULL)
		NL = "\n";

	if ((CE = tgetstr("ce", &ptr)) != NULL)
		term_clear_to_eol_func = term_CE_clear_to_eol;
	else
		term_clear_to_eol_func = term_null_function;

	TE = tgetstr("te", &ptr);
	if (!use_termcap_enterexit() && TE && (TI = tgetstr("ti", &ptr)) != NULL )
		tputs_x(TI);
	else
		TE = TI = NULL;

	/* if ((ND = tgetstr("nd", &ptr)) || (ND = tgetstr("kr", &ptr))) */
	if ((ND = tgetstr("nd", &ptr)) != NULL)
		term_cursor_right_func = term_ND_cursor_right;
	else
		term_cursor_right_func = term_null_function;

	/* if ((LE = tgetstr("le", &ptr)) || (LE = tgetstr("kl", &ptr))) */
	if ((LE = tgetstr("le", &ptr)) != NULL)
		term_cursor_left_func = term_LE_cursor_left;
	else if (tgetflag("bs"))
		term_cursor_left_func = term_BS_cursor_left;
	else
		term_cursor_left_func = term_null_function;

	SF = tgetstr("sf", &ptr);
	SR = tgetstr("sr", &ptr);

	if ((CS = tgetstr("cs", &ptr)) != NULL)
		term_scroll_func = term_CS_scroll;
	else if ((AL = tgetstr("AL", &ptr)) && (DL = tgetstr("DL", &ptr)))
		term_scroll_func = term_param_ALDL_scroll;
	else if ((AL = tgetstr("al", &ptr)) && (DL = tgetstr("dl", &ptr)))
		term_scroll_func = term_ALDL_scroll;
	else
		term_scroll_func = (int (*)(int, int, int)) term_null_function;

	if ((IC = tgetstr("ic", &ptr)) != NULL)
		term_insert_func = term_IC_insert;
	else
	{
		if ((IM = tgetstr("im", &ptr)) && (EI = tgetstr("ei", &ptr)))
			term_insert_func = term_IMEI_insert;
		else
			term_insert_func = (int (*)(u_int)) term_null_function;
	}

	if ((DC = tgetstr("dc", &ptr)) != NULL)
		term_delete_func = term_DC_delete;
	else
		term_delete_func = term_null_function;

	SO = tgetstr("so", &ptr);
	SE = tgetstr("se", &ptr);
	if ((SO == NULL) || (SE == NULL))
	{
		SO = CP(empty_string());
		SE = CP(empty_string());
	}
	US = tgetstr("us", &ptr);
	UE = tgetstr("ue", &ptr);
	if ((US == NULL) || (UE == NULL))
	{
		US = CP(empty_string());
		UE = CP(empty_string());
	}
	MD = tgetstr("md", &ptr);
	ME = tgetstr("me", &ptr);
	if ((MD == NULL) || (ME == NULL))
	{
		MD = CP(empty_string());
		ME = CP(empty_string());
	}
	if ((BL = tgetstr("bl", &ptr)) == NULL)
		BL = "\007";
#endif /* STTY_ONLY */

	if (getenv("IRC_DEBUG")|| (tty_des = open("/dev/tty", O_RDWR, 0)) == -1)
		tty_des = 0;

	tcgetattr(tty_des, &oldb);

	newb = oldb;
	newb.c_lflag &= ~(ICANON | ECHO);	/* set equivalent of
						 * CBREAK and no ECHO
						 */
	newb.c_cc[VMIN] = 1;	/* read() satified after 1 char */
	newb.c_cc[VTIME] = 0;	/* No timer */

#ifndef _POSIX_VDISABLE
# define _POSIX_VDISABLE 0
#endif

	newb.c_cc[VQUIT] = _POSIX_VDISABLE;
#ifdef VDISCARD
	newb.c_cc[VDISCARD] = _POSIX_VDISABLE;
#endif
#ifdef VDSUSP
	newb.c_cc[VDSUSP] = _POSIX_VDISABLE;
#endif
#ifdef VSUSP
	newb.c_cc[VSUSP] = _POSIX_VDISABLE;
#endif

#ifndef STTY_ONLY
	if (!use_flow_control())
		newb.c_iflag &= ~IXON;	/* No XON/XOFF */
#endif /* STTY_ONLY */

	tcsetattr(tty_des, TCSADRAIN, &newb);
}
Esempio n. 26
0
File: more.c Progetto: aalm/obsd-src
/*
 * Terminal I/O
 */
void
initterm(void)
{
	char		buf[TBUFSIZ];
	static char	clearbuf[TBUFSIZ];
	char		*clearptr, *padstr;
	char		*term;
	int		tgrp;
	struct winsize	win;

retry:
	if (!(no_tty = tcgetattr(STDOUT_FILENO, &otty))) {
		docrterase = (otty.c_cc[VERASE] != _POSIX_VDISABLE);
		docrtkill =  (otty.c_cc[VKILL] != _POSIX_VDISABLE);
		/*
		 * Wait until we're in the foreground before we save the
		 * the terminal modes.
		 */
		if ((tgrp = tcgetpgrp(STDOUT_FILENO)) < 0) {
			perror("tcgetpgrp");
			exit(1);
		}
		if (tgrp != getpgrp()) {
			kill(0, SIGTTOU);
			goto retry;
		}
		if ((term = getenv("TERM")) == 0 || tgetent(buf, term) <= 0) {
			dumb++; ul_opt = 0;
		} else {
			if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) < 0) {
				Lpp = tgetnum("li");
				Mcol = tgetnum("co");
			} else {
				if ((Lpp = win.ws_row) == 0)
					Lpp = tgetnum("li");
				if ((Mcol = win.ws_col) == 0)
					Mcol = tgetnum("co");
			}
			if (Lpp <= 0 || tgetflag("hc")) {
				hard++;		/* Hard copy terminal */
				Lpp = 24;
			}
			if (tgetflag("xn")) {
				/* Eat newline at last column + 1 */
				eatnl++;
			}
			if (Mcol <= 0)
				Mcol = 80;

			if (strcmp(__progname, "page") == 0 ||
			    (!hard && tgetflag("ns")))
				noscroll++;
			Wrap = tgetflag("am");
			bad_so = tgetflag ("xs");
			clearptr = clearbuf;
			eraseln = tgetstr("ce", &clearptr);
			Clear = tgetstr("cl", &clearptr);
			Senter = tgetstr("so", &clearptr);
			Sexit = tgetstr("se", &clearptr);
			if ((soglitch = tgetnum("sg")) < 0)
				soglitch = 0;

			/*
			 * Setup for underlining.  Some terminals don't need it,
			 * others have start/stop sequences, still others have
			 * an underline char sequence which is assumed to move
			 * the cursor forward one character.  If underline seq
			 * isn't available, settle for standout sequence.
			 */
			if (tgetflag("ul") || tgetflag("os"))
				ul_opt = 0;
			if ((chUL = tgetstr("uc", &clearptr)) == NULL)
				chUL = "";
			if (((ULenter = tgetstr("us", &clearptr)) == NULL ||
			    (ULexit = tgetstr("ue", &clearptr)) == NULL) &&
			    !*chUL) {
				if ((ULenter = Senter) == NULL ||
				    (ULexit = Sexit) == NULL) {
					ULenter = "";
					ULexit = "";
				} else
					ulglitch = soglitch;
			} else {
				if ((ulglitch = tgetnum("ug")) < 0)
					ulglitch = 0;
			}

			if ((padstr = tgetstr("pc", &clearptr)))
				PC = *padstr;
			Home = tgetstr("ho", &clearptr);
			if (Home == 0 || *Home == '\0') {
				cursorm = tgetstr("cm", &clearptr);
				if (cursorm != NULL) {
					strlcpy(cursorhome,
					    tgoto(cursorm, 0, 0),
					    sizeof(cursorhome));
					Home = cursorhome;
				}
			}
			EodClr = tgetstr("cd", &clearptr);
			if ((chBS = tgetstr("bc", &clearptr)) == NULL)
				chBS = "\b";
			if (tgetstr("te", &clearptr) != NULL &&
			    tgetstr("ti", &clearptr) != NULL)
				altscr = 1;
		}
		if ((shell = getenv("SHELL")) == NULL)
			shell = _PATH_BSHELL;
	}
	no_intty = !isatty(STDIN_FILENO);
	tcgetattr(STDERR_FILENO, &otty);
	slow_tty = cfgetospeed(&otty) < B1200;
	hardtabs = !(otty.c_oflag & OXTABS);
	ntty = otty;
	if (!no_tty) {
		ntty.c_lflag &= ~(ICANON|ECHO);
		ntty.c_cc[VMIN] = 1;	/* read at least 1 char */
		ntty.c_cc[VTIME] = 0;	/* no timeout */
	}
}
Esempio n. 27
0
/*
 * Set up various conversions in 'mode', including parity, tabs, returns,
 * echo, and case, according to the termcap entry.  If the program we're
 * running was named with a leading upper-case character, map external
 * uppercase to internal lowercase.
 */
static void
set_conversions(void)
{
#ifdef __OBSOLETE__
    /*
     * Conversion logic for some *really* ancient terminal glitches,
     * not supported in terminfo.  Left here for succeeding generations
     * to marvel at.
     */
    if (tgetflag("UC")) {
#ifdef IUCLC
	mode.c_iflag |= IUCLC;
	mode.c_oflag |= OLCUC;
#endif
    } else if (tgetflag("LC")) {
#ifdef IUCLC
	mode.c_iflag &= ~IUCLC;
	mode.c_oflag &= ~OLCUC;
#endif
    }
    mode.c_iflag &= ~(PARMRK | INPCK);
    mode.c_lflag |= ICANON;
    if (tgetflag("EP")) {
	mode.c_cflag |= PARENB;
	mode.c_cflag &= ~PARODD;
    }
    if (tgetflag("OP")) {
	mode.c_cflag |= PARENB;
	mode.c_cflag |= PARODD;
    }
#endif /* __OBSOLETE__ */

#ifdef TERMIOS
#ifdef ONLCR
    mode.c_oflag |= ONLCR;
#endif
    mode.c_iflag |= ICRNL;
    mode.c_lflag |= ECHO;
#ifdef OXTABS
    mode.c_oflag |= OXTABS;
#endif /* OXTABS */

    /* test used to be tgetflag("NL") */
    if (newline != (char *) 0 && newline[0] == '\n' && !newline[1]) {
	/* Newline, not linefeed. */
#ifdef ONLCR
	mode.c_oflag &= ~ONLCR;
#endif
	mode.c_iflag &= ~ICRNL;
    }
#ifdef __OBSOLETE__
    if (tgetflag("HD"))		/* Half duplex. */
	mode.c_lflag &= ~ECHO;
#endif /* __OBSOLETE__ */
#ifdef OXTABS
    /* test used to be tgetflag("pt") */
    if (has_hardware_tabs)	/* Print tabs. */
	mode.c_oflag &= ~OXTABS;
#endif /* OXTABS */
    mode.c_lflag |= (ECHOE | ECHOK);
#endif
}
Esempio n. 28
0
/*
 * Figure out what kind of terminal we're dealing with, and then read in
 * its termcap entry.
 */
static const char *
get_termcap_entry(char *userarg)
{
    int errret;
    char *p;
    const char *ttype;
#if HAVE_GETTTYNAM
    struct ttyent *t;
#else
    FILE *fp;
#endif
    char *ttypath;

    if (userarg) {
	ttype = userarg;
	goto found;
    }

    /* Try the environment. */
    if ((ttype = getenv("TERM")) != 0)
	goto map;

    if ((ttypath = ttyname(STDERR_FILENO)) != 0) {
	p = _nc_basename(ttypath);
#if HAVE_GETTTYNAM
	/*
	 * We have the 4.3BSD library call getttynam(3); that means
	 * there's an /etc/ttys to look up device-to-type mappings in.
	 * Try ttyname(3); check for dialup or other mapping.
	 */
	if ((t = getttynam(p))) {
	    ttype = t->ty_type;
	    goto map;
	}
#else
	if ((fp = fopen("/etc/ttytype", "r")) != 0
	    || (fp = fopen("/etc/ttys", "r")) != 0) {
	    char buffer[BUFSIZ];
	    char *s, *t, *d;

	    while (fgets(buffer, sizeof(buffer), fp) != NULL) {
		for (s = buffer, t = d = 0; *s; s++) {
		    if (isspace(UChar(*s)))
			*s = '\0';
		    else if (t == 0)
			t = s;
		    else if (d == 0 && s != buffer && s[-1] == '\0')
			d = s;
		}
		if (t != 0 && d != 0 && !strcmp(d, p)) {
		    ttype = strdup(t);
		    fclose(fp);
		    goto map;
		}
	    }
	    fclose(fp);
	}
#endif /* HAVE_GETTTYNAM */
    }

    /* If still undefined, use "unknown". */
    ttype = "unknown";

  map:ttype = mapped(ttype);

    /*
     * If not a path, remove TERMCAP from the environment so we get a
     * real entry from /etc/termcap.  This prevents us from being fooled
     * by out of date stuff in the environment.
     */
  found:if ((p = getenv("TERMCAP")) != 0 && !_nc_is_abs_path(p)) {
	/* 'unsetenv("TERMCAP")' is not portable.
	 * The 'environ' array is better.
	 */
	int n;
	for (n = 0; environ[n] != 0; n++) {
	    if (!strncmp("TERMCAP=", environ[n], 8)) {
		while ((environ[n] = environ[n + 1]) != 0) {
		    n++;
		}
		break;
	    }
	}
    }

    /*
     * ttype now contains a pointer to the type of the terminal.
     * If the first character is '?', ask the user.
     */
    if (ttype[0] == '?') {
	if (ttype[1] != '\0')
	    ttype = askuser(ttype + 1);
	else
	    ttype = askuser(0);
    }
    /* Find the terminfo entry.  If it doesn't exist, ask the user. */
    while (setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO, &errret)
	   != OK) {
	if (errret == 0) {
	    (void) fprintf(stderr, "%s: unknown terminal type %s\n",
			   _nc_progname, ttype);
	    ttype = 0;
	} else {
	    (void) fprintf(stderr,
			   "%s: can't initialize terminal type %s (error %d)\n",
			   _nc_progname, ttype, errret);
	    ttype = 0;
	}
	ttype = askuser(ttype);
    }
#if BROKEN_LINKER
    tgetflag("am");		/* force lib_termcap.o to be linked for 'ospeed' */
#endif
    return (ttype);
}
Esempio n. 29
0
File: terms.c Progetto: thioshp/w3m
void
getTCstr(void)
{
    char *ent;
    char *suc;
    char *pt = funcstr;
    int r;

    ent = getenv("TERM") ? getenv("TERM") : DEFAULT_TERM;
    if (ent == NULL) {
	fprintf(stderr, "TERM is not set\n");
	reset_exit(SIGNAL_ARGLIST);
    }

    r = tgetent(bp, ent);
    if (r != 1) {
	/* Can't find termcap entry */
	fprintf(stderr, "Can't find termcap entry %s\n", ent);
	reset_exit(SIGNAL_ARGLIST);
    }

    GETSTR(T_ce, "ce");		/* clear to the end of line */
    GETSTR(T_cd, "cd");		/* clear to the end of display */
    GETSTR(T_kr, "nd");		/* cursor right */
    if (suc == NULL)
	GETSTR(T_kr, "kr");
    if (tgetflag("bs"))
	T_kl = "\b";		/* cursor left */
    else {
	GETSTR(T_kl, "le");
	if (suc == NULL)
	    GETSTR(T_kl, "kb");
	if (suc == NULL)
	    GETSTR(T_kl, "kl");
    }
    GETSTR(T_cr, "cr");		/* carriage return */
    GETSTR(T_ta, "ta");		/* tab */
    GETSTR(T_sc, "sc");		/* save cursor */
    GETSTR(T_rc, "rc");		/* restore cursor */
    GETSTR(T_so, "so");		/* standout mode */
    GETSTR(T_se, "se");		/* standout mode end */
    GETSTR(T_us, "us");		/* underline mode */
    GETSTR(T_ue, "ue");		/* underline mode end */
    GETSTR(T_md, "md");		/* bold mode */
    GETSTR(T_me, "me");		/* bold mode end */
    GETSTR(T_cl, "cl");		/* clear screen */
    GETSTR(T_cm, "cm");		/* cursor move */
    GETSTR(T_al, "al");		/* append line */
    GETSTR(T_sr, "sr");		/* scroll reverse */
    GETSTR(T_ti, "ti");		/* terminal init */
    GETSTR(T_te, "te");		/* terminal end */
    GETSTR(T_nd, "nd");		/* move right one space */
    GETSTR(T_eA, "eA");		/* enable alternative charset */
    GETSTR(T_as, "as");		/* alternative (graphic) charset start */
    GETSTR(T_ae, "ae");		/* alternative (graphic) charset end */
    GETSTR(T_ac, "ac");		/* graphics charset pairs */
    GETSTR(T_op, "op");		/* set default color pair to its original value */
#if defined( CYGWIN ) && CYGWIN < 1
    /* for TERM=pcansi on MS-DOS prompt. */
#if 0
    T_eA = "";
    T_as = "\033[12m";
    T_ae = "\033[10m";
    T_ac = "l\001k\002m\003j\004x\005q\006n\020a\024v\025w\026u\027t\031";
#endif
    T_eA = "";
    T_as = "";
    T_ae = "";
    T_ac = "";
#endif				/* CYGWIN */

    LINES = COLS = 0;
    setlinescols();
    setgraphchar();
}
Esempio n. 30
0
static int my_tgetflag(char *s) {
     return tgetflag(s);
}