2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software 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 Lesser General Public License for more details.
|
2003-05-29 23:25:15 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2003-05-29 23:25:15 +00:00
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-16 23:29:48 +00:00
|
|
|
#include "boinc_win.h"
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <cstdlib>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2003-05-29 23:25:15 +00:00
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "parse.h"
|
|
|
|
|
|
|
|
#include "language.h"
|
|
|
|
|
|
|
|
LANGUAGE::LANGUAGE() {
|
2003-06-06 22:08:46 +00:00
|
|
|
language_file_contents = NULL;
|
2003-05-29 23:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LANGUAGE::~LANGUAGE() {
|
2003-06-06 22:08:46 +00:00
|
|
|
if (language_file_contents) free(language_file_contents);
|
|
|
|
language_file_contents = NULL;
|
2003-05-29 23:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int LANGUAGE::read_language_file(char *file_name) {
|
2003-06-06 22:08:46 +00:00
|
|
|
int retval;
|
2003-05-29 23:25:15 +00:00
|
|
|
|
2003-06-06 22:08:46 +00:00
|
|
|
// TODO: put in a size limitation here?
|
2004-07-13 13:54:09 +00:00
|
|
|
|
2003-06-06 22:08:46 +00:00
|
|
|
if (language_file_contents) free(language_file_contents);
|
|
|
|
language_file_contents = NULL;
|
2003-05-29 23:25:15 +00:00
|
|
|
|
2003-06-06 22:08:46 +00:00
|
|
|
retval = read_file_malloc(file_name, language_file_contents);
|
|
|
|
if (retval) return retval;
|
2003-05-29 23:25:15 +00:00
|
|
|
|
2003-06-06 22:08:46 +00:00
|
|
|
return 0;
|
2003-05-29 23:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int LANGUAGE::get_translation(char *section_name, char *entry_name,
|
2003-06-06 22:08:46 +00:00
|
|
|
char *translation, int trans_size) {
|
|
|
|
char buf[256], *sec_ptr, buf2[256];
|
2003-05-29 23:25:15 +00:00
|
|
|
|
2003-06-06 22:08:46 +00:00
|
|
|
// If we never opened the language file, return the default value
|
|
|
|
if (!language_file_contents) goto return_default;
|
2003-05-29 23:25:15 +00:00
|
|
|
|
2003-06-06 22:08:46 +00:00
|
|
|
// Find the specified section
|
|
|
|
sprintf(buf, "[%s]", section_name);
|
|
|
|
sec_ptr = strstr(language_file_contents,buf);
|
|
|
|
if (!sec_ptr) goto return_default;
|
2003-05-29 23:25:15 +00:00
|
|
|
|
2003-06-06 22:08:46 +00:00
|
|
|
// Find the translation in the section
|
|
|
|
// skip the header line
|
|
|
|
sec_ptr += strlen(buf);
|
|
|
|
sprintf(buf, "%s=", entry_name);
|
2003-05-29 23:25:15 +00:00
|
|
|
while (sgets(buf2, 256, sec_ptr)) {
|
|
|
|
if (!strncmp(buf, buf2, strlen(buf))) {
|
2003-06-06 22:08:46 +00:00
|
|
|
safe_strncpy(translation,buf2+strlen(buf),trans_size);
|
|
|
|
return trans_size;
|
2003-05-29 23:25:15 +00:00
|
|
|
} else if (!strncmp("[", buf2, 1)) {
|
2003-06-06 22:08:46 +00:00
|
|
|
goto return_default;
|
|
|
|
}
|
2003-05-29 23:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return_default:
|
2003-06-06 22:08:46 +00:00
|
|
|
safe_strncpy(translation,entry_name,trans_size);
|
|
|
|
return trans_size;
|
2003-05-29 23:51:52 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_c4c9d87372 = "$Id$";
|