+/* 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 <http://www.gnu.org/licenses/>.
+ */
#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"
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);
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
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
}
} 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) {
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;
}
}