X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=blobdiff_plain;f=src%2Flang.c;h=7d1532bf424bd7003cca2560c4da19ef26e1f0c2;hp=924f4b73a4f2691596489987623636bdeb18bd86;hb=HEAD;hpb=f46c89cbc63e8c2c636b9310e1a5b7896693c5fb diff --git a/src/lang.c b/src/lang.c index 924f4b7..7d1532b 100644 --- a/src/lang.c +++ b/src/lang.c @@ -1,7 +1,25 @@ +/* lang.c - NeonServ v5.6 + * Copyright (C) 2011-2012 Philipp Kreil (pk910) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "lang.h" #include "UserNode.h" #include "DBHelper.h" #include "mysqlConn.h" +#include "tools.h" +#include "log.h" #define DEFAULT_LANG_TAG "EN" #define DEFAULT_LANG_NAME "English" @@ -37,7 +55,7 @@ static struct language* add_language(char *langtag, char *langname) { if(cindex == MAXLANGUAGES) return NULL; struct language *lang = malloc(sizeof(*lang)); if (!lang) { - perror("malloc() failed"); + printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__); return NULL; } lang->langtag = strdup(langtag); @@ -119,13 +137,21 @@ void register_default_language_table(const struct default_language_entry *msgtab void register_language_string(struct language *lang, char *ident, char *text) { int cindex = get_entry_index(ident); - struct language_table *lang_entry = malloc(sizeof(*lang_entry)); - if (!lang_entry) { - perror("malloc() failed"); - return; + struct language_table *lang_entry; + for(lang_entry = lang->entrys[cindex]; lang_entry; lang_entry = lang_entry->next) { + if(!strcmp(lang_entry->ident, ident)) break; } - - lang_entry->ident = strdup(ident); + if(!lang_entry) { + lang_entry = malloc(sizeof(*lang_entry)); + if (!lang_entry) { + printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__); + return; + } + lang_entry->ident = strdup(ident); + lang_entry->next = lang->entrys[cindex]; + lang->entrys[cindex] = lang_entry; + } else + free(lang_entry->text); //free old text (new one will be set below) //replace all: //$b to \002 //$k to \003 @@ -141,10 +167,13 @@ void register_language_string(struct language *lang, char *ident, char *text) { if(a) { switch(a[1]) { case 'b': - tmp[tmppos++] = '\002'; + tmp[tmppos++] = 2; break; case 'k': - tmp[tmppos++] = '\003'; + tmp[tmppos++] = 3; + break; + case 'u': + tmp[tmppos++] = 31; break; default: //unknown - just write it @@ -154,8 +183,6 @@ void register_language_string(struct language *lang, char *ident, char *text) { } } while(a); lang_entry->text = strdup(tmp); - lang_entry->next = lang->entrys[cindex]; - lang->entrys[cindex] = lang_entry; } char *get_language_string(struct UserNode *user, const char* msg_ident) { @@ -185,7 +212,7 @@ char *build_language_string(struct UserNode *user, char *buffer, const char *msg if(buffer == NULL) { buffer = (char *)malloc((MAXLEN+1) * sizeof(char)); if (!buffer) { - perror("malloc() failed"); + printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__); return NULL; } }