Exemple #1
12
void DumbFramebuffer::Create()
{
	int r;

	const FormatInfo& format_info = format_info_array.at(m_format);

	m_num_planes = format_info.num_planes;

	for (int i = 0; i < format_info.num_planes; ++i) {
		const FormatPlaneInfo& pi = format_info.planes[i];
		FramebufferPlane& plane = m_planes[i];

		/* create dumb buffer */
		struct drm_mode_create_dumb creq = drm_mode_create_dumb();
		creq.width = width() / pi.xsub;
		creq.height = height() / pi.ysub;
		creq.bpp = pi.bitspp;
		r = drmIoctl(card().fd(), DRM_IOCTL_MODE_CREATE_DUMB, &creq);
		if (r)
			throw std::invalid_argument("foo");

		plane.handle = creq.handle;
		plane.stride = creq.pitch;
		plane.size = creq.height * creq.pitch;

		/*
		printf("buf %d: %dx%d, bitspp %d, stride %d, size %d\n",
			i, creq.width, creq.height, pi->bitspp, plane->stride, plane->size);
		*/

		/* prepare buffer for memory mapping */
		struct drm_mode_map_dumb mreq = drm_mode_map_dumb();
		mreq.handle = plane.handle;
		r = drmIoctl(card().fd(), DRM_IOCTL_MODE_MAP_DUMB, &mreq);
		if (r)
			throw std::invalid_argument("foo");

		/* perform actual memory mapping */
		m_planes[i].map = (uint8_t *)mmap(0, plane.size, PROT_READ | PROT_WRITE, MAP_SHARED,
						  card().fd(), mreq.offset);
		if (plane.map == MAP_FAILED)
			throw std::invalid_argument("foo");

		/* clear the framebuffer to 0 */
		memset(plane.map, 0, plane.size);
	}

	/* create framebuffer object for the dumb-buffer */
	uint32_t bo_handles[4] = { m_planes[0].handle, m_planes[1].handle };
	uint32_t pitches[4] = { m_planes[0].stride, m_planes[1].stride };
	uint32_t offsets[4] = { 0 };
	uint32_t id;
	r = drmModeAddFB2(card().fd(), width(), height(), (uint32_t)format(),
			  bo_handles, pitches, offsets, &id, 0);
	if (r)
		throw std::invalid_argument("foo");

	set_id(id);
}
Exemple #2
0
void	card(char *s, char *p, int type, t_list *tokens)
{
	struct dirent	*f;
	DIR				*ret;
	char			*t;
	int				i;

	if ((i = 0) && s[0] == '/')
		return (card(s + 1, "/", type, tokens));
	if ((ret = opendir(p)) == NULL)
		return ;
	if (((t = ft_strchr(s, '/')) != NULL))
	{
		while ((f = readdir(ret)) != NULL)
		{
			if ((match(f->d_name, ft_strsub(s, 0, t - s))) && (i = 1))
			{
				ft_putchar(p[s - t]);
				if (((p[s - t] != '.' && s[s - t - 1] != '.') &&
					!ft_strcmp(f->d_name, "..")) || end_point(f->d_name))
					continue ;
				card(t + 1, ft_strjoin(p, f->d_name), type, tokens);
			}
		}
	}
	i = (i == 0) ? card2(s, p, type, tokens) : i;
	closedir(ret);
}
Exemple #3
0
/*
 * Create the file n and copy from file descriptor f.
 */
