Пример #1
0
void load_acorn(int rnum, int how_many)
{

    int r, obj_num, znum, n, DROP = 0;
    struct obj_data *acorn;

    znum = world[real_room(rnum)].zone;

    for (n = 0; n <= how_many; n++) {
	r = number(rnum, (rnum + 99));
	if (real_room(r)) {

	    obj_num = real_object(200);
	    acorn = read_object(obj_num, REAL);
	    obj_to_room(acorn, real_room(r));
	    DROP = 1;
	}

    }

    if (DROP) {
	send_to_zone_outdoor(znum,
			     "In the distance, you hear an acorn fall to the ground with a rustle of leaves.\r\n");
    }

    obj_num = real_object(599);
    acorn = read_object(obj_num, REAL);
    obj_to_room(acorn, real_room(220));

}
Пример #2
0
static bool
read_objectList(SerdReader* reader, ReadContext ctx, bool* ate_dot)
{
	TRY_RET(read_object(reader, ctx, ate_dot));
	while (!*ate_dot && eat_delim(reader, ',')) {
		TRY_RET(read_object(reader, ctx, ate_dot));
	}
	return true;
}
Пример #3
0
struct obj_data *Obj_from_store(struct obj_file_elem object, int *location)
{
  struct obj_data *obj;
  int j;

  *location = 0;
  if (real_object(object.item_number) != NOTHING) {
    obj = read_object(object.item_number, VIRTUAL);
#if USE_AUTOEQ
    *location = object.location;
#endif
    GET_OBJ_VAL(obj, 0) = object.value[0];
    GET_OBJ_VAL(obj, 1) = object.value[1];
    GET_OBJ_VAL(obj, 2) = object.value[2];
    GET_OBJ_VAL(obj, 3) = object.value[3];
    GET_OBJ_EXTRA(obj) = object.extra_flags;
    GET_OBJ_WEIGHT(obj) = object.weight;
    GET_OBJ_TIMER(obj) = object.timer;
    obj->obj_flags.bitvector = object.bitvector;

    for (j = 0; j < MAX_OBJ_AFFECT; j++)
      obj->affected[j] = object.affected[j];

    return (obj);
  } else
    return (NULL);
}
Пример #4
0
void mag_creations(int level, struct char_data *ch, int spellnum)
{
  struct obj_data *tobj;
  obj_vnum z;

  if (ch == NULL)
    return;
  /* level = MAX(MIN(level, LVL_IMPL), 1); - Hm, not used. */

  switch (spellnum) {
  case SPELL_CREATE_FOOD:
    z = 10;
    break;
  default:
    send_to_char(ch, "Spell unimplemented, it would seem.\r\n");
    return;
  }

  if (!(tobj = read_object(z, VIRTUAL))) {
    send_to_char(ch, "I seem to have goofed.\r\n");
    log("SYSERR: spell_creations, spell %d, obj %d: obj not found",
	    spellnum, z);
    return;
  }
  obj_to_char(tobj, ch);
  act("$n creates $p.", FALSE, ch, tobj, 0, TO_ROOM);
  act("You create $p.", FALSE, ch, tobj, 0, TO_CHAR);
}
Пример #5
0
void
perform_defile(struct room_data *room, int *state, char **olddesc,
    char **oldtitle)
{

    struct obj_data *fount = NULL;

    if (*state != STATE_HOLY) {
        errlog("invalid state in perform_defile from unholy_square.");
        return;
    }

    *state = STATE_UNHOLY;

    for (fount = room->contents; fount; fount = fount->next_content)
        if (GET_OBJ_VNUM(fount) == FOUNT_HOLY) {
            extract_obj(fount);
            break;
        }

    if (!(fount = read_object(FOUNT_UNHOLY)))
        errlog("unable to load unholy fount in unholy_square.");
    else
        obj_to_room(fount, room);

    *olddesc = room->description;
    *oldtitle = room->name;
    room->name = strdup(TITLE_UNHOLY);
    room->description = strdup(DESC_UNHOLY);

    SET_BIT(room->zone->flags, ZONE_LOCKED);

    REMOVE_BIT(room->room_flags, ROOM_PEACEFUL);
}
Пример #6
0
JsonValue JsonValue::read(const std::string &json, size_t &pos)
{
	read_whitespace(json, pos);

	if (pos == json.length())
		throw JsonException("Unexpected end of JSON data");

	switch (json[pos])
	{
	case '{':
		return read_object(json, pos);
	case '[':
		return read_array(json, pos);
	case '"':
		return read_string(json, pos);
	case '-':
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
		return read_number(json, pos);
	case 'f':
	case 't':
		return read_boolean(json, pos);
	default:
		throw JsonException("Unexpected character in JSON data");
	}
}
Пример #7
0
ctache_data_t
*data_from_json(const char *file_name)
{
	ctache_data_t *data;
	FILE *fp;
	struct json_parser *parser;
	struct json_token *tok;

	data = NULL;
	fp = fopen(file_name, "r");
	if (fp == NULL) {
		return NULL;
	}
	parser = json_parse_file(fp);
	tok = json_next_token(parser);
	if (tok->type == JSON_BRACE_LEFT) {
		data = read_object(parser);
	} else {
		fprintf(stderr, "Bad JSON data\n");
		return NULL;
	}
	fclose(fp);

	return data;
}
Пример #8
0
struct obj_data * Obj_from_store(struct obj_file_elem object, int *locate)
{
  struct obj_data *obj;
  int j;

