1
0
mirror of https://github.com/irssi/irssi.git synced 2025-02-02 15:08:01 -05:00

Simplify computation of TERM_REC fields offsets using G_STRUCT_OFFSET/G_STRUCT_MEMBER_P.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4807 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Emanuele Giaquinta 2008-04-20 09:24:12 +00:00 committed by exg
parent 7bd938542e
commit 0957ac5dfe

View File

@ -43,67 +43,66 @@ typedef struct {
const char *ti_name; /* terminfo name */ const char *ti_name; /* terminfo name */
const char *tc_name; /* termcap name */ const char *tc_name; /* termcap name */
int type; int type;
void *ptr; unsigned int offset;
} TERMINFO_REC; } TERMINFO_REC;
TERM_REC *current_term; TERM_REC *current_term;
static TERM_REC temp_term; /* not really used for anything */
/* Define only what we might need */ /* Define only what we might need */
static TERMINFO_REC tcaps[] = { static TERMINFO_REC tcaps[] = {
/* Terminal size */ /* Terminal size */
{ "cols", "co", CAP_TYPE_INT, &temp_term.width }, { "cols", "co", CAP_TYPE_INT, G_STRUCT_OFFSET(TERM_REC, width) },
{ "lines", "li", CAP_TYPE_INT, &temp_term.height }, { "lines", "li", CAP_TYPE_INT, G_STRUCT_OFFSET(TERM_REC, height) },
/* Cursor movement */ /* Cursor movement */
{ "smcup", "ti", CAP_TYPE_STR, &temp_term.TI_smcup }, { "smcup", "ti", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_smcup) },
{ "rmcup", "te", CAP_TYPE_STR, &temp_term.TI_rmcup }, { "rmcup", "te", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_rmcup) },
{ "cup", "cm", CAP_TYPE_STR, &temp_term.TI_cup }, { "cup", "cm", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_cup) },
{ "hpa", "ch", CAP_TYPE_STR, &temp_term.TI_hpa }, { "hpa", "ch", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_hpa) },
{ "vpa", "vh", CAP_TYPE_STR, &temp_term.TI_vpa }, { "vpa", "vh", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_vpa) },
{ "cub1", "le", CAP_TYPE_STR, &temp_term.TI_cub1 }, { "cub1", "le", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_cub1) },
{ "cuf1", "nd", CAP_TYPE_STR, &temp_term.TI_cuf1 }, { "cuf1", "nd", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_cuf1) },
{ "civis", "vi", CAP_TYPE_STR, &temp_term.TI_civis }, { "civis", "vi", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_civis) },
{ "cnorm", "ve", CAP_TYPE_STR, &temp_term.TI_cnorm }, { "cnorm", "ve", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_cnorm) },
/* Scrolling */ /* Scrolling */
{ "csr", "cs", CAP_TYPE_STR, &temp_term.TI_csr }, { "csr", "cs", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_csr) },
{ "wind", "wi", CAP_TYPE_STR, &temp_term.TI_wind }, { "wind", "wi", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_wind) },
{ "ri", "sr", CAP_TYPE_STR, &temp_term.TI_ri }, { "ri", "sr", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_ri) },
{ "rin", "SR", CAP_TYPE_STR, &temp_term.TI_rin }, { "rin", "SR", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_rin) },
{ "ind", "sf", CAP_TYPE_STR, &temp_term.TI_ind }, { "ind", "sf", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_ind) },
{ "indn", "SF", CAP_TYPE_STR, &temp_term.TI_indn }, { "indn", "SF", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_indn) },
{ "il", "AL", CAP_TYPE_STR, &temp_term.TI_il }, { "il", "AL", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_il) },
{ "il1", "al", CAP_TYPE_STR, &temp_term.TI_il1 }, { "il1", "al", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_il1) },
{ "dl", "DL", CAP_TYPE_STR, &temp_term.TI_dl }, { "dl", "DL", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_dl) },
{ "dl1", "dl", CAP_TYPE_STR, &temp_term.TI_dl1 }, { "dl1", "dl", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_dl1) },
/* Clearing screen */ /* Clearing screen */
{ "clear", "cl", CAP_TYPE_STR, &temp_term.TI_clear }, { "clear", "cl", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_clear) },
{ "ed", "cd", CAP_TYPE_STR, &temp_term.TI_ed }, { "ed", "cd", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_ed) },
/* Clearing to end of line */ /* Clearing to end of line */
{ "el", "ce", CAP_TYPE_STR, &temp_term.TI_el }, { "el", "ce", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_el) },
/* Repeating character */ /* Repeating character */
{ "rep", "rp", CAP_TYPE_STR, &temp_term.TI_rep }, { "rep", "rp", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_rep) },
/* Colors */ /* Colors */
{ "colors", "Co", CAP_TYPE_INT, &temp_term.TI_colors }, { "colors", "Co", CAP_TYPE_INT, G_STRUCT_OFFSET(TERM_REC, TI_colors) },
{ "sgr0", "me", CAP_TYPE_STR, &temp_term.TI_sgr0 }, { "sgr0", "me", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_sgr0) },
{ "smul", "us", CAP_TYPE_STR, &temp_term.TI_smul }, { "smul", "us", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_smul) },
{ "rmul", "ue", CAP_TYPE_STR, &temp_term.TI_rmul }, { "rmul", "ue", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_rmul) },
{ "smso", "so", CAP_TYPE_STR, &temp_term.TI_smso }, { "smso", "so", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_smso) },
{ "rmso", "se", CAP_TYPE_STR, &temp_term.TI_rmso }, { "rmso", "se", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_rmso) },
{ "bold", "md", CAP_TYPE_STR, &temp_term.TI_bold }, { "bold", "md", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_bold) },
{ "blink", "mb", CAP_TYPE_STR, &temp_term.TI_blink }, { "blink", "mb", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_blink) },
{ "setaf", "AF", CAP_TYPE_STR, &temp_term.TI_setaf }, { "setaf", "AF", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_setaf) },
{ "setab", "AB", CAP_TYPE_STR, &temp_term.TI_setab }, { "setab", "AB", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_setab) },
{ "setf", "Sf", CAP_TYPE_STR, &temp_term.TI_setf }, { "setf", "Sf", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_setf) },
{ "setb", "Sb", CAP_TYPE_STR, &temp_term.TI_setb }, { "setb", "Sb", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_setb) },
/* Beep */ /* Beep */
{ "bel", "bl", CAP_TYPE_STR, &temp_term.TI_bel }, { "bel", "bl", CAP_TYPE_STR, G_STRUCT_OFFSET(TERM_REC, TI_bel) },
}; };
/* Move cursor (cursor_address / cup) */ /* Move cursor (cursor_address / cup) */
@ -368,7 +367,7 @@ static void term_fill_capabilities(TERM_REC *term)
char *tptr = term->buffer2; char *tptr = term->buffer2;
#endif #endif
for (i = 0; i < sizeof(tcaps)/sizeof(tcaps[0]); i++) { for (i = 0; i < sizeof(tcaps)/sizeof(tcaps[0]); i++) {
ptr = (char *) term + (int) ((char *) tcaps[i].ptr - (char *) &temp_term); ptr = G_STRUCT_MEMBER_P(term, tcaps[i].offset);
switch (tcaps[i].type) { switch (tcaps[i].type) {
case CAP_TYPE_FLAG: case CAP_TYPE_FLAG: