コード例 #1
0
pointer us_bundle_info(scheme* sc, pointer args)
{
  if(args == sc->NIL)
  {
    std::cerr << "Empty argument list" << std::endl;
    return sc->NIL;
  }

  if (sc->vptr->list_length(sc, args) != 1)
  {
    return sc->NIL;
  }

  const char delimChar = '-';
  char delim[50];
  memset(delim, delimChar, 50);

  pointer arg = pair_car(args);
  Bundle bundle;
  if (is_string(arg))
  {
    std::string name = sc->vptr->string_value(arg);
    if (name == "_header_")
    {
      pointer result = sc->NIL;
      pointer infoList = sc->NIL;
      for (int fi = numFields-1; fi >= 0; --fi)
      {
        delim[fieldWidth[fi]] = '\0';
        infoList = immutable_cons(sc, sc_string(sc, delim), infoList);
        delim[fieldWidth[fi]] = delimChar;
      }
      result = immutable_cons(sc, infoList, result);

      infoList = sc->NIL;
      infoList = immutable_cons(sc, sc_string(sc, "Location"), infoList);
      infoList = immutable_cons(sc, sc_string(sc, "State"), infoList);
      infoList = immutable_cons(sc, sc_string(sc, "Version"), infoList);
      infoList = immutable_cons(sc, sc_string(sc, "Symbolic Name"), infoList);
      infoList = immutable_cons(sc, sc_string(sc, "Id"), infoList);
      return immutable_cons(sc, infoList, result);
    }
    else
    {
      bundle = get_bundle(name);
    }
  }
  else if (is_integer(arg))
  {
    bundle = GetBundleContext().GetBundle(ivalue(arg));
  }
  else
  {
    return sc->NIL;
  }

  if (!bundle)
  {
    return sc->NIL;
  }

  pointer id = sc_int(sc, bundle.GetBundleId());
  pointer name = sc_string(sc, bundle.GetSymbolicName().c_str());
  pointer location = sc_string(sc, bundle.GetLocation().c_str());
  pointer version = sc_string(sc, bundle.GetVersion().ToString().c_str());
  std::stringstream strState;
  strState << bundle.GetState();
  pointer state = sc_string(sc, strState.str().c_str());


  pointer result = sc->NIL;
  result = immutable_cons(sc, location, result);
  result = immutable_cons(sc, state, result);
  result = immutable_cons(sc, version, result);
  result = immutable_cons(sc, name, result);
  result = immutable_cons(sc, id, result);

  // (id, name, version, state, location)
  return result;
}