[PATCH v5 3/7] kernel32: Implement SetUserGeoName().
Alexandre Julliard
julliard at winehq.org
Wed Nov 13 13:12:04 CST 2019
João Diogo Ferreira <devilj at outlook.pt> writes:
> +static const struct geoinfo_t *get_geoinfoptr_by_str(const WCHAR *str, GEOTYPE geotype)
> +{
> + int num;
> +
> + if (!str)
> + return NULL;
> +
> + switch (geotype)
> + {
> + case GEO_ISO2:
> + for (int i = 0; i < ARRAY_SIZE(geoinfodata); i++)
> + if (!(strcmpW(geoinfodata[i].iso2W, str))) return &geoinfodata[i];
> + break;
> + case GEO_ISO_UN_NUMBER:
> + if (!(num = atoiW(str))) return NULL;
> + for (int i = 0; i < ARRAY_SIZE(geoinfodata); i++)
> + if (num == geoinfodata[i].uncode)
> + return geoinfodata[i].kind == LOCATION_REGION ? &geoinfodata[i] : NULL;
> + break;
> + }
> + return NULL;
> +}
> +
> +/******************************************************************************
> + * get_geoinfoptr_by_name
> + *
> + * Parse and fix a geoname and return a pointer
> + * to the matching geoinfo struct.
> + */
> +
> +static inline const struct geoinfo_t *get_geoinfoptr_by_name(const WCHAR *name)
> +{
> + WCHAR buffer[3];
> + int good = 0, len = 0;
> +
> + if (!name)
> + return NULL;
> +
> + /* Check if str is a two-letter country code (and make it uppercase) */
> + for (int i = 0; i <= 2; i++)
> + if ((name[i] <= 127 && isalphaW(name[i])))
> + {
> + buffer[i] = toupperW(name[i]);
> + good++;
> + }
> + else
> + {
> + if (!name[i])
> + {
> + buffer[i] = 0;
> + len = i;
> + }
> + break;
> + }
> +
> + if (good == 2 && len == 2)
> + return get_geoinfoptr_by_str(buffer, GEO_ISO2);
> +
> + /* Now check if it's a three-digit code. */
> + good = 0;
> + len = 0;
> +
> + for (int i = 0; i <= 3; i++)
> + if (isdigitW(name[i]))
> + good++;
> + else
> + {
> + if (!name[i])
> + len = i;
> + break;
> + }
> +
> + if (good == 3 && len == 3)
> + return get_geoinfoptr_by_str(name, GEO_ISO_UN_NUMBER);
> +
> + return NULL;
> +}
Please avoid C99 variable declarations in loops. Also this looks very
complicated for such a simple lookup.
--
Alexandre Julliard
julliard at winehq.org
More information about the wine-devel
mailing list