Esempio n. 1
0
int commandLineMode(std::string input) {

	try {
		
		int result = parseString<int>(input);
		std::cout << result << std::endl;
	
	} catch (ParseError& e) {
		std::cerr << input << std::endl;
		e.print(std::cerr, true, 0);
		exit (e.getID());
	} catch (MathError& e) {
		std::cerr << input << std::endl;
		e.print(std::cerr, true, 0);
		exit (e.getID());
	} catch (Error& e) {
		e.print(std::cerr, true);
		exit (e.getID());
	} catch (...) {
		unknownError();
		exit(EXIT_FAILURE);
	}
	
	// If we made it this far, it means the value parsed and printed successfully!
	exit(EXIT_SUCCESS);
	
}
Esempio n. 2
0
bool ReaderMethod::write(int tag,
                         std::unique_ptr<google::protobuf::Message> request,
                         int timeout) {
  if (!request) {
    unknownError(tag, "Failed to convert to message object.");
    return false;
  }
  new ReaderCallData(tag, channel_.get(), cq_, this, read_, std::move(request),
                     timeout);
  return true;
}
Esempio n. 3
0
bool ReaderWriterMethod::write(
    int tag, std::unique_ptr<google::protobuf::Message> request) {
  if (!request) {
    unknownError(tag, "Failed to convert to message object.");
    return false;
  }
  std::lock_guard<std::mutex> lock(calls_mutex_);
  auto it = calls_.find(tag);
  if (it == calls_.end()) {
    qWarning() << "Tag not found for write " << tag;
    return false;
  }
  return it->second->write(std::move(request));
}
Esempio n. 4
0
ReaderWriterCallData* ReaderWriterMethod::ensureCallData(int tag) {
  ReaderWriterCallData* call = nullptr;
  auto it = calls_.find(tag);
  if (it == calls_.end()) {
    auto res = calls_.insert(std::make_pair(
        tag, new ReaderWriterCallData(tag, channel_.get(), cq_, this, read_)));
    if (!res.second) {
      unknownError(tag, "Failed to create call object");
      return nullptr;
    }
    call = res.first->second;
  } else {
    call = it->second;
  }
  return call;
}
Esempio n. 5
0
int interactiveMode() {
	
	const std::string INPUT_LINE = "Enter a calculation: ";
	const std::string INPUT_LINE_END = "";
	const std::string OUTPUT_LINE = "\033[1;93m > ";
	const std::string OUTPUT_LINE_END = "\033[0m";
	
	// Used for debugging when displaying the error message
	const int INPUT_LINE_LENGTH = 21;
	
	try {
		
		// Detect when the user presses CTRL+C on their keyboard
		signal(SIGINT, sigint);
		
		std::cout << INPUT_LINE;
		std::string input = "";
		while (getline(std::cin, input)) {
			
			std::cout << INPUT_LINE_END;
			
			// Detect special commands
			if (input == "") {
				// No text entered
				// Act the same way as Bash, and just show another empty line
			}
			else if ( input == "help" ) {
				printHelpMessage(std::cout, true);
				// It looks better with an additional blank line after the message.
				std::cout << std::endl;
			}
			else if ( input == "exit" || input == "quit") {
				exit(EXIT_SUCCESS);
			}
			else {
				// No special command entered. Parse the text that was entered as usual.
				int result = parseString<int>(input);
				std::cout << OUTPUT_LINE << result << OUTPUT_LINE_END << std::endl;
			}
			
			// And all over again
			std::cout << INPUT_LINE;
		}
	
	} catch (ParseError& e) {
		e.print(std::cerr, true, INPUT_LINE_LENGTH);
		exit (e.getID());
	} catch (MathError& e) {
		e.print(std::cerr, true, INPUT_LINE_LENGTH);
		exit (e.getID());
	} catch (Error& e) {
		e.print(std::cerr, true);
		exit (e.getID());
	} catch (...) {
		unknownError();
		exit(EXIT_FAILURE);
	}
	
	// Technically, this line should never execute unless we change the way
	//  the above while loop works.
	exit(EXIT_SUCCESS);
}
Esempio n. 6
0
void Pastebin::readData(QNetworkReply* reply)
{
    QByteArray response = reply->readAll();
    qDebug() << reply->header(QNetworkRequest::ContentTypeHeader);
    if (response.contains("Bad API request"))
    {
        m_errorString = response;
        QString code = response.split(',')[1].simplified().toLower();

        if (code == "use post request, not get")
            emit error(InvalidRequestType);
        else if (code == "invalid api_dev_key")
            emit error(InvalidDevKey);
        else if (code == "invalid login")
            emit error(InvalidLogin);
        else if (code == "account not active")
            emit error(InactiveAccount);
        else if (code == "invalid post parameters")
            emit error(InvalidPostParameters);
        else if (code == "invalid permission to remove paste")
            emit error(InvalidPermissions);
        else if (code == "invalid api_option")
            emit error(InvalidOption);
        else if (code == "invalid api_user_key")
            emit error(InvalidUserKey);
        else if (code == "ip blocked")
            emit error(BlockedIP);
        else if (code.contains("maximum number of 10"))
            emit error(Max10Exceeded);
        else if (code.contains("maximum number of 25"))
            emit error(Max25Exceeded);
        else if (code == "invalid_expire_date")
            emit error(InvalidExpireDate);
        else if (code == "maximum paste file size exceeded")
            emit error(MaxSizeExceeded);
        else if (code == "invalid api_paste_format")
            emit error(InvalidFormat);
        else if (code == "api_paste_code was empty")
            emit error(EmptyCode);
        else
            emit unknownError(response);
    }
    else if (reply->url().toString().contains(PASTEBIN_LOGIN))
    {
        m_userKey = QString(response).simplified();
        emit loggedIn(m_userKey);
    }
    else if (reply->url().toString().contains(PASTEBIN_POST))
    {

        if (response.indexOf(PASTEBIN_URL) == 0)
            emit pasteSuccessful(QUrl(response.simplified()));
        if (response.indexOf("Paste Removed") == 0)
            emit deleteSuccessful();
        if (response.contains("<user>"))
            emit user(UserInfo::fromData(response));
        if (response.contains("<paste>"))
            // We have to add opening and closing tags so QXmlStreamReader reads the data correctly.
            // For some reason if the data is not enclosed, the reader flips a shit and goes into an
            // infinite loop.
            emit pastes(PasteInfo::fromList("<trends>\n"+response +"\n</trends>"));
    }
}