void _postmountsrv(Srv *s, char *name, char *mtpt, int flag) { int fd[2]; if(!s->nopipe){ if(pipe(fd) < 0) sysfatal("pipe: %r"); s->infd = s->outfd = fd[1]; s->srvfd = fd[0]; } if(name) if(postfd(name, s->srvfd) < 0) sysfatal("postfd %s: %r", name); if(_forker == nil) sysfatal("no forker"); _forker(postproc, s, RFNAMEG); /* * Normally the server is posting as the last thing it does * before exiting, so the correct thing to do is drop into * a different fd space and close the 9P server half of the * pipe before trying to mount the kernel half. This way, * if the file server dies, we don't have a ref to the 9P server * half of the pipe. Then killing the other procs will drop * all the refs on the 9P server half, and the mount will fail. * Otherwise the mount hangs forever. * * Libthread in general and acme win in particular make * it hard to make this fd bookkeeping work out properly, * so leaveinfdopen is a flag that win sets to opt out of this * safety net. */ if(!s->leavefdsopen){ rfork(RFFDG); rendezvous(0, 0); close(s->infd); if(s->infd != s->outfd) close(s->outfd); } if(mtpt){ if(amount(s->srvfd, mtpt, flag, "") == -1) sysfatal("mount %s: %r", mtpt); }else close(s->srvfd); }
void test_raw() { testcase ("raw"); { Quality q (0x5d048191fb9130daull); // 126836389.7680090 Amounts const value ( amount(349469768), // 349.469768 XRP raw (2755280000000000ull, -15)); // 2.75528 STAmount const limit ( raw (4131113916555555, -16)); // .4131113916555555 Amounts const result (q.ceil_out (value, limit)); expect (result.in != zero); } }
std::string Order::stringRepresentation() const { std::stringstream ss; ss << "LocalID: " << m_id << "; ClientAssignedID: " << clientAssignedId() << "; " << opString(m_operation) << " " << amount() << " of " << security(); if(m_type == Order::OrderType::Limit) ss << " at " << m_price; ss << " ("; switch(m_state) { case State::Submitted: ss << "submitted"; break; case State::Cancelled: ss << "cancelled"; break; case State::Rejected: ss << "rejected"; break; case State::Executed: ss << "executed"; break; case State::PartiallyExecuted: ss << "partially executed"; break; case State::Unsubmitted: ss << "unsubmitted"; break; } ss << ")"; return ss.str(); }
/** Transfer funds (money) from one company to another. * To prevent abuse in multiplayer games you can only send money to other * companies if you have paid off your loan (either explicitely, or implicitely * given the fact that you have more money than loan). * @param tile unused * @param flags operation to perform * @param p1 the amount of money to transfer; max 20.000.000 * @param p2 the company to transfer the money to * @param text unused * @return the cost of this operation or an error */ CommandCost CmdGiveMoney(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { if (!_settings_game.economy.give_money) return CMD_ERROR; const Company *c = Company::Get(_current_company); CommandCost amount(EXPENSES_OTHER, min((Money)p1, (Money)20000000LL)); CompanyID dest_company = (CompanyID)p2; /* You can only transfer funds that is in excess of your loan */ if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() < 0) return CMD_ERROR; if (!_networking || !Company::IsValidID(dest_company)) return CMD_ERROR; if (flags & DC_EXEC) { /* Add money to company */ Backup<CompanyByte> cur_company(_current_company, dest_company, FILE_LINE); SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -amount.GetCost())); cur_company.Restore(); } /* Subtract money from local-company */ return amount; }
int main(int argc, char **argv) { IloEnv env; try { IloInt i, j; IloNum rollWidth; IloNumArray amount(env); IloNumArray size(env); if ( argc > 1 ) readData(argv[1], rollWidth, size, amount); else readData("../../../examples/data/cutstock.dat", rollWidth, size, amount); /// CUTTING-OPTIMIZATION PROBLEM /// IloModel cutOpt (env); IloObjective RollsUsed = IloAdd(cutOpt, IloMinimize(env)); IloRangeArray Fill = IloAdd(cutOpt, IloRangeArray(env, amount, IloInfinity)); IloNumVarArray Cut(env); IloInt nWdth = size.getSize(); for (j = 0; j < nWdth; j++) { Cut.add(IloNumVar(RollsUsed(1) + Fill[j](int(rollWidth / size[j])))); } IloCplex cutSolver(cutOpt); /// PATTERN-GENERATION PROBLEM /// IloModel patGen (env); IloObjective ReducedCost = IloAdd(patGen, IloMinimize(env, 1)); IloNumVarArray Use(env, nWdth, 0.0, IloInfinity, ILOINT); patGen.add(IloScalProd(size, Use) <= rollWidth); IloCplex patSolver(patGen); /// COLUMN-GENERATION PROCEDURE /// IloNumArray price(env, nWdth); IloNumArray newPatt(env, nWdth); /// COLUMN-GENERATION PROCEDURE /// for (;;) { /// OPTIMIZE OVER CURRENT PATTERNS /// cutSolver.solve(); report1 (cutSolver, Cut, Fill); /// FIND AND ADD A NEW PATTERN /// for (i = 0; i < nWdth; i++) { price[i] = -cutSolver.getDual(Fill[i]); } ReducedCost.setLinearCoefs(Use, price); patSolver.solve(); report2 (patSolver, Use, ReducedCost); if (patSolver.getValue(ReducedCost) > -RC_EPS) break; patSolver.getValues(newPatt, Use); Cut.add( IloNumVar(RollsUsed(1) + Fill(newPatt)) ); } cutOpt.add(IloConversion(env, Cut, ILOINT)); cutSolver.solve(); cout << "Solution status: " << cutSolver.getStatus() << endl; report3 (cutSolver, Cut); } catch (IloException& ex) { cerr << "Error: " << ex << endl; } catch (...) { cerr << "Error" << endl; } env.end(); return 0; }
void NYCGenericImporter::loadIngredientLine( const QString &line ) { QString current = line; if ( current.contains( "-----" ) ) { current_header = current.trimmed(); kDebug() << "Found ingredient header: " << current_header ; return ; } MixedNumber amount( 0, 0, 1 ); QString unit; QString name; QString prep; QStringList ingredient_line; if (current.isEmpty()) ingredient_line = QStringList(); else ingredient_line = current.split( ' ', QString::SkipEmptyParts); bool found_amount = false; if ( !ingredient_line.empty() ) //probably an unnecessary check... but to be safe { MixedNumber test_amount; QValidator::State state; state = MixedNumber::fromString( ingredient_line[ 0 ], test_amount ); if ( state != QValidator::Acceptable ) { amount = amount + test_amount; ingredient_line.pop_front(); found_amount = true; } } if ( !ingredient_line.empty() ) //probably an unnecessary check... but to be safe { MixedNumber test_amount; QValidator::State state; state = MixedNumber::fromString( ingredient_line[ 0 ], test_amount ); if ( state == QValidator::Acceptable ) { amount = amount + test_amount; ingredient_line.pop_front(); found_amount = true; } } if ( found_amount ) { unit = ingredient_line[ 0 ]; ingredient_line.pop_front(); } //now join each separate part of ingredient (name, unit, amount) name = ingredient_line.join( " " ); int prep_sep_index = name.indexOf( QRegExp( "(--|,;;)" ) ); if ( prep_sep_index == -1 ) prep_sep_index = name.length(); name = name.left( prep_sep_index ).trimmed(); prep = name.mid( prep_sep_index+1, name.length() ).trimmed(); Ingredient new_ingredient( name, amount.toDouble(), Unit( unit, amount.toDouble() ) ); new_ingredient.group = current_header; new_ingredient.prepMethodList = ElementList::split(",",prep); m_recipe.ingList.append( new_ingredient ); }
int main(void) { int p_pound = 0; // weight of potato int s_pound = 0; // weight of sugarbeet int c_pound = 0; // weight of carrot int weight = 0; // total weight of all goods float total = 0.0; // total cost excluding freight float freight = 0.0; // freight float discount; char ch; // the option printf("\n====================ABC Mail Order Grocery====================\n"); printf("Order List:\n\n"); printf(" a) potato: $%.2f / pound\tb) sugarbeet: $%.2f / pound\n c) carrot: $%.2f / pound\n", POTATO, SUGARBEET, CARROT); printf("\n==============================================================\n"); printf("Select your cargo (q to finish):\n"); // the while loop below controls the ordering flow while ((ch = getchar()) != 'q') { if (ch == '\n') continue; switch (ch) { case 'a': printf("Enter amount(pound): "); p_pound = amount();break; case 'b': printf("Enter amount(pound): "); s_pound = amount();break; case 'c': printf("Enter amount(pound): "); c_pound = amount();break; case 'q': break; default: printf("Invalid input. Please enter again:\n"); break; // used 'continue' and some bad thing happend } while(getchar() != '\n') continue; printf("Keep shopping(choose a) b) c) or q to quit)?\n"); } weight = (p_pound + c_pound + s_pound); if (weight = 0) freight = 0; else if (weight <= P1) freight = F1; else if (weight < P2) freight = F2; else freight = F3 + F4*(weight - P2); total = p_pound*POTATO + s_pound*SUGARBEET +c_pound*CARROT; if (total >= 100) discount = total * DR; else discount = 0; listing(p_pound,s_pound,c_pound,freight,total,discount); return 0; }
Real InflationCoupon::price(const Handle<YieldTermStructure>& discountingCurve) const { return amount() * discountingCurve->discount(date()); }
double Model_Checking::balance(const Data* r, int account_id) { if (Model_Checking::status(r->STATUS) == Model_Checking::VOID_) return 0; return amount(r, account_id); }
Money Money::operator-(const Money & m) const { return Money(amount() - m.amount()); }
// // ------ min method --- // const Money & Money::min(const Money & m) const { return (amount() > m.amount() ? m : (*this)); }
void main() { printf("Sum of three parameters is %.3f!\n\n", amount("213", 2222, -2222, 1000.575)); printf("Check: %.3f!\n\n", (2222 - 2222 + 1000.575)); return; }
// public virtual [base kpEffectWidgetBase] kpImage kpEffectToneEnhanceWidget::applyEffect (const kpImage &image) { return kpEffectToneEnhance::applyEffect (image, granularity (), amount ()); }
QString xmoney::toDbString() const { return QString("(%1,%2)").arg(formatNumber(amount(), decimalPlaces()), currency().isEmpty() ? "\"\"" : currency()); }
void database::init_genesis(const genesis_allocation& initial_allocation) { try { _undo_db.disable(); fc::ecc::private_key genesis_private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("genesis"))); const key_object& genesis_key = create<key_object>( [&genesis_private_key](key_object& k) { k.key_data = public_key_type(genesis_private_key.get_public_key()); }); const account_statistics_object& genesis_statistics = create<account_statistics_object>( [&](account_statistics_object& b){ }); create<account_balance_object>( [](account_balance_object& b) { b.balance = GRAPHENE_INITIAL_SUPPLY; }); const account_object& genesis_account = create<account_object>( [&](account_object& n) { n.name = "genesis"; n.owner.add_authority(genesis_key.get_id(), 1); n.owner.weight_threshold = 1; n.active = n.owner; n.memo_key = genesis_key.id; n.statistics = genesis_statistics.id; }); vector<delegate_id_type> init_delegates; vector<witness_id_type> init_witnesses; flat_set<witness_id_type> init_witness_set; auto delegates_and_witnesses = std::max(GRAPHENE_MIN_WITNESS_COUNT, GRAPHENE_MIN_DELEGATE_COUNT); for( int i = 0; i < delegates_and_witnesses; ++i ) { const account_statistics_object& stats_obj = create<account_statistics_object>( [&](account_statistics_object&){ }); const account_object& delegate_account = create<account_object>( [&](account_object& a) { a.active = a.owner = genesis_account.owner; a.name = string("init") + fc::to_string(i); a.statistics = stats_obj.id; }); const delegate_object& init_delegate = create<delegate_object>( [&](delegate_object& d) { d.delegate_account = delegate_account.id; d.vote_id = i * 2; }); init_delegates.push_back(init_delegate.id); const witness_object& init_witness = create<witness_object>( [&](witness_object& d) { d.witness_account = delegate_account.id; d.vote_id = i * 2 + 1; secret_hash_type::encoder enc; fc::raw::pack( enc, genesis_private_key ); fc::raw::pack( enc, d.last_secret ); d.next_secret = secret_hash_type::hash(enc.result()); }); init_witnesses.push_back(init_witness.id); init_witness_set.insert(init_witness.id); } create<block_summary_object>( [&](block_summary_object& p) { }); const witness_schedule_object& wso = create<witness_schedule_object>( [&]( witness_schedule_object& _wso ) { memset( _wso.rng_seed.begin(), 0, _wso.rng_seed.size() ); witness_scheduler_rng rng( _wso.rng_seed.begin(), GRAPHENE_NEAR_SCHEDULE_CTR_IV ); _wso.scheduler = witness_scheduler(); _wso.scheduler._min_token_count = init_witnesses.size() / 2; _wso.scheduler.update( init_witness_set ); for( int i=0; i<init_witnesses.size(); i++ ) _wso.scheduler.produce_schedule( rng ); _wso.last_scheduling_block = 0; } ) ; assert( wso.id == witness_schedule_id_type() ); const global_property_object& properties = create<global_property_object>( [&](global_property_object& p) { p.active_delegates = init_delegates; for( const witness_id_type& wit : init_witnesses ) p.active_witnesses.insert( wit ); p.next_available_vote_id = delegates_and_witnesses * 2; p.chain_id = fc::digest(initial_allocation); }); (void)properties; create<dynamic_global_property_object>( [&](dynamic_global_property_object& p) { p.time = fc::time_point_sec( GRAPHENE_GENESIS_TIMESTAMP ); }); const asset_dynamic_data_object& dyn_asset = create<asset_dynamic_data_object>( [&]( asset_dynamic_data_object& a ) { a.current_supply = GRAPHENE_INITIAL_SUPPLY; }); const asset_object& core_asset = create<asset_object>( [&]( asset_object& a ) { a.symbol = GRAPHENE_SYMBOL; a.options.max_supply = GRAPHENE_INITIAL_SUPPLY; a.precision = GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS; a.options.flags = 0; a.options.issuer_permissions = 0; a.issuer = genesis_account.id; a.options.core_exchange_rate.base.amount = 1; a.options.core_exchange_rate.base.asset_id = 0; a.options.core_exchange_rate.quote.amount = 1; a.options.core_exchange_rate.quote.asset_id = 0; a.dynamic_asset_data_id = dyn_asset.id; }); assert( asset_id_type(core_asset.id) == asset().asset_id ); assert( get_balance(account_id_type(), asset_id_type()) == asset(dyn_asset.current_supply) ); (void)core_asset; if( !initial_allocation.empty() ) { share_type total_allocation = 0; for( const auto& handout : initial_allocation ) total_allocation += handout.second; auto mangle_to_name = [](const fc::static_variant<public_key_type, address>& key) { string addr = string(key.which() == std::decay<decltype(key)>::type::tag<address>::value? key.get<address>() : key.get<public_key_type>()); string result = "bts"; string key_string = string(addr).substr(sizeof(GRAPHENE_ADDRESS_PREFIX)-1); for( char c : key_string ) { if( isupper(c) ) result += string("-") + char(tolower(c)); else result += c; } return result; }; fc::time_point start_time = fc::time_point::now(); for( const auto& handout : initial_allocation ) { asset amount(handout.second); amount.amount = ((fc::uint128(amount.amount.value) * GRAPHENE_INITIAL_SUPPLY)/total_allocation.value).to_uint64(); if( amount.amount == 0 ) { wlog("Skipping zero allocation to ${k}", ("k", handout.first)); continue; } signed_transaction trx; trx.operations.emplace_back(key_create_operation({asset(), genesis_account.id, handout.first})); relative_key_id_type key_id(0); authority account_authority(1, key_id, 1); account_create_operation cop; cop.name = mangle_to_name(handout.first); cop.registrar = account_id_type(1); cop.active = account_authority; cop.owner = account_authority; cop.memo_key = key_id; trx.operations.push_back(cop); trx.validate(); auto ptrx = apply_transaction(trx, ~0); trx = signed_transaction(); account_id_type account_id(ptrx.operation_results.back().get<object_id_type>()); trx.operations.emplace_back(transfer_operation({ asset(), genesis_account.id, account_id, amount, memo_data()//vector<char>() })); trx.validate(); apply_transaction(trx, ~0); } asset leftovers = get_balance(account_id_type(), asset_id_type()); if( leftovers.amount > 0 ) { modify(*get_index_type<account_balance_index>().indices().get<by_balance>().find(boost::make_tuple(account_id_type(), asset_id_type())), [](account_balance_object& b) { b.adjust_balance(-b.get_balance()); }); modify(core_asset.dynamic_asset_data_id(*this), [&leftovers](asset_dynamic_data_object& d) { d.accumulated_fees += leftovers.amount; }); } fc::microseconds duration = fc::time_point::now() - start_time; ilog("Finished allocating to ${n} accounts in ${t} milliseconds.", ("n", initial_allocation.size())("t", duration.count() / 1000)); } _undo_db.enable(); } FC_LOG_AND_RETHROW() }
template <typename Container> unit::mega_byte amount(Container&& c) { return amount(c.data(), c.size()); }
template <typename T> unit::mega_byte amount(T* from, Ind size) { T* to = from + size; return amount(from, to); }
void AmountUnitInput::emitValueChanged() { emit valueChanged( amount(), unit() ); }
// // ------ max method --- // const Money & Money::max(const Money & m) const { return (amount() < m.amount() ? m : (*this)); }
void test_ceil_out () { testcase ("ceil_out"); { // 1 in, 1 out: Quality q (Amounts (amount(1),amount(1))); ceil_out (q, 1, 1, // 1 in, 1 out 1, // limit 1 1, 1); // 1 in, 1 out ceil_out (q, 10, 10, // 10 in, 10 out 5, // limit 5 5, 5); // 5 in, 5 out ceil_out (q, 10, 10, // 10 in, 10 out 20, // limit 20 10, 10); // 10 in, 10 out } { // 1 in, 2 out: Quality q (Amounts (amount(1),amount(2))); ceil_out (q, 40, 80, // 40 in, 80 out 40, // limit 40 20, 40); // 20 in, 40 out ceil_out (q, 40, 80, // 40 in, 80 out 80, // limit 80 40, 80); // 40 in, 80 out ceil_out (q, 40, 80, // 40 in, 80 out 100, // limit 100 40, 80); // 40 in, 80 out } { // 2 in, 1 out: Quality q (Amounts (amount(2),amount(1))); ceil_out (q, 40, 20, // 40 in, 20 out 20, // limit 20 40, 20); // 40 in, 20 out ceil_out (q, 40, 20, // 40 in, 20 out 40, // limit 40 40, 20); // 40 in, 20 out ceil_out (q, 40, 20, // 40 in, 20 out 10, // limit 10 20, 10); // 20 in, 10 out } }
Money Money::operator+(const Money & m) const { return Money(m.amount() + amount()); }
static Amounts amounts (In in, Out out) { return Amounts (amount(in), amount(out)); }
double Model_Checking::amount(const Data&r, int account_id) { return amount(&r, account_id); }
void test_ceil_in () { testcase ("ceil_in"); { // 1 in, 1 out: Quality q (Amounts (amount(1), amount(1))); ceil_in (q, 1, 1, // 1 in, 1 out 1, // limit: 1 1, 1); // 1 in, 1 out ceil_in (q, 10, 10, // 10 in, 10 out 5, // limit: 5 5, 5); // 5 in, 5 out ceil_in (q, 5, 5, // 5 in, 5 out 10, // limit: 10 5, 5); // 5 in, 5 out } { // 1 in, 2 out: Quality q (Amounts (amount(1), amount(2))); ceil_in (q, 40, 80, // 40 in, 80 out 40, // limit: 40 40, 80); // 40 in, 20 out ceil_in (q, 40, 80, // 40 in, 80 out 20, // limit: 20 20, 40); // 20 in, 40 out ceil_in (q, 40, 80, // 40 in, 80 out 60, // limit: 60 40, 80); // 40 in, 80 out } { // 2 in, 1 out: Quality q (Amounts (amount(2), amount(1))); ceil_in (q, 40, 20, // 40 in, 20 out 20, // limit: 20 20, 10); // 20 in, 10 out ceil_in (q, 40, 20, // 40 in, 20 out 40, // limit: 40 40, 20); // 40 in, 20 out ceil_in (q, 40, 20, // 40 in, 20 out 50, // limit: 40 40, 20); // 40 in, 20 out } }
// ----------------------------------------------------------------------------- // GfxTintDialog class constructor // ----------------------------------------------------------------------------- GfxTintDialog::GfxTintDialog(wxWindow* parent, ArchiveEntry* entry, const Palette& pal) : wxDialog(parent, -1, "Tint", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), entry_{ entry }, palette_{ pal } { // Set dialog icon wxIcon icon; icon.CopyFromBitmap(Icons::getIcon(Icons::General, "tint")); SetIcon(icon); // Setup main sizer auto msizer = new wxBoxSizer(wxVERTICAL); SetSizer(msizer); auto sizer = new wxBoxSizer(wxVERTICAL); msizer->Add(sizer, 1, wxEXPAND | wxALL, 6); // Add colour chooser auto hbox = new wxBoxSizer(wxHORIZONTAL); sizer->Add(hbox, 0, wxEXPAND | wxALL, 4); cb_colour_ = new ColourBox(this, -1, false, true); cb_colour_->setColour(COL_RED); cb_colour_->setPalette(&palette_); hbox->Add(new wxStaticText(this, -1, "Colour:"), 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 4); hbox->Add(cb_colour_, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 8); // Add 'amount' slider hbox = new wxBoxSizer(wxHORIZONTAL); sizer->Add(hbox, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 4); slider_amount_ = new wxSlider(this, -1, 50, 0, 100); label_amount_ = new wxStaticText(this, -1, "100%"); hbox->Add(new wxStaticText(this, -1, "Amount:"), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 4); hbox->Add(slider_amount_, 1, wxEXPAND | wxRIGHT, 4); hbox->Add(label_amount_, 0, wxALIGN_CENTER_VERTICAL); // Add preview gfx_preview_ = new GfxCanvas(this, -1); sizer->Add(gfx_preview_, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 4); // Add buttons sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxEXPAND | wxBOTTOM, 4); // Setup preview gfx_preview_->setViewType(GfxCanvas::View::Centered); gfx_preview_->setPalette(&palette_); gfx_preview_->SetInitialSize(wxSize(256, 256)); Misc::loadImageFromEntry(gfx_preview_->getImage(), entry); gfx_preview_->getImage()->tint(colour(), amount(), &palette_); gfx_preview_->updateImageTexture(); // Init layout wxWindowBase::Layout(); // Bind events cb_colour_->Bind(wxEVT_COLOURBOX_CHANGED, &GfxTintDialog::onColourChanged, this); slider_amount_->Bind(wxEVT_SLIDER, &GfxTintDialog::onAmountChanged, this); Bind(wxEVT_SIZE, &GfxTintDialog::onResize, this); // Setup dialog size SetInitialSize(wxSize(-1, -1)); wxTopLevelWindowBase::SetMinSize(GetSize()); CenterOnParent(); // Set values label_amount_->SetLabel("50% "); }
void main(int argc, char *argv[]) { int fd, doexec; char *srv, *mtpt; char dir[1024]; char err[ERRMAX]; char *p, *p2; int domount, reallymount, try, sleeptime; notify(ignore); domount = 0; reallymount = 0; doexec = 0; sleeptime = 0; ARGBEGIN{ case 'a': mountflag |= MAFTER; domount = 1; reallymount = 1; break; case 'b': mountflag |= MBEFORE; domount = 1; reallymount = 1; break; case 'c': mountflag |= MCREATE; domount = 1; reallymount = 1; break; case 'C': mountflag |= MCACHE; domount = 1; reallymount = 1; break; case 'e': doexec = 1; break; case 'm': domount = 1; reallymount = 1; break; case 'n': doauth = 0; break; case 'q': domount = 1; reallymount = 0; break; case 'r': /* deprecated -r flag; ignored for compatibility */ break; case 's': sleeptime = atoi(EARGF(usage())); break; default: usage(); break; }ARGEND if((mountflag&MAFTER)&&(mountflag&MBEFORE)) usage(); switch(argc){ case 1: /* calculate srv and mtpt from address */ p = strrchr(argv[0], '/'); p = p ? p+1 : argv[0]; srv = smprint("/srv/%s", p); p2 = strchr(p, '!'); p2 = p2 ? p2+1 : p; mtpt = smprint("/n/%s", p2); break; case 2: /* calculate mtpt from address, srv given */ srv = smprint("/srv/%s", argv[1]); p = strrchr(argv[0], '/'); p = p ? p+1 : argv[0]; p2 = strchr(p, '!'); p2 = p2 ? p2+1 : p; mtpt = smprint("/n/%s", p2); break; case 3: /* srv and mtpt given */ domount = 1; reallymount = 1; srv = smprint("/srv/%s", argv[1]); mtpt = smprint("%s", argv[2]); break; default: srv = mtpt = nil; usage(); } try = 0; dest = *argv; Again: try++; if(access(srv, 0) == 0){ if(domount){ fd = open(srv, ORDWR); if(fd >= 0) goto Mount; remove(srv); } else{ fprint(2, "srv: %s already exists\n", srv); exits(0); } } alarm(10000); if(doexec) fd = connectcmd(dest); else{ dest = netmkaddr(dest, 0, "9fs"); fd = dial(dest, 0, dir, 0); } if(fd < 0) { fprint(2, "srv: dial %s: %r\n", dest); exits("dial"); } alarm(0); if(sleeptime){ fprint(2, "sleep..."); sleep(sleeptime*1000); } post(srv, fd); Mount: if(domount == 0 || reallymount == 0) exits(0); if((!doauth && mount(fd, -1, mtpt, mountflag, "") < 0) || (doauth && amount(fd, mtpt, mountflag, "") < 0)){ err[0] = 0; errstr(err, sizeof err); if(strstr(err, "Hangup") || strstr(err, "hungup") || strstr(err, "timed out")){ remove(srv); if(try == 1) goto Again; } fprint(2, "srv %s: mount failed: %s\n", dest, err); exits("mount"); }