flusspferd::value getObjProto( int vnum )
{
	int rnum = real_object( vnum );
	if( rnum == -1 )
		return lookupValue( 0 );
	return lookupValue( obj_proto[rnum] );
}
Exemple #2
0
void Store::resolve(Value& val) const {
    if(val.id() != Value::UNKNOWN_ID)
        return;

    // lookup strings
    val.ensureLexical();
    if(val.isTyped() && val.datatypeLex().null()) {
        Value v = lookupValue(val.datatypeId());
        val.datatypeLex(String(v.lexical()));
    }
    val.ensureDirectStrings(*this);
    val.ensureResolvedStrings(*this);

    // look for pages containing the hash
    Hash::hash_t hash = val.hash();
    Cursor cur = values_.index->lookup(hash);
    if(!cur.valid()) {
        val.id(0);
        return;
    }

    // scan all candidates in the collision list
    Cursor end = db_.pageEnd(cur);
    while(cur != end) {
        if(cur.readInt() != hash)
            break;
        Value::id_t id = cur.readInt();
        Value v = lookupValue(id);
        if(v == val) {
            val.id(id);
            return;
        }
    }
    val.id(0);
}
flusspferd::value JS_getRoom( int vnum )
{
	int rnum = real_room(vnum);

	if( rnum == -1 )
		return lookupValue( 0 );
	else
		return lookupValue( World[rnum] );
}
Exemple #4
0
counts_t * countFile(const char * filename, kvarray_t * kvPairs) {
  
  counts_t *c = createCounts();
  FILE *f = fopen(filename,"r");
  if(f==NULL)
    {
      fprintf(stderr,"Couldn't open File!");
      return NULL;
    }
  char *line=NULL;
    char *value=NULL;
    size_t num=0;
    char *temp=NULL;
  while(getline(&line,&num,f)!=-1)
    {
      temp=strchr(line,'\n');
      *temp='\0';
      value=lookupValue(kvPairs,line);
      addCount(c,value);
      free(line);
      value=NULL;
      temp=NULL;
      //      free(temp);
      num=0;
    }
  // free(value);
  free(line);   
  if(fclose(f)!=0)
    {
      fprintf(stderr,"Couldn't close file!");
    return NULL;
    }
  return c;
}
Exemple #5
0
			IndexEntry const * lookupValuePointer(uint64_t const v) const
			{
				uint64_t const i = lookupValue(v);
				if ( i+1 < index.size() )
					return &(index[i]);
				else
					return 0;
			}
flusspferd::value JS_loadSingleObjectFromDatabase(flusspferd::string objectId)
{
	boost::uuids::string_generator uuidGenerator;

	Object *object = Object::loadSingleItem(uuidGenerator(objectId.to_string()), true);

	return lookupValue(object);
}
flusspferd::array JS_getObjectList()
{
	flusspferd::array vA = flusspferd::create_array();
	for(Object *obj = object_list;obj;obj = obj->next) {
		vA.call("push", lookupValue(obj));
	}
	return vA;
}
flusspferd::array JS_getCharacterList()
{
	flusspferd::array vA = flusspferd::create_array();
	for(Character *ch = character_list;ch;ch = ch->next) {
		vA.call("push", lookupValue(ch));
	}
	return vA;
}
flusspferd::array getConnectedPlayers()
{
	flusspferd::array vA = flusspferd::create_array();
	for(Descriptor *d = descriptor_list;d;d = d->next) {
		if( d->character && d->character->in_room ) {
			vA.call("push", lookupValue(d->character));
		}
	}
	return vA;
}
Exemple #10
0
/*  
    Caller must free
 */
char *getValue(MprTestGroup *gp, char *key)
{
    char    *value;

    value = lookupValue(gp, key);
    if (value == 0) {
        return sclone("");
    } else {
        return value;
    }
}
symbol_t *findSymbol(value_t symTab, value_t name, bool create, uint64_t hash) {
	int idx;

	if ((idx = lookupValue(symTab, name, hash, true)) > 0)
		return symTab.oval->pairsPtr[idx - 1].value.sym;

	if (create)
		return setAttribute(symTab.oval, name, -idx)->sym;

	return NULL;
}
flusspferd::value JS_sendQuery( flusspferd::string qBuffer )
{
	sql::Query MyQuery;
	try {
		MyQuery = gameDatabase->sendQuery( qBuffer.to_string() );
	} catch( sql::QueryException e ) {
		MudLog(BRF, LVL_APPR, TRUE, "JavaScript : sql::Query() : %s", e.getMessage().c_str());
		return flusspferd::value();
	}
	if( MyQuery.use_count() == 0 )
		return flusspferd::value();
	JSBindable *b = new sqlJSQuery( MyQuery );
	return lookupValue( b );
}
Exemple #13
0
/*
    Match a keyword in the content returned from the last request
    Format is:
        KEYWORD = value
 */
