4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
31 static struct locarr locarr = { 0, NULL };
33 static int add(const char *locstr, int length)
38 item = strndup(locstr, length);
40 for (i = 0 ; item[i] ; i++)
41 item[i] = tolower(item[i]);
42 for (i = 0 ; i < locarr.count ; i++)
43 if (!strcmp(item, locarr.arr[i])) {
48 ptr = realloc(locarr.arr, (1 + locarr.count) * sizeof(locarr.arr[0]));
51 locarr.arr[locarr.count++] = item;
63 free(locarr.arr[--locarr.count]);
66 int locales_add(const char *locstr)
68 const char *stop, *next;
70 stop = strchrnul(locstr, ',');
71 next = stop + !!*stop;
72 while (locstr != stop) {
73 if (add(locstr, stop - locstr))
75 do { stop--; } while(stop > locstr && *stop != '-');
82 int locales_score(const char *lang)
87 for (i = 0 ; i < locarr.count ; i++)
88 if (!strcasecmp(lang, locarr.arr[i]))
94 char *locales_locate_file(const char *filename)
100 for (i = 0 ; i < locarr.count ; i++) {
101 if (snprintf(path, sizeof path, "locales/%s/%s", locarr.arr[i], filename) >= (int)(sizeof path)) {
105 if (widget_has(path)) {
106 result = strdup(path);
112 if (widget_has(filename)) {
113 result = strdup(filename);