From a2c1ad411ef19f26fe7ea28a947aab63c7abaca1 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Fri, 31 Aug 2012 14:03:48 +0000 Subject: [PATCH] Android - Iniciando implementação de suporte para script de autostart --- android/jni/main.cpp | 36 ++++++++++++++++++++++++++---------- android/jni/misc.cpp | 10 ++++++++++ android/jni/text.cpp | 43 +++++++++++++++++++++++-------------------- android/res/layout/menu.xml | 2 -- android/res/xml/preferences.xml | 7 +++++++ android/src/br/com/bb/pw3270/PW3270Activity.java | 4 ---- android/src/br/com/bb/pw3270/SettingsActivity.java | 1 + android/src/br/com/bb/pw3270/lib3270.java | 49 +++++++++++++++++++++++++++++++++++-------------- configure.ac | 1 - pw3270.cbp | 2 +- src/include/lib3270.h | 4 ++-- src/include/lib3270/log.h | 15 ++++++++++----- src/include/lib3270/session.h | 6 ++++-- src/include/pw3270.h | 6 ++++++ src/lib3270/ctlr.c | 58 ++++++++++++++++++++++++++++++++++++---------------------- src/lib3270/host.c | 8 ++++++-- src/lib3270/kybd.c | 19 ++++++++++++------- src/lib3270/resolver.c | 8 +++++--- src/lib3270/screen.c | 37 +++++++++++++++++++++++++------------ src/lib3270/selection.c | 2 +- src/lib3270/session.c | 10 ++++++++-- src/lib3270/telnet.c | 7 +++++-- src/pw3270/common/common.h | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/pw3270/common/common.h.in | 100 ---------------------------------------------------------------------------------------------------- src/pw3270/main.c | 11 ++++------- src/pw3270/v3270/mouse.c | 2 +- src/pw3270/v3270/private.h | 2 +- 27 files changed, 327 insertions(+), 221 deletions(-) create mode 100644 src/pw3270/common/common.h delete mode 100644 src/pw3270/common/common.h.in diff --git a/android/jni/main.cpp b/android/jni/main.cpp index bf735e9..d18990b 100644 --- a/android/jni/main.cpp +++ b/android/jni/main.cpp @@ -126,11 +126,6 @@ static int popuphandler(H3270 *session, void *terminal, LIB3270_NOTIFY type, con } } -static void ctlr_done(H3270 *session) -{ - pw3270_jni_post_message(4); -} - void update_status(H3270 *session, LIB3270_MESSAGE id) { pw3270_jni_post_message(1,(int) id); @@ -255,6 +250,26 @@ static void tracehandler(H3270 *session, const char *fmt, va_list args) } #endif // X3270_TRACE +static void ctlr_done(H3270 *session) +{ + __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "%s",__FUNCTION__); + pw3270_jni_post_message(5); +} + +static void autostart(H3270 *session) +{ + // pw3270_jni_post_message(10); + + { + char *text = lib3270_get_text(PW3270_SESSION,0,-1); + if(text) + { + __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "Contents:\n%s\n",text); + lib3270_free(text); + } + } +} + jint JNI_OnLoad(JavaVM *vm, void *reserved) { H3270 * session = lib3270_session_new(""); @@ -270,11 +285,12 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) lib3270_set_popup_handler(popuphandler); lib3270_register_time_handlers(add_timer,remove_timer); - session->write = write_buffer; - session->changed = changed; - session->erase = erase; - session->ctlr_done = ctlr_done; - session->update_status = update_status; + session->write = write_buffer; + session->changed = changed; + session->erase = erase; + session->ctlr_done = ctlr_done; + session->update_status = update_status; + session->autostart = autostart; return JNI_VERSION_1_4; } diff --git a/android/jni/misc.cpp b/android/jni/misc.cpp index bea9a00..22b9c49 100644 --- a/android/jni/misc.cpp +++ b/android/jni/misc.cpp @@ -58,3 +58,13 @@ JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_setToggle(JNIEnv *env, jobj } +JNIEXPORT jboolean JNICALL Java_br_com_bb_pw3270_lib3270_in3270 (JNIEnv *env, jobject obj) +{ + jboolean rc; + + PW3270_JNI_BEGIN + rc = lib3270_in_3270(PW3270_SESSION) ? JNI_TRUE : JNI_FALSE; + PW3270_JNI_END + + return rc; +} diff --git a/android/jni/text.cpp b/android/jni/text.cpp index 8275d65..65d4ef7 100644 --- a/android/jni/text.cpp +++ b/android/jni/text.cpp @@ -68,44 +68,33 @@ JNIEXPORT jbyteArray JNICALL Java_br_com_bb_pw3270_lib3270_getHTML(JNIEnv *env, return ret; } - -/* JNIEXPORT jbyteArray JNICALL Java_br_com_bb_pw3270_lib3270_getText(JNIEnv *env, jobject obj) { jbyteArray ret; PW3270_JNI_BEGIN - trace("%s starts",__FUNCTION__); - - if(session) - { - char *text = lib3270_get_text(session,0,-1); +// trace("%s starts",__FUNCTION__); - trace("%s will return \"%s\"",__FUNCTION__,text ? text : ""); + char *text = lib3270_get_text(PW3270_SESSION,0,-1); - if(text) - { - ret = retString(env,text); - lib3270_free(text); - } - else - { - ret = retString(env, ""); - } + if(text) + { + ret = retString(text); + lib3270_free(text); } else { - ret = retString(env, "Invalid Session ID"); + ret = retString(""); } - trace("%s ends",__FUNCTION__); +// trace("%s ends",__FUNCTION__); PW3270_JNI_END return ret; } -*/ + JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_setTextAt(JNIEnv *env, jobject obj, jint pos, jbyteArray inText, jint szText) { @@ -149,3 +138,17 @@ JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_setTextAt(JNIEnv *env, jobj PW3270_JNI_END } + +JNIEXPORT jint JNICALL Java_br_com_bb_pw3270_lib3270_input(JNIEnv *env, jobject obj, jstring str, jint pasting) +{ + int rc = -1; + + PW3270_JNI_BEGIN + + if(lib3270_connected(PW3270_SESSION)) + rc = lib3270_emulate_input(PW3270_SESSION, env->GetStringUTFChars(str, 0), -1, (int) pasting); + + PW3270_JNI_END + + return rc; +} diff --git a/android/res/layout/menu.xml b/android/res/layout/menu.xml index bd0af73..c503c0c 100644 --- a/android/res/layout/menu.xml +++ b/android/res/layout/menu.xml @@ -7,8 +7,6 @@ android:title="Conectar" /> - + diff --git a/android/src/br/com/bb/pw3270/PW3270Activity.java b/android/src/br/com/bb/pw3270/PW3270Activity.java index 6d7ed39..aa8d841 100644 --- a/android/src/br/com/bb/pw3270/PW3270Activity.java +++ b/android/src/br/com/bb/pw3270/PW3270Activity.java @@ -165,10 +165,6 @@ public class PW3270Activity extends Activity startActivityForResult(myIntent, 0); break; - case R.id.reload: - host.view.reload(); - break; - case R.id.about: showAboutDialog(); break; diff --git a/android/src/br/com/bb/pw3270/SettingsActivity.java b/android/src/br/com/bb/pw3270/SettingsActivity.java index 0654d6b..64593bb 100644 --- a/android/src/br/com/bb/pw3270/SettingsActivity.java +++ b/android/src/br/com/bb/pw3270/SettingsActivity.java @@ -70,6 +70,7 @@ public class SettingsActivity extends Activity // Update summary from settings new stringSetting(findPreference("hostname")); new stringSetting(findPreference("port")); + new stringSetting(findPreference("logonstring")); } diff --git a/android/src/br/com/bb/pw3270/lib3270.java b/android/src/br/com/bb/pw3270/lib3270.java index 6034850..1f464d7 100644 --- a/android/src/br/com/bb/pw3270/lib3270.java +++ b/android/src/br/com/bb/pw3270/lib3270.java @@ -59,12 +59,12 @@ public abstract class lib3270 protected int screenState = -1; private lib3270 hSession = this; - + public ProgressDialog dlgSysMessage = null; public WebView view = null; public Resources res = null; public Activity mainact = null; - + private static boolean initialized = false; private static NetworkThread mainloop = null; private static boolean connected = false; @@ -139,6 +139,25 @@ public abstract class lib3270 new timer(((Long) msg.obj).longValue(), msg.arg1); break; + case 10: // Run autostart + Log.v(TAG, "AAA---------------------------------------------------------------"); + Log.v(TAG, "In3270="+(in3270() ? "Yes" : "No")); + + /* + String str = settings.getString("logonstring",""); + Log.v(TAG, "Logon string is \"" + str + "\""); + if( str != "") + { + int sz = input(str,0); + Log.v(TAG, "Input exits with "+sz); + } + */ + + Log.v(TAG, "Contents:\n" + getText() + "\n"); + + Log.v(TAG, "AAA---------------------------------------------------------------"); + break; + } } }; @@ -157,7 +176,7 @@ public abstract class lib3270 this.screenState = -1; for(int f = 0; f < toggle.length; f++) - setToggle(toggle[f],settings.getBoolean(toggle[f],false)); + setToggle(toggle[f],settings.getBoolean(toggle[f],true)); } @@ -301,12 +320,12 @@ public abstract class lib3270 while (connected) { - byte[] in = new byte[4096]; + byte[] in = new byte[16384]; int sz = -1; try { - sz = inData.read(in, 0, 4096); + sz = inData.read(in, 0, 16384); } catch (Exception e) { @@ -365,18 +384,18 @@ public abstract class lib3270 msg.obj = new popupMessageInfo(title, text, info); mHandler.sendMessage(msg); } - + void setActivity(Activity act) { this.mainact = act; this.settings = PreferenceManager.getDefaultSharedPreferences(act); this.res = act.getResources(); } - + WebView setView(WebView v) { this.view = v; - + view.addJavascriptInterface(this, "pw3270"); view.setWebChromeClient(new WebChromeClient()); @@ -388,11 +407,11 @@ public abstract class lib3270 view.getSettings().setJavaScriptEnabled(true); return view; - + } - + public abstract String getProgramMessageText(int id); - + /*---[ Signal methods ]--------------------------------------------------*/ protected void showProgramMessage(int id) @@ -403,7 +422,6 @@ public abstract class lib3270 if(screenState != 0) { screenState = 0; -// Log.v(TAG, "Status changed to NONE"); reload(); } break; @@ -558,8 +576,8 @@ public abstract class lib3270 return text; } - - + + /*---[ Native calls ]----------------------------------------------------*/ private native int processEvents(); @@ -614,4 +632,7 @@ public abstract class lib3270 public native void setTextAt(int offset, byte[] str, int len); + public native int input(String text, int pasting); + + public native boolean in3270(); } diff --git a/configure.ac b/configure.ac index eef7546..4b2c5ac 100644 --- a/configure.ac +++ b/configure.ac @@ -356,7 +356,6 @@ AC_CONFIG_FILES([ src/lib3270/mkversion.sh src/pw3270/Makefile src/pw3270/uiparser/Makefile - src/pw3270/common/common.h src/tools/Makefile man/Makefile makegtkruntime.sh diff --git a/pw3270.cbp b/pw3270.cbp index 7e89da6..3a2e378 100644 --- a/pw3270.cbp +++ b/pw3270.cbp @@ -219,7 +219,7 @@ - + diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 0a3a1ef..4065273 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -172,7 +172,7 @@ LIB3270_MESSAGE_NONE, /**< No message */ LIB3270_MESSAGE_SYSWAIT, LIB3270_MESSAGE_TWAIT, - LIB3270_MESSAGE_CONNECTED, + LIB3270_MESSAGE_CONNECTED, /**< Connected */ LIB3270_MESSAGE_DISCONNECTED, /**< Disconnected from host */ LIB3270_MESSAGE_AWAITING_FIRST, LIB3270_MESSAGE_MINUS, @@ -443,7 +443,7 @@ * * @return The number of unprocessed characters. */ - LIB3270_EXPORT int lib3270_emulate_input(H3270 *session, char *s, int len, int pasting); + LIB3270_EXPORT int lib3270_emulate_input(H3270 *session, const char *s, int len, int pasting); /** * Set string at current cursor position. diff --git a/src/include/lib3270/log.h b/src/include/lib3270/log.h index a067942..0666b51 100644 --- a/src/include/lib3270/log.h +++ b/src/include/lib3270/log.h @@ -39,10 +39,14 @@ #include + #define DEBUG 1 + #define lib3270_write_log(s,m,f,...) __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, f "\n", __VA_ARGS__ ) #define lib3270_write_rc(s,m,r,f,...) __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, f "\n", __VA_ARGS__ ) #define lib3270_write_va_log(s,m,f,a) __android_log_vprint(ANDROID_LOG_VERBOSE, PACKAGE_NAME, f "\n", a) + #define trace( fmt, ... ) __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); + #else LIB3270_EXPORT void lib3270_set_log_handler(void (*loghandler)(H3270 *, const char *, int, const char *, va_list)); @@ -50,13 +54,14 @@ LIB3270_EXPORT int lib3270_write_rc(H3270 *session, const char *module, int rc, const char *fmt, ...) LIB3270_GNUC_FORMAT(4,5); LIB3270_EXPORT void lib3270_write_va_log(H3270 *session, const char *module, const char *fmt, va_list arg); + #ifdef DEBUG + #define trace( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr); + #else + #define trace(x, ...) // __VA_ARGS__ + #endif + #endif // ANDROID - #ifdef DEBUG - #define trace( fmt, ... ) fprintf(stderr, "%s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__ ); fflush(stderr); - #else - #define trace(x, ...) // __VA_ARGS__ - #endif #endif // LIB3270_LOG_H_INCLUDED diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index 54fbb08..c3af9d2 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -110,6 +110,8 @@ int need_tls_follows : 1; int cut_xfer_in_progress : 1; int auto_keymap : 1; + int formatted : 1; /**< Formatted screen flag */ + int starting : 1; /**< Is starting (no first screen)? */ char * oversize; @@ -162,8 +164,6 @@ int screen_alt; /**< alternate screen? */ int is_altbuffer; - int formatted; /**< set in screen_disp */ - // Screen contents void * buffer[2]; /**< Internal buffers */ struct lib3270_ea * ea_buf; /**< 3270 device buffer. ea_buf[-1] is the dummy default field attribute */ @@ -401,6 +401,7 @@ void (*update_model)(H3270 *session, const char *name, int model, int rows, int cols); void (*update_selection)(H3270 *session, int start, int end); void (*update_ssl)(H3270 *session, LIB3270_SSL_STATE state); +// void (*update_formatted)(H3270 *session,int state); void (*set_timer)(H3270 *session, unsigned char on); void (*erase)(H3270 *session); @@ -409,6 +410,7 @@ void (*cursor)(H3270 *session, LIB3270_CURSOR id); void (*set_selection)(H3270 *session, unsigned char on); void (*ctlr_done)(H3270 *session); + void (*autostart)(H3270 *session); void (*message)(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text); diff --git a/src/include/pw3270.h b/src/include/pw3270.h index 3a02ada..56d61be 100644 --- a/src/include/pw3270.h +++ b/src/include/pw3270.h @@ -61,6 +61,12 @@ LIB3270_EXPORT void pw3270_save_window_state(GtkWidget *widget, const gchar *name); LIB3270_EXPORT void pw3270_restore_window_state(GtkWidget *widget, const gchar *name); +#ifdef HAVE_GTKMAC + LIB3270_EXPORT GtkMacBundle * pw3270_get_bundle(void); +#endif + + + G_END_DECLS #endif // PW3270_H_INCLUDED diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index d97ca9a..678abd8 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -67,7 +67,8 @@ // Boolean dbcs = False; /* Statics */ -static void set_formatted(H3270 *session); +static void update_formatted(H3270 *session); +static void set_formatted(H3270 *hSession, int state); static void ctlr_blanks(H3270 *session); static void ctlr_half_connect(H3270 *session, int ignored, void *dunno); static void ctlr_connect(H3270 *session, int ignored, void *dunno); @@ -224,37 +225,50 @@ void ctlr_set_rows_cols(H3270 *session, int mn, int ovc, int ovr) set_viewsize(session,sz[idx].rows,sz[idx].cols); - /* - // Make sure that the current rows/cols are still 24x80. - session->cols = 80; - session->rows = 24; - session->screen_alt = 0; - */ - } - +static void set_formatted(H3270 *hSession, int state) +{ + hSession->formatted = state; /* - * Set the formatted screen flag. A formatted screen is a screen that - * has at least one field somewhere on it. + int last = (int) hSession->formatted; + hSession->formatted = state; + + if( ((int) hSession->formatted) != last) + { + trace("Screen is now %s",hSession->formatted ? "formatted" : "unformatted"); + hSession->update_formatted(hSession,hSession->formatted); + } +*/ + trace("Screen is now %s",hSession->formatted ? "formatted" : "unformatted"); +} + +/** + * Update the formatted screen flag. + * + * A formatted screen is a screen that has at least one field somewhere on it. + * + * @param hSession Session Handle */ -static void set_formatted(H3270 *hSession) +static void update_formatted(H3270 *hSession) { register int baddr; CHECK_SESSION_HANDLE(hSession); - hSession->formatted = False; baddr = 0; do { if(hSession->ea_buf[baddr].fa) { - hSession->formatted = True; - break; + set_formatted(hSession,1); + return; } INC_BA(baddr); } while (baddr != 0); + + set_formatted(hSession,0); + } /* @@ -277,6 +291,7 @@ static void ctlr_connect(H3270 *hSession, int ignored unused, void *dunno) hSession->ea_buf[-1].fa = FA_PRINTABLE | FA_MODIFY; else hSession->ea_buf[-1].fa = FA_PRINTABLE | FA_PROTECT; + if (!IN_3270 || (IN_SSCP && (hSession->kybdlock & KL_OIA_TWAIT))) { lib3270_kybdlock_clear(hSession,KL_OIA_TWAIT); @@ -292,8 +307,6 @@ static void ctlr_connect(H3270 *hSession, int ignored unused, void *dunno) hSession->crm_nattr = 0; } - - LIB3270_EXPORT int lib3270_field_addr(H3270 *hSession, int baddr) { int sbaddr; @@ -886,7 +899,8 @@ void ctlr_erase_all_unprotected(H3270 *hSession) kybd_inhibit(hSession,False); - if (hSession->formatted) { + if (hSession->formatted) + { /* find first field attribute */ baddr = 0; do { @@ -975,7 +989,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er ctlr_add_gr(hSession,hSession->buffer_addr, 0); \ ctlr_add_ic(hSession,hSession->buffer_addr, 0); \ trace_ds(hSession,"%s",see_attr(fa)); \ - hSession->formatted = True; \ + set_formatted(hSession,1); \ } kybd_inhibit(hSession,False); @@ -1721,7 +1735,7 @@ enum pds ctlr_write(H3270 *hSession, unsigned char buf[], int buflen, Boolean er break; } } - set_formatted(hSession); + update_formatted(hSession); END_TEXT0; trace_ds(hSession,"\n"); if (wcc_keyboard_restore) { @@ -2196,7 +2210,7 @@ ctlr_clear(H3270 *session, Boolean can_snap) cursor_move(session,0); session->buffer_addr = 0; lib3270_unselect(session); - session->formatted = False; + set_formatted(session,0); session->default_fg = 0; session->default_bg = 0; session->default_gr = 0; @@ -2225,7 +2239,7 @@ static void ctlr_blanks(H3270 *session) cursor_move(session,0); session->buffer_addr = 0; lib3270_unselect(session); - session->formatted = False; + set_formatted(session,0); ALL_CHANGED(session); } diff --git a/src/lib3270/host.c b/src/lib3270/host.c index 0b495ed..fbd5263 100644 --- a/src/lib3270/host.c +++ b/src/lib3270/host.c @@ -706,7 +706,9 @@ void host_in3270(H3270 *hSession, LIB3270_CSTATE new_cstate) void lib3270_set_connected(H3270 *hSession) { - hSession->cstate = CONNECTED_INITIAL; + hSession->cstate = CONNECTED_INITIAL; + hSession->starting = 1; // Enable autostart + lib3270_st_changed(hSession, LIB3270_STATE_CONNECT, True); if(hSession->update_connect) hSession->update_connect(hSession,1); @@ -716,7 +718,9 @@ void lib3270_set_disconnected(H3270 *hSession) { CHECK_SESSION_HANDLE(hSession); - hSession->cstate = NOT_CONNECTED; + hSession->cstate = NOT_CONNECTED; + hSession->starting = 0; + set_status(hSession,OIA_FLAG_UNDERA,False); lib3270_st_changed(hSession,LIB3270_STATE_CONNECT, False); status_changed(hSession,LIB3270_MESSAGE_DISCONNECTED); diff --git a/src/lib3270/kybd.c b/src/lib3270/kybd.c index 7a3ae40..abcb250 100644 --- a/src/lib3270/kybd.c +++ b/src/lib3270/kybd.c @@ -1209,7 +1209,8 @@ LIB3270_ACTION( firstfield ) return 0; } #endif /*]*/ - if (!hSession->formatted) { + if (!hSession->formatted) + { cursor_move(hSession,0); return 0; } @@ -2066,8 +2067,10 @@ LIB3270_ACTION( eraseeof ) operator_error(hSession,KL_OERR_PROTECTED); return -1; } - if (hSession->formatted) { /* erase to next field attribute */ - do { + if (hSession->formatted) + { /* erase to next field attribute */ + do + { ctlr_add(hSession,baddr, EBC_null, 0); INC_BA(baddr); } while (!hSession->ea_buf[baddr].fa); @@ -2109,7 +2112,8 @@ LIB3270_ACTION( eraseinput ) if (IN_ANSI) return 0; #endif /*]*/ - if (hSession->formatted) { + if (hSession->formatted) + { /* find first field attribute */ baddr = 0; do { @@ -2170,7 +2174,8 @@ LIB3270_ACTION( deleteword ) return 0; } #if defined(X3270_ANSI) /*[*/ - if (IN_ANSI) { + if (IN_ANSI) + { net_send_werase(hSession); return 0; } @@ -2455,7 +2460,7 @@ static Boolean remargin(H3270 *hSession, int lmargin) return True; } -LIB3270_EXPORT int lib3270_emulate_input(H3270 *hSession, char *s, int len, int pasting) +LIB3270_EXPORT int lib3270_emulate_input(H3270 *hSession, const char *s, int len, int pasting) { enum { BASE, BACKSLASH, BACKX, BACKP, BACKPA, BACKPF, OCTAL, HEX, XGE } state = BASE; int literal = 0; @@ -2474,7 +2479,7 @@ LIB3270_EXPORT int lib3270_emulate_input(H3270 *hSession, char *s, int len, int UChar *ws; #else /*][*/ char c; - char *ws; + const char *ws; #endif /*]*/ CHECK_SESSION_HANDLE(hSession); diff --git a/src/lib3270/resolver.c b/src/lib3270/resolver.c index f82b9b3..c2d93b4 100644 --- a/src/lib3270/resolver.c +++ b/src/lib3270/resolver.c @@ -183,10 +183,10 @@ static int cresolve_host_and_port(H3270 *h, struct parms *p) int resolve_host_and_port(H3270 *hSession, const char *host, char *portname, unsigned short *pport,struct sockaddr *sa, socklen_t *sa_len, char *errmsg, int em_len) { int rc; - LIB3270_STATUS saved_status = hSession->oia_status; + LIB3270_MESSAGE saved_status = hSession->oia_status; struct parms p = { sizeof(struct parms), host, portname, pport, sa, sa_len, errmsg, em_len }; - trace("Calling resolver for %s", p.host); + trace("Calling resolver for %s status=%d", p.host, (int) saved_status); status_changed(hSession,LIB3270_STATUS_RESOLVING); hSession->cursor(hSession,CURSOR_MODE_LOCKED); @@ -194,7 +194,9 @@ int resolve_host_and_port(H3270 *hSession, const char *host, char *portname, uns rc = lib3270_call_thread((int (*)(H3270 *, void *)) cresolve_host_and_port,hSession,&p); hSession->cursor(hSession,CURSOR_MODE_NORMAL); - status_changed(hSession,saved_status); + + if(saved_status != -1) + status_changed(hSession,saved_status); trace("Calling resolver for %s exits with %d", p.host, rc); diff --git a/src/lib3270/screen.c b/src/lib3270/screen.c index a2418b3..cdb3714 100644 --- a/src/lib3270/screen.c +++ b/src/lib3270/screen.c @@ -372,7 +372,21 @@ void screen_update(H3270 *session, int bstart, int bend) session->changed(session,first,len); } - trace("%s ends",__FUNCTION__); + if(session->starting && session->formatted && lib3270_in_3270(session)) + { + session->starting = 0; + session->autostart(session); +#ifdef DEBUG + { + char *text = lib3270_get_text(session,0,-1); + trace("First screen:\n%s\n",text); + lib3270_free(text); + } +#endif + } + +// trace("%s ends",__FUNCTION__); + } LIB3270_EXPORT int lib3270_get_cursor_address(H3270 *h) @@ -426,20 +440,20 @@ void status_ctlr_done(H3270 *session) void status_oerr(H3270 *session, int error_type) { - LIB3270_STATUS sts = LIB3270_STATUS_USER; + LIB3270_STATUS sts = LIB3270_MESSAGE_USER; CHECK_SESSION_HANDLE(session); switch (error_type) { case KL_OERR_PROTECTED: - sts = LIB3270_STATUS_PROTECTED; + sts = LIB3270_MESSAGE_PROTECTED; break; case KL_OERR_NUMERIC: - sts = LIB3270_STATUS_NUMERIC; + sts = LIB3270_MESSAGE_NUMERIC; break; case KL_OERR_OVERFLOW: - sts = LIB3270_STATUS_OVERFLOW; + sts = LIB3270_MESSAGE_OVERFLOW; break; default: @@ -453,9 +467,9 @@ void status_oerr(H3270 *session, int error_type) void status_connecting(H3270 *session, Boolean on) { if(session->cursor) - session->cursor(session,on ? CURSOR_MODE_LOCKED : CURSOR_MODE_NORMAL); + session->cursor(session,on ? CURSOR_MODE_LOCKED : CURSOR_MODE_NORMAL); - status_changed(session, on ? LIB3270_STATUS_CONNECTING : LIB3270_STATUS_BLANK); + status_changed(session, on ? LIB3270_MESSAGE_CONNECTING : LIB3270_MESSAGE_NONE); } void status_reset(H3270 *session) @@ -464,17 +478,17 @@ void status_reset(H3270 *session) if (session->kybdlock & KL_ENTER_INHIBIT) { - status_changed(session,LIB3270_STATUS_INHIBIT); + status_changed(session,LIB3270_MESSAGE_INHIBIT); } else if (session->kybdlock & KL_DEFERRED_UNLOCK) { - status_changed(session,LIB3270_STATUS_X); + status_changed(session,LIB3270_MESSAGE_X); } else { if(session->cursor) session->cursor(session,CURSOR_MODE_NORMAL); - status_changed(session,LIB3270_STATUS_BLANK); + status_changed(session,LIB3270_MESSAGE_NONE); } session->display(session); @@ -503,8 +517,7 @@ void status_changed(H3270 *session, LIB3270_STATUS id) session->oia_status = id; - if(session->update_status) - session->update_status(session,id); + session->update_status(session,id); } void status_twait(H3270 *session) diff --git a/src/lib3270/selection.c b/src/lib3270/selection.c index ef717a6..d80c75e 100644 --- a/src/lib3270/selection.c +++ b/src/lib3270/selection.c @@ -378,7 +378,7 @@ static char * get_text(H3270 *hSession,unsigned char all) size_t buflen = (hSession->rows * (hSession->cols+1))+1; size_t sz = 0; - if(!lib3270_connected(hSession)) + if(!(lib3270_connected(hSession) && hSession->text)) return NULL; ret = lib3270_malloc(buflen); diff --git a/src/lib3270/session.c b/src/lib3270/session.c index 3b16911..742a0d9 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -160,7 +160,7 @@ static void screen_disp(H3270 *session) screen_update(session,0,session->rows*session->cols); } -static void set_width(H3270 *session, int width) +static void nop_int(H3270 *session, int width) { return; } @@ -194,7 +194,9 @@ static void lib3270_session_init(H3270 *hSession, const char *model) hSession->message = message; hSession->update_ssl = update_ssl; hSession->display = screen_disp; - hSession->set_width = set_width; + hSession->set_width = nop_int; + hSession->update_status = (void (*)(H3270 *, LIB3270_STATUS)) nop_int; + hSession->autostart = nop; // Set the defaults. hSession->extended = 1; @@ -425,7 +427,11 @@ void check_session_handle(H3270 **hSession) *hSession = lib3270_get_default_session_handle(); +#ifdef ANDROID + __android_log_print(ANDROID_LOG_VERBOSE, PACKAGE_NAME, "%s called with empty session\n", __FUNCTION__); +#else lib3270_write_log(*hSession,"%s called with empty session",__FUNCTION__); +#endif // ANDROID } LIB3270_EXPORT H3270 * lib3270_get_default_session_handle(void) diff --git a/src/lib3270/telnet.c b/src/lib3270/telnet.c index d9c3741..799c76d 100644 --- a/src/lib3270/telnet.c +++ b/src/lib3270/telnet.c @@ -1300,9 +1300,11 @@ static int telnet_fsm(H3270 *hSession, unsigned char c) hSession->ns_rrcvd++; if (process_eor(hSession)) return -1; - } else + } + else + { Warning(hSession, _( "EOR received when not in 3270 mode, ignored." )); - + } trace_dsn(hSession,"RCVD EOR\n"); hSession->ibptr = hSession->ibuf; hSession->telnet_state = TNS_DATA; @@ -1900,6 +1902,7 @@ static void process_bind(H3270 *hSession, unsigned char *buf, int buflen) static int process_eor(H3270 *hSession) { + trace("%s: syncing=%s",__FUNCTION__,hSession->syncing ? "Yes" : "No"); if (hSession->syncing || !(hSession->ibptr - hSession->ibuf)) return(0); diff --git a/src/pw3270/common/common.h b/src/pw3270/common/common.h new file mode 100644 index 0000000..8f9f248 --- /dev/null +++ b/src/pw3270/common/common.h @@ -0,0 +1,98 @@ +/* + * "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 common.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +#ifndef COMMON_H_INCLUDED + + #define COMMON_H_INCLUDED 1 + + // "PW" Standards + #include + #include + #include + + #ifdef WIN32 + + #include + #define WIN_REGISTRY_ENABLED 1 + + #ifndef KEY_WOW64_64KEY + #define KEY_WOW64_64KEY 0x0100 + #endif // KEY_WOW64_64KEY + + #ifndef KEY_WOW64_32KEY + #define KEY_WOW64_32KEY 0x0200 + #endif // KEY_WOW64_64KEY + + #endif // WIN32 + + #define ENABLE_NLS + + #ifndef GETTEXT_PACKAGE + #define GETTEXT_PACKAGE PACKAGE_NAME + #endif + + #include + #include + #include + + #if defined( DEBUG ) + #define trace(x, ...) fprintf(stderr,"%s(%d):\t" x "\n",__FILE__,__LINE__, __VA_ARGS__); fflush(stderr); + #else + #define trace(x, ...) /* */ + #endif + + // Configuration + void configuration_init(void); + void configuration_deinit(void); + + gchar * get_string_from_config(const gchar *group, const gchar *key, const gchar *def); + gboolean get_boolean_from_config(const gchar *group, const gchar *key, gboolean def); + gint get_integer_from_config(const gchar *group, const gchar *key, gint def); + + void set_string_to_config(const gchar *group, const gchar *key, const gchar *fmt, ...); + void set_boolean_to_config(const gchar *group, const gchar *key, gboolean val); + void set_integer_to_config(const gchar *group, const gchar *key, gint val); + + gchar * build_data_filename(const gchar *first_element, ...); + gchar * filename_from_va(const gchar *first_element, va_list args); + + void save_window_to_config(const gchar *group, const gchar *key, GtkWidget *hwnd); + void restore_window_from_config(const gchar *group, const gchar *key, GtkWidget *hwnd); + +#ifdef WIN_REGISTRY_ENABLED + gboolean get_registry_handle(const gchar *group, HKEY *hKey, REGSAM samDesired); + void registry_foreach(HKEY parent, const gchar *name,void (*cbk)(const gchar *key, const gchar *val, gpointer *user_data), gpointer *user_data); + void registry_set_double(HKEY hKey, const gchar *key, gdouble value); + gboolean registry_get_double(HKEY hKey, const gchar *key, gdouble *value); +#else + GKeyFile * get_application_keyfile(void); +#endif // WIN_REGISTRY_ENABLED + + +#endif diff --git a/src/pw3270/common/common.h.in b/src/pw3270/common/common.h.in deleted file mode 100644 index ae2975b..0000000 --- a/src/pw3270/common/common.h.in +++ /dev/null @@ -1,100 +0,0 @@ -/* - * "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 common.h e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - -#ifndef COMMON_H_INCLUDED - - #define COMMON_H_INCLUDED 1 - - // "PW" Standards - #include - #include - - #ifdef WIN32 - - #include - #define WIN_REGISTRY_ENABLED 1 - - #ifndef KEY_WOW64_64KEY - #define KEY_WOW64_64KEY 0x0100 - #endif // KEY_WOW64_64KEY - - #ifndef KEY_WOW64_32KEY - #define KEY_WOW64_32KEY 0x0200 - #endif // KEY_WOW64_64KEY - - #endif // WIN32 - - #ifndef PACKAGE_NAME - #define PACKAGE_NAME "@PACKAGE_NAME@" - #endif - - #define ENABLE_NLS - - #ifndef GETTEXT_PACKAGE - #define GETTEXT_PACKAGE PACKAGE_NAME - #endif - - #include - #include - #include - - #if defined( DEBUG ) - #define trace(x, ...) fprintf(stderr,"%s(%d):\t" x "\n",__FILE__,__LINE__, __VA_ARGS__); fflush(stderr); - #else - #define trace(x, ...) /* */ - #endif - - // Configuration - void configuration_init(void); - void configuration_deinit(void); - - gchar * get_string_from_config(const gchar *group, const gchar *key, const gchar *def); - gboolean get_boolean_from_config(const gchar *group, const gchar *key, gboolean def); - gint get_integer_from_config(const gchar *group, const gchar *key, gint def); - - void set_string_to_config(const gchar *group, const gchar *key, const gchar *fmt, ...); - void set_boolean_to_config(const gchar *group, const gchar *key, gboolean val); - void set_integer_to_config(const gchar *group, const gchar *key, gint val); - - gchar * build_data_filename(const gchar *first_element, ...); - gchar * filename_from_va(const gchar *first_element, va_list args); - - void save_window_to_config(const gchar *group, const gchar *key, GtkWidget *hwnd); - void restore_window_from_config(const gchar *group, const gchar *key, GtkWidget *hwnd); - -#ifdef WIN_REGISTRY_ENABLED - gboolean get_registry_handle(const gchar *group, HKEY *hKey, REGSAM samDesired); - void registry_foreach(HKEY parent, const gchar *name,void (*cbk)(const gchar *key, const gchar *val, gpointer *user_data), gpointer *user_data); - void registry_set_double(HKEY hKey, const gchar *key, gdouble value); - gboolean registry_get_double(HKEY hKey, const gchar *key, gdouble *value); -#else - GKeyFile * get_application_keyfile(void); -#endif // WIN_REGISTRY_ENABLED - -#endif diff --git a/src/pw3270/main.c b/src/pw3270/main.c index 9de7f20..e659112 100644 --- a/src/pw3270/main.c +++ b/src/pw3270/main.c @@ -42,7 +42,6 @@ #ifdef HAVE_GTKMAC GtkOSXApplication * osxapp = NULL; - GtkMacBundle * macbundle = NULL; #endif // HAVE_GTKMAC /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -149,15 +148,13 @@ int main(int argc, char *argv[]) } #elif defined(HAVE_GTKMAC) { - osxapp = GTK_OSX_APPLICATION(g_object_new(GTK_TYPE_OSX_APPLICATION,NULL)); - - macbundle = gtk_mac_bundle_get_default(); - if(!macbundle) - macbundle = gtk_mac_bundle_new(); + GtkMacBundle * macbundle = gtk_mac_bundle_get_default(); g_chdir(gtk_mac_bundle_get_datadir(macbundle)); bindtextdomain(PACKAGE_NAME,gtk_mac_bundle_get_localedir(macbundle)); - + + osxapp = GTK_OSX_APPLICATION(g_object_new(GTK_TYPE_OSX_APPLICATION,NULL)); + } #elif defined( DATAROOTDIR ) { diff --git a/src/pw3270/v3270/mouse.c b/src/pw3270/v3270/mouse.c index 0b192b2..235c2b8 100644 --- a/src/pw3270/v3270/mouse.c +++ b/src/pw3270/v3270/mouse.c @@ -273,7 +273,7 @@ void v3270_set_scroll_action(GtkWidget *widget, GdkScrollDirection direction, Gt action_scroll[((int) direction) & 0x03] = action; } -gboolean v3270_scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer user_data) +gboolean v3270_scroll_event(GtkWidget *widget, GdkEventScroll *event) { v3270 * terminal = GTK_V3270(widget); diff --git a/src/pw3270/v3270/private.h b/src/pw3270/v3270/private.h index 0925123..f9e1e71 100644 --- a/src/pw3270/v3270/private.h +++ b/src/pw3270/v3270/private.h @@ -254,6 +254,6 @@ gboolean v3270_button_release_event(GtkWidget *widget, GdkEventButton*event); gboolean v3270_motion_notify_event(GtkWidget *widget, GdkEventMotion *event); void v3270_emit_popup(v3270 *widget, int baddr, GdkEventButton *event); gint v3270_get_offset_at_point(v3270 *widget, gint x, gint y); -gboolean v3270_scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer user_data); +gboolean v3270_scroll_event(GtkWidget *widget, GdkEventScroll *event); G_END_DECLS -- libgit2 0.21.2