Commit 66621f1365b8ffb3cda2a810e2c87d7bb911fb3d

Authored by perry.werneck@gmail.com
1 parent 5990d830

Implementando copia do buffer de terminal em formato html

Showing 3 changed files with 174 additions and 3 deletions   Show diff stats
html.c 0 → 100644
... ... @@ -0,0 +1,172 @@
  1 +/*
  2 + * "Software G3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple
  19 + * Place, Suite 330, Boston, MA, 02111-1307, USA
  20 + *
  21 + * Este programa está nomeado como html.c e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + *
  27 + */
  28 +
  29 + #include <string.h>
  30 + #include <lib3270.h>
  31 + #include <lib3270/session.h>
  32 + #include <lib3270/html.h>
  33 +
  34 + #include "globals.h"
  35 + #include "utilc.h"
  36 +
  37 +/*--[ Defines ]--------------------------------------------------------------------------------------*/
  38 +
  39 + enum html_element
  40 + {
  41 + HTML_ELEMENT_LINE_BREAK,
  42 + HTML_ELEMENT_BEGIN_COLOR,
  43 + HTML_ELEMENT_END_COLOR,
  44 +
  45 + HTML_ELEMENT_COUNT
  46 + };
  47 +
  48 + static const char * element_text[HTML_ELEMENT_COUNT] =
  49 + {
  50 +#ifdef DEBUG
  51 + "<br />\n",
  52 +#else
  53 + "<br />",
  54 +#endif // Debug
  55 + "<span style=\"color:%s;background-color:%s\">",
  56 + "</span>",
  57 + };
  58 +
  59 + static const char * html_color[] =
  60 + {
  61 + "black",
  62 + "deepSkyBlue",
  63 + "red",
  64 + "pink",
  65 + "green",
  66 + "turquoise",
  67 + "yellow",
  68 + "white",
  69 + "black",
  70 + "blue",
  71 + "orange",
  72 + "purple",
  73 + "paleGreen",
  74 + "paleTurquoise",
  75 + "grey",
  76 + "white"
  77 + };
  78 +
  79 + struct html_info
  80 + {
  81 + int szText;
  82 + char * text;
  83 + unsigned short fg;
  84 + unsigned short bg;
  85 + };
  86 +
  87 + /*--[ Implement ]------------------------------------------------------------------------------------*/
  88 +
  89 + static void append_string(struct html_info *info, const char *text)
  90 + {
  91 + int sz = strlen(info->text)+strlen(text);
  92 +
  93 + if(strlen(info->text)+sz <= info->szText)
  94 + {
  95 + info->szText += (100+sz);
  96 + info->text = lib3270_realloc(info->text,info->szText);
  97 + }
  98 +
  99 + strcat(info->text,text);
  100 +
  101 + }
  102 +
  103 + static void append_element(struct html_info *info, enum html_element id)
  104 + {
  105 + append_string(info,element_text[id]);
  106 + }
  107 +
  108 + static update_colors(struct html_info *info, unsigned short attr)
  109 + {
  110 + unsigned short fg;
  111 + unsigned short bg = ((attr & 0x00F0) >> 4);
  112 + char * txt;
  113 +
  114 + #warning Fix field colors
  115 + if(attr & LIB3270_ATTR_FIELD)
  116 + fg = (attr & 0x0003);
  117 + else
  118 + fg = (attr & 0x000F);
  119 +
  120 + if(fg == info->fg && bg == info->bg)
  121 + return;
  122 +
  123 + if(info->fg != 0xFF)
  124 + append_string(info,element_text[HTML_ELEMENT_END_COLOR]);
  125 +
  126 + txt = xs_buffer(element_text[HTML_ELEMENT_BEGIN_COLOR],html_color[fg],html_color[bg]);
  127 + append_string(info,txt);
  128 + lib3270_free(txt);
  129 +
  130 + info->fg = fg;
  131 + info->bg = bg;
  132 + }
  133 +
  134 + LIB3270_EXPORT char * lib3270_get_as_html(H3270 *session, unsigned char all)
  135 + {
  136 + int row, col, baddr;
  137 + struct html_info info;
  138 +
  139 + memset(&info,0,sizeof(info));
  140 + info.szText = session->rows * (session->cols + strlen(element_text[HTML_ELEMENT_LINE_BREAK])+1);
  141 + info.text = lib3270_malloc(info.szText+1);
  142 + info.fg = 0xFF;
  143 + info.bg = 0xFF;
  144 +
  145 + baddr = 0;
  146 + for(row=0;row < session->rows;row++)
  147 + {
  148 + int cr = 0;
  149 +
  150 + for(col = 0; col < session->cols;col++)
  151 + {
  152 + if(all || session->text[baddr].attr & LIB3270_ATTR_SELECTED)
  153 + {
  154 + char txt[] = { session->text[baddr].chr, 0 };
  155 + cr++;
  156 + update_colors(&info,session->text[baddr].attr);
  157 + append_string(&info,txt);
  158 + }
  159 + baddr++;
  160 + }
  161 +
  162 + if(cr)
  163 + append_element(&info,HTML_ELEMENT_LINE_BREAK);
  164 + }
  165 +
  166 + if(info.fg != 0xFF)
  167 + append_string(&info,element_text[HTML_ELEMENT_END_COLOR]);
  168 +
  169 + return lib3270_realloc(info.text,strlen(info.text)+2);
  170 + }
  171 +
  172 +
... ...
sources.mak
... ... @@ -27,7 +27,7 @@
27 27 # Terminal only sources
28 28 TERMINAL_SOURCES = bounds.c XtGlue.c ctlr.c util.c toggles.c screen.c selection.c kybd.c telnet.c \
29 29 host.c sf.c ansi.c resolver.c tables.c utf8.c charset.c \
30   - version.c session.c state.c
  30 + version.c session.c state.c html.c
31 31  
32 32 # Network I/O Sources
33 33 NETWORK_SOURCES = iocalls.c proxy.c
... ...
util.c
... ... @@ -191,8 +191,7 @@ char * lib3270_vsprintf(const char *fmt, va_list args)
191 191 * buffer.
192 192 * 'format' is assumed to be a printf format string with '%s's in it.
193 193 */
194   -char *
195   -xs_buffer(const char *fmt, ...)
  194 +char * xs_buffer(const char *fmt, ...)
196 195 {
197 196 va_list args;
198 197 char *r;
... ...