Commit 0804f1916001da9c437f5a568db5f2eb40d4679c
1 parent
d58165ff
Exists in
master
and in
3 other branches
Improving the model number property.
Showing
7 changed files
with
89 additions
and
43 deletions
Show diff stats
src/core/model.c
| ... | ... | @@ -85,7 +85,7 @@ |
| 85 | 85 | * @param hSession selected 3270 session. |
| 86 | 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 | 90 | return hSession->model_num; |
| 91 | 91 | } |
| ... | ... | @@ -95,11 +95,16 @@ const char * lib3270_get_model(const H3270 *hSession) |
| 95 | 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 | 104 | * @brief Parse the model number. |
| 100 | 105 | * |
| 101 | 106 | * @param session Session Handle. |
| 102 | - * @param m Model number. | |
| 107 | + * @param m Model number (NULL for "2"). | |
| 103 | 108 | * |
| 104 | 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 | 114 | int n; |
| 110 | 115 | |
| 111 | 116 | if(!m) |
| 112 | - return 0; | |
| 117 | + m = "2"; | |
| 113 | 118 | |
| 114 | 119 | sl = strlen(m); |
| 115 | 120 | |
| 116 | - /* An empty model number is no good. */ | |
| 121 | + // An empty model number is no good. | |
| 117 | 122 | if (!sl) |
| 118 | 123 | return 0; |
| 119 | 124 | |
| 120 | 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 | 130 | if (!strncmp(m, "3278", 4)) |
| 126 | 131 | { |
| 127 | 132 | session->m3279 = 0; |
| ... | ... | @@ -137,13 +142,13 @@ static int parse_model_number(H3270 *session, const char *m) |
| 137 | 142 | m += 4; |
| 138 | 143 | sl -= 4; |
| 139 | 144 | |
| 140 | - /* Check more syntax. -E is allowed, but ignored. */ | |
| 145 | + // Check more syntax. -E is allowed, but ignored. | |
| 141 | 146 | switch (m[0]) { |
| 142 | 147 | case '\0': |
| 143 | - /* Use default model number. */ | |
| 148 | + // Use default model number. | |
| 144 | 149 | return 0; |
| 145 | 150 | case '-': |
| 146 | - /* Model number specified. */ | |
| 151 | + // Model number specified. | |
| 147 | 152 | m++; |
| 148 | 153 | sl--; |
| 149 | 154 | break; |
| ... | ... | @@ -151,9 +156,9 @@ static int parse_model_number(H3270 *session, const char *m) |
| 151 | 156 | return -1; |
| 152 | 157 | } |
| 153 | 158 | switch (sl) { |
| 154 | - case 1: /* n */ | |
| 159 | + case 1: // n | |
| 155 | 160 | break; |
| 156 | - case 3: /* n-E */ | |
| 161 | + case 3: // n-E | |
| 157 | 162 | if (strcasecmp(m + 1, "-E")) { |
| 158 | 163 | return -1; |
| 159 | 164 | } |
| ... | ... | @@ -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 | 172 | n = atoi(m); |
| 168 | 173 | if (n >= 2 && n <= 5) { |
| 169 | 174 | return n; |
| ... | ... | @@ -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 | 193 | if(hSession->connection.state != LIB3270_NOT_CONNECTED) |
| 181 | 194 | return errno = EISCONN; |
| 182 | 195 | |
| 183 | 196 | strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); |
| 184 | 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 | 199 | if (!model_number) |
| 197 | 200 | { |
| 198 | 201 | #if defined(RESTRICT_3279) | ... | ... |
src/core/properties/signed.c
| ... | ... | @@ -55,13 +55,6 @@ |
| 55 | 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 | 58 | .name = "color_type", // Property name. |
| 66 | 59 | .description = N_( "The color type" ), // Property description. |
| 67 | 60 | .get = lib3270_get_color_type, // Get value. | ... | ... |
src/core/properties/string.c
| ... | ... | @@ -75,8 +75,8 @@ |
| 75 | 75 | { |
| 76 | 76 | .name = "model", // Property name. |
| 77 | 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 | 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 | 57 | const LIB3270_UINT_PROPERTY * lib3270_get_unsigned_properties_list(void) |
| 43 | 58 | { |
| 44 | 59 | |
| 45 | 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 | 368 | // Initialize toggles |
| 369 | 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 | 1324 | |
| 1325 | 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 | 60 | unsigned int (*get)(const H3270 *hSession); ///< @brief Get value. |
| 61 | 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 | 66 | } LIB3270_UINT_PROPERTY; |
| 64 | 67 | |
| 65 | 68 | typedef struct _lib3270_string_property |
| ... | ... | @@ -177,6 +180,16 @@ |
| 177 | 180 | */ |
| 178 | 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 | 193 | #ifdef __cplusplus |
| 181 | 194 | } |
| 182 | 195 | #endif | ... | ... |