static void
copy(int f, char *n)
{
	int fd, i, nr, nc;
	char buf[BUFSIZ];

	if (format == 'p')
		card('T', title ? title : n);
	for (i = 0; i < ncopies; i++)
		card(format, &dfname[inchar-2]);
	card('U', &dfname[inchar-2]);
	card('N', n);
	fd = nfile(dfname);
	nr = nc = 0;
	while ((i = read(f, buf, sizeof(buf))) > 0) {
		if (write(fd, buf, i) != i) {
			warn("%s", n);
			break;
		}
		nc += i;
		if (nc >= sizeof(buf)) {
			nc -= sizeof(buf);
			nr++;
			if (MX > 0 && nr > MX) {
				warnx("%s: copy file is too large", n);
				break;
			}
		}
	}
	(void)close(fd);
	if (nc == 0 && nr == 0) 
		warnx("%s: empty input file", f ? n : "stdin");
	else
		nact++;
}
Exemple #4
0
void	wild_card(char *line, t_list *tokens)
{
	int		type;

	if (line[ft_strlen(line) - 1] == '/')
		type = 1;
	else
		type = 2;
	if (line[0] == '.' && line[1] && line[1] == '/')
	{
		opendir("./");
		card(line + 2, "./", type, tokens);
	}
	if (line[0] == '.' && line[1] && line[1] == '.' && line[2]
			&& line[2] == '/')
	{
		opendir("../");
		card(line + 3, "../", type, tokens);
	}
	else if (line[0] == '/')
	{
		opendir("/");
		card(line + 1, "/", type, tokens);
	}
	else if ((type = 3))
		card(line, "./", type, tokens);
}
void KMenuTab::mouseReleaseEvent(QMouseEvent *e)
{
	printf("KMenuTab::mouseReleaseEvent()\n");
	qApp->setGlobalMouseTracking(false);
	setMouseTracking(false);

	_mouseTrackerTimer.stop();

	if (e->button() == Qt::LeftButton && !_dragger.tracking() && !_animating && !mDontOpenCard)
	{
		if (card()->isOpen())
		{
			card()->shut(true);
		}
		else
		{
			card()->open(true);
		}
	}

	if (e->button() == Qt::RightButton)
	{
		showContextMenu();
	}
	_dragger.done();
}
Exemple #6
0
//! @brief How many levels in the "base-set" for that ciphertext
long Ctxt::findBaseLevel() const 
{
  IndexSet s;
  findBaseSet(s);
  if (context.containsSmallPrime()) {
    if (s.contains(context.ctxtPrimes.first()))
      return 2*card(s) -1; // 1st prime is half size
    else
      return 2*card(s);
  }
  else return card(s);     // one prime per level
}
Exemple #7
0
NS_IMETHODIMP nsAbLDAPDirectory::DeleteCards(nsIArray *aCards)
{
    PRUint32 cardCount;
    PRUint32 i;
    nsCAutoString cardDN;

    nsresult rv = aCards->GetLength(&cardCount);
    NS_ENSURE_SUCCESS(rv, rv);

    for (i = 0; i < cardCount; ++i)
    {
        nsCOMPtr<nsIAbLDAPCard> card(do_QueryElementAt(aCards, i, &rv));
        if (NS_FAILED(rv))
        {
            NS_WARNING("Wrong type of card passed to nsAbLDAPDirectory::DeleteCards");
            break;
        }

        // Set up the search ldap url - this is mURL
        rv = Initiate();
        NS_ENSURE_SUCCESS(rv, rv);

        rv = card->GetDn(cardDN);
        NS_ENSURE_SUCCESS(rv, rv);

        // Launch query
        rv = DoModify(this, nsILDAPModification::MOD_DELETE, cardDN, nsnull,
                      EmptyCString(), EmptyCString());
        NS_ENSURE_SUCCESS(rv, rv);
    }

    return NS_OK;
}
Exemple #8
0
void deck_of_cards::init_cards() {
    for (unsigned int i = 0; i < number_of_suits; i++) {
        for (unsigned int j = 0; j < number_of_ranks; j++) {
            cards.push_back(card(static_cast<suit_t>(i), static_cast<rank_t>(j+1)));
        }
    }
}
Exemple #9
0
void Manager::handlePutBottom(ValueEvent<PutBottomMsg>* e)
{
    auto v = e->value();
    Seat* s = seat(v.seat());
    std::vector<Card> bottom;
    for (auto c : v.card()) {
        bottom.push_back(c);
    }
    if (mStatus != PickBottom) {
        notifyPutBottomFail(s, bottom, ErrorCode::StatusError);
        return;
    }
    if (s->seat() != mDealer) {
        notifyPutBottomFail(s, bottom, ErrorCode::PerformerError);
        return;
    }
    try {
        mChecker->putBottom(s, bottom);
        mRes.putBottom(bottom);
        mStatus = BottomFinish;
        notifyFixBottom(s, bottom, FixBottomReason::Normal);
    } catch (Exception& e) {
        notifyPutBottomFail(s, bottom, e.code());
    }
}
Exemple #10
0
Deck::Deck() : mCardsLeft(52) {
	for (unsigned int i(0); i < SUIT_MAX; ++i)
		for (unsigned int j(0); j < RANK_MAX; ++j) {
				Card card(i, j, j);
				mDeck.push_back(card);
		}
}
Exemple #11
0
void deck::reset(){
	cards.clear();
	for(int rank = card::ACE; rank <= card::KING; rank++)
		for(int suit = card::SPADES; suit <= card::CLUBS; suit++){
			cards.push_back(card(card::cardRank(rank), card::cardSuit(suit)));
		}
}
Exemple #12
0
void SingleCRT::toPoly(ZZX& poly, const IndexSet& s) const
{
  IndexSet s1 = map.getIndexSet() & s;

  if (card(s1) == 0) {
    clear(poly);
    return;
  }

  ZZ p = to_ZZ(context.ithPrime(s1.first()));  // the first modulus

  poly = map[s1.first()];  // Get poly modulo the first prime

  vec_ZZ& vp = poly.rep;

  // ensure that coeficient vector is of size phi(m) with entries in [-p/2,p/2]
  long phim = context.zMstar.phiM();
  long vpLength = vp.length();
  if (vpLength<phim) { // just in case of leading zeros in poly
    vp.SetLength(phim);
    for (long j=vpLength; j<phim; j++) vp[j]=0;
  }
  ZZ p_over_2 = p/2;
  for (long j=0; j<phim; j++) if (vp[j] > p_over_2) vp[j] -= p;

  // do incremental integer CRT for other levels  
  for (long i = s1.next(s1.first()); i <= s1.last(); i = s1.next(i)) {
    long q = context.ithPrime(i);       // the next modulus

    // CRT the coefficient vectors of poly and current
    intVecCRT(vp, p, map[i].rep, q);    // defined in the module NumbTh
    p *= q;     // update the modulus
  }
  poly.normalize(); // need to call this after we work on the coeffs
}
Exemple #13
0
void DrmObject::print_props() const
{
	for (auto it = m_prop_values.begin(); it != m_prop_values.end(); ++it) {
		cout << "\t" << card().get_prop(it->first)->name() <<
			" = " << it->second << endl;
	}
}
Exemple #14
0
/** 
 * Converts the k power set of X in the "natural" order to char**
 * Function is suboptimal, partly because of SET_MAX
 *
 * @param n cardinality of X
 * @param sb the length of k_power_set
 * @param k_power_set array representing the k power set of X
 * @param subset converted k power set 
 * @author Michel Grabisch and Ivan Kojadinovic  
 */
