/** Loads the installed addons from .../addons/addons_installed.xml.
 */
void AddonsManager::loadInstalledAddons()
{
    /* checking for installed addons */
    if(UserConfigParams::logAddons())
    {
        std::cout << "[addons] Loading an xml file for installed addons: ";
        std::cout << m_file_installed << std::endl;
    }
    const XMLNode *xml = file_manager->createXMLTree(m_file_installed);
    if(!xml)
        return;

    for(unsigned int i=0; i<xml->getNumNodes(); i++)
    {
        const XMLNode *node=xml->getNode(i);
        if(node->getName()=="kart"   || node->getName()=="arena" ||
            node->getName()=="track"    )
        {
            Addon addon(*node);
            m_addons_list.getData().push_back(addon);
        }
    }   // for i <= xml->getNumNodes()

    delete xml;
}   // loadInstalledAddons
Ejemplo n.º 2
0
void AddonMgr::LoadFromDB()
{
    QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT name, crc FROM addons");
    if(!result)
    {
        sLog.outErrorDb("The table `addons` is empty");
        return;
    }

    barGoLink bar(result->GetRowCount());
    uint32 count = 0;
    Field *fields;

    do
    {
        fields = result->Fetch();
        bar.step();
        count++;

        std::string name = fields[0].GetCppString();
        uint32 crc = fields[1].GetUInt32();

        SavedAddon addon(name, crc);
        m_knownAddons.push_back(addon);
    } while(result->NextRow());

    sLog.outString();
    sLog.outString(">> Loaded %u known addons", count);
}
Ejemplo n.º 3
0
bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* = true */)
{
  CSingleLock lock(m_critSection);
  addons.clear();
  cp_status_t status;
  int num;
  CStdString ext_point(TranslateType(type));
  cp_extension_t **exts = m_cpluff->get_extensions_info(m_cp_context, ext_point.c_str(), &status, &num);
  for(int i=0; i <num; i++)
  {
    const cp_extension_t *props = exts[i];
    if (m_database.IsAddonDisabled(props->plugin->identifier) != enabled)
    {
      // get a pointer to a running pvrclient if it's already started, or we won't be able to change settings
      if (TranslateType(props->ext_point_id) == ADDON_PVRDLL &&
          enabled &&
          g_PVRManager.IsStarted())
      {
        AddonPtr pvrAddon;
        if (g_PVRClients->GetClient(props->plugin->identifier, pvrAddon))
        {
          addons.push_back(pvrAddon);
          continue;
        }
      }

      AddonPtr addon(Factory(props));
      if (addon)
        addons.push_back(addon);
    }
  }
  m_cpluff->release_info(m_cp_context, exts);
  return addons.size() > 0;
}
Ejemplo n.º 4
0
//----------------------------------------------------------------------------
//  InitAddons
HRESULT CAnchoRuntime::InitAddons()
{
  // create all addons
  // open the registry key where all extensions are registered,
  // iterate subkeys and load each extension

  CRegKey regKey;
  LONG res = regKey.Open(HKEY_CURRENT_USER, s_AnchoExtensionsRegistryKey, KEY_READ);
  if (ERROR_SUCCESS != res)
  {
    return HRESULT_FROM_WIN32(res);
  }
  DWORD iIndex = 0;
  CString sKeyName;
  DWORD dwLen = 4096;
  HRESULT hr = S_OK;

  while(ERROR_SUCCESS == regKey.EnumKey(iIndex++, sKeyName.GetBuffer(dwLen), &dwLen, NULL))
  {
    sKeyName.ReleaseBuffer();
    CAnchoAddonComObject * pNewObject = NULL;
    hr = CAnchoAddonComObject::CreateInstance(&pNewObject);
    if (SUCCEEDED(hr))
    {
      CComPtr<IAnchoAddon> addon(pNewObject);
      hr = addon->Init(sKeyName, m_pAnchoService, m_pWebBrowser);
      if (SUCCEEDED(hr))
      {
        m_Addons[std::wstring(sKeyName)] = addon;
      }
    }
    dwLen = 4096;
  }
  return S_OK;
}
Ejemplo n.º 5
0
  PyObject* Addon_SetSetting(Addon *self, PyObject *args, PyObject *kwds)
  {
    static const char *keywords[] = { "id", "value", NULL };
    char *id = NULL;
    PyObject *pValue = NULL;

    if (!PyArg_ParseTupleAndKeywords(
      args,
      kwds,
      (char*)"sO",
      (char**)keywords,
      &id,
      &pValue
      ))
    {
      return NULL;
    };

    CStdString value;
    if (!id || !PyXBMCGetUnicodeString(value, pValue, 1))
    {
      PyErr_SetString(PyExc_ValueError, "Invalid id or value!");
      return NULL;
    }

    AddonPtr addon(self->pAddon);
    CPyThreadState pyState;
    addon->UpdateSetting(id, value);
    addon->SaveSettings();
    pyState.Restore();

    Py_INCREF(Py_None);
    return Py_None;
  }
