diff --git a/src/core/actions/actions.c b/src/core/actions/actions.c index 66a4666..2380d35 100644 --- a/src/core/actions/actions.c +++ b/src/core/actions/actions.c @@ -31,6 +31,7 @@ #include #include #include +#include struct lib3270_action_callback { @@ -40,33 +41,6 @@ struct lib3270_action_callback /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ -static int compare_alnum(const char *s1, const char *s2) -{ - while(*s1 && *s2) { - - char c1 = toupper(*s1); - if(!isalnum(c1)) { - s1++; - continue; - } - - char c2 = toupper(*s2); - if(!isalnum(c2)) { - s2++; - continue; - } - - if(c1 != c2) - return 1; - - s1++; - s2++; - - } - - return 0; -} - const LIB3270_ACTION * lib3270_action_get_by_name(const char *name) { const LIB3270_ACTION * actions = lib3270_get_actions(); @@ -81,7 +55,7 @@ const LIB3270_ACTION * lib3270_action_get_by_name(const char *name) // Check only alphabetic and numeric (for compatibility) for(f=0; actions[f].name; f++) { - if(!compare_alnum(name,actions[f].name)) + if(!lib3270_compare_alnum(name,actions[f].name)) return actions+f; } diff --git a/src/core/properties/get.c b/src/core/properties/get.c index 2d13632..be40a5b 100644 --- a/src/core/properties/get.c +++ b/src/core/properties/get.c @@ -32,6 +32,7 @@ #include #include #include + #include LIB3270_EXPORT const char * lib3270_property_get_description(const LIB3270_PROPERTY * property) { @@ -53,3 +54,40 @@ return property->name; } + + LIB3270_EXPORT const LIB3270_PROPERTY * lib3270_property_get_by_name(const char *name) { + + // Search string properties + { + const LIB3270_STRING_PROPERTY * property = lib3270_get_string_properties_list(); + + while(property->name) { + + if(!lib3270_compare_alnum(name,property->name)) + return (const LIB3270_PROPERTY *) property; + + property++; + + } + + } + + // Search unsigned int properties. + { + const LIB3270_UINT_PROPERTY * property = lib3270_get_unsigned_properties_list(); + + while(property->name) { + + if(!lib3270_compare_alnum(name,property->name)) + return (const LIB3270_PROPERTY *) property; + + property++; + + } + + } + + // Not found! + errno = ENOENT; + return NULL; + } diff --git a/src/core/properties/string.c b/src/core/properties/string.c index 7c96f3a..25987eb 100644 --- a/src/core/properties/string.c +++ b/src/core/properties/string.c @@ -67,10 +67,11 @@ }, { - .name = "url", // Property name. - .description = N_( "URL of the current host" ), // Property description. - .get = lib3270_get_url, // Get value. - .set = lib3270_set_url // Set value. + .name = "url", // Property name. + .icon = "network-server", // Property icon. + .description = N_( "URL of the current host" ), // Property description. + .get = lib3270_get_url, // Get value. + .set = lib3270_set_url // Set value. }, { diff --git a/src/core/properties/unsigned.c b/src/core/properties/unsigned.c index 45fa80c..c713ad2 100644 --- a/src/core/properties/unsigned.c +++ b/src/core/properties/unsigned.c @@ -68,6 +68,8 @@ { .name = "model_number", // Property name. + .icon = "video-display", // Property Icon. + .label = N_("Terminal model"), // Property label. .description = N_( "The model number" ), // Property description. .min = 2, // Minimum allowable value. .max = 5, // Maximum allowable value. diff --git a/src/core/util.c b/src/core/util.c index fe8ad6c..f1a3d7a 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -807,3 +807,31 @@ char * lib3270_unescape(const char *text) return outString; } + +int lib3270_compare_alnum(const char *s1, const char *s2) +{ + while(*s1 && *s2) { + + char c1 = toupper(*s1); + if(!isalnum(c1)) { + s1++; + continue; + } + + char c2 = toupper(*s2); + if(!isalnum(c2)) { + s2++; + continue; + } + + if(c1 != c2) + return 1; + + s1++; + s2++; + + } + + return 0; +} + diff --git a/src/include/lib3270.h b/src/include/lib3270.h index d47f5cf..3cca886 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -365,6 +365,8 @@ */ #define LIB3270_PROPERTY_HEAD \ const char * name; \ + const char * label; \ + const char * icon; \ const char * summary; \ const char * description; diff --git a/src/include/lib3270/actions.h b/src/include/lib3270/actions.h index 5e20677..4285dce 100644 --- a/src/include/lib3270/actions.h +++ b/src/include/lib3270/actions.h @@ -68,8 +68,6 @@ int (*activatable)(const H3270 *hSession); ///< @brief Is the action activatable? const char *key; ///< @brief Default key (or NULL if no default). - const char *icon; ///< @brief Icon name (from https://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html) - const char *label; ///< @brief Button label (or NULL). } LIB3270_ACTION; diff --git a/src/include/lib3270/properties.h b/src/include/lib3270/properties.h index c3fb355..2cc7b8d 100644 --- a/src/include/lib3270/properties.h +++ b/src/include/lib3270/properties.h @@ -107,6 +107,13 @@ */ LIB3270_EXPORT const LIB3270_STRING_PROPERTY * lib3270_get_string_properties_list(void); + /** + * @brief Get property descriptor by name. + * + * @return Property descriptor or NULL if failed. + * + */ + LIB3270_EXPORT const LIB3270_PROPERTY * lib3270_property_get_by_name(const char *name); /** * @brief Get lib3270 integer property by name. diff --git a/src/include/lib3270/toggle.h b/src/include/lib3270/toggle.h index 8680be7..707c211 100644 --- a/src/include/lib3270/toggle.h +++ b/src/include/lib3270/toggle.h @@ -98,8 +98,6 @@ LIB3270_TOGGLE_ID id; ///< @brief Toggle ID. const char def; ///< @brief Default value. const char * key; ///< @brief Default key (or NULL if no default). - const char * icon; ///< @brief Icon name (from https://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html) - const char * label; ///< @brief Label for button or menu (NULL if isn't available). } LIB3270_TOGGLE; diff --git a/src/include/utilc.h b/src/include/utilc.h index 2372547..68a28b3 100644 --- a/src/include/utilc.h +++ b/src/include/utilc.h @@ -69,3 +69,15 @@ LIB3270_INTERNAL void rpf_free(rpf_t *r); * */ LIB3270_INTERNAL char * lib3270_unescape(const char *text); + +/** + * @brief Compare strings ignoring non alfanumeric chars. + * + * @param s1 First string. + * @param s2 Second string. + * + * @return 0 if equal, non zero if not. + * + */ +LIB3270_INTERNAL int lib3270_compare_alnum(const char *s1, const char *s2); + diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index a7e1666..4fd297e 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -10,6 +10,7 @@ #include #include #include +#include #define MAX_ARGS 10 @@ -152,6 +153,7 @@ int main(int argc, char *argv[]) lib3270_disconnect(h); + /* { lib3270_set_lunames(h,"a,b,c,d,e"); @@ -164,6 +166,14 @@ int main(int argc, char *argv[]) } } + */ + + { + const LIB3270_PROPERTY * property = lib3270_property_get_by_name("model-number"); + + debug("Model-number=%p",property); + + } lib3270_session_free(h); -- libgit2 0.21.2