#include "config.h"
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include "log.h"
#include "locales.h"
Go to the source code of this file.
Defines | |
#define | LOCALE_NAME_FILE "language.name" |
#define | LOCALE_LIB_DIR "/usr/lib/locale" |
Functions | |
static gint | compare_by_language_name (gconstpointer a, gconstpointer b) |
GSList * | locales_list_create () |
GSList * | locales_list_codes (GSList *locales_list) |
GSList * | locales_list_languages (GSList *locales_list) |
void | locales_list_print (GSList *locales_list) |
void | locales_list_free (GSList *locales_list) |
#define LOCALE_LIB_DIR "/usr/lib/locale" |
Definition at line 56 of file locales.c.
Referenced by locales_list_create().
#define LOCALE_NAME_FILE "language.name" |
Definition at line 55 of file locales.c.
Referenced by locales_list_create().
static gint compare_by_language_name | ( | gconstpointer | a, | |
gconstpointer | b | |||
) | [static] |
Definition at line 222 of file locales.c.
References localeEntry::language.
Referenced by locales_list_create().
00223 { 00224 localeEntry *aa = (localeEntry *)a; 00225 localeEntry *bb = (localeEntry *)b; 00226 // LOGPRINTF("sort: %s, %s", (gchar *) (aa->language),(gchar *) (bb->language)); 00227 return strcmp((gchar *) aa->language,(gchar *) bb->language); 00228 }
GSList* locales_list_codes | ( | GSList * | locales_list | ) |
Definition at line 146 of file locales.c.
References localeEntry::code, and LOGPRINTF.
Referenced by set_locale(), and update_installed_locales().
00147 { 00148 GSList *code_list = NULL; 00149 00150 LOGPRINTF("entry"); 00151 00152 while (locales_list != NULL) 00153 { 00154 localeEntry *locale = locales_list->data; 00155 code_list = g_slist_append(code_list, locale->code); 00156 locales_list = locales_list->next; 00157 } 00158 00159 return code_list; 00160 }
GSList* locales_list_create | ( | void | ) |
Definition at line 75 of file locales.c.
References localeEntry::code, compare_by_language_name(), ERRORPRINTF, localeEntry::language, LOCALE_LIB_DIR, LOCALE_NAME_FILE, and LOGPRINTF.
Referenced by set_locale(), and update_installed_locales().
00076 { 00077 DIR *dirp; 00078 struct dirent *dp; 00079 char language[64] = {0}; 00080 GSList *locales_list = NULL; 00081 char *langpath = NULL; 00082 FILE *langfile = NULL; 00083 localeEntry *locale = NULL; 00084 00085 LOGPRINTF("entry"); 00086 00087 // open locales directory 00088 dirp = opendir(LOCALE_LIB_DIR); 00089 if (dirp == NULL) 00090 { 00091 ERRORPRINTF("could not open directory '%s'", LOCALE_LIB_DIR); 00092 } 00093 00094 // scan directory and store its contents except "." and ".." 00095 while ((dp = readdir(dirp)) != NULL) 00096 { 00097 // exclude "." and ".." 00098 if ((dp->d_name[0] != '.' || (dp->d_name[1] != '\0' && 00099 (dp->d_name[1] != '.' || dp->d_name[2] != '\0')))) 00100 { 00101 // reset language name 00102 language[0]='\0'; 00103 00104 // open language name file 00105 langpath = g_strconcat(LOCALE_LIB_DIR, "/", dp->d_name, "/", LOCALE_NAME_FILE, NULL); 00106 langfile = fopen(langpath, "r"); 00107 if (langfile != NULL) 00108 { 00109 // read language name from file 00110 fgets(language, 63, langfile); 00111 fclose(langfile); 00112 } 00113 g_free(langpath); 00114 00115 // add locale to list 00116 locale = g_new0 (localeEntry, 1); 00117 locale->code = g_strdup(dp->d_name); 00118 if (strlen(language) > 0) 00119 { 00120 // found language name, remove trailing linefeed 00121 if (language[strlen(language)-1] == '\n') 00122 { 00123 language[strlen(language)-1]='\0'; 00124 } 00125 locale->language = g_strdup(language); 00126 } 00127 else 00128 { 00129 // no native name found, store locale code 00130 locale->language = g_strdup(dp->d_name); 00131 } 00132 00133 locales_list = g_slist_prepend(locales_list, locale); 00134 } 00135 } 00136 closedir(dirp); 00137 00138 // sort locales by language name 00139 locales_list = g_slist_sort(locales_list, compare_by_language_name); 00140 00141 return locales_list; 00142 }
void locales_list_free | ( | GSList * | locales_list | ) |
Definition at line 199 of file locales.c.
References localeEntry::code, localeEntry::language, and LOGPRINTF.
Referenced by set_locale(), and update_installed_locales().
00200 { 00201 LOGPRINTF("entry"); 00202 00203 g_return_if_fail(locales_list != NULL); 00204 00205 while (locales_list != NULL) 00206 { 00207 localeEntry *locale = locales_list->data; 00208 00209 // free 00210 g_free(locale->code); 00211 g_free(locale->language); 00212 g_free(locale); 00213 00214 locales_list =locales_list->next; 00215 } 00216 00217 g_slist_free(locales_list); 00218 locales_list = NULL; 00219 }
GSList* locales_list_languages | ( | GSList * | locales_list | ) |
Definition at line 163 of file locales.c.
References localeEntry::language, and LOGPRINTF.
Referenced by update_installed_locales().
00164 { 00165 GSList *lang_list = NULL; 00166 00167 LOGPRINTF("entry"); 00168 00169 while (locales_list != NULL) 00170 { 00171 localeEntry *locale = locales_list->data; 00172 lang_list = g_slist_append(lang_list, locale->language); 00173 locales_list = locales_list->next; 00174 } 00175 00176 return lang_list; 00177 }
void locales_list_print | ( | GSList * | locales_list | ) |
Definition at line 180 of file locales.c.
References localeEntry::code, ERRORPRINTF, localeEntry::language, and LOGPRINTF.
00181 { 00182 LOGPRINTF("entry"); 00183 00184 while (locales_list != NULL) 00185 { 00186 #if (ERROR_ON) 00187 localeEntry *locale = locales_list->data; 00188 00189 ERRORPRINTF("code: %s, language: %s", 00190 (char*) locale->code, 00191 (char*) locale->language); 00192 #endif 00193 00194 locales_list = locales_list->next; 00195 } 00196 }