diff options
author | FreeArtMan <dos21h@gmail.com> | 2015-01-10 15:10:01 +0900 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2015-01-10 15:10:01 +0900 |
commit | 3e61314544a9151cb5a49db12a58c4fb74d6bee3 (patch) | |
tree | 5b9116b87b6c8abbc3ac13febc158007e3ccd071 /libterm | |
parent | 3e989921c29534d38dbf6009851389fc4f4e226e (diff) | |
download | microbbs-3e61314544a9151cb5a49db12a58c4fb74d6bee3.tar.gz microbbs-3e61314544a9151cb5a49db12a58c4fb74d6bee3.zip |
Bumped libterm
Diffstat (limited to 'libterm')
-rw-r--r-- | libterm/Makefile | 7 | ||||
-rw-r--r-- | libterm/term.c | 45 | ||||
-rw-r--r-- | libterm/term.h | 29 | ||||
-rw-r--r-- | libterm/term_io.c | 42 | ||||
-rw-r--r-- | libterm/term_io.h | 9 |
5 files changed, 95 insertions, 37 deletions
diff --git a/libterm/Makefile b/libterm/Makefile index 98962f5..457eea6 100644 --- a/libterm/Makefile +++ b/libterm/Makefile @@ -1,11 +1,12 @@ PROJECT=libterm CC=gcc LD=ld +CFLAGS= make: - $(CC) -c term.c - $(CC) -c screen_modes.c - $(CC) -c term_io.c + $(CC) $(CFLAGS) -c term.c + $(CC) $(CFLAGS) -c screen_modes.c + $(CC) $(CFLAGS) -c term_io.c $(LD) -r term.o screen_modes.o term_io.o -o $(PROJECT).o clean: diff --git a/libterm/term.c b/libterm/term.c index f1dbf40..e279e81 100644 --- a/libterm/term.c +++ b/libterm/term.c @@ -69,14 +69,14 @@ int term_get_maxcol( term_screen *ts ) int cur_c; /* get initial cursor position */ - if ( (orig_c = term_cur_pos_c( ts )) == -1 ) + if ( (orig_c = term_cur_get_c( ts )) == -1 ) goto exit_error; /* go to right marging and get position */ if ( write( ts->ofd, T_ESC "[999C", 6 ) != 6 ) goto exit_error; - if ( (cur_c = term_cur_pos_c( ts )) == -1 ) + if ( (cur_c = term_cur_get_c( ts )) == -1 ) goto exit_error; ret = cur_c; @@ -103,14 +103,14 @@ int term_get_maxrow( term_screen *ts ) int cur_r; /* get initial cursor position */ - if ( (orig_r = term_cur_pos_r( ts )) == -1 ) + if ( (orig_r = term_cur_get_r( ts )) == -1 ) goto exit_error; /* go to right marging and get position */ if ( write( ts->ofd, T_ESC "[999B", 6 ) != 6 ) goto exit_error; - if ( (cur_r = term_cur_pos_r( ts )) == -1 ) + if ( (cur_r = term_cur_get_r( ts )) == -1 ) goto exit_error; ret = cur_r; @@ -129,13 +129,7 @@ exit_error: -int term_cur_pos( term_screen *ts ) -{ - int ret=-1; - return ret; -} - -int term_cur_pos_c( term_screen *ts ) +int term_cur_get_c( term_screen *ts ) { unsigned int i; int row, col; @@ -162,7 +156,7 @@ exit_error: } -int term_cur_pos_r( term_screen *ts ) +int term_cur_get_r( term_screen *ts ) { unsigned int i; int row, col; @@ -195,7 +189,7 @@ int term_cur_set_c( term_screen *ts, unsigned int pc ) int cur_r; /* go to right marging and get position */ - if ( (cur_r = term_cur_pos_r( ts )) == -1 ) + if ( (cur_r = term_cur_get_r( ts )) == -1 ) goto exit_error; /* set position */ { @@ -221,7 +215,7 @@ int term_cur_set_r( term_screen *ts, unsigned int pr ) int cur_c; /* go to right marging and get position */ - if ( (cur_c = term_cur_pos_c( ts )) == -1 ) + if ( (cur_c = term_cur_get_c( ts )) == -1 ) goto exit_error; /* set position */ { @@ -240,6 +234,27 @@ exit_error: return -1; } +int term_cur_set_cr( term_screen *ts, unsigned int pc, unsigned int pr ) +{ + int ret = 0; + + /* set position */ + { + char buf[32]; + int l; + + snprintf( buf, 32, T_ESC "[%d;%dH", pr, pc); + l = strlen( buf ); + if ( write( ts->ofd, buf, l ) != l) + goto exit_error; + } + return ret; + +exit_error: + return -1; + +} + int term_set_speed( term_screen *ts ) { int ret = -1; @@ -252,7 +267,7 @@ int term_clr_scr( term_screen *ts ) { int ret = 0; - if ( write( ts->ofd, T_ESC "[H" T_ESC "[2J", 7 ) <= 0 );; + if ( write( ts->ofd, T_ESC "[H" T_ESC "[2J", 7 ) <= 0 ){}; return ret; } diff --git a/libterm/term.h b/libterm/term.h index de4fede..0be7391 100644 --- a/libterm/term.h +++ b/libterm/term.h @@ -14,6 +14,7 @@ #include <unistd.h> #include "screen_modes.h" +#include "debug.h" typedef struct term_screen @@ -24,19 +25,19 @@ typedef struct term_screen screen_mode_e mode; } term_screen; -int term_init( term_screen* ); -int term_get_maxcol( term_screen* ); -int term_get_maxrow( term_screen* ); -int term_cur_pos( term_screen* ); -int term_cur_pos_c( term_screen* ); -int term_cur_pos_r( term_screen* ); -int term_cur_set_c( term_screen*, unsigned int ); -int term_cur_set_r( term_screen*, unsigned int ); -int term_set_speed( term_screen* ); -int term_clr_scr( term_screen* ); -int term_set_raw_mode( term_screen* ); -int term_mode_rows( term_screen* ); -int term_mode_columns( term_screen* ); -void term_set_orig_mode( term_screen* ); +int term_init( term_screen *ts ); +int term_get_maxcol( term_screen *ts ); +int term_get_maxrow( term_screen *ts ); +int term_cur_get_c( term_screen *ts ); +int term_cur_get_r( term_screen *ts ); +int term_cur_set_c( term_screen *ts, unsigned int pc ); +int term_cur_set_r( term_screen *ts, unsigned int pr ); +int term_cur_set_cr( term_screen *ts, unsigned int pc , unsigned int pr ); +int term_set_speed( term_screen *ts ); +int term_clr_scr( term_screen *ts ); +int term_set_raw_mode( term_screen *ts ); +int term_mode_rows( term_screen *ts ); +int term_mode_columns( term_screen *ts ); +void term_set_orig_mode( term_screen *ts ); #endif diff --git a/libterm/term_io.c b/libterm/term_io.c index 1a934f9..5ef682b 100644 --- a/libterm/term_io.c +++ b/libterm/term_io.c @@ -6,6 +6,7 @@ int term_fprint( screen_mode_e mode, FILE *f ) if (f == NULL) return -1; + ERROR("\n"); switch ( mode ) { case SCREEN_MODE_80x25: @@ -19,12 +20,31 @@ int term_fprint( screen_mode_e mode, FILE *f ) return ret; } +int term_print( term_screen *ts, const char *s, size_t n) +{ + int ret=0; + + if ( ts == NULL ) + return -1; + + if ( s == NULL ) + return -1; + + if ( n < 1 ) + return -1; + + if ( n > 80*25 ) + return -1; + + ret = write( ts->ofd, s, n ); + + return ret; +} //print data to terminal starting from x,y -int term_print( term_screen *ts, const char *buf, size_t size, +int term_print_xy( term_screen *ts, const char *buf, size_t size, int init_column, int init_row ) { - int pos_column=0, pos_row=0; int ret=-1; if ( buf == NULL ) { @@ -50,6 +70,24 @@ int term_print( term_screen *ts, const char *buf, size_t size, return ret; } +int term_draw_hline( term_screen *ts, int pc, int pr, const int sz, char ch) +{ + int ret=0; + char buf[sz]; memset( buf, ch, sz ); + + if ( sz > 0) + { + term_cur_set_c( ts, pc ); + term_cur_set_r( ts, pr ); + write( ts->ofd, buf, sz ); + } else + { + ret = -1; + } + + return ret; +} + //read one character from stream int term_getc( term_screen *ts ) { diff --git a/libterm/term_io.h b/libterm/term_io.h index 3d9243f..8c57282 100644 --- a/libterm/term_io.h +++ b/libterm/term_io.h @@ -7,8 +7,11 @@ #include "screen_modes.h" #include "term.h" -int term_fprint( screen_mode_e, FILE* ); -int term_print( term_screen*, const char*, size_t, int, int ); -int term_getc( term_screen* ); +int term_fprint( screen_mode_e mode, FILE *f ); +int term_print( term_screen *ts, const char *s, size_t n ); +int term_print_xy( term_screen *ts, const char *buf, size_t size, + int init_column, int init_row); +int term_draw_hline( term_screen *ts, int pc, int pr, int sz, char ch ); +int term_getc( term_screen *ts ); #endif |