void VertexNormalAttribute::compute_vertex_normals_from_edge(Mesh& mesh) {
    const size_t dim = mesh.get_dim();
    assert(dim == 2);
    const size_t num_vertices = mesh.get_num_vertices();
    const size_t num_faces = mesh.get_num_faces();
    const size_t vertex_per_face = mesh.get_vertex_per_face();

    const VectorF& normals = get_attribute(mesh, "face_normal");

    VectorF& v_normals = m_values;
    v_normals = VectorF::Zero(dim * num_vertices);

    for (size_t i=0; i<num_faces; i++) {
        VectorI face = mesh.get_face(i);
        for (size_t j=0; j<vertex_per_face; j++) {
            size_t prev = (j-1+vertex_per_face) % vertex_per_face;
            size_t next = (j+1) % vertex_per_face;
            Vector2F prev_edge = mesh.get_vertex(face[j]) -
                mesh.get_vertex(face[prev]);
            Vector2F next_edge = mesh.get_vertex(face[next]) -
                mesh.get_vertex(face[j]);

            Vector3F n = normals.segment(i*3, 3);
            Vector3F e1(prev_edge[0], prev_edge[1], 0);
            Vector3F e2(next_edge[0], next_edge[1], 0);
            Vector3F n1 = e1.cross(n);
            Vector3F n2 = e2.cross(n);

            v_normals.segment(face[j]*dim, dim) += (n1 + n2).segment(0, dim);
        }
    }

    for (size_t i=0; i<num_vertices; i++) {
        Float norm = v_normals.segment(i*dim, dim).norm();
        if (norm > 1e-6) {
            v_normals.segment(i*dim, dim) /= norm;
        }
    }
}
static int
jcf_parse_one_method (JCF* jcf, int index)
{
  int i;
  uint16 access_flags = (JCF_FILL (jcf, 8), JCF_readu2 (jcf));
  uint16 name_index = JCF_readu2 (jcf);
  uint16 signature_index = JCF_readu2 (jcf);
  uint16 attribute_count = JCF_readu2 (jcf);
#ifdef HANDLE_METHOD
  HANDLE_METHOD(access_flags, name_index, signature_index, attribute_count);
#endif
  for (i = 0; i < attribute_count; i++)
    {
      int code = get_attribute (jcf, index, JV_METHOD_ATTR);
      if (code != 0)
	return code;
    }
#ifdef HANDLE_END_METHOD
  HANDLE_END_METHOD ();
#endif
  return 0;
}
bool shared_strings_serializer::read_shared_strings(const xml_document &xml, std::vector<std::string> &strings)
{
    strings.clear();

    auto root_node = xml.get_child("sst");
    auto unique_count = 0;

    if (root_node.has_attribute("uniqueCount"))
    {
        unique_count = std::stoull(root_node.get_attribute("uniqueCount"));
    }

    for (const auto &si_node : root_node.get_children())
    {
        if (si_node.get_name() != "si")
        {
            continue;
        }

        if (si_node.has_child("t"))
        {
            strings.push_back(si_node.get_child("t").get_text());
        }
        else if (si_node.has_child("r"))
        {
            strings.push_back(si_node.get_child("r").get_child("t").get_text());
        }
    }

    if (unique_count != strings.size())
    {
        throw std::runtime_error("counts don't match");
    }

    return true;
}
Resource* CreateGraphWidget( XMLIterator i, XMLCreatorEnv *env )
{
    XMLCreatorEnv ch_env;
    XMLAttributes attributes;
    XMLStyle      branch_style;
    CascadeStyles( i, env, attributes, branch_style, ch_env );

    std::string color = get_attribute( attributes, "color" );
    NormalPixel ncolor( to_hex( color ));

    int dotted = 0;
    try_attribute_i( attributes, "dotted", &dotted );

    GraphWidget *ptr = new GraphWidget( Dim2i( 100, 100 ), ncolor.c, 
                                        ( dotted ? GraphWidget::GT_POINTS : GraphWidget::GT_LINES ) 
                                      );
    
    std::string bounds;
    if ( try_attribute( attributes, "bounds", &bounds ))
    {
        std::vector< int > b = to_integer_vector( bounds );
        ptr->SetValueBounds( b[0], b[1], b[2], b[3] );
    }
    
    Useless::GraphWidget::tpe_input_vector initData( 100 );
    initData.resize(0);
    for ( double f=0.0; f <= 6.28; f += 3.14/100.0 )
    {
        double y = sin( f );
        initData.push_back( y );
    }
    ptr->SetInputData( initData );

    InsertChildWidget( ptr, attributes, env);    
    return new AnyResource<GraphWidget*>( ptr );
}
Beispiel #5
0
/* Read fields. */
static int
jcf_parse_fields (JCF* jcf)
{
  int i, j;
  uint16 fields_count;
  JCF_FILL (jcf, 2);
  fields_count = JCF_readu2 (jcf);

#ifdef HANDLE_START_FIELDS
  HANDLE_START_FIELDS (fields_count);
#endif
  for (i = 0; i < fields_count; i++)
    {
      uint16 access_flags = (JCF_FILL (jcf, 8), JCF_readu2 (jcf));
      uint16 name_index = JCF_readu2 (jcf);
      uint16 signature_index = JCF_readu2 (jcf);
      uint16 attribute_count = JCF_readu2 (jcf);
#ifdef HANDLE_START_FIELD
      HANDLE_START_FIELD (access_flags, name_index, signature_index,
			  attribute_count);
#endif
      for (j = 0; j < attribute_count; j++)
	{
	  int code = get_attribute (jcf, i, JV_FIELD_ATTR);
	  if (code != 0)
	    return code;
	}
#ifdef HANDLE_END_FIELD
      HANDLE_END_FIELD ();
#endif
    }
#ifdef HANDLE_END_FIELDS
  HANDLE_END_FIELDS ();
#endif
  return 0;
}
Beispiel #6
0
Datei: bs.c Projekt: MSch/MacRuby
bool 
bs_parser_parse(bs_parser_t *parser, const char *path, 
                const char *framework_path, bs_parse_options_t options, 
                bs_parse_callback_t callback, void *context, char **error)
{
  xmlTextReaderPtr reader;
  bs_element_function_t *func;
  bs_element_class_t *klass;
  bs_element_method_t *method;
  unsigned int i;
#define MAX_ARGS 128
  bs_element_arg_t args[MAX_ARGS];
  bs_element_arg_t fptr_args[MAX_ARGS];
  char *protocol_name = NULL;
  int func_ptr_arg_depth;
  bs_element_function_pointer_t *func_ptr;
  bool success;
  CFStringRef cf_path;
  bool nested_func_ptr;
  unsigned int version_number = 0;

  if (callback == NULL)
    return false;

  /* check if the given framework path has not been loaded already */
  cf_path = CFStringCreateWithFileSystemRepresentation(kCFAllocatorMalloc, 
    path);
  CFMakeCollectable(cf_path);
  for (unsigned i = 0, count = CFArrayGetCount(parser->loaded_paths);
       i < count; i++) {
    CFStringRef s = CFArrayGetValueAtIndex(parser->loaded_paths, i);
    if (CFStringCompare(cf_path, s, kCFCompareCaseInsensitive)
        == kCFCompareEqualTo) {
      /* already loaded */
      return true;
    }
  }

  CFArrayAppendValue(parser->loaded_paths, cf_path);

  //printf("parsing %s\n", path);

#define BAIL(fmt, args...)                      \
  do {                                          \
    if (error != NULL) {                        \
      char buf[1024];                           \
      snprintf(buf, sizeof buf,                 \
               "%s:%ld - "fmt, path,            \
               xmlGetLineNo(xmlTextReaderCurrentNode(reader)), \
               ##args);                         \
      *error = strdup(buf);                     \
    }                                           \
    success = false;                            \
    goto bails;                                 \
  }                                             \
  while (0)

#if __LP64__
# define CHECK_TYPE_ATTRIBUTE(var) CHECK_ATTRIBUTE(var, "type")
#else
# define CHECK_TYPE_ATTRIBUTE(var) \
    if (var == NULL && get_type64_attribute(reader) != NULL) { \
	break; \
    } \
    CHECK_ATTRIBUTE(var, "type")
#endif

#define CHECK_ATTRIBUTE_CAN_BE_EMPTY(a, name) \
  CHECK_ATTRIBUTE0(a, name, true)

#define CHECK_ATTRIBUTE(a, name) \
  CHECK_ATTRIBUTE0(a, name, false)

#define CHECK_ATTRIBUTE0(a, name, can_be_empty)         \
  do {                                                  \
    if (a == NULL)                                      \
      BAIL("expected attribute `%s' for element `%s'",  \
           name, xmlTextReaderConstName(reader));       \
    if (!can_be_empty && *a == '\0') {                  \
      free(a);                                          \
      BAIL("empty attribute `%s' for element `%s'",     \
           name, xmlTextReaderConstName(reader));       \
    }                                                   \
  } while (0)                                           \

  reader = xmlNewTextReaderFilename(path);
  if (reader == NULL)
    BAIL("cannot create XML text reader for file at path `%s'", path);

  func = NULL;
  func_ptr = NULL;
  func_ptr_arg_depth = -1;
  nested_func_ptr = false;
  klass = NULL;
  method = NULL;
  protocol_name = NULL;

  while (true) {
    const char *name;
    unsigned int namelen;
    int node_type = -1;
    bool eof = false;
    struct bs_xml_atom *atom;
    void *bs_element;
    bs_element_type_t bs_element_type = 0;

    do {
      int retval = xmlTextReaderRead(reader);
      if (retval == 0) {
        eof = true;
        break;
      }
      else if (retval < 0)
        BAIL("parsing error: %d", retval);

      node_type = xmlTextReaderNodeType(reader);
    }
    while (node_type != XML_READER_TYPE_ELEMENT 
           && node_type != XML_READER_TYPE_END_ELEMENT);    
    
    if (eof)
      break;

    name = (const char *)xmlTextReaderConstName(reader);
    namelen = strlen(name); 

    bs_element = NULL;

    atom = bs_xml_element(name, namelen);
    if (atom == NULL) {
      // TODO: we should include the "signatures" string into the gperf
      // function.
      if (version_number == 0 && strcmp(name, "signatures") == 0) {
        char *str = get_attribute(reader, "version");
        if (str != NULL) {
          char *p = strchr(str, '.');
          if (p != NULL) {
            *p = '\0';
            int major = atoi(str);
            int minor = atoi(&p[1]);
            assert(major < 10 && minor < 10);
            version_number = (major * 10) + minor;
            parser->version_number = version_number;
          }
          free(str);
        }
      }
      continue;
    }

    if (nested_func_ptr) {
      // FIXME: elements nesting function_pointers aren't supported yet by the
      // parser, so we just ignore them.
      if (node_type == XML_READER_TYPE_END_ELEMENT
          && (atom->val == BS_XML_FUNCTION || atom->val == BS_XML_METHOD)) {
        nested_func_ptr = false;
      }
      continue;
    }

    if (node_type == XML_READER_TYPE_ELEMENT) {
      switch (atom->val) {
        case BS_XML_DEPENDS_ON:
        {
          char *depends_on_path;
          char bs_path[PATH_MAX];
          bool bs_path_found;
          
          depends_on_path = get_attribute(reader, "path");
          CHECK_ATTRIBUTE(depends_on_path, "path");

//printf("depends of %s\n", depends_on_path);
          
          bs_path_found = bs_find_path(depends_on_path, bs_path, 
                                       sizeof bs_path);
          if (bs_path_found) {
            if (!bs_parser_parse(parser, bs_path, depends_on_path, options, 
                                 callback, context, error)) {
              free(depends_on_path);
              return false;
	    }
          }
          free(depends_on_path);
          break;
        }

        case BS_XML_CONSTANT: 
        { 
          bs_element_constant_t *bs_const;
          char *const_name;
          char *const_type;

          const_name = get_attribute(reader, "name");
          CHECK_ATTRIBUTE(const_name, "name");
          const_type = get_type_attribute(reader);
          CHECK_TYPE_ATTRIBUTE(const_type);

          bs_const = (bs_element_constant_t *)
            malloc(sizeof(bs_element_constant_t));
          ASSERT_ALLOC(bs_const);

          bs_const->name = const_name;
          bs_const->type = const_type;
          bs_const->ignore = false;
          bs_const->suggestion = NULL;
          bs_const->magic_cookie = get_boolean_attribute(reader,
            "magic_cookie", false);

          bs_element = bs_const;
          bs_element_type = BS_ELEMENT_CONSTANT;
          break;
        }

        case BS_XML_STRING_CONSTANT:
        {
          bs_element_string_constant_t *bs_strconst;
          char *strconst_name;
          char *strconst_value;

          strconst_name = get_attribute(reader, "name");
          CHECK_ATTRIBUTE(strconst_name, "name");
          strconst_value = get_attribute(reader, "value");
          CHECK_ATTRIBUTE_CAN_BE_EMPTY(strconst_value, "value");

          bs_strconst = (bs_element_string_constant_t *)
            malloc(sizeof(bs_element_string_constant_t));
          ASSERT_ALLOC(bs_strconst);

          bs_strconst->name = strconst_name;
          bs_strconst->value = strconst_value;
          bs_strconst->nsstring = get_boolean_attribute(reader, "nsstring", 
            false);

          bs_element = bs_strconst;
          bs_element_type = BS_ELEMENT_STRING_CONSTANT;
          break;
        }

        case BS_XML_ENUM: 
        { 
          char *enum_name;
          char *enum_value;        

          enum_name = get_attribute(reader, "name");
          CHECK_ATTRIBUTE(enum_name, "name");

#if __LP64__
	  enum_value = get_attribute(reader, "value64");
	  if (enum_value == NULL)
#endif
	    enum_value = get_attribute(reader, "value");

#if BYTE_ORDER == BIG_ENDIAN
# define BYTE_ORDER_VALUE_ATTR_NAME "be_value"
#else
# define BYTE_ORDER_VALUE_ATTR_NAME "le_value"
#endif

          if (enum_value == NULL)
            enum_value = get_attribute(reader, BYTE_ORDER_VALUE_ATTR_NAME); 
          
          if (enum_value != NULL) {
            bs_element_enum_t *bs_enum;
   
            bs_enum = (bs_element_enum_t *)malloc(sizeof(bs_element_enum_t));
            ASSERT_ALLOC(bs_enum);

            bs_enum->name = enum_name;
            bs_enum->value = enum_value;
            bs_enum->ignore = get_boolean_attribute(reader, "ignore", false);
            bs_enum->suggestion = get_attribute(reader, "suggestion");
            
            bs_element = bs_enum;
            bs_element_type = BS_ELEMENT_ENUM;
          }
          break;
        }

        case BS_XML_STRUCT: 
        {
          bs_element_struct_t *bs_struct;
          char *struct_decorated_type;
          char *struct_name;
          char type[MAX_ENCODE_LEN];
          bs_element_struct_field_t fields[128];
          int field_count;

          struct_decorated_type = get_type_attribute(reader);
          CHECK_TYPE_ATTRIBUTE(struct_decorated_type);
          struct_name = get_attribute(reader, "name");
          CHECK_ATTRIBUTE(struct_name, "name");

          if (!undecorate_struct_type(struct_decorated_type, type, 
                                      sizeof type, fields, 128, 
                                      &field_count)) {
            BAIL("Can't handle structure '%s' with type '%s'", 
                 struct_name, struct_decorated_type);
          }

          free(struct_decorated_type);

          bs_struct = 
            (bs_element_struct_t *)malloc(sizeof(bs_element_struct_t));
          ASSERT_ALLOC(bs_struct);

          bs_struct->name = struct_name;
          bs_struct->type = strdup(type);
          
          bs_struct->fields = (bs_element_struct_field_t *)malloc(
            sizeof(bs_element_struct_field_t) * field_count);
          ASSERT_ALLOC(bs_struct->fields);
          memcpy(bs_struct->fields, fields, 
                 sizeof(bs_element_struct_field_t) * field_count); 
          
          bs_struct->fields_count = field_count;
          bs_struct->opaque = get_boolean_attribute(reader, "opaque", false);

          bs_element = bs_struct;
          bs_element_type = BS_ELEMENT_STRUCT;
          break;
        }

        case BS_XML_OPAQUE:
        {
          bs_element_opaque_t *bs_opaque;
          char *opaque_name;
          char *opaque_type;

          opaque_name = get_attribute(reader, "name");
          CHECK_ATTRIBUTE(opaque_name, "name");
          opaque_type = get_type_attribute(reader);
          CHECK_TYPE_ATTRIBUTE(opaque_type);

          bs_opaque = 
            (bs_element_opaque_t *)malloc(sizeof(bs_element_opaque_t));
          ASSERT_ALLOC(bs_opaque);
          
          bs_opaque->name = opaque_name;
          bs_opaque->type = opaque_type;
          
          bs_element = bs_opaque;
          bs_element_type = BS_ELEMENT_OPAQUE;
          break;
        }
        
        case BS_XML_CFTYPE:
        {
          bs_element_cftype_t *bs_cftype;
          char *cftype_name;
          char *cftype_type;

          cftype_name = get_attribute(reader, "name");
          CHECK_ATTRIBUTE(cftype_name, "name");
          cftype_type = get_type_attribute(reader);
          CHECK_TYPE_ATTRIBUTE(cftype_type);

          bs_cftype = 
            (bs_element_cftype_t *)malloc(sizeof(bs_element_cftype_t));
          ASSERT_ALLOC(bs_cftype);

          bs_cftype->name = cftype_name;
          bs_cftype->type = cftype_type;

#if 1
          /* the type_id field isn't used in MacRuby */
          bs_cftype->type_id = 0;
#else
          char *cftype_gettypeid_func_name;
          cftype_gettypeid_func_name = get_attribute(reader, "gettypeid_func");
          if (cftype_gettypeid_func_name != NULL) {
            void *sym;

            sym = dlsym(RTLD_DEFAULT, cftype_gettypeid_func_name);
            if (sym == NULL) {
              BAIL("cannot locate gettypeid_func function `%s'",
                   cftype_gettypeid_func_name);
            }
            else {
              CFTypeID (*cb)(void) = sym;
              bs_cftype->type_id = (*cb)();
            }
          }
          else {
            bs_cftype->type_id = 0;
          }
#endif

          bs_cftype->tollfree = get_attribute(reader, "tollfree");

          bs_element = bs_cftype;
          bs_element_type = BS_ELEMENT_CFTYPE;
          break;
        }
        
        case BS_XML_INFORMAL_PROTOCOL: 
        {
	  if (protocol_name != NULL)
	    free(protocol_name);
          protocol_name = get_attribute(reader, "name");
          CHECK_ATTRIBUTE(protocol_name, "name");
          break;
        }

        case BS_XML_FUNCTION: 
        {
          char *func_name;
          
          func_name = get_attribute(reader, "name");
          CHECK_ATTRIBUTE(func_name, "name");

          func = 
            (bs_element_function_t *)malloc(sizeof(bs_element_function_t));
          ASSERT_ALLOC(func);

          func->name = func_name;
          func->variadic = get_boolean_attribute(reader, "variadic", false);
          func->args_count = 0;
          func->args = NULL;
          func->retval = NULL;

          if (xmlTextReaderIsEmptyElement(reader)) {
            bs_element = func;
            bs_element_type = BS_ELEMENT_FUNCTION;
            func = NULL;
          }
          break;
        }

        case BS_XML_FUNCTION_ALIAS: 
        {
          bs_element_function_alias_t *bs_func_alias;
          char *alias_name;
          char *alias_original;

          alias_name = get_attribute(reader, "name"); 
          CHECK_ATTRIBUTE(alias_name, "name");
          alias_original = get_attribute(reader, "original");
          CHECK_ATTRIBUTE(alias_original, "original");

          bs_func_alias = (bs_element_function_alias_t *)malloc(
            sizeof(bs_element_function_alias_t));
          ASSERT_ALLOC(bs_func_alias);
          
          bs_func_alias->name = alias_name;
          bs_func_alias->original = alias_original;

          bs_element = bs_func_alias;
          bs_element_type = BS_ELEMENT_FUNCTION_ALIAS;
          break;
        }

        case BS_XML_CLASS: 
        {
          char *class_name;
          
          class_name = get_attribute(reader, "name");
          CHECK_ATTRIBUTE(class_name, "name");
        
          klass = (bs_element_class_t *)malloc(sizeof(bs_element_class_t));
          ASSERT_ALLOC(klass);
            
          klass->name = class_name;
          klass->class_methods = klass->instance_methods = NULL;
          klass->class_methods_count = klass->instance_methods_count = 0;
          break;
        }

        case BS_XML_ARG:
        {
          if (func != NULL || method != NULL || func_ptr != NULL) {
            bs_element_arg_t *bs_arg; 
            unsigned *argc;

            argc = func_ptr != NULL
              ? &func_ptr->args_count
              : func != NULL 
                ? &func->args_count 
                : &method->args_count;

            if (*argc >= MAX_ARGS) {
              if (func_ptr != NULL)
                BAIL("maximum number of arguments (%d) reached " \
                     "for function pointer", MAX_ARGS);
              else if (func != NULL)
                BAIL("maximum number of arguments (%d) reached " \
                     "for function '%s'", MAX_ARGS, func->name);
              else
                BAIL("maximum number of arguments (%d) reached " \
                     "for method '%s'", MAX_ARGS, (char *)method->name);
            } 

	    bs_element_arg_t *args_from =
		(func_ptr == NULL ? args : fptr_args);
	    bs_arg = &args_from[(*argc)++];

            if (method != NULL && func_ptr == NULL) {
              char *index = get_attribute(reader, "index");
              CHECK_ATTRIBUTE(index, "index");
              bs_arg->index = strtol(index, NULL, 10);
              free(index);
            }
            else {
              bs_arg->index = -1;
            }
            
            get_type_modifier_attribute(reader, &bs_arg->type_modifier);

#if __LP64__
            bs_arg->sel_of_type = get_attribute(reader, "sel_of_type64");
            if (bs_arg->sel_of_type == NULL)
#endif
              bs_arg->sel_of_type = get_attribute(reader, "sel_of_type");

            bs_arg->printf_format = get_boolean_attribute(reader, 
                "printf_format", false); 
            bs_arg->null_accepted = get_boolean_attribute(reader, 
                "null_accepted", true);
            get_c_ary_type_attribute(reader, 
                &bs_arg->carray_type, &bs_arg->carray_type_value); 
  
            bs_arg->type = get_type_attribute(reader);

            if (get_boolean_attribute(reader, "function_pointer", false)) {
              if (func_ptr != NULL) {
                func_ptr = NULL; 
		nested_func_ptr = true;
		break;
	      }
              bs_arg->function_pointer = (bs_element_function_pointer_t *)
                calloc(1, sizeof(bs_element_function_pointer_t));
              ASSERT_ALLOC(bs_arg->function_pointer);
              func_ptr = bs_arg->function_pointer;
              func_ptr_arg_depth = xmlTextReaderDepth(reader);
            }
	    else {
              bs_arg->function_pointer = NULL;
	    }
          }
          else {
            BAIL("argument defined outside of a " \
                 "function/method/function_pointer");
          }
          break;
        }

        case BS_XML_RETVAL: 
        {
          if (func != NULL || method != NULL || func_ptr != NULL) {
            bs_element_retval_t *bs_retval;  

            if (func_ptr != NULL) {
              if (func_ptr->retval != NULL)
                BAIL("function pointer return value defined more than once");
            }
            else if (func != NULL) {
              if (func->retval != NULL)
                BAIL("function '%s' return value defined more than once", 
                     func->name);
            }
            else if (method != NULL) {
              if (method->retval != NULL)
                BAIL("method '%s' return value defined more than once", 
                     (char *)method->name);
            }
    
            bs_retval = 
              (bs_element_retval_t *)malloc(sizeof(bs_element_retval_t));
            ASSERT_ALLOC(bs_retval);

            get_c_ary_type_attribute(reader, &bs_retval->carray_type, 
              &bs_retval->carray_type_value);

            bs_retval->type = get_type_attribute(reader);
            if (bs_retval->type != NULL)
              bs_retval->already_retained = 
                get_boolean_attribute(reader, "already_retained", false);

            if (func_ptr != NULL) {
              if (bs_retval->type != NULL) {
                func_ptr->retval = bs_retval;
              }
              else {
                free(bs_retval);
                BAIL("function pointer return value defined without type"); 
              }
            }
            else if (func != NULL) {
              if (bs_retval->type != NULL) {
                func->retval = bs_retval;
              }
              else {
                free(bs_retval);
#if !defined(__LP64__)
		if (get_type64_attribute(reader) != NULL) {
		    // The function has no 32-bit return value type and we
		    // run in 32-bit mode. We just ignore it.
		    func = NULL;
		    break;
		}
#endif
                BAIL("function '%s' return value defined without type", 
                     func->name);
              }
            }
            else {
              method->retval = bs_retval;
            }

            if (get_boolean_attribute(reader, "function_pointer", false)) {
              if (func_ptr != NULL) {
                func_ptr = NULL; 
		nested_func_ptr = true;
		break;
              }
              bs_retval->function_pointer = (bs_element_function_pointer_t *)
                calloc(1, sizeof(bs_element_function_pointer_t));
              ASSERT_ALLOC(bs_retval->function_pointer);
              func_ptr = bs_retval->function_pointer;
              func_ptr_arg_depth = xmlTextReaderDepth(reader);
            }
	    else {
              bs_retval->function_pointer = NULL;
	    }
          }
          else {
            BAIL("return value defined outside a function/method");
          }
          break;
        }

        case BS_XML_METHOD: 
        {
          if (protocol_name != NULL) {
            bs_element_informal_protocol_method_t *bs_informal_method;
            char *selector;
            char *method_type;

            selector = get_attribute(reader, "selector");
            CHECK_ATTRIBUTE(selector, "selector");
            
            method_type = get_type_attribute(reader);
            CHECK_TYPE_ATTRIBUTE(method_type);

            bs_informal_method = (bs_element_informal_protocol_method_t *)
              malloc(sizeof(bs_element_informal_protocol_method_t));
            ASSERT_ALLOC(bs_informal_method);

            bs_informal_method->name = sel_registerName(selector);
	    free(selector);
            bs_informal_method->class_method = 
              get_boolean_attribute(reader, "class_method", false);
            bs_informal_method->type = method_type;
            bs_informal_method->protocol_name = strdup(protocol_name);

            bs_element = bs_informal_method;
            bs_element_type = BS_ELEMENT_INFORMAL_PROTOCOL_METHOD;
          }
          else if (klass != NULL) {  
            char *selector;

            selector = get_attribute(reader, "selector");
            CHECK_ATTRIBUTE(selector, "selector");

            method = 
              (bs_element_method_t *)malloc(sizeof(bs_element_method_t));
            ASSERT_ALLOC(method);

            method->name = sel_registerName(selector);
	    free(selector);
            method->class_method = 
              get_boolean_attribute(reader, "class_method", false);
            method->variadic = 
              get_boolean_attribute(reader, "variadic", false);
            method->ignore = 
              get_boolean_attribute(reader, "ignore", false);
            method->suggestion = get_attribute(reader, "suggestion");
            method->args_count = 0;
            method->args = NULL;
            method->retval = NULL;

            if (xmlTextReaderIsEmptyElement(reader)) {
              goto index_method;
            }
          }
          else {
            BAIL("method defined outside a class or informal protocol");
          }
          break;
        }
      }
    }
    else if (node_type == XML_READER_TYPE_END_ELEMENT) {
      switch (atom->val) {
        case BS_XML_INFORMAL_PROTOCOL: 
        {
          protocol_name = NULL;
          break;
        }

        case BS_XML_RETVAL:
        case BS_XML_ARG: 
        {
          if (func_ptr != NULL 
              && func_ptr_arg_depth == xmlTextReaderDepth(reader)) {

	      bs_element_retval_t *retval = NULL;
	      bs_element_arg_t *arg = NULL;
	      unsigned args_count;

	      if (atom->val == BS_XML_RETVAL) {
		  retval = func != NULL ? func->retval : method->retval;
	      }
	      else {
		  args_count = func != NULL ? func->args_count
		      : method->args_count;
		  arg = &args[args_count - 1];
	      }

              // Determine if we deal with a block or a function pointer.
	      const char *old_type = (retval ? retval->type : arg->type);
              const char lambda_type = *old_type == '@'
		? _MR_C_LAMBDA_BLOCK
		: _MR_C_LAMBDA_FUNCPTR;

	      char tmp_type[1025]; // 3 less to fit <, type and >
	      char new_type[1028];

	      // Function ptr return type
	      strlcpy(tmp_type, func_ptr->retval->type, sizeof(tmp_type));
	      // Function ptr args
	      for (i = 0; i < func_ptr->args_count; i++) {
		  strlcat(tmp_type, fptr_args[i].type, sizeof(tmp_type));
	      }
	      // Clear the final type string
	      memset(new_type, 0, sizeof(new_type));
	      // Append the function pointer type
	      snprintf(new_type, sizeof(new_type), "%c%c%s%c",
		      _MR_C_LAMBDA_B, lambda_type, tmp_type, _MR_C_LAMBDA_E);

	      // Free the old values
	      if (retval) {
		  free(retval->type);
		  retval->type = strdup(new_type);
	      }
	      else {
		  free(arg->type);
		  arg->type = strdup(new_type);
	      }
            
	      if (func_ptr->args_count > 0) {
		  size_t len;
      
		  len = sizeof(bs_element_arg_t) * func_ptr->args_count;
		  func_ptr->args = (bs_element_arg_t *)malloc(len);
		  ASSERT_ALLOC(func_ptr->args);
		  memcpy(func_ptr->args, fptr_args, len);
	      }
	      else {
		  func_ptr->args = NULL;
	      }
                        
	      func_ptr = NULL;
	      func_ptr_arg_depth = -1;
          }
          break;
        }
 
        case BS_XML_FUNCTION: 
        {
          if (func == NULL) {
            break;
          }
          for (i = 0; i < func->args_count; i++) {
            if (args[i].type == NULL)
              BAIL("function '%s' argument #%d type not provided", 
                   func->name, i);
          }
    
          if (func->args_count > 0) {
            size_t len;
    
            len = sizeof(bs_element_arg_t) * func->args_count;
            func->args = (bs_element_arg_t *)malloc(len);
            ASSERT_ALLOC(func->args);
            memcpy(func->args, args, len);
          }

          bs_element = func;
          bs_element_type = BS_ELEMENT_FUNCTION;
          func = NULL;
          break;
        }

        case BS_XML_METHOD: 
        {
          bs_element_method_t *methods;
          unsigned *methods_count;
          
          if (method->args_count > 0) {
            size_t len;
      
            len = sizeof(bs_element_arg_t) * method->args_count;
            method->args = (bs_element_arg_t *)malloc(len);
            ASSERT_ALLOC(method->args);
            memcpy(method->args, args, len);
          }

index_method:
          methods = method->class_method 
            ? klass->class_methods : klass->instance_methods;

          methods_count = method->class_method
            ? &klass->class_methods_count : &klass->instance_methods_count;

          if (methods == NULL) {
            methods = (bs_element_method_t *)malloc(
              sizeof(bs_element_method_t) * (*methods_count + 1));
          }
          else {
            methods = (bs_element_method_t *)realloc(methods, 
              sizeof(bs_element_method_t) * (*methods_count + 1));
          }
          ASSERT_ALLOC(methods);

    //      methods[*methods_count] = method;
    // FIXME this is inefficient
          memcpy(&methods[*methods_count], method, 
            sizeof(bs_element_method_t));

          (*methods_count)++;
          
          if (method->class_method)
            klass->class_methods = methods;
          else
            klass->instance_methods = methods;
         
          free(method);
          method = NULL;
          break;
        }

        case BS_XML_CLASS: 
        {
          bs_element = klass;
          bs_element_type = BS_ELEMENT_CLASS;
          klass = NULL;
          break;
        }
      }
    }

    if (bs_element != NULL)
      (*callback)(parser, path, bs_element_type, bs_element, context);
  }
  
  success = true;

bails:
  if (protocol_name != NULL)
    free(protocol_name);

  xmlFreeTextReader(reader);

  if (!success) {
      for (unsigned i = 0, count = CFArrayGetCount(parser->loaded_paths);
	      i < count; i++) {
	  CFStringRef s = CFArrayGetValueAtIndex(parser->loaded_paths, i);
	  if (CFStringCompare(cf_path, s, kCFCompareCaseInsensitive)
		  == kCFCompareEqualTo) {
	      CFArrayRemoveValueAtIndex(parser->loaded_paths, i);
	      break;
	  }
      }
  }

  if (success && options == BS_PARSE_OPTIONS_LOAD_DYLIBS && framework_path != NULL) {
    char buf[PATH_MAX];

    if (_bs_find_path(framework_path, buf, sizeof buf, "dylib")) {
      if (dlopen(buf, RTLD_LAZY) == NULL) {
        if (error != NULL) {
          *error = dlerror();
        }
        success = false;
      }
    }
  }

  return success;
}
Beispiel #7
0
Widget_Assembly Dynamic_Server::request
    ( const std::string& node
    , const int& u
    , const int& g)
{
    user_id = u;
    group_id = g;

    Widget_Assembly assembly {};
    Redis::Node_Editor wnode {Prefix::widget, node};
    std::string source_declaration {get_attribute(&wnode, Mogu_Syntax::source)};
    Source_Declaration_Parser sdp {source_declaration};
    Source_Declaration_Type source_type {sdp.get_type()};

    std::vector <std::string>&& data_list = fill_data_list(wnode,sdp);

    Attribute_Tuple&& t {
        merge_node_attributes(node, get_attribute(
            &wnode, Mogu_Syntax::template_))
    };

    Attribute_Map&& m {std::get<2>(t)};

    std::vector <std::string>&& child_declarations {std::get<0>(t)};
    size_t num_children {data_list.size()};

    std::tuple <const Syntax_Def&,int>&& sort_info 
        {parse_sort_definition(m[Mogu_Syntax::sort.integer])};

    std::vector <Sortable> sortable_containers {};

    for (size_t i = 0; i < num_children; ++i)
    {
        Sortable k {};
        std::string key {};

        std::string data_point {data_list[i]};

        Widget_Assembly& w = k.get_assembly();

        for (size_t j = 0; j < child_declarations.size(); ++j)
        {
            Widget_Assembly&& anon
            {
                source_type != Source_Declaration_Type::alias ?
                    spawn_anonymous_assembly(
                        data_point, child_declarations[j], source_type)
                    : spawn_anonymous_assembly(
                        data_point, child_declarations[j]
                        , sdp.get_alias_type())
            };

            local_cache.add(anon);

            if (j==(size_t) std::get<1>(sort_info))
                key = (std::string) anon.attrdict[Mogu_Syntax::text.integer];

            w.children.push_back(anon.node);
        }

        k.set_key(key);
        w.attrdict = m;
        w.node = create_unique_node_name();
        w.trigger_map = std::get<1>(t);
        local_cache.add(w);
        sortable_containers.push_back(k);
    }

    sort(std::get<0>(sort_info),sortable_containers);

    for (size_t i = 0; i < sortable_containers.size(); ++i)
    {
        assembly.children.push_back(sortable_containers[i].get_assembly().node);
    }

    return assembly;
}
  attribute get_attribute(handle const& loc,
			  const char* attr_name)
  {
    return get_attribute(loc, ".", attr_name);
  }
static void parse_element(rapidxml::xml_node<>* node, configuration const& config, std::string const& parent, Element& el)
{
    if (node != NULL)
    {
        std::string name = node->name();
        std::string full = parent + "." + name;

        if (full == ".briefdescription.para")
        {
            parse_para(node, el.brief_description, el.skip);
        }
        else if (full == ".detaileddescription.para")
        {
            std::string para;
            parse_para(node, para, el.skip);
            if (!para.empty() && !el.detailed_description.empty())
            {
                el.detailed_description += "\n\n";
            }
            el.detailed_description += para;
        }
        else if (full == ".location")
        {
            std::string loc = get_attribute(node, "file");
            // Location of (header)file. It is a FULL path, so find the start
            // and strip the rest
            std::size_t pos = loc.rfind(config.start_include);
            if (pos != std::string::npos)
            {
                loc = loc.substr(pos);
            }
            el.location = loc;
            el.line = atol(get_attribute(node, "line").c_str());
        }
        else if (full == ".detaileddescription.para.qbk")
        {
            el.qbk_markup.push_back(markup(node->value()));
        }
        else if (full == ".detaileddescription.para.qbk.after.synopsis")
        {
            el.qbk_markup.push_back(markup(markup_after, markup_synopsis, node->value()));
        }
        else if (full == ".detaileddescription.para.qbk.before.synopsis")
        {
            el.qbk_markup.push_back(markup(markup_before, markup_synopsis, node->value()));
        }
        else if (full == ".detaileddescription.para.qbk.distinguish")
        {
            el.additional_description = node->value();
            boost::trim(el.additional_description);
        }
        else if (full == ".templateparamlist")
        {
            parse_parameter_list(node->first_node(), el.template_parameters);
        }
        else if (full == ".detaileddescription.para.parameterlist")
        {
            std::string kind = get_attribute(node, "kind");
            if (kind == "param")
            {
                parse_parameter_list(node->first_node(), el.parameters);
            }
            else if (kind == "templateparam")
            {
                parse_parameter_list(node->first_node(), el.template_parameters);
            }
        }

        parse_element(node->first_node(), config, full, el);
        parse_element(node->next_sibling(), config, parent, el);
    }
}
Beispiel #10
0
int main(int argc, char ** argv)
{
	static char filename[1000] = "";
	static char name_column_name[100] = "NAME";
	static char variable_name[100] = "blocks";
	
	static int as_simple_shapes = 0;
	
	int c;
	while (1)
	{
		static struct option long_options[] = {
			{"filename", required_argument, 0, 'f'},
			{"name", required_argument, 0, 'n'},
			{"variable_name", required_argument, 0, 'v'},
			{"shapes", no_argument, &as_simple_shapes, 's'},
			{0, 0, 0, 0}
		};
		
		int option_index = 0;
		c = getopt_long(argc, argv, "f:n:v:", long_options, &option_index);
		if (c == -1) break;
		
		switch (c)
		{
			case 0: break;
			case 'f': strncpy(filename, optarg, sizeof(filename)); break;
			case 'n': strncpy(name_column_name, optarg, sizeof(name_column_name)); break;
			case 'v': strncpy(variable_name, optarg, sizeof(variable_name)); break;
			default: abort();
		}
	}
	
	if (filename[0] == 0 && argc == 2 && argv[1] != NULL)
		strncpy(filename, argv[1], sizeof(filename));
	
	FILE * fp = (filename[0] != 0) ? fopen(filename, "w") : NULL;
	
	if (fp == NULL || filename[0] == 0)
	{
		fprintf(stderr, "ERROR: Usage: %s --filename=[file_name]\n", argv[0]);
		return -1;
	}
	
	fprintf(fp, "var %s = {\n", variable_name);
	fprintf(fp, "  \"blocks\": [\n");
	
	struct Block * block = NULL;
	while ((block = read_block(stdin)))
	{
		int name_column_id = get_column_id_by_name(block, name_column_name);
		
		fprintf(fp, "    {\n");
		
		fprintf(fp, "      \"attributes\": [");
		int attr_id;
		for (attr_id = 0 ; attr_id < block->num_attributes ; attr_id++) {
			struct Attribute * attr = get_attribute(block, attr_id);
			fprintf(fp, "%s\n        [\"%s\", ", (attr_id == 0 ? "" : ","), attribute_get_name(attr));
			if (attr->type == TYPE_CHAR) {
				fprintf(fp, "\"");
			}
			fprintf_attribute_value(fp, block, attr_id); // suppose to addslashes, but I don't want to write that code right now
			if (attr->type == TYPE_CHAR) {
				fprintf(fp, "\"");
			}
			fprintf(fp, "]");
		}
		fprintf(fp, "\n      ],\n");
		fprintf(fp, "      \"columns\": [");
		int column_id;
		for (column_id = 0 ; column_id < block->num_columns ; column_id++) {
			struct Column * column = get_column(block, column_id);
			fprintf(fp, "%s\n        [\"%s\", \"%s\"]", (column_id == 0 ? "" : ","), column_get_name(column), get_type_name(column->type, column->bsize));
		}
		fprintf(fp, "\n      ],\n");
		
		if (as_simple_shapes) {
			fprintf(fp, "      \"shapes\": [");
			int shape_start_id = 0, shape_end_id;
			while ((shape_end_id = get_next_shape_start(block, shape_start_id))) {
				//int shape_row_id = get_cell_as_int32(block, shape_start_id, shape_row_id_column_id);
				fprintf(fp, "%s\n        {", (shape_start_id==0) ? "" : ",");
				if (name_column_id != -1) {
					fprintf(fp, "\n          \"name\":\"%s\",", (char*)get_cell(block, shape_start_id, name_column_id));
				}
				fprintf(fp, "\n          \"parts\":[");
				
				// foreach part of shape
				int part_start_id = shape_start_id, part_end_id;
				while ((part_end_id = get_next_part_start(block, part_start_id))) {
					//int shape_part_id = get_cell_as_int32(block, shape_start_id, shape_row_id_column_id);
					fprintf(fp, "%s\n            [", (part_start_id==shape_start_id) ? "" : ",");
					
					int i;
					for (i = part_start_id ; i < part_end_id ; i++) {
						fprintf(fp, "%s[%.6f,%.6f]", (i==part_start_id) ? "" : ",", get_x(block, i), get_y(block, i));
					}
					
					fprintf(fp, "]");
					if (part_end_id == shape_end_id) {
						break; // last part of shape
					}
					part_start_id = part_end_id;
				}
				fprintf(fp, "\n          ]");
				
				fprintf(fp, "\n        }");
				if (shape_end_id == block->num_rows) {
					break; // last shape
				}
				shape_start_id = shape_end_id;
			}
			fprintf(fp, "\n      ]\n");
		} else {
			fprintf(fp, "      \"data\": [");
			int row_id;
			for (row_id = 0 ; row_id < block->num_rows ; row_id++) {
				fprintf(fp, "%s\n        [", (row_id==0) ? "" : ",");
				for (column_id = 0 ; column_id < block->num_columns ; column_id++) {
					struct Column * column = get_column(block, column_id);
					if (column_id != 0) {
						fprintf(fp, ",");
					}
					if (column->type == TYPE_CHAR) {
						fprintf(fp, "\"");
					}
					fprintf_cell(fp, block, row_id, column_id);
					if (column->type == TYPE_CHAR) {
						fprintf(fp, "\"");
					}
				}
				fprintf(fp, "]");
			}
			fprintf(fp, "\n      ]\n");
		}
		
		/*
		int shape_start_id = 0, shape_end_id;
		while ((shape_end_id = get_next_shape_start(block, shape_start_id)))
		{
			int shape_row_id = get_cell_as_int32(block, shape_start_id, shape_row_id_column_id);
			
			if (name_column_id != -1) {
				fprintf(fp, "      \"name\":\"%s\",\n", (char*)get_cell(block, shape_start_id, name_column_id));
			}
			fprintf(fp, "      \"parts\":[");
			
			//fprintf(stderr, "shape = %d to %d (#%d)\n", shape_start_id, shape_end_id, shape_row_id);
			
			int part_start_id = shape_start_id, part_end_id;
			while ((part_end_id = get_next_part_start(block, part_start_id)))
			{
				int shape_part_id = get_cell_as_int32(block, shape_start_id, shape_row_id_column_id);
				
				fprintf(fp, "[");
				int i;
				for (i = part_start_id ; i < part_end_id ; i++)
				{
					fprintf(fp, "[%.6f,%.6f]%s", get_x(block, i), get_y(block, i), (i != part_end_id-1) ? "," : "");
					if (i % 10000 == 9999) { fprintf(fp, "\n"); }
				}
				
				fprintf(fp, "]");
				//fprintf(stderr, "	part = %d to %d (#%d)\n", part_start_id, part_end_id, shape_part_id);
				if (part_end_id == shape_end_id) break;
				fprintf(fp, ",");
				part_start_id = part_end_id;
			}
			
			fprintf(fp, "]\n");
			fprintf(fp, "    }%s", (shape_end_id == block->num_rows) ? "\n" : ",");
			
			if (shape_end_id == block->num_rows) break;
			//fprintf(fp, ",");
			shape_start_id = shape_end_id;
		}*/
		fprintf(fp, "    }\n");
		free_block(block);
	}
	fprintf(fp, "  ]\n");
	fprintf(fp, "};\n");
	
}
Beispiel #11
0
void Monster::set_jump(Map *map)
{
    set_vy(-get_attribute("jump_speed"));
    m_hit_ground = false;
    set_action(Jump);
}
Beispiel #12
0
/* Loads the levels described in the levels' configuratino file
 * If any sintax error is found, the program is aborted.
 */
void load_levels() {
    xml_node_t *root, **level, **aux;
    char *attr;
    int i;

    root = xml_parser(LEVELS_CONFIG_FILE);
    if(root->child_nodes == NULL || strcmp(root->child_nodes[0]->name, "chessdbot"))
        quit("Error: Malformed levels configuration file!\n");

    level = get_elements_by_tag_name(root, "level");
    if(level == NULL)
        quit("Error: Malformed levels configuration file!\n");

    for(num_levels = 0, aux = level; *aux; aux++, num_levels++);

    levels = (level_t **) malloc(num_levels * sizeof(level_t *));
    if(levels == NULL)
        quit("Error: Could not load levels configuration file!\n");

    for(i = 0; i < num_levels; i++) {
        levels[i] = (level_t *) malloc(sizeof(level_t));
        if(levels[i] == NULL)
            quit("Error: Could not load levels configuration file!\n");

        attr = get_attribute(level[i], "name");
        levels[i]->name = malloc((strlen(attr)+1) * sizeof(char));
        if(levels[i]->name == NULL)
            quit("Error: Could not load levels configuration file!\n");
        strcpy(levels[i]->name, attr);
        aux = get_elements_by_tag_name(level[i], "search");
        if(aux == NULL)
            quit("Error: Malformed levels configuration file!\n");
        attr = get_attribute(*aux, "max_depth");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->max_depth = atoi(attr);
        if(levels[i]->max_depth < 2)
            quit("Error: max_depth must be at least 2\n");
        attr = get_attribute(*aux, "max_seconds");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->max_seconds = atoi(attr);
        if(levels[i]->max_seconds < 1)
            quit("Error: max_seconds must be at least 1\n");
        free(aux);

        aux = get_elements_by_tag_name(level[i], "heuristic");
        if(aux == NULL)
            quit("Error: Malformed levels configuration file!\n");

        attr = get_attribute(*aux, "pawn_val");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->pawn_val = atoi(attr);
        if(levels[i]->pawn_val < 0)
            quit("Error: pawn_val must be at least 0\n");
        attr = get_attribute(*aux, "bishop_val");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bishop_val = atoi(attr);
        if(levels[i]->bishop_val < 0)
            quit("Error: bishop_val must be at least 0\n");
        attr = get_attribute(*aux, "knight_val");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->knight_val = atoi(attr);
        if(levels[i]->knight_val < 0)
            quit("Error: knight_val must be at least 0\n");
        attr = get_attribute(*aux, "rook_val");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->rook_val = atoi(attr);
        if(levels[i]->rook_val < 0)
            quit("Error: rook_val must be at least 0\n");
        attr = get_attribute(*aux, "queen_val");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->queen_val = atoi(attr);
        if(levels[i]->queen_val < 0)
            quit("Error: queen_val must be at least 0\n");
        attr = get_attribute(*aux, "king_val");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->king_val = atoi(attr);
        if(levels[i]->king_val < 0)
            quit("Error: king_val must be at least 0\n");
        attr = get_attribute(*aux, "factor_material");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->factor_material = atoi(attr);
        if(levels[i]->factor_material < 0)
            quit("Error: factor_material must be at least 0\n");
        attr = get_attribute(*aux, "factor_development");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->factor_development = atoi(attr);
        if(levels[i]->factor_development < 0)
            quit("Error: factor_development must be at least 0\n");
        attr = get_attribute(*aux, "factor_pawn");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->factor_pawn = atoi(attr);
        if(levels[i]->factor_pawn < 0)
            quit("Error: factor_pawn must be at least 0\n");
        attr = get_attribute(*aux, "factor_bishop");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->factor_bishop = atoi(attr);
        if(levels[i]->factor_bishop < 0)
            quit("Error: factor_bishop must be at least 0\n");
        attr = get_attribute(*aux, "factor_king");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->factor_king = atoi(attr);
        if(levels[i]->factor_king < 0)
            quit("Error: factor_king must be at least 0\n");
        attr = get_attribute(*aux, "factor_knight");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        if(levels[i]->factor_knight < 0)
            quit("Error: factor_knight must be at least 0\n");
        levels[i]->factor_knight = atoi(attr);
        attr = get_attribute(*aux, "factor_queen");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->factor_queen = atoi(attr);
        if(levels[i]->factor_queen < 0)
            quit("Error: factor_queen must be at least 0\n");
        attr = get_attribute(*aux, "factor_rook");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->factor_rook = atoi(attr);
        if(levels[i]->factor_rook < 0)
            quit("Error: factor_rook must be at least 0\n");
        attr = get_attribute(*aux, "bonus_early_queen_move");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_early_queen_move = atoi(attr);
        attr = get_attribute(*aux, "bonus_early_bishop_stuck");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_early_bishop_stuck = atoi(attr);
        attr = get_attribute(*aux, "bonus_early_knight_stuck");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_early_knight_stuck = atoi(attr);
        attr = get_attribute(*aux, "bonus_has_castled");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_has_castled = atoi(attr);
        attr = get_attribute(*aux, "bonus_hasnt_castled");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_hasnt_castled = atoi(attr);
        attr = get_attribute(*aux, "bonus_passed_pawn");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_passed_pawn = atoi(attr);
        attr = get_attribute(*aux, "bonus_isolated_pawn");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_isolated_pawn = atoi(attr);
        attr = get_attribute(*aux, "bonus_backward_pawn");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_backward_pawn = atoi(attr);
        attr = get_attribute(*aux, "bonus_doubled_pawn");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_doubled_pawn = atoi(attr);
        attr = get_attribute(*aux, "bonus_tripled_pawn");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_tripled_pawn = atoi(attr);
        attr = get_attribute(*aux, "bonus_doubled_bishop");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_doubled_bishop = atoi(attr);
        attr = get_attribute(*aux, "bonus_fianchetto_bishop");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_fianchetto_bishop = atoi(attr);
        attr = get_attribute(*aux, "bonus_knight_on_edge");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_knight_on_edge = atoi(attr);
        attr = get_attribute(*aux, "bonus_knight_on_hole");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_knight_on_hole = atoi(attr);
        attr = get_attribute(*aux, "bonus_rook_open_file");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_rook_open_file = atoi(attr);
        attr = get_attribute(*aux, "bonus_rook_halfopen_file");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_rook_halfopen_file = atoi(attr);
        attr = get_attribute(*aux, "bonus_queen_open_file");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_queen_open_file = atoi(attr);
        attr = get_attribute(*aux, "bonus_queen_halfopen_file");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_queen_halfopen_file = atoi(attr);
        attr = get_attribute(*aux, "bonus_center_control");
        if(attr == NULL)
            quit("Error: Malformed levels configuration file!\n");
        levels[i]->bonus_center_control = atoi(attr);
        free(aux);
    }
    free(level);
    clean_xml_node(root);
}
Beispiel #13
0
static void bit_putcs(struct vc_data *vc, struct fb_info *info,
		      const unsigned short *s, int count, int yy, int xx,
		      int fg, int bg)
{
	struct fb_image image;
	u32 width = DIV_ROUND_UP(vc->vc_font.width, 8);
	u32 cellsize = width * vc->vc_font.height;
	u32 maxcnt = info->pixmap.size/cellsize;
	u32 scan_align = info->pixmap.scan_align - 1;
	u32 buf_align = info->pixmap.buf_align - 1;
	u32 mod = vc->vc_font.width % 8, cnt, pitch, size;
	u32 attribute = get_attribute(info, scr_readw(s));
	u8 *dst, *buf = NULL;

	image.fg_color = fg;
	image.bg_color = bg;
	image.dx = xx * vc->vc_font.width;
	image.dy = yy * vc->vc_font.height;
	image.height = vc->vc_font.height;
	image.depth = 1;

	if (attribute) {
		buf = kmalloc(cellsize, GFP_KERNEL);
		if (!buf)
			return;
	}

	while (count) {
		if (count > maxcnt)
			cnt = maxcnt;
		else
			cnt = count;

		image.width = vc->vc_font.width * cnt;
		pitch = DIV_ROUND_UP(image.width, 8) + scan_align;
		pitch &= ~scan_align;
		size = pitch * image.height + buf_align;
		size &= ~buf_align;
		dst = fb_get_buffer_offset(info, &info->pixmap, size);
		image.data = dst;

		if (!mod)
			bit_putcs_aligned(vc, info, s, attribute, cnt, pitch,
					  width, cellsize, &image, buf, dst);
		else
			bit_putcs_unaligned(vc, info, s, attribute, cnt,
					    pitch, width, cellsize, &image,
					    buf, dst);

		image.dx += cnt * vc->vc_font.width;
		count -= cnt;
		s += cnt;
	}

	/* buf is always NULL except when in monochrome mode, so in this case
	   it's a gain to check buf against NULL even though kfree() handles
	   NULL pointers just fine */
	if (unlikely(buf))
		kfree(buf);

}
Beispiel #14
0
void Actor::move(Map *map)
{
    if (m_invisible_timer.expired(get_attribute("invisible_time"))) {
        set_invisible(false);
    }
}
Beispiel #15
0
bool Actor::animate_attack()
{
    bool result = false;

    if (m_attack_anim_timer.expired(get_attribute("attack_treshold"))) {
        switch(m_dir) {
            case Right:
                if (m_action == Attack) {
                    if (++m_frame > get_attribute("right_attack_end")) {
                        m_frame = get_attribute("right_attack_end");
                        result = true;
                    }
                }
                else if (m_action == AttackLow) {
                    if (++m_frame > get_attribute("right_attack_low_end")) {
                        m_frame = get_attribute("right_attack_low_end");
                        result = true;
                    }
                }
                break;

            case Left:
                if (m_action == Attack) {
                    if (++m_frame > get_attribute("left_attack_end")) {
                        m_frame = get_attribute("left_attack_end");
                        result = true;
                    }
                }
                else if (m_action == AttackLow) {
                    if (++m_frame > get_attribute("left_attack_low_end")) {
                        m_frame = get_attribute("left_attack_low_end");
                        result = true;
                    }
                }
                break;

            case Up:
                if (m_action == Attack) {
                    if (++m_frame > get_attribute("up_attack_end")) {
                        m_frame = get_attribute("up_attack_end");
                        result = true;
                    }
                }
                else if (m_action == AttackLow) {
                    if (++m_frame > get_attribute("up_attack_low_end")) {
                        m_frame = get_attribute("up_attack_low_end");
                        result = true;
                    }
                }
                break;

            case Down:
                if (m_action == Attack) {
                    if (++m_frame > get_attribute("down_attack_end")) {
                        m_frame = get_attribute("down_attack_end");
                        result = true;
                    }
                }
                else if (m_action == AttackLow) {
                    if (++m_frame > get_attribute("down_attack_low_end")) {
                        m_frame = get_attribute("down_attack_low_end");
                        result = true;
                    }
                }
                break;

            default:
                break;
        }
    }

    return result;
}
Beispiel #16
0
void Actor::animate_move()
{
    if (m_anim_timer.expired(get_attribute("treshold"))) {
        switch(m_dir) {
            case Right:
                if (m_anim_dir == AnimUp) {
                    if (++m_frame >= get_attribute("right_move_end")) {
                        m_frame = get_attribute("right_move_end");
                        m_anim_dir = AnimDown;
                    }
                }
                else if (m_anim_dir == AnimDown) {
                    if (--m_frame <= get_attribute("right_move_start")) {
                        m_frame = get_attribute("right_move_start");
                        m_anim_dir = AnimUp;
                    }
                }
                break;

            case Left:
                if (m_anim_dir == AnimUp) {
                    if (++m_frame >= get_attribute("left_move_end")) {
                        m_frame = get_attribute("left_move_end");
                        m_anim_dir = AnimDown;
                    }
                }
                else if (m_anim_dir == AnimDown) {
                    if (--m_frame <= get_attribute("left_move_start")) {
                        m_frame = get_attribute("left_move_start");
                        m_anim_dir = AnimUp;
                    }
                }
                break;

            case Up:
                if (m_anim_dir == AnimUp) {
                    if (++m_frame >= get_attribute("up_move_end")) {
                        m_frame = get_attribute("up_move_end");
                        m_anim_dir = AnimDown;
                    }
                }
                else if (m_anim_dir == AnimDown) {
                    if (--m_frame <= get_attribute("up_move_start")) {
                        m_frame = get_attribute("up_move_start");
                        m_anim_dir = AnimUp;
                    }
                }
                break;

            case Down:
                if (m_anim_dir == AnimUp) {
                    if (++m_frame >= get_attribute("down_move_end")) {
                        m_frame = get_attribute("down_move_end");
                        m_anim_dir = AnimDown;
                    }
                }
                else if (m_anim_dir == AnimDown) {
                    if (--m_frame <= get_attribute("down_move_start")) {
                        m_frame = get_attribute("down_move_start");
                        m_anim_dir = AnimUp;
                    }
                }
                break;

            default:
                break;
        }
    }
}
Beispiel #17
0
void Actor::set_dir(Direction dir)
{
    Direction set_dir;

    if (dir == Keep) {
        set_dir = m_dir;
    }
    else {
        set_dir = dir;
    }

    switch(m_action) {
        case Still:
            if (set_dir == Right) {
                m_frame = get_attribute("right_still");
            }
            else if (set_dir == Left) {
                m_frame = get_attribute("left_still");
            }
            else if (set_dir == Up) {
                m_frame = get_attribute("up_still");
            }
            else if (set_dir == Down) {
                m_frame = get_attribute("down_still");
            }
            break;

        case Move:
            if (set_dir == Right) {
                if (m_frame < get_attribute("right_move_start") ||
                    m_frame > get_attribute("right_move_end")) {
                    m_anim_dir = AnimUp;
                    m_frame = get_attribute("right_move_start");
                }
            }
            else if (set_dir == Left) {
                if (m_frame < get_attribute("left_move_start") ||
                    m_frame > get_attribute("left_move_end")) {
                    m_anim_dir = AnimUp;
                    m_frame = get_attribute("left_move_start");
                }
            }
            else if (set_dir == Up) {
                if (m_frame < get_attribute("up_move_start") ||
                    m_frame > get_attribute("up_move_end")) {
                    m_anim_dir = AnimUp;
                    m_frame = get_attribute("up_move_start");
                }
            }
            else if (set_dir == Down) {
                if (m_frame < get_attribute("down_move_start") ||
                    m_frame > get_attribute("down_move_end")) {
                    m_anim_dir = AnimUp;
                    m_frame = get_attribute("down_move_start");
                }
            }
            break;

        case Jump:
            if (set_dir == Right) {
                m_frame = get_attribute("right_jump");
            }
            else if (set_dir == Left) {
                m_frame = get_attribute("left_jump");
            }
            break;

        case Fall:
            if (set_dir == Right) {
                m_frame = get_attribute("right_fall");
            }
            else if (set_dir == Left) {
                m_frame = get_attribute("left_fall");
            }
            break;

        case Crouch:
            if (set_dir == Right) {
                m_frame = get_attribute("right_crouch");
            }
            else if (set_dir == Left) {
                m_frame = get_attribute("left_crouch");
            }
            break;

        case Attack:
            if (set_dir == Right) {
                if (m_frame < get_attribute("right_attack_start") ||
                    m_frame > get_attribute("right_attack_end")) {
                    m_frame = get_attribute("right_attack_start");
                }
            }
            else if (set_dir == Left) {
                if (m_frame < get_attribute("left_attack_start") ||
                    m_frame > get_attribute("left_attack_end")) {
                    m_frame = get_attribute("left_attack_start");
                }
            }
            else if (set_dir == Up) {
                if (m_frame < get_attribute("up_attack_start") ||
                    m_frame > get_attribute("up_attack_end")) {
                    m_frame = get_attribute("up_attack_start");
                }
            }
            else if (set_dir == Down) {
                if (m_frame < get_attribute("down_attack_start") ||
                    m_frame > get_attribute("down_attack_end")) {
                    m_frame = get_attribute("down_attack_start");
                }
            }
            break;

        case AttackLow:
           if (set_dir == Right) {
                if (m_frame < get_attribute("right_attack_low_start") ||
                    m_frame > get_attribute("right_attack_low_end")) {
                    m_frame = get_attribute("right_attack_low_start");
                }
            }
            else if (set_dir == Left) {
                if (m_frame < get_attribute("left_attack_low_start") ||
                    m_frame > get_attribute("left_attack_low_end")) {
                    m_frame = get_attribute("left_attack_low_start");
                }
            }
            else if (set_dir == Up) {
                if (m_frame < get_attribute("up_attack_low_start") ||
                    m_frame > get_attribute("up_attack_low_end")) {
                    m_frame = get_attribute("up_attack_low_start");
                }
            }
            else if (set_dir == Down) {
                if (m_frame < get_attribute("down_attack_low_start") ||
                    m_frame > get_attribute("down_attack_low_end")) {
                    m_frame = get_attribute("down_attack_low_start");
                }
            }
            break;

        case Hit:
            if (set_dir == Right) {
                m_frame = get_attribute("right_hit");
            }
            else if (set_dir == Left) {
                m_frame = get_attribute("left_hit");
            }
            break;

        default:
            break;
    }

    m_dir = set_dir;
}
Beispiel #18
0
void font::print_to_console ( QTextStream & stream )
{
	stream << QString::fromUtf8 ( "Содержит количество, созданных объектов font = " ) << s_font_main_count << endl;
	stream << QString::fromUtf8 ( "Имя файла оригинала                          = " ) << get_file_name() << endl;
	stream << QString::fromUtf8 ( "attribute                                    = " ) << get_attribute() << endl;
	stream << QString::fromUtf8 ( "Значение above                               = " ) << get_above() << endl;
	stream << QString::fromUtf8 ( "Значение below                               = " ) << get_below() << endl;
	stream << QString::fromUtf8 ( "Значение modes                               = " ) << get_modes() << endl;
	stream << QString::fromUtf8 ( "Количество символов в шрифте                 = " ) << m_forma_l_list->size() << endl;

	/*
	 stream << QString::fromUtf8 ( "Символы шрифта:" ) << endl;

	 for ( int i = 0; i < m_forma_l_list.size(); ++i )
	 {
	  stream << QString::fromUtf8 ( "Номер формы                                i = " ) << i << endl;
	  m_forma_l_list.at ( i ).print_to_console ( stream );
	 }
	*/
}
Beispiel #19
0
static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode,
		       int softback_lines, int fg, int bg)
{
	struct fb_cursor cursor;
	struct fbcon_ops *ops = info->fbcon_par;
	unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
	int w = DIV_ROUND_UP(vc->vc_font.width, 8), c;
	int y = real_y(ops->p, vc->vc_y);
	int attribute, use_sw = (vc->vc_cursor_type & 0x10);
	int err = 1;
	char *src;

	cursor.set = 0;

	if (softback_lines) {
		if (y + softback_lines >= vc->vc_rows) {
			mode = CM_ERASE;
			ops->cursor_flash = 0;
			return;
		} else
			y += softback_lines;
	}

 	c = scr_readw((u16 *) vc->vc_pos);
	attribute = get_attribute(info, c);
	src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height));

	if (ops->cursor_state.image.data != src ||
	    ops->cursor_reset) {
	    ops->cursor_state.image.data = src;
	    cursor.set |= FB_CUR_SETIMAGE;
	}

	if (attribute) {
		u8 *dst;

		dst = kmalloc(w * vc->vc_font.height, GFP_ATOMIC);
		if (!dst)
			return;
		kfree(ops->cursor_data);
		ops->cursor_data = dst;
		update_attr(dst, src, attribute, vc);
		src = dst;
	}

	if (ops->cursor_state.image.fg_color != fg ||
	    ops->cursor_state.image.bg_color != bg ||
	    ops->cursor_reset) {
		ops->cursor_state.image.fg_color = fg;
		ops->cursor_state.image.bg_color = bg;
		cursor.set |= FB_CUR_SETCMAP;
	}

	if ((ops->cursor_state.image.dx != (vc->vc_font.width * vc->vc_x)) ||
	    (ops->cursor_state.image.dy != (vc->vc_font.height * y)) ||
	    ops->cursor_reset) {
		ops->cursor_state.image.dx = vc->vc_font.width * vc->vc_x;
		ops->cursor_state.image.dy = vc->vc_font.height * y;
		cursor.set |= FB_CUR_SETPOS;
	}

	if (ops->cursor_state.image.height != vc->vc_font.height ||
	    ops->cursor_state.image.width != vc->vc_font.width ||
	    ops->cursor_reset) {
		ops->cursor_state.image.height = vc->vc_font.height;
		ops->cursor_state.image.width = vc->vc_font.width;
		cursor.set |= FB_CUR_SETSIZE;
	}

	if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
	    ops->cursor_reset) {
		ops->cursor_state.hot.x = cursor.hot.y = 0;
		cursor.set |= FB_CUR_SETHOT;
	}

	if (cursor.set & FB_CUR_SETSIZE ||
	    vc->vc_cursor_type != ops->p->cursor_shape ||
	    ops->cursor_state.mask == NULL ||
	    ops->cursor_reset) {
		char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
		int cur_height, size, i = 0;
		u8 msk = 0xff;

		if (!mask)
			return;

		kfree(ops->cursor_state.mask);
		ops->cursor_state.mask = mask;

		ops->p->cursor_shape = vc->vc_cursor_type;
		cursor.set |= FB_CUR_SETSHAPE;

		switch (ops->p->cursor_shape & CUR_HWMASK) {
		case CUR_NONE:
			cur_height = 0;
			break;
		case CUR_UNDERLINE:
			cur_height = (vc->vc_font.height < 10) ? 1 : 2;
			break;
		case CUR_LOWER_THIRD:
			cur_height = vc->vc_font.height/3;
			break;
		case CUR_LOWER_HALF:
			cur_height = vc->vc_font.height >> 1;
			break;
		case CUR_TWO_THIRDS:
			cur_height = (vc->vc_font.height << 1)/3;
			break;
		case CUR_BLOCK:
		default:
			cur_height = vc->vc_font.height;
			break;
		}
		size = (vc->vc_font.height - cur_height) * w;
		while (size--)
			mask[i++] = ~msk;
		size = cur_height * w;
		while (size--)
			mask[i++] = msk;
	}
