× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Okay, continuing from our February discussion about the possiblity of
doing screen scrapping with tn5250 code base ...

My developer have begun the task, and follow the hints from Scott.
Attached is the two files he made, assuming that this list support
attachment =) If not, I will send another email with embedded code.

tn5250x.c is his changes to tn5250.c file.
nowin.c is his code in replacement for cursesterm.c file.

He manage to remove the screen, and create a small application (in
Solaris 8). No input is required. The command line parameters list down
all the necessary data to connect to the host (IP, port, etc.).

In this version, he manage to get the initial screen from the host in
the screen buffer. No screen scrapping yet, but at least we can
"retrieve" the "screen" using his codes.

Now, come the fun part. He try to hardcode the keyboard entry. So,
instead of typing (in the screen), the code itself provide the keyboard
entry. As you can see in the line 323 of nowin.c, the code "send" a
string of "testhardcode" to the keyboard buffer. But, to his dismay, the
screen is not updated =(

The strange thing is, the application (in Solaris) is somehow "waiting"
for keyboard entry. When he press ENTER, then suddenly the hardcoded
data is "typed" to the "screen" and the "screen" is updated.

Now, what's wrong? Why the need for ENTER in the application? He tought
that the hardcoded entry should be sufficient.

Anything that he missed?

Thanks.

- irving
#include "tn5250-private.h"
#include "tn5250_define.h"

#define _TN5250_TERMINAL_PRIVATE_DEFINED
#define CTRL_Q 17;

Tn5250Terminal *tn5250_nowin_terminal_new();
void nowin_terminal_setstatus(int status);
int nowin_terminal_getstatus();
char *nowin_terminal_getscreen();
void nowin_terminal_setkeyboard(char *keyboard);
void free_global_nowin_pointer();
void set_nowin_config(Tn5250Config config);

Tn5250Session *sess = NULL;
Tn5250Stream *stream = NULL;
Tn5250Terminal *term = NULL;
Tn5250Display *display = NULL;
Tn5250Config *config = NULL;

/* FIXME: This should be moved into session.[ch] or something. */
static struct valid_term {
   char *name;
   char *descr;
} valid_terms[] = {
   /* DBCS Terminals not yet supported.
    * { "IBM-5555-C01", "DBCS color" },
    * { "IBM-5555-B01", "DBCS monocrome" }, */
   { "IBM-3477-FC",  "27x132 color" },
   { "IBM-3477-FG",  "27x132 monochrome" },
   { "IBM-3180-2",   "27x132 monochrome" },
   { "IBM-3179-2",   "24x80 color" },
   { "IBM-3196-A1",  "24x80 monochrome" },
   { "IBM-5292-2",   "24x80 color" },
   { "IBM-5291-1",   "24x80 monochrome" },
   { "IBM-5251-11",  "24x80 monochrome" },
   { NULL, NULL }
};

static void clean_up_and_exit(int error);
static void syntax(void);

int main(int argc, char *argv[])
{
        int errorNo = 0;
        char huruf;
        
        /*printf("Type your command\n");        
        scanf("%c", &huruf);
        printf("\n your command = %d\n", huruf);
        
        K_CTRL('Q') for quit */
        
        if ((errorNo = tpsvrinit(argc, argv)) != 0) {
                clean_up_and_exit(errorNo);
        }
        
        tn5250_session_main_loop(sess);
        
        clean_up_and_exit(0);
}
        
/*
 * initiaze the tn5250
 */
int tpsvrinit(int argcs, char *argvs[])
{
   config = tn5250_config_new ();
   if (tn5250_config_load_default (config) == -1) {
      tn5250_config_unref (config);
      exit (1);
   }

   if (tn5250_config_parse_argv (config, argcs, argvs) == -1) {
      tn5250_config_unref (config);
      syntax ();
   }

   /* add new config */
   tn5250_config_set(config, "env.SCREEN_SIZE", "1920");
   tn5250_config_set(config, "env.KEYBOARD_SIZE", "1921");
   
   if (tn5250_config_get (config, "help")) {
      syntax ();
   }
   else if (tn5250_config_get (config, "version")) {
      printf ("tn5250 %s\n", VERSION);
      exit (0);
   }
   else if (!tn5250_config_get (config, "host")) {
      syntax ();
   }
   else if (!tn5250_config_get (config, "env.SCREEN_SIZE")) {
        syntax();
   }
   else if (!tn5250_config_get (config, "env.KEYBOARD_SIZE")) {
        syntax();
   }
   
   

   stream = tn5250_stream_open (tn5250_config_get (config, "host"), config);
   if (stream == NULL)
      return errno;

   display = tn5250_display_new ();
   if (tn5250_display_config (display, config) == -1)
      return errno;

   term = tn5250_nowin_terminal_new();
   
   if (tn5250_config_get (config, "underscores")) {}
   if (tn5250_config_get (config, "ruler")) {}
   if ((tn5250_config_get (config, "font_80"))
       && (tn5250_config_get (config, "font_132"))) {}
       
   if (term == NULL)
      return errno;
   if (tn5250_terminal_config (term, config) == -1)
      return errno;

   tn5250_terminal_init(term);  
   
   tn5250_display_set_terminal(display, term);   

   sess = tn5250_session_new();
   tn5250_display_set_session (display, sess);

   term->conn_fd = tn5250_stream_socket_handle(stream);
   tn5250_session_set_stream(sess, stream);
   if (tn5250_session_config (sess, config) == -1)
      return errno;
   
   printf("Tn5250 is ready\n");
   
   return 0;
}
   
/** 
 *  This is called when the program terminates.  It cleans up the 
 *  misc objects & reports an error if one exists.
 **/

static void clean_up_and_exit(int error) {
   free_global_nowin_pointer();
   
   if (term != NULL)
      tn5250_terminal_term(term);
   if (sess != NULL)
      tn5250_session_destroy(sess);
   else if (stream != NULL)
      tn5250_stream_destroy (stream);
   if (config != NULL)
      tn5250_config_unref (config);

   if (errno != 0) {
      printf("Could not start session: %s\n", strerror(errno));
   }
   else {
        printf("session has been shutdown\n");
   }

   exit(0);
}

static void syntax()
{
   struct valid_term *p = NULL;
   Tn5250CharMap *m = NULL;
   int i = 0;

   printf("tn5250 - TCP/IP 5250 emulator\n\ Syntax:\n");
   printf("\  tn5250 [options] HOST[:PORT]\n");
   printf("\n\Options:\n\   map=NAME                ");
   printf("Character map (default is '37'):");
   m = tn5250_transmaps;
   while (m->name != NULL) {
      if (i % 5 == 0)
         printf("\n                             "); 
      printf("%s, ", m->name);
      m++; i++;
   }
   printf("\n\   env.DEVNAME=NAME         ");
   printf("Use NAME as session name (default: none).\n");
   printf("\   +/-underscores          ");
   printf("Use/don't use underscores instead of underline\n");
   printf("\                           attribute.\n\   ");
   printf("+/-ruler                Draw a ruler pointing ");
   printf("to the cursor position\n\   +/-version              ");
   printf("Show emulator version and exit.\n\   ");
   printf("env.NAME=VALUE          Set telnet environment ");
   printf("string NAME to VALUE.\n\   env.TERM=TYPE           ");
   printf("Emulate IBM terminal type (default: depends)");
   
   p = valid_terms;
   while (p->name) {
      printf("\n                             %s (%s)", p->name, p->descr); 
      p++;
   }
   printf("\n\n");
   exit (255);
}

/* vi:set cindent sts=3 sw=3: */

/*
 * Create new terminal the name is nowin terminal
 */
#define _TN5250_TERMINAL_PRIVATE_DEFINED
#include "tn5250-private.h"
#include "tn5250_define.h"

#ifdef USE_CURSES

/* Some versions of ncurses don't have this defined. */
#ifndef A_VERTICAL
#define A_VERTICAL ((1UL) << ((22) + 8))
#endif                          /* A_VERTICAL */

/* Some older versions of ncurses don't define NCURSES_COLOR_T */
#ifndef NCURSES_COLOR_T
#define NCURSES_COLOR_T short
#endif

/* Mapping of 5250 colors to curses colors */
struct _curses_color_map {
   char *name;
   NCURSES_COLOR_T ref;
   attr_t bld;
};
typedef struct _curses_color_map curses_color_map;

static curses_color_map colorlist[] =
{
  { "black",     COLOR_BLACK         },
  { "red",       COLOR_RED,   A_BOLD },
  { "green",     COLOR_GREEN         },
  { "yellow",    COLOR_YELLOW,A_BOLD },
  { "blue",      COLOR_CYAN,  A_BOLD },
  { "pink",      COLOR_MAGENTA       },
  { "turquoise", COLOR_CYAN          },
  { "white",     COLOR_WHITE, A_BOLD },
  { NULL, -1 }
};

#define A_5250_GREEN    
((attr_t)COLOR_PAIR(COLOR_GREEN)|colorlist[COLOR_GREEN].bld)
#define A_5250_WHITE    
((attr_t)COLOR_PAIR(COLOR_WHITE)|colorlist[COLOR_WHITE].bld)
#define A_5250_RED      ((attr_t)COLOR_PAIR(COLOR_RED)|colorlist[COLOR_RED].bld)
#define A_5250_TURQ     
((attr_t)COLOR_PAIR(COLOR_CYAN)|colorlist[COLOR_CYAN].bld)
#define A_5250_YELLOW   
((attr_t)COLOR_PAIR(COLOR_YELLOW)|colorlist[COLOR_YELLOW].bld)
#define A_5250_PINK     
((attr_t)COLOR_PAIR(COLOR_MAGENTA)|colorlist[COLOR_MAGENTA].bld)
#define A_5250_BLUE     
((attr_t)COLOR_PAIR(COLOR_BLUE)|colorlist[COLOR_BLUE].bld)

/*@-globstate -nullpass@*/  /* lclint incorrectly assumes stdscr may be NULL */

static attr_t attribute_map[33];

static void nowin_terminal_init(Tn5250Terminal * This);
static void nowin_terminal_term(Tn5250Terminal * This);
static void nowin_terminal_destroy(Tn5250Terminal * This);
static int nowin_terminal_width(Tn5250Terminal * This);
static int nowin_terminal_height(Tn5250Terminal * This);
static int nowin_terminal_flags(Tn5250Terminal * This);
static void nowin_terminal_update(Tn5250Terminal * This, Tn5250Display * 
display);
static void nowin_terminal_update_indicators(Tn5250Terminal * This, 
Tn5250Display * display);
static int nowin_terminal_waitevent(Tn5250Terminal * This);
static int nowin_terminal_getkey(Tn5250Terminal * This);
static void nowin_terminal_beep(Tn5250Terminal * This);
static int nowin_terminal_config(Tn5250Terminal * This, Tn5250Config *config);


void nowin_terminal_cancelquit(Tn5250Terminal * This);
void nowin_terminal_setscreen(char *screen);
char *nowin_terminal_getscreen();
void nowin_terminal_setkeyboard(char *keyboard);
char *nowin_terminal_getkeyboard();

char *screen = NULL;
char *keyboard = NULL;
unsigned char *old_screen = NULL;
unsigned char *temp_screen = NULL;
Tn5250Config *configs;

int status = 0;
int size_screen = 0;
int size_keyboard = 0;
int sequence_keyboard = 0;
int first = 0;

FILE *log_screen = NULL;

#ifdef USE_OWN_KEY_PARSING
struct _Key {
   int         k_code;
   char        k_str[10];
};

typedef struct _Key Key;
#endif

#define MAX_K_BUF_LEN 20

struct _Tn5250TerminalPrivate {
   int            last_width, last_height;
#ifdef USE_OWN_KEY_PARSING
   unsigned char  k_buf[MAX_K_BUF_LEN];
   int            k_buf_len;

   Key *          k_map;
   int            k_map_len;
#endif
   char *         font_80;
   char *         font_132;
   int            quit_flag : 1;
   int            have_underscores : 1;
   int            underscores : 1;
   int            is_xterm : 1;
   int            display_ruler : 1;
};

#ifdef USE_OWN_KEY_PARSING
/* This is an array mapping our key code to a termcap capability
 * name. */
static Key curses_caps[] = {
   { K_ENTER, "@8" },
   { K_ENTER, "cr" },
   { K_BACKTAB, "kB" },
   { K_F1, "k1" },
   { K_F2, "k2" },
   { K_F3, "k3" },
   { K_F4, "k4" },
   { K_F5, "k5" },
   { K_F6, "k6" },
   { K_F7, "k7" },
   { K_F8, "k8" },
   { K_F9, "k9" },
   { K_F10, "k;" },
   { K_F11, "F1" },
   { K_F12, "F2" },
   { K_F13, "F3" },
   { K_F14, "F4" },
   { K_F15, "F5" },
   { K_F16, "F6" },
   { K_F17, "F7" },
   { K_F18, "F8" },
   { K_F19, "F9" },
   { K_F20, "FA" },
   { K_F21, "FB" },
   { K_F22, "FC" },
   { K_F23, "FD" },
   { K_F24, "FE" },
   { K_LEFT, "kl" },
   { K_RIGHT, "kr" },
   { K_UP, "ku" },
   { K_DOWN, "kd" },
   { K_ROLLDN, "kP" },
   { K_ROLLUP, "kN" },
   { K_BACKSPACE, "kb" },
   { K_HOME, "kh" },
   { K_END, "@7" },
   { K_INSERT, "kI" },
   { K_DELETE, "kD" },
   { K_PRINT, "%9" },
   { K_HELP, "%1" },
   { K_CLEAR, "kC" },
   { K_REFRESH, "&2" },
   { K_FIELDEXIT, "@9" },
};

/* This is an array mapping some of our vt100 sequences to our internal
 * key names. */
static Key curses_vt100[] = {
   /* CTRL strings */
   { K_ATTENTION,       "\001" }, /* CTRL A */
   { K_ROLLDN,          "\002" }, /* CTRL B */
   { K_SYSREQ,          "\003" }, /* CTRL C */
   { K_ROLLUP,          "\004" }, /* CTRL D */
   { K_ERASE,           "\005" }, /* CTRL E */
   { K_ROLLUP,          "\006" }, /* CTRL F */
   { K_FIELDEXIT,       "\013" }, /* CTRL K */
   { K_REFRESH,         "\014" }, /* CTRL L */
   { K_HOME,            "\017" }, /* CTRL O */
   { K_PRINT,           "\020" }, /* CTRL P */
   { K_RESET,           "\022" }, /* CTRL R */
   { K_TESTREQ,         "\024" }, /* CTRL T */
   { K_ROLLDN,          "\025" }, /* CTRL U */
   { K_FIELDPLUS,       "\030" }, /* CTRL X */

   /* ASCII DEL is not correctly reported as the DC key in some
    * termcaps */
   /* But it is backspace in some termcaps... */
   /* { K_DELETE,               "\177" }, /* ASCII DEL */
   { K_DELETE,          "\033\133\063\176" }, /* ASCII DEL Sequence: \E[3~ */
   

   /* ESC strings */
   { K_F1,              "\033\061" }, /* ESC 1 */
   { K_F2,              "\033\062" }, /* ESC 2 */
   { K_F3,              "\033\063" }, /* ESC 3 */
   { K_F4,              "\033\064" }, /* ESC 4 */
   { K_F5,              "\033\065" }, /* ESC 5 */
   { K_F6,              "\033\066" }, /* ESC 6 */
   { K_F7,              "\033\067" }, /* ESC 7 */
   { K_F8,              "\033\070" }, /* ESC 8 */
   { K_F9,              "\033\071" }, /* ESC 9 */
   { K_F10,             "\033\060" }, /* ESC 0 */
   { K_F11,             "\033\055" }, /* ESC - */
   { K_F12,             "\033\075" }, /* ESC = */
   { K_F13,             "\033\041" }, /* ESC ! */
   { K_F14,             "\033\100" }, /* ESC @ */
   { K_F15,             "\033\043" }, /* ESC # */
   { K_F16,             "\033\044" }, /* ESC $ */
   { K_F17,             "\033\045" }, /* ESC % */
   { K_F18,             "\033\136" }, /* ESC ^ */
   { K_F19,             "\033\046" }, /* ESC & */
   { K_F20,             "\033\052" }, /* ESC * */
   { K_F21,             "\033\050" }, /* ESC ( */
   { K_F22,             "\033\051" }, /* ESC ) */
   { K_F23,             "\033\137" }, /* ESC _ */
   { K_F24,             "\033\053" }, /* ESC + */
   { K_ATTENTION,       "\033\101" }, /* ESC A */
   { K_CLEAR,           "\033\103" }, /* ESC C */
   { K_DUPLICATE,       "\033\104" }, /* ESC D */
   { K_HELP,            "\033\110" }, /* ESC H */
   { K_INSERT,          "\033\111" }, /* ESC I */
   { K_REFRESH,         "\033\114" }, /* ESC L */
   { K_FIELDMINUS,      "\033\115" }, /* ESC M */
   { K_NEWLINE,         "\033\116" }, /* ESC N */ /* Our extension */
   { K_PRINT,           "\033\120" }, /* ESC P */
   { K_RESET,           "\033\122" }, /* ESC R */
   { K_SYSREQ,          "\033\123" }, /* ESC S */
   { K_TOGGLE,          "\033\124" }, /* ESC T */
   { K_FIELDEXIT,       "\033\130" }, /* ESC X */
   { K_NEWLINE,         "\033\012" }, /* ESC ^J */
   { K_NEWLINE,         "\033\015" }, /* ESC ^M */
   { K_INSERT,          "\033\177" }, /* ESC DEL */
   { K_NEXTWORD,        "\033\025" }, /* ESC Ctrl-U */
   { K_PREVWORD,        "\033\010" }, /* ESC Ctrl-H */
   { K_FIELDHOME,       "\033\006" }, /* ESC Ctrl-F */
   /* K_INSERT = ESC+DEL handled in code below. */
};
#endif

/****f* tn5250_nowin_terminal_new
 * NAME
 *    tn5250_nowin_terminal_new
 * SYNOPSIS
 *    ret = tn5250_nowin_terminal_new ();
 * INPUTS
 *    None
 * DESCRIPTION
 *    Create a new nowin terminal object.
 *    This is the same like cursesterm unless there is code to open a file for 
debug and there is a pointer to terminal->config
 *****/
Tn5250Terminal *tn5250_nowin_terminal_new()
{
   Tn5250Terminal *r = tn5250_new(Tn5250Terminal, 1);
   if (r == NULL)
      return NULL;

   r->data = tn5250_new(struct _Tn5250TerminalPrivate, 1);
   if (r->data == NULL) {
      free(r);
      return NULL;
   }

   r->data->have_underscores = 0;
   r->data->underscores = 0;
   r->data->quit_flag = 0;
   r->data->last_width = 0;
   r->data->last_height = 0;
   r->data->is_xterm = 0;
   r->data->font_80 = NULL;
   r->data->font_132 = NULL;
   r->data->display_ruler = 0;

#ifdef USE_OWN_KEY_PARSING
   r->data->k_buf_len = 0;
   r->data->k_map_len = 0;
   r->data->k_map = NULL;
#endif

   r->conn_fd = -1;
   r->init = nowin_terminal_init;
   r->term = nowin_terminal_term;
   r->destroy = nowin_terminal_destroy;
   r->width = nowin_terminal_width;
   r->height = nowin_terminal_height;
   r->flags = nowin_terminal_flags;
   r->update = nowin_terminal_update;
   r->update_indicators = nowin_terminal_update_indicators;
   r->waitevent = nowin_terminal_waitevent;
   r->getkey = nowin_terminal_getkey;
   r->beep = nowin_terminal_beep;
   r->config = nowin_terminal_config;
   
   log_screen = fopen("/export/home/root/tn5250-0.16.5/src/debug_screen.txt", 
"w");
   
   return r;
}

/****i* nowin_terminal_init
 * NAME
 *    nowin_terminal_init
 * SYNOPSIS
 *    nowin_terminal_init (This);
 * INPUTS
 *    Tn5250Terminal *     This       - 
 * DESCRIPTION
 *    To get screen size and create old_scree, temp_screen, keyboard buffer
 *    and set the keyboar buffer with string
 *****/
static void nowin_terminal_init(Tn5250Terminal * This) {
        
        /* read environment and assign to nowin global variable*/
        size_screen = atoi(tn5250_config_get(configs, "env.SCREEN_SIZE"));
        size_keyboard = atoi(tn5250_config_get(configs, "env.KEYBOARD_SIZE"));  
        
        old_screen = malloc(sizeof(unsigned char *) * size_screen);
        temp_screen = malloc(sizeof(unsigned char *) * size_screen + 1);
        keyboard = malloc(sizeof(unsigned char *) * size_keyboard);
        
        memset(keyboard, 0, size_keyboard);
        memset(old_screen, 0, size_screen);
        memset(temp_screen, 0, size_screen + 1);
        
        sequence_keyboard = 0;
        strcpy(keyboard, "testhardcode\n");     
        
}

/****i* nowin_terminal_config
 * NAME
 *    nowin_terminal_init
 * SYNOPSIS
 *    nowin_terminal_init (This, config);
 * INPUTS
 *    Tn5250Terminal *     This  
 *    Tn5250Config *       config      
 * DESCRIPTION
 *    To set config to global variable in nowin.c
 *****/
static int nowin_terminal_config(Tn5250Terminal * This, Tn5250Config *config) {
        
        configs = config;
        
        return 0;
}

/****i* nowin_terminal_term
 * NAME
 *    nowin_terminal_term
 * SYNOPSIS
 *    nowin_terminal_term (This);
 * INPUTS
 *    Tn5250Terminal  *    This       - 
 * DESCRIPTION
 *   Don't have anything to do in here
 *****/
static void nowin_terminal_term(Tn5250Terminal * This) {}

/****i* nowin_terminal_destroy
 * NAME
 *    nowin_terminal_destroy
 * SYNOPSIS
 *    nowin_terminal_destroy (This);
 * INPUTS
 *    Tn5250Terminal *     This       - 
 * DESCRIPTION
 *    The same like in cursesterm.c
 *****/
static void nowin_terminal_destroy(Tn5250Terminal * This)
{
#ifdef USE_OWN_KEY_PARSING
   if (This->data->k_map != NULL)
      free(This->data->k_map);
#endif
   if (This->data->font_80 !=NULL)
      free(This->data->font_80);
   if (This->data->font_132 !=NULL)
      free(This->data->font_132);
   if (This->data != NULL)
      free(This->data);
   free(This);
}

/****i* nowin_terminal_width
 * NAME
 *    nowin_terminal_width
 * SYNOPSIS
 *    ret = nowin_terminal_width (This);
 * INPUTS
 *    Tn5250Terminal  *    This       - 
 * DESCRIPTION
 *    Don't have anything to do in here, so return is hardcoded to 1
 *****/
static int nowin_terminal_width(Tn5250Terminal /*@unused@*/ * This)
{
   return 1;
}

/****i* nowin_terminal_height
 * NAME
 *    nowin_terminal_height
 * SYNOPSIS
 *    ret = nowin_terminal_height (This);
 * INPUTS
 *    Tn5250Terminal  *    This       - 
 * DESCRIPTION
 *    Don't have anything to do in here so the return is hardcoded to 1
 *****/
static int nowin_terminal_height(Tn5250Terminal /*@unused@*/ * This)
{
   return 1;
}

/****i* nowin_terminal_flags
 * NAME
 *    nowin_terminal_flags
 * SYNOPSIS
 *    ret = nowin_terminal_flags (This);
 * INPUTS
 *    Tn5250Terminal  *    This       - 
 * DESCRIPTION
 *    Don't have anything to do in here
 *****/
static int nowin_terminal_flags(Tn5250Terminal /*@unused@*/ * This)
{
   int f = 0;
   
   f |= TN5250_TERMINAL_HAS_COLOR;
   
   return f;
}

/****i* nowin_terminal_update
 * NAME
 *    nowin_terminal_update
 * SYNOPSIS
 *    nowin_terminal_update (This, display);
 * INPUTS
 *    Tn5250Terminal *     This       - 
 *    Tn5250Display *      display    - 
 * DESCRIPTION
 *    To get the diplay buffer and compare it with the last copy of display 
buffer if different then write the display buffer to file
 *****/
static void nowin_terminal_update(Tn5250Terminal * This, Tn5250Display *display)
{
   int my, mx;
   int y, x;
   attr_t curs_attr;
   unsigned char a = 0x20, ch;
   static count = 0;   

   mx = tn5250_display_width(display);
   my = tn5250_display_height(display);
   count++;
   
   if (log_screen != NULL && memcmp(old_screen, display->display_buffers->data, 
tn5250_display_height(display) * tn5250_display_width(display)) != 0) {
           fprintf(log_screen, "\nScreen count=%d:\n", count);
           
           for(y = 0; y < my; y++) {
                for(x = 0; x < mx; x++) {
                        tn5250_display_char_map(display);
                        
                        ch = 
tn5250_char_map_to_local(tn5250_display_char_map(display), 
display->display_buffers->data[(y*mx) + x]);
                        
                        /*fprintf(log_screen, "\n\t%d\t%d\t|%c|", ((y*mx) + x), 
ch, ch);*/
                        
                        switch (ch) {
                                case 132 :
                                   ch = 155;
                                   break;
                                case 27 :
                                case 130 :
                                case 128 :
                                   ch = 32;
                                   break;       
                        }
                        /*if (ch == 143) {
                                ch = 32;
                        }
                        else if (ch == 27) {
                                ch = 32;
                        }
                        else if (ch == 129) {
                                ch = 32;
                        }
                        else if (ch == 128) {
                                ch = 32;
                        }
                        fprintf(log_screen, "%c", ch);*/
                        temp_screen[(y*mx) + x] = ch;
                }
                /*printf("\n");*/
           }
           fprintf(log_screen, "%s\nEnd of Screen :\n", temp_screen);
           memcpy(old_screen, display->display_buffers->data, 
tn5250_display_height(display) * tn5250_display_width(display));
           
           fflush(log_screen);
           memset(temp_screen, 0, size_screen + 1);
           
           if (first == 0) {
                first++;
           }
   }
   
   /* This performs the refresh () */
   nowin_terminal_update_indicators(This, display);
}


/****i* nowin_terminal_update_indicators
 * NAME
 *    nowin_terminal_update_indicators
 * SYNOPSIS
 *    nowin_terminal_update_indicators (This, display);
 * INPUTS
 *    Tn5250Terminal  *    This       - 
 *    Tn5250Display *      display    - 
 * DESCRIPTION
 *    Don't have anything to do in here
 *****/
static void nowin_terminal_update_indicators(Tn5250Terminal * This, 
Tn5250Display *display) {}

/****i* nowin_terminal_waitevent
 * NAME
 *    nowin_terminal_waitevent
 * SYNOPSIS
 *    ret = nowin_terminal_waitevent (This);
 * INPUTS
 *    Tn5250Terminal *     This       - 
 * DESCRIPTION
 *    This is the same like in cursesterm.c but what is the event that can 
change the even data to even key ?
 *****/
static int nowin_terminal_waitevent(Tn5250Terminal * This)
{
   fd_set fdr;
   int result = 0;
   int sm;


   if (This->data->quit_flag)
      return TN5250_TERMINAL_EVENT_QUIT;

   FD_ZERO(&fdr);

   FD_SET(0, &fdr);
   sm = 1;
   if (This->conn_fd >= 0) {
      FD_SET(This->conn_fd, &fdr);
      sm = This->conn_fd + 1;
   }

   select(sm, &fdr, NULL, NULL, NULL);

   if (FD_ISSET(0, &fdr))
      result |= TN5250_TERMINAL_EVENT_KEY;

   if (This->conn_fd >= 0 && FD_ISSET(This->conn_fd, &fdr))
      result |= TN5250_TERMINAL_EVENT_DATA;

     
   if (log_screen != NULL) {
           if (result == TN5250_TERMINAL_EVENT_KEY) {
                fprintf(log_screen, "\nTN5250_TERMINAL_EVENT_KEY\n");
           }
           if (result == TN5250_TERMINAL_EVENT_DATA) {
                fprintf(log_screen, "\nTN5250_TERMINAL_EVENT_DATA\n");
           }       
   }
   
   return result;
}

/****i* nowin_terminal_beep
 * NAME
 *    nowin_terminal_beep
 * SYNOPSIS
 *    nowin_terminal_beep (This);
 * INPUTS
 *    Tn5250Terminal *     This       - 
 * DESCRIPTION
 *    Don't have anything to do in here
 *****/
static void nowin_terminal_beep (Tn5250Terminal *This) {}

/****i* nowin_get_key
 * NAME
 *    nowin_get_key
 * SYNOPSIS
 *    nowin_get_key (This);
 * INPUTS
 *    Tn5250Terminal *     This       - 
 *    int                  rmflag
 * DESCRIPTION
 *    Read the char from keyboard buffer
 *****/
static int nowin_get_key (Tn5250Terminal *This, int rmflag)
{
   int ch;
   
   if (sequence_keyboard >= 0) {
        ch = keyboard[sequence_keyboard];
        
        if (ch == '\n') {
                sequence_keyboard = -1;
        }
        else {
                sequence_keyboard++;            
        }
        
        return ch;
   }

   return -1;
}

/****i* nowin_terminal_getkey
 * NAME
 *    nowin_terminal_getkey
 * SYNOPSIS
 *    nowin_terminal_getkey (This);
 * INPUTS
 *    Tn5250Terminal *     This       - 
 *    int                  rmflag
 * DESCRIPTION
 *    This is the same like in cursesterm.c but There is no reading char from 
console
 *****/
static int nowin_terminal_getkey (Tn5250Terminal *This)
{
   int ch;

    /*Retreive all keys from the keyboard buffer. */
   /*while (This->data->k_buf_len < MAX_K_BUF_LEN && (ch = getch ()) != ERR) {
      TN5250_LOG(("nowin_getch: received 0x%02X.\n", ch));*/

      /* FIXME: Here would be the proper place to get mouse events :) */
     
      /* HACK! Why are we gettings these 0410s still?  ncurses bug? */
      /*if (ch < 0 || ch > 255)
         continue;

      This->data->k_buf[This->data->k_buf_len++] = ch;
   }*/ 

   ch = nowin_get_key (This, 1);
   
   if (log_screen != NULL && ch > 0) {
           fprintf(log_screen, "\nthis key int = %d; char = %c\n", ch, ch);
           fflush(log_screen);
   }
   
   switch (ch) {
   case K_CTRL('Q'):
      This->data->quit_flag = 1;
      return -1;
   case 0x0a:
      return 0x0d;      
   }
   return ch;  
   
}

#endif /* USE_CURSES */


/*
 * All function below haven't used yet unless free_global_nowin_pointer
 */
void nowin_terminal_setstatus(int statuz) {
        
        switch (statuz) {
                case LOGIN : 
                        status = LOGIN;
                        break;
                case READY :
                        status = READY;
                        break;
                case SEND :
                        status = SEND;
                        break;
                case IDLE :
                        status = IDLE;
                        break;          
        }
}

int nowin_terminal_getstatus() {
        status;
}

char *nowin_terminal_getscreen() {
        return screen;  
}

void nowin_terminal_setkeyboard(char *keyboard) {
        keyboard = keyboard;
}

void free_global_nowin_pointer() {
        
        if (screen != NULL) {
                free(screen);
                screen = NULL;
        }       
        if (old_screen != NULL) {
                free(old_screen);
                old_screen = NULL;
        }
        if (temp_screen != NULL) {
                free(temp_screen);
                temp_screen = NULL;
        }
        if (keyboard != NULL) {
                free(keyboard);
                keyboard = NULL;
        }
        if (log_screen != NULL) {
                fclose(log_screen);
                free(log_screen);
                log_screen = NULL;
        }
}

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.