コード例 #1
0
ファイル: hw_disk.c プロジェクト: 5kg/gdb
static void
hw_disk_init_address(device *me)
{
  hw_disk_device *disk = device_data(me);
  unsigned_word address;
  int space;
  const char *name;

  /* attach to the parent. Since the bus is logical, attach using just
     the unit-address (size must be zero) */
  device_address_to_attach_address(device_parent(me), device_unit_address(me),
				   &space, &address, me);
  device_attach_address(device_parent(me), attach_callback,
			space, address, 0/*size*/, access_read_write_exec,
			me);

  /* Tell the world we are a disk.  */
  device_add_string_property(me, "device_type", "block");

  /* get the name of the file specifying the disk image */
  disk->name_index = 0;
  disk->nr_names = device_find_string_array_property(me, "file",
						     disk->name_index, &name);
  if (!disk->nr_names)
    device_error(me, "invalid file property");

  /* is it a RO device? */
  disk->read_only =
    (strcmp(device_name(me), "disk") != 0
     && strcmp(device_name(me), "floppy") != 0
     && device_find_property(me, "read-only") == NULL);

  /* now open it */
  open_disk_image(me, disk, name);
}
コード例 #2
0
ファイル: tree.c プロジェクト: 3125788/android_toolchain_gdb
parse_string_property(device *current,
		      const char *property_name,
		      const char *property_value)
{
  char **strings;
  const char *chp;
  int nr_strings;
  int approx_nr_strings;

  /* get an estimate as to the number of strings by counting double
     quotes */
  approx_nr_strings = 2;
  for (chp = property_value; *chp; chp++) {
    if (*chp == '"')
      approx_nr_strings++;
  }
  approx_nr_strings = (approx_nr_strings) / 2;

  /* create a string buffer for that many (plus a null) */
  strings = (char**)zalloc((approx_nr_strings + 1) * sizeof(char*));

  /* now find all the strings */
  chp = property_value;
  nr_strings = 0;
  while (1) {

    /* skip leading space */
    while (*chp != '\0' && isspace(*chp))
      chp += 1;
    if (*chp == '\0')
      break;

    /* copy it in */
    if (*chp == '"') {
      /* a quoted string - watch for '\' et.al. */
      /* estimate the size and allocate space for it */
      int pos;
      chp++;
      pos = 0;
      while (chp[pos] != '\0' && chp[pos] != '"') {
	if (chp[pos] == '\\' && chp[pos+1] != '\0')
	  pos += 2;
	else
	  pos += 1;
      }
      strings[nr_strings] = zalloc(pos + 1);
      /* copy the string over */
      pos = 0;
      while (*chp != '\0' && *chp != '"') {
	if (*chp == '\\' && *(chp+1) != '\0') {
	  strings[nr_strings][pos] = *(chp+1);
	  chp += 2;
	  pos++;
	}
	else {
	  strings[nr_strings][pos] = *chp;
	  chp += 1;
	  pos++;
	}
      }
      if (*chp != '\0')
	chp++;
      strings[nr_strings][pos] = '\0';
    }
    else {
      /* copy over a single unquoted token */
      int len = 0;
      while (chp[len] != '\0' && !isspace(chp[len]))
	len++;
      strings[nr_strings] = zalloc(len + 1);
      strncpy(strings[nr_strings], chp, len);
      strings[nr_strings][len] = '\0';
      chp += len;
    }
    nr_strings++;
    if (nr_strings > approx_nr_strings)
      device_error(current, "String property %s badly formatted",
		   property_name);
  }
  ASSERT(strings[nr_strings] == NULL); /* from zalloc */

  /* install it */
  if (nr_strings == 0)
    device_add_string_property(current, property_name, "");
  else if (nr_strings == 1)
    device_add_string_property(current, property_name, strings[0]);
  else {
    const char **specs = (const char**)strings; /* stop a bogus error */
    device_add_string_array_property(current, property_name,
				     specs, nr_strings);
  }

  /* flush the created string */
  while (nr_strings > 0) {
    nr_strings--;
    zfree(strings[nr_strings]);
  }
  zfree(strings);
}