  if (real_object(object.item_number) > -1) {
    obj = read_object(object.item_number, VNUMBER);
    *locate = (int) object.locate;
    GET_OBJ_VAL(obj, 0) = object.value[0];
    GET_OBJ_VAL(obj, 1) = object.value[1];
    GET_OBJ_VAL(obj, 2) = object.value[2];
    GET_OBJ_VAL(obj, 3) = object.value[3];
    GET_OBJ_VAL(obj, 4) = object.value[4];
    GET_OBJ_VAL(obj, 5) = object.value[5];
    GET_OBJ_VAL(obj, 6) = object.value[6];
    GET_OBJ_VAL(obj, 7) = object.value[7];
    GET_OBJ_VAL(obj, 8) = object.value[8];
    GET_OBJ_VAL(obj, 9) = object.value[9];
    GET_OBJ_EXTRA(obj) = object.extra_flags;
    GET_OBJ_WEIGHT(obj) = object.weight;
    GET_OBJ_TIMER(obj) = object.timer;
    obj->obj_flags.bitvector = object.bitvector;

    for (j = 0; j < MAX_OBJ_AFFECT; j++)
      obj->affected[j] = object.affected[j];

    return obj;
  } else
    return NULL;
}
Пример #9
0
int loadObjects(resource_mgr_t *resmgr) {
	int i;
	int *classes, class_count;
	int positions[1000];

	if (objects_init(resmgr)) {
#ifdef SCRIPT_DEBUG
		perror("objects_init");
#endif
		return 1;
	}
	classes = vocabulary_get_classes(resmgr, &class_count);

	for (i = 0; i < 1000; i++) positions[i] = 0;
	for (i = 0; i < class_count; i++) {
#ifdef SCRIPT_DEBUG
		printf("\n\nReading class 0x%02X\n", i);
#endif
		if (read_class(resmgr, classes[i], positions) == 0) {
#ifdef SCRIPT_DEBUG
			fprintf(stderr, "Failed to load class %d, which is a parent.\n", i);
#endif
			return 1;
		}
	}

	for (i = 0; i < 1000; i++) positions[i] = 0;
	for (i = 0; i < 1000; i++) while (read_object(resmgr, i, positions));

	object_map = fobjects.data;
	max_object = fobjects.used;

	return 0;
}
Пример #10
0
int main(int argc, char *argv[]) {
    FILE *inf;
    wave_object_t obj;
    const size_t NUM_FRAMES = 360;
    RtInt md = 4;
    scene_info_t scene;
    double rad = 20;
    double t = 0.0;
    double dt = 2.0*PI/(NUM_FRAMES-1);
    size_t fnum;

    if (argc <3) {
        printf("No input and output file names given!\n");
        return 1;
    }
    
    inf = fopen(argv[1], "rt");
    if (inf == NULL) {
        printf("Could not open \"%s\"\n", argv[1]);
        return 1;

    }
    init_object(&obj);
    read_object(inf, &obj);
    
    
    printf("Object file has:\n  %zu vertices\n  %zu normals\n  %zu texture coordinates\n  %zu faces\n  %d objects\n",
           obj.num_verts, obj.num_norms, obj.num_texts, obj.num_faces, 1);

    RiBegin(RI_NULL);
    RiOption("trace", "maxdepth", &md, RI_NULL);
    RiSides(2);


    scene.cam.location[0] = rad;
    scene.cam.location[1] = rad;
    scene.cam.location[2] = rad;

    scene.cam.look_at[0]= 0.0;
    scene.cam.look_at[1]= 0.0;
    scene.cam.look_at[2]= 0.0;
    scene.cam.roll = 0.0;
    
    scene.fprefix = argv[2];

    for (fnum = 0; fnum < NUM_FRAMES; ++fnum) {
        scene.cam.location[0] = rad * sin(t);
        scene.cam.location[2] = rad * cos(t);
        t += dt;
        printf("Rendering frame %lu\n", fnum);
        doFrame(fnum, &scene, &obj);
    }
    RiEnd();

    free_object(&obj);

    fclose(inf);
    return 0;
}
Пример #11
0
/*prototipo: int getBucket(char *srvName,char *dirName,char *idBucket)
 *objetivo: Retorna um Bucket, de um Diretorio e Servidor especificados nos parametros de entrada*/
