Ejemplo n.º 1
0
/*
 * read a struct and add it to tree
 */
static void
read_struct(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree,
            int add_type_field)
{
  proto_item *ti;
  proto_tree *new_tree;
  int         length;
  int         i;

  ti = proto_tree_add_item(etch_tree, hf_etch_struct, tvb, *offset,
                           tvb_captured_length(tvb) - *offset, ENC_NA);
  new_tree = proto_item_add_subtree(ti, ett_etch_struct);

  if (add_type_field) {
    read_type(offset, tvb, new_tree);
  }
  /* struct type as hash */
  read_value(offset, tvb, new_tree, hf_etch_value);

  /* struct length */
  length = read_value(offset, tvb, new_tree, hf_etch_length);

  for (i = 0; i < length; i++) {
    read_key_value(offset, tvb, new_tree);
  }

  /* termination */
  read_type(offset, tvb, new_tree);
}
Ejemplo n.º 2
0
/*
 * read a array type flag and add it to tree
 */
static void
read_array_type(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
{
  guint32 type_code;

  type_code = tvb_get_guint8(tvb, *offset);

  read_type(offset, tvb, etch_tree);
  if (type_code == ETCH_TC_CUSTOM) {
    read_type(offset, tvb, etch_tree);
    proto_tree_add_item(etch_tree, hf_etch_value, tvb, *offset, 4,
                        ENC_BIG_ENDIAN);
    (*offset) += 4;
  }
}
Ejemplo n.º 3
0
Archivo: goc2c.c Proyecto: 0day-ci/gcc
/*
 * Read a list of parameters.  Each parameter is a name and a type.
 * The list ends with a ')'.  We have already read the '('.
 */
static struct params *
read_params()
{
	char *token;
	struct params *ret, **pp, *p;

	ret = NULL;
	pp = &ret;
	token = read_token_no_eof();
	if (strcmp(token, ")") != 0) {
		while (1) {
			p = xmalloc(sizeof(struct params));
			p->name = token;
			p->type = read_type();
			p->next = NULL;
			*pp = p;
			pp = &p->next;

			token = read_token_no_eof();
			if (strcmp(token, ",") != 0)
				break;
			token = read_token_no_eof();
		}
	}
	if (strcmp(token, ")") != 0) {
		sysfatal("%s:%ud: expected '('\n",
			file, lineno);
	}
	return ret;
}
Ejemplo n.º 4
0
/*
 * read a number and add it to tree
 */
static void
read_number(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree,
            int asWhat, guint8 type_code)
{
  int byteLength;

  read_type(offset, tvb, etch_tree);
  byteLength = get_byte_length(type_code);
  if (byteLength > 0) {
    proto_item  *ti;
    const gchar *symbol = NULL;
    guint32      hash   = 0;

    gbl_symbol_buffer = wmem_strbuf_new_label(wmem_packet_scope());  /* no symbol found yet */
    if (byteLength == 4) {
      hash = tvb_get_ntohl(tvb, *offset);
      symbol = try_val_to_str_ext(hash, gbl_symbols_vs_ext);
      if(symbol != NULL) {
        asWhat = hf_etch_symbol;
        gbl_have_symbol = TRUE;
        wmem_strbuf_append_printf(gbl_symbol_buffer,"%s",symbol);
      }
    }
    ti = proto_tree_add_item(etch_tree, asWhat, tvb, *offset,
                             byteLength, ENC_BIG_ENDIAN);
    *offset += byteLength;
    if (symbol != NULL) {
      proto_item_append_text(ti, " (0x%08x) %s", hash, symbol);
    }
  }
}
Ejemplo n.º 5
0
static t_myproof_variable *read_data( tree t, t_myproof_function *function )
{
    char identifier[MYPROOF_NAME_SIZE];

    if ( DECL_NAME(t) )
	{
	    strcpy( identifier, IDENTIFIER_POINTER(DECL_NAME(t)) );
	}
    else
	{
	    sprintf(identifier, "%c_%u", ( TREE_CODE(t) == CONST_DECL ) ? 'C' : 'D', DECL_UID(t) );
	}

    t_myproof_variable *variable = mylist_find( function->variables, variable_exists, (void*)identifier );

    if ( variable == NULL )
	{
	    variable = create_variable_struct( identifier, t );
	    mylist_insert( &(function->variables), variable );
	}

    read_type( TREE_TYPE(t), function );

    return variable;
}
Ejemplo n.º 6
0
std::unique_ptr<tag> io::read(std::istream& is, std::string& key)
{
    tag::tag_type tt = read_type(is);
    key = read_str(is);
    if(!is)
        throw tag::input_error((boost::format("Error reading name of tag_%1%") % tt).str());
    return read_payload(tt, is);
}
Ejemplo n.º 7
0
/*
 * read a sequence of bytes and add them to tree
 */
static void
read_bytes(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
{
  int length;
  read_type(offset, tvb, etch_tree);
  length = read_length(offset, tvb, etch_tree);
  proto_tree_add_item(etch_tree, hf_etch_bytes, tvb, *offset, length,
                      ENC_NA);
  (*offset) += length;
}
Ejemplo n.º 8
0
/*
 * read a string and add it to tree
 */
static void
read_string(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
{
  int byteLength;
  read_type(offset, tvb, etch_tree);

  byteLength = read_length(offset, tvb, etch_tree);

  proto_tree_add_item(etch_tree, hf_etch_string, tvb, *offset,
                      byteLength, ENC_ASCII|ENC_NA);
  (*offset) += byteLength;
}
Ejemplo n.º 9
0
void bronco::serverconnection::handle_announce(const boost::system::error_code &error, const protocol::Announce &announce)
{
    if (!error) {
        /* send join request */
        write_message(announce);

        /* wait for reply */
        read_type();
    } else {
        handle_error(error);
    }
}
Ejemplo n.º 10
0
void bronco::serverconnection::handle_connect(const boost::system::error_code &error, const protocol::Peer &me)
{
    if (!error) {
        /* Send join request */
        write_message(me);

        /* Wait for reply */
        read_type();
    } else {
        handle_error(error);
    }
}
Ejemplo n.º 11
0
static void read_data( tree t )
{
    if ( DECL_NAME(t) )
	{
	    /* printf ( "       data \'%s\'\n", IDENTIFIER_POINTER(DECL_NAME(t)) ); */
	}
    else
	{
	    /* printf ( "       data \'%c_%u\'\n", (TREE_CODE(t)==CONST_DECL)?'C':'D', DECL_UID(t) ); */
	}

    read_type ( TREE_TYPE(t) );
}
Ejemplo n.º 12
0
/*
 * read an array from tvb and add it to tree
 */
static void
read_array(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
{
  int length;

  /*  array type */
  read_type(offset, tvb, etch_tree);

  /*  Array of type: */
  read_array_type(offset, tvb, etch_tree);

  /*  Array dim */
  proto_tree_add_item(etch_tree, hf_etch_dim, tvb, *offset, 1, ENC_BIG_ENDIAN);
  (*offset)++;

  /*  Array length */
  length = read_length(offset, tvb, etch_tree);

  for (; length > 0; length--) {
    read_value(offset, tvb, etch_tree, hf_etch_value);
  }
  /*  terminaton */
  read_type(offset, tvb, etch_tree);
}
Ejemplo n.º 13
0
int cw_ktv_parse_string(struct cw_KTV_Reader *r, char *key, char *type, char *val)
{

	int n;

	

	n = read_key (r,key,CW_KTV_MAX_KEY_LEN);
	n = read_type(r,type,200);
	if (n==1)
		return -1;
	n = read_val(r,val,200);
	return n;
	
}
/**
 * A wrapper function around read_type() and read_packet() for reading data from the pipe
 * and returning it.
 *
 * @param[in]   fd      The file descriptor to read from.
 * @param[in]   type    A pointer to the packet type.
 *
 * @return      <ul>
 *                  <li>Returns the packet if successful.</li>
 *                  <li>Returns NULL if it fails to read either of the type or the packet from the pipe.</li>
 *              </ul>
 *
 * @designer    Ramzi Chennafi
 * @author      Ramzi Chennafi
 */
void *read_data(int fd, uint32_t *type) {

    void *packet;
    *type = read_type(fd);
    if(*type <= 0 || *type > NUM_PACKETS) {
        perror("read_data: Failed to read packet type from pipe");
        return NULL;
    }

    if((packet = read_packet(fd, packet_sizes[*type - 1])) == NULL) {
        printf("read_data: Failed to read packet\n");
        return NULL;
    }

    return packet;
}
Ejemplo n.º 15
0
/*
 * read the length of an array and add it to tree
 */
static guint32
read_length(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
{
  guint32 length;
  int     length_of_array_length_type;
  guint8  tiny;

  tiny = tvb_get_guint8(tvb, *offset);

  /*  Is this the value already? */
  if (  tiny <= ETCH_TC_MAX_TINY_INT
        || tiny >= ETCH_TC_MIN_TINY_INT) {
    length = tiny;
    length_of_array_length_type = 1;
  } else {
    guint8 type_code;
    type_code = read_type(offset, tvb, etch_tree);
    length_of_array_length_type = get_byte_length(type_code);

    switch (length_of_array_length_type) {
    case 1:
      length = tvb_get_guint8(tvb, *offset);
      break;
    case 2:
      length = tvb_get_ntohs(tvb, *offset);
      break;
    case 4:
      length = tvb_get_ntohl(tvb, *offset);
      break;
    default:
      return 0;             /* error! */
    }
  }
  proto_tree_add_item(etch_tree, hf_etch_length, tvb, *offset,
                      length_of_array_length_type, ENC_BIG_ENDIAN);
  (*offset) += length_of_array_length_type;

  if (*offset + length < *offset) {
    /* overflow case
     * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8464 */
    length = tvb_reported_length_remaining(tvb, *offset);
  }
  return length;
}
Ejemplo n.º 16
0
/* Read a list of parameters.  Each parameter is a name and a type.
   The list ends with a ')'.  We have already read the '('.  */
static struct params *
read_params(int *poffset)
{
	char *token;
	struct params *ret, **pp, *p;
	int offset, size, rnd;

	ret = NULL;
	pp = &ret;
	token = read_token_no_eof();
	offset = 0;
	if (strcmp(token, ")") != 0) {
		while (1) {
			p = xmalloc(sizeof(struct params));
			p->name = token;
			p->type = read_type();
			p->next = NULL;
			*pp = p;
			pp = &p->next;

			size = type_size(p->type);
			rnd = size;
			if(rnd > structround)
				rnd = structround;
			if(offset%rnd)
				offset += rnd - offset%rnd;
			offset += size;

			token = read_token_no_eof();
			if (strcmp(token, ",") != 0)
				break;
			token = read_token_no_eof();
		}
	}
	if (strcmp(token, ")") != 0) {
		fprintf(stderr, "%s:%u: expected '('\n",
			file, lineno);
		exit(1);
	}
	if (poffset != NULL)
		*poffset = offset;
	return ret;
}
Ejemplo n.º 17
0
/*
 * read the length of an array and add it to tree
 */
static guint32
read_length(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
{
  guint32 length;
  int     length_of_array_length_type;
  guint8  tiny;

  tiny = tvb_get_guint8(tvb, *offset);

  /*  Is this the value already? */
  if (  tiny <= ETCH_TC_MAX_TINY_INT
        || tiny >= ETCH_TC_MIN_TINY_INT) {
    length = tiny;
    length_of_array_length_type = 1;
  } else {
    guint8 type_code;
    type_code = read_type(offset, tvb, etch_tree);
    length_of_array_length_type = get_byte_length(type_code);

    switch (length_of_array_length_type) {
    case 1:
      length = tvb_get_guint8(tvb, *offset);
      break;
    case 2:
      length = tvb_get_ntohs(tvb, *offset);
      break;
    case 4:
      length = tvb_get_ntohl(tvb, *offset);
      break;
    default:
      return 0;             /* error! */
    }
  }
  proto_tree_add_item(etch_tree, hf_etch_length, tvb, *offset,
                      length_of_array_length_type, ENC_BIG_ENDIAN);
  (*offset) += length_of_array_length_type;
  return length;
}
Ejemplo n.º 18
0
static void 
read_text(FILE *fob, mxArray **data, double dbu_to_uu)
{
   mxArray *pstruct;
   mxArray *pprop = NULL;
   uint16_t rtype, rlen;
   int nprop = 0;
   char tstr[TXTLEN+4];
   element_t text;
   const char *fields[] = {"internal", "xy", "prop", "text"};


   /* initialize element */
   init_element(&text, GDS_TEXT);

   /* output data structure */
   pstruct = mxCreateStructMatrix(1,1, 4, fields);

   /* read element properties */
   while (1) {
      
      if ( read_record_hdr(fob, &rtype, &rlen) )
	 mexErrMsgTxt("gds_read_element (text) :  could not read record header.");

      if (rtype == ENDEL)
	 break;

      switch (rtype) {

         case STRING:
	    if ( read_string(fob, tstr, rlen) )
	       mexErrMsgTxt("gds_read_element (text) :  could not read string.");
	    struct_set_string(pstruct, 3, tstr);
	    break;

         case TEXTTYPE:
	    text.dtype = read_type(fob);
	    break;

         case XY:
	    mxSetFieldByNumber(pstruct, 0, 1, read_xy(fob, rlen, dbu_to_uu));
	    break;

         case LAYER:
	    text.layer = read_layer(fob);
	    break;

         case PATHTYPE:
	    text.ptype = read_type(fob);
	    text.has |= HAS_PTYPE;
	    break;

         case WIDTH:
	    text.width = dbu_to_uu * read_width(fob);
	    text.has |= HAS_WIDTH;
	    break;

         case PRESENTATION:
	    if ( read_word(fob, &text.present) )
	       mexErrMsgTxt("gds_read_element (text) :  could not read presentation data.");
	    text.has |= HAS_PRESTN;
	    break;

         case STRANS:
	    if ( read_word(fob, &text.strans.flags) )
	       mexErrMsgTxt("gds_read_element (text) :  could not read strans data.");
	    text.has |= HAS_STRANS;
	    break;

         case MAG:
	    if ( read_real8(fob, &text.strans.mag) )
	       mexErrMsgTxt("gds_read_element (text) :  could not read magnification.");
	    text.has |= HAS_MAG;
	    break;

         case ANGLE:
	    if ( read_real8(fob, &text.strans.angle) )
	       mexErrMsgTxt("gds_read_element (text) :  could not read angle.");
	    text.has |= HAS_ANGLE;
	    break;

         case ELFLAGS:
	    text.elflags = read_elflags(fob);
	    text.has |= HAS_ELFLAGS;
	    break;

         case PLEX:
	    text.plex = read_plex(fob);
	    text.has |= HAS_PLEX;
	    break;

         case PROPATTR:
	    pprop = resize_property_structure(pprop, nprop+1);
	    mxSetFieldByNumber(pprop, nprop, 0, read_propattr(fob));
	    break;

         case PROPVALUE:
 	    mxSetFieldByNumber(pprop, nprop, 1, read_propvalue(fob,rlen));
	    nprop += 1;
	    break;

         default:
	    mexPrintf("Unknown record id: 0x%x\n", rtype);
	    mexErrMsgTxt("TEXT :  found unknown element property.");
      }
   }

   /* set prop field */
   if ( nprop ) {
      mxSetFieldByNumber(pstruct, 0, 2, pprop);
   }
   else {
      mxSetFieldByNumber(pstruct, 0, 2, empty_matrix());
   }

   /* store structure with element data */
   mxSetFieldByNumber(pstruct, 0, 0, copy_element_to_array(&text));

   /* return data */
   *data = pstruct;
}
Ejemplo n.º 19
0
custom_object_callable::custom_object_callable(bool is_singleton)
{
	if(is_singleton) {
		instance_ptr = this;
		set_type_name("custom_obj");
	}

	//make sure 'library' is initialized as a valid type.
	game_logic::get_library_definition();

	static const Property CustomObjectProperties[] = {
	{ "value", "any" },
	{ "_data", "any" },
	{ "arg", "object" },
	{ "consts", "any" },
	{ "type", "string" },
	{ "active", "any" },
	{ "lib", "library" },

	{ "time_in_animation", "int" },
	{ "time_in_animation_delta", "int" },
	{ "frame_in_animation", "int" },
	{ "level", "any" },

	{ "animation", "string/string|map" },
	{ "available_animations", "[string]" },

	{ "hitpoints", "int" },
	{ "max_hitpoints", "int" },
	{ "mass", "int" },
	{ "label", "string" },
	{ "x", "int/int|decimal" },
	{ "y", "int/int|decimal" },
	{ "xy", "[int]" },
	{ "z", "int" },

	{ "relative_x", "int/int|decimal" },
	{ "relative_y", "int/int|decimal" },
	{ "spawned_by", "null|custom_obj" },
	{ "spawned_children", "[custom_obj]" },

	{ "parent", "null|custom_obj" },
	{ "pivot", "string" },
	{ "zorder", "int" },
	{ "zsub_order", "int" },

	{ "previous_y", "int" },
	{ "x1", "int/int|decimal" },
	{ "x2", "int/int|decimal" },
	{ "y1", "int/int|decimal" },
	{ "y2", "int/int|decimal" },
	{ "w", "int" },
	{ "h", "int" },
	{ "mid_x", "int/int|decimal" },
	{ "mid_y", "int/int|decimal" },
	{ "mid_xy", "[int]" },
	{ "midpoint_x", "int/int|decimal" },
	{ "midpoint_y", "int/int|decimal" },
	{ "midpoint_xy", "[int]" },

    { "is_solid", "bool" },
	{ "solid_rect", "rect_obj" },
	{ "solid_mid_x", "int" },
	{ "solid_mid_y", "int" },
	{ "solid_mid_xy", "[int]" }, 

	{ "img_mid_x", "int" },
	{ "img_mid_y", "int" },
	{ "img_mid_xy", "int" },
	{ "img_w", "int" },
	{ "img_h", "int" },
	{ "img_wh", "int" },
	{ "front", "int" },
	{ "back", "int" },
	{ "cycle", "int" },
	{ "facing", "int" },
	
	{ "upside_down", "int" },
	{ "up", "int" },
	{ "down", "int" },
	{ "velocity_x", "int/int|decimal" },
	{ "velocity_y", "int/int|decimal" },
	{ "velocity_xy", "[int]" }, 

	{ "velocity_magnitude", "decimal" },
	{ "velocity_angle", "decimal" },

	{ "accel_x", "int/int|decimal" },
	{ "accel_y", "int/int|decimal" },
	{ "accel_xy", "[int]" },
	{ "gravity_shift", "int" },
	{ "platform_motion_x", "int" },

	{ "registry", "object" },
	{ "globals", "object" },
	{ "vars", "object" },
	{ "tmp", "object" },
	{ "group", "int" },

	{ "rotate", "decimal" },
	{ "rotate_x", "decimal" },
	{ "rotate_y", "decimal" },
	{ "rotate_z", "decimal" },

	{ "me", "any" },
	{ "self", "any" },

	{ "red", "int" },
	{ "green", "int" },
	{ "blue", "int" },
	{ "alpha", "int" },
	{ "text_alpha", "int" },
	{ "damage", "int" },
	{ "hit_by", "null|custom_obj" },

	{ "distortion", "null|object" },
	{ "is_standing", "bool" },
	{ "standing_info", "null|object" },
	
	{ "near_cliff_edge", "bool" },
	{ "distance_to_cliff", "int" },
	
	{ "slope_standing_on", "int" },
	{ "underwater", "bool" },
	
	{ "previous_water_bounds", "[int]" },
	{ "water_bounds", "null|[int]" },
	{ "water_object", "null|custom_obj" },
	
	{ "driver", "null|custom_obj" },
	{ "is_human", "bool" },
	{ "invincible", "int" },
	
	{ "sound_volume", "int" },
	{ "destroyed", "bool" },
	{ "is_standing_on_platform", "null|bool|custom_obj" },
	{ "standing_on", "null|custom_obj" },
	
	{ "shader", "null|shader_program" },
	{ "effects", "[shader_program]" },
	{ "variations", "[string]" },
	
	{ "attached_objects", "[custom_obj]" },
	{ "call_stack", "[string]" },
	{ "lights", "[object]" },
	
	{ "solid_dimensions_in", "[string]" },
	{ "solid_dimensions_not_in", "[string]" },
	
	{ "collide_dimensions_in", "[string]" },
	{ "collide_dimensions_not_in", "[string]" },
	
	{ "brightness", "int" },
	{ "current_generator", "object" },
	{ "tags", "object" },
	{ "draw_area", "any" },
	{ "scale", "decimal" },
	
	{ "activation_area", "null|[int|decimal]" },
	{ "clip_area", "null|[int]" },

	{ "always_active", "bool" },
	{ "activation_border", "int/int|decimal" },
	{ "fall_through_platforms", "any" },
	{ "has_feet", "bool" },
	
	{ "x_schedule", "any" },
	{ "y_schedule", "any" },
	{ "rotation_schedule", "any" },
	{ "schedule_speed", "any" },
	
	{ "schedule_expires", "any" },
	
	{ "platform_area", "null|[int]" },
	{ "platform_offsets", "[int]" },
	{ "custom_draw", "list" },
	
	{ "uv_array", "[decimal]" },
	{ "xy_array", "[decimal]" },
	{ "uv_segments", "[int]" },
	
	{ "draw_primitives", "[object]/[object|map]|map" },
	{ "event_handlers", "object" },
	
	{ "use_absolute_screen_coordinates", "bool" },
	
	{ "widgets", "object/[object|map]|object|map" },
	{ "widget_list", "[widget]" },
	{ "textv", "any" },
	{ "body", "any" },
	{ "paused", "bool" },
	{ "mouseover_delay", "int" },
	{ "mouseover_area", "[int]" },
	{ "particle_systems", "{string -> object}" },

	{ "truez", "bool" },
	{ "tx", "decimal" },
	{ "ty", "decimal" },
	{ "tz", "decimal" },

	{ "animated_movements", "[string]" },

	{ "ctrl_user_output", "any" },
	
	{ "ctrl_up", "bool" },
	{ "ctrl_down", "bool" },
	{ "ctrl_left", "bool" },
	{ "ctrl_right", "bool" },
	
	{ "ctrl_attack", "bool" },
	{ "ctrl_jump", "bool" },
	{ "ctrl_tongue", "bool" },
	{ "ctrl_user", "any" },

	//player-specific
	{ "difficulty", "int" },
	{ "can_interact", "bool" },
	{ "underwater_controls", "bool" },
	{ "ctrl_mod_key", "int" },
	{ "ctrl_keys", "[string]" },
	{ "ctrl_mice", "[[int|string]]" },
	{ "ctrl_tilt", "int" },
	{ "ctrl_x", "int" },
	{ "ctrl_y", "int" },
	{ "ctrl_reverse_ab", "bool" },
	{ "control_scheme", "string" },
	{ "vertical_look", "int" },
	{ "control_lock", "null|[string]" },
};
	ASSERT_EQ(NUM_CUSTOM_OBJECT_PROPERTIES, sizeof(CustomObjectProperties)/sizeof(*CustomObjectProperties));

	if(global_entries().empty()) {
		for(int n = 0; n != sizeof(CustomObjectProperties)/sizeof(*CustomObjectProperties); ++n) {
			global_entries().push_back(entry(CustomObjectProperties[n].id));

			const std::string& type = CustomObjectProperties[n].type;
			std::string::const_iterator itor = std::find(type.begin(), type.end(), '/');
			std::string read_type(type.begin(), itor);
			global_entries().back().set_variant_type(parse_variant_type(variant(read_type)));

			if(itor != type.end()) {
				global_entries().back().write_type = parse_variant_type(variant(std::string(itor+1, type.end())));
			}
		}

		for(int n = 0; n != global_entries().size(); ++n) {
			keys_to_slots()[global_entries()[n].id] = n;
		}

		global_entries()[CUSTOM_OBJECT_ME].set_variant_type(variant_type::get_custom_object());
		global_entries()[CUSTOM_OBJECT_SELF].set_variant_type(variant_type::get_custom_object());

		const variant_type_ptr builtin = variant_type::get_builtin("level");
		global_entries()[CUSTOM_OBJECT_LEVEL].set_variant_type(builtin);
	}

	global_entries()[CUSTOM_OBJECT_PARENT].type_definition = is_singleton ? this : &instance();
	global_entries()[CUSTOM_OBJECT_LIB].type_definition = game_logic::get_library_definition().get();

	entries_ = global_entries();
}
Ejemplo n.º 20
0
static void 
read_box(FILE *fob, mxArray **data, double dbu_to_uu)
{
   mxArray *pstruct;
   mxArray *pprop = NULL;
   uint16_t rtype, rlen;
   int nprop = 0;
   element_t box;
   const char *fields[] = {"internal", "xy", "prop"};


   /* initialize element */
   init_element(&box, GDS_BOX);

   /* output data structure */
   pstruct = mxCreateStructMatrix(1,1, 3, fields);

   /* read element properties */
   while (1) {
      
      if ( read_record_hdr(fob, &rtype, &rlen) )
	 mexErrMsgTxt("gds_read_element (box) :  could not read record header.");

      if (rtype == ENDEL)
	 break;

      switch (rtype) {

         case XY:
	    mxSetFieldByNumber(pstruct, 0, 1, read_xy(fob, rlen, dbu_to_uu));
	    break;

         case LAYER:
	    box.layer = read_layer(fob);
	    break;

         case BOXTYPE:
	    box.dtype = read_type(fob);
	    break;

         case ELFLAGS:
	    box.elflags = read_elflags(fob);
	    box.has |= HAS_ELFLAGS;
	    break;

         case PLEX:
	    box.plex = read_plex(fob);
	    box.has |= HAS_PLEX;
	    break;

         case PROPATTR:
	    pprop = resize_property_structure(pprop, nprop+1);
	    mxSetFieldByNumber(pprop, nprop, 0, read_propattr(fob));
	    break;

         case PROPVALUE:
 	    mxSetFieldByNumber(pprop, nprop, 1, read_propvalue(fob,rlen));
	    nprop += 1;
	    break;

         default:
	    mexPrintf("Unknown record id: 0x%x\n", rtype);
	    mexErrMsgTxt("BOX :  found unknown element property.");
      }
   }

   /* set prop field */
   if ( nprop ) {
      mxSetFieldByNumber(pstruct, 0, 2, pprop);
   }
   else {
      mxSetFieldByNumber(pstruct, 0, 2, empty_matrix());
   }

   /* store structure with element data */
   mxSetFieldByNumber(pstruct, 0, 0, copy_element_to_array(&box));

   /* return data */
   *data = pstruct;
}
Ejemplo n.º 21
0
int parse(FILE *file)
{
  int head = read_header(file);

  if(head == false){
    printf("Invalid Clean C compiled file");
    return 1;
  }

  hash_t *var_map = malloc(sizeof(hash_t));
  hash_init(var_map, 1024);

  int ch = fgetc(file);
  while(ch != EOF){
    CODE code = ch - '0';
    switch(code){
      case PUSHS : {
        char type = read_type(file);
        if(type == 'S'){
          int length;
          fscanf(file, "%d", &length);
          char word[length+1];
          fgets(word, length+1, file);
          word[length+1]='\0';
          push(word);
        }
        break;
      }
      case PUSHV : {
        int length;
        fscanf(file, "%d", &length);
        char var[length+1];
        fgets(var, length+1, file);
        char *value = hash_lookup(var_map, var);
        push(value);
        break;
      }
      case ASSIGN : {
        int length;
        fscanf(file, "%d", &length);
        char var[length+1];
        fgets(var, length+1, file);

        char *value = pop();
        hash_insert(var_map, var, value);

        break;
      }
      case PRINT : {
        char *output = pop();
        printf("%s\n", output);
        break;
      }
      case END :
        return 0;
    }
    ch = fgetc(file);
  }

  free(var_map);
  return 0;
}
Ejemplo n.º 22
0
static void 
read_path(FILE *fob, mxArray **data, double dbu_to_uu) 
{
   mxArray *pstruct;
   mxArray *pprop = NULL;
   mxArray *pc;
   tList xylist;
   uint16_t rtype, rlen;
   int nprop = 0;
   int nle, k;
   element_t path;
   const char *fields[] = {"internal", "xy", "prop"};


   /* initialize element */
   init_element(&path, GDS_PATH);

   /* output data structure */
   pstruct = mxCreateStructMatrix(1,1, 3, fields);

   /* create a list for the XY data record(s) */
   if ( create_list(&xylist) == -1 )
      mexErrMsgTxt("gds_read_element (path) :  could not create list for XY records.");

   /* read element properties */
   while (1) {
      
      if ( read_record_hdr(fob, &rtype, &rlen) )
	 mexErrMsgTxt("gds_read_element (path) :  could not read record header.");

      if (rtype == ENDEL)
	 break;

      switch (rtype) {

         case XY:
	    if ( list_insert(xylist, read_xy(fob, rlen, dbu_to_uu), AFTER) == -1)
	       mexErrMsgTxt("gds_read_element (path) :  list insertion failed.");
	    break;

         case LAYER:
	    path.layer = read_layer(fob);
	    break;

         case PATHTYPE:
	    path.ptype = read_type(fob);
	    path.has |= HAS_PTYPE;
	    break;

         case WIDTH:
	    path.width = dbu_to_uu * (double)read_width(fob);
	    path.has |= HAS_WIDTH;
	    break;

         case BGNEXTN:
	    path.bgnextn = dbu_to_uu * read_extn(fob);
	    path.has |= HAS_BGNEXTN;
	    break;

         case ENDEXTN:
	    path.endextn = dbu_to_uu * read_extn(fob);
	    path.has |= HAS_ENDEXTN;
	    break;

         case DATATYPE:
	    path.dtype = read_type(fob);
	    break;

         case ELFLAGS:
	    path.elflags = read_elflags(fob);
	    path.has |= HAS_ELFLAGS;
	    break;

         case PLEX:
	    path.plex = read_plex(fob);
	    path.has |= HAS_PLEX;
	    break;

         case PROPATTR:
	    pprop = resize_property_structure(pprop, nprop+1);
	    mxSetFieldByNumber(pprop, nprop, 0, read_propattr(fob));
	    break;

         case PROPVALUE:
 	    mxSetFieldByNumber(pprop, nprop, 1, read_propvalue(fob,rlen));
	    nprop += 1;
	    break;

         default:
	    mexPrintf("Unknown record id: 0x%x\n", rtype);
	    mexErrMsgTxt("PATH :  found unknown element property.");
      }
   }

   /* cell array with XY records */
   nle = list_entries(xylist);
   if ( !nle )
      mexErrMsgTxt("gds_read_element (path) :  element has no XY record.");
   pc = mxCreateCellMatrix(1, nle);
   list_head(xylist);
   for (k=0; k<nle; k++)
      mxSetCell(pc, k, (mxArray *)get_current_entry(xylist, NULL));
   mxSetFieldByNumber(pstruct, 0, 1, pc);

   /* set prop field */
   if ( nprop ) {
      mxSetFieldByNumber(pstruct, 0, 2, pprop);
   }
   else {
      mxSetFieldByNumber(pstruct, 0, 2, empty_matrix());
   }

   /* store structure with element data */
   mxSetFieldByNumber(pstruct, 0, 0, copy_element_to_array(&path));

   /* return data */
   *data = pstruct;
}
Ejemplo n.º 23
0
int quicktime_atom_read_header(quicktime_t *file, quicktime_atom_t *atom)
{
	int result = 0;
	char header[10];

	if(file->use_avi)
	{
		reset(atom);
		atom->start = quicktime_position(file);
		if(!quicktime_read_data(file, header, HEADER_LENGTH)) return 1;
		atom->type[0] = header[0];
		atom->type[1] = header[1];
		atom->type[2] = header[2];
		atom->type[3] = header[3];
		atom->type[4] = 0;
		atom->size = 
			(((unsigned char)header[4])      ) |
			(((unsigned char)header[5]) << 8 ) |
			(((unsigned char)header[6]) << 16) |
			(((unsigned char)header[7]) << 24);
		atom->end = quicktime_add3(atom->start, atom->size, 8);
	}
	else
	{
		int64_t size2;

		reset(atom);

		atom->start = quicktime_position(file);

		if(!quicktime_read_data(file, header, HEADER_LENGTH)) return 1;
		result = read_type(header, atom->type);
		atom->size = read_size(header);
		atom->end = atom->start + atom->size;
/*
 * printf("quicktime_atom_read_header 1 %c%c%c%c start %llx size %llx end %llx ftell %llx %llx\n", 
 * 	atom->type[0], atom->type[1], atom->type[2], atom->type[3],
 * 	atom->start, atom->size, atom->end,
 * 	file->file_position,
 * 	(int64_t)FTELL(file->stream));
 */

/* Skip placeholder atom */
		if(quicktime_match_32(atom->type, "wide"))
		{
			atom->start = quicktime_position(file);
			reset(atom);
			if(!quicktime_read_data(file, header, HEADER_LENGTH)) return 1;
			result = read_type(header, atom->type);
			atom->size -= 8;
			if(atom->size <= 0)
			{
/* Wrapper ended.  Get new atom size */
				atom->size = read_size(header);
			}
			atom->end = atom->start + atom->size;
		}
		else
/* Get extended size */
		if(atom->size == 1)
		{
			if(!quicktime_read_data(file, header, HEADER_LENGTH)) return 1;
			atom->size = read_size64(header);
			atom->end = atom->start + atom->size;
/*
 * printf("quicktime_atom_read_header 2 %c%c%c%c start %llx size %llx end %llx ftell %llx\n", 
 * 	atom->type[0], atom->type[1], atom->type[2], atom->type[3],
 * 	atom->start, atom->size, atom->end,
 * 	file->file_position);
 */
		}
	}


	return result;
}
Ejemplo n.º 24
0
int main(int argc, char *argv[]) 
{
	key_t key;
	int msgqueue_id;
	struct mymsgbuf qbuf;

	/* Create unique key via call to ftok() */
	key = ftok(".", 'm');

	if ((msgqueue_id = msgget(key, IPC_CREAT | 0660)) == -1) 
	{
		perror("msgget");
		exit(1);
	}

  	int c = 0;
  	int i = 0;
  	client_type = read_type(msgqueue_id, &qbuf, TYPE_TYPE, 0);
  	char temp[2];
  	sprintf(temp, "%d", client_type + 1);
  	send_message(msgqueue_id, (struct mymsgbuf *) &qbuf, TYPE_TYPE, temp);

  	char buf[MAX_SEND_SIZE];
  	pid_t pid = fork();

	while (c != ESC_CODE) 
	{
		if (pid == 0)
		{
			struct mymsgbuf inpbuf;
			read_message(msgqueue_id, &inpbuf, client_type, 0);
		}
		else
		{
			c = getchar();
			if (i < MAX_SEND_SIZE) 
			{
		    	buf[i++] = c;
			} 
			else 
			{
	      		printf("Very big message!\n");
	      		i = 0;
	      		continue;
			}

			if (c == RETURN_CODE) 
			{
				if (i > 1) 
				{
			    	buf[i] = 0;
			    	struct mymsgbuf outbuf;
					send_message(msgqueue_id, (struct mymsgbuf *) &outbuf, MESSAGE_TYPE, buf);
			  	}
				i = 0;
			}
			
		}
	}
	
	printf("\n");

	return (0);
}