예제 #1
0
static CMaterial *cmaterial( const aiMaterial *mat,CShader *shader ){
	CMaterial *cmat=new CMaterial;
	
	cmat->SetShader( shader );
	
	aiColor4D color;
	aiString path;

	if( aiGetMaterialTexture( mat,aiTextureType_DIFFUSE,0,&path,0,0,0,0,0 )==AI_SUCCESS ){
		cmat->SetTexture( "DiffuseMap",App.TextureUtil()->LoadTexture( cstring( path ) ) );
	}else if( aiGetMaterialColor( mat,AI_MATKEY_COLOR_DIFFUSE,&color )==AI_SUCCESS ){
		cmat->SetColor( "DiffuseColor",ccolor( color ) );
	}

	if( aiGetMaterialTexture( mat,aiTextureType_SPECULAR,0,&path,0,0,0,0,0 )==AI_SUCCESS ){
		cmat->SetTexture( "SpecularMap",App.TextureUtil()->LoadTexture( cstring( path ) ) );
	}else if( aiGetMaterialColor( mat,AI_MATKEY_COLOR_SPECULAR,&color )==AI_SUCCESS ){
		cmat->SetColor( "SpecularColor",ccolor( color ) );
	}
	
	if( aiGetMaterialTexture( mat,aiTextureType_EMISSIVE,0,&path,0,0,0,0,0 )==AI_SUCCESS ){
		cmat->SetTexture( "EmissiveMap",App.TextureUtil()->LoadTexture( cstring( path ) ) );
	}else if( aiGetMaterialColor( mat,AI_MATKEY_COLOR_EMISSIVE,&color )==AI_SUCCESS ){
		cmat->SetColor( "EmissiveColor",ccolor( color ) );
	}
	
	if( aiGetMaterialTexture( mat,aiTextureType_NORMALS,0,&path,0,0,0,0,0 )==AI_SUCCESS ){
		cmat->SetTexture( "NormalMap",App.TextureUtil()->LoadTexture( cstring( path ) ) );
	}

	return cmat;
}
예제 #2
0
    /// Returns current token in the input
    cstring     current_token()
    {
        if( eoi() )
            return cstring();

        return cstring( m_argv[m_curr_token], m_token_size );
    }
