@@ -1778,11 +1778,11 @@ int tb_extend_cell(int x, int y, uint32_t ch) {
1778
1778
if_err_return (rv , cellbuf_get (& global .back , x , y , & cell ));
1779
1779
if (cell -> nech > 0 ) { // append to ech
1780
1780
nech = cell -> nech + 1 ;
1781
- if_err_return (rv , cell_reserve_ech (cell , nech ));
1781
+ if_err_return (rv , cell_reserve_ech (cell , nech + 1 ));
1782
1782
cell -> ech [nech - 1 ] = ch ;
1783
1783
} else { // make new ech
1784
1784
nech = 2 ;
1785
- if_err_return (rv , cell_reserve_ech (cell , nech ));
1785
+ if_err_return (rv , cell_reserve_ech (cell , nech + 1 ));
1786
1786
cell -> ech [0 ] = cell -> ch ;
1787
1787
cell -> ech [1 ] = ch ;
1788
1788
}
@@ -1869,7 +1869,7 @@ int tb_print(int x, int y, uintattr_t fg, uintattr_t bg, const char *str) {
1869
1869
1870
1870
int tb_print_ex (int x , int y , uintattr_t fg , uintattr_t bg , size_t * out_w ,
1871
1871
const char * str ) {
1872
- int rv , w , ix ;
1872
+ int rv , w , ix , x_prev ;
1873
1873
uint32_t uni ;
1874
1874
1875
1875
if_not_init_return ();
@@ -1879,6 +1879,7 @@ int tb_print_ex(int x, int y, uintattr_t fg, uintattr_t bg, size_t *out_w,
1879
1879
}
1880
1880
1881
1881
ix = x ;
1882
+ x_prev = x ;
1882
1883
if (out_w ) * out_w = 0 ;
1883
1884
1884
1885
while (* str ) {
@@ -1895,6 +1896,7 @@ int tb_print_ex(int x, int y, uintattr_t fg, uintattr_t bg, size_t *out_w,
1895
1896
1896
1897
if (uni == '\n' ) { // TODO: \r, \t, \v, \f, etc?
1897
1898
x = ix ;
1899
+ x_prev = x ;
1898
1900
y += 1 ;
1899
1901
continue ;
1900
1902
} else if (!iswprint ((wint_t )uni )) {
@@ -1905,17 +1907,17 @@ int tb_print_ex(int x, int y, uintattr_t fg, uintattr_t bg, size_t *out_w,
1905
1907
if (w < 0 ) {
1906
1908
return TB_ERR ; // shouldn't happen if iswprint
1907
1909
} else if (w == 0 ) { // combining character
1908
- if (cellbuf_in_bounds (& global .back , x - 1 , y )) {
1909
- if_err_return (rv , tb_extend_cell (x - 1 , y , uni ));
1910
+ if (cellbuf_in_bounds (& global .back , x_prev , y )) {
1911
+ if_err_return (rv , tb_extend_cell (x_prev , y , uni ));
1910
1912
}
1911
1913
} else {
1912
1914
if (cellbuf_in_bounds (& global .back , x , y )) {
1913
1915
if_err_return (rv , tb_set_cell (x , y , uni , fg , bg ));
1914
1916
}
1917
+ x_prev = x ;
1918
+ x += w ;
1919
+ if (out_w ) * out_w += w ;
1915
1920
}
1916
-
1917
- x += w ;
1918
- if (out_w ) * out_w += w ;
1919
1921
}
1920
1922
1921
1923
return TB_OK ;
@@ -2220,8 +2222,8 @@ static int cap_trie_add(const char *cap, uint16_t key, uint8_t mod) {
2220
2222
if (!next ) {
2221
2223
// We need to add a new child to node
2222
2224
node -> nchildren += 1 ;
2223
- node -> children =
2224
- tb_realloc ( node -> children , sizeof (* node ) * node -> nchildren );
2225
+ node -> children = ( struct cap_trie_t * ) tb_realloc ( node -> children ,
2226
+ sizeof (* node ) * node -> nchildren );
2225
2227
if (!node -> children ) {
2226
2228
return TB_ERR_MEM ;
2227
2229
}
@@ -2361,7 +2363,7 @@ static int update_term_size_via_esc(void) {
2361
2363
#define TB_RESIZE_FALLBACK_MS 1000
2362
2364
#endif
2363
2365
2364
- char * move_and_report = "\x1b[9999;9999H\x1b[6n" ;
2366
+ char move_and_report [] = "\x1b[9999;9999H\x1b[6n" ;
2365
2367
ssize_t write_rv =
2366
2368
write (global .wfd , move_and_report , strlen (move_and_report ));
2367
2369
if (write_rv != (ssize_t )strlen (move_and_report )) {
@@ -2430,7 +2432,10 @@ static int tb_deinit(void) {
2430
2432
}
2431
2433
}
2432
2434
2433
- sigaction (SIGWINCH , & (struct sigaction ){.sa_handler = SIG_DFL }, NULL );
2435
+ struct sigaction sa ;
2436
+ memset (& sa , 0 , sizeof (sa ));
2437
+ sa .sa_handler = SIG_DFL ;
2438
+ sigaction (SIGWINCH , & sa , NULL );
2434
2439
if (global .resize_pipefd [0 ] >= 0 ) close (global .resize_pipefd [0 ]);
2435
2440
if (global .resize_pipefd [1 ] >= 0 ) close (global .resize_pipefd [1 ]);
2436
2441
@@ -2537,7 +2542,7 @@ static int read_terminfo_path(const char *path) {
2537
2542
}
2538
2543
2539
2544
size_t fsize = st .st_size ;
2540
- char * data = tb_malloc (fsize );
2545
+ char * data = ( char * ) tb_malloc (fsize );
2541
2546
if (!data ) {
2542
2547
fclose (fp );
2543
2548
return TB_ERR ;
@@ -2848,7 +2853,7 @@ static int extract_esc_cap(struct tb_event *event) {
2848
2853
static int extract_esc_mouse (struct tb_event * event ) {
2849
2854
struct bytebuf_t * in = & global .in ;
2850
2855
2851
- enum type { TYPE_VT200 = 0 , TYPE_1006 , TYPE_1015 , TYPE_MAX };
2856
+ enum { TYPE_VT200 = 0 , TYPE_1006 , TYPE_1015 , TYPE_MAX };
2852
2857
2853
2858
const char * cmp [TYPE_MAX ] = {//
2854
2859
// X10 mouse encoding, the simplest one
@@ -2860,7 +2865,7 @@ static int extract_esc_mouse(struct tb_event *event) {
2860
2865
// urxvt: \x1b [ Cb ; Cx ; Cy M
2861
2866
[TYPE_1015 ] = "\x1b[" };
2862
2867
2863
- enum type type = 0 ;
2868
+ int type = 0 ;
2864
2869
int ret = TB_ERR ;
2865
2870
2866
2871
// Unrolled at compile-time (probably)
@@ -3319,7 +3324,7 @@ static int cell_set(struct tb_cell *cell, uint32_t *ch, size_t nch,
3319
3324
} else {
3320
3325
int rv ;
3321
3326
if_err_return (rv , cell_reserve_ech (cell , nch + 1 ));
3322
- memcpy (cell -> ech , ch , sizeof (ch ) * nch );
3327
+ memcpy (cell -> ech , ch , sizeof (* ch ) * nch );
3323
3328
cell -> ech [nch ] = '\0' ;
3324
3329
cell -> nech = nch ;
3325
3330
}
@@ -3358,7 +3363,7 @@ static int cell_free(struct tb_cell *cell) {
3358
3363
}
3359
3364
3360
3365
static int cellbuf_init (struct cellbuf_t * c , int w , int h ) {
3361
- c -> cells = tb_malloc (sizeof (struct tb_cell ) * w * h );
3366
+ c -> cells = ( struct tb_cell * ) tb_malloc (sizeof (struct tb_cell ) * w * h );
3362
3367
if (!c -> cells ) {
3363
3368
return TB_ERR_MEM ;
3364
3369
}
@@ -3491,9 +3496,9 @@ static int bytebuf_reserve(struct bytebuf_t *b, size_t sz) {
3491
3496
}
3492
3497
char * newbuf ;
3493
3498
if (b -> buf ) {
3494
- newbuf = tb_realloc (b -> buf , newcap );
3499
+ newbuf = ( char * ) tb_realloc (b -> buf , newcap );
3495
3500
} else {
3496
- newbuf = tb_malloc (newcap );
3501
+ newbuf = ( char * ) tb_malloc (newcap );
3497
3502
}
3498
3503
if (!newbuf ) {
3499
3504
return TB_ERR_MEM ;
0 commit comments