From 51b3ec906969eda9472870bf9aa3c1b770dba8f4 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Wed, 4 Apr 2012 17:41:31 +0000 Subject: [PATCH] Trabalhando no suporte atk --- screen.c | 7 +++++++ selection.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/screen.c b/screen.c index 7ad09b6..2732bec 100644 --- a/screen.c +++ b/screen.c @@ -223,8 +223,15 @@ static unsigned short calc_attrs(H3270 *session, int baddr, int fa_addr, int fa) return a; } +LIB3270_EXPORT unsigned int lib3270_get_length(H3270 *h) +{ + CHECK_SESSION_HANDLE(h); + return h->rows * h->cols; +} + LIB3270_EXPORT void lib3270_get_screen_size(H3270 *h, int *r, int *c) { + CHECK_SESSION_HANDLE(h); *r = h->rows; *c = h->cols; } diff --git a/selection.c b/selection.c index a66d9a7..7ef4b61 100644 --- a/selection.c +++ b/selection.c @@ -407,9 +407,38 @@ static char * get_text(H3270 *hSession,unsigned char all) return ret; } -LIB3270_EXPORT char * lib3270_get_text(H3270 *hSession) +LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) { - return get_text(hSession,1); + char *buffer; + int col, maxlen; + char *ptr; + + CHECK_SESSION_HANDLE(h); + + maxlen = h->rows * (h->cols+1); + + if(len < 0) + len = (maxlen - offset); + else if(len > maxlen) + len = maxlen; + + buffer = malloc(len+1); + col = offset%h->cols; + ptr = buffer; + + while(len-- > 0) + { + *(ptr++) = h->text[offset++].chr; + if(col++ >= h->cols && len > 0) + { + col = 0; + *(ptr++) = '\n'; + len--; + } + } + *ptr = 0; + + return buffer; } LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) @@ -417,6 +446,10 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) if(!hSession->selected || hSession->select.begin == hSession->select.end) return NULL; + if(!lib3270_connected(hSession)) + return NULL; + + return get_text(hSession,0); } -- libgit2 0.21.2