Example #1
0
static int
dump_attr_json(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv, struct cbdata *cbdata)
{
  Pool *pool = repo->pool;
  const char *keyname;
  KeyValue *kvp;
  int indent = cbdata->baseindent;
  int isarray = 0;
  const char *str;
  int depth = 0;

  keyname = pool_id2str(repo->pool, key->name);
  for (kvp = kv; (kvp = kvp->parent) != 0; indent += 4)
    depth++;
  if (cbdata->nfirst < depth + 1)
    {
      cbdata->first = solv_realloc(cbdata->first, depth + 16);
      memset(cbdata->first + cbdata->nfirst, 0, depth + 16 - cbdata->nfirst);
      cbdata->nfirst = depth + 16;
    }
  switch(key->type)
    {
    case REPOKEY_TYPE_IDARRAY:
    case REPOKEY_TYPE_DIRNUMNUMARRAY:
    case REPOKEY_TYPE_DIRSTRARRAY:
      isarray = 1;
      break;
    case REPOKEY_TYPE_FIXARRAY:
    case REPOKEY_TYPE_FLEXARRAY:
      isarray = 2;
      break;
    default:
      break;
    }
  if (!isarray || !kv->entry)
    {
      if (cbdata->first[depth])
	printf(",\n");
      printf("%*s%s: ", indent, "", jsonstring(pool, keyname));
      cbdata->first[depth] = 1;
    }
  if (isarray == 1 && !kv->entry)
    printf("[\n%*s", indent + 2, "");
  else if (isarray == 1 && kv->entry)
    printf("%*s", indent + 2, "");
  switch(key->type)
    {
    case REPOKEY_TYPE_ID:
      if (data && data->localpool)
	str = stringpool_id2str(&data->spool, kv->id);
      else
	str = pool_dep2str(repo->pool, kv->id);
      printf("%s", jsonstring(pool, str));
      break;
    case REPOKEY_TYPE_CONSTANTID:
      str = pool_dep2str(repo->pool, kv->id);
      printf("%s", jsonstring(pool, str));
      break;
    case REPOKEY_TYPE_IDARRAY:
      if (data && data->localpool)
        str = stringpool_id2str(&data->spool, kv->id);
      else
        str = pool_dep2str(repo->pool, kv->id);
      printf("%s", jsonstring(pool, str));
      break;
    case REPOKEY_TYPE_STR:
      str = kv->str;
      printf("%s", jsonstring(pool, str));
      break;
    case REPOKEY_TYPE_VOID:
      printf("null");
      break;
    case REPOKEY_TYPE_CONSTANT:
      printf("%u", kv->num);
      break;
    case REPOKEY_TYPE_NUM:
      printf("%llu", SOLV_KV_NUM64(kv));
      break;
    case REPOKEY_TYPE_BINARY:
      printf("\"<binary>\"");
      break;
    case REPOKEY_TYPE_DIRNUMNUMARRAY:
      printf("{\n");
      printf("%*s    \"dir\": %s,\n", indent, "", jsonstring(pool, repodata_dir2str(data, kv->id, 0)));
      printf("%*s    \"num1\": %u,\n", indent, "", kv->num);
      printf("%*s    \"num2\": %u\n", indent, "", kv->num2);
      printf("%*s  }", indent, "");
      break;
    case REPOKEY_TYPE_DIRSTRARRAY:
      printf("%s", jsonstring(pool, repodata_dir2str(data, kv->id, kv->str)));
      break;
    case REPOKEY_TYPE_FIXARRAY:
    case REPOKEY_TYPE_FLEXARRAY:
      cbdata->first[depth + 1] = 0;
      if (!kv->entry)
	printf("[\n");
      else
	{
	  if (kv->eof != 2)
            printf("\n%*s  },\n", indent, "");
	  else
            printf("\n%*s  }\n", indent, "");
	}
      if (kv->eof != 2)
        printf("%*s  {\n", indent, "");
      else
        printf("%*s]", indent, "");
      break;
    default:
      if (solv_chksum_len(key->type))
	{
	  printf("{\n");
	  printf("%*s  \"value\": %s,\n", indent, "", jsonstring(pool, repodata_chk2str(data, key->type, (unsigned char *)kv->str)));
	  printf("%*s  \"type\": %s\n", indent, "", jsonstring(pool, solv_chksum_type2str(key->type)));
	  printf("%*s}", indent, "");
	  break;
	}
      printf("\"?\"");
      break;
    }
  if (isarray == 1)
    {
      if (!kv->eof)
        printf(",\n");
      else
        printf("\n%*s]", indent, "");
    }
  return 0;
}
Example #2
0
bool map_bash_info::load(JsonObject &jsobj, std::string member, bool isfurniture) {
    if( jsobj.has_object(member) ) {
        JsonObject j = jsobj.get_object(member);

        if ( jsonint(j, "num_tests", num_tests ) == false ) {
           if ( jsonint(j, "str_min", str_min ) && jsonint(j, "str_max", str_max ) ) {
               num_tests = 1;
           }
        } else if ( num_tests > 0 ) {
           str_min = j.get_int("str_min");
           str_max = j.get_int("str_max");
        }

        jsonint(j, "str_min_blocked", str_min_blocked );
        jsonint(j, "str_max_blocked", str_max_blocked );
        jsonint(j, "str_min_roll", str_min_roll );
        jsonint(j, "explosive", explosive );
        jsonint(j, "chance", chance );
        jsonstring(j, "sound", sound );
        jsonstring(j, "sound_fail", sound_fail );
        jsonstring(j, "furn_set", furn_set );

        if ( jsonstring(j, "ter_set", ter_set ) == false && isfurniture == false ) {
           ter_set = "t_rubble";
           debugmsg("terrain[\"%s\"].bash.ter_set is not set!",jsobj.get_string("id").c_str() );
        }

        if ( j.has_array("items") ) {
           JsonArray ja = j.get_array("items");
           if (ja.size() > 0) {
               int c=0;
               while ( ja.has_more() ) {
                   if ( ja.has_object(c) ) {
                       JsonObject jio = ja.next_object();
                       if ( jio.has_string("item") && jio.has_int("amount") ) {
                           if ( jio.has_int("minamount") ) {
                               map_bash_item_drop drop( jio.get_string("item"), jio.get_int("amount"), jio.get_int("minamount") );
                               jsonint(jio, "chance", drop.chance);
                               items.push_back(drop);
                           } else {
                               map_bash_item_drop drop( jio.get_string("item"), jio.get_int("amount") );
                               jsonint(jio, "chance", drop.chance);
                               items.push_back(drop);
                           }
                       } else {
                           debugmsg("terrain[\"%s\"].bash.items[%d]: invalid entry",jsobj.get_string("id").c_str(),c);
                       }
                   } else {
                       debugmsg("terrain[\"%s\"].bash.items[%d]: invalid entry",jsobj.get_string("id").c_str(),c);
                   }
                   c++;
               }
           }
        }

//debugmsg("%d/%d %s %s/%s %d",str_min,str_max, ter_set.c_str(), sound.c_str(), sound_fail.c_str(), items.size() );
    return true;
  } else {
    return false;
  }
}