Commit ecbf3ba64082cd1b510d91f2ab21825f479f8cb4

Authored by Perry Werneck
1 parent 3b6932dd

Adding method to get property descriptor by name.

src/core/actions/actions.c
... ... @@ -31,6 +31,7 @@
31 31 #include <lib3270/log.h>
32 32 #include <lib3270/trace.h>
33 33 #include <lib3270/actions.h>
  34 +#include <utilc.h>
34 35  
35 36 struct lib3270_action_callback
36 37 {
... ... @@ -40,33 +41,6 @@ struct lib3270_action_callback
40 41  
41 42 /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/
42 43  
43   -static int compare_alnum(const char *s1, const char *s2)
44   -{
45   - while(*s1 && *s2) {
46   -
47   - char c1 = toupper(*s1);
48   - if(!isalnum(c1)) {
49   - s1++;
50   - continue;
51   - }
52   -
53   - char c2 = toupper(*s2);
54   - if(!isalnum(c2)) {
55   - s2++;
56   - continue;
57   - }
58   -
59   - if(c1 != c2)
60   - return 1;
61   -
62   - s1++;
63   - s2++;
64   -
65   - }
66   -
67   - return 0;
68   -}
69   -
70 44 const LIB3270_ACTION * lib3270_action_get_by_name(const char *name)
71 45 {
72 46 const LIB3270_ACTION * actions = lib3270_get_actions();
... ... @@ -81,7 +55,7 @@ const LIB3270_ACTION * lib3270_action_get_by_name(const char *name)
81 55 // Check only alphabetic and numeric (for compatibility)
82 56 for(f=0; actions[f].name; f++)
83 57 {
84   - if(!compare_alnum(name,actions[f].name))
  58 + if(!lib3270_compare_alnum(name,actions[f].name))
85 59 return actions+f;
86 60 }
87 61  
... ...
src/core/properties/get.c
... ... @@ -32,6 +32,7 @@
32 32 #include <string.h>
33 33 #include <lib3270.h>
34 34 #include <lib3270/properties.h>
  35 + #include <utilc.h>
35 36  
36 37 LIB3270_EXPORT const char * lib3270_property_get_description(const LIB3270_PROPERTY * property) {
37 38  
... ... @@ -53,3 +54,40 @@
53 54 return property->name;
54 55  
55 56 }
  57 +
  58 + LIB3270_EXPORT const LIB3270_PROPERTY * lib3270_property_get_by_name(const char *name) {
  59 +
  60 + // Search string properties
  61 + {
  62 + const LIB3270_STRING_PROPERTY * property = lib3270_get_string_properties_list();
  63 +
  64 + while(property->name) {
  65 +
  66 + if(!lib3270_compare_alnum(name,property->name))
  67 + return (const LIB3270_PROPERTY *) property;
  68 +
  69 + property++;
  70 +
  71 + }
  72 +
  73 + }
  74 +
  75 + // Search unsigned int properties.
  76 + {
  77 + const LIB3270_UINT_PROPERTY * property = lib3270_get_unsigned_properties_list();
  78 +
  79 + while(property->name) {
  80 +
  81 + if(!lib3270_compare_alnum(name,property->name))
  82 + return (const LIB3270_PROPERTY *) property;
  83 +
  84 + property++;
  85 +
  86 + }
  87 +
  88 + }
  89 +
  90 + // Not found!
  91 + errno = ENOENT;
  92 + return NULL;
  93 + }
... ...
src/core/properties/string.c
... ... @@ -67,10 +67,11 @@
67 67 },
68 68  
69 69 {
70   - .name = "url", // Property name.
71   - .description = N_( "URL of the current host" ), // Property description.
72   - .get = lib3270_get_url, // Get value.
73   - .set = lib3270_set_url // Set value.
  70 + .name = "url", // Property name.
  71 + .icon = "network-server", // Property icon.
  72 + .description = N_( "URL of the current host" ), // Property description.
  73 + .get = lib3270_get_url, // Get value.
  74 + .set = lib3270_set_url // Set value.
74 75 },
75 76  
76 77 {
... ...
src/core/properties/unsigned.c
... ... @@ -68,6 +68,8 @@
68 68  
69 69 {
70 70 .name = "model_number", // Property name.
  71 + .icon = "video-display", // Property Icon.
  72 + .label = N_("Terminal model"), // Property label.
71 73 .description = N_( "The model number" ), // Property description.
72 74 .min = 2, // Minimum allowable value.
73 75 .max = 5, // Maximum allowable value.
... ...
src/core/util.c
... ... @@ -807,3 +807,31 @@ char * lib3270_unescape(const char *text)
807 807  
808 808 return outString;
809 809 }
  810 +
  811 +int lib3270_compare_alnum(const char *s1, const char *s2)
  812 +{
  813 + while(*s1 && *s2) {
  814 +
  815 + char c1 = toupper(*s1);
  816 + if(!isalnum(c1)) {
  817 + s1++;
  818 + continue;
  819 + }
  820 +
  821 + char c2 = toupper(*s2);
  822 + if(!isalnum(c2)) {
  823 + s2++;
  824 + continue;
  825 + }
  826 +
  827 + if(c1 != c2)
  828 + return 1;
  829 +
  830 + s1++;
  831 + s2++;
  832 +
  833 + }
  834 +
  835 + return 0;
  836 +}
  837 +
... ...
src/include/lib3270.h
... ... @@ -365,6 +365,8 @@
365 365 */
366 366 #define LIB3270_PROPERTY_HEAD \
367 367 const char * name; \
  368 + const char * label; \
  369 + const char * icon; \
368 370 const char * summary; \
369 371 const char * description;
370 372  
... ...
src/include/lib3270/actions.h
... ... @@ -68,8 +68,6 @@
68 68 int (*activatable)(const H3270 *hSession); ///< @brief Is the action activatable?
69 69  
70 70 const char *key; ///< @brief Default key (or NULL if no default).
71   - const char *icon; ///< @brief Icon name (from https://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html)
72   - const char *label; ///< @brief Button label (or NULL).
73 71  
74 72 } LIB3270_ACTION;
75 73  
... ...
src/include/lib3270/properties.h
... ... @@ -107,6 +107,13 @@
107 107 */
108 108 LIB3270_EXPORT const LIB3270_STRING_PROPERTY * lib3270_get_string_properties_list(void);
109 109  
  110 + /**
  111 + * @brief Get property descriptor by name.
  112 + *
  113 + * @return Property descriptor or NULL if failed.
  114 + *
  115 + */
  116 + LIB3270_EXPORT const LIB3270_PROPERTY * lib3270_property_get_by_name(const char *name);
110 117  
111 118 /**
112 119 * @brief Get lib3270 integer property by name.
... ...
src/include/lib3270/toggle.h
... ... @@ -98,8 +98,6 @@
98 98 LIB3270_TOGGLE_ID id; ///< @brief Toggle ID.
99 99 const char def; ///< @brief Default value.
100 100 const char * key; ///< @brief Default key (or NULL if no default).
101   - const char * icon; ///< @brief Icon name (from https://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html)
102   - const char * label; ///< @brief Label for button or menu (NULL if isn't available).
103 101  
104 102 } LIB3270_TOGGLE;
105 103  
... ...
src/include/utilc.h
... ... @@ -69,3 +69,15 @@ LIB3270_INTERNAL void rpf_free(rpf_t *r);
69 69 *
70 70 */
71 71 LIB3270_INTERNAL char * lib3270_unescape(const char *text);
  72 +
  73 +/**
  74 + * @brief Compare strings ignoring non alfanumeric chars.
  75 + *
  76 + * @param s1 First string.
  77 + * @param s2 Second string.
  78 + *
  79 + * @return 0 if equal, non zero if not.
  80 + *
  81 + */
  82 +LIB3270_INTERNAL int lib3270_compare_alnum(const char *s1, const char *s2);
  83 +
... ...
src/testprogram/testprogram.c
... ... @@ -10,6 +10,7 @@
10 10 #include <lib3270/trace.h>
11 11 #include <lib3270/toggle.h>
12 12 #include <lib3270/log.h>
  13 +#include <lib3270/properties.h>
13 14  
14 15 #define MAX_ARGS 10
15 16  
... ... @@ -152,6 +153,7 @@ int main(int argc, char *argv[])
152 153  
153 154 lib3270_disconnect(h);
154 155  
  156 + /*
155 157 {
156 158 lib3270_set_lunames(h,"a,b,c,d,e");
157 159  
... ... @@ -164,6 +166,14 @@ int main(int argc, char *argv[])
164 166 }
165 167  
166 168 }
  169 + */
  170 +
  171 + {
  172 + const LIB3270_PROPERTY * property = lib3270_property_get_by_name("model-number");
  173 +
  174 + debug("Model-number=%p",property);
  175 +
  176 + }
167 177  
168 178 lib3270_session_free(h);
169 179  
... ...