82 lines
1.4 KiB
C
82 lines
1.4 KiB
C
#include <stddef.h>
|
|
|
|
#include "ansi_table.h"
|
|
|
|
Entry *ansi_table_lookup(Table *t, unsigned char code)
|
|
{
|
|
struct table_col **table;
|
|
struct table_col *column = NULL;
|
|
struct table_entry *entry = NULL;
|
|
unsigned int row, col, lr;
|
|
|
|
col = (code & 0xF0) >> 4;
|
|
row = code & 0xF;
|
|
lr = !!(col & 0x8);
|
|
col = col & 0x7;
|
|
|
|
if (lr == 0) {
|
|
if (col < 2) {
|
|
table = t->c0->cols;
|
|
} else {
|
|
col = col - 2;
|
|
table = t->gl->cols;
|
|
}
|
|
} else {
|
|
if (col < 2) {
|
|
table = t->c1->cols;
|
|
} else {
|
|
col = col - 2;
|
|
table = t->gr->cols;
|
|
}
|
|
}
|
|
if (table) {
|
|
column = table[col];
|
|
}
|
|
if (column) {
|
|
entry = column->rows[row];
|
|
}
|
|
|
|
return entry;
|
|
}
|
|
|
|
Entry* csi_table_lookup(CsTable *t, int ic, unsigned char *iv, unsigned char f)
|
|
{
|
|
struct table_col **table;
|
|
struct table_col *column = NULL;
|
|
struct table_entry *entry = NULL;
|
|
unsigned int row, col, code;
|
|
|
|
if (ic > 1) return NULL;
|
|
|
|
if (ic == 1) {
|
|
code = iv[0];
|
|
|
|
col = (code & 0xF0) >> 4;
|
|
row = code & 0xF;
|
|
|
|
/* I values must come from column 2 */
|
|
if (col != 0x2) return NULL;
|
|
|
|
table = t->with_i[row]->cols;
|
|
} else {
|
|
table = t->no_i->cols;
|
|
}
|
|
|
|
if (table) {
|
|
col = (f & 0xF0) >> 4;
|
|
|
|
/* F values must come from columns 4-7 */
|
|
if (col < 0x4 || col > 0x7) return NULL;
|
|
col = col - 0x4;
|
|
|
|
column = table[col];
|
|
}
|
|
|
|
if (column) {
|
|
row = f & 0xF;
|
|
entry = column->rows[row];
|
|
}
|
|
|
|
return entry;
|
|
}
|