Beispiel #20
0
void MekaDragon::move(Map *map)
{
    Monster::move(map);

    switch(m_action) {
        case Still:
            set_action(Move);
            break;

        case Move:
            face_reference(get_attribute("turn_width"));
            set_lock_direction(true);
            if (m_horizontal_dir == HorizontalForward) {

                if (m_dir == Right) {
                    set_vx(get_attribute("move_speed"));
                }
                else {
                    set_vx(-get_attribute("move_speed"));
                }
                animate_move();

                if (abs(m_xref - m_x) < get_attribute("attack_distance")) {
                    m_horizontal_dir = HorizontalBackward;
                }
            }
            else if (m_horizontal_dir == HorizontalBackward) {

                if (m_dir == Right) {
                    set_vx(-get_attribute("move_speed"));
                }
                else {
                    set_vx(get_attribute("move_speed"));
                }
                animate_move();

                if (abs(m_xref - m_x) > get_attribute("retreat_distance") ||
                    check_behind(map)) {
                    m_horizontal_dir = HorizontalForward;
                }
            }

            if (m_attack_now ||
                m_attack_timer.expired(get_attribute("attack_timer"))) {
                m_attack_timer.reset();
                m_attack_now = false;
                set_attack();
            }
            break;

        case Attack:
            if (m_idle_timer.check(get_attribute("attack_idle"))){
                fire();
            }
            break;

        case Hit:
            m_idle_timer.reset();
            m_attack_now = true;
            break;

        default:
            break;
    }

    unsigned n = m_bullets.size();
    for (unsigned i = 0; i < n; i++) {
        m_bullets[i]->move(map);
    }
}
Beispiel #21
0
void Material::aquire(WorldDB *db)
{
    if (get_attribute("once")) {
        db->remove(m_world_key);
    }
}
Beispiel #22
0
/**
 * Prints a character to the screen, is used
 * by kprintf and kputs
 *
 * @param c Character to print
 **/
