Commit cf558eeee423062c1f1c125758e75efba77a65f9
1 parent
a6fdb1f5
Exists in
master
and in
3 other branches
Ajustes para que as macros tratem seleção
Showing
2 changed files
with
38 additions
and
3 deletions
Show diff stats
macros.c
| @@ -35,6 +35,7 @@ | @@ -35,6 +35,7 @@ | ||
| 35 | #include <stdio.h> | 35 | #include <stdio.h> |
| 36 | #include <lib3270.h> | 36 | #include <lib3270.h> |
| 37 | #include <lib3270/macros.h> | 37 | #include <lib3270/macros.h> |
| 38 | + #include <lib3270/selection.h> | ||
| 38 | #include <stdlib.h> | 39 | #include <stdlib.h> |
| 39 | #include <strings.h> | 40 | #include <strings.h> |
| 40 | #include "globals.h" | 41 | #include "globals.h" |
| @@ -278,6 +279,37 @@ | @@ -278,6 +279,37 @@ | ||
| 278 | return strdup("0"); | 279 | return strdup("0"); |
| 279 | } | 280 | } |
| 280 | 281 | ||
| 282 | + LIB3270_MACRO( unselect ) | ||
| 283 | + { | ||
| 284 | + lib3270_unselect(hSession); | ||
| 285 | + return strdup("0"); | ||
| 286 | + } | ||
| 287 | + | ||
| 288 | + LIB3270_MACRO( select ) | ||
| 289 | + { | ||
| 290 | + int rc = -1; | ||
| 291 | + char ret[10]; | ||
| 292 | + | ||
| 293 | + switch(argc) | ||
| 294 | + { | ||
| 295 | + case 1: // 1 argument, select all | ||
| 296 | + rc = lib3270_select_all(hSession); | ||
| 297 | + break; | ||
| 298 | + | ||
| 299 | + case 3: // 2 arguments, first and last addr | ||
| 300 | + rc = lib3270_select_region(hSession,atoi(argv[1]),atoi(argv[2])); | ||
| 301 | + break; | ||
| 302 | + | ||
| 303 | + | ||
| 304 | + default: | ||
| 305 | + errno = EINVAL; | ||
| 306 | + return NULL; | ||
| 307 | + } | ||
| 308 | + | ||
| 309 | + snprintf(ret,9,"%d",rc); | ||
| 310 | + return strdup(ret); | ||
| 311 | + | ||
| 312 | + } | ||
| 281 | 313 | ||
| 282 | /*--[ Macro entry point ]----------------------------------------------------------------------------*/ | 314 | /*--[ Macro entry point ]----------------------------------------------------------------------------*/ |
| 283 | 315 | ||
| @@ -298,6 +330,8 @@ | @@ -298,6 +330,8 @@ | ||
| 298 | LIB3270_MACRO_ENTRY( pf ), | 330 | LIB3270_MACRO_ENTRY( pf ), |
| 299 | LIB3270_MACRO_ENTRY( set ), | 331 | LIB3270_MACRO_ENTRY( set ), |
| 300 | LIB3270_MACRO_ENTRY( status ), | 332 | LIB3270_MACRO_ENTRY( status ), |
| 333 | + LIB3270_MACRO_ENTRY( select ), | ||
| 334 | + LIB3270_MACRO_ENTRY( unselect ), | ||
| 301 | 335 | ||
| 302 | {NULL, NULL} | 336 | {NULL, NULL} |
| 303 | }; | 337 | }; |
selection.c
| @@ -220,24 +220,25 @@ LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) | @@ -220,24 +220,25 @@ LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) | ||
| 220 | 220 | ||
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | -LIB3270_EXPORT void lib3270_select_region(H3270 *h, int start, int end) | 223 | +LIB3270_EXPORT int lib3270_select_region(H3270 *h, int start, int end) |
| 224 | { | 224 | { |
| 225 | int maxlen; | 225 | int maxlen; |
| 226 | 226 | ||
| 227 | CHECK_SESSION_HANDLE(h); | 227 | CHECK_SESSION_HANDLE(h); |
| 228 | 228 | ||
| 229 | if(!lib3270_connected(h)) | 229 | if(!lib3270_connected(h)) |
| 230 | - return; | 230 | + return ENOTCONN; |
| 231 | 231 | ||
| 232 | maxlen = (h->rows * h->cols); | 232 | maxlen = (h->rows * h->cols); |
| 233 | 233 | ||
| 234 | // Check bounds | 234 | // Check bounds |
| 235 | if(start < 0 || start > maxlen || end < 0 || end > maxlen || start > end) | 235 | if(start < 0 || start > maxlen || end < 0 || end > maxlen || start > end) |
| 236 | - return; | 236 | + return EINVAL; |
| 237 | 237 | ||
| 238 | do_select(h,start,end,lib3270_get_toggle(h,LIB3270_TOGGLE_RECTANGLE_SELECT)); | 238 | do_select(h,start,end,lib3270_get_toggle(h,LIB3270_TOGGLE_RECTANGLE_SELECT)); |
| 239 | cursor_move(h,h->select.end); | 239 | cursor_move(h,h->select.end); |
| 240 | 240 | ||
| 241 | + return 0; | ||
| 241 | } | 242 | } |
| 242 | 243 | ||
| 243 | static void do_select(H3270 *h, int start, int end, int rect) | 244 | static void do_select(H3270 *h, int start, int end, int rect) |