int ss_get_bucket(char *srvName,char *dirName,char *idBucket,BUCKET_T *buff_bucket,int* hit){
	
	uint64_t len_bucket;
	time_t mtime;
	char path[PATH_SIZE+1];
	
	*buff_bucket = NULL;	
	*hit = 0; //0 sem cache 1 com cache
	
	snprintf(path,PATH_SIZE,"%s %s %s",srvName,dirName,idBucket);
	
	//cria um contexto de io no ceph, associando ao Pool que faz o papel de servidor
	state = set_server(cluster,srvName,&ioctx);
	if(state >= 0){
		/*se o contexto for criado seta o diretorio
		 *(associa uma chave ao contexto para influenciar o hash)*/ 
		state = set_directory(dirName,&ioctx);
		
		/*obtem o tamanho do bucket e a data de modficacao
		 *sera utilizado na leitura do bucket e para alocar memoria quando nao obtiver cache*/
		state = get_object_size(ioctx, idBucket, &len_bucket, &mtime);
		if(state < 0){
			fprintf(stderr,"[get_bucket/iceph.c] Bucket não localizado!\n");
			destroy_ioctx(&ioctx);
			
			return 1;
		}	
	}else{
		fprintf(stderr,"[get_bucket/iceph.c] Servidor não localizado!\n");
		destroy_ioctx(&ioctx);
		
		return 1;
	}
	
	/*busca no cache o Bucket desejado, se nao encontrar
	 *requisita no sistema de armazenamento e disponibiliza no cache*/
	*hit = get_buffer(idBucket,buff_bucket);
	if(*hit == 0){ //o bucket ainda nao foi para o buffer
		/*se tiver cache disponivel registra o bucket no cache
		 *apos a execucao buff_bucket aponta para a area disponivel*/
		*hit = put_buffer(idBucket,path,buff_bucket);
		if(*hit == 0) //se nao tiver cache disponivel aloca individual
			*buff_bucket = (BUCKET_T) xmalloc(len_bucket);
		
		//busca o bucket no sistema de armazenamento
		state = read_object(ioctx,idBucket,*buff_bucket,len_bucket,0,0);
		//IF TEMPORARIO APENAS DEBUG
		if(*hit == 1)
		  fprintf(stdout,"[get_bucket/iceph.c] cache:\n");
		else
			fprintf(stdout,"[get_bucket/iceph.c] no cache:\n");
	}else //APENAS DEBUG
		fprintf(stdout,"[get_bucket/iceph.c] cache:\n");
	
  destroy_ioctx(&ioctx);
	
	return ( (state >= 0) ? 0 : 1);

}
Пример #12
0
static bool
read_collection(SerdReader* reader, ReadContext ctx, Ref* dest)
{
	eat_byte_safe(reader, '(');
	bool end = peek_delim(reader, ')');
	*dest = end ? reader->rdf_nil : blank_id(reader);
	if (ctx.subject) {
		// subject predicate _:head
		*ctx.flags |= (end ? 0 : SERD_LIST_O_BEGIN);
		TRY_RET(emit_statement(reader, ctx, *dest, 0, 0));
		*ctx.flags |= SERD_LIST_CONT;
	} else {
		*ctx.flags |= (end ? 0 : SERD_LIST_S_BEGIN);
	}

	if (end) {
		return end_collection(reader, ctx, 0, 0, true);
	}

	/* The order of node allocation here is necessarily not in stack order,
	   so we create two nodes and recycle them throughout. */
	Ref n1   = push_node_padded(reader, genid_size(reader), SERD_BLANK, "", 0);
	Ref n2   = 0;
	Ref node = n1;
	Ref rest = 0;

	ctx.subject = *dest;
	while (!(end = peek_delim(reader, ')'))) {
		// _:node rdf:first object
		ctx.predicate = reader->rdf_first;
		bool ate_dot = false;
		if (!read_object(reader, ctx, &ate_dot) || ate_dot) {
			return end_collection(reader, ctx, n1, n2, false);
		}

		if (!(end = peek_delim(reader, ')'))) {
			/* Give rest a new ID.  Done as late as possible to ensure it is
			   used and > IDs generated by read_object above. */
			if (!rest) {
				rest = n2 = blank_id(reader);  // First pass, push
			} else {
				set_blank_id(reader, rest, genid_size(reader));
			}
		}

		// _:node rdf:rest _:rest
		*ctx.flags |= SERD_LIST_CONT;
		ctx.predicate = reader->rdf_rest;
		TRY_RET(emit_statement(reader, ctx,
		                       (end ? reader->rdf_nil : rest), 0, 0));

		ctx.subject = rest;         // _:node = _:rest
		rest        = node;         // _:rest = (old)_:node
		node        = ctx.subject;  // invariant
	}

	return end_collection(reader, ctx, n1, n2, true);
}
Пример #13
0
/*prototipo: int get_lock(char *srvName,char *dirName,char *idBucket,BUCKET_T *buffer)
 *objetivo: verificar se o servidor que ira executar operacao de escrita adquiriu o lock ou nao*/
