Esempio n. 1
0
/*
**	funkey_local(test_list, status, ch)
**
**	Test program local function keys (pfloc)
*/
static void
funkey_local(
		TestList * t,
		int *state,
		int *ch)
{
    if (pkey_local) {
	int fk = 1;

	/* test local function key */
	sprintf(temp,
		"(pfloc) Set function key %d to execute a clear and print \"Done!\"", fk);
	ptextln(temp);
	sprintf(temp, "%sDone!", liberated(clear_screen));
	tc_putp(TPARM_2(pkey_local, fk, temp));
	sprintf(temp, "Hit function key %d.  Then hit return.", fk);
	ptextln(temp);
	(void) wait_here();
	flush_input();
	if (key_f1 && pkey_xmit) {
	    tc_putp(TPARM_2(pkey_xmit, fk, key_f1));
	}
    } else {
	ptextln("Function key execute local (pfloc), not present.");
    }

    generic_done_message(t, state, ch);
}
Esempio n. 2
0
/*
**	crum_os(test_list, status, ch)
**
**	(cup) test Cursor position on overstrike terminals
*/
static void
crum_os(
	struct test_list *t,
	int *state,
	int *ch)
{
	int i;

	if (cursor_address && over_strike) {
		put_clear();
		for (i = 0; i < columns - 2; i++) {
			tc_putch('|');
		}
		for (i = 1; i < lines - 2; i++) {
			put_crlf();
			tc_putch('_');
		}
		for (i = 0; i < columns - 2; i++) {
			tputs(TPARM_2(cursor_address, 0, i), lines, tc_putch);
			tc_putch('+');
		}
		for (i = 0; i < lines - 2; i++) {
			tputs(TPARM_2(cursor_address, i, 0), lines, tc_putch);
			tc_putch(']');
			tc_putch('_');
		}
		go_home();
		put_newlines(3);
		ptext("    All the characters should look the same.  ");
		generic_done_message(t, state, ch);
		put_clear();
	}
}
Esempio n. 3
0
/*
**	funkey_label(test_list, status, ch)
**
**	Test labels (nlab) (smln) (pln) (rmln) (lw) (lh)
*/
static void
funkey_label(
	struct test_list *t,
	int *state,
	int *ch)
{
	int i;
	char outbuf[256];

	if (num_labels == -1) {
		ptextln("Your terminal has no labels. (nlab)");
	} else {
		sprintf(temp, "Your terminal has %d labels (nlab) that are %d characters wide (lw) and %d lines high (lh)",
			num_labels, label_width, label_height);
		ptext(temp);
		ptextln(" Testing (smln) (pln) (rmln)");
		if (label_on) {
			tc_putp(label_on);
		}
		if (label_width <= 0) {
			label_width = sizeof(outbuf) - 1;
		}
		for (i = 1; i <= num_labels; i++) {
			sprintf(outbuf, "L%d..............................", i);
			outbuf[label_width] = '\0';
			tc_putp(TPARM_2(plab_norm, i, outbuf));
		}
		if (label_off) {
			ptext("Hit any key to remove the labels: ");
			(void) wait_here();
			tc_putp(label_off);
		}
	}
	generic_done_message(t, state, ch);
}
Esempio n. 4
0
/*
**	display_basic()
**
**	display the basic terminal definitions
*/
void
display_basic(void)
{
	put_str("Name: ");
	putln(ttytype);

	report_cap("\\r ^M (cr)", carriage_return);
	report_cap("\\n ^J (ind)", scroll_forward);
	report_cap("\\b ^H (cub1)", cursor_left);
	report_cap("\\t ^I (ht)", tab);
/*      report_cap("\\f ^L (ff)", form_feed);	*/
	if (newline) {
		/* OK if missing */
		report_cap("      (nel)", newline);
	}
	report_cap("      (clear)", clear_screen);
	if (!cursor_home && cursor_address) {
		report_cap("(cup) (home)", TPARM_2(cursor_address, 0, 0));
	} else {
		report_cap("      (home)", cursor_home);
	}
#ifdef user9
	report_cap("ENQ   (u9)", user9);
#endif
#ifdef user8
	report_cap("ACK   (u8)", user8);
#endif

	sprintf(temp, "\nTerminal size: %d x %d.  Baud rate: %u.  Frame size: %d.%d",
		columns, lines,
		tty_baud_rate,
		tty_frame_size >> 1,
		(tty_frame_size & 1) * 5);
	putln(temp);
}
Esempio n. 5
0
static void
reset_scroll_region(void)
/* Set the scroll-region to a known state (the default) */
{
    if (change_scroll_region) {
	TPUTS_TRACE("change_scroll_region");
	putp(TPARM_2(change_scroll_region, 0, screen_lines - 1));
    }
}
Esempio n. 6
0
/*
**	funkey_prog(test_list, status, ch)
**
**	Test program function keys (pfx)
*/
static void
funkey_prog(
	       TestList * t,
	       int *state,
	       int *ch)
{
    if (pkey_xmit) {
	int i;
	int fk = 1;
	char mm[256];

	/* test program function key */
	sprintf(temp,
		"(pfx) Set function key %d to transmit abc\\n", fk);
	ptextln(temp);
	tc_putp(TPARM_2(pkey_xmit, fk, "abc\n"));
	sprintf(temp, "Hit function key %d\n", fk);
	ptextln(temp);

	memset(mm, 0, (size_t) 4);
	for (i = 0; i < 4; ++i) {
	    int cc = getchp(STRIP_PARITY);
	    if (cc == EOF)
		break;
	    mm[i] = (char) cc;
	}
	mm[i] = '\0';

	put_crlf();
	if (mm[0] != 'a' || mm[1] != 'b' || mm[2] != 'c') {
	    sprintf(temp, "Error string received was: %s", expand(mm));
	    ptextln(temp);
	} else {
	    putln("Thank you\n");
	}
	flush_input();
	if (key_f1) {
	    tc_putp(TPARM_2(pkey_xmit, fk, key_f1));
	}
    } else {
	ptextln("Function key transmit (pfx), not present.");
    }
    generic_done_message(t, state, ch);
}
Esempio n. 7
0
/*
**	funkey_prog(test_list, status, ch)
**
**	Test program function keys (pfx)
*/
static void
funkey_prog(
	struct test_list *t,
	int *state,
	int *ch)
{
	int i, fk;
	char mm[256];

	fk = 1;	/* use function key 1 for now */
	if (pkey_xmit) {
		/* test program function key */
		sprintf(temp,
			"(pfx) Set function key %d to transmit abc\\n", fk);
		ptextln(temp);
		tc_putp(TPARM_2(pkey_xmit, fk, "abc\n"));
		sprintf(temp, "Hit function key %d\n", fk);
		ptextln(temp);
		for (i = 0; i < 4; ++i)
			mm[i] = (char) getchp(STRIP_PARITY);
		mm[i] = '\0';
		put_crlf();
		if (mm[0] != 'a' || mm[1] != 'b' || mm[2] != 'c') {
			sprintf(temp, "Error string received was: %s", expand(mm));
			ptextln(temp);
		} else {
			putln("Thank you\n");
		}
		flush_input();
		if (key_f1) {
			tc_putp(TPARM_2(pkey_xmit, fk, key_f1));
		}
	} else {
		ptextln("Function key transmit (pfx), not present.");
	}
	generic_done_message(t, state, ch);
}
Esempio n. 8
0
/*
 * Write the soft labels to the soft-key window.
 */
