00001 00006 #include <glib.h> 00007 #include <string.h> 00008 #include <stdio.h> 00019 char *** 00020 dict_get_words (const char *fn, const char *sep, int *wnum) 00021 { 00022 FILE *F = fopen (fn, "r"); 00023 char ***words = NULL, *line, *psz, **ws; 00024 int wn = 0, seplen = strlen (sep); 00025 *wnum = 0; 00026 if (F == NULL) 00027 return NULL; 00028 while (fscanf (F, "%a[^\n]\n", &line) != EOF) 00029 { 00030 if ((psz = strstr (line, sep)) != NULL) 00031 { 00032 *psz = 0; 00033 ws = (char **) malloc (2 * sizeof (char *)); 00034 ws[0] = g_locale_to_utf8(line, -1, NULL, NULL, NULL); 00035 ws[1] = g_locale_to_utf8(psz + seplen, -1, NULL, NULL, NULL); 00036 free(line); 00037 words = (char ***) realloc (words, ++wn * sizeof (char **)); 00038 words[wn - 1] = ws; 00039 } 00040 else 00041 free (line); 00042 } 00043 *wnum = wn; 00044 fclose (F); 00045 return (words); 00046 }