Exemplo n.º 1
0
_nc_find_entry(const char *string,
	       const short *hash_table)
{
    int hashvalue;
    struct name_table_entry const *ptr = 0;
    struct name_table_entry const *real_table;

    hashvalue = hash_function(string);

    if (hash_table[hashvalue] >= 0) {
	real_table = _nc_get_table(hash_table != _nc_get_hash_table(FALSE));
	ptr = real_table + hash_table[hashvalue];
	while (strcmp(ptr->nte_name, string) != 0) {
	    if (ptr->nte_link < 0)
		return 0;
	    ptr = real_table + (ptr->nte_link + hash_table[HASHTABSIZE]);
	}
    }

    return (ptr);
}
Exemplo n.º 2
0
    for (token_type = _nc_get_token(silent);
	 token_type != EOF && token_type != NAMES;
	 token_type = _nc_get_token(silent)) {
	bool is_use = (strcmp(_nc_curr_token.tk_name, "use") == 0);
	bool is_tc = !is_use && (strcmp(_nc_curr_token.tk_name, "tc") == 0);
	if (is_use || is_tc) {
	    entryp->uses[entryp->nuses].name = _nc_save_str(_nc_curr_token.tk_valstring);
	    entryp->uses[entryp->nuses].line = _nc_curr_line;
	    entryp->nuses++;
	    if (entryp->nuses > 1 && is_tc) {
		BAD_TC_USAGE
	    }
	} else {
	    /* normal token lookup */
	    entry_ptr = _nc_find_entry(_nc_curr_token.tk_name,
				       _nc_get_hash_table(_nc_syntax));

	    /*
	     * Our kluge to handle aliasing.  The reason it's done
	     * this ugly way, with a linear search, is so the hashing
	     * machinery doesn't have to be made really complicated
	     * (also we get better warnings this way).  No point in
	     * making this case fast, aliased caps aren't common now
	     * and will get rarer.
	     */
	    if (entry_ptr == NOTFOUND) {
		const struct alias *ap;

		if (_nc_syntax == SYN_TERMCAP) {
		    if (entryp->nuses != 0) {
			BAD_TC_USAGE
Exemplo n.º 3
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);
}
Exemplo n.º 4
0
static int
tput(int argc, char *argv[])
{
    NCURSES_CONST char *name;
    char *s;
    int i, j, c;
    int status;
    FILE *f;

    check_aliases(name = argv[0]);
    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;

        if (set_lr_margin != 0) {
            PUTS(tparm(set_lr_margin, 0, columns - 1));
        } else if (set_left_margin_parm != 0
                   && set_right_margin_parm != 0) {
            PUTS(tparm(set_left_margin_parm, 0));
            PUTS(tparm(set_right_margin_parm, columns - 1));
        } else 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(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(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(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(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_2string != 0) {
            PUTS(init_2string);
        }
        FLUSH;
        return 0;
    }

    if (strcmp(name, "longname") == 0) {
        PUTS(longname());
        return 0;
    }
#if !PURE_TERMINFO
    {
        const struct name_table_entry *np;

        if ((np = _nc_find_entry(name, _nc_get_hash_table(1))) != 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;
            }
    }
#endif

    if ((status = tigetflag(name)) != -1) {
        return (status != 0);
    } else if ((status = tigetnum(name)) != CANCELLED_NUMERIC) {
        (void) printf("%d\n", status);
        return (0);
    } else if ((s = tigetstr(name)) == CANCELLED_STRING) {
        quit(4, "%s: unknown terminfo capability '%s'", prg_name, name);
    } else if (s != ABSENT_STRING) {
        if (argc > 1) {
            int k;
            int numbers[10];
            char *strings[10];

            /* 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 <= 9; k++) {
                numbers[k] = 0;
                strings[k] = 0;
            }

            switch (tparm_type(name)) {
            case Num_Str:
                s = tparm(s, numbers[1], strings[2]);
                break;
            case Num_Str_Str:
                s = tparm(s, numbers[1], strings[2], strings[3]);
                break;
            default:
                s = tparm(s,
                          numbers[1], numbers[2], numbers[3],
                          numbers[4], numbers[5], numbers[6],
                          numbers[7], numbers[8], numbers[9]);
                break;
            }
        }

        /* use putp() in order to perform padding */
        putp(s);
        return (0);
    }
    return (0);
}