annotate mcabber/lang.c @ 0:b3b2332715fb

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