diff --git a/lib3270.cbp b/lib3270.cbp index d9d6bb3..5898b7c 100644 --- a/lib3270.cbp +++ b/lib3270.cbp @@ -220,6 +220,9 @@ + + diff --git a/src/include/lib3270.h b/src/include/lib3270.h index a799e9c..78ba705 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -1040,7 +1040,7 @@ * @return selected text if available, or NULL. Release it with free() * */ - LIB3270_EXPORT char * lib3270_get_selected(H3270 *h); + LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession); LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession); diff --git a/src/include/lib3270/selection.h b/src/include/lib3270/selection.h index e90ae34..5b4cae0 100644 --- a/src/include/lib3270/selection.h +++ b/src/include/lib3270/selection.h @@ -24,11 +24,16 @@ * * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) * */ + /** + * @brief LIB3270 calls for managing selected area. + * + * @author perry.werneck@gmail.com + * + */ + #ifndef LIB3270_SELECTION_H_INCLUDED #define LIB3270_SELECTION_H_INCLUDED 1 @@ -41,7 +46,21 @@ LIB3270_EXPORT int lib3270_select_all(H3270 *session); /** - * "Paste" supplied string. + * @brief Get selection options. + * + * @see lib3270_get_selection + * + */ + typedef enum _LIB3270_SELECTION_OPTIONS { + + LIB3270_SELECTION_CUT = 0x0001, ///< @brief Cut selected data (if available). + LIB3270_SELECTION_ALL = 0x0002, ///< @brief Get all data (the default is get only selected data). + LIB3270_SELECTION_UNPROTECTED_ONLY = 0x0004, ///< @brief Get only unprotected contents. + + } LIB3270_SELECTION_OPTIONS; + + /** + * @brief "Paste" supplied string. * * @param h Session handle. * @param str String to paste. @@ -54,7 +73,7 @@ LIB3270_EXPORT int lib3270_paste(H3270 *h, const unsigned char *str); /** - * Paste remaining string. + * @brief Paste remaining string. * * @param h Session handle. * @@ -66,7 +85,7 @@ LIB3270_EXPORT int lib3270_pastenext(H3270 *h); /** - * Move selected box 1 char in the selected direction. + * @brief Move selected box 1 char in the selected direction. * * @param h Session handle. * @param dir Direction to move @@ -76,7 +95,7 @@ LIB3270_EXPORT int lib3270_move_selection(H3270 *h, LIB3270_DIRECTION dir); /** - * Move selected box. + * @brief Move selected box. * * @param h Session handle. * @param from Address of origin position inside the selected buffer. @@ -88,7 +107,7 @@ LIB3270_EXPORT int lib3270_move_selected_area(H3270 *h, int from, int to); /** - * Drag selected region. + * @brief Drag selected region. * * Move or resize selected box according to the selection flags. * @@ -103,7 +122,7 @@ LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int origin, int baddr); /** - * Gets the selected range of characters in the screen + * @brief Gets the selected range of characters in the screen * * @param h Session handle. * @param start return location for start of selection, as a character offset. @@ -115,7 +134,7 @@ LIB3270_EXPORT int lib3270_get_selection_bounds(H3270 *hSession, int *start, int *end); /** - * Get bitmasked flag for the current selection. + * @brief Get bitmasked flag for the current selection. * * Calculate flags to help drawing of the correct mouse pointer over a selection. * @@ -127,7 +146,7 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *h, int baddr); /** - * Get a string from required region. + * @brief Get a string from required region. * * @param h Session handle. * @param start_pos First char to get. @@ -141,7 +160,7 @@ /** - * Selects a range of characters in the screen. + * @brief Selects a range of characters in the screen. * * @param h Session handle. * @param start_offset Start offset. diff --git a/src/lib3270/private.h b/src/lib3270/private.h index 617cc3a..dc8b146 100644 --- a/src/lib3270/private.h +++ b/src/lib3270/private.h @@ -670,7 +670,7 @@ LIB3270_INTERNAL void lib3270_sock_disconnect(H3270 *hSession); LIB3270_INTERNAL int lib3270_default_event_dispatcher(H3270 *hSession, int block); -LIB3270_INTERNAL void do_select(H3270 *h, int start, int end, int rect); +LIB3270_INTERNAL void do_select(H3270 *h, unsigned int start, unsigned int end, unsigned int rect); /** diff --git a/src/lib3270/selection/get.c b/src/lib3270/selection/get.c new file mode 100644 index 0000000..311ee37 --- /dev/null +++ b/src/lib3270/selection/get.c @@ -0,0 +1,144 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include "../private.h" + #include + #include + #include + #include "3270ds.h" + + /*--[ Implement ]------------------------------------------------------------------------------------*/ + +static void clear_chr(H3270 *hSession, int baddr) +{ + hSession->text[baddr].chr = ' '; + + hSession->ea_buf[baddr].cc = EBC_null; + hSession->ea_buf[baddr].cs = 0; + + hSession->cbk.update( hSession, + baddr, + hSession->text[baddr].chr, + hSession->text[baddr].attr, + baddr == hSession->cursor_addr ); +} + +LIB3270_EXPORT char * lib3270_get_selection(H3270 *hSession, char tok, LIB3270_SELECTION_OPTIONS options) +{ + int row, col, baddr; + char * ret; + size_t buflen = (hSession->rows * (hSession->cols+1))+1; + size_t sz = 0; + unsigned short attr = 0xFFFF; + char cut = (options & LIB3270_SELECTION_CUT) != 0; + char all = (options & LIB3270_SELECTION_ALL) != 0; + + if(check_online_session(hSession)) + return NULL; + + if(!hSession->selected || hSession->select.start == hSession->select.end) + return NULL; + + ret = lib3270_malloc(buflen); + + baddr = 0; + unsigned char fa = 0; + + for(row=0;row < ((int) hSession->rows);row++) + { + int cr = 0; + + for(col = 0; col < ((int) hSession->cols);col++) + { + if(hSession->ea_buf[baddr].fa) { + fa = hSession->ea_buf[baddr].fa; + } + + if(all || hSession->text[baddr].attr & LIB3270_ATTR_SELECTED) + { + if(tok && attr != hSession->text[baddr].attr) + { + attr = hSession->text[baddr].attr; + ret[sz++] = tok; + ret[sz++] = (attr & 0x0F); + ret[sz++] = ((attr & 0xF0) >> 4); + + } + + cr++; + ret[sz++] = hSession->text[baddr].chr; + + if(cut && !FA_IS_PROTECTED(fa)) { + clear_chr(hSession,baddr); + } + + } + baddr++; + } + + if(cr) + ret[sz++] = '\n'; + + if((sz+10) > buflen) + { + buflen += 100; + ret = lib3270_realloc(ret,buflen); + } + } + + if(!sz) + { + lib3270_free(ret); + errno = ENOENT; + return NULL; + } + else if(sz > 1 && ret[sz-1] == '\n') // Remove ending \n + { + ret[sz-1] = 0; + } + + ret[sz++] = 0; + + if(sz != buflen) + ret = lib3270_realloc(ret,sz); + + return ret; +} + +LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) +{ + return lib3270_get_selection(hSession,0,0); +} + +LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) +{ + return lib3270_get_selection(hSession,0,LIB3270_SELECTION_CUT); +} + + diff --git a/src/lib3270/selection/selection.c b/src/lib3270/selection/selection.c index 2e2159e..7ed893b 100644 --- a/src/lib3270/selection/selection.c +++ b/src/lib3270/selection/selection.c @@ -84,9 +84,9 @@ static void update_selected_rectangle(H3270 *session) // First remove unselected areas baddr = 0; - for(row=0;row < session->rows;row++) + for(row=0;row < ((int) session->rows);row++) { - for(col = 0; col < session->cols;col++) + for(col = 0; col < ((int) session->cols);col++) { if(!(row >= p[0].row && row <= p[1].row && col >= p[0].col && col <= p[1].col) && (session->text[baddr].attr & LIB3270_ATTR_SELECTED)) { @@ -99,9 +99,9 @@ static void update_selected_rectangle(H3270 *session) // Then, draw selected ones baddr = 0; - for(row=0;row < session->rows;row++) + for(row=0;row < ((int) session->rows);row++) { - for(col = 0; col < session->cols;col++) + for(col = 0; col < ((int) session->cols);col++) { if((row >= p[0].row && row <= p[1].row && col >= p[0].col && col <= p[1].col) && !(session->text[baddr].attr & LIB3270_ATTR_SELECTED)) { @@ -163,9 +163,9 @@ void toggle_rectselect(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LI update_selected_region(session); } -void do_select(H3270 *h, int start, int end, int rect) +void do_select(H3270 *h, unsigned int start, unsigned int end, unsigned int rect) { - if(start < 0 || end > (h->rows * h->cols)) + if(end > (h->rows * h->cols)) return; // Do we really need to change selection? @@ -240,6 +240,7 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int ba return rc; } +/* static void clear_chr(H3270 *hSession, int baddr) { hSession->text[baddr].chr = ' '; @@ -254,7 +255,7 @@ static void clear_chr(H3270 *hSession, int baddr) baddr == hSession->cursor_addr ); } -static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok, Boolean cut) +static char * get_text(H3270 *hSession, unsigned char all, char tok, unsigned char cut) { int row, col, baddr; char * ret; @@ -333,6 +334,7 @@ static char * get_text(H3270 *hSession,unsigned char all, unsigned char tok, Boo return ret; } +*/ LIB3270_EXPORT char * lib3270_get_region(H3270 *h, int start_pos, int end_pos, unsigned char all) { @@ -341,9 +343,7 @@ LIB3270_EXPORT char * lib3270_get_region(H3270 *h, int start_pos, int end_pos, u int sz = 0; int baddr; - CHECK_SESSION_HANDLE(h); - - if(!lib3270_connected(h)) + if(check_online_session(h)) return NULL; maxlen = h->rows * (h->cols+1); @@ -470,14 +470,3 @@ LIB3270_EXPORT int lib3270_has_selection(H3270 *hSession) return hSession->selected != 0; } - -LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) -{ - return get_text(hSession,0,0,0); -} - -LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) -{ - return get_text(hSession,0,0,1); -} - -- libgit2 0.21.2