int get_lock(char *srvName,char *dirName,char *idBucket,BUCKET_T *buffer){
	
	char lock_flag;
	BUCKET_T header;
	char lock_owner[SRVNAME_SIZE];
	int locked;
	
	lock_flag = ' ';
	locked = 0;
	header = *buffer;
	
	memset(lock_owner,'\0',SRVNAME_SIZE);
	
	/*utilizar check_locked() para verifcar se o servidor ja adquiriu o lock
	  se ele ja tiver adquirido lock, locked vai retornar 1 e lock_owner vai
	  retornar o nome do servidor*/
	state = check_locked(idBucket,srvName,&locked,lock_owner);
	/*somente sera requerido lock se nao houver lock no bufffer
	  se o buffer ja tiver bloqueado pelo proprio servidor que esta pedindo
	  vai retornar 1 permitindo a operacao de escrita*/
	if((state == 1) && (locked == 0) && (strlen(lock_owner) == 0) ){
		// conecta-se ao pool/servidor
		state	=	set_server(cluster,srvName,&ioctx);
		if(state < 0){
			fprintf(stderr,"[get_lock/iceph.c] Servidor não localizado!\n");
			return 1;
		}
	
		//seta o diretorio
		state	=	set_directory(dirName,&ioctx);
		if(state >= 0){
			state = read_object(ioctx,idBucket,&lock_flag,LOCK_FLAG_SIZE,0,0);		
			if(state >= 0){
				if(lock_flag == '0'){
					lock_flag = '1';
					//altera o flag em disco
					state = write_object(ioctx,idBucket,&lock_flag,LOCK_FLAG_SIZE,0,0);
					if(state >= 0){
						//altera no buffer
						*(header+LCKFLAG_OFFSET) = lock_flag;
						//altera o parametro locked no buffer_pool
						state = set_locked(idBucket,srvName,lock_flag);
					}
				}else
				  return 0;
			}else
				return 0; //retorna 0 pois nao conseguir escrever no bucket
		}else{
			fprintf(stderr,"[get_lock/iceph.c] Diretório não localizado!\n");
			return 0;
		}
		header = NULL;
	}else if((state == 1) && (locked == 1))
		return 1; //srvName ja adquiriu o lock neste buffer

	return 1;	 
}
Пример #14
0
int read_object(FILE *fp, object *obj)
{
        int             cnt, error=0;
        int		temp;
        otag            *op;
        otag            **prev;
        object          *tobj;
	char		str[10];

	fscanf(fp, "%s", str); 
	if (strcmp(str, "#begobj"))
		return(1);

        read_object_basic(fp, &temp, obj);

	fscanf(fp, "%s", str); 
	if (strcmp(str, "#endobj"))
		return(1);

        obj->first_obj = 0;
        obj->parent_obj = 0;
        obj->parent_rom = 0;
        obj->parent_crt = 0;
        if(obj->shotscur > obj->shotsmax)
                obj->shotscur = obj->shotsmax;

/* get # of objects to read in */
        read_int(fp, &cnt);

        prev = &obj->first_obj;
        while(cnt > 0) {
                cnt--;
                op = (otag *)malloc(sizeof(otag));
                if(op) {
                        tobj = (object *)malloc(sizeof(object));
                        if(tobj) {
                                if(read_object(fp, tobj) == -1)
                                        error = 1;
                                tobj->parent_obj = obj;
                                op->obj = tobj;
                                op->next_tag = 0;
                                *prev = op;
                                prev = &op->next_tag;
                        }
                        else
                                merror("read_obj", FATAL);
                }
                else
                        merror("read_obj", FATAL);
        }

        if(error)
                return(-11);
        else
                return(temp);
}
Пример #15
0
internal cont_p
repl2(cont_p cont)
{
    object_p scan_obj = cont->args_locals[0];
    object_p obj;

    obj = read_object(&scan_obj->scanner);

    CP_CALL2(cont, scm_eval, global_env, obj, repl3);
}
Пример #16
0
static void event_scatter_goodies_zone(int rnum, struct room_data *rp,
				       struct event_goodies *stuff)
{
    int                                     i = 0;
    int                                     exit_found = 0;
    int                                     gold = 0;
    struct char_data                       *monster = NULL;
    struct obj_data                        *object = NULL;
    struct obj_data                        *coins = NULL;

    if (DEBUG > 1)
	log_info("called %s with %d, %08zx, %08zx", __PRETTY_FUNCTION__, rnum, (size_t) rp,
		 (size_t) stuff);

