Commit 6d6dd3a396a5d33404301c4ee21f11f8cd8f5e75

Authored by Perry Werneck
1 parent 597257dd

Small changes in the paste methods.

Showing 2 changed files with 14 additions and 10 deletions   Show diff stats
src/include/lib3270.h
@@ -717,11 +717,12 @@ @@ -717,11 +717,12 @@
717 * @param hSession Session handle. 717 * @param hSession Session handle.
718 * @param baddr Adress for the first character. 718 * @param baddr Adress for the first character.
719 * @param str String to set. 719 * @param str String to set.
  720 + * @param length Length of the string (-1 for auto-detect).
720 * 721 *
721 * @return Negative if error or number of processed characters. 722 * @return Negative if error or number of processed characters.
722 * 723 *
723 */ 724 */
724 - LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, const unsigned char *str); 725 + LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, const unsigned char *str, int length);
725 726
726 /** 727 /**
727 * @brief Insert string at current cursor position. 728 * @brief Insert string at current cursor position.
src/lib3270/paste.c
@@ -24,9 +24,6 @@ @@ -24,9 +24,6 @@
24 * 24 *
25 * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) 25 * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
26 * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) 26 * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
27 - * licinio@bb.com.br (Licínio Luis Branco)  
28 - * kraucer@bb.com.br (Kraucer Fernandes Mazuco)  
29 - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda)  
30 * 27 *
31 */ 28 */
32 29
@@ -164,17 +161,22 @@ @@ -164,17 +161,22 @@
164 return c; 161 return c;
165 } 162 }
166 163
167 -static int set_string(H3270 *hSession, const unsigned char *str) 164 +static int set_string(H3270 *hSession, const unsigned char *str, int length)
168 { 165 {
169 PASTE_DATA data; 166 PASTE_DATA data;
170 unsigned char last = 1; 167 unsigned char last = 1;
  168 + int ix;
171 169
172 memset(&data,0,sizeof(data)); 170 memset(&data,0,sizeof(data));
173 data.row = BA_TO_ROW(hSession->cursor_addr); 171 data.row = BA_TO_ROW(hSession->cursor_addr);
174 data.orig_addr = hSession->cursor_addr; 172 data.orig_addr = hSession->cursor_addr;
175 data.orig_col = BA_TO_COL(hSession->cursor_addr); 173 data.orig_col = BA_TO_COL(hSession->cursor_addr);
176 174
177 - while(*str && last && !hSession->kybdlock && hSession->cursor_addr >= data.orig_addr) 175 + if(length < 0)
  176 + length = (int) strlen((const char *) str);
  177 +
  178 +// while(*str && last && !hSession->kybdlock && hSession->cursor_addr >= data.orig_addr)
  179 + for(ix = 0; ix < length && *str && last && !hSession->kybdlock && hSession->cursor_addr >= data.orig_addr; ix++)
178 { 180 {
179 switch(*str) 181 switch(*str)
180 { 182 {
@@ -207,6 +209,7 @@ static int set_string(H3270 *hSession, const unsigned char *str) @@ -207,6 +209,7 @@ static int set_string(H3270 *hSession, const unsigned char *str)
207 last = paste_char(hSession,&data, *str); 209 last = paste_char(hSession,&data, *str);
208 210
209 } 211 }
  212 +
210 str++; 213 str++;
211 214
212 if(IN_3270 && lib3270_get_toggle(hSession,LIB3270_TOGGLE_MARGINED_PASTE) && BA_TO_COL(hSession->cursor_addr) < ((unsigned int) data.orig_col)) 215 if(IN_3270 && lib3270_get_toggle(hSession,LIB3270_TOGGLE_MARGINED_PASTE) && BA_TO_COL(hSession->cursor_addr) < ((unsigned int) data.orig_col))
@@ -254,7 +257,7 @@ LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, unsigned int row, unsi @@ -254,7 +257,7 @@ LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, unsigned int row, unsi
254 hSession->cbk.suspend(hSession); 257 hSession->cbk.suspend(hSession);
255 258
256 hSession->cursor_addr = (row * hSession->cols) + col; 259 hSession->cursor_addr = (row * hSession->cols) + col;
257 - rc += set_string(hSession, str); 260 + rc += set_string(hSession, str, -1);
258 261
259 hSession->cbk.resume(hSession); 262 hSession->cbk.resume(hSession);
260 } 263 }
@@ -264,7 +267,7 @@ LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, unsigned int row, unsi @@ -264,7 +267,7 @@ LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, unsigned int row, unsi
264 return rc; 267 return rc;
265 } 268 }
266 269
267 -LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, const unsigned char *str) 270 +LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, const unsigned char *str, int length)
268 { 271 {
269 int rc = -1; 272 int rc = -1;
270 273
@@ -280,7 +283,7 @@ LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, con @@ -280,7 +283,7 @@ LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, con
280 lib3270_unselect(hSession); 283 lib3270_unselect(hSession);
281 284
282 hSession->cbk.suspend(hSession); 285 hSession->cbk.suspend(hSession);
283 - rc = set_string(hSession, str); 286 + rc = set_string(hSession, str, length);
284 hSession->cbk.resume(hSession); 287 hSession->cbk.resume(hSession);
285 288
286 return rc; 289 return rc;
@@ -305,7 +308,7 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str) @@ -305,7 +308,7 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str)
305 return errno = EPERM; 308 return errno = EPERM;
306 309
307 hSession->cbk.suspend(hSession); 310 hSession->cbk.suspend(hSession);
308 - rc = set_string(hSession, str); 311 + rc = set_string(hSession, str, -1);
309 hSession->cbk.resume(hSession); 312 hSession->cbk.resume(hSession);
310 313
311 return rc; 314 return rc;