static void
slk_intern_refresh(SLK * slk)
{
    int i;
    int fmt = SP->slk_format;

    for (i = 0; i < slk->labcnt; i++) {
        if (slk->dirty || slk->ent[i].dirty) {
            if (slk->ent[i].visible) {
                if (num_labels > 0 && SLK_STDFMT(fmt)) {
                    if (i < num_labels) {
                        TPUTS_TRACE("plab_norm");
                        putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text));
                    }
                } else {
                    if (fmt == 4)
                        slk_paint_info(slk->win);
                    wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x);
                    if (SP->_slk) {
                        wattrset(slk->win, AttrOf(SP->_slk->attr));
                    }
                    waddstr(slk->win, slk->ent[i].form_text);
                    /* if we simulate SLK's, it's looking much more
                       natural to use the current ATTRIBUTE also
                       for the label window */
                    wattrset(slk->win, WINDOW_ATTRS(stdscr));
                }
            }
            slk->ent[i].dirty = FALSE;
        }
    }
    slk->dirty = FALSE;

    if (num_labels > 0) {
        if (slk->hidden) {
            TPUTS_TRACE("label_off");
            putp(label_off);
        } else {
            TPUTS_TRACE("label_on");
            putp(label_on);
        }
    }
}
Esempio n. 9
0
static NCURSES_INLINE int
onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
/* onscreen move from (yold, xold) to (ynew, xnew) */
{
    string_desc result;
    char buffer[OPT_SIZE];
    int tactic = 0, newcost, usecost = INFINITY;
    int t5_cr_cost;

#if defined(MAIN) || defined(NCURSES_TEST)
    struct timeval before, after;

    gettimeofday(&before, NULL);
#endif /* MAIN */

#define NullResult _nc_str_null(&result, sizeof(buffer))
#define InitResult _nc_str_init(&result, buffer, sizeof(buffer))

    /* tactic #0: use direct cursor addressing */
    if (_nc_safe_strcpy(InitResult, TPARM_2(SP->_address_cursor, ynew, xnew))) {
	tactic = 0;
	usecost = SP->_cup_cost;

#if defined(TRACE) || defined(NCURSES_TEST)
	if (!(_nc_optimize_enable & OPTIMIZE_MVCUR))
	    goto nonlocal;
#endif /* TRACE */

	/*
	 * We may be able to tell in advance that the full optimization
	 * will probably not be worth its overhead.  Also, don't try to
	 * use local movement if the current attribute is anything but
	 * A_NORMAL...there are just too many ways this can screw up
	 * (like, say, local-movement \n getting mapped to some obscure
	 * character because A_ALTCHARSET is on).
	 */
	if (yold == -1 || xold == -1 || NOT_LOCAL(yold, xold, ynew, xnew)) {
#if defined(MAIN) || defined(NCURSES_TEST)
	    if (!profiling) {
		(void) fputs("nonlocal\n", stderr);
		goto nonlocal;	/* always run the optimizer if profiling */
	    }
#else
	    goto nonlocal;
#endif /* MAIN */
	}
    }
#ifndef NO_OPTIMIZE
    /* tactic #1: use local movement */
    if (yold != -1 && xold != -1
	&& ((newcost = relative_move(NullResult, yold, xold, ynew, xnew,
				     ovw)) != INFINITY)
	&& newcost < usecost) {
	tactic = 1;
	usecost = newcost;
    }

    /* tactic #2: use carriage-return + local movement */
    if (yold != -1 && carriage_return
	&& ((newcost = relative_move(NullResult, yold, 0, ynew, xnew, ovw))
	    != INFINITY)
	&& SP->_cr_cost + newcost < usecost) {
	tactic = 2;
	usecost = SP->_cr_cost + newcost;
    }

    /* tactic #3: use home-cursor + local movement */
    if (cursor_home
	&& ((newcost = relative_move(NullResult, 0, 0, ynew, xnew, ovw)) != INFINITY)
	&& SP->_home_cost + newcost < usecost) {
	tactic = 3;
	usecost = SP->_home_cost + newcost;
    }

    /* tactic #4: use home-down + local movement */
    if (cursor_to_ll
	&& ((newcost = relative_move(NullResult, screen_lines - 1, 0, ynew,
				     xnew, ovw)) != INFINITY)
	&& SP->_ll_cost + newcost < usecost) {
	tactic = 4;
	usecost = SP->_ll_cost + newcost;
    }

    /*
     * tactic #5: use left margin for wrap to right-hand side,
     * unless strange wrap behavior indicated by xenl might hose us.
     */
    t5_cr_cost = (xold > 0 ? SP->_cr_cost : 0);
    if (auto_left_margin && !eat_newline_glitch
	&& yold > 0 && cursor_left
	&& ((newcost = relative_move(NullResult, yold - 1, screen_columns -
				     1, ynew, xnew, ovw)) != INFINITY)
	&& t5_cr_cost + SP->_cub1_cost + newcost < usecost) {
	tactic = 5;
	usecost = t5_cr_cost + SP->_cub1_cost + newcost;
    }

    /*
     * These cases are ordered by estimated relative frequency.
     */
    if (tactic)
	InitResult;
    switch (tactic) {
    case 1:
	(void) relative_move(&result, yold, xold, ynew, xnew, ovw);
	break;
    case 2:
	(void) _nc_safe_strcpy(&result, carriage_return);
	(void) relative_move(&result, yold, 0, ynew, xnew, ovw);
	break;
    case 3:
	(void) _nc_safe_strcpy(&result, cursor_home);
	(void) relative_move(&result, 0, 0, ynew, xnew, ovw);
	break;
    case 4:
	(void) _nc_safe_strcpy(&result, cursor_to_ll);
	(void) relative_move(&result, screen_lines - 1, 0, ynew, xnew, ovw);
	break;
    case 5:
	if (xold > 0)
	    (void) _nc_safe_strcat(&result, carriage_return);
	(void) _nc_safe_strcat(&result, cursor_left);
	(void) relative_move(&result, yold - 1, screen_columns - 1, ynew,
			     xnew, ovw);
	break;
    }
#endif /* !NO_OPTIMIZE */

  nonlocal:
#if defined(MAIN) || defined(NCURSES_TEST)
    gettimeofday(&after, NULL);
    diff = after.tv_usec - before.tv_usec
	+ (after.tv_sec - before.tv_sec) * 1000000;
    if (!profiling)
	(void) fprintf(stderr,
		       "onscreen: %d microsec, %f 28.8Kbps char-equivalents\n",
		       (int) diff, diff / 288);
#endif /* MAIN */

    if (usecost != INFINITY) {
	TPUTS_TRACE("mvcur");
	tputs(buffer, 1, _nc_outch);
	SP->_cursrow = ynew;
	SP->_curscol = xnew;
	return (OK);
    } else
	return (ERR);
}
Esempio n. 10
0
_nc_mvcur_init(void)
/* initialize the cost structure */
{
    if (isatty(fileno(SP->_ofp)))
	SP->_char_padding = ((BAUDBYTE * 1000 * 10)
			     / (BAUDRATE > 0 ? BAUDRATE : 9600));
    else
	SP->_char_padding = 1;	/* must be nonzero */
    if (SP->_char_padding <= 0)
	SP->_char_padding = 1;	/* must be nonzero */
    TR(TRACE_CHARPUT | TRACE_MOVE, ("char_padding %d msecs", SP->_char_padding));

    /* non-parameterized local-motion strings */
    SP->_cr_cost = CostOf(carriage_return, 0);
    SP->_home_cost = CostOf(cursor_home, 0);
    SP->_ll_cost = CostOf(cursor_to_ll, 0);
#if USE_HARD_TABS
    if (getenv("NCURSES_NO_HARD_TABS") == 0) {
	SP->_ht_cost = CostOf(tab, 0);
	SP->_cbt_cost = CostOf(back_tab, 0);
    } else {
	SP->_ht_cost = INFINITY;
	SP->_cbt_cost = INFINITY;
    }
#endif /* USE_HARD_TABS */
    SP->_cub1_cost = CostOf(cursor_left, 0);
    SP->_cuf1_cost = CostOf(cursor_right, 0);
    SP->_cud1_cost = CostOf(cursor_down, 0);
    SP->_cuu1_cost = CostOf(cursor_up, 0);

    SP->_smir_cost = CostOf(enter_insert_mode, 0);
    SP->_rmir_cost = CostOf(exit_insert_mode, 0);
    SP->_ip_cost = 0;
    if (insert_padding) {
	SP->_ip_cost = CostOf(insert_padding, 0);
    }

    /*
     * Assumption: if the terminal has memory_relative addressing, the
     * initialization strings or smcup will set single-page mode so we
     * can treat it like absolute screen addressing.  This seems to be true
     * for all cursor_mem_address terminal types in the terminfo database.
     */
    SP->_address_cursor = cursor_address ? cursor_address : cursor_mem_address;

    /*
     * Parametrized local-motion strings.  This static cost computation
     * depends on the following assumptions:
     *
     * (1) They never have * padding.  In the entire master terminfo database
     *     as of March 1995, only the obsolete Zenith Z-100 pc violates this.
     *     (Proportional padding is found mainly in insert, delete and scroll
     *     capabilities).
     *
     * (2) The average case of cup has two two-digit parameters.  Strictly,
     *     the average case for a 24 * 80 screen has ((10*10*(1 + 1)) +
     *     (14*10*(1 + 2)) + (10*70*(2 + 1)) + (14*70*4)) / (24*80) = 3.458
     *     digits of parameters.  On a 25x80 screen the average is 3.6197.
     *     On larger screens the value gets much closer to 4.
     *
     * (3) The average case of cub/cuf/hpa/ech/rep has 2 digits of parameters
     *     (strictly, (((10 * 1) + (70 * 2)) / 80) = 1.8750).
     *
     * (4) The average case of cud/cuu/vpa has 2 digits of parameters
     *     (strictly, (((10 * 1) + (14 * 2)) / 24) = 1.5833).
     *
     * All these averages depend on the assumption that all parameter values
     * are equally probable.
     */
    SP->_cup_cost = CostOf(TPARM_2(SP->_address_cursor, 23, 23), 1);
    SP->_cub_cost = CostOf(TPARM_1(parm_left_cursor, 23), 1);
    SP->_cuf_cost = CostOf(TPARM_1(parm_right_cursor, 23), 1);
    SP->_cud_cost = CostOf(TPARM_1(parm_down_cursor, 23), 1);
    SP->_cuu_cost = CostOf(TPARM_1(parm_up_cursor, 23), 1);
    SP->_hpa_cost = CostOf(TPARM_1(column_address, 23), 1);
    SP->_vpa_cost = CostOf(TPARM_1(row_address, 23), 1);

    /* non-parameterized screen-update strings */
    SP->_ed_cost = NormalizedCost(clr_eos, 1);
    SP->_el_cost = NormalizedCost(clr_eol, 1);
    SP->_el1_cost = NormalizedCost(clr_bol, 1);
    SP->_dch1_cost = NormalizedCost(delete_character, 1);
    SP->_ich1_cost = NormalizedCost(insert_character, 1);

    /*
     * If this is a bce-terminal, we want to bias the choice so we use clr_eol
     * rather than spaces at the end of a line.
     */
    if (back_color_erase)
	SP->_el_cost = 0;

    /* parameterized screen-update strings */
    SP->_dch_cost = NormalizedCost(TPARM_1(parm_dch, 23), 1);
    SP->_ich_cost = NormalizedCost(TPARM_1(parm_ich, 23), 1);
    SP->_ech_cost = NormalizedCost(TPARM_1(erase_chars, 23), 1);
    SP->_rep_cost = NormalizedCost(TPARM_2(repeat_char, ' ', 23), 1);

    SP->_cup_ch_cost = NormalizedCost(TPARM_2(SP->_address_cursor, 23, 23), 1);
    SP->_hpa_ch_cost = NormalizedCost(TPARM_1(column_address, 23), 1);
    SP->_cuf_ch_cost = NormalizedCost(TPARM_1(parm_right_cursor, 23), 1);
    SP->_inline_cost = min(SP->_cup_ch_cost,
			   min(SP->_hpa_ch_cost,
			       SP->_cuf_ch_cost));

    /*
     * If save_cursor is used within enter_ca_mode, we should not use it for
     * scrolling optimization, since the corresponding restore_cursor is not
     * nested on the various terminals (vt100, xterm, etc.) which use this
     * feature.
     */
    if (save_cursor != 0
	&& enter_ca_mode != 0
	&& strstr(enter_ca_mode, save_cursor) != 0) {
	T(("...suppressed sc/rc capability due to conflict with smcup/rmcup"));
	save_cursor = 0;
	restore_cursor = 0;
    }

    /*
     * A different, possibly better way to arrange this would be to set
     * SP->_endwin = TRUE at window initialization time and let this be
     * called by doupdate's return-from-shellout code.
     */
    _nc_mvcur_resume();
}
Esempio n. 11
0
/*
**	move_to(from-row, from-column, to-row, to-column, selection)
**
**	move the cursor from (rf, cf) to (rt, ct) using sel
*/
static void
move_to(
	int rf,
	int cf,
	int rt,
	int ct,
	int sel)
{
	char *s;

	if (sel & 16) {	/* use (cup) */
		s = TPARM_2(cursor_address, rt, ct);
		tputs(s, lines, tc_putch);
		return;
	}
	if (sel & 8) {	/* use (hpa) (vpa) */
		if (column_address) {
			s = TPARM_1(column_address, ct);
			tputs(s, 1, tc_putch);
			cf = ct;
		}
		if (row_address) {
			s = TPARM_1(row_address, rt);
			tputs(s, 1, tc_putch);
			rf = rt;
		}
	}
	if (sel & 4) {	/* parameterized relative cursor movement */
		if (parm_right_cursor)
			if (cf < ct) {
				s = TPARM_1(parm_right_cursor, ct - cf);
				tputs(s, ct - cf, tc_putch);
				cf = ct;
			}
		if (parm_left_cursor)
			if (cf > ct) {
				s = TPARM_1(parm_left_cursor, cf - ct);
				tputs(s, cf - ct, tc_putch);
				cf = ct;
			}
		if (parm_down_cursor)
			if (rf < rt) {
				s = TPARM_1(parm_down_cursor, rt - rf);
				tputs(s, rt - rf, tc_putch);
				rf = rt;
			}
		if (parm_up_cursor)
			if (rf > rt) {
				s = TPARM_1(parm_up_cursor, rf - rt);
				tputs(s, rf - rt, tc_putch);
				rf = rt;
			}
	}
	if (sel & 2) {
		if (cursor_left)
			while (cf > ct) {
				tc_putp(cursor_left);
				cf--;
			}
		/*
		   do vertical motion next.  Just in case cursor_down has a
		   side effect of changing the column.  This could happen if
		   the tty handler translates NL to CRNL.
		*/
		if (cursor_down)
			while (rf < rt) {
				tc_putp(cursor_down);
				rf++;
			}
		if (cursor_up)
			while (rf > rt) {
				tc_putp(cursor_up);
				rf--;
			}
		if (cursor_right)
			while (cf < ct) {
				tc_putp(cursor_right);
				cf++;
			}
	}
	/* last chance */
	if (rf > rt) {
		if (can_go_home) {	/* a bit drastic but ... */
			go_home();
			cf = 0;
			rf = 0;
		} else if (cursor_up) {
			while (rf > rt) {
				tc_putp(cursor_up);
				rf--;
			}
		}
	}
	if (ct == 0 && rt > rf) {
		put_crlf();
		cf = 0;
		rf++;
	}
	if (ct == 0 && cf != 0) {
		put_cr();
		cf = 0;
	}
	while (rf < rt) {
		put_lf();
		rf++;
	}
	while (cf > ct) {
		put_str("\b");
		cf--;
	}
	if (cursor_right) {
		while (cf < ct) {
			tc_putp(cursor_right);
			cf++;
		}
	} else {
		/* go ahead and trash my display */
		while (cf < ct) {
			putchp(' ');
			cf++;
		}
	}
}
Esempio n. 12
0
static int
tput(int argc, char *argv[])
{
    NCURSES_CONST char *name;
    char *s;
    int i, j, c;
    int status;
    FILE *f;
#if !PURE_TERMINFO
    bool termcap = FALSE;
#endif

    if ((name = argv[0]) == 0)
	name = "";
    check_aliases(name);
    if (is_reset || is_init) {
	if (init_prog != 0) {
	    system(init_prog);
	}
	FLUSH;

	if (is_reset && reset_1string != 0) {
	    PUTS(reset_1string);
	} else if (init_1string != 0) {
	    PUTS(init_1string);
	}
	FLUSH;

	if (is_reset && reset_2string != 0) {
	    PUTS(reset_2string);
	} else if (init_2string != 0) {
	    PUTS(init_2string);
	}
	FLUSH;

#ifdef set_lr_margin
	if (set_lr_margin != 0) {
	    PUTS(TPARM_2(set_lr_margin, 0, columns - 1));
	} else
#endif
#ifdef set_left_margin_parm
	    if (set_left_margin_parm != 0
		&& set_right_margin_parm != 0) {
	    PUTS(TPARM_1(set_left_margin_parm, 0));
	    PUTS(TPARM_1(set_right_margin_parm, columns - 1));
	} else
#endif
	    if (clear_margins != 0
		&& set_left_margin != 0
		&& set_right_margin != 0) {
	    PUTS(clear_margins);
	    if (carriage_return != 0) {
		PUTS(carriage_return);
	    } else {
		PUTCHAR('\r');
	    }
	    PUTS(set_left_margin);
	    if (parm_right_cursor) {
		PUTS(TPARM_1(parm_right_cursor, columns - 1));
	    } else {
		for (i = 0; i < columns - 1; i++) {
		    PUTCHAR(' ');
		}
	    }
	    PUTS(set_right_margin);
	    if (carriage_return != 0) {
		PUTS(carriage_return);
	    } else {
		PUTCHAR('\r');
	    }
	}
	FLUSH;

	if (init_tabs != 8) {
	    if (clear_all_tabs != 0 && set_tab != 0) {
		for (i = 0; i < columns - 1; i += 8) {
		    if (parm_right_cursor) {
			PUTS(TPARM_1(parm_right_cursor, 8));
		    } else {
			for (j = 0; j < 8; j++)
			    PUTCHAR(' ');
		    }
		    PUTS(set_tab);
		}
		FLUSH;
	    }
	}

	if (is_reset && reset_file != 0) {
	    f = fopen(reset_file, "r");
	    if (f == 0) {
		quit(4 + errno, "Can't open reset_file: '%s'", reset_file);
	    }
	    while ((c = fgetc(f)) != EOF) {
		PUTCHAR(c);
	    }
	    fclose(f);
	} else if (init_file != 0) {
	    f = fopen(init_file, "r");
	    if (f == 0) {
		quit(4 + errno, "Can't open init_file: '%s'", init_file);
	    }
	    while ((c = fgetc(f)) != EOF) {
		PUTCHAR(c);
	    }
	    fclose(f);
	}
	FLUSH;

	if (is_reset && reset_3string != 0) {
	    PUTS(reset_3string);
	} else if (init_3string != 0) {
	    PUTS(init_3string);
	}
	FLUSH;
	return 0;
    }

    if (strcmp(name, "longname") == 0) {
	PUTS(longname());
	return 0;
    }
#if !PURE_TERMINFO
  retry:
#endif
    if ((status = tigetflag(name)) != -1) {
	return exit_code(BOOLEAN, status);
    } else if ((status = tigetnum(name)) != CANCELLED_NUMERIC) {
	(void) printf("%d\n", status);
	return exit_code(NUMBER, 0);
    } else if ((s = tigetstr(name)) == CANCELLED_STRING) {
#if !PURE_TERMINFO
	if (!termcap) {
	    const struct name_table_entry *np;

	    termcap = TRUE;
	    if ((np = _nc_find_entry(name, _nc_get_hash_table(termcap))) != 0) {
		switch (np->nte_type) {
		case BOOLEAN:
		    if (bool_from_termcap[np->nte_index])
			name = boolnames[np->nte_index];
		    break;

		case NUMBER:
		    if (num_from_termcap[np->nte_index])
			name = numnames[np->nte_index];
		    break;

		case STRING:
		    if (str_from_termcap[np->nte_index])
			name = strnames[np->nte_index];
		    break;
		}
		goto retry;
	    }
	}
#endif
	quit(4, "unknown terminfo capability '%s'", name);
    } else if (s != ABSENT_STRING) {
	if (argc > 1) {
	    int k;
	    int popcount;
	    long numbers[1 + NUM_PARM];
	    char *strings[1 + NUM_PARM];
	    char *p_is_s[NUM_PARM];

	    /* Nasty hack time. The tparm function needs to see numeric
	     * parameters as numbers, not as pointers to their string
	     * representations
	     */

	    for (k = 1; k < argc; k++) {
		char *tmp = 0;
		strings[k] = argv[k];
		numbers[k] = strtol(argv[k], &tmp, 0);
		if (tmp == 0 || *tmp != 0)
		    numbers[k] = 0;
	    }
	    for (k = argc; k <= NUM_PARM; k++) {
		numbers[k] = 0;
		strings[k] = 0;
	    }

	    switch (tparm_type(name)) {
	    case Num_Str:
		s = TPARM_2(s, numbers[1], strings[2]);
		break;
	    case Num_Str_Str:
		s = TPARM_3(s, numbers[1], strings[2], strings[3]);
		break;
	    case Numbers:
	    default:
		(void) _nc_tparm_analyze(s, p_is_s, &popcount);
#define myParam(n) (p_is_s[n - 1] != 0 ? ((TPARM_ARG) strings[n]) : numbers[n])
		s = TPARM_9(s,
			    myParam(1),
			    myParam(2),
			    myParam(3),
			    myParam(4),
			    myParam(5),
			    myParam(6),
			    myParam(7),
			    myParam(8),
			    myParam(9));
		break;
	    }
	}

	/* use putp() in order to perform padding */
	putp(s);
	return exit_code(STRING, 0);
    }
    return exit_code(STRING, 1);
}
Esempio n. 13
0
/*
 * Write the soft labels to the soft-key window.
 */
