Пример #1
0
void ObjectPool::releaseObjectAtPos(PoolItem *item, size_t pos)
{
    if (!isused(pos))
        printf ("error: release of an unused item %p [location: %ld]\n", item, pos);
    else
        setused(pos, 0);
}
Пример #2
0
// calculate per cell scores
static void mkscores(void) {int i,j,k,l,m; int*p; float f;
for(i=0;i<nc;i++) for(j=0;j<nl;j++) cells[i].score[j]=0.0;
for(i=0;i<nw;i++) {
  m=words[i].length;
  p=words[i].flist;
  l=words[i].flistlen;
//  if(p==NULL) {p=dwds[words[i].length];l=dcount[words[i].length];} // default feasible word list
  if(words[i].fe) continue;
  if(afunique&&words[i].commit>=0) {  // avoid zero score if we've committed
    if(l==1) for(k=0;k<m;k++) words[i].c[k]->score[chartol[(int)lts[p[0]].s[k]]]+=1.0;
    else     assert(l==0);
    }
  else {
    for(j=0;j<l;j++) if(!(afunique&&isused(p[j]))) { // for each remaining feasible word
      f=ansp[lts[p[j]].ans]->score;
      for(k=0;k<m;k++) words[i].c[k]->score[chartol[(int)lts[p[j]].s[k]]]+=f; // add in its score to this cell's score
      }
    }
  }
for(i=0;i<ne;i++) for(j=0;j<nl;j++) entries[i].score[j]=1.0;
for(i=0;i<nc;i++) {
//   f=(float)lcount[cells[i].w->length];
//  if(f!=0.0) f=1.0/f;
  f=1.0;
  for(j=0;j<nl;j++) cells[i].e->score[j]*=f*cells[i].score[j]; // copy scores to entries, scaled by total word count at this length
  }
for(i=0;i<ne;i++) {
  f=-BIGF; for(j=0;j<nl;j++) f=MX(f,entries[i].score[j]);
  entries[i].crux=f; // crux at an entry is the greatest score over all possible letters
  }
}
Пример #3
0
// check updated entries and rebuild feasible word lists
// returns -2 for infeasible, -1 for out of memory, 0 if no feasible word lists affected, >=1 otherwise
static int settleents(void) {struct entry*e;struct word*w;int f,i,l; int*p;
DEB1 printf("settleents() sdep=%d\n",sdep);
f=0;
for(i=0;i<nc;i++) cells[i].upd=0;
for(i=0;i<nc;i++) cells[i].upd|=cells[i].e->upd; // generate cell updated flags from entry updated flags
for(i=0;i<nc;i++) if(cells[i].upd) {
  e=cells[i].e;
  w=cells[i].w;
  p=w->flist;
  l=w->flistlen;
  if(sflistlen[sdep][w-words]==-1) {  // then we mustn't trash words[].flist
    sflist   [sdep][w-words]=w->flist;
    sflistlen[sdep][w-words]=w->flistlen;
    w->flist=(int*)malloc(l*sizeof(int)); // new list can be at most as long as old one
    if(w->flist==NULL) return -1; // out of memory
    ct_malloc++;
    }
  w->flistlen=listisect(w->flist,p,l,cells[i].wp,e->flbm); // generate new feasible word list
  if(w->flistlen!=l) {w->upd=1;f++;} // word list has changed: feasible letter lists will need updating
  if(w->flistlen==0&&!w->fe) return -2; // no options left, not a fully-entered word
  if(w->flistlen==1&&w->commit==-1) { // down to a single word?
    if(afunique&&isused(w->flist[0])) { // in no-duplicates mode and only answer left is already used? (could check all on list)
      w->flistlen=0; // abort
      return -2;
      }
    else { // otherwise, if down to one word, commit it
//      printf("committing word %d (%s)\n",w,lts[w->flist[0]].s);fflush(stdout);
      setused(w->flist[0],1); // flag as used
      w->commit=w->flist[0];
      scommit[sdep][w-words]=w->flist[0];
      }
    }
  }
for(i=0;i<ne;i++) entries[i].upd=0; // all entry update effects now propagated into word updates
// printf("settleents returns %d\n",f);fflush(stdout);
return f;
}
Пример #4
0
bool CertificatesScreen::Certificate::processKeyInFocus(const Key &key)
{
	if (key == key_DELETECERTIFICATE)
	{
		std::vector<myServer *>::iterator b, e;

		for (b=myServer::server_list.begin(),
			     e=myServer::server_list.end();
		     b != e; ++b)
		{
			if ((*b)->certificate == id)
			{
				isused( (*b)->serverName);
				return true;
			}
		}

		if (id == myServer::smtpServerCertificate)
		{
			mail::loginInfo SMTPServerLoginInfo;

			mail::loginUrlDecode(myServer::smtpServerURL,
					     SMTPServerLoginInfo);

			isused(Gettext(_("%1% (SMTP server)")) <<
			       SMTPServerLoginInfo.server);
			return true;

		}

		myServer::promptInfo askdel(_("Delete this certificate? (Y/N) "));

		askdel=myServer::prompt(askdel.yesno());

		if (askdel.abortflag || (std::string)askdel != "Y")
			return true;

		parent->removeCertificate(myIter);
		return true;
	}

	if (key == key_RENAMECERTIFICATE)
	{
		myServer::promptInfo
			newname(_("New certificate name: "));

		newname=myServer::prompt(newname);

		if (newname.abortflag)
			return true;

		std::string newname_s=newname;

		if (newname_s.size() == 0)
			return true;

		myServer::certs->certs[id].name=newname_s;
		setText(newname_s);
		PasswordList::passwordList.save();
		return true;
	}

	return CursesButton::processKeyInFocus(key);
}