void kputch(unsigned char c)
{
    unsigned short *where;
    unsigned att = get_attribute() << 8;


    if(c == 0x08)
    {
		/// ! SELBER SCHREIBEN !
        if(get_cursor_x() != 0) set_cursor_x(get_cursor_x() - 1);
    }

	//
    else if(c == 0x09)
    {
        int newx;

		/// ! SELBER SCHREIBEN !
        newx = (get_cursor_x() + 8) & ~(8 - 1);

        set_cursor_x(newx);
    }

	// Carriage return? Set the cursor to the beginning of the current line
    else if(c == '\r')
    {
		/// ! SELBER SCHREIBEN !
        set_cursor_x(0);
    }

	// Linefeed? Set the cursor to the next line
    else if(c == '\n')
    {
		/// ! SELBER SCHREIBEN !
        set_cursor_x(0);
        set_cursor_y(get_cursor_y() + 1);
    }

    else if(c >= ' ')
    {
		/// ! SELBER SCHREIBEN !
        //FIXME: get_textmemptr() doesn't work here (whyever...)
        where = (unsigned short*)0xB8000 + (get_cursor_y() * 80 + get_cursor_x());
        *where = c | att;
        set_cursor_x(get_cursor_x() + 1);
    }

	/// ! SELBER SCHREIBEN !

    // More than 80 lines? Scroll the screen
    if(get_cursor_x() >= 80)
    {
        set_cursor_x(0);
        set_cursor_y(get_cursor_y() + 1);
    }

	/// ! SELBER SCHREIBEN !

    // Scroll the screen and move the cursor
    scroll_screen();
    move_cursor();
}
Beispiel #23
0
static int
get_attribute (JCF *jcf, int index, 
	       jv_attr_type attr_type ATTRIBUTE_UNUSED)
{
  uint16 attribute_name = (JCF_FILL (jcf, 6), JCF_readu2 (jcf));
  uint32 attribute_length = JCF_readu4 (jcf);
  uint32 start_pos = JCF_TELL(jcf);
  int name_length;
  const unsigned char *name_data;
  JCF_FILL (jcf, (long) attribute_length);
  if (attribute_name <= 0 || attribute_name >= JPOOL_SIZE(jcf))
    return -2;
  if (JPOOL_TAG (jcf, attribute_name) != CONSTANT_Utf8)
    return -2;
  name_length = JPOOL_UTF_LENGTH (jcf, attribute_name);
  name_data = JPOOL_UTF_DATA (jcf, attribute_name);

#define MATCH_ATTRIBUTE(S) \
  (name_length == sizeof (S)-1 && memcmp (name_data, S, sizeof (S)-1) == 0)

#ifdef IGNORE_ATTRIBUTE
   if (IGNORE_ATTRIBUTE (jcf, attribute_name, attribute_length))
     {
       JCF_SKIP (jcf, attribute_length);
     }
   else
#endif
#ifdef HANDLE_SOURCEFILE
  if (MATCH_ATTRIBUTE ("SourceFile"))
    {
      uint16 sourcefile_index = JCF_readu2 (jcf);
      HANDLE_SOURCEFILE(sourcefile_index);
    }
  else
#endif
#ifdef HANDLE_CONSTANTVALUE
  if (MATCH_ATTRIBUTE ("ConstantValue"))
    {
      uint16 constantvalue_index = JCF_readu2 (jcf);
      if (constantvalue_index <= 0 || constantvalue_index >= JPOOL_SIZE(jcf))
	return -2;
      HANDLE_CONSTANTVALUE(constantvalue_index);
    }
  else
#endif
#ifdef HANDLE_CODE_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("Code"))
    {
      uint16 j;
      uint16 max_stack ATTRIBUTE_UNUSED = JCF_readu2 (jcf);
      uint16 max_locals ATTRIBUTE_UNUSED = JCF_readu2 (jcf);
      uint32 code_length = JCF_readu4 (jcf);
      uint16 exception_table_length, attributes_count;
      if (code_length + 12 > attribute_length)
	return -1;
      HANDLE_CODE_ATTRIBUTE(max_stack, max_locals, code_length);
      JCF_SKIP (jcf, code_length);
      exception_table_length = JCF_readu2 (jcf);
      if (code_length + 8 * exception_table_length + 12 > attribute_length)
	return -1;
#ifdef HANDLE_EXCEPTION_TABLE
      HANDLE_EXCEPTION_TABLE (jcf->read_ptr, exception_table_length);
#endif
      JCF_SKIP (jcf, 2 * 4 * exception_table_length);
      attributes_count = JCF_readu2 (jcf);
      for (j = 0; j < attributes_count; j++)
	{
	  int code = get_attribute (jcf, index, JV_METHOD_ATTR);
	  if (code != 0)
	    return code;
	}
    }
  else
#endif /* HANDLE_CODE_ATTRIBUTE */
#ifdef HANDLE_EXCEPTIONS_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("Exceptions"))
    {
      uint16 count = JCF_readu2 (jcf);
      HANDLE_EXCEPTIONS_ATTRIBUTE (count);
    }
  else
#endif
#ifdef HANDLE_LINENUMBERTABLE_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("LineNumberTable"))
    {
      uint16 count = JCF_readu2 (jcf);
      HANDLE_LINENUMBERTABLE_ATTRIBUTE (count);
    }
  else
#endif
#ifdef HANDLE_LOCALVARIABLETABLE_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("LocalVariableTable"))
    {
      uint16 count = JCF_readu2 (jcf);
      HANDLE_LOCALVARIABLETABLE_ATTRIBUTE (count);
    }
  else
#endif
#ifdef HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("LocalVariableTypeTable"))
    {
      uint16 count = JCF_readu2 (jcf);
      HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE (count);
    }
  else
#endif
#ifdef HANDLE_INNERCLASSES_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("InnerClasses"))
    {
      uint16 count = JCF_readu2 (jcf);
      HANDLE_INNERCLASSES_ATTRIBUTE (count);
    }
  else
#endif
#ifdef HANDLE_SYNTHETIC_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("Synthetic"))
    {
      HANDLE_SYNTHETIC_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_GCJCOMPILED_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("gnu.gcj.gcj-compiled"))
    {
      HANDLE_GCJCOMPILED_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_DEPRECATED_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("Deprecated"))
    {
      HANDLE_DEPRECATED_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_SOURCEDEBUGEXTENSION_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("SourceDebugExtension")) /* JSR 45 */
    {
      HANDLE_SOURCEDEBUGEXTENSION_ATTRIBUTE (attribute_length);
    }
  else
#endif
#ifdef HANDLE_ENCLOSINGMETHOD_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("EnclosingMethod"))
    {
      HANDLE_ENCLOSINGMETHOD_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_SIGNATURE_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("Signature"))
    {
      HANDLE_SIGNATURE_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("RuntimeVisibleAnnotations"))
    {
      HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("RuntimeInvisibleAnnotations"))
    {
      HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("RuntimeVisibleParameterAnnotations"))
    {
      HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("RuntimeInvisibleParameterAnnotations"))
    {
      HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("AnnotationDefault"))
    {
      HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE ();
    }
  else
#endif
  if (MATCH_ATTRIBUTE ("BootstrapMethods"))
    {
#ifdef HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE
      HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE();
#else
      JCF_SKIP (jcf, attribute_length);
#endif
    }
   else
    {
#ifdef PROCESS_OTHER_ATTRIBUTE
      PROCESS_OTHER_ATTRIBUTE(jcf, attribute_name, attribute_length);
#else
      JCF_SKIP (jcf, attribute_length);
#endif
    }
  if ((long) (start_pos + attribute_length) != JCF_TELL(jcf))
    return -1;
  return 0;
}
Beispiel #24
0
static void
keyboards_start_element_callback (GMarkupParseContext *pcontext,
                                  const gchar         *element_name,
                                  const gchar        **attribute_names,
                                  const gchar        **attribute_values,
                                  gpointer             user_data,
                                  GError             **error)
{
    KeyboardsParseData *data = user_data;

    if (!validate (keyboards_valid_path_list,
                   G_N_ELEMENTS (keyboards_valid_path_list),
                   element_name,
                   data->element_stack,
                   error))
        return;

    if (g_strcmp0 (element_name, "keyboard") == 0) {
        EekXmlKeyboardDesc *desc = g_slice_new0 (EekXmlKeyboardDesc);
        const gchar *attribute;

        data->keyboards = g_list_prepend (data->keyboards, desc);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "id");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"id\" attribute for \"keyboard\"");
            return;
        }
        desc->id = g_strdup (attribute);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "name");
        if (attribute)
            desc->name = g_strdup (attribute);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "geometry");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"geometry\" attribute for \"keyboard\"");
            return;
        }
        desc->geometry = g_strdup (attribute);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "symbols");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"symbols\" attribute for \"keyboard\"");
            goto out;
        }
        desc->symbols = g_strdup (attribute);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "longname");
        if (attribute)
            desc->longname = g_strdup (attribute);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "language");
        if (attribute)
            desc->language = g_strdup (attribute);
    }

 out:
    data->element_stack = g_slist_prepend (data->element_stack,
                                           g_strdup (element_name));
}
Beispiel #25
0
ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid)
{
    return (get_attribute(si->unauth_attr, nid));
}
Beispiel #26
0
static void
geometry_start_element_callback (GMarkupParseContext *pcontext,
                                 const gchar         *element_name,
                                 const gchar        **attribute_names,
                                 const gchar        **attribute_values,
                                 gpointer             user_data,
                                 GError             **error)
{
    GeometryParseData *data = user_data;
    const gchar *attribute;

    if (!validate (geometry_valid_path_list,
                   G_N_ELEMENTS (geometry_valid_path_list),
                   element_name,
                   data->element_stack,
                   error)) {
        return;
    }

    if (g_strcmp0 (element_name, "bounds") == 0) {
        EekBounds bounds;

        attribute = get_attribute (attribute_names, attribute_values, "x");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"x\" attribute for \"bounds\"");
            return;
        }
        bounds.x = g_strtod (attribute, NULL);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "y");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"y\" attribute for \"bounds\"");
            return;
        }
        bounds.y = g_strtod (attribute, NULL);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "width");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"width\" attribute for \"bounds\"");
            return;
        }
        bounds.width = g_strtod (attribute, NULL);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "height");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"height\" attribute for \"bounds\"");
            return;
        }
        bounds.height = g_strtod (attribute, NULL);

        if (g_strcmp0 (data->element_stack->data, "geometry") == 0)
            eek_element_set_bounds (EEK_ELEMENT(data->keyboard), &bounds);
        else if (g_strcmp0 (data->element_stack->data, "section") == 0)
            eek_element_set_bounds (EEK_ELEMENT(data->section), &bounds);
        else if (g_strcmp0 (data->element_stack->data, "key") == 0)
            eek_element_set_bounds (EEK_ELEMENT(data->key), &bounds);

        goto out;
    }

    if (g_strcmp0 (element_name, "section") == 0) {
        data->section = eek_keyboard_create_section (data->keyboard);
        attribute = get_attribute (attribute_names, attribute_values,
                                   "id");
        if (attribute != NULL)
            eek_element_set_name (EEK_ELEMENT(data->section), attribute);
        attribute = get_attribute (attribute_names, attribute_values,
                                   "angle");
        if (attribute != NULL) {
            gint angle;
            angle = strtol (attribute, NULL, 10);
            eek_section_set_angle (data->section, angle);
        }
        goto out;
    }

    if (g_strcmp0 (element_name, "row") == 0) {
        attribute = get_attribute (attribute_names, attribute_values,
                                   "orientation");
        if (attribute != NULL)
            data->orientation = strtol (attribute, NULL, 10);

        eek_section_add_row (data->section,
                             data->num_columns,
                             data->orientation);

        data->num_rows++;
        goto out;
    }

    if (g_strcmp0 (element_name, "key") == 0) {
        guint keycode;

        attribute = get_attribute (attribute_names, attribute_values,
                                   "keycode");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"keycode\" attribute for \"key\"");
            return;
        }
        keycode = strtoul (attribute, NULL, 10);

        data->key = eek_section_create_key (data->section,
                                            keycode,
                                            data->num_columns,
                                            data->num_rows - 1);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "name");
        if (attribute != NULL)
            eek_element_set_name (EEK_ELEMENT(data->key), attribute);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "oref");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"oref\" attribute for \"key\"");
            return;
        }
        g_hash_table_insert (data->key_oref_hash,
                             data->key,
                             g_strdup (attribute));

        data->num_columns++;

        goto out;
    }

    if (g_strcmp0 (element_name, "outline") == 0) {
        attribute = get_attribute (attribute_names, attribute_values, "id");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"id\" attribute for \"outline\"");
            return;
        }
        data->oref = g_strdup (attribute);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "corner-radius");
        if (attribute != NULL)
            data->corner_radius = g_strtod (attribute, NULL);
        
        goto out;
    }

    if (g_strcmp0 (element_name, "point") == 0) {
        EekPoint *point;
        gdouble x, y;

        attribute = get_attribute (attribute_names, attribute_values, "x");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"x\" attribute for \"bounds\"");
            return;
        }
        x = g_strtod (attribute, NULL);

        attribute = get_attribute (attribute_names, attribute_values, "y");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"y\" attribute for \"bounds\"");
            return;
        }
        y = g_strtod (attribute, NULL);

        point = g_slice_new (EekPoint);
        point->x = x;
        point->y = y;

        data->points = g_slist_prepend (data->points, point);
        goto out;
    }

 out:
    data->element_stack = g_slist_prepend (data->element_stack,
                                           g_strdup (element_name));
}
static void parse(rapidxml::xml_node<>* node, configuration const& config, documentation& doc, bool member = false)
{
    if (node != NULL)
    {
        bool recurse = false;
        bool is_member = member;

        std::string nodename = node->name();

        if (nodename == "doxygen")
        {
            recurse = true;
        }
        else if (nodename == "sectiondef")
        {
            std::string kind = get_attribute(node, "kind");

            if (kind == "func"
                || kind == "define"
                || kind == "enum"
                )
            {
                recurse = true;
            }
            else if (boost::starts_with(kind, "public"))
            {
                recurse = true;
                is_member = true;
            }
        }
        else if (nodename == "compounddef")
        {
            std::string kind = get_attribute(node, "kind");
            if (kind == "group")
            {
                recurse = true;
            }
            else if (kind == "struct")
            {
                recurse = true;
                doc.cos.is_class = false;
                parse_element(node->first_node(), config, "", doc.cos);
            }
            else if (kind == "class")
            {
                recurse = true;
                doc.cos.is_class = true;
                parse_element(node->first_node(), config, "", doc.cos);
            }
        }
        else if (nodename == "memberdef")
        {
            std::string kind = get_attribute(node, "kind");
            if (kind == "function")
            {
                function f;
                parse_element(node->first_node(), config, "", f);
                parse_function(node->first_node(), config, "", f);
                if (member)
                {
                    f.type = boost::equals(f.name, doc.cos.name) 
                        ? function_constructor 
                        : function_member;
                    doc.cos.functions.push_back(f);
                }
                else
                {
                    f.type = function_free;
                    doc.functions.push_back(f);
                }
            }
            else if (kind == "define")
            {
                function f;
                f.type = function_define;
                parse_element(node->first_node(), config, "", f);
                parse_function(node->first_node(), config, "", f);
                doc.functions.push_back(f);
            }
            else if (kind == "enum")
            {
                enumeration e;
                parse_element(node->first_node(), config, "", e);
                parse_enumeration(node->first_node(), config, "", e);
                doc.enumerations.push_back(e);
            }
            else if (kind == "typedef")
            {
                if (boost::equals(get_attribute(node, "prot"), "public"))
                {
                    std::string name = parse_named_node(node->first_node(), "name");
                    doc.cos.typedefs.push_back(base_element(name));
                }
            }
            else if (kind == "variable")
            {
                if (boost::equals(get_attribute(node, "static"), "yes")
                    && boost::equals(get_attribute(node, "mutable"), "no")
                    && boost::equals(get_attribute(node, "prot"), "public"))
                {
                    std::string name = parse_named_node(node->first_node(), "name");
                    doc.cos.variables.push_back(base_element(name));
                }
            }

        }
        else if (nodename == "compoundname")
        {
            std::string name = node->value();
            if (name.find("::") != std::string::npos)
            {
                doc.cos.fullname = name;

                // For a class, it should have "boost::something::" before
                // set its name without namespace
                doc.cos.name = keep_after(name, "::");
            }
        }
        else if (nodename == "basecompoundref")
        {
            base_class bc;
            bc.name = node->value();
            bc.derivation = get_attribute(node, "prot");
            bc.virtuality = get_attribute(node, "virt");
            doc.cos.base_classes.push_back(bc);
        }
        else
        {
            //std::cout << nodename << " ignored." << std::endl;
        }


        if (recurse)
        {
            // First recurse into childnodes, then handle next siblings
            parse(node->first_node(), config, doc, is_member);
        }
        parse(node->next_sibling(), config, doc, is_member);
    }
}
Beispiel #28
0
static void
symbols_start_element_callback (GMarkupParseContext *pcontext,
                                const gchar         *element_name,
                                const gchar        **attribute_names,
                                const gchar        **attribute_values,
                                gpointer             user_data,
                                GError             **error)
{
    SymbolsParseData *data = user_data;
    const gchar *attribute;

    if (!validate (symbols_valid_path_list,
                   G_N_ELEMENTS (symbols_valid_path_list),
                   element_name,
                   data->element_stack,
                   error))
        return;

    if (g_strcmp0 (element_name, "key") == 0) {
        guint keycode;

        attribute = get_attribute (attribute_names, attribute_values,
                                   "keycode");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"keycode\" attribute for \"key\"");
            return;
        }
        keycode = strtoul (attribute, NULL, 10);

        data->key = eek_keyboard_find_key_by_keycode (data->keyboard,
                                                      keycode);
        if (data->key == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_INVALID_CONTENT,
                         "no such keycode %u", keycode);
            return;
        }

        attribute = get_attribute (attribute_names, attribute_values,
                                   "groups");
        if (attribute != NULL)
            data->groups = strtol (attribute, NULL, 10);
        else
            data->groups = 1;
        data->symbols = NULL;
        goto out;
    }

    if (g_strcmp0 (element_name, "keysym") == 0) {
        attribute = get_attribute (attribute_names, attribute_values,
                                   "keyval");
        if (attribute == NULL) {
            g_set_error (error,
                         G_MARKUP_ERROR,
                         G_MARKUP_ERROR_MISSING_ATTRIBUTE,
                         "no \"keyval\" attribute for \"keysym\"");
            return;
        }
        data->keyval = strtoul (attribute, NULL, 0);
    }

    if (g_strcmp0 (element_name, "symbol") == 0 ||
        g_strcmp0 (element_name, "keysym") == 0 ||
        g_strcmp0 (element_name, "text") == 0) {
        attribute = get_attribute (attribute_names, attribute_values,
                                   "label");
        if (attribute != NULL)
            data->label = g_strdup (attribute);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "icon");
        if (attribute != NULL)
            data->icon = g_strdup (attribute);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "tooltip");
        if (attribute != NULL)
            data->tooltip = g_strdup (attribute);

        attribute = get_attribute (attribute_names, attribute_values,
                                   "category");
        if (attribute != NULL)
            data->category = strtoul (attribute, NULL, 10);
        else
            data->category = EEK_SYMBOL_CATEGORY_KEYNAME;
    }

 out:
    data->element_stack = g_slist_prepend (data->element_stack,
                                           g_strdup (element_name));
    data->text->len = 0;
}
Beispiel #29
0
void Player::player_move(Map *map)
{
    Actor::move(map);

    check_water(map);

    int input = get_input();

    const Tmx::Tileset *tileset = map->get_tileset(0);
    const Tmx::PropertySet prop = tileset->GetProperties();

    // Check if on catapult
    int catid = prop.GetNumericProperty("catapult");
    if (catid && check_below(map, 1, catid, catid) == 0) {
        if (input & PRESS_RIGHT) {
            set_vx(get_attribute("move_speed"));
        }
        else if (input & PRESS_LEFT) {
            set_vx(-get_attribute("move_speed"));
        }
        set_jump(map, true);
    }

    switch(m_action) {
        case Still:
            set_vx(0);

        case Move:
            // Check for crouch or move
            if (input & PRESS_DOWN) {
                set_action(Crouch);
            }
            else if (input & PRESS_RIGHT) {
                animate_move();
                set_action(Move);
                set_vx(get_attribute("move_speed"));
            }
            else if (input & PRESS_LEFT) {
                animate_move();
                set_action(Move);
                set_vx(-get_attribute("move_speed"));
            }
            else {
                set_action(Still);
            }

            // Check for jump
            if (input & PRESS_JUMP) {
                if (m_jump_ready && m_hit_ground) {
                    if (input & PRESS_RIGHT) {
                        set_vx(get_attribute("move_speed"));
                    }
                    else if (input & PRESS_LEFT) {
                        set_vx(-get_attribute("move_speed"));
                    }
                    set_jump(map, false);
                }
                m_jump_ready = false;
            }
            else {
                // Restore jump lock
                m_jump_ready = true;
            }

            Body::move(map);
            if (get_fall()) {
                set_action(Fall);
            }
            break;

        case Fall:
            // Check for change of direction during fall
            if (input & PRESS_RIGHT) {
                set_vx(get_attribute("move_speed"));
            }
            else if (input & PRESS_LEFT) {
                set_vx(-get_attribute("move_speed"));
            }

            Body::move(map);
            if (!get_fall()) {
                m_hit_ground = true;
                set_action(Still);
            }
            break;

        case Jump:
        case Catapult:
            Body::move(map);
            if (get_fall()) {
                set_action(Fall);
            }
            break;

        case Crouch:
            set_vx(0);
            Body::move(map);
            if (!get_fall()) {
                m_hit_ground = true;
            }

            if (!(input & PRESS_DOWN)) {
                set_action(Still);
            }
            break;

        case Hit:
            if (m_hit_timer.expired(get_attribute("hit_time"))) {
                set_vx(0);
                set_lock_direction(false);
                reset_hit();
            }
            Body::move(map);
            break;

        case HitPerish:
            animate_perish();
            set_speed(0, -get_attribute("move_speed"));
            Body::move(map);
            if (m_y < -get_image_height()) {
                set_solid(true);
                set_invisible(false);
                set_action(HitPerished);
            }
            break;

        case Attack:
        case AttackLow:
            if (animate_attack()) {
                reset_attack();
            }
            Body::move(map);
            if (!get_fall()) {
                m_hit_ground = true;
            }
            break;

        default:
            Body::move(map);
            break;
    }
}
Resource* CreateSkinMixer( XMLIterator i, XMLCreatorEnv *env)
{
    SPointer<SkinMan> sp_skin_man;
    SkinMixer *p_mixer = new SkinMixer;

    const XMLNode &node = *i;

    std::map< std::string, int > skin_IDs;

    std::string map_name = get_attribute( node._attributes, "mapping");
    
    std::vector<int> *p_map;
    Resources::Instance().Query( "mappings", map_name, p_map);

    int ni = 0;
    
    for ( i.StepInto(); !!i; ++i, ++ni)
    {
        int oid = (*p_map)[ni];
        
        if ( (*i)._name == "state" )
        {
            XMLIterator j = i;
            
            for ( j.StepInto(); !!j; ++j)
            {
                if ( (*j)._name == "mix")
                {
                    int iid;
                    std::string id = get_attribute( (*j)._attributes, "id");
                    if ( skin_IDs.find( id) == skin_IDs.end())
                    {
                        Skin &skin = QuerySkin( id);
                        iid = p_mixer->Insert( skin);
                        skin_IDs[id] = iid;
                    }
                    else {
                        iid = skin_IDs[id];
                    }
                    
                    int alignment = -1;
                    Pos offset(0,0);
                    std::string tmp;
                    if ( try_attribute( (*j)._attributes, "halign", &tmp ))
                    {
                        if ( tmp == "left" ) { alignment = Rect::HALIGNLEFT; } else
                        if ( tmp == "center" ) { alignment = Rect::HALIGNCENTER; } else
                        if ( tmp == "right" ) { alignment = Rect::HALIGNRIGHT; } else
                        if ( tmp == "fill" ) { alignment = -1; }
                    }
                    if ( try_attribute( (*j)._attributes, "valign", &tmp ))
                    {
                        if ( alignment == -1 ) { alignment = 0; }
                        if ( tmp == "top" ) { alignment |= Rect::VALIGNTOP; } else
                        if ( tmp == "center" ) { alignment |= Rect::VALIGNCENTER; } else
                        if ( tmp == "bottom" ) { alignment |= Rect::VALIGNBOTTOM; } else
                        if ( tmp == "fill" ) { alignment = -1; }
                    }
                    
                    p_mixer->Mix( oid, iid, alignment, offset);
                    
                }
                else {
                    C_verify( !"CreateSkinMixer: Tag <mix /> was excpected.");
                }
            }
        }
    }

    return new AnyResource< SPointer<SkinMan> >( p_mixer);
}