static void
slk_intern_refresh(SCREEN *sp)
{
    int i;
    int fmt;
    SLK *slk;
    int numlab;

    if (sp == 0)
	return;

    slk = sp->_slk;
    fmt = sp->slk_format;
    numlab = NumLabels;

    if (slk->hidden)
	return;

    for (i = 0; i < slk->labcnt; i++) {
	if (slk->dirty || slk->ent[i].dirty) {
	    if (slk->ent[i].visible) {
		if (numlab > 0 && SLK_STDFMT(fmt)) {
#ifdef USE_TERM_DRIVER
		    CallDriver_2(sp, hwlabel, i + 1, slk->ent[i].form_text);
#else
		    if (i < num_labels) {
			TPUTS_TRACE("plab_norm");
			putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text));
		    }
#endif
		} else {
		    if (fmt == 4)
			slk_paint_info(slk->win);
		    wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x);
		    if (sp->_slk) {
			(void) wattrset(slk->win, AttrOf(sp->_slk->attr));
		    }
		    waddstr(slk->win, slk->ent[i].form_text);
		    /* if we simulate SLK's, it's looking much more
		       natural to use the current ATTRIBUTE also
		       for the label window */
		    (void) wattrset(slk->win, WINDOW_ATTRS(StdScreen(sp)));
		}
	    }
	    slk->ent[i].dirty = FALSE;
	}
    }
    slk->dirty = FALSE;

    if (numlab > 0) {
#ifdef USE_TERM_DRIVER
	CallDriver_1(sp, hwlabelOnOff, slk->hidden ? FALSE : TRUE);
#else
	if (slk->hidden) {
	    TPUTS_TRACE("label_off");
	    putp(label_off);
	} else {
	    TPUTS_TRACE("label_on");
	    putp(label_on);
	}
#endif
    }
}
Esempio n. 14
0
/* Output startup string. */
bool
send_init_strings(int fd GCC_UNUSED, TTY * old_settings)
{
    int i;
    bool need_flush = FALSE;

    (void) old_settings;
#ifdef TAB3
    if (old_settings != 0 &&
	old_settings->c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) {
	old_settings->c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET);
	SET_TTY(fd, old_settings);
    }
