int get_trans_config(XMLReader *xml, Trans_cfg *tcfg) {
    char tmp_str[200];
    memset(tcfg, 0, sizeof(Trans_cfg));
    tcfg->available = (0 == strcmp("true", xml->property["available"].c_str()));
    strncpy(tcfg->filename_prefix, xml->property["prefix"].c_str(), 20);
    memset(tmp_str, '\0', sizeof(tmp_str));
    strncpy(tmp_str, xml->property["type"].c_str(), 20);
    if (0 == strncmp("cs", tmp_str, 2)) tcfg->pt = pt_CS;
    else if (0 == strncmp("ps", tmp_str, 2)) tcfg->pt = pt_PS;
    else tcfg->pt = pt_Undefined;
    tcfg->timestamp_begin  = atoi(xml->getNodeByName("file_name", 0)->property["timestamp_begin"].c_str());
    tcfg->timestamp_length = atoi(xml->getNodeByName("file_name", 0)->property["timestamp_len"]  .c_str());
    tcfg->filenum_length   = atoi(xml->getNodeByName("file_name", 0)->property["file_num_len"]   .c_str());
    tcfg->fmt_orig         = atoi(xml->getNodeByName("format", 0)   ->property["origin_num"]     .c_str());
    tcfg->fmt_after        = atoi(xml->getNodeByName("format", 0)   ->property["num"]            .c_str());
    tcfg->fmt_available    = (0 == strcmp("true", xml->getNodeByName("format", 0)->property["available"].c_str()));
    tcfg->fmt_order = (int*) malloc(sizeof(int) * tcfg->fmt_after);
    memset(tmp_str, '\0', sizeof(tmp_str));
    strcpy(tmp_str, xml->getNodeByName("format", 0)->value);
    split_value_to_int(tcfg->fmt_order, tmp_str, ',');
    tcfg->evt_map_available = (0 == strcmp("true", xml->getNodeByName("event", 0)->property["available"].c_str()));
    tcfg->evt_idx     = atoi(xml->getNodeByName("event", 0)->property["index"]   .c_str()) - 1;
    tcfg->num_evt_map = atoi(xml->getNodeByName("event", 0)->property["type_num"].c_str());
    tcfg->evt_map = (char***) malloc(sizeof(char**) * tcfg->num_evt_map);
    for (int i = 0; i < tcfg->num_evt_map; i++) {
        tcfg->evt_map[i] = (char**) malloc(sizeof(char*) * 2);
        memset(tmp_str, '\0', sizeof(tmp_str));
        strcpy(tmp_str, xml->getNodeByName("event", 0)->getNodeByName("event_type", i)->value);
        split_value(tcfg->evt_map[i], tmp_str, ',');
    }
    qsort(tcfg->evt_map, tcfg->num_evt_map, sizeof(char**), strcomp1);
    if (xml->getNodeByName("swap_on_event", 0) != NULL) {
        strcpy(tcfg->soe_event,             xml->getNodeByName("swap_on_event", 0)->property["event"].c_str());
        split_value_to_int(tcfg->soe_field, xml->getNodeByName("swap_on_event", 0)->property["col"]  .c_str(), ',');
    }
    tcfg->field_spliter = xml->getNodeByName("field_spliter", 0)->value[0];
    return 0;
}
Exemple #2
0
struct hw *
hw_tree_vparse (struct hw *current,
		const char *fmt,
		va_list ap)
{
  char device_specifier[1024];
  name_specifier spec;

  /* format the path */
  vsprintf (device_specifier, fmt, ap);
  if (strlen (device_specifier) >= sizeof (device_specifier))
    hw_abort (NULL, "device_tree_add_deviced: buffer overflow\n");

  /* construct the tree down to the final struct hw */
  current = split_fill_path (current, device_specifier, &spec);

  /* is there an interrupt spec */
  if (spec.property == NULL
      && spec.value != NULL)
    {
      char *op = split_value (&spec);
      switch (op[0])
	{
	case '>':
	  {
	    char *my_port_name = split_value (&spec);
	    int my_port;
	    char *dest_port_name = split_value (&spec);
	    int dest_port;
	    name_specifier dest_spec;
	    char *dest_hw_name = split_value (&spec);
	    struct hw *dest;
	    /* find my name */
	    if (!hw_finished_p (current))
	      hw_finish (current);
	    my_port = hw_port_decode (current, my_port_name, output_port);
	    /* find the dest device and port */
	    dest = split_fill_path (current, dest_hw_name, &dest_spec);
	    if (!hw_finished_p (dest))
	      hw_finish (dest);
	    dest_port = hw_port_decode (dest, dest_port_name,
					input_port);
	    /* connect the two */
	    hw_port_attach (current,
			    my_port,
			    dest,
			    dest_port,
			    permenant_object);
	    break;
	  }
	default:
	  hw_abort (current, "unreconised interrupt spec %s\n", spec.value);
	  break;
	}
    }

  /* is there a property */
  if (spec.property != NULL)
    {
      if (strcmp (spec.value, "true") == 0)
	hw_add_boolean_property (current, spec.property, 1);
      else if (strcmp (spec.value, "false") == 0)
	hw_add_boolean_property (current, spec.property, 0);
      else
	{
	  const struct hw_property *property;
	  switch (spec.value[0])
	    {
#if NOT_YET
	    case '*':
	      {
		parse_ihandle_property (current, spec.property, spec.value + 1);
		break;
	      }
#endif
	    case '[':
	      {
		unsigned8 words[1024];
		char *curr = spec.value + 1;
		int nr_words = 0;
		while (1)
		  {
		    char *next;
		    words[nr_words] = H2BE_1 (strtoul (curr, &next, 0));
		    if (curr == next)
		      break;
		    curr = next;
		    nr_words += 1;
		  }
		hw_add_array_property (current, spec.property,
				       words, sizeof(words[0]) * nr_words);
		break;
	      }
	    case '"':
	      {
		parse_string_property (current, spec.property, spec.value);
		break;
	      }
	    case '!':
	      {
		spec.value++;
		property = hw_tree_find_property (current, spec.value);
		if (property == NULL)
		  hw_abort (current, "property %s not found\n", spec.value);
		hw_add_duplicate_property (current,
					   spec.property,
					   property);
		break;
	      }
	    default:
	      {
		if (strcmp (spec.property, "reg") == 0
		    || strcmp (spec.property, "assigned-addresses") == 0
		    || strcmp (spec.property, "alternate-reg") == 0)
		  {
		    parse_reg_property (current, spec.property, spec.value);
		  }
		else if (strcmp (spec.property, "ranges") == 0)
		  {
		    parse_ranges_property (current, spec.property, spec.value);
		  }
		else if (isdigit(spec.value[0])
			 || (spec.value[0] == '-' && isdigit(spec.value[1]))
			 || (spec.value[0] == '+' && isdigit(spec.value[1])))
		  {
		    parse_integer_property(current, spec.property, spec.value);
		  }
		else
		  parse_string_property(current, spec.property, spec.value);
		break;
	      }
	    }
	}
    }
  return current;
}