示例#1
0
void CSXParser::importCsx(std::string origCsxFilename, std::string tlCsxFilename, std::deque<std::string> utfFilenames) {
    std::cout << "Parsing CSX..." << std::endl;
    parseCsx(origCsxFilename);
    std::cout << "Extracting scenario..." << std::endl;
    image.extractStrings();
    std::cout << "Scenario has " << image.messages.size() << " messages and " << image.choices.size() << " choices." << std::endl;
    std::cout << "Parsing TXT files..." << std::endl;
    TxtParser txt;
    TxtParser::Stats totalStats;
    for (size_t i = 0; i < utfFilenames.size(); ++i) {
        TxtParser::Stats fileStats = txt.parseTxt(utfFilenames[i]);
        totalStats += fileStats;
        std::cout << "File " << utfFilenames[i] << ": " << fileStats << std::endl;
    }
    std::cout << "Total: " << totalStats << std::endl;
    std::cout << "Updating scenario..." << std::endl;
    image.substituteStrings(txt.messages, txt.choices);
    std::cout << "Updating short jump offsets..." << std::endl;
    image.updateShortHops();
    std::cout << "Updating long jump offsets..." << std::endl;
    function.updateOffsets(image.positionsComputer());
    std::cout << "Updating header..." << std::endl;
    updateHeader();
    std::cout << "Writing CSX file..." << std::endl;
    writeCsx(tlCsxFilename);
}
void LTransTextProcessor::on_submit_process(EventData * p_edata, EventEngine * p_caller)
{
    cout << "test2 in on_submit_process..." << endl;
    assert(p_edata && p_caller);

    //转换请求
    TextProcReq * p_req = dynamic_cast<TextProcReq*>(p_edata);

    if(!p_req)
    {
        lerr << "Convert to TextProcReq Failed." << endl;
        return;
    }

    if(p_req->GetTransType() != TRANS_TYPE_RTT)
    {
        lerr << "Local process can't accept a un rtt trans type." << endl;
        return;
    }

    TransText * p_text = p_req->GetTransText();

    assert(p_text);

    int result = SUCCESS;

    try
    {
        //Step 1 语种识别
        //DO NOTHING

        //Step 2 txt文本格式解析
        TxtParser txt;
        vector<string> para_vec;
        vector<pair<size_t,size_t> > pos_vec;

        if(false == txt.Parse(p_text->GetSrcData(), para_vec, pos_vec) )
        {
            lerr << "Txt Format parse Failed." << endl;
            result = ERR_PROC_TXT_FROMAT;
            throw -1;
        }

        p_text->SetFormatSrc(para_vec, pos_vec);

    }catch(...)
    {
    }

    //返回结果事件
    TextProcRes *p_proc_res = new TextProcRes(p_req->GetCallID(), p_text, result);
    Event re(p_proc_res, this);

    p_caller->PostEvent(re);

    return;
}
示例#3
0
// s might be modified in-place
bool MuiFromText(ParsedMui& res, const std::string_view& str) {
    TxtParser parser;
    parser.SetToParse(str);
    bool ok = ParseTxt(parser);
    if (!ok)
        return false;
    ParseMuiDefinition(GetRootArray(&parser), res);
    CrashIf(!ok);
    return ok;
}
示例#4
0
bool MuiFromText(char *s, ParsedMui& res)
{
    TxtParser parser;
    parser.SetToParse(s, str::Len(s));
    bool ok = ParseTxt(parser);
    if (!ok)
        return false;
    ParseMuiDefinition(GetRootArray(&parser), res);
    CrashIf(!ok);
    return ok;
}
示例#5
0
void CSXParser::exportCsx(std::string origCsxFilename, std::string utfFilename) {
    std::cout << "Parsing CSX..." << std::endl;
    parseCsx(origCsxFilename);
    std::cout << "Extracting scenario..." << std::endl;
    image.extractStrings();
    std::cout << "Scenario has " << image.messages.size() << " messages and " << image.choices.size() << " choices." << std::endl;
    std::cout << "Writing TXT file..." << std::endl;
    TxtParser txt;
    txt.messages.swap(image.messages);
    txt.choices.swap(image.choices);
    txt.writeTxt(utfFilename);
}
示例#6
0
// on_load_text_3
int TextHandler::build_base_source(const string & text, TransText & trans_text)
{
    string source_text = text;

    //1 编码识别和转换
    charset_handle(source_text);

    //2 文本格式解析,存入TransText
    trans_text.ResetSrcData(source_text);

    TxtParser txt;
    vector<string> para_vec;
    vector<pair<size_t,size_t> > pos_vec;

    if(false == txt.Parse(trans_text.GetSrcData(), para_vec, pos_vec) )
    {
        lerr << "Txt Format parse Failed." << endl;
        return ERR_PROC_TXT_FROMAT;
    }

    trans_text.SetFormatSrc(para_vec, pos_vec);

    //3 保存Base pos & Base source文件
    string pos_content;
    trans_text.GetFromat().Serialization(pos_content);

    string pos_file_path = m_default_file_path + trans_text.GetID() + BASE_TEXT_POS_POSTFIX;
    if(false == write_file(pos_file_path, pos_content.c_str(), pos_content.size()))
    {
        return ERR_SAVE_BASE_POS_FILE_FAIELD;
    }

    string source_file_path = m_default_file_path + trans_text.GetID() + BASE_TEXT_SOURCE_POSTFIX;
    if(false == write_file(source_file_path, source_text.c_str(), source_text.size()) )
    {
        return ERR_SAVE_BASE_SOURCE_FILE_FAILED;
    }

    return SUCCESS;
}
示例#7
0
文件: Quaddon.cpp 项目: dakyri/qua
Quaddon::Quaddon(char *path, image_id id, int n):
	Stackable(DefineSymbol(AddonName(id,n), S_QUADDON, 0,
					this, nullptr,
					REF_VALUE, ATTRIB_NONE, false, DISP_MODE_NOT))
{
	status_t	err;
	
	srcImage = id;
	srcIndex = n;
	
	fprintf(stderr, "addon %s, image %d, hook %d: name %s\n", path, id, n, sym->name);
	
	uint32	*addon_id_p;
	if ((err=get_image_symbol(
			id, "addon_id", B_SYMBOL_TYPE_DATA, (void**)&addon_id_p)) >= B_NO_ERROR) {
		subType = *addon_id_p;
	} else if ((err=get_image_symbol(
			id, "addon_id_array", B_SYMBOL_TYPE_DATA, (void**)&addon_id_p)) >= B_NO_ERROR) {
		subType = addon_id_p[n];
	} else {
		subType = 0;
	}
	
	char		**addon_formal_p;
	if ((err=get_image_symbol(
			id, "addon_params", B_SYMBOL_TYPE_DATA, (void **)&addon_formal_p)) >= B_NO_ERROR) {
		controlVariableDef = new char[strlen(*addon_formal_p)+1];
		strcpy(controlVariableDef, *addon_formal_p);
	} else if ((err=get_image_symbol(
			id, "addon_params_array", B_SYMBOL_TYPE_DATA, (void**)&addon_formal_p)) >= B_NO_ERROR) {
		controlVariableDef = new char[strlen(addon_formal_p[n])+1];
		strcpy(controlVariableDef, addon_formal_p[n]);
	} else {
		controlVariableDef = new char[strlen("()")+1];
		strcpy(controlVariableDef, "()");
	}

	InitFnPtr	*addon_init_array_p;
	if ((err=get_image_symbol(
			id, "init", B_SYMBOL_TYPE_TEXT, (void**)&init)) >= B_NO_ERROR) {
		;
	} else if ((err=get_image_symbol(
			id, "init_array", B_SYMBOL_TYPE_DATA, (void**)&addon_init_array_p)) >= B_NO_ERROR) {
		init = addon_init_array_p[n];
	} else {
		init = nullptr;
	}
	
	DisInitFnPtr	*addon_disinit_array_p;
	if ((err=get_image_symbol(
			id, "disinit", B_SYMBOL_TYPE_TEXT, (void**)&disInit)) >= B_NO_ERROR) {
		;
	} else if ((err=get_image_symbol(
			id, "disinit_array", B_SYMBOL_TYPE_DATA, (void**)&addon_disinit_array_p)) >= B_NO_ERROR) {
		disInit = addon_disinit_array_p[n];
	} else {
		disInit = nullptr;
	}
	
	ApplyFnPtr	*addon_apply_array_p;
	if ((err=get_image_symbol(
			id, "apply", B_SYMBOL_TYPE_TEXT, (void **)&apply)) >= B_NO_ERROR) {
		;
	} else if ((err=get_image_symbol(
			id, "apply_array", B_SYMBOL_TYPE_DATA, (void**)&addon_apply_array_p)) >= B_NO_ERROR) {
		apply = addon_apply_array_p[n];
	} else {
		apply = nullptr;
	}
	
	ResetFnPtr	*addon_reset_array_p;
	if ((err=get_image_symbol(
			id, "reset", B_SYMBOL_TYPE_TEXT, (void**)&reset)) >= B_NO_ERROR) {
		;
	} else if ((err=get_image_symbol(
			id, "reset_array", B_SYMBOL_TYPE_DATA, (void**)&addon_reset_array_p)) >= B_NO_ERROR) {
		reset = addon_reset_array_p[n];
	} else {
		reset = nullptr;
	}
	
	SetParamFnPtr	*addon_setp_array_p;
	if ((err=get_image_symbol(
			id, "set_parameters", B_SYMBOL_TYPE_TEXT, (void**)&setParameters)) >= B_NO_ERROR) {
		;
	} else if ((err=get_image_symbol(
			id, "set_parameters_array", B_SYMBOL_TYPE_DATA, (void**)&addon_setp_array_p)) >= B_NO_ERROR) {
		setParameters = addon_setp_array_p[n];
	} else {
		setParameters = nullptr;
	}
	
	// allocate a pointer on the stack for the cookie...
	cookieVar.Set(S_STRANGE_POINTER, REF_STACK, sym,
			(long)AllocStack(sym, S_STRANGE_POINTER, 1));

	TxtParser	*p = new TxtParser(controlVariableDef, path, nullptr);
	p->GetToken();
	p->ParseFormalsList(sym);
	next = nullptr;
}