2004-11-20 07:32:32 +00:00
|
|
|
static volatile const char *BOINCrcsid="$Id$";
|
2003-06-11 23:36:48 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2003-05-29 23:25:15 +00:00
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
2003-06-11 23:36:48 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2003-05-29 23:25:15 +00:00
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
2004-07-13 13:54:09 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2003-05-29 23:25:15 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2004-07-13 13:54:09 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2003-05-29 23:25:15 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|