Mercurial > hg
comparison mcabber/src/lang.c @ 24:e88b15cbf2de
[/trunk] Changeset 40 by mikael
* Change structure -> src directory for mcabber source code...
author | mikael |
---|---|
date | Sun, 27 Mar 2005 20:16:02 +0000 |
parents | |
children | 0cd8025eebee |
comparison
equal
deleted
inserted
replaced
23:d7107507424b | 24:e88b15cbf2de |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <unistd.h> | |
4 #include <string.h> | |
5 #include <ctype.h> | |
6 | |
7 | |
8 #include "utils.h" | |
9 | |
10 char Lang[100]; | |
11 | |
12 void lng_InitLanguage(void) | |
13 { | |
14 FILE *fp; | |
15 memset(Lang, 0, 100); | |
16 sprintf(Lang, "./lang/%s.txt", getenv("LANG")); | |
17 /* strcpy(Lang, "./lang/"); | |
18 strcat(Lang, getenv("LANG")); | |
19 strcat(Lang, ".txt"); | |
20 */ | |
21 if ((fp = fopen(Lang, "r")) == NULL) { | |
22 /* reverting to default */ | |
23 ut_WriteLog("Reverting language to default: POSIX\n"); | |
24 strcpy(Lang, "./lang/POSIX.txt"); | |
25 } else { | |
26 fclose(fp); | |
27 ut_WriteLog("Setting language to %s\n", getenv("LANG")); | |
28 } | |
29 } | |
30 | |
31 char *i18n(char *text) | |
32 { | |
33 /* hack */ | |
34 char *buf = (char *) malloc(1024); | |
35 static char result[1024]; | |
36 FILE *fp; | |
37 char *line; | |
38 char *value; | |
39 int found = 0; | |
40 | |
41 memset(result, 0, 1024); | |
42 | |
43 if ((fp = fopen(Lang, "r")) != NULL) { | |
44 while ((fgets(buf, 1024, fp) != NULL) && (!found)) { | |
45 line = buf; | |
46 | |
47 while (isspace((int) *line)) | |
48 line++; | |
49 | |
50 while ((strlen(line) > 0) | |
51 && isspace((int) line[strlen(line) - 1])) | |
52 line[strlen(line) - 1] = '\0'; | |
53 | |
54 if ((*line == '\n') || (*line == '\0') || (*line == '#')) | |
55 continue; | |
56 | |
57 if ((strchr(line, '=') != NULL)) { | |
58 value = strchr(line, '='); | |
59 *value = '\0'; | |
60 value++; | |
61 | |
62 while (isspace((int) *value)) | |
63 value++; | |
64 | |
65 while ((strlen(line) > 0) | |
66 && isspace((int) line[strlen(line) - 1])) | |
67 line[strlen(line) - 1] = '\0'; | |
68 | |
69 if (!strcasecmp(line, text)) { | |
70 strcpy(result, value); | |
71 found = 1; | |
72 } | |
73 continue; | |
74 } | |
75 /* fprintf(stderr, "CFG: orphaned line \"%s\"\n", line); */ | |
76 } | |
77 fclose(fp); | |
78 } | |
79 | |
80 if (!found) { | |
81 strcpy(result, text); | |
82 } | |
83 | |
84 free(buf); | |
85 return result; | |
86 } |