Exemple #1
0
char*
mu_str_process_query_term (const char *str)
{
	g_return_val_if_fail (str, NULL);

	return process_str (str, TRUE, TRUE);

}
// ---------------------------------------------------------------------------
// 
// -----------
bool bXMapStringProcessing::process(int msg, void* prm){
_bTrace_("bXMapStringProcessing::process()",true);	
	switch(msg){
        case kExtProcessCallFromIntf:
            process_str();
            break;
        case kExtProcessCallWithParams:
            process_str((strprocess_prm*)prm,true);
            break;
        case kExtProcessCallWithXMLTree:
            process_str(true);
            break;
        default:
            break;
	}
	return(true);
}
Exemple #3
0
char*
mu_str_process_text (const char *str)
{
	g_return_val_if_fail (str, NULL);

	return process_str (str, FALSE, FALSE);

}
// ---------------------------------------------------------------------------
//
// -----------
bool bXMapStringProcessing::process_str(){
bEventLog	log(_gapp,this);
    _gapp->layersMgr()->SetObjInvalidation(false);
    process_str(&_prm,false);
    _arr.reset();
    _gapp->layersMgr()->SetObjInvalidation(true);
    log.close();
    return(true);
}
Exemple #5
0
string Compiler::text()
{
    stringstream ss;
    ss << "Compiler {" << endl;
    ss << "  cmd = '" << cmd_ << "'," << endl;
    ss << "  inc = '" << inc_ << "'," << endl;
    ss << "  lib = '" << lib_ << "'," << endl;
    ss << "  flg = '" << flg_ << "'," << endl;
    ss << "  ext = '" << ext_ << "'," << endl;
    ss << "  process_str = '" << process_str("OBJ", "SRC") << "'" << endl;
    ss << "}";
    return ss.str();
}
Exemple #6
0
/**
 *  Compile the given sourcecode into a shared object.
 *
 *  @returns True the system compiler returns exit-code 0 and False othervise.
 */
bool Compiler::compile(string object_abspath, string src_abspath)
{
    string cmd = process_str(object_abspath, src_abspath);

    // Execute the process
    FILE *cmd_stdin = NULL;                     // Handle for library-file
    cmd_stdin = popen(cmd.c_str(), "w");        // Execute the command
    if (!cmd_stdin) {
        std::cout << "Err: Could not execute process! ["<< cmd <<"]" << std::endl;
        return false;
    }

    fflush(cmd_stdin);
    int exit_code = (pclose(cmd_stdin)/256);
    return (exit_code==0);
}
Exemple #7
0
//
// Main
//
int main(char *lol, char *outbuf) {
	int len;
	u8 membuf[0x1000];
	int membuf_len;
	int ret;

	//main_unpack42(test, test_len);
	//main_unpack(bigbuf, bigbuf_len);
	// exit(1);

	OUTPUT_LEN = 0;

	//init memory
	memset(bigbuf,0,sizeof(bigbuf));
	bigbuf_len = 0;

	// process strings of hex bytes
	process_str(lol);

	// main blob decoding
	len = main_unpack(bigbuf, bigbuf_len, outbuf);

	// decode 04-04 blob additionally
	ret = main_unpack_checkblob(bigbuf, bigbuf_len, 0x04, 0x04);
	if (ret == 1){
		main_unpack_getbuf(bigbuf, bigbuf_len, membuf, &membuf_len, 0x04, 0x04);
		if (membuf_len<=0) {
			OUTPUT_LEN+=sprintf(outbuf+OUTPUT_LEN,"unpack_getbuf size error\n");
		} else {
			OUTPUT_LEN+=sprintf(outbuf+OUTPUT_LEN,"===\n");
			OUTPUT_LEN+=sprintf(outbuf+OUTPUT_LEN,"\n");
			OUTPUT_LEN+=sprintf(outbuf+OUTPUT_LEN,"===\n");
			main_unpack(membuf, membuf_len, outbuf);
		};
	};

	len = OUTPUT_LEN;
	return len;
};
Exemple #8
0
/**
 *  Compile the given sourcecode into a shared object.
 *
 *  @returns True the system compiler returns exit-code 0 and False othervise.
 */
bool Compiler::compile(string object_abspath, const char* sourcecode, size_t source_len)
{
    string cmd = process_str(object_abspath, " - ");

    FILE* cmd_stdin = popen(cmd.c_str(), "w");  // Open process and get stdin stream
    if (!cmd_stdin) {
        perror("popen()");
        fprintf(stderr, "popen() failed for: [%s]", sourcecode);
        pclose(cmd_stdin);
        return false;
    }
                                                // Write / pipe to stdin
    int write_res = fwrite(sourcecode, sizeof(char), source_len, cmd_stdin);
    if (write_res < (int)source_len) {
        perror("fwrite()");
        fprintf(stderr, "fwrite() failed in file %s at line # %d\n", __FILE__, __LINE__-5);
        pclose(cmd_stdin);
        return false;
    }

    int flush_res = fflush(cmd_stdin);          // Flush stdin
    if (EOF == flush_res) {
        perror("fflush()");
        fprintf(stderr, "fflush() failed in file %s at line # %d\n", __FILE__, __LINE__-5);
        pclose(cmd_stdin);
        return false;
    }

    int exit_code = (pclose(cmd_stdin)/256);
    if (0!=exit_code) {
        perror("pclose()");
        fprintf(stderr, "pclose() failed.\n");
    }
    
    return (exit_code==0);
}
Exemple #9
0
/** process_str
  *
  * Unescapes and removes quotes from string (see lc3_parser.cpp if you change this)
  */