    if (!rp || rp->number < stuff->bottom || rp->number > stuff->top)
	return;
    if (IS_SET(rp->room_flags, (NO_MOB | PEACEFUL | PRIVATE)))
	return;
    exit_found = 0;
    for (i = 0; i < MAX_NUM_EXITS; i++)			       /* neswud */
	if (rp->dir_option[i]) {
	    exit_found = 1;
	    break;
	}
    if (!exit_found)
	return;
    if (number(0, 99) >= stuff->chance)
	return;
    gold = dice(stuff->gold_dice, stuff->gold_die) + stuff->gold_mod;
    gold_count += gold;
    coins = create_money(gold);
    obj_to_room(coins, rnum);
    rprintf(rnum,
	    "In a brilliant green flash, a pile of %s appears before you!\r\n",
	    coins->short_description);
    if (number(0, 99) < stuff->mob_chance) {
	i = number(1, stuff->mob_count) - 1;
	if ((monster = read_mobile(stuff->mob_vnum[i], VIRTUAL))) {
	    GET_GOLD(monster) = 0;
	    mob_count++;
	    char_to_room(monster, rnum);
	    act("A rift of red light rips open and $N rushes out!", FALSE,
		monster, 0, monster, TO_ROOM);
	}
    }
    if (number(0, 99) < stuff->obj_chance) {
	i = number(1, stuff->obj_count) - 1;
	if ((object = read_object(stuff->obj_vnum[i], VIRTUAL))) {
	    obj_count++;
	    obj_to_room(object, rnum);
	    rprintf(rnum, "In a shimmering of blue light, %s %s forms!\r\n",
		    SANA(object), object->short_description);
	}
    }
}
Пример #17
0
void Crash_listrent(struct char_data * ch, char *name)
{
  FILE *fl;
  char fname[MAX_INPUT_LENGTH], buf[MAX_STRING_LENGTH];
  struct obj_file_elem object;
  struct obj_data *obj;
  struct rent_info rent;

  if (!get_filename(name, fname, CRASH_FILE))
    return;
  if (!(fl = fopen(fname, "rb"))) {
    sprintf(buf, "%s has no rent file.\r\n", name);
    send_to_char(buf, ch);
    return;
  }
  sprintf(buf, "%s\r\n", fname);
  if (!feof(fl))
    fread(&rent, sizeof(struct rent_info), 1, fl);
  switch (rent.rentcode) {
  case RENT_RENTED:
    strcat(buf, "Rent\r\n");
    break;
  case RENT_CRASH:
    strcat(buf, "Crash\r\n");
    break;
  case RENT_CRYO:
    strcat(buf, "Cryo\r\n");
    break;
  case RENT_TIMEDOUT:
  case RENT_FORCED:
    strcat(buf, "TimedOut\r\n");
    break;
  default:
    strcat(buf, "Undef\r\n");
    break;
  }
  while (!feof(fl)) {
    fread(&object, sizeof(struct obj_file_elem), 1, fl);
    if (ferror(fl)) {
      fclose(fl);
      return;
    }
    if (!feof(fl))
      if (real_object(object.item_number) > -1) {
	obj = read_object(object.item_number, VNUMBER);
	sprintf(buf, "%s [%ld] (%5dau) %-20s\r\n", buf,
		object.item_number, GET_OBJ_RENT(obj),
		obj->short_description);
	extract_obj(obj);
      }
  }
  send_to_char(buf, ch);
  fclose(fl);
}
Пример #18
0
static ctache_data_t
*read_object(struct json_parser *parser)
{
	ctache_data_t *data;
	struct json_token *tok;
	char *key;
	ctache_data_t *val;
	int done = 0;
	size_t len;

	data = ctache_data_create_hash();

	while (!done) {
		tok = json_next_token(parser);
		key = strdup(tok->value.string);
		tok = json_next_token(parser);
		if (tok->type != JSON_COLON) {
			fprintf(stderr, "ERROR: Expected ':'\n");
			ctache_data_destroy(data);
			free(key);
			return NULL;
		}
		tok = json_next_token(parser);
		if (tok->type == JSON_STRING) {
			len = strlen(tok->value.string);
			val = ctache_data_create_string(tok->value.string, len);
		} else if (tok->type == JSON_BOOLEAN) {
			val = ctache_data_create_boolean(tok->value.boolean);
		} else if (tok->type == JSON_BRACE_LEFT) {
			val = read_object(parser);
		} else if (tok->type == JSON_BRACKET_LEFT) {
			val = read_array(parser);
		} else {
			fprintf(stderr, "ERROR: Expected value\n");
			ctache_data_destroy(data);
			free(key);
			return NULL;
		}
		ctache_data_hash_table_set(data, key, val);
		free(key);

		tok = json_next_token(parser);
		if (tok->type == JSON_BRACE_RIGHT) {
			done = 1;
		} else if (tok->type == JSON_COMMA) {
			done = 0;
		} else {
			fprintf(stderr, "ERROR: Expected '}'\n");
			ctache_data_destroy(data);
			return NULL;
		}
	}
	return data;
}
Пример #19
0
struct obj_data *create_object(int vnum, int dummy)
{
int r_num;
struct obj_data *tobj;

if((r_num = real_object(vnum)) < 0)
tobj = NULL;
else
 tobj = read_object(r_num, REAL);
 return(tobj);
}
Пример #20
0
static COMMAND_FUNC( rd_obj )
{
	Data_Obj *dp;
	Image_File *ifp;

	dp=PICK_OBJ( "name of image data object" );
	ifp=PICK_IMG_FILE("");
	if( dp == NO_OBJ ) return;
	if( ifp == NO_IMAGE_FILE ) return;
	read_object(QSP_ARG  dp, ifp);
}
Пример #21
0
void stream_reader::read_string_ex(pfc::string_base & p_out,t_size p_bytes,abort_callback & p_abort) {
	const t_size expBase = 64*1024;
	if (p_bytes > expBase) {
		pfc::array_t<char> temp;
		t_size allocWalk = expBase;
		t_size done = 0;
		for(;;) {
			const t_size target = pfc::min_t(allocWalk, p_bytes);
			temp.set_size(target);
			read_object(temp.get_ptr() + done, target - done, p_abort);
			if (target == p_bytes) break;
			done = target;
			allocWalk <<= 1;
		}
		p_out.set_string(temp.get_ptr(), p_bytes);
	} else {
		pfc::string_buffer buf(p_out, p_bytes);
		read_object(buf.get_ptr(),p_bytes,p_abort);
	}
}
Пример #22
0
exprt dereferencet::dereference_rec(
  const exprt &address,
  const exprt &offset,
  const typet &type)
{
  if(address.id()==ID_address_of)
  {
    const address_of_exprt &address_of_expr=to_address_of_expr(address);

    const exprt &object=address_of_expr.object();

    return read_object(object, offset, type);
  }
  else if(address.id()==ID_typecast)
  {
    const typecast_exprt &typecast_expr=to_typecast_expr(address);

    return dereference_typecast(typecast_expr, offset, type);
  }
  else if(address.id()==ID_plus)
  {
    // pointer arithmetic
    if(address.operands().size()<2)
      throw "plus with less than two operands";

    return dereference_plus(address, offset, type);
  }
  else if(address.id()==ID_if)
  {
    const if_exprt &if_expr=to_if_expr(address);

    return dereference_if(if_expr, offset, type);
  }
  else if(address.id()==ID_constant)
  {
    const typet result_type=ns.follow(address.type()).subtype();

    // pointer-typed constant
    if(to_constant_expr(address).get_value()==ID_NULL) // NULL
    {
      // we turn this into (type *)0
      exprt zero=gen_zero(index_type());
      return dereference_rec(
        typecast_exprt(zero, address.type()), offset, type);
    }
    else
      throw "dereferencet: unexpected pointer constant "+address.pretty();
  }
  else
  {
    throw "failed to dereference `"+address.id_string()+"'";
  }
}
Пример #23
0
int main(int argc, char *argv[])
{
  char *cases[] = {
    /* "(+. 1.1 1.2)", */
    /* "(integer->float 123)", */
    /* "(& 5 7)", */
    /* "'hello", */
    /* "-", */
    /* "(define a (string->in-port \"abc\"))", */
    /* "(read-string-in-port-char a)", */
    /* "(+i 1 2)", */
    /* "(*i 3 4)", */
    /* "(quotient 10 3)", */
    /* "(remainder 10 3)", */
    /* "(= 1 2)", */
    /* "(> 4 5)", */
    /* "(& 5 7)", */
    /* "(| 5 7)", */
    /* "(~ 5)", */
    /* "(eq? 'hello 'hello)", */
    /* "(eq? 1 1)", */
    /* "(eq? (string->symbol \"hello\") 'hello)", */
    /* "(type-of 'hello)", */
    /* "type-of", */
    /* "#\\a", */
    /* "(type-of #\\a)", */
    /* "(define a #(1 2 3))", */
    /* "#\\汉", */
    /* "(set! a 123)", */
    "(string-ref \"汉字\" 0)",
  };
  init_impl();
  /* printf("Address of `-': %p\n", &primitive_procs[1]); */
  for (int i = 0; i < sizeof(cases) / sizeof(char *); i++) {
    FILE *stream = fmemopen(cases[i], strlen(cases[i]), "r");
    sexp in_port = make_file_in_port(stream);
    /* inc_ref_count(in_port); */
    printf(">> %s\n=> ", cases[i]);
    sexp value = read_object(in_port);
    if (is_eof(value))
      break;
    /* inc_ref_count(input); */
    value = eval_object(value, repl_environment);
    /* if (!is_self_eval(input)) */
    /*   inc_ref_count(value); */
    write_object(value, scm_out_port);
    putchar('\n');
  }
  /* write_object(make_wstring("汉"), scm_out_port); */
  /* trigger_gc(); */
  return 0;
}
Пример #24
0
static void event_fill_zone_with_mobs(int rnum, struct room_data *rp,
				      struct event_mob_in_zone *mobs)
{
    int                                     i = 0;
    int                                     j = 0;
    int                                     couldbe = 0;
    int                                     exit_found = FALSE;
    struct char_data                       *monster = NULL;
    struct obj_data                        *object = NULL;