#endif
    if (use_reset || use_init) {
	if (VALID_STRING(init_prog)) {
	    IGNORE_RC(system(init_prog));
	}

	need_flush |= sent_string((use_reset && (reset_1string != 0))
				  ? reset_1string
				  : init_1string);

	need_flush |= sent_string((use_reset && (reset_2string != 0))
				  ? reset_2string
				  : init_2string);

#if defined(set_lr_margin)
	if (VALID_STRING(set_lr_margin)) {
	    need_flush |= sent_string(TPARM_2(set_lr_margin, 0,
					      columns - 1));
	} else
#endif
#if defined(set_left_margin_parm) && defined(set_right_margin_parm)
	    if (VALID_STRING(set_left_margin_parm)
		&& VALID_STRING(set_right_margin_parm)) {
	    need_flush |= sent_string(TPARM_1(set_left_margin_parm, 0));
	    need_flush |= sent_string(TPARM_1(set_right_margin_parm,
					      columns - 1));
	} else
#endif
	    if (VALID_STRING(clear_margins)
		&& VALID_STRING(set_left_margin)
		&& VALID_STRING(set_right_margin)) {
	    need_flush |= sent_string(clear_margins);
	    need_flush |= to_left_margin();
	    need_flush |= sent_string(set_left_margin);
	    if (VALID_STRING(parm_right_cursor)) {
		need_flush |= sent_string(TPARM_1(parm_right_cursor,
						  columns - 1));
	    } else {
		for (i = 0; i < columns - 1; i++) {
		    out_char(' ');
		    need_flush = TRUE;
		}
	    }
	    need_flush |= sent_string(set_right_margin);
	    need_flush |= to_left_margin();
	}

	need_flush |= reset_tabstops(columns);

	need_flush |= cat_file((use_reset && reset_file) ? reset_file : init_file);

	need_flush |= sent_string((use_reset && (reset_3string != 0))
				  ? reset_3string
				  : init_3string);
    }

    return need_flush;
}