Commit 5d70e80ba1ee6504e8de77ac6e3233420905b384
1 parent
649883fc
Exists in
master
and in
3 other branches
Adding method to set field and jump to next.
Showing
3 changed files
with
84 additions
and
8 deletions
Show diff stats
src/core/keyboard/kybd.c
... | ... | @@ -1631,17 +1631,17 @@ int lib3270_get_field_end(H3270 *hSession, int baddr) |
1631 | 1631 | #if defined(X3270_ANSI) /*[*/ |
1632 | 1632 | if (IN_ANSI) |
1633 | 1633 | { |
1634 | - return errno = EINVAL; | |
1634 | + return -(errno = ENOTSUP); | |
1635 | 1635 | } |
1636 | 1636 | #endif /*]*/ |
1637 | 1637 | |
1638 | 1638 | if (!hSession->formatted) |
1639 | - return errno = EINVAL; | |
1639 | + return -(errno = ENOTSUP); | |
1640 | 1640 | |
1641 | 1641 | faddr = lib3270_field_addr(hSession,baddr); |
1642 | 1642 | fa = hSession->ea_buf[faddr].fa; |
1643 | 1643 | if (faddr == baddr || FA_IS_PROTECTED(fa)) |
1644 | - return errno = EPERM; | |
1644 | + return -(errno = EPERM); | |
1645 | 1645 | |
1646 | 1646 | baddr = faddr; |
1647 | 1647 | while (True) | ... | ... |
src/core/paste.c
... | ... | @@ -295,6 +295,59 @@ LIB3270_EXPORT int lib3270_set_string_at_address(H3270 *hSession, int baddr, con |
295 | 295 | return rc; |
296 | 296 | } |
297 | 297 | |
298 | +LIB3270_EXPORT int lib3270_set_field(H3270 *hSession, const char *text, int length) | |
299 | +{ | |
300 | + int addr; | |
301 | + int numchars = 0; | |
302 | + | |
303 | + if(!text) | |
304 | + return - (errno = EINVAL); | |
305 | + | |
306 | + if(check_online_session(hSession)) | |
307 | + return - errno; | |
308 | + | |
309 | + if(hSession->kybdlock) | |
310 | + return - (errno = EPERM); | |
311 | + | |
312 | + if (!hSession->formatted) | |
313 | + return - (errno = ENOTSUP); | |
314 | + | |
315 | + if(length < 0) | |
316 | + length = (int) strlen((const char *) text); | |
317 | + | |
318 | + addr = lib3270_field_addr(hSession,hSession->cursor_addr); | |
319 | + if(addr < 0) | |
320 | + return addr; | |
321 | + | |
322 | + if(hSession->selected && !lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_SELECTED)) | |
323 | + lib3270_unselect(hSession); | |
324 | + | |
325 | + hSession->cbk.suspend(hSession); | |
326 | + hSession->cursor_addr = addr; | |
327 | + numchars = set_string(hSession, (const unsigned char *) text, length); | |
328 | + hSession->cbk.resume(hSession); | |
329 | + | |
330 | + if(numchars < 0) | |
331 | + return numchars; | |
332 | + | |
333 | + // Find the end of the field. | |
334 | + addr = lib3270_get_field_end(hSession,addr); | |
335 | + if(addr < 0) | |
336 | + return addr; | |
337 | + | |
338 | + addr = lib3270_get_next_unprotected(hSession, addr); | |
339 | + | |
340 | + if(addr > 0) { | |
341 | + addr = lib3270_set_cursor_address(hSession,addr); | |
342 | + if(addr < 0) | |
343 | + return addr; | |
344 | + } | |
345 | + | |
346 | + return hSession->cursor_addr; | |
347 | + | |
348 | +} | |
349 | + | |
350 | + | |
298 | 351 | LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str, int length) |
299 | 352 | { |
300 | 353 | int rc; | ... | ... |
src/include/lib3270.h
... | ... | @@ -660,6 +660,26 @@ |
660 | 660 | LIB3270_EXPORT int lib3270_translate_to_address(const H3270 *hSession, unsigned int row, unsigned int col); |
661 | 661 | |
662 | 662 | /** |
663 | + * @brief Set field contents, jump to the next one. | |
664 | + * | |
665 | + * Set the string inside the corrent field, jump to the next one. | |
666 | + * | |
667 | + * @param hSession Session handle. | |
668 | + * @param text String to input. | |
669 | + * @param length Length of the string (-1 for auto-detect). | |
670 | + * | |
671 | + * @return address of the cursor, negative if failed. | |
672 | + * | |
673 | + * @retval 0 No next field. | |
674 | + * @retval -EPERM The keyboard is locked. | |
675 | + * @retval -ENOTCONN Disconnected from host. | |
676 | + * @retval -ENODATA No field at the current cursor position. | |
677 | + * @retval -ENOTSUP The screen is not formatted. | |
678 | + * | |
679 | + */ | |
680 | + LIB3270_EXPORT int lib3270_set_field(H3270 *hSession, const char *text, int length); | |
681 | + | |
682 | + /** | |
663 | 683 | * @brief Set string at current cursor position. |
664 | 684 | * |
665 | 685 | * Returns are ignored; newlines mean "move to beginning of next line"; |
... | ... | @@ -1178,7 +1198,10 @@ |
1178 | 1198 | * @param hSession Session handle. |
1179 | 1199 | * @param baddr Field address. |
1180 | 1200 | * |
1181 | - * @return address of the first blank or -1 if invalid. | |
1201 | + * @return address of the first blank or negative if invalid. | |
1202 | + * | |
1203 | + * @retval -ENOTSUP Screen is not formatted. | |
1204 | + * @retval -EPERM Current cursor position is protected. | |
1182 | 1205 | */ |
1183 | 1206 | LIB3270_EXPORT int lib3270_get_field_end(H3270 *hSession, int baddr); |
1184 | 1207 | |
... | ... | @@ -1190,10 +1213,10 @@ |
1190 | 1213 | * |
1191 | 1214 | * @return field address or negative if the screen isn't formatted (sets errno). |
1192 | 1215 | * |
1193 | - * @exception -ENOTCONN Not connected to host. | |
1194 | - * @exception -EOVERFLOW Invalid position. | |
1195 | - * @exception -ENOTSUP Screen is not formatted. | |
1196 | - * @exception -ENODATA No field at the address. | |
1216 | + * @retval -ENOTCONN Not connected to host. | |
1217 | + * @retval -EOVERFLOW Invalid position. | |
1218 | + * @retval -ENOTSUP Screen is not formatted. | |
1219 | + * @retval -ENODATA No field at the address. | |
1197 | 1220 | * |
1198 | 1221 | */ |
1199 | 1222 | LIB3270_EXPORT int lib3270_field_addr(const H3270 *hSession, int baddr); | ... | ... |