X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=madtty%2Finject.c;h=29755fb91610292894d42653aa7703780729f49b;hb=f825f4ca53c05c78e52b7e007e07ad76587fb46c;hp=5d1f7d792274d4575ba71d7660d7e787561be026;hpb=f46c74119660de56f0bdc40f75d74acd3abf86fb;p=apps%2Fmadtty.git diff --git a/madtty/inject.c b/madtty/inject.c index 5d1f7d7..29755fb 100644 --- a/madtty/inject.c +++ b/madtty/inject.c @@ -24,20 +24,29 @@ #include #include "madtty.h" -#include "roteprivate.h" +#include "madtty_priv.h" #define MAX_CSI_ES_PARAMS 32 static inline void clamp_cursor_to_bounds(RoteTerm *rt) { - if (rt->crow < 0) rt->curpos_dirty = true, rt->crow = 0; - if (rt->ccol < 0) rt->curpos_dirty = true, rt->ccol = 0; - - if (rt->crow >= rt->rows) - rt->curpos_dirty = true, rt->crow = rt->rows - 1; + if (rt->crow < 0) { + rt->curpos_dirty = true; + rt->crow = 0; + } + if (rt->ccol < 0) { + rt->curpos_dirty = true; + rt->ccol = 0; + } - if (rt->ccol >= rt->cols) - rt->curpos_dirty = true, rt->ccol = rt->cols - 1; + if (rt->crow >= rt->rows) { + rt->curpos_dirty = true; + rt->crow = rt->rows - 1; + } + if (rt->ccol >= rt->cols) { + rt->curpos_dirty = true; + rt->ccol = rt->cols - 1; + } } static void cursor_line_down(RoteTerm *rt) @@ -62,7 +71,7 @@ static void cursor_line_down(RoteTerm *rt) /* clear last row of the scrolling region */ for (i = 0; i < rt->cols; i++) { - rt->cells[rt->pd->scrollbottom][i].ch = 0x20; + rt->cells[rt->pd->scrollbottom][i].ch = 0x20; rt->cells[rt->pd->scrollbottom][i].attr = 0x70; } } @@ -89,12 +98,12 @@ static void cursor_line_up(RoteTerm *rt) /* clear first row of the scrolling region */ for (i = 0; i < rt->cols; i++) { - rt->cells[rt->pd->scrolltop][i].ch = 0x20; + rt->cells[rt->pd->scrolltop][i].ch = 0x20; rt->cells[rt->pd->scrolltop][i].attr = 0x70; } } -static inline void put_normal_char(RoteTerm *rt, char c) +static inline void put_normal_char(RoteTerm *rt, int c) { if (rt->ccol >= rt->cols) { rt->ccol = 0; @@ -104,11 +113,12 @@ static inline void put_normal_char(RoteTerm *rt, char c) if (rt->insert) { int i; - for(i = rt->cols - 1; i >= rt->ccol+1; i--) + for(i = rt->cols - 1; i >= rt->ccol+1; i--) { rt->cells[rt->crow][i] = rt->cells[rt->crow][i-1]; + } } - rt->cells[rt->crow][rt->ccol].ch = c; + rt->cells[rt->crow][rt->ccol].ch = c; rt->cells[rt->crow][rt->ccol].attr = rt->curattr; rt->ccol++; @@ -116,7 +126,7 @@ static inline void put_normal_char(RoteTerm *rt, char c) rt->curpos_dirty = true; } -static inline void put_graphmode_char(RoteTerm *rt, char c) +static inline void put_graphmode_char(RoteTerm *rt, int c) { char nc; /* do some very pitiful translation to regular ascii chars */ @@ -155,17 +165,19 @@ static void handle_control_char(RoteTerm *rt, int c) break; case '\n': /* line feed */ - rt->ccol = 0; cursor_line_down(rt); + rt->ccol = 0; + cursor_line_down(rt); rt->curpos_dirty = true; break; case '\b': /* backspace */ - if (rt->ccol > 0) rt->ccol--; + if (rt->ccol > 0) + rt->ccol--; rt->curpos_dirty = true; break; case '\t': /* tab */ - rt->ccol += 8 - (rt->ccol % 8); + rt->ccol = (rt->ccol + 8) & ~7; clamp_cursor_to_bounds(rt); break; @@ -197,7 +209,7 @@ static void handle_control_char(RoteTerm *rt, int c) } } -static inline bool is_valid_csi_ender(char c) +static inline bool is_valid_csi_ender(int c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') @@ -209,29 +221,8 @@ static void try_interpret_escape_seq(RoteTerm *rt) char firstchar = rt->pd->esbuf[0]; char lastchar = rt->pd->esbuf[rt->pd->esbuf_len-1]; - if (!firstchar) return; /* too early to do anything */ - - if (rt->pd->handler) { - /* call custom handler */ - - int answer = (*(rt->pd->handler))(rt, rt->pd->esbuf); - if (answer == ROTE_HANDLERESULT_OK) { - /* successfully handled */ - - cancel_escape_sequence(rt); - return; - } else - if (answer == ROTE_HANDLERESULT_NOTYET) { - /* handler might handle it when more characters are appended to - * it. So for now we don't interpret it */ - return; - } - - /* If we got here then answer == ROTE_HANDLERESULT_NOWAY */ - /* handler said it can't handle that escape sequence, - * but we can still try handling it ourselves, so - * we proceed normally. */ - } + if (!firstchar) + return; /* too early to do anything */ /* interpret ESC-M as reverse line-feed */ if (firstchar == 'M') { @@ -263,15 +254,10 @@ static void try_interpret_escape_seq(RoteTerm *rt) cancel_escape_sequence(rt); } -void rote_vt_inject(RoteTerm *rt, const char *data, int len) +int rote_vt_inject(RoteTerm *rt, const char *data, int len) { - int i; - - for (i = 0; i < len; i++, data++) { - if (*data == 0) - continue; /* completely ignore NUL */ - - if (*data >= 1 && *data <= 31) { + for (; len-- > 0; data++) { + if ((unsigned char)*data <= 31) { handle_control_char(rt, *data); continue; } @@ -289,6 +275,8 @@ void rote_vt_inject(RoteTerm *rt, const char *data, int len) put_normal_char(rt, *data); } } + + return 0; } /****************************************************************************/ @@ -391,7 +379,7 @@ static void interpret_csi_ED(RoteTerm *rt, int param[], int pcount) c <= (r == end_row ? end_col : rt->cols - 1); c++) { - rt->cells[r][c].ch = 0x20; + rt->cells[r][c].ch = 0x20; rt->cells[r][c].attr = rt->curattr; } } @@ -451,7 +439,7 @@ static void interpret_csi_EL(RoteTerm *rt, int param[], int pcount) } for (i = erase_start; i <= erase_end; i++) { - rt->cells[rt->crow][i].ch = 0x20; + rt->cells[rt->crow][i].ch = 0x20; rt->cells[rt->crow][i].attr = rt->curattr; } @@ -469,7 +457,7 @@ static void interpret_csi_ICH(RoteTerm *rt, int param[], int pcount) } for (i = rt->ccol; i < rt->ccol + n; i++) { - rt->cells[rt->crow][i].ch = 0x20; + rt->cells[rt->crow][i].ch = 0x20; rt->cells[rt->crow][i].attr = rt->curattr; } @@ -486,7 +474,7 @@ static void interpret_csi_DCH(RoteTerm *rt, int param[], int pcount) if (i + n < rt->cols) { rt->cells[rt->crow][i] = rt->cells[rt->crow][i + n]; } else { - rt->cells[rt->crow][i].ch = 0x20; + rt->cells[rt->crow][i].ch = 0x20; rt->cells[rt->crow][i].attr = rt->curattr; } } @@ -507,7 +495,8 @@ static void interpret_csi_IL(RoteTerm *rt, int param[], int pcount) for (i = rt->crow; i < rt->crow + n && i <= rt->pd->scrollbottom; i++) { rt->line_dirty[i] = true; for (j = 0; j < rt->cols; j++) { - rt->cells[i][j].ch = 0x20, rt->cells[i][j].attr = rt->curattr; + rt->cells[i][j].ch = 0x20; + rt->cells[i][j].attr = rt->curattr; } } @@ -525,7 +514,8 @@ static void interpret_csi_DL(RoteTerm *rt, int param[], int pcount) memcpy(rt->cells[i], rt->cells[i+n], sizeof(RoteCell) * rt->cols); } else { for (j = 0; j < rt->cols; j++) { - rt->cells[i][j].ch = 0x20, rt->cells[i][j].attr = rt->curattr; + rt->cells[i][j].ch = 0x20; + rt->cells[i][j].attr = rt->curattr; } } } @@ -538,7 +528,7 @@ static void interpret_csi_ECH(RoteTerm *rt, int param[], int pcount) int i; for (i = rt->ccol; i < rt->ccol + n && i < rt->cols; i++) { - rt->cells[rt->crow][i].ch = 0x20; + rt->cells[rt->crow][i].ch = 0x20; rt->cells[rt->crow][i].attr = rt->curattr; } @@ -578,13 +568,19 @@ static void interpret_csi_DECSTBM(RoteTerm *rt, int param[], int pcount) rt->pd->scrollbottom = newbottom; } -static void interpret_csi_SAVECUR(RoteTerm *rt, int param[], int pcount) +static void +interpret_csi_SAVECUR(RoteTerm *rt, + int param[] __attribute__((unused)), + int pcount __attribute__((unused))) { rt->pd->saved_x = rt->ccol; rt->pd->saved_y = rt->crow; } -static void interpret_csi_RESTORECUR(RoteTerm *rt, int param[], int pcount) +static void +interpret_csi_RESTORECUR(RoteTerm *rt, + int param[] __attribute__((unused)), + int pcount __attribute__((unused))) { rt->ccol = rt->pd->saved_x; rt->crow = rt->pd->saved_y;