GenericType OptionsFunctionalityNode::getOption(const string &name) const{

  // Locate the option
  Dictionary::const_iterator it = dictionary_.find(name);

  // Check if found
  if(it == dictionary_.end()){
    stringstream ss;
    if (allowed_options.find(name)!=allowed_options.end()) {
      ss << "Option: '" << name << "' has not been set." << endl;
      printOption(name,ss);
    } else {
      ss << "Option: '" << name << "' does not exist." << endl << endl;
      std::vector<std::string> suggestions;
      getBestMatches(name,suggestions,5);
      ss << "Did you mean one of the following?" << endl;
      for (int i=0;i<suggestions.size();++i)
        printOption(suggestions[i],ss);
      ss << "Use printOptions() to get a full list of options." << endl;
    }
    casadi_error(ss.str());
  }
  
  // Return the option
  return GenericType(it->second);
}
Beispiel #2
0
//! Parses a single string containing the contents of a $rem section.
void RemSection::read(QString const& input) {
   init();

   // Bit of a hack here.  The file to be read in may not have GUI set, so we
   // clear it here to avoid including it prematurely.
   printOption("GUI",false);  
   m_options["GUI"] = "0";

   QStringList lines( input.trimmed().split("\n", QString::SkipEmptyParts) );
   QStringList invalidLines;
   QStringList tokens;
   QString line;

   for (int i = 0; i < lines.count(); ++i) {
       line = lines[i].replace(QChar('='),QChar(' '));
       tokens = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);

       if (tokens.count() >= 2) {
          QString rem(tokens[0].toUpper());
          QString value(tokens[1]);
          fixOptionForQui(rem, value);
          setOption(rem, value);
          printOption(rem, true);
       }else {
          invalidLines << lines[i];
       }
   }

   if (invalidLines.count() > 0) {
      QString msg("An error occured when parsing the following options:\n");
      msg += invalidLines.join("\n");
      QMessageBox::warning(0, "Input File Error", msg); 
   }
}
void SsuRegClient::handleResponse()
{
  QTextStream qout(stdout);

  if (_ssu.error()) {
    qout << printOption(_option) << " failed: " << _ssu.lastError() << endl;
    QCoreApplication::exit(1);
  } else {
    qout << printOption(_option) << " successful" << endl;
    QCoreApplication::exit(0);
  }
}
Beispiel #4
0
Datei: fw.c Projekt: r-mite/nat
int analyzeMobility(u_char *data, int size){
	u_char *ptr;
	int lest;
	struct mobility_hdr *mob;

	ptr = data;
	lest = size;
	
	if(lest < sizeof(struct mobility_hdr)){
		fprintf(stderr, "lest(%d)<sizeof(struct mobility_hdr)\n", lest);
		return -1;
	}

	mob = (struct mobility_hdr *)ptr;
	ptr += sizeof(struct mobility_hdr);
	lest -= sizeof(struct mobility_hdr);

	int moblen;
	moblen = printMobility(mob, stdout);

	int optlen;
	optlen = printBindingUpdate(mob, stdout);
	printOption(mob, optlen, stdout);
	//analyzeBindingUpdate(mob, lest);

	return 0;
}
void OptionsFunctionalityNode::printOptions(ostream &stream) const{
  stream << "\"Option name\" [type] = value" << endl;
  for(map<string, opt_type>::const_iterator it=allowed_options.begin(); it!=allowed_options.end(); ++it){
    printOption(it->first,stream);
  }
  stream << endl;
}
Beispiel #6
0
int main()
{

    int keep = 1;

    while(keep) {

        switch(getOption()) {

            case '1':
                insertOption();
                break;
            case '2':
                searchOption();
                break;
            case '3':
                printOption();
                break;
            case '0':
                keep = 0;
                break;

        }

    }

    return 0;
}
Beispiel #7
0
QString RemSection::dump()  {
   QString s("$rem\n");
   std::map<QString,QString>::const_iterator iter;
   QString name, value;

   for (iter = m_options.begin(); iter != m_options.end(); ++iter) {
       name  = iter->first;
       value = iter->second;
       if (printOption(name) && fixOptionForQChem(name, value)) {
          s += "   " + name + "  =  " + value + "\n";
       }
   }

   s += "$end\n";
   return s;
}
void OptionsFunctionalityNode::assert_exists(const std::string &name) const {
  // First check if the option exists
  map<string, opt_type>::const_iterator it = allowed_options.find(name);
  if(it == allowed_options.end()){
    stringstream ss;
    ss << "Unknown option: " << name << endl;
    std::vector<std::string> suggestions;
    getBestMatches(name,suggestions,5);
    ss << endl;
    ss << "Did you mean one of the following?" << endl;
    for (int i=0;i<suggestions.size();++i)
      printOption(suggestions[i],ss);
    ss << "Use printOptions() to get a full list of options." << endl;
    casadi_error(ss.str());
  }
}
Beispiel #9
0
int main(int argc, char* argv[])
{
	QCoreApplication::setOrganizationName("rapcad");
	QCoreApplication::setOrganizationDomain("rapcad.org");
	QCoreApplication::setApplicationName("RapCAD");
	QCoreApplication::setApplicationVersion(STRINGIFY(RAPCAD_VERSION));

	QCoreApplication* a = new QCoreApplication(argc,argv);

	QCommandLineParser p;
	p.setApplicationDescription(QCoreApplication::translate("main","RapCAD the rapid prototyping IDE"));
	p.addHelpOption();
	p.addVersionOption();
	p.addPositionalArgument("filename", QCoreApplication::translate("main","File to open or process."));

	QCommandLineOption testOption(QStringList() << "t" << "test", QCoreApplication::translate("main","Run through tests in working directory."));
	p.addOption(testOption);

	QCommandLineOption compareOption(QStringList() << "c" << "compare", QCoreApplication::translate("main","Compare two files to see if they are identical."),"filename");
	p.addOption(compareOption);

	QCommandLineOption printOption(QStringList() << "p" << "print", QCoreApplication::translate("main","Print debugging output."));
	p.addOption(printOption);

	QCommandLineOption outputOption(QStringList() << "o" << "output",QCoreApplication::translate("main","Create output file <filename>."),"filename");
	p.addOption(outputOption);

#ifdef USE_READLINE
	QCommandLineOption interactOption(QStringList() << "i" << "interactive",QCoreApplication::translate("main","Start an interactive session"));
	p.addOption(interactOption);
#endif
	p.process(*a);

	QStringList inputFiles=p.positionalArguments();
	QString inputFile;
	if(!inputFiles.isEmpty())
		inputFile=inputFiles.at(0);

	QString outputFile;
	if(p.isSet(outputOption))
		outputFile=p.value(outputOption);
	else if(p.isSet(compareOption))
		outputFile=p.value(compareOption);

	QTextStream output(stdout);
	Strategy* s=NULL;
	if(p.isSet(compareOption)) {
		Comparer* c=new Comparer(output);
		c->setup(inputFile,outputFile);
		s=c;
	} else if(p.isSet(testOption)) {
		s=new Tester(output);
	} else if(p.isSet(outputOption)||p.isSet(printOption)) {
		Worker* w=new Worker(output);
		bool print = p.isSet(printOption);
		w->setup(inputFile,outputFile,print,false);
		s=w;
#ifdef USE_READLINE
    } else if(p.isSet(interactOption)) {
        showVersion(output);
		s=new Interactive(output);
#endif
	}

	if(s) {
		int retcode=s->evaluate();
		a->quit();
		return retcode;
	} else {
		delete a;
		a=new QApplication(argc,argv);
		return showUi(a,inputFiles);
	}
}
void CheckList::keyEvent(KEY_EVENT_RECORD keyEvent) {
	if (_isComponetVisible == true) {
		static int counter = 0;
		counter++;
		if (counter % 2 == 0) {
			return;
		}

		char c = keyEvent.uChar.AsciiChar;
		//move down
		DWORD textColor = _textColor | _backgroundColor; //green
		DWORD textColorSelect = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY;

		switch (keyEvent.wVirtualKeyCode)
		{
		case VK_ESCAPE:
			cout << "esc";
			break;

		case VK_RETURN:
			chooseOption();
			break;
		case VK_UP:
			if (coordtemp.Y - _position.getStartCord().Y > 1) {
				//print the priviuse to green
				SetConsoleTextAttribute(_handle, textColor);
				coordtemp.X--;
				SetConsoleCursorPosition(_handle, coordtemp);
				printOption();
				coordtemp.X++;
				SetConsoleCursorPosition(_handle, coordtemp);
				//going up
				coordtemp.Y--;
				SetConsoleCursorPosition(_handle, coordtemp);
				//setting to yellow
				SetConsoleTextAttribute(_handle, textColorSelect);
				//print the current
				coordtemp.X--;
				SetConsoleCursorPosition(_handle, coordtemp);
				printOption();
				coordtemp.X++;
				SetConsoleCursorPosition(_handle, coordtemp);
			}
			else {//first line
				 //print the priviuse to green
				 DWORD wAttr = FOREGROUND_GREEN;//v
				SetConsoleTextAttribute(_handle, textColor);//v
				coordtemp.X--;
				SetConsoleCursorPosition(_handle, coordtemp);
				printOption();
				//return one right
				coordtemp.X++;
				SetConsoleCursorPosition(_handle, coordtemp);
				//going to last row
				coordtemp.Y = _position.getStartCord().Y + _data.size() ;//going to last
				SetConsoleCursorPosition(_handle, coordtemp);
				//setting to yellow
				SetConsoleTextAttribute(_handle, textColorSelect);
				//print the current
				coordtemp.X--;
				SetConsoleCursorPosition(_handle, coordtemp);
				printOption();
				coordtemp.X++;
				SetConsoleCursorPosition(_handle, coordtemp);

			}
			//printf("x\n");
			SetConsoleCursorPosition(_handle, coordtemp);
			break;

		case VK_DOWN:
			if (coordtemp.Y - _position.getStartCord().Y < _data.size()) {
				//color the previous line from yellow to green		
				SetConsoleTextAttribute(_handle, textColor);
				//move 1 place left
				coordtemp.X--;
				SetConsoleCursorPosition(_handle, coordtemp);
				//print the priviouse line
				printOption();
				//changing to yellow
				SetConsoleTextAttribute(_handle, textColorSelect);
				//going to next line
				coordtemp.Y = coordtemp.Y + 1;
				SetConsoleCursorPosition(_handle, coordtemp);
				//print the new current line
				printOption();
				//move back one place right
				coordtemp.X++;
				SetConsoleCursorPosition(_handle, coordtemp);
			}
			else { //coord2.Y == 4 ==last line

				//color the last line from yellow to green
				SetConsoleTextAttribute(_handle, textColor);
				//move one place left
				coordtemp.X--;
				SetConsoleCursorPosition(_handle, coordtemp);
				//print the priviouse line
				printOption();
				//return one place right
				coordtemp.X++;
				SetConsoleCursorPosition(_handle, coordtemp);
				//color first LINE TO YELLOW
				SetConsoleTextAttribute(_handle, textColorSelect);
				//going to first line		
				coordtemp.Y = _position.getStartCord().Y + 1;
				//go one left
				coordtemp.X--;
				SetConsoleCursorPosition(_handle, coordtemp);
				printOption();
				//go beck one rigt
				coordtemp.X++;
				SetConsoleCursorPosition(_handle, coordtemp);
			}
			break;

		}
		if (c == 'f') { //finish- return chosing values
			vector <string> v = getChoosenData();
			SetConsoleCursorPosition(_handle, COORD{ 30,40 });
			for (int i = 0; i < v.size(); i++) {
				cout << v[i] << endl;
			}
		}
	}
}
Beispiel #11
0
int main(int argc, char *argv[])
{
	int status = 0;
	int length = 0;
	networkAddress address = { { 0, 0, 0, 0, 0, 0 } };
	networkFilter filter;
	unsigned char *buffer = NULL;
	int count, bytes;

	setlocale(LC_ALL, getenv(ENV_LANG));
	textdomain("telnet");

	if (argc != 2)
	{
		usage(argv[0]);
		return (status = ERR_ARGUMENTCOUNT);
	}

	// Parse the supplied network address into our networkAddress structure.

	length = strlen(argv[1]);

	// Replace dots ('.') with NULLS
	for (count = 0; count < length; count ++)
		if (argv[1][count] == '.')
			argv[1][count] = '\0';

	// Get the decimal value of up to 4 numbers
	for (count = 0; count < 4; count ++)
	{
		status = atoi(argv[1]);
		if (status < 0)
		{
			usage(argv[0]);
			return (status = ERR_INVALID);
		}

		address.bytes[count] = status;
		argv[1] += (strlen(argv[1]) + 1);
	}

	buffer = malloc(NETWORK_PACKET_MAX_LENGTH);
	if (!buffer)
	{
		errno = ERR_MEMORY;
		perror(argv[0]);
		return (status);
	}

	// Clear out our filter and ask for the network the headers we want
	memset(&filter, 0, sizeof(networkFilter));
	filter.transProtocol = NETWORK_TRANSPROTOCOL_TCP;
	filter.localPort = 12468;
	filter.remotePort = 23;

	printf("Telnet %d.%d.%d.%d\n", address.bytes[0], address.bytes[1],
		address.bytes[2], address.bytes[3]);

	// Open a connection on the adapter
	connection = networkOpen(NETWORK_MODE_READWRITE, &address, &filter);
	if (!connection)
	{
		errno = ERR_IO;
		perror(argv[0]);
		free(buffer);
		return (status = errno);
	}

	// Set up the signal handler for catching CTRL-C interrupt
	if (signal(SIGINT, &interrupt) == SIG_ERR)
	{
		errno = ERR_NOTINITIALIZED;
		perror(argv[0]);
		networkClose(connection);
		free(buffer);
		return (status);
	}

	//if (0)
	{
		// Send some commands
		//sendCommand(TELNET_COMMAND_DO, TELNET_OPTION_SUPGA);
		//sendCommand(TELNET_COMMAND_WILL, TELNET_OPTION_TTYPE);

		while (!stop)
		{
			bytes = networkCount(connection);
			if (bytes < 0)
				break;

			if (bytes)
			{
				bytes = networkRead(connection, buffer,
					NETWORK_PACKET_MAX_LENGTH);
				if (bytes < 0)
					break;

				for (count = 0 ; count < bytes; count ++)
				{
					if ((unsigned char) buffer[count] == TELNET_COMMAND_IAC)
					{
						count ++;
						printCommand(buffer[count]);

						switch ((unsigned char) buffer[count])
						{
							case TELNET_COMMAND_WILL:
							case TELNET_COMMAND_WONT:
							case TELNET_COMMAND_DO:
							case TELNET_COMMAND_DONT:
								count ++;
								printOption(buffer[count]);
								printCommand(TELNET_COMMAND_WONT);
								printOption(buffer[count]);
								sendCommand(TELNET_COMMAND_WONT,
									buffer[count]);
								break;

							default:
								break;
						}
					}
					else
						printf("%c", buffer[count]);
				}
			}

			multitaskerYield();
		}
	}

	free(buffer);

	status = networkClose(connection);
	if (status < 0)
	{
		errno = status;
		perror(argv[0]);
		return (status);
	}

	return (status = 0);
}