Commit cb78e38cc7b83e685ce8b5ef2e2d2f103212dfa8
1 parent
3061a0da
Exists in
master
and in
5 other branches
Implementando funções rexx
Showing
8 changed files
with
195 additions
and
60 deletions
Show diff stats
src/include/lib3270.h
... | ... | @@ -468,6 +468,7 @@ |
468 | 468 | */ |
469 | 469 | LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str); |
470 | 470 | |
471 | + LIB3270_EXPORT int lib3270_set_string_at(H3270 *h, int row, int col, const unsigned char *str); | |
471 | 472 | LIB3270_EXPORT void lib3270_input_string(H3270 *hSession, const unsigned char *str); |
472 | 473 | |
473 | 474 | /** |
... | ... | @@ -481,6 +482,8 @@ |
481 | 482 | */ |
482 | 483 | LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *h, int baddr); |
483 | 484 | |
485 | + LIB3270_EXPORT int lib3270_set_cursor_position(H3270 *h, int row, int col); | |
486 | + | |
484 | 487 | /** |
485 | 488 | * Move cursor |
486 | 489 | * | ... | ... |
src/lib3270/paste.c
... | ... | @@ -161,34 +161,18 @@ |
161 | 161 | } |
162 | 162 | |
163 | 163 | return c; |
164 | - } | |
164 | +} | |
165 | 165 | |
166 | -/** | |
167 | - * Set string at cursor position. | |
168 | - * | |
169 | - * @param hSession Session handle. | |
170 | - * @param str String to set | |
171 | - * | |
172 | - * @return Number of characters inserted; <0 in case of error. | |
173 | - * | |
174 | - */ | |
175 | -LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str) | |
166 | +static int set_string(H3270 *hSession, const unsigned char *str) | |
176 | 167 | { |
177 | 168 | PASTE_DATA data; |
178 | 169 | unsigned char last = 1; |
179 | 170 | |
180 | - CHECK_SESSION_HANDLE(hSession); | |
181 | - | |
182 | 171 | memset(&data,0,sizeof(data)); |
183 | 172 | data.row = BA_TO_ROW(hSession->cursor_addr); |
184 | 173 | data.orig_addr = hSession->cursor_addr; |
185 | 174 | data.orig_col = BA_TO_COL(hSession->cursor_addr); |
186 | 175 | |
187 | - if(hSession->kybdlock) | |
188 | - return -EINVAL; | |
189 | - | |
190 | - hSession->suspend(hSession); | |
191 | - | |
192 | 176 | while(*str && last && !hSession->kybdlock && hSession->cursor_addr >= data.orig_addr) |
193 | 177 | { |
194 | 178 | switch(*str) |
... | ... | @@ -234,9 +218,61 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str) |
234 | 218 | break; |
235 | 219 | } |
236 | 220 | |
221 | + return data.qtd; | |
222 | +} | |
223 | + | |
224 | +LIB3270_EXPORT int lib3270_set_string_at(H3270 *hSession, int row, int col, const unsigned char *str) | |
225 | +{ | |
226 | + int rc = -1; | |
227 | + | |
228 | + CHECK_SESSION_HANDLE(hSession); | |
229 | + | |
230 | + if(hSession->kybdlock) | |
231 | + return -EINVAL; | |
232 | + | |
233 | + if(hSession->selected && !lib3270_get_toggle(hSession,LIB3270_TOGGLE_KEEP_SELECTED)) | |
234 | + lib3270_unselect(hSession); | |
235 | + | |
236 | + row--; | |
237 | + col--; | |
238 | + | |
239 | + if(row >= 0 && col >= 0 && row <= hSession->rows && col <= hSession->cols) | |
240 | + { | |
241 | + hSession->suspend(hSession); | |
242 | + | |
243 | + hSession->cursor_addr = (row * hSession->cols) + col; | |
244 | + rc = set_string(hSession, str); | |
245 | + | |
246 | + hSession->resume(hSession); | |
247 | + } | |
248 | + | |
249 | + return rc; | |
250 | +} | |
251 | + | |
252 | + | |
253 | +/** | |
254 | + * Set string at cursor position. | |
255 | + * | |
256 | + * @param hSession Session handle. | |
257 | + * @param str String to set | |
258 | + * | |
259 | + * @return Number of characters inserted; <0 in case of error. | |
260 | + * | |
261 | + */ | |
262 | +LIB3270_EXPORT int lib3270_set_string(H3270 *hSession, const unsigned char *str) | |
263 | +{ | |
264 | + int rc; | |
265 | + | |
266 | + CHECK_SESSION_HANDLE(hSession); | |
267 | + | |
268 | + if(hSession->kybdlock) | |
269 | + return -EINVAL; | |
270 | + | |
271 | + hSession->suspend(hSession); | |
272 | + rc = set_string(hSession, str); | |
237 | 273 | hSession->resume(hSession); |
238 | 274 | |
239 | - return data.qtd; | |
275 | + return rc; | |
240 | 276 | } |
241 | 277 | |
242 | 278 | LIB3270_EXPORT int lib3270_paste(H3270 *h, const unsigned char *str) | ... | ... |
src/lib3270/screen.c
... | ... | @@ -398,11 +398,36 @@ LIB3270_EXPORT int lib3270_set_cursor_address(H3270 *h, int baddr) |
398 | 398 | return cursor_move(h,baddr); |
399 | 399 | } |
400 | 400 | |
401 | -int cursor_move(H3270 *h, int baddr) | |
401 | +LIB3270_EXPORT int lib3270_set_cursor_position(H3270 *h, int row, int col) | |
402 | 402 | { |
403 | - int ret; | |
403 | + int baddr = -1; | |
404 | + | |
405 | + CHECK_SESSION_HANDLE(h); | |
406 | + | |
407 | + if(h->selected && !lib3270_get_toggle(h,LIB3270_TOGGLE_KEEP_SELECTED)) | |
408 | + lib3270_unselect(h); | |
409 | + | |
410 | + row--; | |
411 | + col--; | |
412 | + | |
413 | + if(row >= 0 && col >= 0 && row <= h->rows && col <= h->cols) | |
414 | + { | |
415 | + baddr = (row * h->cols) + col; | |
404 | 416 | |
405 | - ret = h->cursor_addr; | |
417 | + if(baddr != h->cursor_addr) | |
418 | + { | |
419 | + h->cursor_addr = baddr; | |
420 | + h->update_cursor(h,(unsigned short) row,(unsigned short) col,h->text[baddr].chr,h->text[baddr].attr); | |
421 | + } | |
422 | + } | |
423 | + | |
424 | + return baddr; | |
425 | +} | |
426 | + | |
427 | + | |
428 | +int cursor_move(H3270 *h, int baddr) | |
429 | +{ | |
430 | + int ret = h->cursor_addr; | |
406 | 431 | |
407 | 432 | if(ret == baddr) |
408 | 433 | return ret; | ... | ... |
src/plugins/rx3270/pluginmain.cc
... | ... | @@ -34,10 +34,12 @@ |
34 | 34 | |
35 | 35 | LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window) |
36 | 36 | { |
37 | + rx3270_set_mode(RX3270_MODE_PLUGIN); | |
37 | 38 | return 0; |
38 | 39 | } |
39 | 40 | |
40 | 41 | LIB3270_EXPORT int pw3270_plugin_deinit(GtkWidget *window) |
41 | 42 | { |
43 | + rx3270_set_mode(RX3270_MODE_UNDEFINED); | |
42 | 44 | return 0; |
43 | 45 | } | ... | ... |
src/plugins/rx3270/rx3270.h
... | ... | @@ -66,12 +66,19 @@ |
66 | 66 | REXX_TYPED_ROUTINE_PROTOTYPE(rx3270IsTerminalReady); |
67 | 67 | REXX_TYPED_ROUTINE_PROTOTYPE(rx3270ReadScreen); |
68 | 68 | REXX_TYPED_ROUTINE_PROTOTYPE(rx3270queryStringAt); |
69 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270SetStringAt); | |
69 | 70 | |
70 | 71 | /*---[ Globals ]---------------------------------------------------------------------------------------------*/ |
71 | 72 | |
72 | - #define RX3270SESSION lib3270_get_default_session_handle() | |
73 | + enum rx3270mode | |
74 | + { | |
75 | + RX3270_MODE_STANDALONE, /**< Running outside pw3270's main process */ | |
76 | + RX3270_MODE_PLUGIN, /**< Running inside pw3270's main process */ | |
77 | + | |
78 | + RX3270_MODE_UNDEFINED | |
79 | + }; | |
73 | 80 | |
74 | - char * get_contents(H3270 *hSession, int start, int sz); | |
81 | + #define RX3270SESSION lib3270_get_default_session_handle() | |
75 | 82 | |
76 | 83 | #ifdef HAVE_ICONV |
77 | 84 | extern iconv_t outputConv; |
... | ... | @@ -80,4 +87,9 @@ |
80 | 87 | |
81 | 88 | /*--[ Prototipes ]-------------------------------------------------------------------------------------------*/ |
82 | 89 | |
90 | + char * get_contents(H3270 *hSession, int start, int sz); | |
91 | + char * set_contents(H3270 *hSession, const char *text); | |
92 | + | |
93 | + LIB3270_EXPORT void rx3270_set_mode(enum rx3270mode mode); | |
94 | + | |
83 | 95 | #endif // RX3270_H_INCLUDED | ... | ... |
src/plugins/rx3270/rxapimain.cc
... | ... | @@ -59,6 +59,8 @@ |
59 | 59 | int librx3270_unloaded(void) __attribute__((destructor)); |
60 | 60 | #endif |
61 | 61 | |
62 | + static enum rx3270mode active_mode = RX3270_MODE_UNDEFINED; | |
63 | + | |
62 | 64 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
63 | 65 | |
64 | 66 | #if defined WIN32 |
... | ... | @@ -80,8 +82,15 @@ BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd) |
80 | 82 | } |
81 | 83 | #endif |
82 | 84 | |
85 | +void rx3270_set_mode(enum rx3270mode mode) | |
86 | +{ | |
87 | + active_mode = mode; | |
88 | +} | |
89 | + | |
83 | 90 | int librx3270_loaded(void) |
84 | 91 | { |
92 | + active_mode = RX3270_MODE_STANDALONE; | |
93 | + | |
85 | 94 | #ifdef HAVE_ICONV |
86 | 95 | outputConv = iconv_open(REXX_DEFAULT_CHARSET, lib3270_get_default_charset()); |
87 | 96 | inputConv = iconv_open(lib3270_get_default_charset(), REXX_DEFAULT_CHARSET); |
... | ... | @@ -92,6 +101,8 @@ int librx3270_loaded(void) |
92 | 101 | |
93 | 102 | int librx3270_unloaded(void) |
94 | 103 | { |
104 | + active_mode = RX3270_MODE_UNDEFINED; | |
105 | + | |
95 | 106 | #ifdef HAVE_ICONV |
96 | 107 | |
97 | 108 | if(outputConv != (iconv_t) (-1)) |
... | ... | @@ -104,42 +115,6 @@ int librx3270_unloaded(void) |
104 | 115 | return 0; |
105 | 116 | } |
106 | 117 | |
107 | - | |
108 | -/* | |
109 | -::method setStringAt | |
110 | - use arg row, col, str | |
111 | -return rx3270InputString(row,col,str) | |
112 | - | |
113 | -::method setCursorPosition | |
114 | - use arg row, col | |
115 | -return rx3270SetCursorPosition(row,col) | |
116 | - | |
117 | -::method RunMode | |
118 | -return rx3270QueryRunMode() | |
119 | - | |
120 | -::method 'encoding=' | |
121 | - use arg ptr | |
122 | -return rx3270SetCharset(ptr) | |
123 | - | |
124 | -::method sendfile | |
125 | - use arg from, tostrncasecmp | |
126 | - | |
127 | - status = rx3270BeginFileSend(from,to) | |
128 | - if status <> 0 | |
129 | - then return status | |
130 | - | |
131 | -return rx3270WaitForFTComplete() | |
132 | - | |
133 | -::method recvfile | |
134 | - use arg from, to | |
135 | - | |
136 | - status = rx3270BeginFileRecv(from,to) | |
137 | - if status <> 0 | |
138 | - then return status | |
139 | - | |
140 | -return rx3270WaitForFTComplete() | |
141 | -*/ | |
142 | - | |
143 | 118 | // now build the actual entry list |
144 | 119 | RexxRoutineEntry rx3270_functions[] = |
145 | 120 | { |
... | ... | @@ -159,6 +134,7 @@ RexxRoutineEntry rx3270_functions[] = |
159 | 134 | REXX_TYPED_ROUTINE(rx3270IsTerminalReady, rx3270IsTerminalReady), |
160 | 135 | REXX_TYPED_ROUTINE(rx3270ReadScreen, rx3270ReadScreen), |
161 | 136 | REXX_TYPED_ROUTINE(rx3270queryStringAt, rx3270queryStringAt), |
137 | + REXX_TYPED_ROUTINE(rx3270SetStringAt, rx3270SetStringAt), | |
162 | 138 | |
163 | 139 | REXX_LAST_METHOD() |
164 | 140 | }; | ... | ... |
src/plugins/rx3270/text.cc
... | ... | @@ -79,3 +79,35 @@ char * get_contents(H3270 *hSession, int start, int sz) |
79 | 79 | return strdup((char *) str); |
80 | 80 | } |
81 | 81 | |
82 | +char * set_contents(H3270 *hSession, const char *str) | |
83 | +{ | |
84 | +#ifdef HAVE_ICONV | |
85 | + // Convert received string to 3270 encoding | |
86 | + if(inputConv != (iconv_t)(-1)) | |
87 | + { | |
88 | + size_t in = strlen(str); | |
89 | + size_t out = (in << 1); | |
90 | + char * ptr; | |
91 | + char * buffer = (char *) malloc(out); | |
92 | + char * ret; | |
93 | + | |
94 | + memset(ptr=buffer,0,out); | |
95 | + | |
96 | + iconv(inputConv,NULL,NULL,NULL,NULL); // Reset state | |
97 | + | |
98 | + if(iconv(inputConv,(char **) &str,&in,&ptr,&out) == ((size_t) -1)) | |
99 | + ret = strdup(str); | |
100 | + else | |
101 | + ret = strdup(buffer); | |
102 | + | |
103 | + free(buffer); | |
104 | + | |
105 | + return ret; | |
106 | + } | |
107 | +#endif // HAVE_ICONV | |
108 | + | |
109 | + return strdup((char *) str); | |
110 | + | |
111 | +} | |
112 | + | |
113 | + | ... | ... |
src/plugins/rx3270/typed_routines.cc
... | ... | @@ -242,3 +242,52 @@ RexxRoutine3(int, rx3270queryStringAt, int, row, int, col, CSTRING, key) |
242 | 242 | return 0; |
243 | 243 | } |
244 | 244 | |
245 | +RexxRoutine2(int, rx3270SetCursorPosition, int, row, int, col) | |
246 | +{ | |
247 | + return lib3270_set_cursor_position(RX3270SESSION,row,col); | |
248 | +} | |
249 | + | |
250 | +RexxRoutine3(int, rx3270SetStringAt, int, row, int, col, CSTRING, text) | |
251 | +{ | |
252 | + int rc; | |
253 | + H3270 * hSession = RX3270SESSION; | |
254 | + char * str = set_contents(hSession,text); | |
255 | + | |
256 | + if(str) | |
257 | + rc = lib3270_set_string_at(hSession,row,col,(const unsigned char *) str); | |
258 | + else | |
259 | + rc = -1; | |
260 | + | |
261 | + free(str); | |
262 | + | |
263 | + return rc; | |
264 | +} | |
265 | + | |
266 | +/* | |
267 | +::method RunMode | |
268 | +return rx3270QueryRunMode() | |
269 | + | |
270 | +::method 'encoding=' | |
271 | + use arg ptr | |
272 | +return rx3270SetCharset(ptr) | |
273 | + | |
274 | +::method sendfile | |
275 | + use arg from, tostrncasecmp | |
276 | + | |
277 | + status = rx3270BeginFileSend(from,to) | |
278 | + if status <> 0 | |
279 | + then return status | |
280 | + | |
281 | +return rx3270WaitForFTComplete() | |
282 | + | |
283 | +::method recvfile | |
284 | + use arg from, to | |
285 | + | |
286 | + status = rx3270BeginFileRecv(from,to) | |
287 | + if status <> 0 | |
288 | + then return status | |
289 | + | |
290 | +return rx3270WaitForFTComplete() | |
291 | +*/ | |
292 | + | |
293 | + | ... | ... |