    if (DEBUG > 1)
	log_info("called %s with %d, %08zx, %08zx", __PRETTY_FUNCTION__, rnum, (size_t) rp,
		 (size_t) mobs);

    if (!rp || rp->number < mobs->bottom || rp->number > mobs->top)
	return;
    if (IS_SET(rp->room_flags, (NO_MOB | PEACEFUL | PRIVATE)))
	return;
    exit_found = 0;
    for (i = 0; i < MAX_NUM_EXITS; i++)			       /* neswud */
	if (rp->dir_option[i]) {
	    exit_found = 1;
	    break;
	}
    if (!exit_found)
	return;
    couldbe = number(mobs->atleast, mobs->atmost);
    for (j = 0; j < couldbe; j++) {
	if (number(0, 99) >= mobs->chance)
	    continue;
	i = number(1, mobs->count) - 1;
	if (!(monster = read_mobile(mobs->mobset[i].vnum, VIRTUAL)))
	    continue;
	monster->points.max_hit = dice(mobs->mobset[i].hp_dice,
				       mobs->mobset[i].hp_die) + mobs->mobset[i].hp_mod;
	GET_HIT(monster) = GET_MAX_HIT(monster);
	GET_EXP(monster) = (dice(mobs->mobset[i].exp_dice, mobs->mobset[i].exp_die)
			    + mobs->mobset[i].exp_mod) * GET_MAX_HIT(monster);
	GET_GOLD(monster) = number(mobs->mobset[i].gold_dice, mobs->mobset[i].gold_die)
	    + mobs->mobset[i].gold_mod;
	if (mobs->mobset[i].obj_vnum >= 0) {
	    if (number(0, 99) < mobs->mobset[i].obj_chance) {
		if ((object = read_object(mobs->mobset[i].obj_vnum, VIRTUAL)))
		    obj_to_char(object, monster);
	    }
	}
	char_to_room(monster, rnum);
	mob_count++;
	act("In a shimmering column of blue light, $N appears!", FALSE,
	    monster, 0, monster, TO_ROOM);
    }
}
Пример #25
0
ReaderObject
ReaderMapping::read_object(const char* key) const
{
  if (!m_impl)
  {
    return {};
  }
  {
    ReaderObject result;
    read_object(key, result);
    return result;
  }
}
Пример #26
0
int main(int argc, char *argv[])
{
  init_impl();
  char *cases[] = {
    /* "1", */
    /* "12.3", */
    /* "123.45", */
    /* "1234.567", */
    /* "12345.6789", */
    /* ";;\n987654.3210", */
    /* "+i", */
    /* "'hello", */
    /* "#\\汉", */
    /* "(if #t 1 2)", */
    /* "(set! a 1)", */
    /* "(begin (set! a 1) a)", */
    /* "(begin \"doc\" (write \"Hello, world\") 2)", */
    /* "(lambda (x) (+i x 1))", */
    /* "(+i 1 1)", */
    /* "(eq? \"abc\" \"abc\")", */
    /* "(eq? #\\a #\\a)", */
    /* "((lambda (x . y) (cons x y)) 1 2 3 4)", */
    /* "(eq? 'hello 'hello)", */
    /* "(cdr '(1 2))", */
    /* "(string-ref \"汉\" 0)", */
    /* "(string-length \"汉字\")", */
    /* "(string-set! \"汉字\" 1 #\\语)", */
    /* "(eval '(cdr '(1 2 3)) (repl-environment))", */
    /* "(cons 1 2)", */
    /* "#(1 2 3)", */
    /* "(+i 1 2)", */
    /* "(-i 1 2)", */
    /* "(*i 1 2)", */
    /* "(/i 1 2)", */
    "not",
  };
  for (int i = 0; i < sizeof(cases) / sizeof(char *); i++) {
    FILE *fp = fmemopen(cases[i], strlen(cases[i]), "r");
    lisp_object_t in_port = make_file_in_port(fp);
    printf(">> %s\n", cases[i]);
    lisp_object_t compiled_code =
        compile_as_fn(read_object(in_port), repl_environment);
    /* port_format(scm_out_port, "-- %*\n", compiled_code); */
    lisp_object_t value =
        run_compiled_code(compiled_code, repl_environment, vm_stack);
    port_format(scm_out_port, "=> %*\n", value);
    fclose(fp);
  }
  port_format(scm_out_port, "%*\n", vm_stack);
  return 0;
}
Пример #27
0
void SDLReader::read_sdl(Scene &scene, string file_object, string file_camera, string file_light, string file_plane)
{
  Camera *camera = read_camera(file_camera);
  scene.set_camera(camera);
  Material *material;
  Light *light = read_light(file_light, &material, scene);
  scene.add_light(light);
  Mesh *mesh = read_object(file_object, material);
  scene.add_mesh(mesh);
  if(file_plane.size() == 0) 
	return;
  Plane *plane = read_plane(file_plane);
  scene.set_plane(plane);
}
Пример #28
0
static ctache_data_t
*read_array(struct json_parser *parser)
{
	ctache_data_t *data;
	ctache_data_t *elem;
	struct json_token *tok;
	char *str;
	size_t str_len;
	int done;

	data = ctache_data_create_array(0);
	if (data == NULL) {
		return NULL;
	}
	
	done = 0;
	while (!done) {
		elem = NULL;
		tok = json_next_token(parser);
		if (tok->type == JSON_BRACKET_RIGHT) {
			done = 1;
		} else if (tok->type == JSON_STRING) {
			str = tok->value.string;
			str_len = strlen(str);
			elem = ctache_data_create_string(str, str_len);
		} else if (tok->type == JSON_BRACE_LEFT) {
			elem = read_object(parser);
		} else {
			fprintf(stderr, "ERROR: Expected value\n");
			ctache_data_destroy(data);
			return NULL;
		}
		if (elem != NULL) {
			ctache_data_array_append(data, elem);
		}
		tok = json_next_token(parser);
		if (tok->type != JSON_COMMA
			&& tok->type != JSON_BRACKET_RIGHT) {
			fprintf(stderr, "ERROR: Expected ']' or ','\n");
			ctache_data_destroy(data);
			return NULL;
		}
		if (tok->type == JSON_BRACKET_RIGHT) {
			done = 1;
		}
	}
	return data;
}
Пример #29
0
int pray_for_items(struct char_data *ch, int cmd, char *arg)
{
  char buf[256];
  int key_room, gold;
  bool found;
  struct obj_data *tmp_obj, *obj;
	struct extra_descr_data *ext;

	if (cmd != 176) /* You must pray to get the stuff */
		return FALSE;

	key_room = 1+ch->in_room;

  strcpy(buf, "item_for_");
  strcat(buf, GET_NAME(ch));

  gold = 0;
  found = FALSE;

  for (tmp_obj = world[key_room].contents; tmp_obj; tmp_obj = tmp_obj->next_content)
    for(ext = tmp_obj->ex_description; ext; ext = ext->next)
      if (str_cmp(buf, ext->keyword) == 0) {
		  if (gold == 0) {
		     gold = 1;
			   act("$n kneels and at the altar and chants a prayer to Odin.",
					 FALSE, ch, 0, 0, TO_ROOM);
				act("You notice a faint light in Odin's eye.",
					 FALSE, ch, 0, 0, TO_CHAR);
		  }
        obj = read_object(tmp_obj->item_number, REAL);
        obj_to_room(obj, ch->in_room);
		  act("$p slowly fades into existence.",FALSE,ch,obj,0,TO_ROOM);
		  act("$p slowly fades into existence.",FALSE,ch,obj,0,TO_CHAR);
        gold += obj->obj_flags.cost;
        found = TRUE;
      }

  if (found) {
    GET_GOLD(ch) -= gold;
    GET_GOLD(ch) = MAX(0, GET_GOLD(ch));
    return TRUE;
	}

  return FALSE;
}
Пример #30
0
int save_state::load_from_file(int thread, 
				int steady_iter, 
				void (*read_object)(object_write_buffer *)) {
  
  object_write_buffer *buf = new object_write_buffer();
  
  char fname[256];
  sprintf(fname, "%s%d.%d", PATH, thread, steady_iter);
  
  //fprintf(stderr,"thread: %d file: %s\n", thread, fname);
  
  int fd = open(fname, O_RDONLY);
  
  if (fd == -1) {
    perror("load_checkpoint");
    return -1;
  }
  
  netsocket file_sock(fd);

  int count = 0;
  
  for (;;) {
    char tmp[4];
    int retval = file_sock.read_chunk(tmp, 4);
    if (retval == -1) break;
    buf->write(tmp, 4);

    count += 4;

    //fprintf(stderr,"read data (4 bytes)\n");
  }

  if (debugging) {
    fprintf(stderr,"thread: %d file: %s size: %d bytes\n", thread, fname, count);
  }
  close(fd);
  
  buf->set_read_offset(0);
  read_object(buf);

  delete buf;

  return 0;
}