Index: apps/gui/gwps-common.c =================================================================== --- apps/gui/gwps-common.c (Revision 18378) +++ apps/gui/gwps-common.c (Arbeitskopie) @@ -761,6 +761,27 @@ return buf; } + +/* Writes the value of a zero based setting to two destinations: + 1. As a 1-based value (i.e. value+1) to (*dst_one_based) -- only + if the pointer is not NULL + 2. The string representation of the value (as is) to the string buffer + + Returns buf. + + The function can be used to output the values of some simple WPS tags, + e.g. %mm, %mp, etc. + */ +static char *write_int_setting_value(int setting_val_zero_based, int *dst_one_based, + char *buf, int buf_size) +{ + if (dst_one_based) + *dst_one_based = setting_val_zero_based + 1; + snprintf(buf, buf_size, "%d", setting_val_zero_based); + return buf; +} + + /* Return the tag found at index i and write its value in buf. The return value is buf if the tag had a value, or NULL if not. @@ -1136,15 +1157,13 @@ } case WPS_TOKEN_REPEAT_MODE: - if (intval) - *intval = global_settings.repeat_mode + 1; - snprintf(buf, buf_size, "%d", *intval); - return buf; + return write_int_setting_value(global_settings.repeat_mode, + intval, buf, buf_size); + case WPS_TOKEN_RTC_12HOUR_CFG: - if (intval) - *intval = global_settings.timeformat + 1; - snprintf(buf, buf_size, "%d", *intval); - return buf; + return write_int_setting_value(global_settings.timeformat, + intval, buf, buf_size); + #if CONFIG_RTC case WPS_TOKEN_RTC_DAY_OF_MONTH: /* d: day of month (01..31) */ @@ -1314,10 +1333,8 @@ #if (CONFIG_CODEC == SWCODEC) case WPS_TOKEN_CROSSFADE: - if (intval) - *intval = global_settings.crossfade + 1; - snprintf(buf, buf_size, "%d", global_settings.crossfade); - return buf; + return write_int_setting_value(global_settings.crossfade, + intval, buf, buf_size); case WPS_TOKEN_REPLAYGAIN: {