diff --git a/src/core/model.c b/src/core/model.c index ff16d92..1abf682 100644 --- a/src/core/model.c +++ b/src/core/model.c @@ -85,7 +85,7 @@ * @param hSession selected 3270 session. * @return Current model number. */ -int lib3270_get_model_number(const H3270 *hSession) +unsigned int lib3270_get_model_number(const H3270 *hSession) { return hSession->model_num; } @@ -95,11 +95,16 @@ const char * lib3270_get_model(const H3270 *hSession) return hSession->model_name; } +const char * lib3270_get_model_name(const H3270 *hSession) +{ + return hSession->model_name; +} + /** * @brief Parse the model number. * * @param session Session Handle. - * @param m Model number. + * @param m Model number (NULL for "2"). * * @return -1 (error), 0 (default), or the specified number. */ @@ -109,19 +114,19 @@ static int parse_model_number(H3270 *session, const char *m) int n; if(!m) - return 0; + m = "2"; sl = strlen(m); - /* An empty model number is no good. */ + // An empty model number is no good. if (!sl) return 0; if (sl > 1) { - /* - * If it's longer than one character, it needs to start with - * '327[89]', and it sets the m3279 resource. - */ + + // If it's longer than one character, it needs to start with + // '327[89]', and it sets the m3279 resource. + if (!strncmp(m, "3278", 4)) { session->m3279 = 0; @@ -137,13 +142,13 @@ static int parse_model_number(H3270 *session, const char *m) m += 4; sl -= 4; - /* Check more syntax. -E is allowed, but ignored. */ + // Check more syntax. -E is allowed, but ignored. switch (m[0]) { case '\0': - /* Use default model number. */ + // Use default model number. return 0; case '-': - /* Model number specified. */ + // Model number specified. m++; sl--; break; @@ -151,9 +156,9 @@ static int parse_model_number(H3270 *session, const char *m) return -1; } switch (sl) { - case 1: /* n */ + case 1: // n break; - case 3: /* n-E */ + case 3: // n-E if (strcasecmp(m + 1, "-E")) { return -1; } @@ -163,7 +168,7 @@ static int parse_model_number(H3270 *session, const char *m) } } - /* Check the numeric model number. */ + // Check the numeric model number. n = atoi(m); if (n >= 2 && n <= 5) { return n; @@ -173,26 +178,24 @@ static int parse_model_number(H3270 *session, const char *m) } -int lib3270_set_model(H3270 *hSession, const char *model) +int lib3270_set_model_name(H3270 *hSession, const char *model_name) +{ + return lib3270_set_model_number(hSession,parse_model_number(hSession, model_name)); +} + +int lib3270_set_model(H3270 *hSession, const char *model_name) { - int model_number; + return lib3270_set_model_number(hSession,parse_model_number(hSession, model_name)); +} +int lib3270_set_model_number(H3270 *hSession, unsigned int model_number) +{ if(hSession->connection.state != LIB3270_NOT_CONNECTED) return errno = EISCONN; strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); hSession->model_name = &hSession->full_model_name[4]; - if(!*model) - model = "2"; // No model, use the default one - - model_number = parse_model_number(hSession,model); - if (model_number < 0) - { - popup_an_error(hSession,"Invalid model number: %s", model); - model_number = 0; - } - if (!model_number) { #if defined(RESTRICT_3279) diff --git a/src/core/properties/signed.c b/src/core/properties/signed.c index 7d72ff9..4a69374 100644 --- a/src/core/properties/signed.c +++ b/src/core/properties/signed.c @@ -55,13 +55,6 @@ static const LIB3270_INT_PROPERTY properties[] = { { - .name = "model_number", // Property name. - .description = N_( "The model number" ), // Property description. - .get = lib3270_get_model_number, // Get value. - .set = NULL // Set value. - }, - - { .name = "color_type", // Property name. .description = N_( "The color type" ), // Property description. .get = lib3270_get_color_type, // Get value. diff --git a/src/core/properties/string.c b/src/core/properties/string.c index 957d98a..64fdb0a 100644 --- a/src/core/properties/string.c +++ b/src/core/properties/string.c @@ -75,8 +75,8 @@ { .name = "model", // Property name. .description = N_( "Model name" ), // Property description. - .get = lib3270_get_model, // Get value. - .set = lib3270_set_model // Set value. + .get = lib3270_get_model_name, // Get value. + .set = lib3270_set_model_name // Set value. }, { diff --git a/src/core/properties/unsigned.c b/src/core/properties/unsigned.c index becbecd..38e5abf 100644 --- a/src/core/properties/unsigned.c +++ b/src/core/properties/unsigned.c @@ -39,16 +39,40 @@ return (unsigned int) lib3270_get_keyboard_lock_state(hSession); } + const LIB3270_UINT_PROPERTY * lib3270_unsigned_property_get_by_name(const char *name) + { + size_t ix; + const LIB3270_UINT_PROPERTY * list = lib3270_get_unsigned_properties_list(); + + for(ix = 0;list[ix].name;ix++) + { + if(!strcasecmp(list[ix].name,name)) + return &list[ix]; + } + + errno = ENOENT; + return NULL; + } + const LIB3270_UINT_PROPERTY * lib3270_get_unsigned_properties_list(void) { static const LIB3270_UINT_PROPERTY properties[] = { { - .name = "cursor_address", // Property name. - .description = N_( "Cursor address" ), // Property description. - .get = lib3270_get_cursor_address, // Get value. - .set = lib3270_set_cursor_address // Set value. + .name = "model_number", // Property name. + .description = N_( "The model number" ), // Property description. + .min = 2, // Minimum allowable value. + .max = 5, // Maximum allowable value. + .get = lib3270_get_model_number, // Get value. + .set = lib3270_set_model_number // Set value. + }, + + { + .name = "cursor_address", // Property name. + .description = N_( "Cursor address" ), // Property description. + .get = lib3270_get_cursor_address, // Get value. + .set = lib3270_set_cursor_address // Set value. }, { diff --git a/src/core/session.c b/src/core/session.c index 5c88a04..b3bd956 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -368,7 +368,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char // Initialize toggles initialize_toggles(hSession); - lib3270_set_model(hSession,model); + lib3270_set_model_name(hSession,model); } diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 292c946..afdb7ee 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -1324,10 +1324,23 @@ LIB3270_EXPORT int lib3270_get_word_bounds(H3270 *hSession, int baddr, int *start, int *end); - LIB3270_EXPORT int lib3270_set_model(H3270 *hSession, const char *name); + LIB3270_EXPORT int LIB3270_DEPRECATED(lib3270_set_model(H3270 *hSession, const char *model_name)); + LIB3270_EXPORT const char * LIB3270_DEPRECATED(lib3270_get_model(const H3270 *session)); - LIB3270_EXPORT const char * lib3270_get_model(const H3270 *session); - LIB3270_EXPORT int lib3270_get_model_number(const H3270 *hSession); + LIB3270_EXPORT const char * lib3270_get_model_name(const H3270 *session); + LIB3270_EXPORT int lib3270_set_model_name(H3270 *hSession, const char *model_name); + + LIB3270_EXPORT unsigned int lib3270_get_model_number(const H3270 *hSession); + + /** + * @brief Set TN3270 model number. + * + * @param hSession Session handle. + * @param model_number The new model number (2-5). + * + * @return + */ + LIB3270_EXPORT int lib3270_set_model_number(H3270 *hSession, unsigned int model_number); /** * diff --git a/src/include/lib3270/properties.h b/src/include/lib3270/properties.h index 7648fda..7a218ad 100644 --- a/src/include/lib3270/properties.h +++ b/src/include/lib3270/properties.h @@ -60,6 +60,9 @@ unsigned int (*get)(const H3270 *hSession); ///< @brief Get value. int (*set)(H3270 *hSession, unsigned int value); ///< @brief Set value. + unsigned int min; ///< @brief Minimum allowable value. + unsigned int max; ///< @brief Maximum allowable value. + } LIB3270_UINT_PROPERTY; typedef struct _lib3270_string_property @@ -177,6 +180,16 @@ */ LIB3270_EXPORT const char * lib3270_property_get_summary(const LIB3270_PROPERTY * property); + /** + * @brief Get unsigned int property by name. + * + * @param name Property name. + * + * @return Property descriptor, or NULL if failed. + * + */ + const LIB3270_UINT_PROPERTY * lib3270_unsigned_property_get_by_name(const char *name); + #ifdef __cplusplus } #endif -- libgit2 0.21.2