diff options
author | Simo Sorce <idra@samba.org> | 2002-07-29 07:57:48 +0000 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2002-07-29 07:57:48 +0000 |
commit | 9b031d83783d7211de8f6fa03232eec8e9fa39d2 (patch) | |
tree | 220bb5736e5db857a63f9310e86633406f0458c3 /source3/web | |
parent | 0872bc448686cad6e9e95d24fbf72fdad48ed5d3 (diff) | |
download | samba-9b031d83783d7211de8f6fa03232eec8e9fa39d2.tar.gz samba-9b031d83783d7211de8f6fa03232eec8e9fa39d2.tar.bz2 samba-9b031d83783d7211de8f6fa03232eec8e9fa39d2.zip |
people should be happier now.
changed strtof with sscanf to make things working on all platforms.
changed auto-made bubble sort for more efficient and clean qsort()
(This used to be commit 61294d74b20741d683b8955d75d44eef00f94a0e)
Diffstat (limited to 'source3/web')
-rw-r--r-- | source3/web/neg_lang.c | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index 72dd70fd98..da974f78a4 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -48,16 +48,30 @@ int web_open(const char *fname, int flags, mode_t mode) } +struct pri_list { + float pri; + char *string; +}; + +static int qsort_cmp_list(const void *x, const void *y) { + struct pri_list *a = (struct pri_list *)x; + struct pri_list *b = (struct pri_list *)y; + if (a->pri > b->pri) return -1; + if (a->pri == b->pri) return 0; + return 1; +} + /* choose from a list of languages. The list can be comma or space separated Keep choosing until we get a hit Changed to habdle priority -- Simo */ + void web_set_lang(const char *lang_string) { char **lang_list, **count; - float *pri; + struct pri_list *pl; int lang_num, i; /* build the lang list */ @@ -71,37 +85,33 @@ void web_set_lang(const char *lang_string) count++; lang_num++; } - pri = (float *)malloc(sizeof(float) * lang_num); + pl = (struct pri_list *)malloc(sizeof(struct pri_list) * lang_num); for (i = 0; i < lang_num; i++) { char *pri_code; if ((pri_code=strstr(lang_list[i], ";q="))) { *pri_code = '\0'; pri_code += 3; - pri[i] = strtof(pri_code, NULL); + sscanf(pri_code, "%f", &(pl[i].pri)); } else { - pri[i] = 1; + pl[i].pri = 1; } - if (i != 0) { - int l; - for (l = i; l > 0; l--) { - if (pri[l] > pri[l-1]) { - char *tempc; - int tempf; - tempc = lang_list[l]; - tempf = pri[l]; - lang_list[l] = lang_list[l-1]; - pri[i] = pri[l-1]; - lang_list[l-1] = tempc; - pri[l-1] = tempf; - } - } - } + pl[i].string = strdup(lang_list[i]); } + str_list_free(&lang_list); + + qsort(pl, lang_num, sizeof(struct pri_list), &qsort_cmp_list); - for (i = 0; i < lang_num; i++) { - if (lang_tdb_init(lang_list[i])) return; - } - /* it's not an error to not initialise - we just fall back to the default */ + + for (i = 0; i < lang_num; i++) { + if (lang_tdb_init(pl[i].string)) break; + } + + for (i = 0; i < lang_num; i++) { + SAFE_FREE(pl[i].string); + } + SAFE_FREE(pl); + + return; } |