Ejemplo n.º 6
0
bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* = true */, bool bGetDisabledPVRAddons /* = true */)
{
  CStdString xbmcPath = CSpecialProtocol::TranslatePath("special://xbmc/addons");
  CSingleLock lock(m_critSection);
  addons.clear();
  cp_status_t status;
  int num;
  CStdString ext_point(TranslateType(type));
  cp_extension_t **exts = m_cpluff->get_extensions_info(m_cp_context, ext_point.c_str(), &status, &num);
  for(int i=0; i <num; i++)
  {
    const cp_extension_t *props = exts[i];
    bool bIsPVRAddon(TranslateType(props->ext_point_id) == ADDON_PVRDLL);

    if (((bGetDisabledPVRAddons && bIsPVRAddon) || m_database.IsAddonDisabled(props->plugin->identifier) != enabled))
    {
      if (bIsPVRAddon && g_PVRManager.IsStarted())
      {
        AddonPtr pvrAddon;
        if (g_PVRClients->GetClient(props->plugin->identifier, pvrAddon))
        {
          addons.push_back(pvrAddon);
          continue;
        }
      }

      AddonPtr addon(Factory(props));
      if (addon)
        addons.push_back(addon);
    }
  }
  m_cpluff->release_info(m_cp_context, exts);
  return addons.size() > 0;
}
Ejemplo n.º 7
0
 void Addon::setSetting(const char* id, const String& value)
 {
   DelayedCallGuard dcguard(languageHook);
   ADDON::AddonPtr addon(pAddon);
   bool save=true;
   if (g_windowManager.IsWindowActive(WINDOW_DIALOG_ADDON_SETTINGS))
   {
     CGUIDialogAddonSettings* dialog = (CGUIDialogAddonSettings*)g_windowManager.GetWindow(WINDOW_DIALOG_ADDON_SETTINGS);
     if (dialog->GetCurrentID() == addon->ID())
     {
       CGUIMessage message(GUI_MSG_SETTING_UPDATED,0,0);
       std::vector<std::string> params;
       params.push_back(id);
       params.push_back(value);
       message.SetStringParams(params);
       g_windowManager.SendThreadMessage(message,WINDOW_DIALOG_ADDON_SETTINGS);
       save=false;
     }
   }
   if (save)
   {
     addon->UpdateSetting(id, value);
     addon->SaveSettings();
   }
 }
Ejemplo n.º 8
0
bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* = true */)
{
  CSingleLock lock(m_critSection);
  addons.clear();
  if (!m_cp_context)
    return false;
  cp_status_t status;
  int num;
  std::string ext_point(TranslateType(type));
  cp_extension_t **exts = m_cpluff->get_extensions_info(m_cp_context, ext_point.c_str(), &status, &num);
  for(int i=0; i <num; i++)
  {
    const cp_extension_t *props = exts[i];
    if (IsAddonDisabled(props->plugin->identifier) != enabled)
    {
      AddonPtr addon(Factory(props));
      if (addon)
      {
        if (enabled)
        {
          // if the addon has a running instance, grab that
          AddonPtr runningAddon = addon->GetRunningInstance();
          if (runningAddon)
            addon = runningAddon;
        }
        addons.push_back(addon);
      }
    }
  }
  m_cpluff->release_info(m_cp_context, exts);
  return addons.size() > 0;
}
Ejemplo n.º 9
0
void AddonMgr::LoadFromDB()
{
    uint32 oldMSTime = getMSTime();

    QueryResult result = CharacterDatabase.Query("SELECT name, crc FROM addons");

    if (!result)
    {
        sLog->outString(">> Loaded 0 known addons. DB table `addons` is empty!");
        sLog->outString();
        return;
    }

    uint32 count = 0;

    do
    {
        Field *fields = result->Fetch();

        std::string name = fields[0].GetString();
        uint32 crc = fields[1].GetUInt32();

        SavedAddon addon(name, crc);
        m_knownAddons.push_back(addon);

        ++count;
    }
    while (result->NextRow());

    sLog->outString(">> Loaded %u known addons in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
    sLog->outString();
}
Ejemplo n.º 10
0
 void Addon::openSettings()
 {
   DelayedCallGuard dcguard(languageHook);
   // show settings dialog
   ADDON::AddonPtr addon(pAddon);
   CGUIDialogAddonSettings::ShowAndGetInput(addon);
 }
Ejemplo n.º 11
0
std::complex<double> ZipfRand::CFImpl(double t) const
{
    std::complex<double> sum(0.0, 0.0);
    for (int i = 1; i <= n; ++i)
    {
        std::complex<double> addon(-s * std::log(i), i * t);
        sum += std::exp(addon);
    }
    return invHarmonicNumber * sum;
}
Ejemplo n.º 12
0
  PyObject* Addon_OpenSettings(Addon *self, PyObject *args, PyObject *kwds)
  {
    // show settings dialog
    AddonPtr addon(self->pAddon);
    CPyThreadState pyState;
    CGUIDialogAddonSettings::ShowAndGetInput(addon);
    pyState.Restore();

    Py_INCREF(Py_None);
    return Py_None;
  }
Ejemplo n.º 13
0
    void Addon::openSettings()
    {
      AddonPtr temp;
      if (!ADDON::CAddonMgr::Get().GetAddon(pAddon->ID(), temp))
        return;

      DelayedCallGuard dcguard(languageHook);
      // show settings dialog
      ADDON::AddonPtr addon(pAddon);
      CGUIDialogAddonSettings::ShowAndGetInput(addon);
    }
Ejemplo n.º 14
0
wxString SectionFieldDescriptor::Format(wxString& value)
{
    if ( value.Length() > GetSize() ) {
        return value.Truncate(GetSize());
    } else {
        wxString addon(GetFiller(), GetSize() - value.Length());
        if ( GetAlignment() == FA_LEFT ) {
            return value + addon;
        } else {
            return addon + value;
        }
    }
}
Ejemplo n.º 15
0
bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* = true */)
{
  CSingleLock lock(m_critSection);
  addons.clear();
  cp_status_t status;
  int num;
  CStdString ext_point(TranslateType(type));
  cp_extension_t **exts = m_cpluff->get_extensions_info(m_cp_context, ext_point.c_str(), &status, &num);
  for(int i=0; i <num; i++)
  {
    AddonPtr addon(Factory(exts[i]));
    if (addon && m_database.IsAddonDisabled(addon->ID()) != enabled)
      addons.push_back(addon);
  }
  m_cpluff->release_info(m_cp_context, exts);
  return addons.size() > 0;
}
Ejemplo n.º 16
0
std::unique_ptr<Addon>
Addon::parse(const ReaderMapping& lisp)
{
  std::unique_ptr<Addon> addon(new Addon);

  try
  {
    if (!lisp.get("id", addon->m_id))
    {
      throw std::runtime_error("(id ...) field missing from addon description");
    }

    if (addon->m_id.empty())
    {
      throw std::runtime_error("addon id is empty");
    }

    if (addon->m_id.find_first_not_of(s_allowed_characters) != std::string::npos)
    {
      throw std::runtime_error("addon id contains illegal characters: " + addon->m_id);
    }

    lisp.get("version", addon->m_version);

    std::string type;
    lisp.get("type", type);
    addon->m_type = addon_type_from_string(type);

    lisp.get("title", addon->m_title);
    lisp.get("author", addon->m_author);
    lisp.get("license", addon->m_license);
    lisp.get("url", addon->m_url);
    lisp.get("md5", addon->m_md5);
    lisp.get("format", addon->m_format);

    return addon;
  }
  catch(const std::exception& err)
  {
    std::stringstream msg;
    msg << "Problem when parsing addoninfo: " << err.what();
    throw std::runtime_error(msg.str());
  }
}
Ejemplo n.º 17
0
bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* = true */)
{
  CStdString xbmcPath = _P("special://xbmc/addons");
  CSingleLock lock(m_critSection);
  addons.clear();
  cp_status_t status;
  int num;
  CStdString ext_point(TranslateType(type));
  cp_extension_t **exts = m_cpluff->get_extensions_info(m_cp_context, ext_point.c_str(), &status, &num);
  for(int i=0; i <num; i++)
  {
    AddonPtr addon(Factory(exts[i]));
    if (addon && addon->Type() == ADDON_PVRDLL && addon->Path().Left(xbmcPath.size()).Equals(xbmcPath))
    {
      if (m_database.IsSystemPVRAddonEnabled(addon->ID()) != enabled)
        addon->Disable();
    }
    if (addon && m_database.IsAddonDisabled(addon->ID()) != enabled)
      addons.push_back(addon);
  }
  m_cpluff->release_info(m_cp_context, exts);
  return addons.size() > 0;
}
/** This initialises the online portion of the addons manager. It uses the
 *  downloaded list of available addons. This is called by network_http before
 *  it goes into command-receiving mode, so we can't use any asynchronous calls
 *  here (though this is being called from a separate thread , so the
 *  main GUI is not blocked anyway). This function will update the state 
 *  variable
 */
