diff --git a/pw3270.cbp b/pw3270.cbp
index a418b3b..10d857b 100644
--- a/pw3270.cbp
+++ b/pw3270.cbp
@@ -9,8 +9,8 @@
-
-
+
+
@@ -20,8 +20,8 @@
-
-
+
+
@@ -35,7 +35,7 @@
-
+
@@ -45,285 +45,286 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
+
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
+
+
+
-
-
+
+
-
-
-
+
+
+
-
+
-
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
+
+
-
+
-
-
-
-
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
+
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
-
-
+
+
+
-
+
-
-
-
+
+
+
diff --git a/src/android/jni/Android.mk b/src/android/jni/Android.mk
index 8ae9594..567f73d 100644
--- a/src/android/jni/Android.mk
+++ b/src/android/jni/Android.mk
@@ -29,7 +29,7 @@ include $(CLEAR_VARS)
# include ../lib3270/sources.mak
TERMINAL_SOURCES= bounds.c XtGlue.c ctlr.c util.c toggles.c screen.c selection.c kybd.c telnet.c \
- host.c sf.c ansi.c log.c resolver.c xio.c tables.c proxy.c
+ host.c sf.c ansi.c log.c resolver.c xio.c tables.c proxy.c utf8.c charset.c
LOCAL_CFLAGS=-I../include
LOCAL_MODULE := lib3270
diff --git a/src/include/lib3270.h b/src/include/lib3270.h
index b60185c..73af79a 100644
--- a/src/include/lib3270.h
+++ b/src/include/lib3270.h
@@ -749,6 +749,43 @@
LIB3270_EXPORT int lib3270_is_protected(H3270 *h, unsigned int baddr);
+ /**
+ * Alloc/Realloc memory buffer.
+ *
+ * Allocate/reallocate an array.
+ *
+ * @param elsize Element size.
+ * @param nelem Number of elements in the array.
+ * @param ptr Pointer to the actual array.
+ *
+ * @return Clean buffer with size for the number of elements.
+ *
+ */
+ LIB3270_EXPORT void * lib3270_calloc(int elsize, int nelem, void *ptr);
+
+ LIB3270_EXPORT void * lib3270_malloc(int len);
+ LIB3270_EXPORT void * lib3270_realloc(void *p, int len);
+
+ /**
+ * Release allocated memory.
+ *
+ * @param p Memory block to release (can be NULL)
+ *
+ */
+ LIB3270_EXPORT void lib3270_free(void *p);
+
+
+ /**
+ * Get resource string.
+ *
+ * @param first_element First element of resource path
+ * @param ... Resource path (ends with NULL)
+ *
+ * @return Resource string (Release with lib3270_free())
+ *
+ */
+ LIB3270_EXPORT char * lib3270_get_resource_string(const char *first_element, ...);
+
#ifdef __cplusplus
}
diff --git a/src/lib3270/XtGlue.c b/src/lib3270/XtGlue.c
index d318f93..6e941ba 100644
--- a/src/lib3270/XtGlue.c
+++ b/src/lib3270/XtGlue.c
@@ -566,60 +566,6 @@ static int DefaultProcessEvents(int block)
/*---[ Implement external calls ]---------------------------------------------------------------------------*/
-void * Malloc(size_t len)
-{
- char *r;
-
- r = malloc(len);
- if (r == (char *)NULL)
- Error(NULL,"Out of memory");
- return r;
-}
-
-void * Calloc(size_t nelem, size_t elsize)
-{
- int sz = nelem * elsize;
- char * r = malloc(sz);
-
- if(!r)
- Error(NULL,"Out of memory");
-
- memset(r, 0, sz);
- return r;
-}
-
-void * Realloc(void *p, size_t len)
-{
- p = realloc(p, len);
- if (p == NULL)
- Error(NULL,"Out of memory");
- return p;
-}
-
-void Free(void *p)
-{
- if(p)
- free(p);
-}
-
-void * lib3270_calloc(size_t elsize, size_t nelem, void *ptr)
-{
- size_t sz = nelem * elsize;
-
- if(ptr)
- ptr = realloc(ptr,sz);
- else
- ptr = malloc(sz);
-
- if(ptr)
- memset(ptr,0,sz);
- else
- Error(NULL,"Out of memory");
-
- return ptr;
-}
-
-
static struct {
const char *name;
KeySym keysym;
diff --git a/src/lib3270/charset.c b/src/lib3270/charset.c
index 6745575..b7d0003 100644
--- a/src/lib3270/charset.c
+++ b/src/lib3270/charset.c
@@ -159,25 +159,28 @@ restore_charset(void)
}
/* Get a character set definition. */
-static const char * get_charset_def(const char *csname)
+/*
+static char * get_charset_def(const char *csname)
{
- return get_fresource("%s.%s", ResCharset, csname);
+ return get_fresource("%s.%s", "charset", csname);
}
+*/
-#if defined(X3270_DBCS) /*[*/
/*
- * Initialize the DBCS conversion functions, based on resource values.
- */
+#if defined(X3270_DBCS)
+//
+// Initialize the DBCS conversion functions, based on resource values.
+//
static int
wide_resource_init(char *csname)
{
char *cn, *en;
- cn = get_fresource("%s.%s", ResDbcsConverters, csname);
+ cn = get_fresource("%s.%s", "dbcsConverters", csname);
if (cn == CN)
return 0;
- en = get_fresource("%s.%s", ResLocalEncoding, csname);
+ en = get_fresource("%s.%s", "localEncoding", csname);
if (en == CN)
en = appres.local_encoding;
Replace(converter_names, cn);
@@ -186,78 +189,60 @@ wide_resource_init(char *csname)
return wide_init(cn, en);
}
-#endif /*]*/
+#endif
+*/
/*
* Change character sets.
*/
enum cs_result charset_init(H3270 *session, char *csname)
{
- const char *cs;
+ char *cs;
const char *ftcs;
enum cs_result rc;
char *ccs, *cftcs;
-/*
-#if defined(X3270_DISPLAY)
- char *xks;
-#endif
-*/
const char *ak;
-/*
-#if !defined(_WIN32)
- char *codeset_name;
-#endif
-
-#if !defined(_WIN32)
- // Get all of the locale stuff right.
-
- // Figure out the locale code set (character set encoding).
- codeset_name = nl_langinfo(CODESET);
- Trace("codeset_name: %s",codeset_name);
- set_codeset(codeset_name);
-#endif
-*/
-
/* Do nothing, successfully. */
if (csname == CN || !strcasecmp(csname, "us"))
{
charset_defaults();
set_cgcsgids(CN);
-// set_charset_name(CN);
set_display_charset(session, "ISO-8859-1");
return CS_OKAY;
}
/* Figure out if it's already in a resource or in a file. */
- cs = get_charset_def(csname);
- if (cs == CN &&
- strlen(csname) > ES_SIZE &&
- !strcasecmp(csname + strlen(csname) - ES_SIZE, EURO_SUFFIX)) {
- char *basename;
+#ifdef ANDROID
+ ccs = strdup("0xad: [ \n 0xba: Yacute \n0xbd: ] \n 0xbb: diaeresis \n");
+#else
+ ccs = lib3270_get_resource_string("charset", csname, NULL);
+#endif
+/*
+ if (cs == CN && strlen(csname) > ES_SIZE && !strcasecmp(csname + strlen(csname) - ES_SIZE, EURO_SUFFIX))
+ {
+ char *basename =
+ lib3270_free(cs);
- /* Grab the non-Euro definition. */
+ // Grab the non-Euro definition.
basename = xs_buffer("%.*s", (int) (strlen(csname) - ES_SIZE), csname);
cs = get_charset_def(basename);
Free(basename);
}
- if (cs == CN)
+*/
+ if (!ccs)
return CS_NOTFOUND;
/* Grab the File Transfer character set. */
- ftcs = get_fresource("%s.%s", ResFtCharset, csname);
-
- /* Copy strings. */
- ccs = NewString(cs);
- cftcs = (ftcs == NULL)? NULL: NewString(ftcs);
+ cftcs = lib3270_get_resource_string("ftCharset",csname,NULL);
/* Save the current definitions, and start over with the defaults. */
save_charset();
charset_defaults();
/* Check for auto-keymap. */
- ak = get_fresource("%s.%s", ResAutoKeymap, csname);
+ ak = lib3270_get_resource_string("autoKeymap", csname, NULL);
if (ak != NULL)
auto_keymap = !strcasecmp(ak, "true");
else
@@ -277,12 +262,15 @@ enum cs_result charset_init(H3270 *session, char *csname)
if (rc != CS_OKAY)
restore_charset();
-#if defined(X3270_DBCS) /*[*/
+
+/*
+#if defined(X3270_DBCS)
else if (wide_resource_init(csname) < 0) {
restore_charset();
return CS_NOTFOUND;
}
-#endif /*]*/
+#endif
+*/
/*
#if defined(X3270_DISPLAY)
@@ -384,11 +372,11 @@ set_charset_name(char *csname)
/* Define a charset from resources. */
static enum cs_result resource_charset(char *csname, char *cs, char *ftcs)
{
- enum cs_result rc;
- int ne = 0;
- const char *rcs = CN;
- int n_rcs = 0;
- const char *dcs;
+ enum cs_result rc;
+ int ne = 0;
+ char * rcs = CN;
+ int n_rcs = 0;
+ char * dcs;
/* Interpret the spec. */
rc = remap_chars(csname, cs, (ftcs == NULL)? BOTH: CS_ONLY, &ne);
@@ -400,37 +388,44 @@ static enum cs_result resource_charset(char *csname, char *cs, char *ftcs)
return rc;
}
- rcs = get_fresource("%s.%s", ResDisplayCharset, csname);
+// rcs = get_fresource("%s.%s", "displayCharset", csname);
+ rcs = lib3270_get_resource_string("displayCharset", csname, NULL);
/* Isolate the pieces. */
- if (rcs != CN) {
- char *rcs_copy, *buf, *token;
+ if (rcs != CN)
+ {
+ char *buf, *token;
- buf = rcs_copy = NewString(rcs);
- while ((token = strtok(buf, "+")) != CN) {
+ buf = rcs;
+ while ((token = strtok(buf, "+")) != CN)
+ {
buf = CN;
- switch (n_rcs) {
+ switch (n_rcs)
+ {
case 0:
-#if defined(X3270_DBCS) /*[*/
+#if defined(X3270_DBCS)
case 1:
-#endif /*]*/
+#endif
break;
default:
- popup_an_error(NULL,"Extra %s value(s), ignoring",
- ResDisplayCharset);
+ popup_an_error(NULL,"Extra value(s) in displayCharset.%s, ignoring", csname);
break;
}
n_rcs++;
}
}
-#if defined(X3270_DBCS) /*[*/
- /* Can't swap DBCS modes while connected. */
+ lib3270_free(rcs);
+
+/*
+#if defined(X3270_DBCS)
+ // Can't swap DBCS modes while connected.
if (IN_3270 && (n_rcs == 2) != dbcs) {
popup_an_error(NULL,"Can't change DBCS modes while connected");
return CS_ILLEGAL;
}
-#endif /*]*/
+#endif
+*/
/*
#if !defined(_WIN32)
@@ -445,15 +440,23 @@ static enum cs_result resource_charset(char *csname, char *cs, char *ftcs)
*/
/* Set up the cgcsgid. */
- set_cgcsgids(get_fresource("%s.%s", ResCodepage, csname));
+// set_cgcsgids(get_fresource("%s.%s", "codepage", csname));
+ {
+ char *ptr = lib3270_get_resource_string("codepage", csname, NULL);
+ set_cgcsgids(ptr);
+ lib3270_free(ptr);
+ }
- dcs = get_fresource("%s.%s", ResDisplayCharset, csname);
+// dcs = get_fresource("%s.%s", "displayCharset", csname);
+ dcs = lib3270_get_resource_string("displayCharset", csname, NULL);
if (dcs != NULL)
set_display_charset(&h3270,dcs);
else
set_display_charset(&h3270,"ISO-8859-1");
+ lib3270_free(dcs);
+
/* Set up the character set name. */
// set_charset_name(csname);
diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c
index da6aad3..180b031 100644
--- a/src/lib3270/ctlr.c
+++ b/src/lib3270/ctlr.c
@@ -56,7 +56,7 @@
#include "screenc.h"
#include "scrollc.h"
#include "seec.h"
-#include "sfc.h"
+#include "sf.h"
#include "statusc.h"
#include "tablesc.h"
#include "telnetc.h"
@@ -167,8 +167,7 @@ void ctlr_reinit(H3270 *session, unsigned cmask)
struct ea *tmp;
size_t sz = (session->maxROWS * session->maxCOLS);
-
- session->buffer[0] = tmp = lib3270_calloc(sizeof(struct ea),sz+1, session->buffer[0]);
+ session->buffer[0] = tmp = lib3270_calloc(sizeof(struct ea), sz+1, session->buffer[0]);
session->ea_buf = tmp + 1;
session->buffer[1] = tmp = lib3270_calloc(sizeof(struct ea),sz+1,session->buffer[1]);
diff --git a/src/lib3270/kybd.c b/src/lib3270/kybd.c
index 00a3cc9..0d14111 100644
--- a/src/lib3270/kybd.c
+++ b/src/lib3270/kybd.c
@@ -3461,7 +3461,7 @@ add_xk(KeySym key, KeySym assoc)
xk[i].assoc = assoc;
return;
}
- xk = (struct xks *)Realloc(xk, (nxk + 1) * sizeof(struct xks));
+ xk = (struct xks *) Realloc(xk, (nxk + 1) * sizeof(struct xks));
xk[nxk].key = key;
xk[nxk].assoc = assoc;
nxk++;
diff --git a/src/lib3270/localdefs.h b/src/lib3270/localdefs.h
index 8745605..4e94fb9 100644
--- a/src/lib3270/localdefs.h
+++ b/src/lib3270/localdefs.h
@@ -63,24 +63,15 @@ typedef struct _XtActionsRec{
/* These are local functions with similar semantics to X functions. */
-void * Malloc(size_t);
-void Free(void *);
-void * Calloc(size_t, size_t);
-void * Realloc(void *, size_t);
+// void * Malloc(size_t);
+// void Free(void *);
+// void * Calloc(size_t, size_t);
+// void * Realloc(void *, size_t);
-/**
- * Alloc/Realloc memory buffer.
- *
- * Allocate/reallocate an array.
- *
- * @param elsize Element size.
- * @param nelem Number of elements in the array.
- * @param ptr Pointer to the actual array.
- *
- * @return ptr allocated with the new array size.
- *
- */
-void * lib3270_calloc(size_t elsize, size_t nelem, void *ptr);
+#define Malloc(x) lib3270_malloc(x)
+#define Free(x) lib3270_free(x)
+#define Calloc(e,n) lib3270_calloc(e,n,NULL)
+#define Realloc(x,n) lib3270_realloc(x,n)
#define NewString(x) strdup(x)
//extern char *NewString(const char *);
diff --git a/src/lib3270/rpq.c b/src/lib3270/rpq.c
index 44d52ba..4edc475 100644
--- a/src/lib3270/rpq.c
+++ b/src/lib3270/rpq.c
@@ -64,6 +64,7 @@
#include "telnetc.h"
#include "trace_dsc.h"
#include "utilc.h"
+#include "sf.h"
/* Statics */
static Boolean select_rpq_terms(void);
@@ -121,8 +122,7 @@ static char *x3270rpq;
/*
* RPQNAMES query reply.
*/
-void
-do_qr_rpqnames(void)
+void do_qr_rpqnames(void)
{
#define TERM_PREFIX_SIZE 2 /* Each term has 1 byte length and 1
byte id */
diff --git a/src/lib3270/sf.c b/src/lib3270/sf.c
index 2dea6d8..8c9f5ce 100644
--- a/src/lib3270/sf.c
+++ b/src/lib3270/sf.c
@@ -56,7 +56,7 @@
#include "kybdc.h"
#include "screenc.h"
#include "seec.h"
-#include "sfc.h"
+#include "sf.h"
#include "tablesc.h"
#include "telnetc.h"
#include "trace_dsc.h"
@@ -92,13 +92,13 @@ static void query_reply_start(void);
static void do_query_reply(unsigned char code);
static void query_reply_end(void);
-typedef void qr_single_fn_t(void);
typedef Boolean qr_multi_fn_t(unsigned *subindex, Boolean *more);
static qr_single_fn_t do_qr_summary, do_qr_usable_area, do_qr_alpha_part,
do_qr_charsets, do_qr_color, do_qr_highlighting, do_qr_reply_modes,
do_qr_imp_part, do_qr_null;
-extern qr_single_fn_t do_qr_rpqnames;
+
+
#if defined(X3270_DBCS) /*[*/
static qr_single_fn_t do_qr_dbcs_asia;
#endif /*]*/
@@ -121,10 +121,15 @@ static struct reply {
#if defined(X3270_DBCS) /*[*/
{ QR_DBCS_ASIA, do_qr_dbcs_asia, NULL }, /* 0x91 */
#endif /*]*/
+
#if defined(X3270_FT) /*[*/
{ QR_DDM, do_qr_ddm, NULL }, /* 0x95 */
#endif /*]*/
+
+#ifndef ANDROID
{ QR_RPQNAMES, do_qr_rpqnames, NULL }, /* 0xa1 */
+#endif // !ANDROID
+
{ QR_IMP_PART, do_qr_imp_part, NULL }, /* 0xa6 */
/* QR_NULL must be last in the table */
diff --git a/src/lib3270/sf.h b/src/lib3270/sf.h
new file mode 100644
index 0000000..ac34033
--- /dev/null
+++ b/src/lib3270/sf.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 1995, 1999, 2000 by Paul Mattes.
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation.
+ *
+ * x3270, c3270, s3270, tcl3270 and pr3287 are distributed in the hope that
+ * they will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * file LICENSE for more details.
+ */
+
+typedef void qr_single_fn_t(void);
+
+LIB3270_INTERNAL qr_single_fn_t do_qr_rpqnames;
+
+LIB3270_INTERNAL enum pds write_structured_field(unsigned char buf[], int buflen);
diff --git a/src/lib3270/sfc.h b/src/lib3270/sfc.h
deleted file mode 100644
index 00f3de1..0000000
--- a/src/lib3270/sfc.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 1995, 1999, 2000 by Paul Mattes.
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and that
- * both that copyright notice and this permission notice appear in
- * supporting documentation.
- *
- * x3270, c3270, s3270, tcl3270 and pr3287 are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the implied
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * file LICENSE for more details.
- */
-
-/*
- * sfc.h
- * Global declarations for sf.c.
- */
-
-LIB3270_INTERNAL enum pds write_structured_field(unsigned char buf[], int buflen);
diff --git a/src/lib3270/util.c b/src/lib3270/util.c
index c24adab..c8bc989 100644
--- a/src/lib3270/util.c
+++ b/src/lib3270/util.c
@@ -1087,3 +1087,100 @@ StringToKeysym(char *s)
}
#endif
*/
+
+LIB3270_EXPORT void lib3270_free(void *p)
+{
+ if(p)
+ free(p);
+}
+
+LIB3270_EXPORT void * lib3270_realloc(void *p, int len)
+{
+ p = realloc(p, len);
+ if(!p)
+ Error(NULL,"Out of memory");
+ return p;
+}
+
+LIB3270_EXPORT void * lib3270_calloc(int elsize, int nelem, void *ptr)
+{
+ size_t sz = nelem * elsize;
+
+ if(ptr)
+ ptr = realloc(ptr,sz);
+ else
+ ptr = malloc(sz);
+
+ if(ptr)
+ memset(ptr,0,sz);
+ else
+ Error(NULL,"Out of memory");
+
+ return ptr;
+}
+
+
+LIB3270_EXPORT void * lib3270_malloc(int len)
+{
+ char *r;
+
+ r = malloc(len);
+ if (r == (char *)NULL)
+ {
+ Error(NULL,"Out of memory");
+ return 0;
+ }
+
+ memset(r,0,len);
+ return r;
+}
+
+/*
+void * Calloc(size_t nelem, size_t elsize)
+{
+ int sz = nelem * elsize;
+ char * r = malloc(sz);
+
+ if(!r)
+ Error(NULL,"Out of memory");
+
+ memset(r, 0, sz);
+ return r;
+}
+*/
+
+LIB3270_EXPORT char * lib3270_get_resource_string(const char *first_element, ...)
+{
+#ifndef ANDROID
+
+ #warning Work in progress
+
+ char buffer[4096];
+ char * ptr = buffer;
+ const char * element;
+ va_list args;
+ const char * res;
+
+ va_start(args, first_element);
+
+ for(element = first_element;element;element = va_arg(args, const char *))
+ {
+ if(ptr != buffer)
+ *(ptr++) = '.';
+
+ strncpy(ptr,element,4096-strlen(buffer));
+ ptr += strlen(ptr);
+ }
+
+ va_end(args);
+
+ *ptr = 0;
+
+ trace("%s: %s",__FUNCTION__,buffer);
+
+ res = get_resource(buffer);
+ if(res)
+ return strdup(res);
+#endif
+ return NULL;
+}
--
libgit2 0.21.2