Exemplo n.º 1
0
bool Channel::_UpdateStringInDB(const std::string& colName, const std::string& colValue) const
{
    // Prevent SQL-injection
    std::string _name(m_name);
    std::string _colValue(colValue);
    CharacterDatabase.EscapeString(_colValue);
    CharacterDatabase.EscapeString(_name);
    return CharacterDatabase.PExecute("UPDATE channels SET %s = '%s' WHERE m_name = '%s' AND m_team = '%u'",
        colName.c_str(), _colValue.c_str(), _name.c_str(), m_Team);
}
Exemplo n.º 2
0
//simplification
void Context::simplify (bool create)
{
    logger.debug() << "simplifying definitions" |0;
    Logging::IndentBlock block;

    m_simple.clear();
    m_names.clear();
    for (def_iter i=def_begin(); i!=def_end(); ++i) {
        _name(i->first, i->second);
    }
}
Exemplo n.º 3
0
static Imlib_Image
imlib2_load_image (url u) {
  url name= resolve (u);
  if (is_none (name))
    name= resolve ("$TEXMACS_PIXMAP_PATH/TeXmacs-gnu.xpm");
  Imlib_Image image;
  {
    c_string _name (as_string (name));
    image = IMLIB2_load_image (_name);
  }
  return image;
}
Exemplo n.º 4
0
bool Context::operator() (VarHdl name, ExprHdl meaning)
{
    //prevent multiple definition
    if (m_defs.find(&*name) != m_defs.end()) {
        logger.error() << name << " is already defined" |0;
        return false;
    }

    _define(name,meaning);
    _name(name,meaning);
    return true;
}
Exemplo n.º 5
0
BOOL CTag_Ape::SetComment(const char *name,const char *value)
{
	m_bHasApetag = TRUE;
	m_comments.erase(name);
	if(strlen(value) == 0)
	{
		return TRUE;	// 空はセットしない
	}
	CString _name(name);
//	_name.MakeUpper();
	m_comments.insert(pair<CString,CString>(_name,CString(value)));
	
	return TRUE;
}
Exemplo n.º 6
0
char* _std _splitfname(const char *fname, char *dir, char *name) {
   if (!fname || !name&&!dir) return 0;
   spstr _dir, _name;
   splitfname(fname, _dir, _name);
   if (dir) {
      strncpy(dir, _dir(), _MAX_PATH);
      dir[_MAX_PATH-1] = 0;
   }
   if (name) {
      strncpy(name, _name(), _MAX_PATH);
      name[_MAX_PATH-1] = 0;
      return name;
   } else
      return dir;
}
Exemplo n.º 7
0
bool BundleCompiler::compile(const char* type, const char* name, const char* platform)
{
	StringId64 _type(type);
	StringId64 _name(name);

	TempAllocator512 alloc;
	DynamicString path(alloc);
	TempAllocator512 alloc2;
	DynamicString src_path(alloc2);

	src_path += name;
	src_path += ".";
	src_path += type;

	char res_name[1 + 2*StringId64::STRING_LENGTH];
	_type.to_string(res_name);
	res_name[16] = '-';
	_name.to_string(res_name + 17);

	path::join(CROWN_DATA_DIRECTORY, res_name, path);

	CE_LOGI("%s <= %s.%s", res_name, name, type);

	bool success = true;
	jmp_buf buf;

	Buffer output(default_allocator());
	array::reserve(output, 4*1024*1024);

	if (!setjmp(buf))
	{
		CompileOptions opts(_source_fs, output, platform, &buf);
		compile(_type, src_path.c_str(), opts);
		File* outf = _bundle_fs.open(path.c_str(), FileOpenMode::WRITE);
		u32 size = array::size(output);
		u32 written = outf->write(array::begin(output), size);
		_bundle_fs.close(*outf);
		success = size == written;
	}
	else
	{
		success = false;
	}

	return success;
}
Exemplo n.º 8
0
void
Test::seedStocks(vector<O_Stock>& stocks)
{
    string testDB("graham_test");
    cout << "\n Switching to TEST DB--------------------" << endl;

    if (DBFace::instance()->switchDB( testDB ) )
        cout << "Switch to TEST db succeccful" << endl;
    // Ensure we switched to test DB
    bool rok(false);
    rok = db_setup();
    if(!rok)
    {
        LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)."
                  << "EXITING";
        cout << "An error uccored. exiting";
        exit(-1);
    }

    T_Stock ts;
    for(auto it = stocks.begin(); it != stocks.end();++it)
    {
        if ( ts.select( ts._ticker() == it->_ticker()).empty() )
        {
            O_Stock stock;            
            stock._ticker() = it->_ticker();
            stock._cik() = it->_cik();
            stock._fiscal_year_end() = it->_fiscal_year_end();
            stock._country() = it->_country();
            stock._listed() = it->_listed();
            stock._company_type() = it->_company_type();
            stock._name() = it->_name();
            stock.insert();
            LOG_INFO << "Seeded " <<stock._ticker() << " to TEST DB\n";
            cout << "Seeded " <<stock._ticker() << " to TEST DB\n";
        }else{
            LOG_INFO <<it->_ticker() << "Already in TEST DB\n";
            O_Stock stock = ts.select( ts._ticker() == it->_ticker()).front();
            stock._country() = it->_country();
            stock._listed() = it->_listed();
            stock._company_type() = it->_company_type();
            stock.update();
            cout <<it->_ticker() << "Already in TEST DB - UPDATED"<<endl;
        }
    }
}
Exemplo n.º 9
0
void TiXmlElement::SetAttribute(const char * cname, const char * cvalue) {

	TIXML_STRING _name(cname);
	TIXML_STRING _value(cvalue);

	TiXmlAttribute* node = attributeSet.Find(_name);
	if (node) {
		node->SetValue(_value);
		return;
	}

	TiXmlAttribute* attrib = new TiXmlAttribute(cname, cvalue);
	if (attrib) {
		attributeSet.Add(attrib);
	} else {
		TiXmlDocument* document = GetDocument();
		if (document) document->SetError(TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN);
	}
}
Exemplo n.º 10
0
void init_city_roles()
{
  for (int i = 0; i < CITY_ROLE_MAX; i++) {
    City_role_data[i] = new City_role_datum;
  }
  int cur_id = 0;

  _role(CITY_ROLE_NULL);
    _name("none");
    _food_percentage(100);

  _role(CITY_ROLE_FARMING);
    _name("farming");
    _skill(SKILL_FARMING, 3);
    _food_percentage(125);

  _role(CITY_ROLE_HUNTING);
    _name("hunting");
    _skill(SKILL_HUNTING, 2); // We're forgiving!
    _food_percentage(120);

  _role(CITY_ROLE_LIVESTOCK);
    _name("livestock");
    _skill(SKILL_LIVESTOCK, 3);
    _food_percentage(120);

  _role(CITY_ROLE_MINING);
    _name("mining");
    _skill(SKILL_MINING, 3);
    _resource_export(RES_STONE);
    _mineral_export(MINERAL_TIN);
    _mineral_export(MINERAL_COPPER);
    _mineral_export(MINERAL_IRON);
    _mineral_export(MINERAL_COAL);

  _role(CITY_ROLE_LOGGING);
    _name("logging");
    _skill(SKILL_FORESTRY, 2);
    _resource_export(RES_WOOD);
}
Exemplo n.º 11
0
void VarDeclaration::codegen(Ir* p)
{
    Logger::print("VarDeclaration::codegen(): %s | %s\n", toChars(), type->toChars());
    LOG_SCOPE;

    if (type->ty == Terror)
    {   error("had semantic errors when compiling");
        return;
    }

    // just forward aliases
    if (aliassym)
    {
        Logger::println("alias sym");
        toAlias()->codegen(p);
        return;
    }

    // output the parent aggregate first
    if (AggregateDeclaration* ad = isMember())
        ad->codegen(p);

    // global variable
    // taken from dmd2/structs
    if (isDataseg() || (storage_class & (STCconst | STCimmutable) && init))
    {
        Logger::println("data segment");

    #if 0 // TODO:
        assert(!(storage_class & STCmanifest) &&
            "manifest constant being codegen'd!");
    #endif

        // don't duplicate work
        if (this->ir.resolved) return;
        this->ir.resolved = true;
        this->ir.declared = true;

        this->ir.irGlobal = new IrGlobal(this);

        Logger::println("parent: %s (%s)", parent->toChars(), parent->kind());

        // not sure why this is only needed for d2
        bool _isconst = isConst() && init;

        Logger::println("Creating global variable");

        assert(!ir.initialized);
        ir.initialized = gIR->dmodule;
        std::string _name(mangle());

        LLType *_type = DtoConstInitializerType(type, init);

        // create the global variable
#if LDC_LLVM_VER >= 302
        // FIXME: clang uses a command line option for the thread model
        LLGlobalVariable* gvar = new LLGlobalVariable(*gIR->module, _type, _isconst,
                                                      DtoLinkage(this), NULL, _name, 0,
                                                      isThreadlocal() ? LLGlobalVariable::GeneralDynamicTLSModel
                                                                      : LLGlobalVariable::NotThreadLocal);
#else
        LLGlobalVariable* gvar = new LLGlobalVariable(*gIR->module, _type, _isconst,
                                                      DtoLinkage(this), NULL, _name, 0, isThreadlocal());
#endif
        this->ir.irGlobal->value = gvar;

        // Set the alignment (it is important not to use type->alignsize because
        // VarDeclarations can have an align() attribute independent of the type
        // as well).
        if (alignment != STRUCTALIGN_DEFAULT)
            gvar->setAlignment(alignment);

        if (Logger::enabled())
            Logger::cout() << *gvar << '\n';

        // if this global is used from a nested function, this is necessary or
        // optimization could potentially remove the global (if it's the only use)
        if (nakedUse)
            gIR->usedArray.push_back(DtoBitCast(gvar, getVoidPtrType()));

        // assign the initializer
        if (!(storage_class & STCextern) && mustDefineSymbol(this))
        {
            if (Logger::enabled())
            {
                Logger::println("setting initializer");
                Logger::cout() << "global: " << *gvar << '\n';
    #if 0
                Logger::cout() << "init:   " << *initVal << '\n';
    #endif
            }
            // build the initializer
            LLConstant *initVal = DtoConstInitializer(loc, type, init);

            // set the initializer
            assert(!ir.irGlobal->constInit);
            ir.irGlobal->constInit = initVal;
            gvar->setInitializer(initVal);

            // do debug info
            DtoDwarfGlobalVariable(gvar, this);
        }
    }
}
Exemplo n.º 12
0
Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team)
 : m_name(name), m_announce(true), m_moderate(false), m_channelId(channel_id), m_ownerGUID(0), m_password(""), m_flags(0), m_Team(Team)
{
    // set special flags if built-in channel
    ChatChannelsEntry const* ch = GetChannelEntryFor(channel_id);
    if (ch)                                                  // it's built-in channel
    {
        channel_id = ch->ChannelID;                         // built-in channel
        m_announce = false;                                 // no join/leave announces

        m_flags |= CHANNEL_FLAG_GENERAL;                    // for all built-in channels

        if (ch->flags & CHANNEL_DBC_FLAG_TRADE)              // for trade channel
            m_flags |= CHANNEL_FLAG_TRADE;

        if (ch->flags & CHANNEL_DBC_FLAG_CITY_ONLY2)         // for city only channels
            m_flags |= CHANNEL_FLAG_CITY;

        if (ch->flags & CHANNEL_DBC_FLAG_LFG)                // for LFG channel
            m_flags |= CHANNEL_FLAG_LFG;
        else                                                // for all other channels
            m_flags |= CHANNEL_FLAG_NOT_LFG;
        m_IsSaved = false;
    }
    else                                                    // it's custom channel
    {
        m_flags |= CHANNEL_FLAG_CUSTOM;
        //load not built in channel if saved
        std::string _name(name);
        CharacterDatabase.escape_string(_name);
        QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT m_announce, m_moderate, m_public, m_password, BannedList FROM channels WHERE m_name = '%s' AND m_team = '%u'", _name.c_str(), m_Team);
        if (result)//load
        {
            Field *fields = result->Fetch();
            m_announce = fields[0].GetBool();
            m_moderate = fields[1].GetBool();
            m_public = fields[2].GetBool();
            m_password  = fields[3].GetString();
            const char* db_BannedList = fields[4].GetString();

            m_IsSaved = true;

            if (db_BannedList)
            {
                Tokens tokens = StrSplit(db_BannedList, " ");
                Tokens::iterator iter;
                for (iter = tokens.begin(); iter != tokens.end(); ++iter)
                {
                    uint64 banned_guid = atol((*iter).c_str());
                    if (banned_guid)
                    {
                        sLog.outDebug("Channel(%s) loaded banned guid: %u",name.c_str(), banned_guid);
                        banned.insert(banned_guid);
                    }
                }
            }
        }
        else // save
        {
            // _name is already escaped at this point.
            if (CharacterDatabase.PExecute("INSERT INTO channels (m_name, m_team, m_announce, m_moderate, m_public, m_password) "
                "VALUES ('%s', '%u', '1', '0', '1', '')", _name.c_str(), m_Team))
            {
                sLog.outDebug("New Channel(%s) saved", name.c_str());
                m_IsSaved = true;
            }
        }
    }
}
Exemplo n.º 13
0
void init_building_data()
{
  for (int i = 0; i < BUILD_MAX; i++) {
    Building_data[i] = new Building_datum;
    Building_data[i]->uid = i;
  }

  int cur_id;

  _build(BUILD_PARK);
    _name("park");
    _cost(RES_GOLD, 300);
    _build_time(3);
    _destroy_cost(20);
    _upkeep(4);
    _base_morale(3);
    _description("\
A park is a well-groomed area of nature, with carefully designed paths and \
seating areas.\
");

  _build(BUILD_PLAZA);
    _name("plaza");
    _cost(RES_GOLD,  500);
    _cost(RES_STONE, 500);
    _build_time(5);
    _destroy_cost(150);
    _upkeep(4);
    _base_morale(1);
    _description("\
A plaza is an urban area that combines the pleasant environment and seating \
and strolling areas of a <link=park>park</link>, with the \
<link=building>business</link> space of a <link=marketplace>marketplace</link>.\
");

  _build(BUILD_MARKETPLACE);
    _name("marketplace");
    _cost(RES_GOLD,   800);
    _cost(RES_STONE, 1500);
    _build_time(7);
    _destroy_cost(350);
    _upkeep(2);
    _description("\
A marketplace is an area designed purely for business, with lots of space for \
<link=building>buildings</link> of various natures.\
");

  _build(BUILD_HOVEL);
    _name("hovels");
    _plural();
    _cost(RES_GOLD, 300);
    _cost(RES_WOOD, 300);
    _build_time(3);
    _destroy_cost(250);
    _upkeep(5);
    _housing(CIT_PEASANT, 100);
    _description("\
Hovels are simple homes, sacrificing comfort and style to be a purely \
utilitarian living space for <link=peasants>peasants</link>.\
");

  _build(BUILD_HOUSE);
    _name("houses");
    _plural();
    _cost(RES_GOLD, 800);
    _cost(RES_WOOD, 500);
    _build_time(10);
    _destroy_cost(600);
    _upkeep(10);
    _housing(CIT_MERCHANT, 100);
    _description("\
Houses are respectable homes with a moderate degree of comfort, suitable for \
the <link=merchants>middle classes</link>.\
");

  _build(BUILD_MANOR);
    _name("manor");
    _cost(RES_GOLD,  1200);
    _cost(RES_WOOD,   500);
    _cost(RES_STONE, 1000);
    _build_time(30);
    _destroy_cost(1250);
    _upkeep(20);
    _housing(CIT_BURGHER, 50);
    _description("\
A manor is a large, well-furnished home.  Its high degree of comfort and low-\
density quarters are ideal for the <link=burghers>upper class</link>.\
");

  _build(BUILD_KEEP);
    _name("keep");
    _cost(RES_GOLD,  3000);
    _cost(RES_STONE, 4000);
    _build_time(90);
    _destroy_cost(2500);
    _upkeep(30);
    _housing(CIT_BURGHER,   5);
    _housing(CIT_MERCHANT, 50);
    _housing(CIT_PEASANT, 100);
    _description("\
A keep is the center of any city.  It provides a home for the \
<link=nobles>nobility</link> as well as space for some <link=citizens>citizens\
</link>.  It also has space to support several <link=building>businesses\
</link>.\
");

  _build(BUILD_FARM);
    _name("farm");
    _cost(RES_GOLD, 250);
    _build_time(1);
    _destroy_cost(50);
    _upkeep(1);
    _jobs(CIT_PEASANT, 15);
    _wages(1);
    _produces(RES_FARMING, 1);
    _description("\
A farm is a tilled piece of land designed for growing <link=crop>crops</link>.\
");

  _build(BUILD_HUNTING_CAMP);
    _name("hunting camp");
    _cost(RES_GOLD, 200);
    _build_time(1);
    _destroy_cost(100);
    _upkeep(3);
    _jobs(CIT_PEASANT, 10);
    _wages(1);
    _produces(RES_HUNTING, 1);
    _description("\
A hunting camp is a base of operations for <link=hunting>hunters</link>, \
allowing them to catch <link=animals>game</link> in the land upon which it is \
built.\
");

  _build(BUILD_MINE);
    _name("mine");
    _cost(RES_GOLD, 500);
    _cost(RES_WOOD, 400);
    _build_time(10);
    _destroy_cost(1500);
    _upkeep(8);
    _jobs(CIT_PEASANT, 8);
    _wages(2);
    _produces(RES_MINING, 5);
    _description("\
A mine is set of several shafts dug into the land, allowing <link=mining>miners\
</link> to pull <link=minerals>minerals</link> from the ground.\
");

  _build(BUILD_SAWMILL);
    _name("sawmill");
    _forbidden(RACE_ELF);
    _cost(RES_GOLD,  200);
    _cost(RES_STONE, 350);
    _build_time(5);
    _destroy_cost(350);
    _upkeep(3);
    _jobs(CIT_PEASANT, 6);
    _wages(1);
    _produces(RES_LOGGING, 5);
    _description("\
A sawmill is a site for the processing of <link=logging>logging</link> \
operations.  It should be built on a <link=city map tile>map tile</link> that \
has <link=trees>trees</link> growing on it; it will remove the trees and turn \
them into <link=wood>wood</link> for use.  Once the trees are cleared, the \
sawmill will automatically close.\
");

  _build(BUILD_PASTURE);
    _name("pasture");
    _cost(RES_GOLD, 100);
    _cost(RES_WOOD, 100);
    _build_time(1);
    _destroy_cost(20);
    _upkeep(1);
    _livestock(500);
    _description("\
A pasture is a fenced-in area used for keeping <link=livestock>livestock\
</link>.  The terrain it is built upon does not matter.\
");

  _build(BUILD_BARRACKS);
    _name("barracks");
    _plural();
    _cost(RES_GOLD, 800);
    _cost(RES_WOOD, 650);
    _build_time(14);
    _destroy_cost(800);
    _upkeep(15);
    _military(50);
    _description("\
Barracks are a space for the housing and training of <link=army>military units\
</link>.\
");

  _build(BUILD_MASONRY);
    _category(BUILDCAT_MANUFACTURING);
    _name("masonry");
    _cost(RES_GOLD, 250);
    _cost(RES_WOOD, 600);
    _build_time(5);
    _upkeep(3);
    _jobs(CIT_PEASANT, 3);
    _wages(1);
    _recipe(RES_STONE, 1);
      _units_per_day(3);
      _max_deficit(0);
      _uses_mineral(MINERAL_STONE, 1);
    _description("\
A masonry is a <link=building>building</link> where uncut <link=stone>stone\
</link> is cut into useful blocks.\
");

  _build(BUILD_SMELTERY);
    _category(BUILDCAT_MANUFACTURING);
    _name("smeltery");
    _cost(RES_GOLD,   500);
    _cost(RES_STONE, 1000);
    _build_time(6);
    _unlock(CITY_ACHIEVE_ORES, 0, 0);
    _jobs(CIT_PEASANT, 10);
    _wages(2);
    _recipe(RES_TIN, 1);
      _recipe_name("Smelt tin (burn wood)");
      _units_per_day(1);
      _max_deficit(0);
      _uses_mineral(MINERAL_TIN, 1);
      _uses_resource(RES_WOOD, 3);
    _recipe(RES_TIN, 3);
      _recipe_name("Smelt tin (burn coal)");
      _units_per_day(3);
      _max_deficit(0);
      _uses_mineral(MINERAL_TIN, 3);
      _uses_mineral(MINERAL_COAL, 1);
    _recipe(RES_COPPER, 1);
      _recipe_name("Smelt copper (burn wood)");
      _units_per_day(1);
      _max_deficit(0);
      _uses_mineral(MINERAL_COPPER, 1);
      _uses_resource(RES_WOOD, 3);
    _recipe(RES_COPPER, 3);
      _recipe_name("Smelt copper (burn coal)");
      _units_per_day(3);
      _max_deficit(0);
      _uses_mineral(MINERAL_COPPER, 3);
      _uses_mineral(MINERAL_COAL, 1);
    _recipe(RES_IRON, 1);
      _recipe_name("Smelt iron (burn wood)");
      _days_per_unit(2);
      _max_deficit(0);
      _uses_mineral(MINERAL_IRON, 1);
      _uses_resource(RES_WOOD, 3);
    _recipe(RES_IRON, 3);
      _recipe_name("Smelt iron (burn coal)");
      _units_per_day(2);
      _max_deficit(0);
      _uses_mineral(MINERAL_IRON, 3);
      _uses_mineral(MINERAL_COAL, 1);
    _description("\
A smeltery is a high-temperature furnace used to melt metals out of the \
<link=minerals>ores</link> they naturally appear in.  These ores are virtually \
useless before smelting; thus a smeltery is a vital addition to any mining \
operation.  It is possible to smelt ores using <link=wood>wood</link> as a \
fuel; however, it is much faster and more efficient to burn <link=coal>coal\
</link> if it is available.\
");

  _build(BUILD_MINT);
    _category(BUILDCAT_MANUFACTURING);
    _name("mint");
    _cost(RES_GOLD,   500);
    _cost(RES_STONE, 1000);
    _cost(RES_IRON,   200);
    _build_time(6);
    _unlock( CITY_ACHIEVE_POP, CIT_MERCHANT, 1 );
    _upkeep(6);
    _jobs(CIT_MERCHANT, 3);
    _wages(4);
    _recipe(RES_GOLD, 1);
      _recipe_name("Gold (burn wood)");
      _units_per_day(3);
      _max_deficit(0);
      _uses_mineral(MINERAL_GOLD, 1);
      _uses_resource(RES_WOOD, 3);
    _recipe(RES_GOLD, 3);
      _recipe_name("Gold (burn coal)");
      _units_per_day(3);
      _max_deficit(0);
      _uses_mineral(MINERAL_GOLD, 3);
      _uses_mineral(MINERAL_COAL, 1);
    _description("\
A mint is a <link=building>building</link> where raw <link=gold>gold</link> \
ore can be forged into spendable coins and bars.  Doing so requires a fuel \
source; <link=wood>wood</link> can be used, but <link=coal>coal</link> is more \
Exemplo n.º 14
0
tree
sql_exec (url db_name, string cmd) {
  if (!sqlite3_initialized)
    tm_sqlite3_initialize ();
  if (sqlite3_error) {
    cout << "TeXmacs] ERROR: SQLite support not properly configured.\n";
    return tree (TUPLE);
  }
  string name= concretize (db_name);
  if (!sqlite3_connections->contains (name)) {
    c_string _name (name);
    sqlite3* db= NULL;
    //cout << "Opening " << _name << "\n";
    int status= SQLITE3_open (_name, &db);
    if (status == SQLITE_OK)
      sqlite3_connections (name) = (void*) db;
  }
  if (!sqlite3_connections->contains (name)) {
    cout << "TeXmacs] SQL error: database " << name << " could not be opened\n";
    return tree (TUPLE);
  }
  tree ret (TUPLE);
  sqlite3* db= (sqlite3*) sqlite3_connections [name];
  c_string _cmd (sql_escape (cmd));
  char** tab;
  int rows, cols;
  char* err;
  //cout << "Executing " << _cmd << "\n";
  int status= SQLITE3_get_table (db, _cmd, &tab, &rows, &cols, &err);

  int attempt= 0;
  while (status != SQLITE_OK &&
         string (err) == string ("database is locked") &&
         attempt < 100) {
    usleep (100000);
    attempt++;
    status= SQLITE3_get_table (db, _cmd, &tab, &rows, &cols, &err);
  }

  if (status != SQLITE_OK) {
    // TODO: improve error handling
    cout << "TeXmacs] SQL error\n";
    if (err != NULL) cout << "TeXmacs] " << err << "\n";
  }

  for (int r=0; r<=rows; r++) {
    tree row (TUPLE);
    //cout << "  Row " << r << LF;
    for (int c=0; c<cols; c++) {
      int i= r*cols + c;
      if (tab[i] == NULL) row << tree (TUPLE);
      else {
        row << tree (scm_quote (sql_unescape (tab[i])));
        //cout << "    Column " << c << ": " << tab[i] << LF;
      }
    }
    ret << row;
  }

  SQLITE3_free_table (tab);
  //cout << "Return " << ret << "\n";
  return ret;
}
Exemplo n.º 15
0
struct inode *namepi(char *path, char *name)
{
    return _name(path, 1, name);
}
void GpuProgramManager::compileShaders(GpuProgramRefArray p_Refs,
                                       bool p_ForceRecompile,
                                       bool p_UpdateResources)
{
  _INTR_LOG_INFO("Loading/Compiling GPU Programs...");

  GpuProgramRefArray changedGpuPrograms;

  for (uint32_t gpIdx = 0u; gpIdx < p_Refs.size(); ++gpIdx)
  {
    GpuProgramRef ref = p_Refs[gpIdx];
    const _INTR_STRING gpuProgramName =
        "gpu_program_" + StringUtil::toString(_name(ref)._hash);

    SpirvBuffer& spirvBuffer = _spirvBuffer(ref);
    spirvBuffer.clear();

    EShLanguage stage = Helper::mapGpuProgramTypeToEshLang(
        (GpuProgramType::Enum)_descGpuProgramType(ref));
    glslang::TShader shader(stage);
    glslang::TProgram program;

    const EShMessages messages =
        (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules);

    const _INTR_STRING& fileName = _descGpuProgramName(ref);
    _INTR_STRING filePath = _shaderPath + fileName;

    _INTR_FSTREAM inFileStream =
        _INTR_FSTREAM(filePath.c_str(), std::ios::in | std::ios::binary);
    _INTR_STRING glslString;
    uint32_t shaderHash = 0u;

    if (inFileStream)
    {
      _INTR_OSTRINGSTREAM contents;
      contents << inFileStream.rdbuf();
      inFileStream.close();
      glslString = contents.str();

      // Add pre processor defines
      {
        _INTR_ARRAY(_INTR_STRING) preProcessorDefines;
        StringUtil::split(_descPreprocessorDefines(ref), ";",
                          preProcessorDefines);

        _INTR_STRING defineStr;
        for (uint32_t i = 0u; i < preProcessorDefines.size(); ++i)
        {
          _INTR_LOG_INFO("Adding preprocessor #define '%s'...",
                         preProcessorDefines[i].c_str());
          defineStr += preProcessorDefines[i] + "\n";
        }

        StringUtil::replace(glslString, "/* __PREPROCESSOR DEFINES__ */",
                            defineStr);
      }

      shaderHash =
          Math::hash(glslString.c_str(), sizeof(char) * glslString.length());

      if (!p_ForceRecompile)
      {
        if (isShaderUpToDate(shaderHash, gpuProgramName.c_str()))
        {
          loadShaderFromCache(gpuProgramName.c_str(), spirvBuffer);
          continue;
        }
      }
    }
    else
    {
      _INTR_LOG_WARNING(
          "Shader for GPU program '%s' not found, trying to load from cache...",
          _descGpuProgramName(ref).c_str());
      loadShaderFromCache(gpuProgramName.c_str(), spirvBuffer);
      continue;
    }

    _INTR_LOG_INFO("Compiling GPU program '%s'...",
                   _descGpuProgramName(ref).c_str());

    const char* glslStringChar = glslString.c_str();
    shader.setStrings(&glslStringChar, 1);

    if (!shader.parse(&_defaultResource, 100, ECoreProfile, false, false,
                      messages, _includer))
    {
      _INTR_LOG_WARNING("Parsing of GPU program failed...");
      _INTR_LOG_WARNING(shader.getInfoLog());
      _INTR_LOG_WARNING(shader.getInfoDebugLog());

      // Try to load the previous shader from the cache
      loadShaderFromCache(gpuProgramName.c_str(), spirvBuffer);
      continue;
    }

    program.addShader(&shader);

    if (!program.link(messages))
    {
      _INTR_LOG_WARNING("Linking of GPU program failed...");
      _INTR_LOG_WARNING(shader.getInfoLog());
      _INTR_LOG_WARNING(shader.getInfoDebugLog());

      // Try to load the previous shader from the cache
      loadShaderFromCache(gpuProgramName.c_str(), spirvBuffer);
      continue;
    }

    _INTR_LOG_WARNING(shader.getInfoLog());
    _INTR_LOG_WARNING(shader.getInfoDebugLog());

    glslang::GlslangToSpv(*program.getIntermediate(stage), spirvBuffer);
    addShaderToCache(shaderHash, gpuProgramName.c_str(), spirvBuffer);

    changedGpuPrograms.push_back(ref);
  }

  // Update all pipelines which reference this GPU program
  PipelineRefArray changedPipelines;
  for (uint32_t gpIdx = 0u; gpIdx < changedGpuPrograms.size(); ++gpIdx)
  {
    GpuProgramRef ref = changedGpuPrograms[gpIdx];

    for (uint32_t pipIdx = 0u;
         pipIdx < Resources::PipelineManager::getActiveResourceCount();
         ++pipIdx)
    {
      Resources::PipelineRef pipelineRef =
          Resources::PipelineManager::getActiveResourceAtIndex(pipIdx);

      if (Resources::PipelineManager::_descVertexProgram(pipelineRef) == ref ||
          Resources::PipelineManager::_descFragmentProgram(pipelineRef) ==
              ref ||
          Resources::PipelineManager::_descGeometryProgram(pipelineRef) ==
              ref ||
          Resources::PipelineManager::_descComputeProgram(pipelineRef) == ref)
      {
        changedPipelines.push_back(pipelineRef);
      }
    }
  }

  if (p_UpdateResources)
  {
    PipelineManager::destroyResources(changedPipelines);
    GpuProgramManager::destroyResources(changedGpuPrograms);

    GpuProgramManager::createResources(changedGpuPrograms);
    PipelineManager::createResources(changedPipelines);
  }
}
Exemplo n.º 17
0
static int _namerev(const void* lhs, const void* rhs)
{
    return -_name(lhs, rhs);
}
Exemplo n.º 18
0
	const char* name(type_index id) const
		{
		assert(core_types_size+dynamic_types.size()>=id);
		return _name(id);
		}