diff --git a/android/jni/actions.cpp b/android/jni/actions.cpp index 455b858..f551ce2 100644 --- a/android/jni/actions.cpp +++ b/android/jni/actions.cpp @@ -36,7 +36,10 @@ JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_sendEnter(JNIEnv *env, jobj { PW3270_JNI_BEGIN - lib3270_enter(PW3270_SESSION); + if(lib3270_connected(PW3270_SESSION)) + lib3270_enter(PW3270_SESSION); + else + pw3270_jni_post_message(1,LIB3270_MESSAGE_DISCONNECTED); PW3270_JNI_END } @@ -45,7 +48,10 @@ JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_sendPFkey(JNIEnv *env, jobj { PW3270_JNI_BEGIN - lib3270_pfkey(PW3270_SESSION,key); + if(lib3270_connected(PW3270_SESSION)) + lib3270_pfkey(PW3270_SESSION,key); + else + pw3270_jni_post_message(1,LIB3270_MESSAGE_DISCONNECTED); PW3270_JNI_END } diff --git a/android/jni/globals.h b/android/jni/globals.h index c79d028..8d4b117 100644 --- a/android/jni/globals.h +++ b/android/jni/globals.h @@ -76,6 +76,7 @@ void pw3270_jni_lock(JNIEnv *env, jobject obj); void pw3270_jni_unlock(); + void pw3270_jni_post_message(int msgid, int arg1 = 0, int arg2 = 0); jmethodID lib3270_getmethodID(const char *name, const char *sig); diff --git a/android/jni/main.cpp b/android/jni/main.cpp index 9a7cd98..7b990fb 100644 --- a/android/jni/main.cpp +++ b/android/jni/main.cpp @@ -63,7 +63,7 @@ jmethodID lib3270_getmethodID(const char *name, const char *sig) return PW3270_JNI_ENV->GetMethodID(PW3270_JNI_ENV->GetObjectClass(PW3270_JNI_OBJ), name, sig ); } -static void post_message(int msgid, int arg1 = 0, int arg2 = 0) +void pw3270_jni_post_message(int msgid, int arg1, int arg2) { trace("%s: pw3270_env=%p pw3270_obj=%p",__FUNCTION__,PW3270_JNI_ENV,PW3270_JNI_OBJ); @@ -73,12 +73,12 @@ static void post_message(int msgid, int arg1 = 0, int arg2 = 0) static void changed(H3270 *session, int offset, int len) { - post_message(2,offset,len); + pw3270_jni_post_message(2,offset,len); } static void erase(H3270 *session) { - post_message(4); + pw3270_jni_post_message(4); } static int popuphandler(H3270 *session, void *terminal, LIB3270_NOTIFY type, const char *title, const char *msg, const char *fmt, va_list args) @@ -124,13 +124,13 @@ static int popuphandler(H3270 *session, void *terminal, LIB3270_NOTIFY type, con static void ctlr_done(H3270 *session) { - post_message(4); + pw3270_jni_post_message(4); } void update_status(H3270 *session, LIB3270_MESSAGE id) { - __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "Status changed to %d",(int) id); - post_message(1,(int) id); +// __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "Status changed to %d",(int) id); + pw3270_jni_post_message(1,(int) id); } static int write_buffer(H3270 *session, unsigned const char *buf, int len) @@ -335,6 +335,8 @@ JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_set_1connection_1status(JNI { PW3270_JNI_BEGIN + trace("Host is %s",connected ? "connected" : "disconnected"); + if(connected) lib3270_set_connected(PW3270_SESSION); else diff --git a/android/jni/text.cpp b/android/jni/text.cpp index f4d2233..6167cf8 100644 --- a/android/jni/text.cpp +++ b/android/jni/text.cpp @@ -108,43 +108,43 @@ JNIEXPORT jbyteArray JNICALL Java_br_com_bb_pw3270_lib3270_getText(JNIEnv *env, JNIEXPORT void JNICALL Java_br_com_bb_pw3270_lib3270_setTextAt(JNIEnv *env, jobject obj, jint pos, jbyteArray inText, jint szText) { - unsigned char str[szText+1]; - int f; - jbyte * bt; - PW3270_JNI_BEGIN - bt = env->GetByteArrayElements(inText,0); + if(lib3270_connected(PW3270_SESSION)) + { + unsigned char str[szText+1]; + int f; + jbyte * bt = env->GetByteArrayElements(inText,0); + + for(int f=0;fReleaseByteArrayElements(inText,bt,JNI_ABORT); + env->ReleaseByteArrayElements(inText,bt,JNI_ABORT); + } PW3270_JNI_END } diff --git a/android/res/values/drawables.xml b/android/res/values/drawables.xml index 045e125..6f69e98 100644 --- a/android/res/values/drawables.xml +++ b/android/res/values/drawables.xml @@ -1,3 +1,4 @@ + diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index 743f409..1a29a18 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -7,7 +7,7 @@ X Aguarde Conectado Desconectado - X + X Aguardando X -f X Protegido X Numérico diff --git a/android/src/br/com/bb/pw3270/PW3270Activity.java b/android/src/br/com/bb/pw3270/PW3270Activity.java index 1fef3bb..ac910a6 100644 --- a/android/src/br/com/bb/pw3270/PW3270Activity.java +++ b/android/src/br/com/bb/pw3270/PW3270Activity.java @@ -192,20 +192,24 @@ public class PW3270Activity extends Activity public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection - Log.d(TAG,"Menu item selected"); - /* - switch (item.getItemId()) { - case R.id.new_game: - newGame(); - return true; - case R.id.help: - showHelp(); - return true; - default: - return super.onOptionsItemSelected(item); + switch (item.getItemId()) + { + case R.id.connect: + host.connect(); + break; + + case R.id.disconnect: + host.disconnect(); + break; + + case R.id.settings: + break; + + default: + return super.onOptionsItemSelected(item); } - */ - return super.onOptionsItemSelected(item); + return true; + } } diff --git a/android/src/br/com/bb/pw3270/lib3270.java b/android/src/br/com/bb/pw3270/lib3270.java index d5dffc3..bc5289d 100644 --- a/android/src/br/com/bb/pw3270/lib3270.java +++ b/android/src/br/com/bb/pw3270/lib3270.java @@ -1,3 +1,31 @@ +/* + * "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. 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 lib3270.java e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * + */ + package br.com.bb.pw3270; import java.lang.Thread; @@ -13,13 +41,15 @@ import java.io.DataOutputStream; // import java.util.Vector; -public class lib3270 { +public class lib3270 +{ private NetworkThread mainloop = null; private static final String TAG = "lib3270"; protected int screenState = 0; private boolean connected = false; private boolean refresh = true; + private Socket sock = null; DataOutputStream outData = null; DataInputStream inData = null; @@ -28,17 +58,74 @@ public class lib3270 { protected int port = 8023; protected boolean ssl = false; - static { + // Define the Handler that receives messages from the thread + final Handler mHandler = new Handler() + { + public void handleMessage(Message msg) + { + switch (msg.what) + { + case 0: // Connected/Disconnected + set_connection_status(connected); + break; + + case 1: // OIA message has changed + showProgramMessage(msg.arg1); + break; + + case 2: // Screen changed + Log.d(TAG, "Screen changed"); + screenState = 1; + break; + + case 3: // Popup + popupMessageInfo popup = (popupMessageInfo) msg.obj; + popupMessage(msg.arg1, popup.title, popup.text, popup.info); + break; + + case 4: // erase + if(screenState != 2) + { + screenState = 2; + erase(); + } + break; + + case 5: // ctlr_done + Log.d(TAG, "ctlr_done"); + break; + + case 6: // recv_data + procRecvdata(((byteMessage) msg.obj).getMessage(), + ((byteMessage) msg.obj).getLength()); + break; + + case 7: // ready + hideProgressDialog(); + break; + + case 8: // busy + showProgressDialog("Aguarde..."); + break; + } + } + }; + + + static + { System.loadLibrary("3270"); init(); } - lib3270() { + lib3270() + { screenState = 0; mainloop = null; } - private class timer extends CountDownTimer { + private class timer extends CountDownTimer + { private long id; private lib3270 terminal; @@ -53,17 +140,20 @@ public class lib3270 { this.start(); } - public void onTick(long millisUntilFinished) { + public void onTick(long millisUntilFinished) + { } - public void onFinish() { + public void onFinish() + { Log.d(TAG, "Timer " + id + " finished"); terminal.timerFinish(id); } } - private class popupMessageInfo { + private class popupMessageInfo + { public String title; public String text; public String info; @@ -75,7 +165,8 @@ public class lib3270 { } } - private class byteMessage { + private class byteMessage + { byte[] msg; int sz; @@ -93,14 +184,17 @@ public class lib3270 { } } - protected int send_data(byte[] data, int len) { + protected int send_data(byte[] data, int len) + { Log.i(TAG, "Bytes a enviar: " + len); try { outData.write(data, 0, len); outData.flush(); return len; - } catch (Exception e) { + } + catch (Exception e) + { String msg = e.getLocalizedMessage(); if (msg == null) @@ -111,23 +205,17 @@ public class lib3270 { Log.i(TAG, "Erro ao enviar dados: " + msg); - postPopup(0, "Erro na comunicação", - "Não foi possível enviar dados", msg); + postPopup(0, "Erro na comunicação", "Não foi possível enviar dados", msg); } return -1; } // Main Thread - private class NetworkThread extends Thread { - Handler mHandler; - Socket sock = null; - - NetworkThread(Handler h) { - mHandler = h; - } - - private boolean connect() { + private class NetworkThread extends Thread + { + private boolean connect() + { // Connecta no host SocketFactory socketFactory; @@ -148,7 +236,9 @@ public class lib3270 { outData = new DataOutputStream(sock.getOutputStream()); inData = new DataInputStream(sock.getInputStream()); - } catch (Exception e) { + } + catch (Exception e) + { String msg = e.getLocalizedMessage(); if (msg == null) @@ -159,8 +249,7 @@ public class lib3270 { Log.i(TAG, "Erro ao conectar: " + msg); - postPopup(0, "Erro na conexão", "Não foi possível conectar", - msg); + postPopup(0, "Erro na conexão", "Não foi possível conectar", msg); postMessage(0, 0, 0); @@ -172,15 +261,18 @@ public class lib3270 { } - public void run() { + public void run() + { info(TAG, "Network thread started"); connected = connect(); - if (connected) { + if (connected) + { postMessage(0, 0, 0); - while (connected) { + while (connected) + { byte[] in = new byte[4096]; int sz = -1; @@ -202,10 +294,13 @@ public class lib3270 { } } - try { + Log.v(TAG, "Exiting communication thread"); + + try + { sock.close(); - } catch (Exception e) { } + catch (Exception e) { } sock = null; outData = null; @@ -217,15 +312,19 @@ public class lib3270 { info(TAG, "Network thread stopped"); } - public void postMessage(int what, int arg1, int arg2) { + /* + public void postMessage(int what, int arg1, int arg2) + { Message msg = mHandler.obtainMessage(); msg.what = what; msg.arg1 = arg1; msg.arg2 = arg2; mHandler.sendMessage(msg); } + */ - public void postPopup(int type, String title, String text, String info) { + public void postPopup(int type, String title, String text, String info) + { Message msg = mHandler.obtainMessage(); msg.what = 3; @@ -236,11 +335,17 @@ public class lib3270 { } - public void postMessage(int what, int arg1, int arg2) { - mainloop.postMessage(what, arg1, arg2); + public void postMessage(int what, int arg1, int arg2) + { + Message msg = mHandler.obtainMessage(); + msg.what = what; + msg.arg1 = arg1; + msg.arg2 = arg2; + mHandler.sendMessage(msg); } - public void postPopup(int type, String title, String text, String info) { + public void postPopup(int type, String title, String text, String info) + { Log.d(TAG, "Type:" + type); Log.d(TAG, "Title:" + title); Log.d(TAG, "Text:" + text); @@ -248,124 +353,109 @@ public class lib3270 { mainloop.postPopup(type, title, text, info); } - // Define the Handler that receives messages from the thread and update the - // progress - final Handler handler = new Handler() { - public void handleMessage(Message msg) { - switch (msg.what) { - case 0: // Connected/Disconnected - set_connection_status(connected); - Log.d(TAG, connected ? "Connected" : "Disconnected"); - break; - - case 1: // OIA message has changed - showProgramMessage(msg.arg1); - break; - - case 2: // Screen changed - Log.d(TAG, "Screen changed"); - screenState = 1; - break; - - case 3: // Popup - popupMessageInfo popup = (popupMessageInfo) msg.obj; - popupMessage(msg.arg1, popup.title, popup.text, popup.info); - break; - - case 4: // erase - if(screenState != 2) - { - screenState = 2; - erase(); - } - break; - - case 5: // ctlr_done - Log.d(TAG, "ctlr_done"); - break; - - case 6: // recv_data - procRecvdata(((byteMessage) msg.obj).getMessage(), - ((byteMessage) msg.obj).getLength()); - break; - - case 7: // ready - hideProgressDialog(); - break; - - case 8: // busy - showProgressDialog("Aguarde..."); - break; - } - } - }; - /*---[ Signal methods ]--------------------------------------------------*/ - protected boolean showProgramMessage(int id) + protected boolean showProgramMessage(int id) { - if(id == 0 && screenState != 0) + switch(id) { - screenState = 0; - updateScreen(); - return true; + case 0: // LIB3270_MESSAGE_NONE + if(screenState != 0) + { + screenState = 0; + updateScreen(); + } + break; + + case 4: // LIB3270_MESSAGE_DISCONNECTED + Log.v(TAG, "Disconnected"); + connected = false; + erase(); + break; + + case 3: // LIB3270_MESSAGE_CONNECTED + Log.v(TAG, "Connected"); + break; + + // 01 LIB3270_MESSAGE_SYSWAIT + // 02 LIB3270_MESSAGE_TWAIT + // 03 LIB3270_MESSAGE_CONNECTED + // 05 LIB3270_MESSAGE_AWAITING_FIRST + // 06 LIB3270_MESSAGE_MINUS + // 07 LIB3270_MESSAGE_PROTECTED + // 08 LIB3270_MESSAGE_NUMERIC + // 09 LIB3270_MESSAGE_OVERFLOW + // 10 LIB3270_MESSAGE_INHIBIT + // 11 LIB3270_MESSAGE_KYBDLOCK + // 12 LIB3270_MESSAGE_X + // 13 LIB3270_MESSAGE_RESOLVING + // 14 LIB3270_MESSAGE_CONNECTING + + default: + return false; } - - return false; + + return true; } - protected void popupMessage(int type, String title, String text, String info) { + protected void popupMessage(int type, String title, String text, String info) + { } - protected void info(String tag, String msg) { + protected void info(String tag, String msg) + { Log.i(tag, msg); } - protected void error(String tag, String msg) { + protected void error(String tag, String msg) + { Log.e(tag, msg); } - protected void erase() + protected void erase() { } protected void updateScreen() { } - - public void pfkey(int id) + + public void pfkey(int id) { sendPFkey(id); } - public void xmit() + public void xmit() { sendEnter(); } - public void ready() + public void ready() { postMessage(7, 0, 0); } - public void busy() + public void busy() { postMessage(8, 0, 0); } - public void hideProgressDialog() + public void hideProgressDialog() { } - public void showProgressDialog(String msg) { + public void showProgressDialog(String msg) + { } /*---[ External methods ]------------------------------------------------*/ - public int connect() { - if (mainloop == null) { + public int connect() + { + if (mainloop == null) + { info(TAG, "Starting comm thread"); - mainloop = new NetworkThread(handler); + mainloop = new NetworkThread(); mainloop.start(); return 0; } @@ -373,12 +463,25 @@ public class lib3270 { return -1; } - public int disconnect() { + public int disconnect() + { + Log.v(TAG, "Disconnecting"); connected = false; + + if(sock != null) + { + try + { + sock.shutdownInput(); + sock.shutdownOutput(); + } catch(Exception e) { } + } + return 0; } - public void setStringAt(int offset, String str) { + public void setStringAt(int offset, String str) + { refresh = false; try { setTextAt(offset, str.getBytes(getEncoding()), str.length()); diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index cd5f430..4ca18c8 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -69,6 +69,10 @@ #define SSL void #endif // !HEADER_SSL_H +#ifndef LIB3270_TA + #define LIB3270_TA void +#endif // !LIB3270_TA + struct _h3270 { unsigned short sz; /**< Struct size */ @@ -245,6 +249,8 @@ unsigned char aid; /**< current attention ID */ void * unlock_id; time_t unlock_delay_time; + LIB3270_TA * ta_head; + LIB3270_TA * ta_tail; // Widget info void * widget; diff --git a/src/lib3270/kybd.c b/src/lib3270/kybd.c index e49043b..154a2f9 100644 --- a/src/lib3270/kybd.c +++ b/src/lib3270/kybd.c @@ -35,6 +35,10 @@ * This module handles the keyboard for the 3270 emulator. */ +struct ta; + +#define LIB3270_TA struct ta + #include "globals.h" #ifndef ANDROID @@ -153,7 +157,7 @@ static int n_composites = 0; #define ak_eq(k1, k2) (((k1).keysym == (k2).keysym) && \ ((k1).keytype == (k2).keytype)) -static struct ta +struct ta { struct ta *next; @@ -164,12 +168,15 @@ static struct ta TA_TYPE_USER } type; - H3270 * session; void (*fn)(H3270 *, const char *, const char *); char *parm[2]; unsigned char aid_code; -} *ta_head = (struct ta *) NULL, +}; + +/* +*ta_head = (struct ta *) NULL, *ta_tail = (struct ta *) NULL; +*/ #if defined(DEBUG) || defined(ANDROID) @@ -238,16 +245,16 @@ static int enq_chk(H3270 *session) trace("Adding key %02x on queue",(int) aid_code); - if (ta_head) + if (session->ta_head) { - ta_tail->next = ta; + session->ta_tail->next = ta; } else { - ta_head = ta; + session->ta_head = ta; status_typeahead(session,True); } - ta_tail = ta; + session->ta_tail = ta; trace_event(" Key-aid queued (kybdlock 0x%x)\n", session->kybdlock); } @@ -271,7 +278,6 @@ static void enq_ta(H3270 *hSession, void (*fn)(H3270 *, const char *, const char return; ta = (struct ta *) lib3270_malloc(sizeof(*ta)); - ta->session = hSession; ta->next = (struct ta *) NULL; ta->type = TA_TYPE_DEFAULT; ta->fn = fn; @@ -282,16 +288,16 @@ static void enq_ta(H3270 *hSession, void (*fn)(H3270 *, const char *, const char if (parm2) ta->parm[1] = NewString(parm2); - if (ta_head) + if(hSession->ta_head) { - ta_tail->next = ta; + hSession->ta_tail->next = ta; } else { - ta_head = ta; + hSession->ta_head = ta; status_typeahead(hSession,True); } - ta_tail = ta; + hSession->ta_tail = ta; trace_event(" action queued (kybdlock 0x%x)\n", h3270.kybdlock); } @@ -303,30 +309,30 @@ Boolean run_ta(void) { struct ta *ta; - if (h3270.kybdlock || (ta = ta_head) == (struct ta *)NULL) + if (h3270.kybdlock || (ta = h3270.ta_head) == (struct ta *)NULL) return False; - if ((ta_head = ta->next) == (struct ta *)NULL) + if ((h3270.ta_head = ta->next) == (struct ta *)NULL) { - ta_tail = (struct ta *)NULL; + h3270.ta_tail = (struct ta *)NULL; status_typeahead(&h3270,False); } switch(ta->type) { case TA_TYPE_DEFAULT: - ta->fn(ta->session,ta->parm[0],ta->parm[1]); + ta->fn(&h3270,ta->parm[0],ta->parm[1]); lib3270_free(ta->parm[0]); lib3270_free(ta->parm[1]); break; case TA_TYPE_KEY_AID: trace("Sending enqueued key %02x",ta->aid_code); - key_AID(ta->session,ta->aid_code); + key_AID(&h3270,ta->aid_code); break; default: - popup_an_error(ta->session, _( "Unexpected type %d in typeahead queue" ), ta->type); + popup_an_error(&h3270, _( "Unexpected type %d in typeahead queue" ), ta->type); } @@ -339,13 +345,12 @@ Boolean run_ta(void) * Flush the typeahead queue. * Returns whether or not anything was flushed. */ -static Boolean -flush_ta(void) +static Boolean flush_ta(void) { struct ta *ta, *next; Boolean any = False; - for (ta = ta_head; ta != (struct ta *) NULL; ta = next) + for (ta = h3270.ta_head; ta != (struct ta *) NULL; ta = next) { lib3270_free(ta->parm[0]); lib3270_free(ta->parm[1]); @@ -353,7 +358,7 @@ flush_ta(void) lib3270_free(ta); any = True; } - ta_head = ta_tail = (struct ta *) NULL; + h3270.ta_head = h3270.ta_tail = (struct ta *) NULL; status_typeahead(&h3270,False); return any; } @@ -1001,316 +1006,6 @@ static Boolean key_Character(int code, Boolean with_ge, Boolean pasting, Boolean } /* -#if defined(X3270_DBCS) -static void -key_WCharacter_wrapper(Widget w unused, XEvent *event unused, String *params, Cardinal *num_params unused) -{ - int code; - unsigned char codebuf[2]; - - code = atoi(params[0]); - trace_event(" %s -> Key(0x%04x)\n", - ia_name[(int) ia_cause], code); - codebuf[0] = (code >> 8) & 0xff; - codebuf[1] = code & 0xff; - (void) key_WCharacter(codebuf, NULL); -} - -// -// Input a DBCS character. -// Returns True if a character was stored in the buffer, False otherwise. -// -Boolean key_WCharacter(unsigned char code[], Boolean *skipped) -{ - int baddr; - register unsigned char fa; - int faddr; - enum dbcs_state d; - int xaddr; - Boolean done = False; - Boolean no_si = False; - extern unsigned char reply_mode; // XXX - - reset_idle_timer(); - - if (kybdlock) { - char codename[64]; - - (void) sprintf(codename, "%d", (code[0] << 8) | code[1]); - enq_ta(key_WCharacter_wrapper, codename, CN); - return False; - } - - if (skipped != NULL) - *skipped = False; - - // In DBCS mode? - if (!dbcs) { - trace_event("DBCS character received when not in DBCS mode, " - "ignoring.\n"); - return True; - } - -#if defined(X3270_ANSI) - // In ANSI mode? - if (IN_ANSI) { - char mb[16]; - - dbcs_to_mb(code[0], code[1], mb); - net_sends(mb); - return True; - } -#endif - - baddr = cursor_addr; - fa = get_field_attribute(baddr); - faddr = find_field_attribute(baddr); - - // Protected? - if (ea_buf[baddr].fa || FA_IS_PROTECTED(fa)) { - operator_error(KL_OERR_PROTECTED); - return False; - } - - // Numeric? - if (h3270.numeric_lock && FA_IS_NUMERIC(fa)) { - operator_error(KL_OERR_NUMERIC); - return False; - } - - // - // Figure our what to do based on the DBCS state of the buffer. - // Leaves baddr pointing to the next unmodified position. - // -retry: - switch (d = ctlr_dbcs_state(baddr)) { - case DBCS_RIGHT: - case DBCS_RIGHT_WRAP: - // Back up one position and process it as a LEFT. - DEC_BA(baddr); - // fall through... - case DBCS_LEFT: - case DBCS_LEFT_WRAP: - // Overwrite the existing character. - if (insert) { - if (!ins_prep(faddr, baddr, 2)) { - return False; - } - } - ctlr_add(baddr, code[0], ea_buf[baddr].cs); - INC_BA(baddr); - ctlr_add(baddr, code[1], ea_buf[baddr].cs); - INC_BA(baddr); - done = True; - break; - case DBCS_SB: - // Back up one position and process it as an SI. - DEC_BA(baddr); - // fall through... - case DBCS_SI: - // Extend the subfield to the right. - if (insert) { - if (!ins_prep(faddr, baddr, 2)) { - return False; - } - } else { - // Don't overwrite a field attribute or an SO. - xaddr = baddr; - INC_BA(xaddr); // C1 - if (ea_buf[xaddr].fa) - break; - if (ea_buf[xaddr].cc == EBC_so) - no_si = True; - INC_BA(xaddr); // SI - if (ea_buf[xaddr].fa || ea_buf[xaddr].cc == EBC_so) - break; - } - ctlr_add(baddr, code[0], ea_buf[baddr].cs); - INC_BA(baddr); - ctlr_add(baddr, code[1], ea_buf[baddr].cs); - if (!no_si) { - INC_BA(baddr); - ctlr_add(baddr, EBC_si, ea_buf[baddr].cs); - } - done = True; - break; - case DBCS_DEAD: - break; - case DBCS_NONE: - if (ea_buf[faddr].ic) { - Boolean extend_left = FALSE; - - // Is there room? - if (insert) { - if (!ins_prep(faddr, baddr, 4)) { - return False; - } - } else { - xaddr = baddr; // baddr, SO - if (ea_buf[xaddr].cc == EBC_so) { - // - // (baddr), where we would have put the - // SO, is already an SO. Move to - // (baddr+1) and try again. - // -#if defined(DBCS_RIGHT_DEBUG) - printf("SO in position 0\n"); -#endif - INC_BA(baddr); - goto retry; - } - - INC_BA(xaddr); // baddr+1, C0 - if (ea_buf[xaddr].fa) - break; - if (ea_buf[xaddr].cc == EBC_so) { - enum dbcs_state e; - - // - // (baddr+1), where we would have put - // the left side of the DBCS, is a SO. - // If there's room, we can extend the - // subfield to the left. If not, we're - // stuck. - // - DEC_BA(xaddr); - DEC_BA(xaddr); - e = ctlr_dbcs_state(xaddr); - if (e == DBCS_NONE || e == DBCS_SB) { - extend_left = True; - no_si = True; -#if defined(DBCS_RIGHT_DEBUG) - printf("SO in position 1, " - "extend left\n"); -#endif - } else { - // - // Won't actually happen, - // because this implies that - // the buffer addr at baddr - // is an SB. - // -#if defined(DBCS_RIGHT_DEBUG) - printf("SO in position 1, " - "no room on left, " - "fail\n"); -#endif - break; - } - } - - INC_BA(xaddr); // baddr+2, C1 - if (ea_buf[xaddr].fa) - break; - if (ea_buf[xaddr].cc == EBC_so) { - // - // (baddr+2), where we want to put the - // right half of the DBCS character, is - // a SO. This is a natural extension - // to the left -- just make sure we - // don't write an SI. - // - no_si = True; -#if defined(DBCS_RIGHT_DEBUG) - printf("SO in position 2, no SI\n"); -#endif - } - - // - // Check the fourth position only if we're - // not doing an extend-left. - /// - if (!no_si) { - INC_BA(xaddr); // baddr+3, SI - if (ea_buf[xaddr].fa) - break; - if (ea_buf[xaddr].cc == EBC_so) { - // - // (baddr+3), where we want to - // put an - // SI, is an SO. Forget it. - // -#if defined(DBCS_RIGHT_DEBUG) - printf("SO in position 3, " - "retry right\n"); - INC_BA(baddr); - goto retry; -#endif - break; - } - } - } - // Yes, add it. - if (extend_left) - DEC_BA(baddr); - ctlr_add(baddr, EBC_so, ea_buf[baddr].cs); - INC_BA(baddr); - ctlr_add(baddr, code[0], ea_buf[baddr].cs); - INC_BA(baddr); - ctlr_add(baddr, code[1], ea_buf[baddr].cs); - if (!no_si) { - INC_BA(baddr); - ctlr_add(baddr, EBC_si, ea_buf[baddr].cs); - } - done = True; - } else if (reply_mode == SF_SRM_CHAR) { - // Use the character attribute. - if (insert) { - if (!ins_prep(faddr, baddr, 2)) { - return False; - } - } else { - xaddr = baddr; - INC_BA(xaddr); - if (ea_buf[xaddr].fa) - break; - } - ctlr_add(baddr, code[0], CS_DBCS); - INC_BA(baddr); - ctlr_add(baddr, code[1], CS_DBCS); - INC_BA(baddr); - done = True; - } - break; - } - - if (done) { - // Implement blank fill mode. - if (lib3270_get_toggle(&h3270,LIB3270_TOGGLE_BLANK_FILL)) { - xaddr = faddr; - INC_BA(xaddr); - while (xaddr != baddr) { - if (ea_buf[xaddr].cc == EBC_null) - ctlr_add(xaddr, EBC_space, CS_BASE); - else - break; - INC_BA(xaddr); - } - } - - mdt_set(cursor_addr); - - // Implement auto-skip. - while (ea_buf[baddr].fa) { - if (skipped != NULL) - *skipped = True; - if (FA_IS_SKIP(ea_buf[baddr].fa)) - baddr = next_unprotected(&h3270,baddr); - else - INC_BA(baddr); - } - cursor_move(baddr); - (void) ctlr_dbcs_postprocess(); - return True; - } else { - operator_error(KL_OERR_DBCS); - return False; - } -} -#endif -*/ - -/* * Handle an ordinary character key, given an ASCII code. */ void key_ACharacter(unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped) @@ -1341,59 +1036,6 @@ void key_ACharacter(unsigned char c, enum keytype keytype, enum iaction cause,Bo } } - -/* - * Simple toggles. - */ -/* -#if defined(X3270_DISPLAY) -void -AltCursor_action(Widget w unused, XEvent *event, String *params, - Cardinal *num_params) -{ - reset_idle_timer(); - do_toggle(ALT_CURSOR); -} -#endif -*/ - -/* -void -MonoCase_action(Widget w unused, XEvent *event, String *params, - Cardinal *num_params) -{ - reset_idle_timer(); - do_toggle(MONOCASE); -} -*/ - -/* - * Flip the display left-to-right - */ - /* -void -Flip_action(Widget w unused, XEvent *event, String *params, - Cardinal *num_params) -{ - -// reset_idle_timer(); - - screen_flip(); -} -*/ - - -/* - * Tab forward to next field. - */ -/* -void -Tab_action(Widget w unused, XEvent *event, String *params, Cardinal *num_params) -{ - action_NextField(); -} -*/ - LIB3270_ACTION( nextfield ) { @@ -1612,13 +1254,6 @@ do_left(void) cursor_move(&h3270,baddr); } -/* -void Left_action(Widget w unused, XEvent *event, String *params, Cardinal *num_params) -{ - action_CursorLeft(); -} -*/ - LIB3270_CURSOR_ACTION( left ) { if (hSession->kybdlock) @@ -2323,116 +1958,6 @@ LIB3270_ACTION( clear ) return 0; } - -/* - * Cursor Select key (light pen simulator). - */ - /* -static void -lightpen_select(int baddr) -{ - int faddr; - register unsigned char fa; - int designator; -#if defined(X3270_DBCS) - int designator2; -#endif - - faddr = find_field_attribute(baddr); - fa = ea_buf[faddr].fa; - if (!FA_IS_SELECTABLE(fa)) { - lib3270_ring_bell(); - return; - } - designator = faddr; - INC_BA(designator); - -#if defined(X3270_DBCS) - if (dbcs) { - if (ea_buf[baddr].cs == CS_DBCS) { - designator2 = designator; - INC_BA(designator2); - if ((ea_buf[designator].db != DBCS_LEFT && - ea_buf[designator].db != DBCS_LEFT_WRAP) && - (ea_buf[designator2].db != DBCS_RIGHT && - ea_buf[designator2].db != DBCS_RIGHT_WRAP)) { - lib3270_ring_bell(); - return; - } - if (ea_buf[designator].cc == 0x42 && - ea_buf[designator2].cc == EBC_greater) { - ctlr_add(designator2, EBC_question, CS_DBCS); - mdt_clear(faddr); - } else if (ea_buf[designator].cc == 0x42 && - ea_buf[designator2].cc == EBC_question) { - ctlr_add(designator2, EBC_greater, CS_DBCS); - mdt_clear(faddr); - } else if ((ea_buf[designator].cc == EBC_space && - ea_buf[designator2].cc == EBC_space) || - (ea_buf[designator].cc == EBC_null && - ea_buf[designator2].cc == EBC_null)) { - ctlr_add(designator2, EBC_greater, CS_DBCS); - mdt_set(faddr); - key_AID(AID_SELECT); - } else if (ea_buf[designator].cc == 0x42 && - ea_buf[designator2].cc == EBC_ampersand) { - mdt_set(faddr); - key_AID(AID_ENTER); - } else { - lib3270_ring_bell(); - } - return; - } - } -#endif - - switch (ea_buf[designator].cc) { - case EBC_greater: - ctlr_add(designator, EBC_question, 0); - mdt_clear(faddr); - break; - case EBC_question: - ctlr_add(designator, EBC_greater, 0); - mdt_set(faddr); - break; - case EBC_space: - case EBC_null: - mdt_set(faddr); - key_AID(AID_SELECT); - break; - case EBC_ampersand: - mdt_set(faddr); - key_AID(AID_ENTER); - break; - default: - lib3270_ring_bell(); - break; - } -} -*/ - -/* - * Cursor Select key (light pen simulator) -- at the current cursor location. - */ -/* -void -CursorSelect_action(Widget w unused, XEvent *event, String *params, - Cardinal *num_params) -{ -// reset_idle_timer(); - if (kybdlock) { - enq_ta(CursorSelect_action, CN, CN); - return; - } - -#if defined(X3270_ANSI) - if (IN_ANSI) - return; -#endif - lightpen_select(cursor_addr); -} -*/ - /** * Erase End Of Line Key. * -- libgit2 0.21.2