void k_power_set_char(int *n, int *sb, int *k_power_set, char **subset) {

  subset[0] = (char *) R_alloc(3, sizeof(char));
  sprintf(subset[0],"{}");

  for(int i=1; i<*sb; i++) {
    int j, x[32];

    for(j=0; j<*n; j++)
      x[j]=0;

    binary2subset(*n, k_power_set[i], x);

    subset[i] = (char *) R_alloc(SET_MAX * (*n), sizeof(char));
    sprintf(subset[i],"{%d",x[0]+1);

    for(j=1; j < card(k_power_set[i]); j++) {
      char string[255];
      sprintf(string,",%d", x[j]+1);
      strcat(subset[i],string);
    }

    strcat(subset[i],"}");
  }
}
Exemple #15
0
void IndexSet::remove(const IndexSet& s) {
  if (this == &s) { clear(); return; }
  if (s.card() == 0) return;
  if (card() == 0) return;

  for (long i = s.first(); i <= s.last(); i = s.next(i)) remove(i);
  // NOTE: traversal order should not matter here
}
Exemple #16
0
void IndexSet::retain(const IndexSet& s) {
  if (this == &s) return;
  if (s.card() == 0) { clear(); return; }
  if (card() == 0) return;

  for (long i = first(); i <= last(); i = next(i)) {
    if (!s.contains(i)) remove(i);
  }
}
Exemple #17
0
void DumbFramebuffer::Destroy()
{
	/* delete framebuffer */
	drmModeRmFB(card().fd(), id());

	for (uint i = 0; i < m_num_planes; ++i) {
		FramebufferPlane& plane = m_planes[i];

		/* unmap buffer */
		munmap(plane.map, plane.size);

		/* delete dumb buffer */
		struct drm_mode_destroy_dumb dreq = drm_mode_destroy_dumb();
		dreq.handle = plane.handle;
		drmIoctl(card().fd(), DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);

	}
}
Exemple #18
0
void Deck::mRefill() {
	std::cout << "Out of cards! Shuffling the deck...." << std::endl;
	for (unsigned int i(0); i < SUIT_MAX; ++i)
		for (unsigned int j(0); j < RANK_MAX; ++j) {
			Card card(i, j, j);
			mDeck.push_back(card);
		}
	mCardsLeft = 52;
}
Exemple #19
0
void love(void)
{
    int n;

    while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount)
	continue;
    if (wordtype[wordnumber] == NOUNS) {
	if ((testbit(location[position].objects, BATHGOD) || testbit(location[position].objects, NORMGOD)) && wordvalue[wordnumber] == NORMGOD) {
	    if (loved) {
		printf("Loved.\n");
		return;
	    }
	    if (godready >= 2) {
		puts("She cuddles up to you, and her mouth starts to work:\n'That was my sister's amulet. The lovely goddess, Purl, was she. The Empire\ncaptured her just after the Darkness came. My other sister, Vert, was killed\nby the Dark Lord himself. He took her amulet and warped its power.\nYour quest was foretold by my father before he died, but to get the Dark Lord's\namulet you must use cunning and skill. I will leave you my amulet,");
		puts("which you may use as you wish. As for me, I am the last goddess of the\nwaters. My father was the Island King, and the rule is rightfully mine.'\n\nShe pulls the throne out into a large bed.");
		power++;
		pleasure += 15;
		ego++;
		if (card(injuries, NUMOFINJURIES)) {
		    puts("Her kisses revive you; your wounds are healed.\n");
		    for (n = 0; n < NUMOFINJURIES; n++)
			injuries[n] = 0;
		    WEIGHT = MAXWEIGHT;
		    CUMBER = MAXCUMBER;
		}
		printf("Goddess:\n");
		if (!loved)
		    setbit(location[position].objects, MEDALION);
		loved = 1;
		ourtime += 10;
		printf("Loved.\n");
		zzz();
		return;
	    } else {
		puts("You wish!");
		return;
	    }
	}
	if (testbit(location[position].objects, wordvalue[wordnumber])) {
	    if (wordvalue[wordnumber] == NATIVE) {
		puts("The girl peels off her sarong and indulges you.");
		power++;
		pleasure += 5;
		printf("Girl:\n");
		ourtime += 10;
		printf("Loved.\n");
		zzz();
	    }
	    if (wordvalue[wordnumber] == MAN || wordvalue[wordnumber] == BODY || wordvalue[wordnumber] == ELF || wordvalue[wordnumber] == TIMER)
		puts("Kinky!");
	    else
		puts("It doesn't seem to work.");
	} else
	    puts("Where's your lover?");
    } else
	puts("It doesn't seem to work.");
}
Exemple #20
0
uint64_t DrmObject::get_prop_value(const string& name) const
{
	for (auto pair : m_prop_values) {
		auto prop = card().get_prop(pair.first);
		if (name == prop->name())
			return m_prop_values.at(prop->id());
	}

	throw invalid_argument(string(name) + ": property not found");
}
Exemple #21
0
bool IndexSet::disjointFrom(const IndexSet& s) const
{
  // quick tests for some common cases
  if (card() == 0 || s.card() == 0
      || last() < s.first() || s.last() < first()) return true;

  for (long i = s.first(); i <= s.last(); i = s.next(i))
    if (contains(i)) return false;
  return true;
}
Exemple #22
0
solution::solution() : desk_()
{
    suit suits[] = { suit::Clubs, suit::Diamonds, suit::Hearts, suit::Spades };
    rank ranks[] = { rank::_2, rank::_3, rank::_4, rank::_5, rank::_6, rank::_7, rank::_8, rank::_9, rank::T, rank::J, rank::Q, rank::K, rank::A };
    desk_.reserve(52);
    std::for_each(suits, suits + 4, [&](const suit& s) {
        std::for_each(ranks, ranks + 13, [&](const rank& r) {
            desk_.push_back(card(r, s));
        });
    });
}
Exemple #23
0
Deck::deck(int num)
{
    for(int i = 0; i < num; i++)
    {
        for(int j = 0; j < VALS * SUITS; j++)
        {
            this.cards.push_back(card(j));
        }
    }
    this.size = VALS * SUITS * num;
}
Exemple #24
0
void Puff::paintEvent(QPaintEvent *e)
{
  Q_UNUSED(e);  
  QPainter painter(this);
  
  // painter.drawRect(p.x(), p.y(), 10, 10);
  // painter.drawImage(p, img);
  QString card("red_joker");
  QRect roi = rdr.boundsOnElement(card).toRect();
  rdr.render(&painter, card, QRect(p, roi.size()));
}
Exemple #25
0
int BingoApp::generateCard(QTextStream& sourceSvgCard, size_t cardNumber)
{
	const QString& targetFilename = generateTargetCardFilename(cardNumber);
	QFile targetFile(targetFilename);
	if ( ! targetFile.open(QIODevice::Text | QIODevice::WriteOnly) )
		{ cerr << "bingo: could not create " << targetFilename << endl; return 22; }

	QTextStream targetStream(&targetFile);
	Card card(cardNumber, symbols);
	return card.fillSvg(sourceSvgCard, targetStream);
}
Exemple #26
0
Deck::Deck()
{
    for (unsigned int i(0); i < SUIT_MAX; ++i)
    {
        for (unsigned int j(0); j < RANK_MAX; ++j)
        {
            Card card(i, j);
            m_deck.push_back(card);
        }
    }
}
PokerHand::PokerHand(std::string handtext) {
	auto offset = 0;
	auto handoffset = 0;
	for (auto cardIndex = 0; cardIndex < 5; cardIndex++) {
		std::string cardStr(handtext, offset, 2);
		offset += 2;
		PokerCard card(cardStr);
		hand[handoffset++] = card;
	}
	SortByRank();
}
Exemple #28
0
void IndexSet::insert(const IndexSet& s) {
  if (this == &s) return;
  if (s.card() == 0) return;
  if (card() == 0) {
    *this = s;
    return;
  }

  for (long i = s.last(); i >= s.first(); i = s.prev(i)) insert(i);
  // NOTE: traversal done from high to low so as to trigger at 
  // at most one resize

}
Exemple #29
0
// Find the IndexSet such that modDown to that set of primes makes the
// additive term due to rounding into the dominant noise term 
void Ctxt::findBaseSet(IndexSet& s) const
{
  if (getNoiseVar()<=0.0) { // an empty ciphertext
    s = context.ctxtPrimes;
    return;
  }

  assert(verifyPrimeSet());
  bool halfSize = context.containsSmallPrime();
  double addedNoise = log(modSwitchAddedNoiseVar())/2;
  double curNoise = log(getNoiseVar())/2;
  double firstNoise = context.logOfPrime(0);

  // remove special primes, if they are included in this->primeSet
  s = getPrimeSet();
  if (!s.disjointFrom(context.specialPrimes)) { 
    // scale down noise
    curNoise -= context.logOfProduct(context.specialPrimes);
    s.remove(context.specialPrimes);
  }

  if (curNoise<=2*addedNoise) return; // no need to mod down

  // if the first prime in half size, begin by removing it
  if (halfSize && s.contains(0)) {
    curNoise -= firstNoise;
    s.remove(0);
  }

  // while noise is larger than added term, scale down by the next prime
  while (curNoise>addedNoise && card(s)>1) {
    curNoise -= context.logOfPrime(s.last());
    s.remove(s.last());
  }

  if (halfSize) {
    // If noise is still too big, drop last big prime and insert half-size prime
    if (curNoise>addedNoise) {
      curNoise = firstNoise;
      s = IndexSet(0);
    } 
    // Otherwise check if you can add back the half-size prime
    else if (curNoise+firstNoise <= addedNoise) {
      curNoise += firstNoise;
      s.insert(0);
    }
  }

  if (curNoise>addedNoise && log_of_ratio()>-0.5)
    cerr << "Ctxt::findBaseSet warning: already at lowest level\n";
}
// this takes care of the cases when the state is deleted
nsresult nsAbPalmHotSync::LoadDeletedCardsSinceLastSync()
{
    if (!mDBOpen || !mABDB || !mInitialized) 
        return NS_ERROR_NOT_INITIALIZED;
    
    nsCOMPtr<nsIArray> deletedCardArray;
    nsresult rv = mABDB->GetDeletedCardList(getter_AddRefs(deletedCardArray));
    if (NS_FAILED(rv))
        return rv;

    PRUint32 deletedCardCount;
    rv = deletedCardArray->GetLength(&deletedCardCount);
    if (NS_FAILED(rv))
        return rv;

    for(PRUint32 i=0; i < deletedCardCount; i++) 
    {
        nsCOMPtr<nsIAbCard> card(do_QueryElementAt(deletedCardArray, i, &rv));
        if (NS_FAILED(rv)) // can this be anything but a card?
            continue;
        
        PRBool isMailingList=PR_FALSE;
        rv = card->GetIsMailList(&isMailingList);
        if (NS_FAILED(rv) || isMailingList)
            continue;

        PRUint32 lastModifiedDate = 0;
        rv = card->GetLastModifiedDate(&lastModifiedDate);
        if (NS_FAILED(rv) || !lastModifiedDate)
            continue;

        if(lastModifiedDate > mPalmSyncTimeStamp)
        {
            nsAbIPCCard  ipcCard(card);
            // check in the list of Palm records
            for(PRInt32 i=mPalmRecords.Count()-1; i >=0;  i--) 
            {
                nsABCOMCardStruct * palmRec = (nsABCOMCardStruct *) mPalmRecords.ElementAt(i);
                // if same record exists in palm list, donot delete it from Palm
                if(ipcCard.Same(palmRec, mIsPalmDataUnicode))
                    continue;
            }
            ipcCard.SetStatus(ATTR_DELETED);

            rv = AddToListForPalm(ipcCard);
            if(NS_FAILED(rv))
                break;
        }
    }
    return rv;
}