diff --git a/pw3270.cbp b/pw3270.cbp
index eb676de..bd5b78a 100644
--- a/pw3270.cbp
+++ b/pw3270.cbp
@@ -9,8 +9,8 @@
-
-
+
+
@@ -20,8 +20,8 @@
-
-
+
+
@@ -35,304 +35,308 @@
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
+
+
-
-
-
+
+
+
-
-
+
+
-
+
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
+
+
-
-
+
+
-
-
-
+
+
-
+
+
+
-
+
-
-
+
-
-
-
-
+
+
-
-
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
-
+
+
-
-
+
+
+
+
-
+
+
-
+
-
-
-
-
+
-
-
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
+
+
-
-
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
+
+
-
-
-
-
-
+
+
+
-
+
+
+
+
+
-
-
+
-
-
+
+
-
+
+
-
-
+
-
-
+
+
-
+
+
-
-
+
-
+
+
-
+
-
+
-
+
-
+
-
+
-
-
+
-
-
+
+
-
+
+
-
-
+
-
+
+
-
+
-
-
+
-
-
+
+
-
+
+
-
+
-
+
-
-
+
-
-
-
+
+
-
+
+
+
-
-
-
+
+
+
+
+
+
diff --git a/src/include/lib3270/html.h b/src/include/lib3270/html.h
new file mode 100644
index 0000000..bbe7027
--- /dev/null
+++ b/src/include/lib3270/html.h
@@ -0,0 +1,35 @@
+/*
+ * "Software G3270, 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., 59 Temple
+ * Place, Suite 330, Boston, MA, 02111-1307, USA
+ *
+ * Este programa está nomeado como html.h e possui - linhas de código.
+ *
+ * Contatos:
+ *
+ * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
+ *
+ */
+
+#ifndef LIB3270_HTML_H_INCLUDED
+
+ #define LIB3270_HTML_H_INCLUDED 1
+
+
+#endif // LIB3270_HTML_H_INCLUDED
+
diff --git a/src/lib3270/html.c b/src/lib3270/html.c
new file mode 100644
index 0000000..b82ef0f
--- /dev/null
+++ b/src/lib3270/html.c
@@ -0,0 +1,172 @@
+/*
+ * "Software G3270, 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., 59 Temple
+ * Place, Suite 330, Boston, MA, 02111-1307, USA
+ *
+ * Este programa está nomeado como html.c e possui - linhas de código.
+ *
+ * Contatos:
+ *
+ * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
+ *
+ */
+
+ #include
+ #include
+ #include
+ #include
+
+ #include "globals.h"
+ #include "utilc.h"
+
+/*--[ Defines ]--------------------------------------------------------------------------------------*/
+
+ enum html_element
+ {
+ HTML_ELEMENT_LINE_BREAK,
+ HTML_ELEMENT_BEGIN_COLOR,
+ HTML_ELEMENT_END_COLOR,
+
+ HTML_ELEMENT_COUNT
+ };
+
+ static const char * element_text[HTML_ELEMENT_COUNT] =
+ {
+#ifdef DEBUG
+ "
\n",
+#else
+ "
",
+#endif // Debug
+ "",
+ "",
+ };
+
+ static const char * html_color[] =
+ {
+ "black",
+ "deepSkyBlue",
+ "red",
+ "pink",
+ "green",
+ "turquoise",
+ "yellow",
+ "white",
+ "black",
+ "blue",
+ "orange",
+ "purple",
+ "paleGreen",
+ "paleTurquoise",
+ "grey",
+ "white"
+ };
+
+ struct html_info
+ {
+ int szText;
+ char * text;
+ unsigned short fg;
+ unsigned short bg;
+ };
+
+ /*--[ Implement ]------------------------------------------------------------------------------------*/
+
+ static void append_string(struct html_info *info, const char *text)
+ {
+ int sz = strlen(info->text)+strlen(text);
+
+ if(strlen(info->text)+sz <= info->szText)
+ {
+ info->szText += (100+sz);
+ info->text = lib3270_realloc(info->text,info->szText);
+ }
+
+ strcat(info->text,text);
+
+ }
+
+ static void append_element(struct html_info *info, enum html_element id)
+ {
+ append_string(info,element_text[id]);
+ }
+
+ static update_colors(struct html_info *info, unsigned short attr)
+ {
+ unsigned short fg;
+ unsigned short bg = ((attr & 0x00F0) >> 4);
+ char * txt;
+
+ #warning Fix field colors
+ if(attr & LIB3270_ATTR_FIELD)
+ fg = (attr & 0x0003);
+ else
+ fg = (attr & 0x000F);
+
+ if(fg == info->fg && bg == info->bg)
+ return;
+
+ if(info->fg != 0xFF)
+ append_string(info,element_text[HTML_ELEMENT_END_COLOR]);
+
+ txt = xs_buffer(element_text[HTML_ELEMENT_BEGIN_COLOR],html_color[fg],html_color[bg]);
+ append_string(info,txt);
+ lib3270_free(txt);
+
+ info->fg = fg;
+ info->bg = bg;
+ }
+
+ LIB3270_EXPORT char * lib3270_get_as_html(H3270 *session, unsigned char all)
+ {
+ int row, col, baddr;
+ struct html_info info;
+
+ memset(&info,0,sizeof(info));
+ info.szText = session->rows * (session->cols + strlen(element_text[HTML_ELEMENT_LINE_BREAK])+1);
+ info.text = lib3270_malloc(info.szText+1);
+ info.fg = 0xFF;
+ info.bg = 0xFF;
+
+ baddr = 0;
+ for(row=0;row < session->rows;row++)
+ {
+ int cr = 0;
+
+ for(col = 0; col < session->cols;col++)
+ {
+ if(all || session->text[baddr].attr & LIB3270_ATTR_SELECTED)
+ {
+ char txt[] = { session->text[baddr].chr, 0 };
+ cr++;
+ update_colors(&info,session->text[baddr].attr);
+ append_string(&info,txt);
+ }
+ baddr++;
+ }
+
+ if(cr)
+ append_element(&info,HTML_ELEMENT_LINE_BREAK);
+ }
+
+ if(info.fg != 0xFF)
+ append_string(&info,element_text[HTML_ELEMENT_END_COLOR]);
+
+ return lib3270_realloc(info.text,strlen(info.text)+2);
+ }
+
+
diff --git a/src/lib3270/sources.mak b/src/lib3270/sources.mak
index 819f19f..86ed9a5 100644
--- a/src/lib3270/sources.mak
+++ b/src/lib3270/sources.mak
@@ -27,7 +27,7 @@
# Terminal only sources
TERMINAL_SOURCES = bounds.c XtGlue.c ctlr.c util.c toggles.c screen.c selection.c kybd.c telnet.c \
host.c sf.c ansi.c resolver.c tables.c utf8.c charset.c \
- version.c session.c state.c
+ version.c session.c state.c html.c
# Network I/O Sources
NETWORK_SOURCES = iocalls.c proxy.c
diff --git a/src/lib3270/util.c b/src/lib3270/util.c
index 6b9f219..bd5e6d6 100644
--- a/src/lib3270/util.c
+++ b/src/lib3270/util.c
@@ -191,8 +191,7 @@ char * lib3270_vsprintf(const char *fmt, va_list args)
* buffer.
* 'format' is assumed to be a printf format string with '%s's in it.
*/
-char *
-xs_buffer(const char *fmt, ...)
+char * xs_buffer(const char *fmt, ...)
{
va_list args;
char *r;
diff --git a/src/pw3270/window.c b/src/pw3270/window.c
index aa72aa1..957fed4 100644
--- a/src/pw3270/window.c
+++ b/src/pw3270/window.c
@@ -461,6 +461,16 @@
// Finish setup
#ifdef DEBUG
lib3270_testpattern(host);
+
+ {
+ #warning Temporario
+ char * text = lib3270_get_as_html(host,1);
+
+ printf("\n%s\n",text);
+
+ lib3270_free(text);
+ }
+
#endif
trace("%s ends",__FUNCTION__);
--
libgit2 0.21.2