Example #1
0
NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx NCURSES_CONST char *str)
{
    char *result = CANCELLED_STRING;
    int j = -1;

    T((T_CALLED("tigetstr(%p, %s)"), (void *) SP_PARM, str));

    if (HasTInfoTerminal(SP_PARM)) {
	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
	struct name_table_entry const *entry_ptr;

	entry_ptr = _nc_find_type_entry(str, STRING, FALSE);
	if (entry_ptr != 0) {
	    j = entry_ptr->nte_index;
	}
#if NCURSES_XNAMES
	else {
	    int i;
	    for_each_ext_string(i, tp) {
		const char *capname = ExtStrname(tp, i, strnames);
		if (same_name(str, capname)) {
		    j = i;
		    break;
		}
	    }
	}
#endif
	if (j >= 0) {
	    /* note: setupterm forces cancelled strings to null */
	    result = tp->Strings[j];
	}
    }

    returnPtr(result);
}
Example #2
0
NCURSES_SP_NAME(tgetstr) (NCURSES_SP_DCLx NCURSES_CONST char *id, char **area)
{
    char *result = NULL;
    int i, j;

    T((T_CALLED("tgetstr(%s,%p)"), id, (void *) area));
    if (HasTInfoTerminal(SP_PARM)) {
	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
	struct name_table_entry const *entry_ptr;

	entry_ptr = _nc_find_type_entry(id, STRING, TRUE);
	if (entry_ptr != 0) {
	    j = entry_ptr->nte_index;
	}
#if NCURSES_XNAMES
	else {
	    j = -1;
	    for_each_ext_string(i, tp) {
		const char *capname = ExtStrname(tp, i, strcodes);
		if (same_tcname(id, capname)) {
		    j = i;
		    break;
		}
	    }
	}
#endif
	if (j >= 0) {
	    result = tp->Strings[j];
	    TR(TRACE_DATABASE, ("found match : %s", _nc_visbuf(result)));
	    /* setupterm forces canceled strings to null */
	    if (VALID_STRING(result)) {
		if (result == exit_attribute_mode
		    && FIX_SGR0 != 0) {
		    result = FIX_SGR0;
		    TR(TRACE_DATABASE, ("altered to : %s", _nc_visbuf(result)));
		}
		if (area != 0
		    && *area != 0) {
		    (void) strcpy(*area, result);
		    result = *area;
		    *area += strlen(*area) + 1;
		}
	    }
	}
    }
    returnPtr(result);
}
Example #3
0
_nc_init_keytry(SCREEN *sp)
{
    unsigned n;

    /* The sp->_keytry value is initialized in newterm(), where the sp
     * structure is created, because we can not tell where keypad() or
     * mouse_activate() (which will call keyok()) are first called.
     */

    if (sp != 0) {
	for (n = 0; _nc_tinfo_fkeys[n].code; n++) {
	    if (_nc_tinfo_fkeys[n].offset < STRCOUNT) {
		(void) _nc_add_to_try(&(sp->_keytry),
				      CUR Strings[_nc_tinfo_fkeys[n].offset],
				      _nc_tinfo_fkeys[n].code);
	    }
	}
#if NCURSES_XNAMES
	/*
	 * Add any of the extended strings to the tries if their name begins
	 * with 'k', i.e., they follow the convention of other terminfo key
	 * names.
	 */
	{
	    TERMTYPE *tp = &(sp->_term->type);
	    for (n = STRCOUNT; n < NUM_STRINGS(tp); ++n) {
		const char *name = ExtStrname(tp, (int) n, strnames);
		char *value = tp->Strings[n];
		if (name != 0
		    && *name == 'k'
		    && value != 0
		    && NCURSES_SP_NAME(key_defined) (NCURSES_SP_ARGx
						     value) == 0) {
		    (void) _nc_add_to_try(&(sp->_keytry),
					  value,
					  n - STRCOUNT + KEY_MAX);
		}
	    }
	}
#endif
#ifdef TRACE
	_nc_trace_tries(sp->_keytry);
#endif
    }
}
Example #4
0
NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *sp, int c)
{
	int i;
	char name[20];
	char *p;
	NCURSES_CONST char *result = 0;

	if (c == -1) {
		result = "-1";
	} else {
		for (i = 0; _nc_key_names[i].offset != -1; i++) {
			if (_nc_key_names[i].code == c) {
				result = (NCURSES_CONST char *)key_names + _nc_key_names[i].offset;
				break;
			}
		}

		if (result == 0 && (c >= 0 && c < SIZEOF_TABLE)) {
			if (MyTable == 0)
				MyTable = typeCalloc(char *, SIZEOF_TABLE);
			if (MyTable != 0) {
				if (MyTable[c] == 0) {
					int cc = c;
					p = name;
					if (cc >= 128 && (sp == 0 || sp->_use_meta)) {
						strcpy(p, "M-");
						p += 2;
						cc -= 128;
					}
					if (cc < 32)
						sprintf(p, "^%c", cc + '@');
					else if (cc == 127)
						strcpy(p, "^?");
					else
						sprintf(p, "%c", cc);
					MyTable[c] = strdup(name);
				}
				result = MyTable[c];
			}
#if NCURSES_EXT_FUNCS && NCURSES_XNAMES
		} else if (result == 0 && cur_term != 0) {
			int j, k;
			char * bound;
			TERMTYPE *tp = &(cur_term->type);
			int save_trace = _nc_tracing;

			_nc_tracing = 0;	/* prevent recursion via keybound() */
			for (j = 0; (bound = keybound(c, j)) != 0; ++j) {
				for(k = STRCOUNT; k < (int) NUM_STRINGS(tp);  k++) {
					if (tp->Strings[k] != 0 && !strcmp(bound, tp->Strings[k])) {
						result = ExtStrname(tp, k, strnames);
						break;
					}
				}
				free(bound);
				if (result != 0)
					break;
			}
			_nc_tracing = save_trace;
#endif
		}
	}
Example #5
0
static void
demo_terminfo(char *name)
{
    unsigned n;
    NCURSES_CONST char *cap;

    printf("Terminal type \"%s\"\n", name);
    setupterm(name, 1, (int *) 0);

    if (b_opt) {
	for (n = 0;; ++n) {
	    cap = f_opt ? boolfnames[n] : boolnames[n];
	    if (cap == 0)
		break;
	    dumpit(cap);
	}
    }

    if (n_opt) {
	for (n = 0;; ++n) {
	    cap = f_opt ? numfnames[n] : numnames[n];
	    if (cap == 0)
		break;
	    dumpit(cap);
	}
    }

    if (s_opt) {
	for (n = 0;; ++n) {
	    cap = f_opt ? strfnames[n] : strnames[n];
	    if (cap == 0)
		break;
	    dumpit(cap);
	}
    }
#ifdef NCURSES_VERSION
    if (x_opt) {
	int mod;
	if (f_opt) {
#if NCURSES_XNAMES
	    TERMTYPE *term = &(cur_term->type);
	    if (term != 0
		&& ((NUM_BOOLEANS(term) != BOOLCOUNT)
		    || (NUM_NUMBERS(term) != NUMCOUNT)
		    || (NUM_STRINGS(term) != STRCOUNT))) {
		for (n = BOOLCOUNT; n < NUM_BOOLEANS(term); ++n) {
		    dumpit(ExtBoolname(term, (int) n, boolnames));
		}
		for (n = NUMCOUNT; n < NUM_NUMBERS(term); ++n) {
		    dumpit(ExtNumname(term, (int) n, numnames));
		}
		for (n = STRCOUNT; n < NUM_STRINGS(term); ++n) {
		    dumpit(ExtStrname(term, (int) n, strnames));
		}
	    }
#endif
	} else {
	    char temp[10];
	    static const char *xterm_keys[] =
	    {
		"kDC", "kDN", "kEND", "kHOM", "kIC",
		"kLFT", "kNXT", "kPRV", "kRIT", "kUP",
	    };
	    for (n = 0; n < SIZEOF(xterm_keys); ++n) {
		for (mod = 0; mod < 8; ++mod) {
		    if (mod == 0)
			strcpy(temp, xterm_keys[n]);
		    else
			sprintf(temp, "%s%d", xterm_keys[n], mod);
		    dumpit(temp);
		}
	    }
	}
    }
#endif

}
safe_keyname (SCREEN *sp, int c)
{
	int i;
	char name[20];
	char *p;
	NCURSES_CONST char *result = 0;

	if (c == -1) {
		result = "-1";
	} else {
		for (i = 0; _nc_key_names[i].offset != -1; i++) {
			if (_nc_key_names[i].code == c) {
				result = (NCURSES_CONST char *)key_names + _nc_key_names[i].offset;
				break;
			}
		}

		if (result == 0 && (c >= 0 && c < SIZEOF_TABLE)) {
			if (MyTable == 0)
				MyTable = typeCalloc(char *, SIZEOF_TABLE);

			if (MyTable != 0) {
				int m_prefix = (sp == 0 || sp->_use_meta);

				/* if sense of meta() changed, discard cached data */
				if (MyInit != (m_prefix + 1)) {
					MyInit = m_prefix + 1;
					for (i = 0; i < SIZEOF_TABLE; ++i) {
						if (MyTable[i]) {
							FreeAndNull(MyTable[i]);
						}
					}
				}

				/* create and cache result as needed */
				if (MyTable[c] == 0) {
					int cc = c;
					p = name;
#define P_LIMIT (sizeof(name) - (size_t) (p - name))
					if (cc >= 128 && m_prefix) {
						_nc_STRCPY(p, "M-", P_LIMIT);
						p += 2;
						cc -= 128;
					}
					if (cc < 32)
						_nc_SPRINTF(p, _nc_SLIMIT(P_LIMIT) "^%c", cc + '@');
					else if (cc == 127)
						_nc_STRCPY(p, "^?", P_LIMIT);
					else
						_nc_SPRINTF(p, _nc_SLIMIT(P_LIMIT) "%c", cc);
					MyTable[c] = strdup(name);
				}
				result = MyTable[c];
			}
#if NCURSES_EXT_FUNCS && NCURSES_XNAMES
		} else if (result == 0 && HasTerminal(sp)) {
			int j, k;
			char * bound;
			TERMTYPE *tp = &(TerminalOf(sp)->type);
			unsigned save_trace = _nc_tracing;

			_nc_tracing = 0;	/* prevent recursion via keybound() */
			for (j = 0; (bound = NCURSES_SP_NAME(keybound)(NCURSES_SP_ARGx c, j)) != 0; ++j) {
				for(k = STRCOUNT; k < (int) NUM_STRINGS(tp);  k++) {
					if (tp->Strings[k] != 0 && !strcmp(bound, tp->Strings[k])) {
						result = ExtStrname(tp, k, strnames);
						break;
					}
				}
				free(bound);
				if (result != 0)
					break;
			}
			_nc_tracing = save_trace;
#endif
		}
	}