bool match(MprTestGroup *gp, char *key, char *value)
{
    char    *vp, *trim;

    vp = lookupValue(gp, key);
    if (vp == 0 && value == 0) {
        return 1;
    }
    trim = strim(vp, "\"", MPR_TRIM_BOTH);
    if (vp == 0 || value == 0 || scmp(trim, value) != 0) {
        mprLog("appweb test match", 0, "Match %s failed. Got \"%s\" expected \"%s\"", key, vp, value);
        mprLog("appweb test match", 0, "Content %s", gp->content);
        return 0;
    }
    return 1;
}
Exemple #14
0
Fichier : main.c Projet : jvm3487/C
counts_t * countFile(const char * filename, kvarray_t * kvPairs) {
  //WRITE ME
  counts_t * c = createCounts();
  FILE * f = fopen(filename,"r");
  char * line = NULL;
  size_t sz = 0;
  while(getline(&line, &sz, f) >= 0) {
    char * ptr = strchr(line, '\n');
    if (ptr != NULL) {
      *ptr = '\0';
    }
    char * value = lookupValue(kvPairs, line);
    addCount(c, value);
  }
  fclose(f);
  free(line);
  return c;
}
Exemple #15
0
/*
    Match a keyword an ignore case for windows
 */
bool matchAnyCase(MprTestGroup *gp, char *key, char *value)
{
    char    *vp, *trim;

    vp = lookupValue(gp, key);
    if (vp == 0 && value == 0) {
        return 1;
    }
    trim = strim(vp, "\"", MPR_TRIM_BOTH);
#if BIT_WIN_LIKE
    if (vp == 0 || scaselesscmp(trim, value) != 0)
#else
    if (vp == 0 || value == 0 || scmp(trim, value) != 0)
#endif
    {
        mprLog("appweb test match", 0, "Match %s failed. Got %s expected %s", key, vp, value);
        return 0;
    }
    return 1;
}
flusspferd::array JS_loadObjectsByHolderFromDatabase(flusspferd::string holderType, flusspferd::string holderId)
{
	flusspferd::array objects = flusspferd::create_array();

	if(holderType.size() == 0) {

		throw flusspferd::exception("Attempting to load objects from holder of empty type.");
	}

	std::list< Object* > objectList = Object::loadItemList(true, holderType.c_str()[0], holderId.to_string());

	while(objectList.empty() == false) {
		objects.call("push", lookupValue(objectList.front()));
//		objects.push(lookupValue(objectList.front()));

		objectList.pop_front();
	}

	return objects;
}
int JS_getCharacterArenaTeam( Character *ch )
{
	try {
		flusspferd::value chValue = lookupValue(ch);
		
		if( chValue.is_object() == false )
			MudLog(BRF, LVL_APPR, TRUE, "JS_getCharacterArenaTeam : chValue is not an object");
		
		flusspferd::object chObject = chValue.to_object();
		flusspferd::value chArenaTeam = chObject.get_property("arenaTeam");

		if(chArenaTeam.is_number() != false)
			return (int)chArenaTeam.to_number();
	}
	catch(flusspferd::exception e) {
		MudLog(BRF, LVL_APPR, TRUE, "Generic Exception: %s", e.what());
	}

	return 0;

}
Exemple #18
0
ValueRange Store::eqClass(const Value& val) const {
    if(val.id() > 0)
        return eqClass(val.id());
    assert(val.interpreted());

    // costly binary search for equivalent value
    Value::id_t left  = 1;
    Value::id_t right = values_.count + 1;
    while(left != right) {
        Value::id_t middle = left + (right - left) / 2;
        Value mVal = lookupValue(middle);
        mVal.ensureInterpreted(*this);
        if(mVal.compare(val) == 0)
            return eqClass(middle);
        if(mVal < val)
            left = middle + 1;
        else
            right = middle;
    }
    ValueRange result = {left, left - 1};
    return result;
}
flusspferd::value getMobProtoByRnum( int rnum )
{
	return lookupValue( MobManager::GetManager().GetPrototype( rnum ) );
}
js_extra_data make_extra(std::string name, Room *val)
{
    flusspferd::object data = flusspferd::create_object();
    data.set_property(name, lookupValue(val));
    return data;
}
flusspferd::value JS_getRoomByRnum( int rnum )
{
	if( rnum >= 0 && rnum < World.size() )
		return lookupValue( World[rnum] );
	return lookupValue( 0 );
}
flusspferd::value getObjProtoByRnum( int rnum )
{
	if( rnum >= 0 && rnum < top_of_objt )
		return lookupValue( obj_proto[ rnum ] );
	return lookupValue( 0 );
}
flusspferd::value getMobProto( int vnum )
{
	return lookupValue( MobManager::GetManager().GetPrototypeByVnum( vnum ) );
}