Reaming struct term_emul into struct terminal
This commit is contained in:
parent
89768710c6
commit
6f80a5f5cd
26
term.c
26
term.c
|
@ -26,14 +26,14 @@
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void term_push(struct term_emul *term, char c)
|
static void term_push(struct terminal *term, char c)
|
||||||
{
|
{
|
||||||
if (term->stack_ptr >= TERM_STACK_SIZE)
|
if (term->stack_ptr >= TERM_STACK_SIZE)
|
||||||
return ;
|
return ;
|
||||||
term->stack[term->stack_ptr++] = c;
|
term->stack[term->stack_ptr++] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void term_parse_params(struct term_emul *term)
|
static void term_parse_params(struct terminal *term)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int got_something;
|
int got_something;
|
||||||
|
@ -59,7 +59,7 @@ static void term_parse_params(struct term_emul *term)
|
||||||
term->argc += got_something;
|
term->argc += got_something;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void term_call_CSI(struct term_emul *term, char c)
|
static void term_call_CSI(struct terminal *term, char c)
|
||||||
{
|
{
|
||||||
term_parse_params(term);
|
term_parse_params(term);
|
||||||
if (((term_action *)&term->callbacks.csi)[c - '0'] == NULL)
|
if (((term_action *)&term->callbacks.csi)[c - '0'] == NULL)
|
||||||
|
@ -76,7 +76,7 @@ leave:
|
||||||
term->argc = 0;
|
term->argc = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void term_call_ESC(struct term_emul *term, char c)
|
static void term_call_ESC(struct terminal *term, char c)
|
||||||
{
|
{
|
||||||
if (((term_action *)&term->callbacks.esc)[c - '0'] == NULL)
|
if (((term_action *)&term->callbacks.esc)[c - '0'] == NULL)
|
||||||
{
|
{
|
||||||
|
@ -91,7 +91,7 @@ leave:
|
||||||
term->argc = 0;
|
term->argc = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void term_call_HASH(struct term_emul *term, char c)
|
static void term_call_HASH(struct terminal *term, char c)
|
||||||
{
|
{
|
||||||
if (((term_action *)&term->callbacks.hash)[c - '0'] == NULL)
|
if (((term_action *)&term->callbacks.hash)[c - '0'] == NULL)
|
||||||
{
|
{
|
||||||
|
@ -106,7 +106,7 @@ leave:
|
||||||
term->argc = 0;
|
term->argc = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void term_call_GSET(struct term_emul *term, char c)
|
static void term_call_GSET(struct terminal *term, char c)
|
||||||
{
|
{
|
||||||
if (c < '0' || c > 'B'
|
if (c < '0' || c > 'B'
|
||||||
|| ((term_action *)&term->callbacks.scs)[c - '0'] == NULL)
|
|| ((term_action *)&term->callbacks.scs)[c - '0'] == NULL)
|
||||||
|
@ -137,7 +137,7 @@ leave:
|
||||||
** | | \_ term_call_GSET()
|
** | | \_ term_call_GSET()
|
||||||
** \_ term->write()
|
** \_ term->write()
|
||||||
*/
|
*/
|
||||||
void term_read(struct term_emul *term, char c)
|
void term_read(struct terminal *term, char c)
|
||||||
{
|
{
|
||||||
if (term->state == INIT)
|
if (term->state == INIT)
|
||||||
{
|
{
|
||||||
|
@ -184,14 +184,14 @@ void term_read(struct term_emul *term, char c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void term_read_str(struct term_emul *term, char *c)
|
void term_read_str(struct terminal *term, char *c)
|
||||||
{
|
{
|
||||||
while (*c)
|
while (*c)
|
||||||
term_read(term, *c++);
|
term_read(term, *c++);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
void term_default_unimplemented(struct term_emul* term, char *seq, char chr)
|
void term_default_unimplemented(struct terminal* term, char *seq, char chr)
|
||||||
{
|
{
|
||||||
unsigned int argc;
|
unsigned int argc;
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ void term_default_unimplemented(struct term_emul* term, char *seq, char chr)
|
||||||
fprintf(stderr, ")%o\n", chr);
|
fprintf(stderr, ")%o\n", chr);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void term_default_unimplemented(struct term_emul* term, char *seq, char chr)
|
void term_default_unimplemented(struct terminal* term, char *seq, char chr)
|
||||||
{
|
{
|
||||||
term = term;
|
term = term;
|
||||||
seq = seq;
|
seq = seq;
|
||||||
|
@ -213,10 +213,10 @@ void term_default_unimplemented(struct term_emul* term, char *seq, char chr)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct term_emul *term_init(unsigned int width, unsigned int height,
|
struct terminal *term_init(unsigned int width, unsigned int height,
|
||||||
void (*vtwrite)(struct term_emul *, char))
|
void (*vtwrite)(struct terminal *, char))
|
||||||
{
|
{
|
||||||
struct term_emul *term;
|
struct terminal *term;
|
||||||
|
|
||||||
term = calloc(1, sizeof(*term));
|
term = calloc(1, sizeof(*term));
|
||||||
term->width = width;
|
term->width = width;
|
||||||
|
|
20
term.h
20
term.h
|
@ -13,9 +13,9 @@ enum term_state
|
||||||
CSI
|
CSI
|
||||||
};
|
};
|
||||||
|
|
||||||
struct term_emul;
|
struct terminal;
|
||||||
|
|
||||||
typedef void (*term_action)(struct term_emul *emul);
|
typedef void (*term_action)(struct terminal *emul);
|
||||||
|
|
||||||
struct ascii_callbacks
|
struct ascii_callbacks
|
||||||
{
|
{
|
||||||
|
@ -108,7 +108,7 @@ struct term_callbacks
|
||||||
struct ascii_callbacks scs;
|
struct ascii_callbacks scs;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct term_emul
|
struct terminal
|
||||||
{
|
{
|
||||||
unsigned int width;
|
unsigned int width;
|
||||||
unsigned int height;
|
unsigned int height;
|
||||||
|
@ -117,21 +117,21 @@ struct term_emul
|
||||||
enum term_state state;
|
enum term_state state;
|
||||||
unsigned int argc;
|
unsigned int argc;
|
||||||
unsigned int argv[TERM_STACK_SIZE];
|
unsigned int argv[TERM_STACK_SIZE];
|
||||||
void (*write)(struct term_emul *, char c);
|
void (*write)(struct terminal *, char c);
|
||||||
char stack[TERM_STACK_SIZE];
|
char stack[TERM_STACK_SIZE];
|
||||||
unsigned int stack_ptr;
|
unsigned int stack_ptr;
|
||||||
struct term_callbacks callbacks;
|
struct term_callbacks callbacks;
|
||||||
char flag;
|
char flag;
|
||||||
void *user_data;
|
void *user_data;
|
||||||
void (*unimplemented)(struct term_emul*,
|
void (*unimplemented)(struct terminal*,
|
||||||
char *seq, char chr);
|
char *seq, char chr);
|
||||||
int fd;
|
int fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct term_emul *term_init(unsigned int width, unsigned int height,
|
struct terminal *term_init(unsigned int width, unsigned int height,
|
||||||
void (*write)(struct term_emul *, char));
|
void (*write)(struct terminal *, char));
|
||||||
void term_default_unimplemented(struct term_emul* term, char *seq, char chr);
|
void term_default_unimplemented(struct terminal* term, char *seq, char chr);
|
||||||
void term_read(struct term_emul *term, char c);
|
void term_read(struct terminal *term, char c);
|
||||||
void term_read_str(struct term_emul *term, char *c);
|
void term_read_str(struct terminal *term, char *c);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
48
vt100.c
48
vt100.c
|
@ -210,7 +210,7 @@ static void blank_screen(struct vt100_term *vt100_term)
|
||||||
This sequence causes the cursor position, graphic rendition, and
|
This sequence causes the cursor position, graphic rendition, and
|
||||||
character set to be saved. (See DECRC).
|
character set to be saved. (See DECRC).
|
||||||
*/
|
*/
|
||||||
static void DECSC(struct term_emul *term_emul)
|
static void DECSC(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
/*TODO: Save graphic rendition and charset.*/
|
/*TODO: Save graphic rendition and charset.*/
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
|
@ -231,7 +231,7 @@ static void DECSC(struct term_emul *term_emul)
|
||||||
Modes following this section).
|
Modes following this section).
|
||||||
|
|
||||||
*/
|
*/
|
||||||
static void RM(struct term_emul *term_emul)
|
static void RM(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
unsigned int mode;
|
unsigned int mode;
|
||||||
|
@ -268,7 +268,7 @@ static void RM(struct term_emul *term_emul)
|
||||||
The numbering of lines depends on the state of the Origin Mode
|
The numbering of lines depends on the state of the Origin Mode
|
||||||
(DECOM).
|
(DECOM).
|
||||||
*/
|
*/
|
||||||
static void CUP(struct term_emul *term_emul)
|
static void CUP(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
int arg0;
|
int arg0;
|
||||||
|
@ -307,7 +307,7 @@ static void CUP(struct term_emul *term_emul)
|
||||||
it is reset by a reset mode (RM) control sequence.
|
it is reset by a reset mode (RM) control sequence.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
static void SM(struct term_emul *term_emul)
|
static void SM(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
unsigned int mode;
|
unsigned int mode;
|
||||||
|
@ -353,7 +353,7 @@ static void SM(struct term_emul *term_emul)
|
||||||
cursor is placed in the home position (see Origin Mode DECOM).
|
cursor is placed in the home position (see Origin Mode DECOM).
|
||||||
|
|
||||||
*/
|
*/
|
||||||
static void DECSTBM(struct term_emul *term_emul)
|
static void DECSTBM(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
unsigned int margin_top;
|
unsigned int margin_top;
|
||||||
unsigned int margin_bottom;
|
unsigned int margin_bottom;
|
||||||
|
@ -414,7 +414,7 @@ static void DECSTBM(struct term_emul *term_emul)
|
||||||
activate the currently selected attribute. (See cursor selection in
|
activate the currently selected attribute. (See cursor selection in
|
||||||
Chapter 1).
|
Chapter 1).
|
||||||
*/
|
*/
|
||||||
static void SGR(struct term_emul *term_emul)
|
static void SGR(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
term_emul = term_emul;
|
term_emul = term_emul;
|
||||||
/* Just ignore them for now, we are rendering pure text only */
|
/* Just ignore them for now, we are rendering pure text only */
|
||||||
|
@ -443,7 +443,7 @@ static void SGR(struct term_emul *term_emul)
|
||||||
GPO, STP and AVO ESC [?1;7c
|
GPO, STP and AVO ESC [?1;7c
|
||||||
|
|
||||||
*/
|
*/
|
||||||
static void DA(struct term_emul *term_emul)
|
static void DA(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
|
|
||||||
|
@ -459,7 +459,7 @@ static void DA(struct term_emul *term_emul)
|
||||||
This sequence causes the previously saved cursor position, graphic
|
This sequence causes the previously saved cursor position, graphic
|
||||||
rendition, and character set to be restored.
|
rendition, and character set to be restored.
|
||||||
*/
|
*/
|
||||||
static void DECRC(struct term_emul *term_emul)
|
static void DECRC(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
/*TODO Save graphic rendition and charset */
|
/*TODO Save graphic rendition and charset */
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
|
@ -478,7 +478,7 @@ static void DECRC(struct term_emul *term_emul)
|
||||||
focus and alignment. This command is used by DEC manufacturing and
|
focus and alignment. This command is used by DEC manufacturing and
|
||||||
Field Service personnel.
|
Field Service personnel.
|
||||||
*/
|
*/
|
||||||
static void DECALN(struct term_emul *term_emul)
|
static void DECALN(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
unsigned int x;
|
unsigned int x;
|
||||||
|
@ -499,7 +499,7 @@ static void DECALN(struct term_emul *term_emul)
|
||||||
without changing the column position. If the active position is at the
|
without changing the column position. If the active position is at the
|
||||||
bottom margin, a scroll up is performed. Format Effector
|
bottom margin, a scroll up is performed. Format Effector
|
||||||
*/
|
*/
|
||||||
static void IND(struct term_emul *term_emul)
|
static void IND(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
unsigned int x;
|
unsigned int x;
|
||||||
|
@ -528,7 +528,7 @@ static void IND(struct term_emul *term_emul)
|
||||||
preceding line. If the active position is at the top margin, a scroll
|
preceding line. If the active position is at the top margin, a scroll
|
||||||
down is performed. Format Effector
|
down is performed. Format Effector
|
||||||
*/
|
*/
|
||||||
static void RI(struct term_emul *term_emul)
|
static void RI(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
|
|
||||||
|
@ -554,7 +554,7 @@ static void RI(struct term_emul *term_emul)
|
||||||
on the next line downward. If the active position is at the bottom
|
on the next line downward. If the active position is at the bottom
|
||||||
margin, a scroll up is performed. Format Effector
|
margin, a scroll up is performed. Format Effector
|
||||||
*/
|
*/
|
||||||
static void NEL(struct term_emul *term_emul)
|
static void NEL(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
unsigned int x;
|
unsigned int x;
|
||||||
|
@ -587,7 +587,7 @@ static void NEL(struct term_emul *term_emul)
|
||||||
upward. If an attempt is made to move the cursor above the top margin,
|
upward. If an attempt is made to move the cursor above the top margin,
|
||||||
the cursor stops at the top margin. Editor Function
|
the cursor stops at the top margin. Editor Function
|
||||||
*/
|
*/
|
||||||
static void CUU(struct term_emul *term_emul)
|
static void CUU(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
unsigned int arg0;
|
unsigned int arg0;
|
||||||
|
@ -617,7 +617,7 @@ static void CUU(struct term_emul *term_emul)
|
||||||
cursor below the bottom margin, the cursor stops at the bottom
|
cursor below the bottom margin, the cursor stops at the bottom
|
||||||
margin. Editor Function
|
margin. Editor Function
|
||||||
*/
|
*/
|
||||||
static void CUD(struct term_emul *term_emul)
|
static void CUD(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
unsigned int arg0;
|
unsigned int arg0;
|
||||||
|
@ -645,7 +645,7 @@ static void CUD(struct term_emul *term_emul)
|
||||||
is made to move the cursor to the right of the right margin, the
|
is made to move the cursor to the right of the right margin, the
|
||||||
cursor stops at the right margin. Editor Function
|
cursor stops at the right margin. Editor Function
|
||||||
*/
|
*/
|
||||||
static void CUF(struct term_emul *term_emul)
|
static void CUF(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
unsigned int arg0;
|
unsigned int arg0;
|
||||||
|
@ -673,7 +673,7 @@ static void CUF(struct term_emul *term_emul)
|
||||||
left. If an attempt is made to move the cursor to the left of the left
|
left. If an attempt is made to move the cursor to the left of the left
|
||||||
margin, the cursor stops at the left margin. Editor Function
|
margin, the cursor stops at the left margin. Editor Function
|
||||||
*/
|
*/
|
||||||
static void CUB(struct term_emul *term_emul)
|
static void CUB(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
unsigned int arg0;
|
unsigned int arg0;
|
||||||
|
@ -706,7 +706,7 @@ static void CUB(struct term_emul *term_emul)
|
||||||
2 Erase all of the display – all lines are erased, changed to
|
2 Erase all of the display – all lines are erased, changed to
|
||||||
single-width, and the cursor does not move.
|
single-width, and the cursor does not move.
|
||||||
*/
|
*/
|
||||||
static void ED(struct term_emul *term_emul)
|
static void ED(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
unsigned int arg0;
|
unsigned int arg0;
|
||||||
|
@ -755,7 +755,7 @@ static void ED(struct term_emul *term_emul)
|
||||||
1 Erase from the start of the screen to the active position, inclusive
|
1 Erase from the start of the screen to the active position, inclusive
|
||||||
2 Erase all of the line, inclusive
|
2 Erase all of the line, inclusive
|
||||||
*/
|
*/
|
||||||
static void EL(struct term_emul *term_emul)
|
static void EL(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
unsigned int arg0;
|
unsigned int arg0;
|
||||||
|
@ -798,12 +798,12 @@ static void EL(struct term_emul *term_emul)
|
||||||
columns depends on the reset or set state of the origin mode
|
columns depends on the reset or set state of the origin mode
|
||||||
(DECOM). Format Effector
|
(DECOM). Format Effector
|
||||||
*/
|
*/
|
||||||
static void HVP(struct term_emul *term_emul)
|
static void HVP(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
CUP(term_emul);
|
CUP(term_emul);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TBC(struct term_emul *term_emul)
|
static void TBC(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
@ -820,7 +820,7 @@ static void TBC(struct term_emul *term_emul)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HTS(struct term_emul *term_emul)
|
static void HTS(struct terminal *term_emul)
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
|
|
||||||
|
@ -828,7 +828,7 @@ static void HTS(struct term_emul *term_emul)
|
||||||
vt100->tabulations[vt100->x] = '|';
|
vt100->tabulations[vt100->x] = '|';
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vt100_write(struct term_emul *term_emul, char c __attribute__((unused)))
|
static void vt100_write(struct terminal *term_emul, char c __attribute__((unused)))
|
||||||
{
|
{
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
|
|
||||||
|
@ -895,9 +895,9 @@ const char **vt100_dump(struct vt100_term *vt100)
|
||||||
return (const char **)vt100->lines;
|
return (const char **)vt100->lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct term_emul *vt100_init(void (*unimplemented)(struct term_emul* term_emul, char *seq, char chr))
|
struct terminal *vt100_init(void (*unimplemented)(struct terminal* term_emul, char *seq, char chr))
|
||||||
{
|
{
|
||||||
struct term_emul *term;
|
struct terminal *term;
|
||||||
struct vt100_term *vt100;
|
struct vt100_term *vt100;
|
||||||
|
|
||||||
vt100 = calloc(1, sizeof(*vt100));
|
vt100 = calloc(1, sizeof(*vt100));
|
||||||
|
|
2
vt100.h
2
vt100.h
|
@ -63,7 +63,7 @@ struct vt100_term
|
||||||
char *lines[80];
|
char *lines[80];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct term_emul *vt100_init(void (*unimplemented)(struct term_emul* term_emul, char *seq, char chr));
|
struct terminal *vt100_init(void (*unimplemented)(struct terminal* term_emul, char *seq, char chr));
|
||||||
char get(struct vt100_term *vt100, unsigned int x, unsigned int y);
|
char get(struct vt100_term *vt100, unsigned int x, unsigned int y);
|
||||||
const char **vt100_dump(struct vt100_term *vt100);
|
const char **vt100_dump(struct vt100_term *vt100);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user