Commit 0804f1916001da9c437f5a568db5f2eb40d4679c

Authored by Perry Werneck
1 parent d58165ff

Improving the model number property.

src/core/model.c
@@ -85,7 +85,7 @@ @@ -85,7 +85,7 @@
85 * @param hSession selected 3270 session. 85 * @param hSession selected 3270 session.
86 * @return Current model number. 86 * @return Current model number.
87 */ 87 */
88 -int lib3270_get_model_number(const H3270 *hSession) 88 +unsigned int lib3270_get_model_number(const H3270 *hSession)
89 { 89 {
90 return hSession->model_num; 90 return hSession->model_num;
91 } 91 }
@@ -95,11 +95,16 @@ const char * lib3270_get_model(const H3270 *hSession) @@ -95,11 +95,16 @@ const char * lib3270_get_model(const H3270 *hSession)
95 return hSession->model_name; 95 return hSession->model_name;
96 } 96 }
97 97
  98 +const char * lib3270_get_model_name(const H3270 *hSession)
  99 +{
  100 + return hSession->model_name;
  101 +}
  102 +
98 /** 103 /**
99 * @brief Parse the model number. 104 * @brief Parse the model number.
100 * 105 *
101 * @param session Session Handle. 106 * @param session Session Handle.
102 - * @param m Model number. 107 + * @param m Model number (NULL for "2").
103 * 108 *
104 * @return -1 (error), 0 (default), or the specified number. 109 * @return -1 (error), 0 (default), or the specified number.
105 */ 110 */
@@ -109,19 +114,19 @@ static int parse_model_number(H3270 *session, const char *m) @@ -109,19 +114,19 @@ static int parse_model_number(H3270 *session, const char *m)
109 int n; 114 int n;
110 115
111 if(!m) 116 if(!m)
112 - return 0; 117 + m = "2";
113 118
114 sl = strlen(m); 119 sl = strlen(m);
115 120
116 - /* An empty model number is no good. */ 121 + // An empty model number is no good.
117 if (!sl) 122 if (!sl)
118 return 0; 123 return 0;
119 124
120 if (sl > 1) { 125 if (sl > 1) {
121 - /*  
122 - * If it's longer than one character, it needs to start with  
123 - * '327[89]', and it sets the m3279 resource.  
124 - */ 126 +
  127 + // If it's longer than one character, it needs to start with
  128 + // '327[89]', and it sets the m3279 resource.
  129 +
125 if (!strncmp(m, "3278", 4)) 130 if (!strncmp(m, "3278", 4))
126 { 131 {
127 session->m3279 = 0; 132 session->m3279 = 0;
@@ -137,13 +142,13 @@ static int parse_model_number(H3270 *session, const char *m) @@ -137,13 +142,13 @@ static int parse_model_number(H3270 *session, const char *m)
137 m += 4; 142 m += 4;
138 sl -= 4; 143 sl -= 4;
139 144
140 - /* Check more syntax. -E is allowed, but ignored. */ 145 + // Check more syntax. -E is allowed, but ignored.
141 switch (m[0]) { 146 switch (m[0]) {
142 case '\0': 147 case '\0':
143 - /* Use default model number. */ 148 + // Use default model number.
144 return 0; 149 return 0;
145 case '-': 150 case '-':
146 - /* Model number specified. */ 151 + // Model number specified.
147 m++; 152 m++;
148 sl--; 153 sl--;
149 break; 154 break;
@@ -151,9 +156,9 @@ static int parse_model_number(H3270 *session, const char *m) @@ -151,9 +156,9 @@ static int parse_model_number(H3270 *session, const char *m)
151 return -1; 156 return -1;
152 } 157 }
153 switch (sl) { 158 switch (sl) {
154 - case 1: /* n */ 159 + case 1: // n
155 break; 160 break;
156 - case 3: /* n-E */ 161 + case 3: // n-E
157 if (strcasecmp(m + 1, "-E")) { 162 if (strcasecmp(m + 1, "-E")) {
158 return -1; 163 return -1;
159 } 164 }
@@ -163,7 +168,7 @@ static int parse_model_number(H3270 *session, const char *m) @@ -163,7 +168,7 @@ static int parse_model_number(H3270 *session, const char *m)
163 } 168 }
164 } 169 }
165 170
166 - /* Check the numeric model number. */ 171 + // Check the numeric model number.
167 n = atoi(m); 172 n = atoi(m);
168 if (n >= 2 && n <= 5) { 173 if (n >= 2 && n <= 5) {
169 return n; 174 return n;
@@ -173,26 +178,24 @@ static int parse_model_number(H3270 *session, const char *m) @@ -173,26 +178,24 @@ static int parse_model_number(H3270 *session, const char *m)
173 178
174 } 179 }
175 180
176 -int lib3270_set_model(H3270 *hSession, const char *model) 181 +int lib3270_set_model_name(H3270 *hSession, const char *model_name)
  182 +{
  183 + return lib3270_set_model_number(hSession,parse_model_number(hSession, model_name));
  184 +}
  185 +
  186 +int lib3270_set_model(H3270 *hSession, const char *model_name)
177 { 187 {
178 - int model_number; 188 + return lib3270_set_model_number(hSession,parse_model_number(hSession, model_name));
  189 +}
179 190
  191 +int lib3270_set_model_number(H3270 *hSession, unsigned int model_number)
  192 +{
180 if(hSession->connection.state != LIB3270_NOT_CONNECTED) 193 if(hSession->connection.state != LIB3270_NOT_CONNECTED)
181 return errno = EISCONN; 194 return errno = EISCONN;
182 195
183 strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); 196 strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH);
184 hSession->model_name = &hSession->full_model_name[4]; 197 hSession->model_name = &hSession->full_model_name[4];
185 198
186 - if(!*model)  
187 - model = "2"; // No model, use the default one  
188 -  
189 - model_number = parse_model_number(hSession,model);  
190 - if (model_number < 0)  
191 - {  
192 - popup_an_error(hSession,"Invalid model number: %s", model);  
193 - model_number = 0;  
194 - }  
195 -  
196 if (!model_number) 199 if (!model_number)
197 { 200 {
198 #if defined(RESTRICT_3279) 201 #if defined(RESTRICT_3279)
src/core/properties/signed.c
@@ -55,13 +55,6 @@ @@ -55,13 +55,6 @@
55 static const LIB3270_INT_PROPERTY properties[] = { 55 static const LIB3270_INT_PROPERTY properties[] = {
56 56
57 { 57 {
58 - .name = "model_number", // Property name.  
59 - .description = N_( "The model number" ), // Property description.  
60 - .get = lib3270_get_model_number, // Get value.  
61 - .set = NULL // Set value.  
62 - },  
63 -  
64 - {  
65 .name = "color_type", // Property name. 58 .name = "color_type", // Property name.
66 .description = N_( "The color type" ), // Property description. 59 .description = N_( "The color type" ), // Property description.
67 .get = lib3270_get_color_type, // Get value. 60 .get = lib3270_get_color_type, // Get value.
src/core/properties/string.c
@@ -75,8 +75,8 @@ @@ -75,8 +75,8 @@
75 { 75 {
76 .name = "model", // Property name. 76 .name = "model", // Property name.
77 .description = N_( "Model name" ), // Property description. 77 .description = N_( "Model name" ), // Property description.
78 - .get = lib3270_get_model, // Get value.  
79 - .set = lib3270_set_model // Set value. 78 + .get = lib3270_get_model_name, // Get value.
  79 + .set = lib3270_set_model_name // Set value.
80 }, 80 },
81 81
82 { 82 {
src/core/properties/unsigned.c
@@ -39,16 +39,40 @@ @@ -39,16 +39,40 @@
39 return (unsigned int) lib3270_get_keyboard_lock_state(hSession); 39 return (unsigned int) lib3270_get_keyboard_lock_state(hSession);
40 } 40 }
41 41
  42 + const LIB3270_UINT_PROPERTY * lib3270_unsigned_property_get_by_name(const char *name)
  43 + {
  44 + size_t ix;
  45 + const LIB3270_UINT_PROPERTY * list = lib3270_get_unsigned_properties_list();
  46 +
  47 + for(ix = 0;list[ix].name;ix++)
  48 + {
  49 + if(!strcasecmp(list[ix].name,name))
  50 + return &list[ix];
  51 + }
  52 +
  53 + errno = ENOENT;
  54 + return NULL;
  55 + }
  56 +
42 const LIB3270_UINT_PROPERTY * lib3270_get_unsigned_properties_list(void) 57 const LIB3270_UINT_PROPERTY * lib3270_get_unsigned_properties_list(void)
43 { 58 {
44 59
45 static const LIB3270_UINT_PROPERTY properties[] = { 60 static const LIB3270_UINT_PROPERTY properties[] = {
46 61
47 { 62 {
48 - .name = "cursor_address", // Property name.  
49 - .description = N_( "Cursor address" ), // Property description.  
50 - .get = lib3270_get_cursor_address, // Get value.  
51 - .set = lib3270_set_cursor_address // Set value. 63 + .name = "model_number", // Property name.
  64 + .description = N_( "The model number" ), // Property description.
  65 + .min = 2, // Minimum allowable value.
  66 + .max = 5, // Maximum allowable value.
  67 + .get = lib3270_get_model_number, // Get value.
  68 + .set = lib3270_set_model_number // Set value.
  69 + },
  70 +
  71 + {
  72 + .name = "cursor_address", // Property name.
  73 + .description = N_( "Cursor address" ), // Property description.
  74 + .get = lib3270_get_cursor_address, // Get value.
  75 + .set = lib3270_set_cursor_address // Set value.
52 }, 76 },
53 77
54 { 78 {
src/core/session.c
@@ -368,7 +368,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char @@ -368,7 +368,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char
368 // Initialize toggles 368 // Initialize toggles
369 initialize_toggles(hSession); 369 initialize_toggles(hSession);
370 370
371 - lib3270_set_model(hSession,model); 371 + lib3270_set_model_name(hSession,model);
372 372
373 } 373 }
374 374
src/include/lib3270.h
@@ -1324,10 +1324,23 @@ @@ -1324,10 +1324,23 @@
1324 1324
1325 LIB3270_EXPORT int lib3270_get_word_bounds(H3270 *hSession, int baddr, int *start, int *end); 1325 LIB3270_EXPORT int lib3270_get_word_bounds(H3270 *hSession, int baddr, int *start, int *end);
1326 1326
1327 - LIB3270_EXPORT int lib3270_set_model(H3270 *hSession, const char *name); 1327 + LIB3270_EXPORT int LIB3270_DEPRECATED(lib3270_set_model(H3270 *hSession, const char *model_name));
  1328 + LIB3270_EXPORT const char * LIB3270_DEPRECATED(lib3270_get_model(const H3270 *session));
1328 1329
1329 - LIB3270_EXPORT const char * lib3270_get_model(const H3270 *session);  
1330 - LIB3270_EXPORT int lib3270_get_model_number(const H3270 *hSession); 1330 + LIB3270_EXPORT const char * lib3270_get_model_name(const H3270 *session);
  1331 + LIB3270_EXPORT int lib3270_set_model_name(H3270 *hSession, const char *model_name);
  1332 +
  1333 + LIB3270_EXPORT unsigned int lib3270_get_model_number(const H3270 *hSession);
  1334 +
  1335 + /**
  1336 + * @brief Set TN3270 model number.
  1337 + *
  1338 + * @param hSession Session handle.
  1339 + * @param model_number The new model number (2-5).
  1340 + *
  1341 + * @return
  1342 + */
  1343 + LIB3270_EXPORT int lib3270_set_model_number(H3270 *hSession, unsigned int model_number);
1331 1344
1332 /** 1345 /**
1333 * 1346 *
src/include/lib3270/properties.h
@@ -60,6 +60,9 @@ @@ -60,6 +60,9 @@
60 unsigned int (*get)(const H3270 *hSession); ///< @brief Get value. 60 unsigned int (*get)(const H3270 *hSession); ///< @brief Get value.
61 int (*set)(H3270 *hSession, unsigned int value); ///< @brief Set value. 61 int (*set)(H3270 *hSession, unsigned int value); ///< @brief Set value.
62 62
  63 + unsigned int min; ///< @brief Minimum allowable value.
  64 + unsigned int max; ///< @brief Maximum allowable value.
  65 +
63 } LIB3270_UINT_PROPERTY; 66 } LIB3270_UINT_PROPERTY;
64 67
65 typedef struct _lib3270_string_property 68 typedef struct _lib3270_string_property
@@ -177,6 +180,16 @@ @@ -177,6 +180,16 @@
177 */ 180 */
178 LIB3270_EXPORT const char * lib3270_property_get_summary(const LIB3270_PROPERTY * property); 181 LIB3270_EXPORT const char * lib3270_property_get_summary(const LIB3270_PROPERTY * property);
179 182
  183 + /**
  184 + * @brief Get unsigned int property by name.
  185 + *
  186 + * @param name Property name.
  187 + *
  188 + * @return Property descriptor, or NULL if failed.
  189 + *
  190 + */
  191 + const LIB3270_UINT_PROPERTY * lib3270_unsigned_property_get_by_name(const char *name);
  192 +
180 #ifdef __cplusplus 193 #ifdef __cplusplus
181 } 194 }
182 #endif 195 #endif