예제 #3
0
void	querywin::current(int mode, int doraise)
{
	if(mode)
	{
		queryframe->configure("-bg yellow");
		if(doraise)
		{
			tk->eval("wm deiconify " + cstring(path()));
			tk->eval("raise " + cstring(path()));
		}
	}
	else
		queryframe->configure("-bg grey");
}
예제 #4
0
channelwin::channelwin(char *p, char *opt): 
            toplevel(cstring(".channel") << _serial++, opt)
{
	sessionid = 0;
	cname = p;
	buildwindow(this);
}
예제 #5
0
파일: devsign.c 프로젝트: 8l/inferno
static Signerkey*
strtopk(char *buf)
{
	SigAlgVec *sa;
	char *p;
	Signerkey *key;

	key = malloc(sizeof(*key));
	if(key == nil)
		return nil;
	key->r.ref = 1;
	sa = cstrtoalg(buf, &p);
	if(sa == nil){
		free(key);
		return nil;
	}
	key->alg = sa;
	key->pkfree = sa->pkfree;
	key->owner = cstring(p, &p);
	if(key->owner == nil){
		free(key);
		return nil;
	}
	key->pk = (*sa->str2pk)(p, &p);
	if(key->pk == nil){
		free(key->owner);
		free(key);
		return nil;
	}
	return key;
}
예제 #6
0
void Tracing::end(const String& name)
{
    StringUTF8Adaptor utf8(name);
    // TRACE_EVENT_COPY_END0 needs a c-style null-terminated string.
    CString cstring(utf8.data(), utf8.length());
    TRACE_EVENT_COPY_END0("script", cstring.data());
}
예제 #7
0
파일: loadmod.c 프로젝트: manu321/LSE64
void loadmod(void) {
	int (*lse_mod_test)(void) ;
	char * modname = cstring(0,0);
        lt_dlhandle modp;

        // Initialize libtool
        lt_dlinit(); 
        // Add local modules to search path
        lt_dladdsearchdir("./modules/");

#ifdef PKGLIBDIR
        // Add global modules to search path
        lt_dladdsearchdir(PKGLIBDIR);
#endif
        // try to load the module
        modp = lt_dlopenext(modname);

        // If we fail, set the flag to 0 and exit
	flag = 0;
	if ( ! modp ) return;

        // Else make sure the module is sane
	if ( !(lse_mod_test = (int (*)(void)) lt_dlsym(modp, "lse_mod_test")) ) return;
        // If all is well, then the test value 
        // should return 1, so se the flag to this and 
	flag = lse_mod_test();
}
예제 #8
0
// ----------------------------------------------------------------------------
void CodeSnippetsConfig::SettingsLoad()
// ----------------------------------------------------------------------------
{
        // file will be saved in $HOME/codesnippets.ini


    #ifdef LOGGING
     wxString fn(__FUNCTION__, wxConvUTF8);
     LOGIT( _T("--- [%s] ---"),fn.c_str() );
     LOGIT(wxT("Loading Settings File[%s]"),SettingsSnippetsCfgPath.c_str());
    #endif //LOGGING

    wxFileConfig cfgFile(
                    wxEmptyString,              // appname
                    wxEmptyString,              // vendor
                    SettingsSnippetsCfgPath,// local filename
                    wxEmptyString,              // global file
                    wxCONFIG_USE_LOCAL_FILE);

	cfgFile.Read( wxT("ExternalEditor"),  &SettingsExternalEditor, wxEmptyString ) ;
	cfgFile.Read( wxT("SnippetFile"),     &SettingsSnippetsXmlPath, wxEmptyString ) ;
	cfgFile.Read( wxT("SnippetFolder"),   &SettingsSnippetsFolder, wxEmptyString ) ;
	cfgFile.Read( wxT("ViewSearchBox"),   &GetConfig()->SettingsSearchBox, true ) ;
	cfgFile.Read( wxT("casesensitive"),   &m_SearchConfig.caseSensitive, true ) ;
	int nScope;
	cfgFile.Read( wxT("scope"),             &nScope, SCOPE_BOTH ) ;
    m_SearchConfig.scope = (SearchScope)nScope;

    // read Editors Stay-On-Top of main window option
    cfgFile.Read( _T("EditorsStayOnTop"), &SettingsEditorsStayOnTop, true);
    // read Editors ToolTips option
    cfgFile.Read( _T("ToolTipsOption"), &SettingsToolTipsOption, true);

    // Read External App state. Launched App will see it as false because
    // plugin has not set it true yet, so if this is launched App, set it true
	cfgFile.Read( wxT("ExternalPersistentOpen"), &m_IsExternalPersistentOpen, false ) ;
	if ( IsApplication() ) SetExternalPersistentOpen(true);

    // read user specified window state (External, Floating, or Docked)
    cfgFile.Read( wxT("WindowState"), &m_SettingsWindowState, wxT("Floating") );
    #if defined(LOGGING)
     LOGIT( _T("WindowState[%s]"), GetSettingsWindowState().c_str() );
    #endif
    // read last window position
    wxString winPos;
    cfgFile.Read( wxT("WindowPosition"),  &winPos, wxEmptyString) ;
    if ( not winPos.IsEmpty() )
    {
        const wxWX2MBbuf buf = csU2C(winPos);
        std::string cstring( buf );
        std::stringstream istream(cstring);
        istream >> windowXpos ;
        istream >> windowYpos ;
        istream >> windowWidth ;
        istream >> windowHeight ;
    }
    else
    {
예제 #9
0
파일: json.cpp 프로젝트: ederollora/p4c
JsonObject* JsonObject::emplace(cstring label, IJson* value) {
    if (label.isNullOrEmpty())
        throw std::logic_error("Empty label");
    auto j = get(label);
    if (j != nullptr)
        throw std::logic_error(cstring("Duplicate label in json object ") + label.c_str());
    ordered_map<cstring, IJson*>::emplace(label, value);
    return this;
}
예제 #10
0
void Directory::Iterator::go(void) {
	errno = 0;
	while(true) {
		struct dirent *dirent = readdir((DIR *)dir);
		if(dirent) {
			if(cstring(dirent->d_name) != "." && cstring(dirent->d_name) != "..") {
				file = FileItem::get(path / dirent->d_name);
				return;
			}
		}
		else {
			if(errno)
				throw SystemException(errno, "file");
			else
				file = 0;
			break;
		}
	}
}
예제 #11
0
void WinPlaySound (CLEAN_STRING filename, OS ios, Bool *ook, OS *oos)
{
    char sys[64] = "paplay ";

    rprintf("WinPlaySound\n");

    strcat(sys, cstring(filename));
    strcat(sys, " &");

    system(sys);

    *ook = TRUE;
    *oos = ios;
}
예제 #12
0
//----------------------------------------------------------------------------------------
nsFileURL::nsFileURL(const nsString& inString, PRBool inCreateDirs)
//----------------------------------------------------------------------------------------
{
    NS_LossyConvertUCS2toASCII cstring(inString);
    if (!inString.Length())
        return;
    NS_ASSERTION(strstr(cstring.get(), kFileURLPrefix) == cstring.get(),
                 "Not a URL!");
    // Make canonical and absolute. Since it's a parameter to this constructor,
    // inString is escaped. We want to make an nsFilePath, which requires
    // an unescaped string.
    nsSimpleCharString unescapedPath(cstring.get() + kFileURLPrefixLength);
    unescapedPath.Unescape();
    nsFilePath path(unescapedPath, inCreateDirs);
    *this = path;
} // nsFileURL::nsFileURL
예제 #13
0
querywin::querywin(cstring p, cstring opt): 
	  targetif(targetif::query_target), 
          toplevel(cstring(".query") << _serial++, opt)

{
	sessionid = 0;
	serverentry = NULL;
	person = p;
	cstring dcc_status = tk->evaluate("dcc status " + p + " chat");
	if(dcc_status == "active")
		has_dcc = active;
	else
		has_dcc = none;
	use_dcc = false;
	build_querywindow(this);
	bindings();
	info = true;
}
예제 #14
0
const IR::Node* ReplaceStructs::postorder(IR::Member* expression) {
    // Find out if this applies to one of the parameters that are being replaced.
    const IR::Expression* e = expression;
    cstring prefix = "";
    while (auto mem = e->to<IR::Member>()) {
        e = mem->expr;
        prefix = cstring(".") + mem->member + prefix;
    }
    auto pe = e->to<IR::PathExpression>();
    if (pe == nullptr)
        return expression;
    // At this point we know that pe is an expression of the form
    // param.field1.etc.fieldN, where param has a type that needs to be replaced.
    auto decl = replacementMap->refMap->getDeclaration(pe->path, true);
    auto param = decl->to<IR::Parameter>();
    if (param == nullptr)
        return expression;
    auto repl = ::get(toReplace, param);
    if (repl == nullptr)
        return expression;
    auto newFieldName = ::get(repl->fieldNameRemap, prefix);
    const IR::Expression* result;
    if (newFieldName.isNullOrEmpty()) {
        auto type = replacementMap->typeMap->getType(getOriginal(), true);
        // This could be, for example, a method like setValid.
        if (!type->is<IR::Type_Struct>())
            return expression;
        if (getParent<IR::Member>() != nullptr)
            // We only want to process the outermost Member
            return expression;
        // Prefix is a reference to a field of the original struct whose
        // type is actually a struct itself.  We need to replace the field
        // with a struct initializer expression.  (This won't work if the
        // field is being used as a left-value.  Hopefully, all such uses
        // of a struct-valued field as a left-value have been already
        // replaced by the NestedStructs pass.)
        result = repl->explode(pe, prefix);
    } else {
        result = new IR::Member(pe, newFieldName);
    }
    LOG3("Replacing " << expression << " with " << result);
    return result;
}
boost::optional<cstring>
get_param_value( param_namespace const& where_from,
                 cstring                name_part1,
                 cstring                name_part2,
                 cstring                name_part3,
                 cstring                name_part4,
                 cstring                name_part5 )
{
    if( name_part2.is_empty() ) {
        boost::optional<cstring> res;

        BOOST_TEST_FOREACH( parameter const&, p, where_from ) {
            if( p.p_name == name_part1 ) {
                res = cstring( p.p_value );
                break;
            }
        }

        return res;
    }
예제 #16
0
inline bool
interpret_argument_value( cstring source, hexerboost::optional<std::list<T> >& res, int )
{
    BOOST_RT_PARAM_TRACE( "In interpret_argument_value<std::list<T>>" );

    res = std::list<T>();

    while( !source.is_empty() ) {
        // !! should we use token_iterator
        cstring::iterator single_value_end = std::find( source.begin(), source.end(), BOOST_RT_PARAM_LITERAL( ',' ) );

        hexerboost::optional<T> value;
        interpret_argument_value( cstring( source.begin(), single_value_end ), value, 0 );

        res->push_back( *value );

        source.trim_left( single_value_end + 1 );
    }

    return true;
}
예제 #17
0
파일: graphs.cpp 프로젝트: ederollora/p4c
boost::optional<Graphs::vertex_t> Graphs::merge_other_statements_into_vertex() {
    if (statementsStack.empty()) return boost::none;
    std::stringstream sstream;
    if (statementsStack.size() == 1) {
        statementsStack[0]->dbprint(sstream);
    } else if (statementsStack.size() == 2) {
        statementsStack[0]->dbprint(sstream);
        sstream << "\n";
        statementsStack[1]->dbprint(sstream);
    } else {
        statementsStack[0]->dbprint(sstream);
        sstream << "\n...\n";
        statementsStack.back()->dbprint(sstream);
    }
    auto v = add_vertex(cstring(sstream), VertexType::STATEMENTS);
    for (auto parent : parents)
        add_edge(parent.first, v, parent.second->label());
    parents = {{v, new EdgeUnconditional()}};
    statementsStack.clear();
    return v;
}
void NetworkDataProcessor::UpdateList(string ActiveClientList)
{
	std::string::iterator iter;
	NetworkDataProcessor::List.clear();
	string delimiter = "_";
	string name;
	size_t pos = 0;
	//char Username[20];
	CConnectionManager* client = CConnectionManager::GetClientInstance();
	while ((pos = ActiveClientList.find(delimiter)) != string::npos)
	{
		name = ActiveClientList.substr(0, pos);
		CString cstring(name.c_str());
		if (cstring!=client->ClientName)
		{
			//Here is my code for changing the usernames into a human readable code.
			for (iter = name.begin(); iter != name.end(); iter++)
			{
				if (iter == name.begin())
				{
					*iter = toupper(*iter);

				}
				if (*iter == '.')
				{
					*iter = ' ';
					iter++;
					*iter = toupper(*iter);
				}
			}
			CString cstr(name.c_str());
			NetworkDataProcessor::List.push_back(cstr);
		}
		
		ActiveClientList.erase(0, pos + delimiter.length());
	}
	
}
예제 #19
0
void trans_layer::timeout(trans_bucket* bucket, sip_trans* t)
{
    t->reset_all_timers();
    t->state = TS_TERMINATED;

    // send 408 to 'ua'
    sip_msg  msg;
    sip_msg* req = t->msg;

    msg.type = SIP_REPLY;
    msg.u.reply = new sip_reply();

    msg.u.reply->code = 408;
    msg.u.reply->reason = cstring("Timeout");

    msg.from = req->from;
    msg.to = req->to;
    msg.cseq = req->cseq;
    msg.callid = req->callid;

    ua->handle_sip_reply(&msg);

    bucket->remove_trans(t);
}
예제 #20
0
int parse_nameaddr_list(list<cstring>& nas, const char* c, int len)
{
    const char* end = c + len;
    const char* na_end = NULL;

    while(c < end) {

      const char* na_begin = c;
      int err = skip_2_next_nameaddr(c,na_end,end);
      if(err < 0){
	ERROR("While parsing nameaddr list ('%.*s')\n",len,na_begin);
	return -1;
      }

      if(na_end) {
	nas.push_back(cstring(na_begin, na_end-na_begin));
      }

      if(err == 0)
	break;
    }

    return 0;
}
예제 #21
0
 // Constructors
 explicit    char_parameter_t( char_type name ) : base( cstring( &name, 1 ) ) {}
예제 #22
0
 // Constructor
 explicit    delim_policy( ti_delimeter_type t = dt_char, cstring d = cstring() )
 : m_type( t )
 {
     set_delimeters( d );
 }
예제 #23
0
static int parse_sip_uri(sip_uri* uri, const char* beg, int len)
{
    enum {
	URI_USER=0, 
	URI_PW,
	URI_HOST,
	URI_PORT,
	URI_PNAME,
	URI_PVALUE,
	URI_HNAME,
	URI_HVALUE
    };

    int st  = URI_HOST;
    const char* c = beg;
    //int escaped = 0;

    cstring tmp1, tmp2;

    // Search for '@', so that we can decide
    // wether to start in URI_USER or URI_HOST state.
    // This is not very efficient, but it makes the 
    // parser much easier!

    for(;c!=beg+len;c++){
	// user part present in URI
	if(*c == '@') {
	    st = URI_USER;
	}
    }

    if(st == URI_USER) {
	uri->user.s = beg;
    }
    else {
	uri->host.s = beg;
    }

    c = beg;


    for(;c!=beg+len;c++){

	switch(*c){

	case HCOLON:
	    switch(st){

	    case URI_USER:
		uri->user.len = c - uri->user.s;
		if(!uri->user.len){
		    DBG("Password given for empty user!\n");
		    return MALFORMED_URI;
		}
		uri->passwd.s = c+1;
		st = URI_PW;
		break;

	    case URI_HOST:
		uri->host.len = c - uri->host.s;
		if(!uri->host.len){
		    DBG("Empty host part\n");
		    return MALFORMED_URI;
		}
		uri->port_str.s = c+1;
		st = URI_PORT;
		break;
	    }
	    break;

	case '@':
	    switch(st){

	    case URI_USER:
		uri->user.len = c - uri->user.s;
		st = URI_HOST;
		uri->host.set(c+1,0);
		break;

	    case URI_PW:
		uri->passwd.len = c - uri->passwd.s; 
		st = URI_HOST;
		uri->host.set(c+1,0);
		break;

	    default:
		DBG("Illegal char '@' in non-user part\n");
		return MALFORMED_URI;
		break;
	    }
	    break;

	case ';':
	    switch(st){
	    case URI_HOST:
		uri->host.len = c - uri->host.s;
		st = URI_PNAME;
		tmp1.set(c+1,0);
		break;

	    case URI_PORT:
		uri->port_str.len = c - uri->port_str.s;
		st = URI_PNAME;
		tmp1.set(c+1,0);
		break; 

	    case URI_PNAME:
		//DBG("Empty URI parameter\n");
		//return MALFORMED_URI;
		tmp1.len = c - tmp1.s;
		uri->params.push_back(new sip_avp(tmp1,cstring(0,0)));
		tmp1.s = c+1;
		break;

	    case URI_PVALUE:
		tmp2.len = c - tmp2.s;
		uri->params.push_back(new sip_avp(tmp1,tmp2));

		//DBG("uri param: \"%.*s\"=\"%.*s\"\n",
		//    tmp1.len, tmp1.s,
		//    tmp2.len, tmp2.s);

		tmp1.s = c+1;
		st = URI_PNAME;
		break;
	    }
	    break;

	case '?':
	    switch(st){

	    case URI_HOST:
		uri->host.len = c - uri->host.s;
		st = URI_HNAME;
		tmp1.s = c+1;
		break;

	    case URI_PORT:
		uri->port_str.len = c - uri->port_str.s;
		st = URI_HNAME;
		tmp1.s = c+1;
		break;

	    case URI_PNAME:
// 		DBG("Empty URI parameter\n");
// 		return MALFORMED_URI;
		tmp1.len = c - tmp1.s;
		uri->params.push_back(new sip_avp(tmp1,cstring(0,0)));
		tmp1.s = c+1;
		break;

	    case URI_PVALUE:
		tmp2.len = c - tmp2.s;
		uri->params.push_back(new sip_avp(tmp1,tmp2));

		//DBG("uri param: \"%.*s\"=\"%.*s\"\n",
		//    tmp1.len, tmp1.s,
		//    tmp2.len, tmp2.s);

		tmp1.s = c+1;
		st = URI_HNAME;
		break;
	    }
	    break;

	case '=':
	    switch(st){
	    case URI_PNAME:
	    case URI_HNAME:
		tmp1.len = c - tmp1.s;
		if(!tmp1.len){
		    DBG("Empty param/header name\n");
		    return MALFORMED_URI;
		}
		tmp2.s = c+1;
		st++;
		break;
	    }
	    break;

	case '&':
	    switch(st){
	    case URI_HNAME:
		DBG("Empty URI header\n");
		return MALFORMED_URI;

	    case URI_HVALUE:
		tmp2.len = c - tmp2.s;
		uri->hdrs.push_back(new sip_avp(tmp1,tmp2));

		//DBG("uri hdr: \"%.*s\"=\"%.*s\"\n",
		//    tmp1.len, tmp1.s,
		//    tmp2.len, tmp2.s);

		tmp1.s = c+1;
		st = URI_HNAME;
		break;
	    }
	    break;
	}
    }

    switch(st){

    case URI_USER:
    case URI_PW:
	DBG("Missing host part\n");
	return MALFORMED_URI;

    case URI_HOST:
	uri->host.len = c - uri->host.s;
	if(!uri->host.len){
	    DBG("Missing host part\n");
	    return MALFORMED_URI;
	}
	break;

    case URI_PORT:
	uri->port_str.len = c - uri->port_str.s; 
	break;

    case URI_PNAME:
	//DBG("Empty URI parameter\n");
	//return MALFORMED_URI;

	tmp1.len = c - tmp1.s;
	uri->params.push_back(new sip_avp(tmp1,cstring(0,0)));
	break;

    case URI_PVALUE:
	tmp2.len = c - tmp2.s;
	uri->params.push_back(new sip_avp(tmp1,tmp2));
	
	//DBG("uri param: \"%.*s\"=\"%.*s\"\n",
	//    tmp1.len, tmp1.s,
	//    tmp2.len, tmp2.s);
	break;
	
    case URI_HNAME:
	DBG("Empty URI header\n");
	return MALFORMED_URI;

    case URI_HVALUE:
	tmp2.len = c - tmp2.s;
	uri->hdrs.push_back(new sip_avp(tmp1,tmp2));
	
	//DBG("uri hdr: \"%.*s\"=\"%.*s\"\n",
	//    tmp1.len, tmp1.s,
	//    tmp2.len, tmp2.s);
	break;
    }

    if(uri->port_str.len){
	uri->port = 0;
	for(unsigned int i=0; i<uri->port_str.len; i++){
	    uri->port = uri->port*10 + (uri->port_str.s[i] - '0');
	}
    }
    else {
	uri->port = 5060;
    }

    DBG("Converted URI port (%.*s) to int (%i)\n",
	uri->port_str.len,uri->port_str.s,uri->port);

    return 0;
}
예제 #24
0
const IR::Node* DoMoveActionsToTables::postorder(IR::MethodCallStatement* statement) {
    auto mi = MethodInstance::resolve(statement, refMap, typeMap);
    if (!mi->is<ActionCall>())
        return statement;
    auto ac = mi->to<ActionCall>();

    auto action = ac->action;
    auto directionArgs = new IR::Vector<IR::Argument>();
    auto mc = statement->methodCall;

    // TODO: should use argument names
    auto it = action->parameters->parameters.begin();
    auto arg = mc->arguments->begin();
    for (; it != action->parameters->parameters.end(); ++it) {
        auto p = *it;
        if (p->direction == IR::Direction::None)
            break;
        directionArgs->push_back(*arg);
        ++arg;
    }

    // Action invocation
    BUG_CHECK(ac->expr->method->is<IR::PathExpression>(),
              "%1%: Expected a PathExpression", ac->expr->method);
    auto actionPath = new IR::PathExpression(IR::ID(mc->srcInfo, ac->action->name));
    auto call = new IR::MethodCallExpression(mc->srcInfo, actionPath,
                                             new IR::Vector<IR::Type>(), directionArgs);
    auto actinst = new IR::ActionListElement(statement->srcInfo, call);
    // Action list property
    auto actlist = new IR::ActionList({actinst});
    auto prop = new IR::Property(
        IR::ID(IR::TableProperties::actionsPropertyName, nullptr),
        actlist, false);
    // default action property
    auto otherArgs = new IR::Vector<IR::Argument>();
    for (; it != action->parameters->parameters.end(); ++it) {
        otherArgs->push_back(*arg);
        ++arg;
    }
    BUG_CHECK(arg == mc->arguments->end(), "%1%: mismatched arguments", mc);
    auto amce = new IR::MethodCallExpression(mc->srcInfo, mc->method, mc->typeArguments, otherArgs);
    auto defactval = new IR::ExpressionValue(amce);
    auto defprop = new IR::Property(
        IR::ID(IR::TableProperties::defaultActionPropertyName, nullptr),
        defactval, true);

    // List of table properties
    auto props = new IR::TableProperties({ prop, defprop });
    // Synthesize a new table
    cstring tblName = IR::ID(refMap->newName(cstring("tbl_") + ac->action->name.name), nullptr);

    auto annos = new IR::Annotations();
    annos->add(new IR::Annotation(IR::Annotation::hiddenAnnotation, {}));
    auto tbl = new IR::P4Table(tblName, annos, props);
    tables.push_back(tbl);

    // Table invocation statement
    auto tblpath = new IR::PathExpression(tblName);
    auto method = new IR::Member(tblpath, IR::IApply::applyMethodName);
    auto mce = new IR::MethodCallExpression(
        statement->srcInfo, method, new IR::Vector<IR::Type>(),
        new IR::Vector<IR::Argument>());
    auto stat = new IR::MethodCallStatement(mce->srcInfo, mce);
    return stat;
}
예제 #25
0
파일: genlib.c 프로젝트: Unidata/netcdf-c
/*
 * Generate C code for creating netCDF from in-memory structure.
 */
static void
gen_c(
     const char *filename)
{
    int idim, ivar, iatt, jatt, maxdims;
    int vector_atts;
    char *val_string;
    char stmnt[C_MAX_STMNT];

    /* wrap in main program */
    cline("#include <stdio.h>");
    cline("#include <stdlib.h>");
    cline("#include <netcdf.h>");
    cline("");
    cline("void");
    cline("check_err(const int stat, const int line, const char *file) {");
    cline("    if (stat != NC_NOERR) {");
    cline("	   (void) fprintf(stderr, \"line %d of %s: %s\\n\", line, file, nc_strerror(stat));");
    cline("        exit(1);");
    cline("    }");
    cline("}");
    cline("");
    cline("int");
    sprintf(stmnt, "main() {\t\t\t/* create %s */", filename);
    cline(stmnt);

    /* create necessary declarations */
    cline("");
    cline("   int  stat;\t\t\t/* return status */");
    cline("   int  ncid;\t\t\t/* netCDF id */");

    if (ndims > 0) {
	cline("");
	cline("   /* dimension ids */");
	for (idim = 0; idim < ndims; idim++) {
	    sprintf(stmnt, "   int %s_dim;", dims[idim].lname);
	    cline(stmnt);
	    }

	cline("");
	cline("   /* dimension lengths */");
	for (idim = 0; idim < ndims; idim++) {
	    if (dims[idim].size == NC_UNLIMITED) {
		sprintf(stmnt, "   size_t %s_len = NC_UNLIMITED;",
			dims[idim].lname);
	    } else {
		sprintf(stmnt, "   size_t %s_len = %lu;",
			dims[idim].lname,
			(unsigned long) dims[idim].size);
	    }
	    cline(stmnt);
	}
    }

    maxdims = 0;	/* most dimensions of any variable */
    for (ivar = 0; ivar < nvars; ivar++)
      if (vars[ivar].ndims > maxdims)
	maxdims = vars[ivar].ndims;

    if (nvars > 0) {
	cline("");
	cline("   /* variable ids */");
	for (ivar = 0; ivar < nvars; ivar++) {
	    sprintf(stmnt, "   int %s_id;", vars[ivar].lname);
	    cline(stmnt);
	}

	cline("");
	cline("   /* rank (number of dimensions) for each variable */");
	for (ivar = 0; ivar < nvars; ivar++) {
	    sprintf(stmnt, "#  define RANK_%s %d", vars[ivar].lname,
		    vars[ivar].ndims);
	    cline(stmnt);
	}
	if (maxdims > 0) {	/* we have dimensioned variables */
	    cline("");
	    cline("   /* variable shapes */");
	    for (ivar = 0; ivar < nvars; ivar++) {
		if (vars[ivar].ndims > 0) {
		    sprintf(stmnt, "   int %s_dims[RANK_%s];",
			    vars[ivar].lname, vars[ivar].lname);
		    cline(stmnt);
		}
	    }
	}
    }

    /* determine if we need any attribute vectors */
    vector_atts = 0;
    for (iatt = 0; iatt < natts; iatt++) {
	if (atts[iatt].type != NC_CHAR) {
	    vector_atts = 1;
	    break;
	}
    }
    if (vector_atts) {
	cline("");
	cline("   /* attribute vectors */");
	for (iatt = 0; iatt < natts; iatt++) {
	    if (atts[iatt].type != NC_CHAR) {
		sprintf(stmnt,
		    "   %s %s_%s[%lu];",
		    ncatype(atts[iatt].type),
		    atts[iatt].var == -1 ? "cdf" : vars[atts[iatt].var].lname,
		    atts[iatt].lname,
		    (unsigned long) atts[iatt].len);
		cline(stmnt);
	    }
	}
    }

    /* create netCDF file, uses NC_CLOBBER mode */
    cline("");
    cline("   /* enter define mode */");

    if (!cmode_modifier) {
	sprintf(stmnt,
		"   stat = nc_create(\"%s\", NC_CLOBBER, &ncid);",
		filename);
    } else if (cmode_modifier & NC_64BIT_OFFSET) {
	sprintf(stmnt,
		"   stat = nc_create(\"%s\", NC_CLOBBER|NC_64BIT_OFFSET, &ncid);",
		filename);
#ifdef USE_NETCDF4
    } else if (cmode_modifier & NC_CLASSIC_MODEL) {
	sprintf(stmnt,
		"   stat = nc_create(\"%s\", NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL, &ncid);",
		filename);
    } else if (cmode_modifier & NC_NETCDF4) {
	sprintf(stmnt,
		"   stat = nc_create(\"%s\", NC_CLOBBER|NC_NETCDF4, &ncid);",
		filename);
#endif
    } else {
       derror("unknown cmode modifier");
    }
    cline(stmnt);
    cline("   check_err(stat,__LINE__,__FILE__);");
    
    /* define dimensions from info in dims array */
    if (ndims > 0) {
	cline("");
	cline("   /* define dimensions */");
    }
    for (idim = 0; idim < ndims; idim++) {
	sprintf(stmnt,
		"   stat = nc_def_dim(ncid, \"%s\", %s_len, &%s_dim);",
		dims[idim].name, dims[idim].lname, dims[idim].lname);
	cline(stmnt);
	cline("   check_err(stat,__LINE__,__FILE__);");
    }

    /* define variables from info in vars array */
    if (nvars > 0) {
	cline("");
	cline("   /* define variables */");
	for (ivar = 0; ivar < nvars; ivar++) {
	    cline("");
	    for (idim = 0; idim < vars[ivar].ndims; idim++) {
		sprintf(stmnt,
			"   %s_dims[%d] = %s_dim;",
			vars[ivar].lname,
			idim,
			dims[vars[ivar].dims[idim]].lname);
		cline(stmnt);
	    }
	    if (vars[ivar].ndims > 0) {	/* a dimensioned variable */
		sprintf(stmnt,
			"   stat = nc_def_var(ncid, \"%s\", %s, RANK_%s, %s_dims, &%s_id);",
			vars[ivar].name,
			nctype(vars[ivar].type),
			vars[ivar].lname,
			vars[ivar].lname,
			vars[ivar].lname);
	    } else {		/* a scalar */
		sprintf(stmnt,
			"   stat = nc_def_var(ncid, \"%s\", %s, RANK_%s, 0, &%s_id);",
			vars[ivar].name,
			nctype(vars[ivar].type),
			vars[ivar].lname,
			vars[ivar].lname);
	    }
	    cline(stmnt);
	    cline("   check_err(stat,__LINE__,__FILE__);");
	}
    }
    
    /* define attributes from info in atts array */
    if (natts > 0) {
	cline("");
	cline("   /* assign attributes */");
	for (iatt = 0; iatt < natts; iatt++) {
	    if (atts[iatt].type == NC_CHAR) { /* string */
		val_string = cstrstr((char *) atts[iatt].val, atts[iatt].len);
		sprintf(stmnt,
			"   stat = nc_put_att_text(ncid, %s%s, \"%s\", %lu, %s);",
			atts[iatt].var == -1 ? "NC_GLOBAL" : vars[atts[iatt].var].lname,
			atts[iatt].var == -1 ? "" : "_id",
			atts[iatt].name,
			(unsigned long) atts[iatt].len,
			val_string);
		cline(stmnt);
		free (val_string);
	    }
	    else {			/* vector attribute */
		for (jatt = 0; jatt < atts[iatt].len ; jatt++) {
		    val_string = cstring(atts[iatt].type,atts[iatt].val,jatt);
		    sprintf(stmnt, "   %s_%s[%d] = %s;",
			    atts[iatt].var == -1 ? "cdf" : vars[atts[iatt].var].lname,
			    atts[iatt].lname,
			    jatt, 
			    val_string);
		    cline(stmnt);
		    free (val_string);
		}
		
		sprintf(stmnt,
			"   stat = nc_put_att_%s(ncid, %s%s, \"%s\", %s, %lu, %s_%s);",
			ncatype(atts[iatt].type),
			atts[iatt].var == -1 ? "NC_GLOBAL" : vars[atts[iatt].var].lname,
			atts[iatt].var == -1 ? "" : "_id",
			atts[iatt].name,
			nctype(atts[iatt].type),
			(unsigned long) atts[iatt].len,
			atts[iatt].var == -1 ? "cdf" : vars[atts[iatt].var].lname,
			atts[iatt].lname);
		cline(stmnt);
	    }
	    cline("   check_err(stat,__LINE__,__FILE__);");
	}
    }

    if (nofill_flag) {
        cline("   /* don't initialize variables with fill values */");
	cline("   stat = nc_set_fill(ncid, NC_NOFILL, 0);");
	cline("   check_err(stat,__LINE__,__FILE__);");
    }

    cline("");
    cline("   /* leave define mode */");
    cline("   stat = nc_enddef (ncid);");
    cline("   check_err(stat,__LINE__,__FILE__);");
}
예제 #26
0
파일: json.cpp 프로젝트: ederollora/p4c
cstring IJson::toString() const {
    std::stringstream str;
    serialize(str);
    return cstring(str.str());
}
예제 #27
0
void trans_layer::send_200_ack(sip_msg* reply, sip_trans* t)
{
    // Set request URI
    // TODO: use correct R-URI instead of just 'Contact'
    if(!get_contact(reply)) {
	DBG("Sorry, reply has no Contact header: could not send ACK\n");
	return;
    }
    
    sip_nameaddr na;
    const char* c = get_contact(reply)->value.s;
    if(parse_nameaddr(&na,&c,get_contact(reply)->value.len) < 0){
	DBG("Sorry, reply's Contact parsing failed: could not send ACK\n");
	return;
    }
    
    cstring r_uri = na.addr;
    list<sip_header*> route_hdrs;

    if(t && !t->msg->route.empty()){
	for(list<sip_header*>::iterator it = t->msg->route.begin();
	    it != t->msg->route.end(); ++it) {
	    
	    route_hdrs.push_back(new sip_header(0,"Route",(*it)->value));
	}
    }
    else {
	for(list<sip_header*>::reverse_iterator it = reply->record_route.rbegin();
	    it != reply->record_route.rend(); ++it) {
	    
	    route_hdrs.push_back(new sip_header(0,"Route",(*it)->value));
	}
    }

    sockaddr_storage remote_ip;
    set_next_hop(route_hdrs,r_uri,&remote_ip);

    int request_len = request_line_len(cstring("ACK",3),r_uri);
   
    char branch_buf[BRANCH_BUF_LEN];
    compute_branch(branch_buf,reply->callid->value,reply->cseq->value);
    cstring branch(branch_buf,BRANCH_BUF_LEN);

    sip_header* max_forward = new sip_header(0,cstring("Max-Forwards"),cstring("10"));

    cstring via((char*)transport->get_local_ip()); 

    request_len += via_len(via,branch);

    request_len += copy_hdrs_len(route_hdrs);

    request_len += copy_hdr_len(reply->to);
    request_len += copy_hdr_len(reply->from);
    request_len += copy_hdr_len(reply->callid);
    request_len += copy_hdr_len(max_forward);
    request_len += cseq_len(get_cseq(reply)->num_str,cstring("ACK",3));
    request_len += 2/* CRLF end-of-headers*/;

    // Allocate new message
    char* ack_buf = new char[request_len];

    // generate it
    char* msg = ack_buf;

    request_line_wr(&msg,cstring("ACK",3),r_uri);
    via_wr(&msg,via,branch);

    copy_hdrs_wr(&msg,route_hdrs);
    // clear route headers list
    for (list<sip_header*>::iterator it=route_hdrs.begin(); 
	 it!= route_hdrs.end(); it++)
	delete *it;
    
    copy_hdr_wr(&msg,reply->from);
    copy_hdr_wr(&msg,reply->to);
    copy_hdr_wr(&msg,reply->callid);
    copy_hdr_wr(&msg,max_forward);
    delete max_forward;
    cseq_wr(&msg,get_cseq(reply)->num_str,cstring("ACK",3));

    *msg++ = CR;
    *msg++ = LF;

    DBG("About to send 200 ACK\n");
    //    DBG("About to send 200 ACK: \n<%.*s>\n",request_len,ack_buf);

    assert(transport);
    int send_err = transport->send(&remote_ip,ack_buf,request_len);
    if(send_err < 0){
	ERROR("Error from transport layer\n");
	delete [] ack_buf;
    }
    else if(t){
	delete [] t->retr_buf;
	t->retr_buf = ack_buf;
	t->retr_len = request_len;
	memcpy(&t->retr_addr,&remote_ip,sizeof(sockaddr_storage));
    }
}
예제 #28
0
파일: json.cpp 프로젝트: ederollora/p4c
bool JsonValue::operator==(const char* s) const
{ return tag == Kind::String ? cstring(s) == str : false; }