summaryrefslogtreecommitdiff
path: root/src/client/language.c
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-28 16:38:35 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-28 16:38:35 +0000
commit2d776fcd61be168e1ff0ff2e4a5e71835e7cea19 (patch)
tree7cf274897bf540d5332d446f583ffd066e4e2e1d /src/client/language.c
parentb877ae23ac5d380ab3aa48d7724045cf4883b186 (diff)
- prekopanie adresarovej struktury, prva cast
git-svn-id: http://opensvn.csie.org/tuxanci_ng@77 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/client/language.c')
-rw-r--r--src/client/language.c157
1 files changed, 157 insertions, 0 deletions
diff --git a/src/client/language.c b/src/client/language.c
new file mode 100644
index 0000000..5444253
--- /dev/null
+++ b/src/client/language.c
@@ -0,0 +1,157 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "base/main.h"
+#include "base/list.h"
+#include "base/homeDirector.h"
+#include "base/textFile.h"
+
+#include "client/configFile.h"
+#include "client/language.h"
+
+static textFile_t *languageFile;
+static char fontFile[STR_FILE_NAME_SIZE];
+static int fontSize;
+
+char* getHead(textFile_t *ts)
+{
+ int i;
+
+ for( i = 0 ; i < ts->text->count ; i++ )
+ {
+ char *line;
+ line = (char *) (ts->text->list[i]);
+
+ if( strncmp(line, "HEAD", 4) == 0 )
+ {
+ return line;
+ }
+ }
+
+ return NULL;
+}
+
+
+int initLanguage()
+{
+ textFile_t *languageTypeFile;
+ char path[STR_PATH_SIZE];
+ char *lang;
+ char *head;
+
+ sprintf(path, "%s/lang.conf", getHomeDirector());
+ printf("open %s\n", path);
+ languageTypeFile = loadTextFile(path);
+
+ if( languageTypeFile == NULL )
+ {
+ fprintf(stderr, "Don't load %s\n", path);
+ fprintf(stderr, "I create %s\n", path);
+
+ languageTypeFile = newTextFile(path);
+ addList(languageTypeFile->text, strdup("en") );
+ saveTextFile(languageTypeFile);
+ }
+
+ if( languageTypeFile == NULL )
+ {
+ fprintf(stderr, "Don't create %s\n", path);
+ return -1;
+ }
+
+ if( languageTypeFile->text->count == 0 )
+ {
+ fprintf(stderr, "File %s empty\n", path);
+ return -1;
+ }
+
+ lang = ((char *)languageTypeFile->text->list[0]);
+ printf("select lang %s\n", lang);
+
+ sprintf(path, PATH_LANG "%s.lang", lang);
+
+ destroyTextFile(languageTypeFile);
+
+ accessExistFile(path);
+ languageFile = loadTextFile(path);
+
+ if( languageFile == NULL )
+ {
+ fprintf(stderr, "Don't load %s\n", path);
+ return -1;
+ }
+
+ head = getHead(languageFile);
+
+ if( head != NULL )
+ {
+ char val[STR_SIZE];
+
+ if( getValue(head, "fontfile", val, STR_SIZE) == 0 )
+ {
+ strcpy(fontFile, val);
+ }
+ else
+ {
+ fprintf(stderr, "fontfile in lang file %s not found\n", path);
+ return -1;
+ }
+
+ if( getValue(head, "fontsize", val, STR_SIZE) == 0 )
+ {
+ fontSize = atoi(val);
+ }
+ else
+ {
+ fprintf(stderr, "fontsize in lang file %s not found\n", path);
+ return -1;
+ }
+ }
+ else
+ {
+ fprintf(stderr, "head in lang file %s not found\n", path);
+ return -1;
+ }
+
+ return 0;
+}
+
+char* getMyText(char *key)
+{
+ int i;
+ int len;
+
+ len = strlen(key);
+
+ for( i = 0 ; i < languageFile->text->count ; i++ )
+ {
+ char *line;
+ line = (char *) (languageFile->text->list[i]);
+
+ if( strncmp(key, line, len) == 0 )
+ {
+ return line+strlen(key)+1;
+ }
+ }
+
+ return NULL;
+}
+
+char* getLanguageFont()
+{
+ return fontFile;
+}
+
+int getLanguageSize()
+{
+ return fontSize;
+}
+
+void quitLanguage()
+{
+ destroyTextFile(languageFile);
+}
+