Пример #1
0
/* Opens a popup window to mount a new partition */
void ManagerWindow::AddMount()
{
    mountDialog mnt(this);
    mnt.exec();
    if(mnt.result()==QDialog::Rejected)
        return;

    const char* result = mnt.MountCommand;
    system(result); /* TODO: Need to make this part better with error detection. Also I need to stop using system! :( */

    RefreshMounts();
}
Пример #2
0
int commandtool::mount_part(const blockdevice *block, QString mount_point, QString uid, QString gid)
{
    int r, trys;
    QString result;
    QStringList args;
    args << block->device << mount_point;
    trys = 0;

    int usr_id = uid.toInt();
    int grp_id = getgid();
    if (!gid.isEmpty())
    {
        grp_id = gid.toInt();
    }

    QDir mnt(mount_point);
    if (!mnt.exists())
    {
        mnt.mkdir(mount_point);
    }

    while (true)
    {
        r = exec(COMMAND_MOUNT, args, result);
        if (r == 32)    //mount failure
        {
            sleep(2);
            if (++trys > 8)
            {
                break;
            }
        }
        else{
            break;
        }
    }
    r = chown(mount_point.toAscii().data(), usr_id, grp_id);
    if(r < 0)
    {
        util::log(QString("chown %1 to uid=%2 gid=%3 error %3").arg(mount_point).arg(usr_id).arg(grp_id).arg(errno));
    }
    return (r == 0) ? 0 : -1;
}
Пример #3
0
void Parser::parse(std::istream* in) {
	this->generate();
	std::cout << std::endl;

	std::cout << "=== Generating extended grammar" << std::endl;
	this->generate_extended_grammar();
	std::cout << "=== Done extended grammar" << std::endl;
	std::cout << std::endl;

	std::cout << "=== Generating first and follow sets" << std::endl;
	this->generate_first_and_follow();
	std::cout << "=== Done first and follow sets" << std::endl;
	std::cout << std::endl;

	std::cout << "=== Generating extended sets" << std::endl;
	this->generate_extended_first_and_follow();
	std::cout << "=== Done extended sets" << std::endl;
	std::cout << std::endl;

	Parser::debug(this);

	this->generate_actions_and_gotos();

	std::cout << std::endl << "===== Parsing" << std::endl;
	this->parse_stack.push(0);
	Symbol last_reduction = "";
	while (true) {
		std::unique_ptr<ItemSet>& current_state = this->states.at(this->parse_stack.top());
		bool accept = false;
		for (const Item& item : current_state->head) {
			if (item.first->target == this->start && Parser::is_item_done(item)) {
				accept = true;
				break;
			}
		}
		if (accept) {
			std::cout << "Accepted." << std::endl;
			//break;
		}

		Symbol lr2 = last_reduction;
		last_reduction = "";
		if (lr2.length() > 0) {
			std::map<std::string, ItemSet*>::iterator it = current_state->next.find(lr2);
			if (it != current_state->next.end()) {
				std::cout << "goto " << it->second->index << std::endl;
				this->parse_stack.push(it->second->index);
				continue;
			} else {
				// TODO: what?
				std::cout << "No next state" << std::endl;
			}
		}
		std::unique_ptr<Token> t = this->next_token(in);
		if (t == nullptr) {
			std::cout << "Got null token, state " << current_state->index << std::endl;
			// TODO: refactor?
			std::map<Symbol, Production*> reduction_row = this->reductions.at(current_state->index);
			std::map<Symbol, Production*>::iterator it = reduction_row.find(Parser::END);
			if (it != reduction_row.end()) {
				std::cout << "Reducing via end" << std::endl;
				t.reset(new Token(Parser::END, "", LocationInfo(0, 0)));
			} else {
				std::cout << "Breaking." << std::endl;
				break;
			}
		}
		std::cout << "Got token " << t->tag << ": " << t->lexeme << std::endl;
		std::map<std::string, ItemSet*>::iterator it = current_state->next.find(t->tag);
		if (it != current_state->next.end()) {
			std::cout << "shift " << it->second->index << std::endl;
			this->parse_stack.push(it->second->index);
			this->parse_stack_matches.push(std::unique_ptr<Match>(new MatchedTerminal(std::move(t))));
			continue;
		}
		std::map<Symbol, Production*> reduction_row = this->reductions.at(current_state->index);
		std::map<Symbol, Production*>::iterator it2 = reduction_row.find(t->tag);
		if (it2 != reduction_row.end()) {
			it2->second->handler(nullptr);
			std::cout << "reducing via rule ";
			Parser::debug_production(it2->second);
			std::unique_ptr<MatchedNonterminal> mnt(new MatchedNonterminal(it2->second));
			for (size_t i = 0; i < it2->second->symbols.size(); i++) {
				this->parse_stack.pop();
				std::unique_ptr<Match> m = std::move(this->parse_stack_matches.top());
				this->parse_stack_matches.pop();
				std::cout << "Removing entry ";
				Parser::debug_match(m.get(), 0);
				mnt->terms[it2->second->symbols.size() - i - 1] = std::move(m);
			}
			this->parse_stack_matches.push(std::move(mnt));
			last_reduction = it2->second->target;
			this->push_token(std::move(t));
			continue;
		} else {
			// TODO: what is this?
			std::cout << "No reduction" << std::endl;
		}
	}
	assert(this->parse_stack.size() == 1);
	assert(this->parse_stack_matches.size() == 1);
	return;
}