Ejemplo n.º 1
0
void LocationParser_br::parseNoneData(ZonePtr z) {
	/* the only case we have to handle here is that of "scende2", which is the only Animation with
	   a command list following the type marker.
	*/
	if (!scumm_stricmp(_tokens[0], "commands")) {
		parseCommands(z->_commands);
	}
}
Ejemplo n.º 2
0
void* socketThread(void* args) {
  std::cout << std::endl;
  struct thread_info *tinfo;
  tinfo = (thread_info *) args;
  int sock = tinfo->sock;
  userDB *users = tinfo->users;
  std::string sessionKey;
  int sentNumber = 0;

  bool logginIn = false;

  while (1) {
    int n;
    char buffer[256];
    char sendBuffer[256];
    bzero(buffer,256);
    bzero(sendBuffer,256);

    n = read(sock,buffer,255);

    if (n < 0) {
      error("ERROR writing to socket");
      closeSocket(users, sessionKey, sock);
      break;
    }
    if (n == 0) {
      closeSocket(users, sessionKey, sock);
      break;
    }
    if (std::string(buffer).compare("1 init") == 0) {
      std::cout << "atm connection ~ : ";
      std::cout << "socket# " << sock << " connected" << std::endl;
    } else {
      #ifdef _debug
      std::cout << "atm connection ~ : ";
      std::cout << buffer << std::endl;
      #endif
    }
    std::string send = parseCommands(buffer, users, sessionKey, sentNumber);
    n = write(sock, send.c_str(), send.length());
    if (send.compare("not the message I was expecting") == 0) {
      closeSocket(users, sessionKey, sock);
      break;
    }
  }
  pthread_exit(NULL);		// Ends the thread
  return NULL;
}
Ejemplo n.º 3
0
TestClient::TestClient (CORBA::ORB_ptr orb, int argc, ACE_TCHAR *argv[])
: orb_(CORBA::ORB::_duplicate(orb))
, pauseType_('s')
, startupPause_(0)
, threadCount_(0)
, instance_(0)
, iterations_(0)
, requestCount_(0)
, randomRequests_(false)
, shutdownOrb_(false)
, expectHolding_(false)
, expectNoProfile_(false)
, iorFile_(ACE_TEXT("imr_test.ior"))
{
  parseCommands (argc, argv);
}
Ejemplo n.º 4
0
void LocationParser_ns::parseNoneData(ZonePtr z) {
	// "None" zones should have no content, but some
	// inconsistently define their command list after
	// the TYPE marker. This routine catches these
	// command lists that would be lost otherwise.
	if (!scumm_stricmp(_tokens[0], "commands")) {
		parseCommands(z->_commands);
		ctxt.endcommands = false;
		do {
			_script->readLineToken(true);
			_parser->parseStatement();
		} while (!ctxt.endcommands);

		// no need to parse one more line here, as
		// it is done by the caller
	}
}
Ejemplo n.º 5
0
void LocationParser_ns::parseAnswerBody(Answer *answer) {
	answer->_text = parseDialogueString();

	_script->readLineToken(true);
	answer->_mood = atoi(_tokens[0]);
	answer->_followingName = parseDialogueString();

	_script->readLineToken(true);
	if (!scumm_stricmp(_tokens[0], "commands")) {

		parseCommands(answer->_commands);
		ctxt.endcommands = false;
		do {
			_script->readLineToken(true);
			_parser->parseStatement();
		} while (!ctxt.endcommands);

		_script->readLineToken(true);
	}
}
Ejemplo n.º 6
0
void Time::parse(vector<string> args) {
    if (args.size() == 0) {
        printf("%3.3f s\n", currentTime());
        return;
    }

    vector<string> newArgs(args.size());

    for (size_t i = 0; i < args.size(); i++) {
        if (args[i].size() > 1 && args[i][0] == '-' && args[i][1] == '-') {
            newArgs[i] = args[i].substr(1, args[i].size() - 1);
        } else {
            newArgs[i] = args[i];
        }
    }

    float t1 = currentTime();
    parseCommands(newArgs);
    float t2 = currentTime();
    printf("%3.3f s\n", t2 - t1);
}
Ejemplo n.º 7
0
void Action::setCommand(const QString &command, const QStringList &arguments)
{
    m_cmds = parseCommands(command, arguments);
}
Ejemplo n.º 8
0
int main(int argc , char* argv[])
{
    char* fim = "fim"; 
    char** args;
    char argumentos[512];  
    int qntPipes,tmp_entrada,tmp_saida,bg=0; 
    char* prompt = "Quais são suas ordens ? ";
    pid_t processo,w;
    int fileOpen,status;

    fileOpen = open(argv[1],O_RDONLY);

    /* Open File For Standard Input */
    if( ( fileOpen ) == 0 ){
        printf( "Cannot Open File ") ;
        exit( 1 ) ;
    }

    if( fileOpen != 0 ){
        dup2( fileOpen, 0 ); /* Make fp stdin */
        close( fileOpen ) ; /* Close original fp */
    }

    //Valida o que for escrito pelo usuario
    printf("%s",prompt);

    while(fgets(argumentos,512,stdin) != NULL){

        strtok(argumentos,"\n");

        args = parseCommands(argumentos);

        localizaRedirecionamentos(args,&tmp_entrada,&tmp_saida,&bg);
        if(bg != 0){
            removeSimboloBackground(args,bg);
        }
        qntPipes = quantidadePipes(args); 

        processo = fork();
        if (processo == 0){
            if(bg != 0)printf("[1] %ld\n", (long) getpid());
            executarComandos(args,qntPipes);
            _exit(EXIT_SUCCESS);
        }else{
            if(bg != 0){
                do {
                    w = waitpid(processo, &status, WUNTRACED | WCONTINUED);
                    if (w == -1) {
                        perror("waitpid");
                        exit(EXIT_FAILURE);
                    }

                    if (WIFEXITED(status)) {
                        printf("Concluido status=%d\n", WEXITSTATUS(status));
                    } else if (WIFSIGNALED(status)) {
                        printf("killed by signal %d\n", WTERMSIG(status));
                    } else if (WIFSTOPPED(status)) {
                        printf("stopped by signal %d\n", WSTOPSIG(status));
                    } else if (WIFCONTINUED(status)) {
                        printf("continued\n");
                    }
                } while (!WIFEXITED(status) && !WIFSIGNALED(status));
            }else{
                wait(NULL);
                //exit(EXIT_SUCCESS);
            }
        }            
        

        if(strcmp(argumentos,fim) == 0) exit(EXIT_SUCCESS);
        printf("%s",prompt);

    }

    return 0;
}
int main( int argc, const char* argv[])
{
	int rt = 0;
	std::auto_ptr<strus::ErrorBufferInterface> errorBuffer( strus::createErrorBuffer_standard( 0, 2));
	if (!errorBuffer.get())
	{
		std::cerr << _TXT("failed to create error buffer") << std::endl;
		return -1;
	}
	strus::ProgramOptions opt;
	bool printUsageAndExit = false;
	try
	{
		opt = strus::ProgramOptions(
				argc, argv, 6,
				"h,help", "v,version", "license", "m,module:", "M,moduledir:", "T,trace:");
		if (opt( "help"))
		{
			printUsageAndExit = true;
		}
		std::auto_ptr<strus::ModuleLoaderInterface> moduleLoader(
			strus::createModuleLoader( errorBuffer.get()));
		if (!moduleLoader.get()) throw strus::runtime_error(_TXT("error creating module loader"));

		if (opt("moduledir"))
		{
			std::vector<std::string> modirlist( opt.list("moduledir"));
			std::vector<std::string>::const_iterator mi = modirlist.begin(), me = modirlist.end();
			for (; mi != me; ++mi)
			{
				moduleLoader->addModulePath( *mi);
			}
			moduleLoader->addSystemModulePath();
		}
		if (opt("module"))
		{
			std::vector<std::string> modlist( opt.list("module"));
			std::vector<std::string>::const_iterator mi = modlist.begin(), me = modlist.end();
			for (; mi != me; ++mi)
			{
				if (!moduleLoader->loadModule( *mi))
				{
					throw strus::runtime_error(_TXT("error failed to load module %s"), mi->c_str());
				}
			}
		}
		if (opt("license"))
		{
			std::vector<std::string> licenses_3rdParty = moduleLoader->get3rdPartyLicenseTexts();
			std::vector<std::string>::const_iterator ti = licenses_3rdParty.begin(), te = licenses_3rdParty.end();
			if (ti != te) std::cout << _TXT("3rd party licenses:") << std::endl;
			for (; ti != te; ++ti)
			{
				std::cout << *ti << std::endl;
			}
			std::cerr << std::endl;
			if (!printUsageAndExit) return 0;
		}
		if (opt( "version"))
		{
			std::cout << _TXT("Strus utilities version ") << STRUS_UTILITIES_VERSION_STRING << std::endl;
			std::cout << _TXT("Strus storage version ") << STRUS_STORAGE_VERSION_STRING << std::endl;
			std::cout << _TXT("Strus module version ") << STRUS_MODULE_VERSION_STRING << std::endl;
			std::cout << _TXT("Strus rpc version ") << STRUS_RPC_VERSION_STRING << std::endl;
			std::cout << _TXT("Strus trace version ") << STRUS_TRACE_VERSION_STRING << std::endl;
			std::cout << _TXT("Strus base version ") << STRUS_BASE_VERSION_STRING << std::endl;
			std::vector<std::string> versions_3rdParty = moduleLoader->get3rdPartyVersionTexts();
			std::vector<std::string>::const_iterator vi = versions_3rdParty.begin(), ve = versions_3rdParty.end();
			if (vi != ve) std::cout << _TXT("3rd party versions:") << std::endl;
			for (; vi != ve; ++vi)
			{
				std::cout << *vi << std::endl;
			}
			if (!printUsageAndExit) return 0;
		}
		else if (!printUsageAndExit)
		{
			if (opt.nofargs() < 2)
			{
				std::cerr << _TXT("too few arguments") << std::endl;
				printUsageAndExit = true;
				rt = 1;
			}
			if (opt.nofargs() > 2)
			{
				std::cerr << _TXT("too many arguments") << std::endl;
				printUsageAndExit = true;
				rt = 2;
			}
		}
		if (printUsageAndExit)
		{
			std::cout << _TXT("usage:") << " strusAlterMetaData [options] <config> <cmds>" << std::endl;
			std::cout << "<config>  : " << _TXT("configuration string of the storage") << std::endl;
			std::cout << "            " << _TXT("semicolon';' separated list of assignments:") << std::endl;
			printStorageConfigOptions( std::cout, moduleLoader.get(), (opt.nofargs()>=1?opt[0]:""), errorBuffer.get());
			std::cout << "<cmds>    : " << _TXT("semicolon separated list of commands:") << std::endl;
			std::cout << "            alter <name> <newname> <newtype>" << std::endl;
			std::cout << "              <name>    :" << _TXT("name of the element to change") << std::endl;
			std::cout << "              <newname> :" << _TXT("new name of the element") << std::endl;
			std::cout << "              <newtype> :" << _TXT("new type (*) of the element") << std::endl;
			std::cout << "            add <name> <type>" << std::endl;
			std::cout << "              <name>    :" << _TXT("name of the element to add") << std::endl;
			std::cout << "              <type>    :" << _TXT("type (*) of the element to add") << std::endl;
			std::cout << "            delete <name>" << std::endl;
			std::cout << "              <name>    :" << _TXT("name of the element to remove") << std::endl;
			std::cout << "            rename <name> <newname>" << std::endl;
			std::cout << "              <name>    :" << _TXT("name of the element to rename") << std::endl;
			std::cout << "              <newname> :" << _TXT("new name of the element") << std::endl;
			std::cout << "            clear <name>" << std::endl;
			std::cout << "              <name>    :" << _TXT("name of the element to clear all values") << std::endl;
			std::cout << "(*)       :" << _TXT("type of an element is one of the following:") << std::endl;
			std::cout << "              INT8      :" << _TXT("one byte signed integer value") << std::endl;
			std::cout << "              UINT8     :" << _TXT("one byte unsigned integer value") << std::endl;
			std::cout << "              INT16     :" << _TXT("two bytes signed integer value") << std::endl;
			std::cout << "              UINT16    :" << _TXT("two bytes unsigned integer value") << std::endl;
			std::cout << "              INT32     :" << _TXT("four bytes signed integer value") << std::endl;
			std::cout << "              UINT32    :" << _TXT("four bytes unsigned integer value") << std::endl;
			std::cout << "              FLOAT16   :" << _TXT("two bytes floating point value (IEEE 754 small)") << std::endl;
			std::cout << "              FLOAT32   :" << _TXT("four bytes floating point value (IEEE 754 single)") << std::endl;
			std::cout << _TXT("description: Executes a list of alter the meta data table commands.") << std::endl;
			std::cout << _TXT("options:") << std::endl;
			std::cout << "-h|--help" << std::endl;
			std::cout << "    " << _TXT("Print this usage and do nothing else") << std::endl;
			std::cout << "-v|--version" << std::endl;
			std::cout << "    " << _TXT("Print the program version and do nothing else") << std::endl;
			std::cout << "--license" << std::endl;
			std::cout << "    " << _TXT("Print 3rd party licences requiring reference") << std::endl;
			std::cout << "-m|--module <MOD>" << std::endl;
			std::cout << "    " << _TXT("Load components from module <MOD>") << std::endl;
			std::cout << "-M|--moduledir <DIR>" << std::endl;
			std::cout << "    " << _TXT("Search modules to load first in <DIR>") << std::endl;
			std::cout << "-T|--trace <CONFIG>" << std::endl;
			std::cout << "    " << _TXT("Print method call traces configured with <CONFIG>") << std::endl;
			std::cout << "    " << strus::string_format( _TXT("Example: %s"), "-T \"log=dump;file=stdout\"") << std::endl;
			return rt;
		}
		// Parse arguments:
		std::string storagecfg = opt[0];
		std::vector<AlterMetaDataCommand> cmds = parseCommands( opt[1]);

		// Declare trace proxy objects:
		typedef strus::Reference<strus::TraceProxy> TraceReference;
		std::vector<TraceReference> trace;
		if (opt("trace"))
		{
			std::vector<std::string> tracecfglist( opt.list("trace"));
			std::vector<std::string>::const_iterator ti = tracecfglist.begin(), te = tracecfglist.end();
			for (; ti != te; ++ti)
			{
				trace.push_back( new strus::TraceProxy( moduleLoader.get(), *ti, errorBuffer.get()));
			}
		}

		// Create objects for altering the meta data table:
		std::auto_ptr<strus::StorageObjectBuilderInterface> builder;
		std::auto_ptr<strus::StorageAlterMetaDataTableInterface> md;

		builder.reset( moduleLoader->createStorageObjectBuilder());
		if (!builder.get()) throw strus::runtime_error(_TXT("failed to create storage object builder"));

		// Create proxy objects if tracing enabled:
		std::vector<TraceReference>::const_iterator ti = trace.begin(), te = trace.end();
		for (; ti != te; ++ti)
		{
			strus::StorageObjectBuilderInterface* builderproxy = (*ti)->createProxy( builder.get());
			builder.release();
			builder.reset( builderproxy);
		}

		md.reset( strus::createAlterMetaDataTable( builder.get(), errorBuffer.get(), storagecfg));
		if (!md.get()) throw strus::runtime_error(_TXT("failed to create storage alter metadata table structure"));

		// Execute alter meta data table commands:
		std::vector<AlterMetaDataCommand>::const_iterator ci = cmds.begin(), ce = cmds.end();
		for (; ci != ce; ++ci)
		{
			switch (ci->id())
			{
				case AlterMetaDataCommand::Alter:
					md->alterElement( ci->name(), ci->newname(), ci->type());
					break;
				case AlterMetaDataCommand::Add:
					md->addElement( ci->name(), ci->type());
					break;
				case AlterMetaDataCommand::Delete:
					md->deleteElement( ci->name());
					break;
				case AlterMetaDataCommand::Rename:
					md->renameElement( ci->name(), ci->newname());
					break;
				case AlterMetaDataCommand::Clear:
					md->clearElement( ci->name());
					break;
			}
		}
		std::cerr << _TXT("updating meta data table changes...") << std::endl;
		if (!md->commit()) throw strus::runtime_error(_TXT("alter meta data commit failed"));

		std::cerr << _TXT("done") << std::endl;
		if (errorBuffer->hasError())
		{
			throw strus::runtime_error(_TXT("unhandled error in alter meta data"));
		}
		return 0;
	}
	catch (const std::bad_alloc&)
	{
		std::cerr << _TXT("ERROR ") << _TXT("out of memory") << std::endl;
	}
	catch (const std::runtime_error& e)
	{
		const char* errormsg = errorBuffer->fetchError();
		if (errormsg)
		{
			std::cerr << _TXT("ERROR ") << e.what() << ": " << errormsg << std::endl;
		}
		else
		{
			std::cerr << _TXT("ERROR ") << e.what() << std::endl;
		}
	}
	catch (const std::exception& e)
	{
		std::cerr << _TXT("EXCEPTION ") << e.what() << std::endl;
	}
	return -1;
}