summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2019-10-27 12:06:18 +0100
committerBoris Faure <billiob@gmail.com>2019-10-27 12:06:18 +0100
commit7dcb9e4e43f5af67d3f989d9e69aa6f4a328d607 (patch)
tree828f8f747f27cefbd6ed8872b7a6a7ed1861caf2
parent7634b61283a92266afb81293ceb49f27f020c44c (diff)
termio_selection_get(): simplify by using macros
-rw-r--r--src/bin/termiointernals.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/src/bin/termiointernals.c b/src/bin/termiointernals.c
index 555c27a..bb91705 100644
--- a/src/bin/termiointernals.c
+++ b/src/bin/termiointernals.c
@@ -21,6 +21,16 @@ termio_selection_get(Termio *sd,
21{ 21{
22 int x, y; 22 int x, y;
23 23
24#define SB_ADD(STR, LEN) do { \
25 if (ty_sb_add(sb, STR, LEN) < 0) \
26 goto err; \
27} while (0)
28
29#define RTRIM() do { \
30 if (rtrim) \
31 ty_sb_spaces_rtrim(sb); \
32} while (0)
33
24 termpty_backlog_lock(); 34 termpty_backlog_lock();
25 for (y = c1y; y <= c2y; y++) 35 for (y = c1y; y <= c2y; y++)
26 { 36 {
@@ -33,15 +43,14 @@ termio_selection_get(Termio *sd,
33 cells = termpty_cellrow_get(sd->pty, y, &w); 43 cells = termpty_cellrow_get(sd->pty, y, &w);
34 if (!cells || !w) 44 if (!cells || !w)
35 { 45 {
36 if (ty_sb_add(sb, "\n", 1) < 0) goto err; 46 SB_ADD("\n", 1);
37 continue; 47 continue;
38 } 48 }
39 if (w > sd->grid.w) w = sd->grid.w; 49 if (w > sd->grid.w) w = sd->grid.w;
40 if (y == c1y && c1x >= w) 50 if (y == c1y && c1x >= w)
41 { 51 {
42 if (rtrim) 52 RTRIM();
43 ty_sb_spaces_rtrim(sb); 53 SB_ADD("\n", 1);
44 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
45 continue; 54 continue;
46 } 55 }
47 start_x = c1x; 56 start_x = c1x;
@@ -60,18 +69,20 @@ termio_selection_get(Termio *sd,
60 { 69 {
61 if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth)) 70 if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth))
62 { 71 {
63 if (x < end_x) x++; 72 if (x < end_x)
64 else break; 73 x++;
74 else
75 break;
65 } 76 }
66 if (x >= w) break; 77 if (x >= w)
78 break;
67 if (cells[x].att.newline) 79 if (cells[x].att.newline)
68 { 80 {
69 last0 = -1; 81 last0 = -1;
70 if ((y != c2y) || (x != end_x)) 82 if ((y != c2y) || (x != end_x))
71 { 83 {
72 if (rtrim) 84 RTRIM();
73 ty_sb_spaces_rtrim(sb); 85 SB_ADD("\n", 1);
74 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
75 } 86 }
76 break; 87 break;
77 } 88 }
@@ -90,21 +101,20 @@ termio_selection_get(Termio *sd,
90 last0 = -1; 101 last0 = -1;
91 while (v >= 0) 102 while (v >= 0)
92 { 103 {
93 if (ty_sb_add(sb, " ", 1) < 0) goto err; 104 SB_ADD(" ", 1);
94 v--; 105 v--;
95 } 106 }
96 } 107 }
97 txtlen = codepoint_to_utf8(cells[x].codepoint, txt); 108 txtlen = codepoint_to_utf8(cells[x].codepoint, txt);
98 if (txtlen > 0) 109 if (txtlen > 0)
99 if (ty_sb_add(sb, txt, txtlen) < 0) goto err; 110 SB_ADD(txt, txtlen);
100 if ((x == (w - 1)) && 111 if ((x == (w - 1)) &&
101 ((x != c2x) || (y != c2y))) 112 ((x != c2x) || (y != c2y)))
102 { 113 {
103 if (!cells[x].att.autowrapped) 114 if (!cells[x].att.autowrapped)
104 { 115 {
105 if (rtrim) 116 RTRIM();
106 ty_sb_spaces_rtrim(sb); 117 SB_ADD("\n", 1);
107 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
108 } 118 }
109 } 119 }
110 } 120 }
@@ -133,9 +143,8 @@ termio_selection_get(Termio *sd,
133 } 143 }
134 if (!have_more) 144 if (!have_more)
135 { 145 {
136 if (rtrim) 146 RTRIM();
137 ty_sb_spaces_rtrim(sb); 147 SB_ADD("\n", 1);
138 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
139 } 148 }
140 else 149 else
141 { 150 {
@@ -148,27 +157,27 @@ termio_selection_get(Termio *sd,
148 else break; 157 else break;
149 } 158 }
150 if (x >= w) break; 159 if (x >= w) break;
151 if (ty_sb_add(sb, " ", 1) < 0) goto err; 160 SB_ADD(" ", 1);
152 } 161 }
153 } 162 }
154 } 163 }
155 else 164 else
156 { 165 {
157 if (rtrim) 166 RTRIM();
158 ty_sb_spaces_rtrim(sb); 167 SB_ADD("\n", 1);
159 if (ty_sb_add(sb, "\n", 1) < 0) goto err;
160 } 168 }
161 } 169 }
162 } 170 }
163 termpty_backlog_unlock(); 171 termpty_backlog_unlock();
164 172
165 if (rtrim) 173 RTRIM();
166 ty_sb_spaces_rtrim(sb);
167 174
168 return; 175 return;
169 176
170err: 177err:
171 ty_sb_free(sb); 178 ty_sb_free(sb);
179#undef SB_ADD
180#undef RTRIM
172} 181}
173 182
174 183
@@ -1305,8 +1314,6 @@ _selection_newline_extend_fix(Termio *sd)
1305 termpty_backlog_unlock(); 1314 termpty_backlog_unlock();
1306} 1315}
1307 1316
1308/* }}} */
1309
1310void 1317void
1311termio_selection_dbl_fix(Termio *sd) 1318termio_selection_dbl_fix(Termio *sd)
1312{ 1319{
@@ -1393,6 +1400,7 @@ termio_selection_dbl_fix(Termio *sd)
1393 sd->pty->selection.end.y = end_y; 1400 sd->pty->selection.end.y = end_y;
1394} 1401}
1395 1402
1403/* }}} */
1396 1404
1397static void 1405static void
1398_handle_mouse_down_single_click(Termio *sd, 1406_handle_mouse_down_single_click(Termio *sd,