Exemplo n.º 1
0
///
/// Internal function to automaticaly free memory when seting to a
/// new value.
///
static int SetValueXML(char ** dest, const char * tag)
{
   char * val;
   val = xmlFile.getValue((char *)tag);
   if(val != NULL)
     {
	free(*dest);
	*dest = strdup(val);
     }
   return 0;
}
Exemplo n.º 2
0
///
/// The do all function for translation.
/// This automaticaly loads the correct language file on the first call.
/// The tag is the english string that is mangled to an xml tag that is
/// used to return the translated vr using the XmlParser class.
///
extern "C" char * ctrl_gettext(const char * tag)
{
   char * val;
   char * text;

   if(!loaded && loadok) // first call
     {
        LanguageXMLload();
     }
   if(!loadok) // failed first call
     {
#ifdef DEBUG
	printf("Not Loaded, TAG: %s\n", tag);
#endif
	return (char *)tag;
     }

   // Get the translation
   val = xmlFile.getValue((char *)textmangler(tag));
   if(val == NULL)
     {
#ifdef DEBUG
	printf("XML TAG <%s> Not Found!\n",textmangler(tag));
	printf("<%s>%s</%s>\n",textmangler(tag),tag,textmangler(tag));
#endif
	return (char *)tag;
     }
#ifdef DEBUG
   printf("TAG: %s VAL: %s\n", textmangler(tag), val);
#endif

   // allocate new memory and add to list
   text = strdup(val);
   AddText(text);

   return text;
}
Exemplo n.º 3
0
///
/// The *hack* to load the correct xml file.
/// This looks for the myserver.xml file and grabs the name of the
/// lanugage file.  Then it tries to load that file in the default
/// locations.
///
void LanguageXMLload()
{
   char languages_path[MAX_PATH];
   char language_file[MAX_PATH];
   char main_configuration_file[MAX_PATH];
   char * chrptr;
   XmlParser xmlFile;
   bool langFound = true;
   bool confFound = true;
   int ret;

   LanguageXMLinit();

   // Find the language files:
#ifdef WIN32
   strncpy(languages_path, "languages/", MAX_PATH);
#else
   if(FilesUtility::fileExists("languages"))
     {
	strncpy(languages_path, "languages/", MAX_PATH);
     }
   else
     {
# ifdef PREFIX
	snprintf(languages_path, MAX_PATH, "%s/share/myserver/languages/", PREFIX);
# else
	strncpy(languages_path, "/usr/share/myserver/languages/", MAX_PATH);
# endif
     }
   if(!(FilesUtility::fileExists(languages_path)))
     {
	loadok = false;
	langFound = false;
	return;
     }
#endif

   // Search for myserver.xml
   /* Under an *nix environment look for .xml files in the following order.
    * 1) myserver executable working directory
    * 2) ~/.myserver/
    * 3) /etc/myserver/
    */
#ifndef WIN32
   // just a little hack
   snprintf(main_configuration_file, MAX_PATH, "%s/.myserver/myserver.xml", getenv("HOME"));
#endif
   if(FilesUtility::fileExists("myserver.xml"))
     {
	strncpy(main_configuration_file,"myserver.xml", MAX_PATH);
     }
#ifndef WIN32
   else if(FilesUtility::fileExists(main_configuration_file))
     {
	// do nothing
     }
   else if(FilesUtility::fileExists("/etc/myserver/myserver.xml"))
     {
	strncpy(main_configuration_file,"/etc/myserver/myserver.xml", MAX_PATH);
     }
#endif
   else
     {
	confFound = false;
	loadok = false;
	return;
     }

   // Load the language file for configure
   if(confFound && langFound)
     {
	xmlFile.open(main_configuration_file);
	chrptr = xmlFile.getValue("LANGUAGE");
	if(chrptr != NULL)
	  snprintf(language_file, MAX_PATH, "%sconfigure/%s", languages_path, chrptr);
	xmlFile.close();
	ret = LanguageXMLfile(language_file);
	if(ret)
	  loadok = false;
     }

}