//Submit a bid to a normal auction, a bid has the bidder's number // and a price, a new bid has to have a price higher than the //current highest bid otherwise it's not allowed auctionErrorCode submitBidToAuction(int bidderNum, double bidderPrice, const char *auctionItemName) { auctionData *thisAuction = keyLookup(auctionItemName); if (thisAuction == NULL) { return AUCTION_ERR_KEY; } if (thisAuction->auctionStarted == false) { return AUCTION_ERR_STARTED; } if (thisAuction->auctionEnded == true) { return AUCTION_ERR_ENDED; } if (thisAuction->highBidPrice > bidderPrice) { return AUCTION_ERR_LOWBID; } thisAuction->highBidNum = bidderNum; thisAuction->highBidPrice = bidderPrice; return AUCTION_SUCCESS; }
//Call the normal auction - bring it to an end. If the current highest //bid is higher than the reserved price of the item, the auction is //deemed as a success other wise it's marked as failure. The item sold //should be no longer available for future auctions auctionErrorCode endAuction(const char *auctionItemName) { auctionData *thisAuction = keyLookup(auctionItemName); if (thisAuction == NULL) { return AUCTION_ERR_KEY; } if (thisAuction->auctionStarted == false) { return AUCTION_ERR_STARTED; } thisAuction->auctionEnded = true; thisAuction->itemSold = (thisAuction->reservePrice < thisAuction->highBidPrice); return AUCTION_SUCCESS; }
//Add an item that can be auctioned. An item has a name and reserve price auctionErrorCode addAuctionItem(const char *name, double reservePrice) { auctionData *thisAuction; if (!addKey(name)) { return AUCTION_ERR_KEY; //key may already exist, or may be "bad" } thisAuction = keyLookup(name); if (thisAuction == NULL) { return AUCTION_ERR_DATASTORE; //datastore invariant broken } thisAuction->reservePrice = reservePrice; return AUCTION_SUCCESS; }
//Start an auction on an item auctionErrorCode startAuction(const char *name) { auctionData *thisAuction = keyLookup(name); if (thisAuction == NULL) { return AUCTION_ERR_KEY; } if (thisAuction->auctionStarted) { return AUCTION_ERR_STARTED; } if (thisAuction->auctionEnded) { return AUCTION_ERR_ENDED; } thisAuction->auctionStarted = true; return AUCTION_SUCCESS; }
void parseArgs(int nargs, char **args, isc_opt_t *op) { char **ar; char *p, *v; textkey_t *tk; for(ar = args; nargs > 0; nargs--, ar++) { p = strchr(*ar, '='); if(p == NULL) continue; *p = 0; v = p + 1; while(isspace((unsigned char)*--p)) *p = 0; while(isspace((unsigned char)*v)) v++; if((tk = keyLookup(*ar)) == NULL) continue; setOption(op, tk->tokenID, v); } }