void AddonsManager::initOnline(const XMLNode *xml)
{
    m_addons_list.lock();
    // Clear the list in case that a reinit is being done.
    m_addons_list.getData().clear();
    loadInstalledAddons();
    m_addons_list.unlock();

    for(unsigned int i=0; i<xml->getNumNodes(); i++)
    {
        const XMLNode *node = xml->getNode(i);
        const std::string &name = node->getName();
        // Ignore news/redirect, which is handled by network_http
        if(name=="include" || name=="message") continue;
        if(node->getName()=="track" || node->getName()=="kart" ||
            node->getName()=="arena"                                 )
        {
            Addon addon(*node);
            int index = getAddonIndex(addon.getId());

            int stk_version=0;
            node->get("format", &stk_version);
            int   testing=-1;
            node->get("testing", &testing);

            bool wrong_version=false;

            if(addon.getType()=="kart")
                wrong_version = stk_version <stk_config->m_min_kart_version ||
                                stk_version >stk_config->m_max_kart_version   ;
            else
                wrong_version = stk_version <stk_config->m_min_track_version ||
                                stk_version >stk_config->m_max_track_version   ;
            // If the add-on is included, behave like it is a wrong version
            if (addon.testIncluded(addon.getMinIncludeVer(), addon.getMaxIncludeVer()))
                wrong_version = true;

            // Check which version to use: only for this stk version,
            // and not addons that are marked as hidden (testing=0)
            if(wrong_version|| testing==0)
            {
                // If the version is too old (e.g. after an update of stk)
                // remove a cached icon.
                std::string full_path = 
                    file_manager->getAddonsFile("icons/"
                                                +addon.getIconBasename());
                if(file_manager->fileExists(full_path))
                {
                    if(UserConfigParams::logAddons())
                        printf("[addons] Removing cached icon '%s'.\n", 
                               addon.getIconBasename().c_str());
                    file_manager->removeFile(full_path);
                }
                continue;
            }

            m_addons_list.lock();
            if(index>=0)
            {
                Addon& tmplist_addon = m_addons_list.getData()[index];
                
                // Only copy the data if a newer revision is found (ignore unapproved
                // revisions unless player is in the mode to see them)
                if (tmplist_addon.getRevision() < addon.getRevision() &&
                    (addon.testStatus(Addon::AS_APPROVED) || UserConfigParams::m_artist_debug_mode))
                {
                    m_addons_list.getData()[index].copyInstallData(addon);
                }
            }
            else
            {
                m_addons_list.getData().push_back(addon);
                index = m_addons_list.getData().size()-1;
            }
            // Mark that this addon still exists on the server
            m_addons_list.getData()[index].setStillExists();
            m_addons_list.unlock();
        }
        else
        {
            fprintf(stderr, 
                    "[addons] Found invalid node '%s' while downloading addons.\n",
                    node->getName().c_str());
            fprintf(stderr, "[addons] Ignored.\n");
        }
    }   // for i<xml->getNumNodes
    delete xml;

    // Now remove all items from the addons-installed list, that are not
    // on the server anymore (i.e. not in the addons.xml file), and not
    // installed. If found, remove the icon cached for this addon.
    // Note that if (due to a bug) an icon is shared (i.e. same icon on
    // an addon that's still on the server and an invalid entry in the
    // addons installed file), it will be re-downloaded later.
    m_addons_list.lock();
    unsigned int count = m_addons_list.getData().size();

    for(unsigned int i=0; i<count;)
    {
        if(m_addons_list.getData()[i].getStillExists() ||
            m_addons_list.getData()[i].isInstalled())
        {
            i++;
            continue;
        }
        // This addon is not on the server anymore, and not installed. Remove
        // it from the list. 
        if(UserConfigParams::logAddons())
            printf(
                "[addons] Removing '%s' which is not on the server anymore.\n",
                m_addons_list.getData()[i].getId().c_str() );
        std::string icon = m_addons_list.getData()[i].getIconBasename();
        std::string icon_file =file_manager->getAddonsFile("icons/"+icon);
        if(file_manager->fileExists(icon_file))
        {
            file_manager->removeFile(icon_file);
            // Ignore errors silently.
        }
        m_addons_list.getData()[i] = m_addons_list.getData()[count-1];
        m_addons_list.getData().pop_back();
        count--;
    }
    m_addons_list.unlock();

    m_state.setAtomic(STATE_READY);

    if (UserConfigParams::m_internet_status == INetworkHttp::IPERM_ALLOWED)
        downloadIcons();
}   // initOnline
Ejemplo n.º 19
0
void InputMethodManager::setInstance(Instance *instance) {
    FCITX_D();
    d->instance_ = instance;
    d->eventWatcher_.reset(
        d->instance_->watchEvent(EventType::InputContextKeyEvent, EventWatcherPhase::InputMethod, [this](Event &event) {
            FCITX_D();
            auto &keyEvent = static_cast<KeyEvent &>(event);
            auto entry = d->instance_->inputMethodEntry(keyEvent.inputContext());
            if (!entry) {
                return;
            }
            auto engine = static_cast<InputMethodEngine *>(d->instance_->addonManager().addon(entry->addon()));
            if (!engine) {
                return;
            }
            engine->keyEvent(*entry, keyEvent);
        }));
}
Ejemplo n.º 20
0
void itegeppXXR(int *tog, double *lim, char **gent, double *qtrait,
int *xnp, double *likeres, char **freqres, char **hapres, char **desres)
{
  char      lino[10000], lin[10000];
  
  char* CharNull = "\0"; /* 06.11.2014/SKn */

  double    likold,
            pe, pex,                 /* 10.3. 2000 ROHDE */
	    *p2max,
            gsum;                    /* 10.3. 2000 ROHDE */
  int       i, inp, it, j, k, ki, kj, h, s, glev, non,
            ac[2],
	    drei,
	    null,
	    df = 0 /*SKn*/,
	    combinations,
	    nz,
	    iqual,
            nhap,
           *hlist,
	    **pimax,
            h1x, h2x;
  uint      iterations, h1, h2;
  bool      loop;

  // new for create design matrix (tog=0)
  double  pehh,
          *peh;
  

/* Max. 16 SNPs */
 if ( strlen(gent[0]) > 16 ) error ("Number of SNPs should smaller than 17.") ;

  np       = *xnp;
  len      =  (int) (strlen(gent[0]) + 1);

  mg       = ivector(np);
  merke    = ivector(np);
  nulmer   = ivector(np);
  ge       = ivector(np);
  hlist    = ivector(np);
  po       = uivector(len);

  geno     = cmatrix(np, len);
  max_prob = init_dvector(NULL, 0.0, np);
  prob	   = init_dvector(NULL, 0.0, np);


  hap	   = init_dvector (NULL,  0.0, Hapco);
  hc	   = init_ivector (NULL, -1,Hapco);

  po[0]=1;
  for(i=1;i<len;i++)po[i] = 2*po[i-1];
  combinations = po[len-1];


    init_dvector(hap,  0.0, Hapco);
    init_ivector (hc, -1,Hapco);

    ng = 0;

    /* read input data */
    for(inp=0;inp<np;inp++){
    drei = 0;
    null = 0;
    for (i=0; i<len-1; i++) {
    if(i < len-1 && (gent[inp][i] < 48 || gent[inp][i] > 51) ){
    Rprintf("%d %d %d\n",inp, i, gent[inp][i]);
    //Rprintf("\n Error in data person %d\n",inp+1); /* ROHDE 15.03.2000 */
    error("\n Error in data person %d\n",inp+1);;
    }
    if ( gent[inp][i] == '3' )  drei  ++;
    if ( gent[inp][i] == '0' )  null  ++;
    }
    gent[inp][len-1] = '\0';

    it = 1;
    for (i=0; i<ng; i++) {
    if ( strncmp (geno[i], gent[inp], len) == 0 ) {

    /*** a certain genotype was found more than just once ***/
    ge[inp] = i;
    mg[i] ++;
    it       = 0;
    merke[i] = drei;
    break;
    }
    }
    if (it) {
    /*** a certain genotype was encountered the first time ***/
    strcpy (geno[ng], gent[inp]);
    ge[inp] = ng;
    mg[ng]    = 1;
    merke[ng] = drei;
    nulmer[ng] = null;
    ng ++;
    }
    }   /* end while */
    People 	= np;
    Loci 	= len-1;
    /* end of reading sample data */

    nall = 2 * np;
    nstate  = init_ivector (NULL, 0, ng);
    mstate  = init_ivector (NULL, 0, ng);

    state = (uint***) calloc(ng , sizeof(uint**));
    for (i=0; i<ng; i++) {
      nz       = po[merke[i]] * po[nulmer[i]] * po[nulmer[i]];
      state[i] = uimatrix(nz, 2);
    }
    /*** sort genotypes by weights *******************************************/
    genoProb = dvector(ng);
    genoId   = ivector(ng);
    for (i=0; i<ng; i++) {
      genoId[i]   = i;
      genoProb[i] = ((double)mg[i])/((double) po[merke[i]])/pow(4.0,nulmer[i]);
    }
    sortByProb(genoProb, genoId, ng);

    glev=0;
    for(i=0;i<ng;i++)if(genoProb[i] >= SignificanceLevel)glev++;

    /*** process sorted genotypes ********************************************/

    nh = 0;

    for (i=0; i<glev; i++) {
/*    printf("\n ng: %d glev: %d  i: %d",ng,glev+1,i+1);    */
      rechap(genoId[i], 0, len-1);
/*    printf("\n %s >> %d\n",geno[genoId[i]],mg[genoId[i]]);
      for(k=0;k<16;k++)printf("%2d:%g ",hc[k],hap[k]);
      printf("\n");                                         */
    }

    for (i=glev; i<ng; i++) {
      s = 0;
/*    printf("\n ng: %d glev: %d  i: %d",ng,glev+1,i+1);    */
      for (j=0; j<nh; j++) {
        ac[0] = hc[j];
        for (k=j; k<nh; k++) {
          ac[1] = hc[k];
	  if ( compatible(geno[genoId[i]], ac) ) {
            state[genoId[i]][s][0] = j;
            state[genoId[i]][s][1] = k;
            s ++;
            if ( j != k ) {
              state[genoId[i]][s][0] = k;
              state[genoId[i]][s][1] = j;
              s ++;
	    }
	  }
        }
      }
      nstate[genoId[i]] = s;
    }
    for (i=glev; i<ng; i++) {
      addon(genoId[i]);
    }

/*  printf("\n");
    printf("\ngloop: %d ng: %d glev: %d nh: %d\n",gloop,ng,glev,nh);  */

    /*** now comes the output that does not need simulated annealing *********/

    first  = 1;           /*** start likelihood outside of annealing loops ***/

    df = nh;

    hapnew = init_dvector(NULL, 0.0, nh );
    haptmp = init_dvector(NULL, 0.0, nh );

    for (i=0; i<ng; i++)selprob(i);

    likold = likea();

    /* Continue computation of mean probabilities */

    for(i=0;i<ng;i++)
      for(j=0;j<mstate[i];j++) {
        double pp = 0.0;

        if ( nstate[i] > 1 ) {
          h          = state[i][j][0];
          hapnew[h] += (double)mg[i] / (double)mstate[i];
          h          = state[i][j][1];
          pp        += hapnew[h];
          hapnew[h] += ((double) mg[i]) / ((double) mstate[i]);
          pp        += hapnew[h];
        }
        else {
          h          = state[i][j][0];
          hapnew[h] += 2.0 * ((double) mg[i]) / ((double) mstate[i]);
          pp        += hapnew[h];
        }
      }


    non = 0;
    for (i=0; i<nh; i++) {
    if(hapnew[i]==0.0)non++;
    else hapnew[i] /= (double) nall;
    }

    for (i=0; i<nh; i++) {
    if(hapnew[i]==0.0)hapnew[i] = 0.0001/(double)non;
    else hapnew[i] *= 0.9999;
    }


	iterations = 0;
    first = 0;

    do {
      loop = 0;
      iterations ++;
/*    printf("gloop:%3d  count: %d\n",gloop,iterations);  */
      /* Recompute mean probabilities */
      for (i=0; i<nh; i++) {
        if ( fabs(hap[i] - hapnew[i]) > LoopPrecision )
          loop = 1;
        hap[i] = hapnew[i];
      }

      init_dvector(prob,   0.0, np);
      init_dvector(haptmp, 0.0, nh);
      init_dvector(hapnew, 0.0, nh);
      likold = likea();
      for (i=0; i<nh; i++)
        hapnew[i] /= (double) nall;

    } while (loop);

/*  Rprintf("\n");
    Rprintf("  Results Ensemble means: \n\n"); */
    nhap = 0;
    j    = 0;
    for (i=0; i<nh; i++)
      {
      if ( hapnew[i] >= *lim ) {
    /* 07.06.2007  S.Kn|ppel > Beschrdnken der geschdtzten Haplotypen. */
    if ( (*tog==0) &&  ((nhap+1) > 1500) ) {
     error ("Error in itegeppXXR: Too much estimated haplotypes. Increase option lim.") ;
    }
    if ( (*tog==1) &&  ((nhap+1) > 1500) ) {
     error ("Error in itegeppXXR: Too much estimated haplotypes. Increase option lim.") ;
    }


       
/*    	sprintf(lino,"\0"); 02.06.2015/SKn */  
    /*    sprintf("%s", "%s", *lino, *CharNull);*/
       sprintf(lino, "%s", CharNull);


   printHaplotype(hc[i], len, lino);
	/*
        printf("    hapnew[%8d] = %7.4f  (%7.4f)\n",
	    hc[i], hapnew[i], hap[i]);
        */
  /* sprintf(lin,"%9.6f\0", hapnew[i]); 06.11.2014/SKn */
	sprintf(lin,"%9.6f%s", hapnew[i], CharNull); /* 06.11.2014/SKn */
	strcat(lino,lin);
	strcpy(freqres[j],lino);
	j++;
        hlist[nhap++] = i;



      }
      }
      k = 0;
      htpp = init_uimatrix(NULL,0,nhap+1,nhap+1);
      for(i=0;i<nhap+1;i++)
	      for(j=i;j<nhap+1;j++)htpp[i][j]=k++;

      pgen = init_dmatrix(NULL,0.0,ng,(nhap+1)*(nhap+2)/2);

      /* start find best states after MLE   10.3.2000 ROHDE  */

   	  pimax  = imatrix(ng,10);               /* ROHDE  10.3.2000 */
          p2max = init_dvector(NULL,0.0,ng);     /* ROHDE  10.3.2000 */
	  for(i=0;i<ng;i++)max_prob[i] = 0.0;    /* ROHDE  10.3.2000 */
      for (i=0;i<ng;i++){
      for(j=0;j<10;j++)pimax[genoId[i]][j] = -1;
          iqual=1;
      for (j=0;j<nstate[genoId[i]];j++){
      pe = hapnew[state[genoId[i]][j][0]] * hapnew[state[genoId[i]][j][1]];
	  if( state[genoId[i]][j][0] != state[genoId[i]][j][1] ) pe += pe;

	  if(pe > p2max[genoId[i]]){

      if (pe > max_prob[genoId[i]]){
		p2max[genoId[i]] = max_prob[genoId[i]];
      	max_prob[genoId[i]] = pe;
      	pimax[genoId[i]][0]=j;
		for(k=1;k<10;k++)pimax[genoId[i]][k]=-1;
		iqual = 1;                 /***   ROHDE  04.09.2001 ***/
      	}

	  else{
	  if (pe == max_prob[genoId[i]] && iqual < 9){
	  	for(k=0;k<iqual;k++) if(state[genoId[i]][j][0] ==
						state[genoId[i]][pimax[genoId[i]][k]][1]) pe=0.0;
	  	if(pe > 0.0)pimax[genoId[i]][iqual++]=j;
	  	}
	    else p2max[genoId[i]] = pe;
		}
	  }

      }
      }    /* end of maximum state search */

/*    Rprintf("\n Haplotypes after MLE\n");           */
      jjx = 0;
      for(i=0;i<np;i++){
        /* sprintf(lino,"%i %s >> \0",i, geno[ge[i]]); 06.11.2014/SKn */
           sprintf(lino,"%i %s >> %s",i, geno[ge[i]], CharNull);
        for(k=0;k<10;k++){
          j = pimax[ge[i]][k];
          if(j > -1){
            if(k>0)pspace(len+3,lino);   /*** ROHDE  11.09.2001 ***/
            printHaplotype(hc[state[ge[i]][j][0]],len,lino);
            strcat(lino," <> \0");
            printHaplotype(hc[state[ge[i]][j][1]],len,lino);
            sprintf(lin,"  P>> %9.7f D>> %9.7f",
      	                 max_prob[ge[i]],max_prob[ge[i]]-p2max[ge[i]]);
            strcat(lino,lin);
          } else break;
        }
        strcpy(hapres[jjx++],lino);
      }

      /* endfind best states after MLE   10.3.2000 ROHDE  */


/*    Rprintf("\n\n       Likelihood = %f\n", likold);
      Rprintf("\n");                                      */
      /* sprintf(lino,"Likelihood = %f\0", likold); 06.11.2014/SKn */
         sprintf(lino,"Likelihood = %f%s", likold, CharNull);
     // strcpy(likeres[0],lino);
      (*likeres) = likold ;
      
/*  Sample over states for each genotype ***********************************/

      for(i=0;i<ng;i++){
      gsum = 0.0;
      for(j=0;j<nstate[genoId[i]];j++){
      h1 = state[genoId[i]][j][0];
      h2 = state[genoId[i]][j][1];
      h1x = h2x = 0;
      for(ki=1;ki<=nhap;ki++) if( h1 == hlist[ki-1] ) h1x=ki;
      for(kj=1;kj<=nhap;kj++) if( h2 == hlist[kj-1] ) h2x=kj;
      if(h1x>0 && h2x>0){
	      if(h2x < h1x){ k=h1x; h1x=h2x; h2x=k;}
	      pgen[genoId[i]][htpp[h1x-1][h2x-1]] += hapnew[h1]*hapnew[h2];
	                                     gsum += hapnew[h1]*hapnew[h2];
	}
	else{ pgen[genoId[i]][htpp[nhap][nhap]] += hapnew[h1]*hapnew[h2];
		                           gsum += hapnew[h1]*hapnew[h2];
	}
      }
      for(k=0;k<(nhap+1)*(nhap+2)/2;k++)pgen[genoId[i]][k] /= gsum;
      }

/*    for(i=0;i<ng;i++){
      Rprintf("i:%2d  %s\t",i,geno[genoId[i]]);
      for(ki=0;ki<nhap+1;ki++){
	for(kj=ki;kj<nhap+1;kj++)
               Rprintf("%4.2f ",pgen[genoId[i]][htpp[ki][kj]]);
	if(kj<ki)printf("0.000\t ");
	else	printf("%4.2f\t",pgen[genoId[i]][htpp[ki][kj]]);
      Rprintf("\t");
      }
      Rprintf("\n");
      }
*/

      jjx = 0;

      if (*tog == 1){
      for(i=0;i<np;i++){
      /*
      printf("\n%4s %s %4.2f >> ",pid[i],geno[ge[i]],qtrait[i]);
      */
      strcpy(lino,"\0");
      for(ki=0;ki<nhap;ki++){  /*  each haplotype alone   */
        for(kj=ki;kj<nhap;kj++){
          /* sprintf(lin,"%8.6f \0",pgen[ge[i]][htpp[ki][kj]]); 06.11.2014/SKn */
	           sprintf(lin,"%8.6f %s",pgen[ge[i]][htpp[ki][kj]], CharNull);
          strcat(lino,lin);
	      }

      }
      
      /* sprintf(lin,"%8.6f\0",pgen[ge[i]][htpp[nhap][nhap]]); 06.11.2014/SKn */
         sprintf(lin,"%8.6f%s",pgen[ge[i]][htpp[nhap][nhap]], CharNull);
      strcat(lino,lin);
      strcpy(desres[jjx],lino);
      jjx++;
      }
      }
      
 /* gedndert nach Klaus; Bildung Designmatrix
    16.09.2008 */
 
 /*     if(*tog == 0){
      for(i=0;i<np;i++){
      //
      //printf("\n%4s %s %4.2f >> ",id[i],geno[ge[i]],qtrait[i]);
      //
      strcpy(lino,"\0");
          pex = 0.0;
      for(j=0;j<nhap;j++){
          pe = 0.0;
      for(ki=0;ki<nhap;ki++){    // over all haplotype pairs  
      for(kj=ki;kj<nhap;kj++){
      if(ki==j && kj==j && pgen[ge[i]][htpp[ki][kj]] > 0.0)
	      pe +=2.0*pgen[ge[i]][htpp[ki][kj]];
      else if ((ki==j || kj==j) && pgen[ge[i]][htpp[ki][kj]] > 0.0)
                                    pe += pgen[ge[i]][htpp[ki][kj]];
      }
      }
      pex += pe;
      sprintf(lin,"%8.6f \0",pe);
      strcat(lino,lin);
      }
      sprintf(lin,"%8.6f\0",2.0-pex);
      strcat(lino,lin);
      strcpy(desres[jjx],lino);
      jjx++;
      }
      }
*/
/* new: nach Klaus; 17.09.2008 */
        if(*tog == 0){
        
      peh = init_dvector(NULL, 0.0, nhap+1);
      for(i=0;i<np;i++){
      /*
      printf("\n%4s %s %4.2f >> ",id[i],geno[ge[i]],qtrait[i]);
      */
      strcpy(lino,"\0");
      for(j=0;j<nhap;j++){
      gsum  = 0.0;
      /*
      for(ki=0;ki<nhap;ki++){    * over all haplotype pairs  *
      for(kj=ki;kj<nhap;kj++){
      if(ki==j && kj==j && pgen[ge[i]][htpp[ki][kj]] > 0.0)
	      pe +=2.0*pgen[ge[i]][htpp[ki][kj]];
      else if ((ki==j || kj==j) && pgen[ge[i]][htpp[ki][kj]] > 0.0)
                                    pe += pgen[ge[i]][htpp[ki][kj]];
      }
      }
      */
      for(ki=0;ki<nstate[ge[i]];ki++){
      h1 = state[ge[i]][ki][0];
      h2 = state[ge[i]][ki][1];
      h  = hlist[j];
      pex = hapnew[h1]*hapnew[h2];
      gsum += 2*pex;
      if((h == h1) && (h == h2))peh[j] += 2*pex;
      else if((h == h1) || (h == h2))peh[j] += pex;
      }  /* end nstate */
      }  /* end nhap   */
      pehh = 0.0;
      for(j=0;j<nhap;j++){
      pehh += 2*peh[j];
      /* sprintf(lin,"%8.6f \0",2*peh[j]/gsum); 06.11.2014/SKn */
      sprintf(lin,"%8.6f %s",2*peh[j]/gsum, CharNull);
      strcat(lino,lin);
      }  /* end print */
      /* sprintf(lin,"%8.6f\0",2.0-pehh/gsum); 06.11.2014/SKn */
         sprintf(lin,"%8.6f%s",2.0-pehh/gsum, CharNull);
      
      strcat(lino,lin);
      strcpy(desres[jjx],lino);
      jjx++;
      init_dvector(peh, 0.0, nhap+1);
      }  /*  end np  */
      destroy_d_array(peh);
      }

    
    destroy_c_array2(geno);
    destroy_u_array(po);
    for ( i=0;i<ng;i++) { destroy_u_array2(state[i]) ; }
    free((uint***)state);
    destroy_u_array2(htpp);
    destroy_i_array(nstate);
    destroy_i_array(mstate);
    destroy_i_array(genoId);
    destroy_i_array(mg);
    destroy_i_array(merke);
    destroy_i_array(nulmer);
    destroy_i_array(ge);
    destroy_i_array(hlist);
    destroy_d_array(prob);
    destroy_d_array(max_prob);
    destroy_d_array(hapnew);
    destroy_d_array(haptmp);
    destroy_d_array(hap);
    destroy_d_array(genoProb);
    destroy_d_array2(pgen);
    destroy_i_array(hc);
    destroy_d_array(p2max);
    destroy_i_array2(pimax);
}
Ejemplo n.º 21
0
void WorldSession::ReadAddonsInfo(WorldPacket &data)
{
    if (data.rpos() + 4 > data.size())
        return;

    uint32 size;
    data >> size;

    if (!size)
        return;

    if (size > 0xFFFFF)
    {
        TC_LOG_ERROR("misc", "WorldSession::ReadAddonsInfo addon info too big, size %u", size);
        return;
    }

    uLongf uSize = size;

    uint32 pos = data.rpos();

    ByteBuffer addonInfo;
    addonInfo.resize(size);

    if (uncompress(addonInfo.contents(), &uSize, data.contents() + pos, data.size() - pos) == Z_OK)
    {
        uint32 addonsCount;
        addonInfo >> addonsCount;                         // addons count

        for (uint32 i = 0; i < addonsCount; ++i)
        {
            std::string addonName;
            uint8 usingPubKey;
            uint32 crc, urlFile;

            // check next addon data format correctness
            if (addonInfo.rpos() + 1 > addonInfo.size())
                return;

            addonInfo >> addonName;

            addonInfo >> usingPubKey >> crc >> urlFile;

            TC_LOG_INFO("misc", "ADDON: Name: %s, UsePubKey: 0x%x, CRC: 0x%x, UrlFile: %i", addonName.c_str(), usingPubKey, crc, urlFile);

            AddonInfo addon(addonName, true, crc, 2, usingPubKey);

            SavedAddon const* savedAddon = AddonMgr::GetAddonInfo(addonName);
            if (savedAddon)
            {
                if (addon.CRC != savedAddon->CRC)
                    TC_LOG_INFO("misc", "ADDON: %s was known, but didn't match known CRC (0x%x)!", addon.Name.c_str(), savedAddon->CRC);
                else
                    TC_LOG_INFO("misc", "ADDON: %s was known, CRC is correct (0x%x)", addon.Name.c_str(), savedAddon->CRC);
            }
            else
            {
                AddonMgr::SaveAddon(addon);

                TC_LOG_INFO("misc", "ADDON: %s (0x%x) was not known, saving...", addon.Name.c_str(), addon.CRC);
            }

            /// @todo Find out when to not use CRC/pubkey, and other possible states.
            m_addonsList.push_back(addon);
        }

        uint32 currentTime;
        addonInfo >> currentTime;
        TC_LOG_DEBUG("network", "ADDON: CurrentTime: %u", currentTime);
    }
Ejemplo n.º 22
0
Archivo: main.c Proyecto: pgtux/C
int main(void) {
	printf("-- We are gonna check the call to shared object --\n");
	shared_function();
	addon();
	return 0;
}
Ejemplo n.º 23
0
void WorldSession::ReadAddonsInfo(WorldPacket &data)
{
    if (data.rpos() + 4 > data.size())
        return;

    uint32 size;
    data >> size;

    if (!size)
        return;

    if (size > 0xFFFFF)
    {
        sLog->outError(LOG_FILTER_GENERAL, "WorldSession::ReadAddonsInfo addon info too big, size %u", size);
        return;
    }

    uLongf uSize = size;

    uint32 pos = data.rpos();

    ByteBuffer addonInfo;
    addonInfo.resize(size);

    if (uncompress(const_cast<uint8*>(addonInfo.contents()), &uSize, const_cast<uint8*>(data.contents() + pos), data.size() - pos) == Z_OK)
    {
        uint32 addonsCount;
        addonInfo >> addonsCount;                         // addons count

        for (uint32 i = 0; i < addonsCount; ++i)
        {
            std::string addonName;
            uint8 enabled;
            uint32 crc, unk1;

            // check next addon data format correctness
            if (addonInfo.rpos() + 1 > addonInfo.size())
                return;

            addonInfo >> addonName;

            addonInfo >> enabled >> crc >> unk1;

            sLog->outInfo(LOG_FILTER_GENERAL, "ADDON: Name: %s, Enabled: 0x%x, CRC: 0x%x, Unknown2: 0x%x", addonName.c_str(), enabled, crc, unk1);

            AddonInfo addon(addonName, enabled, crc, 2, true);

            SavedAddon const* savedAddon = AddonMgr::GetAddonInfo(addonName);
            if (savedAddon)
            {
                bool match = true;

                if (addon.CRC != savedAddon->CRC)
                    match = false;

                if (!match)
                    sLog->outInfo(LOG_FILTER_GENERAL, "ADDON: %s was known, but didn't match known CRC (0x%x)!", addon.Name.c_str(), savedAddon->CRC);
                else
                    sLog->outInfo(LOG_FILTER_GENERAL, "ADDON: %s was known, CRC is correct (0x%x)", addon.Name.c_str(), savedAddon->CRC);
            }
            else
            {
                AddonMgr::SaveAddon(addon);

                sLog->outInfo(LOG_FILTER_GENERAL, "ADDON: %s (0x%x) was not known, saving...", addon.Name.c_str(), addon.CRC);
            }

            // TODO: Find out when to not use CRC/pubkey, and other possible states.
            m_addonsList.push_back(addon);
        }

        uint32 currentTime;
        addonInfo >> currentTime;
        sLog->outDebug(LOG_FILTER_NETWORKIO, "ADDON: CurrentTime: %u", currentTime);

        if (addonInfo.rpos() != addonInfo.size())
            sLog->outDebug(LOG_FILTER_NETWORKIO, "packet under-read!");
    }
Ejemplo n.º 24
0
void WorldSession::ReadAddonsInfo (WorldPacket &data)
{
    if (data.rpos() + 4 > data.size())
        return;
    uint32 size;
    data >> size;

    if (!size)
        return;

    if (size > 0xFFFFF)
    {
        sLog->outError("WorldSession::ReadAddonsInfo addon info too big, size %u", size);
        return;
    }

    uLongf uSize = size;

    uint32 pos = data.rpos();

    ByteBuffer addonInfo;
    addonInfo.resize(size);

    if (uncompress(const_cast<uint8*>(addonInfo.contents()), &uSize, const_cast<uint8*>(data.contents() + pos), data.size() - pos) == Z_OK)
    {
        uint32 addonsCount;
        addonInfo >> addonsCount;          // addons count

        for (uint32 i = 0; i < addonsCount; ++i)
        {
            std::string addonName;
            uint8 enabled;
            uint32 crc, unk1;

            // check next addon data format correctness
            if (addonInfo.rpos() + 1 > addonInfo.size())
                return;

            addonInfo >> addonName;

            addonInfo >> enabled >> crc >> unk1;

            AddonInfo addon(addonName, enabled, crc, 2, true);

            SavedAddon const* savedAddon = sAddonMgr->GetAddonInfo(addonName);
            if (savedAddon)
            {
                bool match = true;

                if (addon.CRC != savedAddon->CRC)
                    match = false;
            }
            else
                sAddonMgr->SaveAddon(addon);

            // TODO: Find out when to not use CRC/pubkey, and other possible states.
            m_addonsList.push_back(addon);
        }

        uint32 currentTime;
        addonInfo >> currentTime;
        sLog->outDebug(LOG_FILTER_NETWORKIO, "ADDON: CurrentTime: %u", currentTime);

        if (addonInfo.rpos() != addonInfo.size())
            sLog->outDebug(LOG_FILTER_NETWORKIO, "packet under-read!");
    }