std::string process_str(wxString str, int& error)
{
    return process_str(str.ToStdString(), error);
}
Exemple #10
0
bool XmlTestParser::LoadTestOutput(lc3_test& test, wxXmlNode* root)
{
    wxXmlNode* child = root->GetChildren();
    int error = 0;

    while(child)
    {
        wxXmlNode* grandchild = child->GetChildren();
        lc3_test_output output;
        output.passed = false;
        output.points = 0;

        wxString points = child->GetAttribute("points", "0");
        wxString mode = child->GetAttribute("condition", "equals");
        output.points = wxAtoi(points);

        if (child->GetName() == "test-value")
        {
            if (grandchild->GetName() != "address") throw "address must come before value";
            output.address = grandchild->GetNodeContent();
            grandchild = getNextNode(grandchild);
            if (grandchild->GetName() != "value") throw "value tag not found";
            output.value = grandchild->GetNodeContent();

            output.type = TEST_VALUE;
        }
        else if (child->GetName() == "test-register")
        {
            if (grandchild->GetName() != "register") throw "register must come before value";
            output.address = grandchild->GetNodeContent();
            grandchild = getNextNode(grandchild);
            if (grandchild->GetName() != "value") throw "value tag not found";
            output.registerval = grandchild->GetNodeContent();

            output.type = TEST_REGISTER;
        }
        else if (child->GetName() == "test-pc")
        {
            if (grandchild->GetName() != "value") throw "value tag not found";
            output.pcval = grandchild->GetNodeContent();

            output.type = TEST_PC;
        }
        else if (child->GetName() == "test-pointer")
        {
            if (grandchild->GetName() != "address") throw "address must come before value";
            output.address = grandchild->GetNodeContent();
            grandchild = getNextNode(grandchild);
            if (grandchild->GetName() != "value") throw "value tag not found";
            output.pointer = grandchild->GetNodeContent();

            output.type = TEST_POINTER;
        }
        else if (child->GetName() == "test-string")
        {
            if (grandchild->GetName() != "address") throw "address must come before value";
            output.address = grandchild->GetNodeContent();
            grandchild = getNextNode(grandchild);
            if (grandchild->GetName() != "value") throw "value tag not found";
            output.text = process_str(grandchild->GetNodeContent(), error);
            if (error) throw "malformed string in test-string";

            output.type = TEST_STRING;
        }
        else if (child->GetName() == "test-array")
        {
            if (grandchild->GetName() != "address") throw "address must come before value";
            output.address = grandchild->GetNodeContent();
            grandchild = getNextNode(grandchild);
            if (grandchild->GetName() != "value") throw "value tag not found";
            std::string array = grandchild->GetNodeContent().ToStdString();
            tokenize(array, output.array, ",");

            output.type = TEST_ARRAY;
        }
        else if (child->GetName() == "test-stdout")
        {
            if (grandchild->GetName() != "value") throw "value tag not found";
            output.io = process_str(grandchild->GetNodeContent(), error);
            if (error) throw "malformed string in test-stdout";

            output.type = TEST_IO;
        }
        else if (child->GetName() != "comment")
        {
            return false;
        }
        else
        {
            child = getNextNode(child);
            continue;
        }

        output.cmp_type = GetCompareType(output.type, mode);

        test.output.push_back(output);

        child = getNextNode(child);
    }

    return true;
}
Exemple #11
0
bool XmlTestParser::LoadTestInput(lc3_test& test, wxXmlNode* root)
{
    wxXmlNode* child = root->GetChildren();
    int error = 0;

    while(child)
    {
        lc3_test_input input;
        wxXmlNode* grandchild = child->GetChildren();
        if (child->GetName() == "test-value")
        {
            if (grandchild->GetName() != "address") throw "address must come before value";
            input.address = grandchild->GetNodeContent();
            grandchild = getNextNode(grandchild);
            if (grandchild->GetName() != "value") throw "value tag not found";
            input.value = grandchild->GetNodeContent();

            input.type = TEST_VALUE;
        }
        else if (child->GetName() == "test-register")
        {
            if (grandchild->GetName() != "register") throw "register must come before value";
            input.address = grandchild->GetNodeContent();
            grandchild = getNextNode(grandchild);
            if (grandchild->GetName() != "value") throw "value tag not found";
            input.registerval = grandchild->GetNodeContent();

            input.type = TEST_REGISTER;
        }
        else if (child->GetName() == "test-pc")
        {
            if (grandchild->GetName() != "value") throw "value tag not found";
            input.pcval = grandchild->GetNodeContent();

            input.type = TEST_PC;
        }
        else if (child->GetName() == "test-pointer")
        {
            if (grandchild->GetName() != "address") throw "address must come before value";
            input.address = grandchild->GetNodeContent();
            grandchild = getNextNode(grandchild);
            if (grandchild->GetName() != "value") throw "value tag not found";
            input.pointer = grandchild->GetNodeContent();

            input.type = TEST_POINTER;
        }
        else if (child->GetName() == "test-string")
        {
            if (grandchild->GetName() != "address") throw "address must come before value";
            input.address = grandchild->GetNodeContent();
            grandchild = getNextNode(grandchild);
            if (grandchild->GetName() != "value") throw "value tag not found";
            input.text = process_str(grandchild->GetNodeContent(), error);
            if (error) throw "malformed string in test-string";

            input.type = TEST_STRING;
        }
        else if (child->GetName() == "test-array")
        {
            if (grandchild->GetName() != "address") throw "address must come before value";
            input.address = grandchild->GetNodeContent();
            grandchild = getNextNode(grandchild);
            if (grandchild->GetName() != "value") throw "value tag not found";
            std::string array = grandchild->GetNodeContent().ToStdString();
            tokenize(array, input.array, ",");

            input.type = TEST_ARRAY;
        }
        else if (child->GetName() == "test-stdin")
        {
            if (grandchild->GetName() != "value") throw "value tag not found";
            input.io = process_str(grandchild->GetNodeContent(), error);
            if (error) throw "malformed string in test-stdin";

            input.type = TEST_IO;
        }
        else if (child->GetName() != "comment")
        {
            return false;
        }
        else
        {
            child = getNextNode(child);
            continue;
        }

        test.input.push_back(input);

        child = getNextNode(child);
    }

    return true;
}
// ---------------------------------------------------------------------------
//
// -----------
bool bXMapStringProcessing::process_str(bool dummy){
_bTrace_("bXMapStringProcessing::process_str",true);
strprocess_prm			p;
bGenericXMLBaseElement*	elt;
bGenericXMLBaseElement*	cnt;
bGenericType*			tp;
int						idx;
char					value[_values_length_max_];
bArray					arr(sizeof(int));
    
    p.tp=SelectionIsMonoType(_gapp);
    if(p.tp==0){
_te_("bad selection");
        return(false);
    }
    
    tp=_gapp->typesMgr()->get(p.tp);
    p.arr=&arr;
    
// Fields
    cnt=getelement(1);
    if(!cnt){
_te_("no field container");
        return(false);
    }
    for(long i=1;i<=cnt->countelements();i++){
        elt=cnt->getelement(i);
        elt->getvalue(value);
        idx=tp->fields()->get_index(value);
        if(idx==0){
_te_("bad field "+value);
            return(false);
        }
        arr.add(&idx);
    }
    if(arr.count()==0){
_te_("no field");
        return(false);
    }
// Separator
    elt=getelement(2);
    if(!elt){
_te_("no separator");
        return(false);
    }
    elt->getvalue(p.sep);
// Case
    elt=getelement(3);
    if(!elt){
_te_("no case");
        return(false);
    }
    elt->getvalue(value);
    p.cas=atoi(value);
    if((p.cas<kStrProcessCaseDontChange)||(p.cas>kStrProcessCaseFWUpper)){
_te_("bad case "+p.cas);
        return(false);
    }
// Search
    elt=getelement(4);
    if(!elt){
_te_("no search");
        return(false);
    }
    elt->getvalue(p.srch);
char pat[4]={'<','>','&',0};
    
//    if(strcmp(pat,p.srch)==0){
//        strcpy(p.srch," ");
//    }
_tm_("tst :"+pat[0]+"="+(pat[0]/16)+(pat[0]%16));
_tm_("tst :"+pat[1]+"="+(pat[1]/16)+(pat[1]%16));
_tm_("tst :"+pat[2]+"="+(pat[2]/16)+(pat[2]%16));
    
_tm_("search string :"+p.srch);
// Replace
    elt=getelement(5);
    if(!elt){
_te_("no replacement");
        return(false);
    }
    elt->getvalue(p.repl);
//    if(strcmp(pat,p.repl)==0){
//        strcpy(p.repl," ");
//    }
_tm_("replacement string :"+p.repl);
// Format
    elt=getelement(6);
    if(!elt){
_te_("no format");
        return(false);
    }
    elt->getvalue(p.fmt);
// Fill field
    elt=getelement(7);
    if(!elt){
_te_("no target field");
        return(false);
    }
    elt->getvalue(value);
    p.target=tp->fields()->get_index(value);
    if(p.target==0){
_te_("bad target field "+value);
        return(false);
    }
    
    return(process_str(&p,true));
}