Example #1
0
int main(int argc, char **argv)
{
	if (argc != 4)
		PrintUsage();

	if (		!strcmp (argv[1],  "-h")
			||  !strcmp (argv[1],  "-help")
			||  !strcmp (argv[1],  "/h")
			||  !strcmp (argv[1],  "/help")
	)
		PrintUsage();
	string Action = argv[1];
	if	(		(Action != "ToTxt")  
			&&	(Action != "FromTxt")  
		)
		PrintUsage();

	string FileName = argv[2];
	CDictionary Dict;
	if (Action == "FromTxt")
	{
		if (access (FileName.c_str(), 04) != 0)
		{
			fprintf (stderr, "Cannot read %s\n",FileName.c_str());
			return 1;

		};
		if (!Dict.LoadOnlyConstants(argv[3]))
		{
			fprintf (stderr, "Cannot load an empty dictionary from %s\n",argv[3]);
			return 1;
		};
		Dict.m_bShouldSaveComments = true;

		string Messages;
		bool bResult = Dict.ImportFromText(FileName,false, iceSkip,1, Messages);
		fprintf (stderr, "%s", Messages.c_str() );
		if (bResult)
			if (Dict.Save())
				return  0;
		return 1;
	}
	else
	{
		if (!Dict.Load(argv[3]) || !Dict.ReadUnitComments())
		{
			fprintf (stderr, "Cannot load dictionary from %s\n",argv[3]);
			return 1;
		};
		FILE * fp = fopen (FileName.c_str(),"wb");
		if (!fp)
		{
			fprintf (stderr, "Cannot write to %s\n",FileName.c_str());
			return 1;
		};

		CTempArticle A;
		A.m_pRoss = &Dict;

		for (WORD i = 0;  i < Dict.m_Units.size(); i++)
		{ 
			fprintf (fp,"============\r\n");
			fprintf (fp,"%s", Dict.GetUnitTextHeader(i).c_str());
			try 
			{
				A.ReadFromDictionary(i, false, true);
				if (!A.ArticleToText())
				{
					fprintf (fp,"Error! Cannot get the entry No %i\r\n", i);
					return 1;
				};
				fprintf (fp,"%s",A.GetArticleStr().c_str());
			}
			catch (...)
			{
				fprintf (fp,"Error! Cannot get the entry No %i\r\n", i);
				return 1;
			}
			
		};
		fclose(fp);
		return 0;


	};

	
}
Example #2
0
void CViewport::LoadDictionary(void)
{
	CSV::CSVDocument doc;
	CSV::CSVDocument::row_index_type row_count;

	//Parse from the document

	try
	{
		row_count = doc.load_file("captionmod/dictionary.csv");
	}
	catch(std::exception &err)
	{
		Sys_ErrorEx("%s\n%s", "LoadDictionary: ", err.what());
	}

	if(row_count < 2)
		return;

	IScheme *ischeme = scheme()->GetIScheme(GetScheme());

	if(!ischeme)
		return;

	Color defaultColor = ischeme->GetColor("BaseText", Color(255, 255, 255, 200));
	
	//Initialize the dictionary hashtable
	m_StringsHashTable.SetSize(2048);

	for (int i = 0; i < m_StringsHashTable.Count(); i++)
		m_StringsHashTable[i].next = NULL;

	EmptyDictionaryHash();

	int nRowCount = row_count;
	
	//parse the dictionary line by line...
	for (int i = 1;i < nRowCount; ++i)
	{
		CSV::CSVDocument::row_type row = doc.get_row(i);

		if(row.size() < 1)
			continue;

		const char *title = row[0].c_str();

		if(!title || !title[0])
			continue;

		CDictionary *Dict = new CDictionary;

		Dict->Load(row, defaultColor, ischeme);

		m_Dictionary.AddToTail(Dict);

		AddDictionaryHash(Dict, Dict->m_szTitle);
	}

	//Link the dictionaries

	for(int i = 0; i < m_Dictionary.Count(); ++i)
	{
		CDictionary *Dict = m_Dictionary[i];
		if(Dict->m_szNext[0])
		{
			Dict->m_pNext = FindDictionary(Dict->m_szNext);
		}
	}
}