コード例 #1
0
ファイル: cod_tool.cpp プロジェクト: AlainRoy/htcondor
void
parsePOpt( char* opt, char* arg )
{
 		// first, try to understand what the option is they passed,
		// given what kind of cod command we want to send.  -proc
		// is only valid for activate, so if we're not doing that, we
		// can assume they want -pool

	char _pool[] = "-pool";
	char _proc[] = "-proc";
	char* parse_target = NULL;

		// we already checked these, make sure we're not crazy
	assert( opt[0] == '-' && opt[1] == 'p' );  

	if( cmd == CA_ACTIVATE_CLAIM ) {
		if( ! opt[2] ) {
			ambiguous( opt );
		}
		switch( opt[2] ) {
		case 'o':
			if( strncmp(_pool, opt, strlen(opt)) ) {
				invalid( opt );
			} 
			parse_target = _pool;
			break;

		case 'r':
			if( strncmp(_proc, opt, strlen(opt)) ) {
				invalid( opt );
			} 
			parse_target = _proc;
			break;

		default:
			invalid( opt );
			break;
		}
	} else { 
		if( strncmp(_pool, opt, strlen(opt)) ) {
			invalid( opt );
		} 
		parse_target = _pool;
	}

		// now, make sure we got the arg
	if( ! arg ) {
		another( parse_target );
	}

	if( parse_target == _pool ) {
		pool = new DCCollector( arg );
		if( ! pool->addr() ) {
			fprintf( stderr, "%s: %s\n", my_name, pool->error() );
			exit( 1 );
		}
	} else {
		proc_id = atoi( arg );
	}
}
コード例 #2
0
ファイル: int.c プロジェクト: xatier/brainfuck-tools
// compact: compact repeat instructions
static instruction *compact (instruction *prog) {
    instruction *ret = prog;
    register char flag1 = 0, flag2 = 0;

    while (prog) {
        switch ((int) prog->opcode) {
            case LOOP_START:
                prog->loop = compact(prog->loop);
                break;
            case INC:
            case DEC:
            case NEXT:
            case PREV:
                flag1 = flag2 = 0;
                while (prog->next && (flag1 = same(prog) || (flag2 = another(prog)))) {
                    instruction *t = prog->next;
                    prog->value += flag1 && !flag2 ? t->value : -t->value;
                    prog->next = t->next;
                    free(t);
                }
                break;
        }
        prog = prog->next;
    }
    return ret;
}
コード例 #3
0
ファイル: cod_tool.cpp プロジェクト: AlainRoy/htcondor
void
parseCOpt( char* opt, char* arg )
{
 		// first, try to understand what the option is they passed,
		// given what kind of cod command we want to send.  -cluster
		// is only valid for activate, so if we're not doing that, we
		// can assume they want -classad

	char _cpath[] = "-classad";
	char _clust[] = "-cluster";
	char* parse_target = NULL;

		// we already checked these, make sure we're not crazy
	assert( opt[0] == '-' && opt[1] == 'c' );  

	if( cmd == CA_ACTIVATE_CLAIM ) {
		if( ! (opt[2] && opt[3]) ) {
			ambiguous( opt );
		}
		if( opt[2] != 'l' ) {
			invalid( opt );
		}
		switch( opt[3] ) {
		case 'a':
			if( strncmp(_cpath, opt, strlen(opt)) ) {
				invalid( opt );
			} 
			parse_target = _cpath;
			break;

		case 'u':
			if( strncmp(_clust, opt, strlen(opt)) ) {
				invalid( opt );
			} 
			parse_target = _clust;
			break;

		default:
			invalid( opt );
			break;
		}
	} else { 
		if( strncmp(_cpath, opt, strlen(opt)) ) {
			invalid( opt );
		}
		parse_target = _cpath;
	}

		// now, make sure we got the arg
	if( ! arg ) {
		another( parse_target );
	}
	if( parse_target == _clust ) {
			// we can check like that, since we're setting target to
			// point to it, so we don't have to do a strcmp().
		cluster_id = atoi( arg );
	} else {
		classad_path = strdup( arg );
	}
}
コード例 #4
0
ファイル: cmdcb.c プロジェクト: BillTheBest/SCPS_Project
/* cmdcp -
 *     Execute a remote file copy.
 */
int
cmdcp (int argc, char *argv[])
{
  char buf[80];

  if (argc < 2 && !another (&argc, &argv, "from-name"))
    goto usage;
  if (argc < 3 && !another (&argc, &argv, "to-name"))
    {
    usage:
      printf ("%s from-name to-name\n", argv[0]);
      code = -1;
      return 0;
    }
  nsprintf (buf, sizeof (buf), "COPY %s %s", argv[1], argv[2]);
  return (COMPLETE == sendcommand (buf) ? 0 : -1);
}				/* cmdcp() */
コード例 #5
0
ファイル: cmdcb.c プロジェクト: BillTheBest/SCPS_Project
/* cmduser -
 *
 *    Returns 0 on success, -1 on error.
 */
int
cmduser (int argc, char *argv[])
{
  char acct[80];
  int n, aflag = 0;

  if (argc < 2)
    if (0 > another (&argc, &argv, "username"))
      return (-1);
  if (argc < 2 || argc > 4)
    {
      printf ("usage: %s username [password] [account]\n", argv[0]);
      code = -1;
      return (-1);
    }
  nsprintf (msgbuf, sizeof (msgbuf), "USER %s", argv[1]);
  n = sendcommand (msgbuf);
  if (n == CONTINUE)
    {
      if (argc < 3)
#if defined(SUNOS) || defined(__BSD__)
	argv[2] = gpass ("Password: "******"Password: "******"PASS %s", argv[2]);
      n = sendcommand (msgbuf);
      memset (argv[2], 0, strlen (argv[2]));
    }
  if (n == CONTINUE)
    {
      if (argc < 4)
	{
	  printf ("Account: ");
	  (void) fflush (stdout);
	  (void) fgets (acct, sizeof (acct) - 1, stdin);
	  acct[strlen (acct) - 1] = '\0';
	  argv[3] = acct;
	  argc++;
	}
      nsprintf (msgbuf, sizeof (msgbuf), "ACCT %s", argv[3]);
      n = sendcommand (msgbuf);
      aflag++;
    }
  if (n != COMPLETE)
    {
      fprintf (stdout, "Login failed.\n");
      return (-1);
    }
  if (!aflag && argc == 4)
    {
      nsprintf (msgbuf, sizeof (msgbuf), "ACCT %s", argv[3]);
      (void) sendcommand (msgbuf);
    }
  return 0;
}				/* cmduser() */
コード例 #6
0
ファイル: vcbutton_test.cpp プロジェクト: ChrisLaurie/qlcplus
void VCButton_Test::toggle()
{
    QWidget w;

    Scene* sc = new Scene(m_doc);
    sc->setValue(0, 0, 255);
    sc->setFadeInSpeed(1000);
    sc->setFadeOutSpeed(1000);
    m_doc->addFunction(sc);

    VCButton btn(&w, m_doc);
    btn.setCaption("Foobar");
    btn.setFunction(sc->id());
    btn.setAction(VCButton::Toggle);
    btn.setKeySequence(QKeySequence(keySequenceB));
    btn.enableStartupIntensity(true);
    btn.setStartupIntensity(qreal(0.2));

    // Mouse button press in design mode doesn't toggle the function
    QCOMPARE(m_doc->mode(), Doc::Design);
    QMouseEvent ev(QEvent::MouseButtonPress, QPoint(0, 0), Qt::LeftButton, 0, 0);
    btn.mousePressEvent(&ev);
    QCOMPARE(m_doc->masterTimer()->m_functionList.size(), 0);
    ev = QMouseEvent(QEvent::MouseButtonRelease, QPoint(0, 0), Qt::LeftButton, 0, 0);
    btn.mouseReleaseEvent(&ev);
    QCOMPARE(m_doc->masterTimer()->m_functionList.size(), 0);

    // Mouse button press in operate mode should toggle the function
    m_doc->setMode(Doc::Operate);
    btn.slotKeyPressed(QKeySequence(keySequenceB));
    // tell MasterTimer to process start queue
    m_doc->masterTimer()->timerTick();
    QCOMPARE(m_doc->masterTimer()->m_functionList.size(), 1);
    QCOMPARE(m_doc->masterTimer()->m_functionList[0], sc);
    QCOMPARE(sc->getAttributeValue(Function::Intensity), btn.startupIntensity());
    btn.slotKeyReleased(QKeySequence(keySequenceB));
    m_doc->masterTimer()->timerTick(); // Allow MasterTimer to take the function under execution
    QCOMPARE(sc->stopped(), false);
    QCOMPARE(btn.isOn(), true);

    ev = QMouseEvent(QEvent::MouseButtonPress, QPoint(0, 0), Qt::LeftButton, 0, 0);
    btn.mousePressEvent(&ev);
    QCOMPARE(sc->m_stop, true);
    QCOMPARE(btn.isOn(), true);

    btn.slotFunctionStopped(sc->id());
    QCOMPARE(btn.isOn(), false);
    VCButton another(&w, m_doc);
    QVERIFY(btn.palette().color(QPalette::Button) != another.palette().color(QPalette::Button));
    QTest::qWait(500);
    QVERIFY(btn.palette().color(QPalette::Button) == another.palette().color(QPalette::Button));

    ev = QMouseEvent(QEvent::MouseButtonRelease, QPoint(0, 0), Qt::LeftButton, 0, 0);
    btn.mouseReleaseEvent(&ev);
}
コード例 #7
0
ファイル: cmdcb.c プロジェクト: BillTheBest/SCPS_Project
/* cmdrename -
 *     Rename a remote file.
 */
int
cmdrename (int argc, char *argv[])
{
  char buf[80];

  if (argc < 2 && !another (&argc, &argv, "from-name"))
    goto usage;
  if (argc < 3 && !another (&argc, &argv, "to-name"))
    {
    usage:
      printf ("%s from-name to-name\n", argv[0]);
      code = -1;
      return 0;
    }
  nsprintf (buf, sizeof (buf), "RNFR %s", argv[1]);
  if (sendcommand (buf) == CONTINUE)
    {
      nsprintf (buf, sizeof (buf), "RNTO %s", argv[2]);
      return (COMPLETE == sendcommand (buf) ? 0 : -1);
    }
  else
    return -1;
}				/* cmdrename() */
コード例 #8
0
ファイル: cmdcb.c プロジェクト: BillTheBest/SCPS_Project
/* cmdrmdir -
 *     Remove a directory
 */
int
cmdrmdir (int argc, char *argv[])
{
  char buf[256];

  if (argc < 2 && !another (&argc, &argv, "directory-name"))
    {
      printf ("usage: %s directory-name\n", argv[0]);
      code = -1;
      return 0;
    }
  nsprintf (buf, sizeof (buf), "RMD %s", argv[1]);
  return (COMPLETE == sendcommand (buf) ? 0 : -1);
}				/* cmdrmdir() */
コード例 #9
0
QTreeWidgetItem* VCXYPadProperties::fixtureItem(const VCXYPadFixture& fxi)
{
    QTreeWidgetItemIterator it(m_tree);
    while (*it != NULL)
    {
        QVariant var((*it)->data(KColumnFixture, Qt::UserRole));
        VCXYPadFixture another(m_doc, var);
        if (fxi.head() == another.head())
            return *it;
        else
            ++it;
    }

    return NULL;
}
コード例 #10
0
void DMTest::testTempVar()
{
    // Test add temp variables
    
    //! test bool
    TEMP_VAR->set("test_bool", true);
    CCASSERT(TEMP_VAR->getBool("test_bool"), "");
    TEMP_VAR->set("test_bool", false);
    CCASSERT(!TEMP_VAR->getBool("test_bool"), "");
    
    CCASSERT(!TEMP_VAR->getBool("test_bool2"),"");
    
    //! test int
    CCASSERT(TEMP_VAR->getInt("int1")==0,"");
    TEMP_VAR->set("int1", 100);
    CCASSERT(TEMP_VAR->getInt("int1")==100,"");
    TEMP_VAR->set("int1", -99);
    CCASSERT(TEMP_VAR->getInt("int1")==-99,"");
    
    //! test uint
    unsigned int ui = 91900;
    CCASSERT(TEMP_VAR->getUint("uint1")==0,"");
    TEMP_VAR->set("uint1", ui);
    CCASSERT(TEMP_VAR->getUint("uint1")==ui,"");
    TEMP_VAR->set("uint1", ui+1);
    CCASSERT(TEMP_VAR->getUint("uint1")==91901,"");
    
    //!test int64
    int64_t i64 = 288288;
    CCASSERT(TEMP_VAR->getInt64("int64")==0,"");
    TEMP_VAR->set("int64", i64);
    CCASSERT(TEMP_VAR->getInt64("int64")==i64,"");
    TEMP_VAR->set("int64", i64-8);
    CCASSERT(TEMP_VAR->getInt64("int64")==288280,"");
    
    //!test uint64
    uint64_t ui64 = 9999999;
    CCASSERT(TEMP_VAR->getUint64("uint64")==0,"");
    TEMP_VAR->set("uint64", ui64);
    CCASSERT(TEMP_VAR->getUint64("uint64")==ui64,"");
    TEMP_VAR->set("uint64", ui64 + 1);
    CCASSERT(TEMP_VAR->getUint64("uint64")==10000000,"");

    //!test double
    CCASSERT(TEMP_VAR->getDouble("double1")==0,"");
    TEMP_VAR->set("double1", 10.01);
    CCASSERT(TEMP_VAR->getDouble("double1")==10.01,"");
    TEMP_VAR->set("double1", -1001.99);
    CCASSERT(TEMP_VAR->getDouble("double1")==-1001.99, "");
    
    //! test string
    CCASSERT(TEMP_VAR->getCharArray("string1")==nullptr, "");
    TEMP_VAR->set("string1", "i am a const char* !");
    CCASSERT(strcmp(TEMP_VAR->getCharArray("string1"), "i am a const char* !") == 0 , "");
    TEMP_VAR->set("string1", "i am not the same");
    const char* string1 = TEMP_VAR->getCharArray("string1");
    CCASSERT(strcmp(string1, "i am not the same") == 0, "");
    
    TEMP_VAR->set("string2", std::string("hello"));
    CCASSERT(TEMP_VAR->getString("string2").compare("hello") == 0, "");
    std::string another("world");
    TEMP_VAR->set("string2", another);
    CCASSERT(TEMP_VAR->getString("string2").compare("world") == 0, "");
    
    //! test map
    std::unordered_map<std::string, int> testmap = {{"key1", 0}, {"key2", 1}, {"key3", 2}};
    //! resetmap
    TEMP_VAR->set("map1", testmap); //left value
    
    TEMP_VAR->set("map2", std::unordered_map<std::string, double> ( { {"11",19.9}, {"22", 29.9}, {"33", 39.9} } )); //right value
    
    //! add to map
    for (int i = 0; i < 100; ++i) {
        char buf[20];
        sprintf(buf, "key_%d", i);
        TEMP_VAR->addMemberToMap("map1", buf, i);  //already exist
        TEMP_VAR->addMemberToMap("map2", buf, 0.99+i); //already exist
    }
    for (int i = 0; i < 10; ++i) {
        char buf[20];
        sprintf(buf, "key_%d", i);
        TEMP_VAR->addMemberToMap("map3", buf, i); //not exist
    }
    
    //! remove from map
    for (int i = 0; i < 100; ++i) {
        char buf[20];
        sprintf(buf, "key_%d", i);
        TEMP_VAR->removeFromMap("map1", buf);
        TEMP_VAR->removeFromMap("map2", buf);
    }
    
    TEMP_VAR->removeFromMap("map3", "key_0");
    TEMP_VAR->removeFromMap("map4", "n"); // not exist
    
    //print all the map
    //! map1
    auto& map1 = TEMP_VAR->getObject("map1");
    std::for_each(map1.MemberonBegin(), map1.MemberonEnd(), [](ValueType::Member& member){std::cout<<"["<<member.name.GetString() << ","<<member.value.GetInt() << "] ";});
    
    std::cout<<std::endl;
    
    auto& map2 = TEMP_VAR->getObject("map2");
    std::for_each(map2.MemberonBegin(), map2.MemberonEnd(), [](ValueType::Member& member){std::cout<<"["<<member.name.GetString() << ","<<member.value.GetDouble() << "] ";});
    
    std::cout<<std::endl;
    
    auto& map3 = TEMP_VAR->getObject("map3");
    std::for_each(map3.MemberonBegin(), map3.MemberonEnd(), [](ValueType::Member& member){std::cout<<"["<<member.name.GetString() << ","<<member.value.GetInt() << "] ";});
    
    std::cout<<std::endl;
    
    CCASSERT(TEMP_VAR->getValueFromMap("map1", "key1").GetInt() == 0, "");
    CCASSERT(TEMP_VAR->getValueFromMap("map2", "11").GetDouble() == 19.9, "");
    CCASSERT(TEMP_VAR->getValueFromMap("map3", "key_1").GetInt() == 1, "");
    CCASSERT(TEMP_VAR->getValueFromMap("map3", "key_0").IsNull(), ""); //not exist
    CCASSERT(TEMP_VAR->getValueFromMap("map4", "oo").IsNull(), "");//not exist
    CCASSERT(TEMP_VAR->getValueFromMap("map5", "hh").IsNull(), "");//not exist
    
    
    //! test array
    std::vector<int> array = {10,20,30,40,50};
    TEMP_VAR->set("arr1", array);
    TEMP_VAR->set("arr2", std::vector<double>{1.0,2.0,3.0,4.0,5.0,6.0} ) ;
    
    TEMP_VAR->addValueToArray("arr1", 60);
    TEMP_VAR->addValueToArray("arr2", 7.0);
    TEMP_VAR->addValueToArray("arr3", 100); // not exist
    
    CCASSERT(TEMP_VAR->getSize("arr1") == 6, "");
    CCASSERT(TEMP_VAR->getSize("arr2") == 7, "");
    CCASSERT(TEMP_VAR->getSize("arr3") == 1, "");
    CCASSERT(TEMP_VAR->getSize("arr100") == 0, "");
    CCASSERT(TEMP_VAR->isArrayEmpty("arr100"), "");
    CCASSERT(TEMP_VAR->isArrayEmpty("arr101"), "");
    
    TEMP_VAR->popFromArray("arr1");
    TEMP_VAR->popFromArray("arr1");
    TEMP_VAR->popFromArray("arr2");
    TEMP_VAR->popFromArray("arr2");
    TEMP_VAR->popFromArray("arr3");
//    TEMP_VAR->popFromArray("arr3"); //not allowed
    
    CCASSERT(TEMP_VAR->isArrayEmpty("arr3"), "");
    
    auto& v1 = TEMP_VAR->getValueFromArray("arr1", 0);
    CCASSERT(v1.GetInt() == 10, "");
    auto& v2 = TEMP_VAR->getValueFromArray("arr2", 2);
    CCASSERT(v2.GetDouble() == 3.0, "");
    
    TEMP_VAR->addValueToArray("arr3", 200);
    CCASSERT(TEMP_VAR->getValueFromArray("arr3", 0).GetInt() == 200, "");
    
    //! test Serializable object
    {
        Dependent dep("Lua YIP", 3, new Education("Happy Kindergarten", 3.5));
        TEMP_VAR->setSerializable("p1", dep);
        Dependent dep1("Luo Zhouqiong", 3, nullptr);
        TEMP_VAR->setSerializable("p2", dep1);
        Dependent dep2 = dep;
        TEMP_VAR->setSerializable("p3", dep2);
        dep = dep1;
        TEMP_VAR->setSerializable("p1", dep);
    }
    {
        Dependent dep1, dep2, dep3;
        TEMP_VAR->getSerializable("p1", dep1);
        TEMP_VAR->getSerializable("p2", dep2);
        TEMP_VAR->getSerializable("p3", dep3);
        
        std::cout<< dep1 <<std::endl;
        std::cout<< dep2 <<std::endl;
        std::cout<< dep3 <<std::endl;
        
    }
    
    
    //dump the memory
    TEMP_VAR->dumpMemory(std::cout);
    
    // Test remove temp variables
    
    TEMP_VAR->remove("string1");
    TEMP_VAR->remove("arr3");
    TEMP_VAR->remove("map1");
    
    //dump the memory
    TEMP_VAR->dumpMemory(std::cout);
    
    // Then add temp variables
    TEMP_VAR->set("++++++", true);
    TEMP_VAR->set("+++++++", 999.999);
    
    //dump the memory
    TEMP_VAR->dumpMemory(std::cout);
    
    // Then add temp variables
    TEMP_VAR->set("++++++++", "I love you!");
    TEMP_VAR->set("+++++++++", "I love you too!");
    TEMP_VAR->dumpMemory(std::cout);

}
コード例 #11
0
ファイル: main.c プロジェクト: Freeaqingme/OpenBSD
int
main(int ac, char *av[])
{
	bool		show_only;
	extern char	*Scorefile;
	int		score_wfd;     /* high score writable file descriptor */
	int		score_err = 0; /* hold errno from score file open */
	int		ch;
	extern int	optind;
	gid_t		gid;
#ifdef FANCY
	char		*sp;
#endif

	if ((score_wfd = open(Scorefile, O_RDWR)) < 0)
		score_err = errno;

	/* revoke privs */
	gid = getgid();
	setresgid(gid, gid, gid);

	show_only = FALSE;
	while ((ch = getopt(ac, av, "srajt")) != -1)
		switch (ch) {
		case 's':
			show_only = TRUE;
			break;
		case 'r':
			Real_time = TRUE;
			/* Could be a command-line option */
			tv.tv_sec = 3;
			tv.tv_usec = 0;
			FD_ZERO(&rset);
			break;
		case 'a':
			Start_level = 4;
			break;
		case 'j':
			Jump = TRUE;
			break;
		case 't':
			Teleport = TRUE;
			break;
		case '?':
		default:
			usage();
		}
	ac -= optind;
	av += optind;

	if (ac > 1)
		usage();
	if (ac == 1) {
		Scorefile = av[0];
		if (score_wfd >= 0)
			close(score_wfd);
		/* This file requires no special privileges. */
		if ((score_wfd = open(Scorefile, O_RDWR)) < 0)
			score_err = errno;
#ifdef	FANCY
		sp = strrchr(Scorefile, '/');
		if (sp == NULL)
			sp = Scorefile;
		if (strcmp(sp, "pattern_roll") == 0)
			Pattern_roll = TRUE;
		else if (strcmp(sp, "stand_still") == 0)
			Stand_still = TRUE;
		if (Pattern_roll || Stand_still)
			Teleport = TRUE;
#endif
	}

	if (show_only) {
		show_score();
		exit(0);
	}

	if (score_wfd < 0) {
		warnx("%s: %s; no scores will be saved", Scorefile,
			strerror(score_err));
		sleep(1);
	}

	initscr();
	signal(SIGINT, quit);
	cbreak();
	noecho();
	nonl();
	if (LINES != Y_SIZE || COLS != X_SIZE) {
		if (LINES < Y_SIZE || COLS < X_SIZE) {
			endwin();
			errx(1, "Need at least a %dx%d screen", Y_SIZE, X_SIZE);
		}
		delwin(stdscr);
		stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
	}

	srandomdev();
	do {
		init_field();
		for (Level = Start_level; !Dead; Level++) {
			make_level();
			play_level();
		}
		move(My_pos.y, My_pos.x);
		printw("AARRrrgghhhh....");
		refresh();
		score(score_wfd);
	} while (another());
	quit(0);
	/* NOT REACHED */
}
コード例 #12
0
ファイル: domacro.c プロジェクト: GnoConsortium/gno
void domacro (int argc, char **argv)
{
int i, j;
char *cp1, *cp2;
int count = 2, loopflg = 0;
static char line2[200];
struct cmd *c;

	if (argc < 2 && !another(&argc, &argv, "macro name")) {
		printf("Usage: %s macro_name.\n", argv[0]);
		code = -1;
		return;
	}
	for (i = 0; i < macnum; ++i) {
		if (!strncmp(argv[1], macros[i].mac_name, 9)) {
			break;
		}
	}
	if (i == macnum) {
		printf("'%s' macro not found.\n", argv[1]);
		code = -1;
		return;
	}
	(void) strcpy(line2, line);
TOP:
	cp1 = macros[i].mac_start;
	while (cp1 != macros[i].mac_end) {
		while (isspace(*cp1)) {
			cp1++;
		}
		cp2 = line;
		while (*cp1 != '\0') {
		      switch(*cp1) {
		   	    case '\\':
				 *cp2++ = *++cp1;
				 break;
			    case '$':
				 if (isdigit(*(cp1+1))) {
				    j = 0;
				    while (isdigit(*++cp1)) {
					  j = 10*j +  *cp1 - '0';
				    }
				    cp1--;
				    if (argc - 2 >= j) {
					(void) strcpy(cp2, argv[j+1]);
					cp2 += strlen(argv[j+1]);
				    }
				    break;
				 }
				 if (*(cp1+1) == 'i') {
					loopflg = 1;
					cp1++;
					if (count < argc) {
					   (void) strcpy(cp2, argv[count]);
					   cp2 += strlen(argv[count]);
					}
					break;
				}
				/* intentional drop through */
			    default:
				*cp2++ = *cp1;
				break;
		      }
		      if (*cp1 != '\0') {
			 cp1++;
		      }
		}
		*cp2 = '\0';
		makeargv();
		c = getcmd(margv[0]);
		if (c == (struct cmd *)-1) {
			printf("?Ambiguous command\n");
			code = -1;
		}
		else if (c == 0) {
			printf("?Invalid command\n");
			code = -1;
		}
		else if (c->c_conn && !connected) {
			printf("Not connected.\n");
			code = -1;
		}
		else {
			if (verbose) {
				printf("%s\n",line);
			}
			(*c->c_handler)(margc, margv);
			if (bell && c->c_bell) {
				(void) putchar('\007');
			}
			(void) strcpy(line, line2);
			makeargv();
			argc = margc;
			argv = margv;
		}
		if (cp1 != macros[i].mac_end) {
			cp1++;
		}
	}
	if (loopflg && ++count < argc) {
		goto TOP;
	}
}
コード例 #13
0
ファイル: main.c プロジェクト: a565109863/src
int
main(int ac, char *av[])
{
	bool		show_only;
	extern char	Scorefile[PATH_MAX];
	int		score_wfd;     /* high score writable file descriptor */
	int		score_err = 0; /* hold errno from score file open */
	int		ch;
	int		ret;
	extern int	optind;
	char		*home;
#ifdef FANCY
	char		*sp;
#endif

	if (pledge("stdio rpath wpath cpath tty", NULL) == -1)
		err(1, "pledge");

	home = getenv("HOME");
	if (home == NULL || *home == '\0')
		err(1, "getenv");

	ret = snprintf(Scorefile, sizeof(Scorefile), "%s/%s", home,
	    ".robots.scores");
	if (ret < 0 || ret >= PATH_MAX)
		errc(1, ENAMETOOLONG, "%s/%s", home, ".robots.scores");

	if ((score_wfd = open(Scorefile, O_RDWR | O_CREAT, 0666)) < 0)
		score_err = errno;

	show_only = FALSE;
	while ((ch = getopt(ac, av, "srajt")) != -1)
		switch (ch) {
		case 's':
			show_only = TRUE;
			break;
		case 'r':
			Real_time = TRUE;
			/* Could be a command-line option */
			tv.tv_sec = 3;
			break;
		case 'a':
			Start_level = 4;
			break;
		case 'j':
			Jump = TRUE;
			break;
		case 't':
			Teleport = TRUE;
			break;
		case '?':
		default:
			usage();
		}
	ac -= optind;
	av += optind;

	if (ac > 1)
		usage();
	if (ac == 1) {
		if (strlcpy(Scorefile, av[0], sizeof(Scorefile)) >=
		    sizeof(Scorefile))
			errc(1, ENAMETOOLONG, "%s", av[0]);
		if (score_wfd >= 0)
			close(score_wfd);
		/* This file requires no special privileges. */
		if ((score_wfd = open(Scorefile, O_RDWR | O_CREAT, 0666)) < 0)
			score_err = errno;
#ifdef	FANCY
		sp = strrchr(Scorefile, '/');
		if (sp == NULL)
			sp = Scorefile;
		if (strcmp(sp, "pattern_roll") == 0)
			Pattern_roll = TRUE;
		else if (strcmp(sp, "stand_still") == 0)
			Stand_still = TRUE;
		if (Pattern_roll || Stand_still)
			Teleport = TRUE;
#endif
	}

	if (show_only) {
		show_score();
		return 0;
	}

	if (score_wfd < 0) {
		warnx("%s: %s; no scores will be saved", Scorefile,
			strerror(score_err));
		sleep(1);
	}

	initscr();
	signal(SIGINT, quit);
	cbreak();
	noecho();
	nonl();
	if (LINES != Y_SIZE || COLS != X_SIZE) {
		if (LINES < Y_SIZE || COLS < X_SIZE) {
			endwin();
			errx(1, "Need at least a %dx%d screen", Y_SIZE, X_SIZE);
		}
		delwin(stdscr);
		stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
	}

	do {
		init_field();
		for (Level = Start_level; !Dead; Level++) {
			make_level();
			play_level();
		}
		if (My_pos.x > X_FIELDSIZE - 16)
			move(My_pos.y, X_FIELDSIZE - 16);
		else
			move(My_pos.y, My_pos.x);
		printw("AARRrrgghhhh....");
		refresh();
		score(score_wfd);
	} while (another());
	quit(0);
}
コード例 #14
0
ファイル: domacro.c プロジェクト: yunxiaoxiao110/haiku
void
domacro(int argc, char *argv[])
{
    int i, j, count = 2, loopflg = 0;
    char *cp1, *cp2, line2[FTPBUFLEN];
    struct cmd *c;

    if ((argc == 0 && argv != NULL) ||
            (argc < 2 && !another(&argc, &argv, "macro name"))) {
        fprintf(ttyout, "usage: %s macro_name [args]\n", argv[0]);
        code = -1;
        return;
    }
    for (i = 0; i < macnum; ++i) {
        if (!strncmp(argv[1], macros[i].mac_name, 9))
            break;
    }
    if (i == macnum) {
        fprintf(ttyout, "'%s' macro not found.\n", argv[1]);
        code = -1;
        return;
    }
    (void)strlcpy(line2, line, sizeof(line2));
TOP:
    cp1 = macros[i].mac_start;
    while (cp1 != macros[i].mac_end) {
        while (isspace((unsigned char)*cp1))
            cp1++;
        cp2 = line;
        while (*cp1 != '\0') {
            switch(*cp1) {
            case '\\':
                *cp2++ = *++cp1;
                break;
            case '$':
                if (isdigit((unsigned char)*(cp1+1))) {
                    j = 0;
                    while (isdigit((unsigned char)*++cp1))
                        j = 10*j +  *cp1 - '0';
                    cp1--;
                    if (argc - 2 >= j) {
                        (void)strlcpy(cp2, argv[j+1],
                                      sizeof(line) - (cp2 - line));
                        cp2 += strlen(argv[j+1]);
                    }
                    break;
                }
                if (*(cp1+1) == 'i') {
                    loopflg = 1;
                    cp1++;
                    if (count < argc) {
                        (void)strlcpy(cp2, argv[count],
                                      sizeof(line) - (cp2 - line));
                        cp2 += strlen(argv[count]);
                    }
                    break;
                }
            /* intentional drop through */
            default:
                *cp2++ = *cp1;
                break;
            }
            if (*cp1 != '\0')
                cp1++;
        }
        *cp2 = '\0';
        makeargv();
        c = getcmd(margv[0]);
        if (c == (struct cmd *)-1) {
            fputs("?Ambiguous command.\n", ttyout);
            code = -1;
        } else if (c == 0) {
            fputs("?Invalid command.\n", ttyout);
            code = -1;
        } else if (c->c_conn && !connected) {
            fputs("Not connected.\n", ttyout);
            code = -1;
        } else {
            if (verbose) {
                fputs(line, ttyout);
                putc('\n', ttyout);
            }
            margv[0] = c->c_name;
            (*c->c_handler)(margc, margv);
            if (bell && c->c_bell)
                (void)putc('\007', ttyout);
            (void)strlcpy(line, line2, sizeof(line));
            makeargv();
            argc = margc;
            argv = margv;
        }
        if (cp1 != macros[i].mac_end)
            cp1++;
    }
    if (loopflg && ++count < argc)
        goto TOP;
}
コード例 #15
0
ファイル: main.c プロジェクト: ajinkya93/netbsd-src
int
main(int argc, char **argv)
{
	const char *word;
	bool show_only;
	int score_wfd; /* high score writable file descriptor */
	int score_err = 0; /* hold errno from score file open */
	int maximum = 0;
	int ch, i;

	score_wfd = open(Scorefile, O_RDWR);
	if (score_wfd < 0)
		score_err = errno;
	else if (score_wfd < 3)
		exit(1);

	/* Revoke setgid privileges */
	setgid(getgid());

	show_only = false;
	Num_games = 1;

	while ((ch = getopt(argc, argv, "Aajnrst")) != -1) {
		switch (ch) {
		    case 'A':
			Auto_bot = true;
			break;
		    case 'a':
			Start_level = 4;
			break;
		    case 'j':
			Jump = true;
			break;
		    case 'n':
			Num_games++;
			break;
		    case 'r':
			Real_time = true;
			break;
		    case 's':
			show_only = true;
			break;
		    case 't':
			Teleport = true;
			break;
		    default:
			errx(1,
			    "Usage: robots [-Aajnrst] [maximum] [scorefile]");
			break;
		}
	}

	for (i = optind; i < argc; i++) {
		word = argv[i];
		if (isdigit((unsigned char)word[0])) {
			maximum = atoi(word);
		} else {
			Scorefile = word;
			Max_per_uid = maximum;
			if (score_wfd >= 0)
				close(score_wfd);
			score_wfd = open(Scorefile, O_RDWR);
			if (score_wfd < 0)
				score_err = errno;
#ifdef FANCY
			word = strrchr(Scorefile, '/');
			if (word == NULL)
				word = Scorefile;
			if (strcmp(word, "pattern_roll") == 0)
				Pattern_roll = true;
			else if (strcmp(word, "stand_still") == 0)
				Stand_still = true;
			if (Pattern_roll || Stand_still)
				Teleport = true;
#endif
		}
	}

	if (show_only) {
		show_score();
		exit(0);
		/* NOTREACHED */
	}

	if (score_wfd < 0) {
		errno = score_err;
		warn("%s", Scorefile);
		warnx("High scores will not be recorded!");
		sleep(2);
	}

	if (!initscr())
		errx(0, "couldn't initialize screen");
	signal(SIGINT, quit);
	cbreak();
	noecho();
	nonl();
	if (LINES != Y_SIZE || COLS != X_SIZE) {
		if (LINES < Y_SIZE || COLS < X_SIZE) {
			endwin();
			printf("Need at least a %dx%d screen\n",
			    Y_SIZE, X_SIZE);
			exit(1);
		}
		delwin(stdscr);
		stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
	}

	srandom(time(NULL));
	if (Real_time)
		signal(SIGALRM, move_robots);
	do {
		while (Num_games--) {
			init_field();
			for (Level = Start_level; !Dead; Level++) {
				make_level();
				play_level();
				if (Auto_bot)
					sleep(1);
			}
			move(My_pos.y, My_pos.x);
			printw("AARRrrgghhhh....");
			refresh();
			if (Auto_bot)
				sleep(1);
			score(score_wfd);
			if (Auto_bot)
				sleep(1);
			refresh();
		}
		Num_games = 1;
	} while (!Auto_bot && another());
	quit(0);
	/* NOTREACHED */
	return(0);
}
コード例 #16
0
ファイル: drain.cpp プロジェクト: AlainRoy/htcondor
void
parseArgv( int argc, char* argv[] )
{
	int i;

	my_name = strdup(argv[0]);
	cmd = DRAIN_JOBS;

	for( i=1; i<argc; i++ ) {
		if( match_prefix( argv[i], "-help" ) ) {
			usage(my_name);
		}
		else if( match_prefix( argv[i], "-version" ) ) {
			version();
		}
		else if( is_dash_arg_prefix( argv[i], "verbose", 4 ) ) {
			dash_verbose = 1;
		}
		else if( match_prefix( argv[i], "-pool" ) ) {
			if( i+1 >= argc ) another(argv[i]);
			if (pool) {
				free(pool);
			}
			pool = strdup(argv[++i]);
		}
		else if( match_prefix( argv[i], "-cancel" ) ) {
			cmd = CANCEL_DRAIN_JOBS;
		}
		else if( match_prefix( argv[i], "-fast" ) ) {
			how_fast = DRAIN_FAST;
		}
		else if( match_prefix( argv[i], "-quick" ) ) {
			how_fast = DRAIN_QUICK;
		}
		else if( match_prefix( argv[i], "-graceful" ) ) {
			how_fast = DRAIN_GRACEFUL;
		}
		else if( match_prefix( argv[i], "-resume-on-completion" ) ) {
			resume_on_completion = true;
		}
		else if( match_prefix( argv[i], "-request-id" ) ) {
			if( i+1 >= argc ) another(argv[i]);
			if (cancel_request_id) {
				free(cancel_request_id);
			}
			cancel_request_id = strdup(argv[++i]);
		}
		else if( match_prefix( argv[i], "-check" ) ) {
			if( i+1 >= argc ) another(argv[i]);
			if (draining_check_expr) {
				free(draining_check_expr);
			}
			draining_check_expr = strdup(argv[++i]);
		}
		else if( argv[i][0] != '-' ) {
			break;
		}
		else {
			fprintf(stderr,"ERROR: unexpected argument: %s\n", argv[i]);
			exit(2);
		}
	}

    if( i != argc-1 ) {
        fprintf(stderr,"ERROR: must specify one target machine\n");
        exit(2);
    }

	target = strdup(argv[i]);

	if( cmd == DRAIN_JOBS ) {
		if( cancel_request_id ) {
			fprintf(stderr,"ERROR: -request-id may only be used with -cancel\n");
			exit(2);
		}
	}
	if( cmd == CANCEL_DRAIN_JOBS ) {
		if( draining_check_expr ) {
			fprintf(stderr,"ERROR: -check may not be used with -cancel\n");
			exit(2);
		}
	}
}
コード例 #17
0
ファイル: matchio.cpp プロジェクト: renqHIT/Tale
void writeMatchDOT(
		ostream & s, 
		HashGraph * G1, 
		OrthologInfoList* pOrthinfolist1, 
		int** D1, 
		HashGraph * G2, 
		OrthologInfoList* pOrthinfolist2, 
		int** D2, 
		GraphMatch & M
		)
{
	s<<"graph G {\n";
	//the query graph
	s<<"\tsubgraph cluster0 {\n";
	s<<"\t\tlabel=\"query: "<<G1->getGraphAttrs()->find("name")->second.value<<"\";\n";
	s<<"\t\tcolor=blue;\n";
	
	NodeMappingSet::iterator iter, iter1, iter2;
	
	hash_set<int> qnmset, dbnmset;
	
	for(iter=M.mappings.begin(); iter!=M.mappings.end(); iter++)
	{
		qnmset.insert(iter->source);
		dbnmset.insert(iter->target);
	}
	
	for(int i=0; i<G1->n(); i++)
	{
		if(qnmset.find(i)!=qnmset.end())
			s<< "\t\tq"<<i<<" [label=\""<<G1->getNodeAttrs(i)->find("name")->second.value<<"\" shape=box style=filled fillcolor=lightblue color=blue];\n";
		else
			s<< "\t\tq"<<i<<" [label=\""<<G1->getNodeAttrs(i)->find("name")->second.value<<"\" shape=box];\n";
	}
	
	char arrow[3];
	strcpy(arrow, "--");
	
	//non-important edges
	for(int i=0; i<G1->n(); i++)
		for(int j=i+1; j<G1->n(); j++)
		{
			if(G1->isEdge(i,j) && (qnmset.find(i)==qnmset.end() || qnmset.find(j)==qnmset.end()) )
			{
				s<< "\t\tq"<<i<<" "<<arrow<<" q"<<j<<";\n";
			}
		}
	
	//important edges
	for(iter1=M.mappings.begin(); iter1!=M.mappings.end(); iter1++)
	{
		iter2=iter1;
		iter2++;
		for(; iter2!=M.mappings.end(); iter2++)
		{
			if(G1->isEdge(iter1->source, iter2->source))
			{ 
				if(G2->isEdge(iter1->target, iter2->target))
					s<< "\t\tq"<<iter1->source<<" "<<arrow<<" q"<<iter2->source<<" [style=\"bold\" color=blue];\n";
				else
					s<< "\t\tq"<<iter1->source<<" "<<arrow<<" q"<<iter2->source<<";\n";
			}
		}
	}
	
	s<< "\t}\n";
	//the database graph
		
	s<< "\tsubgraph cluster1 {\n";
	
	s<< "\t\tlabel=\"DB graph: "<<G2->getGraphAttrs()->find("name")->second.value<<"\";\n";
	
	s<< "\t\tcolor=blue;\n";
	
	set<int> vset;
	set<int>::iterator p1, p2;
	for(iter1=M.mappings.begin(); iter1!=M.mappings.end(); iter1++)
	{
		iter2=iter1;
		iter2++;
		for(; iter2!=M.mappings.end(); iter2++)
		{
			int dist=D2[iter1->target][iter2->target];
			getBridge(G2, iter1->target, iter2->target, dist, vset);
		}
	}
	
	set<int> another(vset);

	//db graph vertices
	vector<string> nodes;
	for(iter=M.mappings.begin(); iter!=M.mappings.end(); iter++)
	{
		another.erase(iter->target);
		s<< "\t\tdb"<<iter->target<<" [label=\""<<G2->getNodeAttrs(iter->source)->find("name")->second.value
			<<"\" shape=box style=filled fillcolor=lightblue color=blue];\n";
			
	}

		
	for(p1=another.begin(); p1!=another.end(); p1++)
	{
		s<< "\t\tdb"<< (*p1)<<" [label=\""<<G2->getNodeAttrs(iter->source)->find("name")->second.value<<"\" shape=box];\n";
	}
	//non important edges
	for(p1=vset.begin(); p1!=vset.end(); p1++)
	{
		p2=p1;
		p2++;
		for(; p2!=vset.end(); p2++)
		{
			if( (dbnmset.find((*p1))==dbnmset.end() || dbnmset.find((*p2))==dbnmset.end()) && G2->isEdge((*p1), (*p2)))
			{
				
				s<< "\t\tdb"<<(*p1)<<" "<<arrow<<" db"<<(*p2)<<";\n";
			}
		}
	}
	
	
	//important edges
	for(iter1=M.mappings.begin(); iter1!=M.mappings.end(); iter1++)
	{
		iter2=iter1;
		iter2++;
		for(; iter2!=M.mappings.end(); iter2++)
		{
			if(G2->isEdge(iter1->target, iter2->target))
			{
				if(G1->isEdge(iter1->source,iter2->source))
				{
					s<< "\t\tdb"<<iter1->target<<" "<<arrow<<" db"<<iter2->target<<" [style=\"bold\" color=blue];\n";
				}
				else
				{
					s<< "\t\tdb"<<iter1->target<<" "<<arrow<<" db"<<iter2->target<<";\n";
				}
			}
		}
	}
	
	s<< "\t}\n";

	//emphasize the mapping
	for(iter=M.mappings.begin(); iter!=M.mappings.end(); iter++)
		s<< "\tq"<<iter->source<<" -- db"<<iter->target<<" [color=red]\n";
	s<< "}\n";	
}
コード例 #18
0
ファイル: cod_tool.cpp プロジェクト: AlainRoy/htcondor
void
parseArgv( int  /*argc*/, char* argv[] )
{
	char** tmp = argv;

	for( tmp++; *tmp; tmp++ ) {
		if( (*tmp)[0] != '-' ) {
				// If it doesn't start with '-', skip it
			continue;
		}
		switch( (*tmp)[1] ) {

				// // // // // // // // // // // // // // // //
				// Shared options that make sense to all cmds 
				// // // // // // // // // // // // // // // //

		case 'v':
			if( strncmp("-version", *tmp, strlen(*tmp)) ) {
				invalid( *tmp );
			} 
			version();
			break;

		case 'h':
			if( strncmp("-help", *tmp, strlen(*tmp)) ) {
				invalid( *tmp );
			} 
			usage( my_name, 0);
			break;

		case 'd':
			if( strncmp("-debug", *tmp, strlen(*tmp)) ) {
				invalid( *tmp );
			} 
			dprintf_set_tool_debug("TOOL", 0);
			break;

		case 'a':
			if( cmd != CA_REQUEST_CLAIM ) {
				invalid( *tmp );
			}
			if( strncmp("-address", *tmp, strlen(*tmp)) ) {
				invalid( *tmp );
			} 
			tmp++;
			if( ! (tmp && *tmp) ) {
				another( "-address" );
			}
			if( ! is_valid_sinful(*tmp) ) {
                fprintf( stderr, "%s: '%s' is not a valid address\n",
						 my_name, *tmp );
				exit( 1 );
			}
			if (addr) {
				free(addr);
			}
			addr = strdup( *tmp ); 
			break;

		case 'n':
			if( cmd != CA_REQUEST_CLAIM ) {
				invalid( *tmp );
			}
			if( strncmp("-name", *tmp, strlen(*tmp)) ) {
				invalid( *tmp );
			} 
			tmp++;
			if( ! (tmp && *tmp) ) {
				another( "-name" );
			}
			if (name) {
				free(name);
			}
			name = get_daemon_name( *tmp );
			if( ! name ) {
                fprintf( stderr, "%s: unknown host %s\n", my_name, 
                         get_host_part(*tmp) );
				exit( 1 );
			}
			break;

				// // // // // // // // // // // // // // // //
				// Switches that only make sense to some cmds 
				// // // // // // // // // // // // // // // //

		case 'f':
			if( !((cmd == CA_RELEASE_CLAIM) || 
				  (cmd == CA_DEACTIVATE_CLAIM)) )
			{
				invalid( *tmp );
			}
			if( strncmp("-fast", *tmp, strlen(*tmp)) ) {
				invalid( *tmp );
			} 
			vacate_type = VACATE_FAST;
			break;

		case 'r':
			if( !((cmd == CA_REQUEST_CLAIM) || 
				  (cmd == CA_ACTIVATE_CLAIM)) )
			{
				invalid( *tmp );
			}
			if( strncmp("-requirements", *tmp, strlen(*tmp)) ) {
				invalid( *tmp );
			} 
			tmp++;
			if( ! (tmp && *tmp) ) {
				another( "-requirements" );
			}
			if (requirements) {
				free(requirements);
			}
			requirements = strdup( *tmp );
			break;

		case 'i':
			if( cmd == CA_REQUEST_CLAIM ) {
				invalid( *tmp );
			}
			if( strncmp("-id", *tmp, strlen(*tmp)) ) {
				invalid( *tmp );
			} 
			tmp++;
			if( ! (tmp && *tmp) ) {
				another( "-id" );
			}
			if (claim_id) {
				free(claim_id);
			}
			claim_id = strdup( *tmp );
			break;

		case 'j':
			if( cmd != CA_ACTIVATE_CLAIM ) {
				invalid( *tmp );
			}
			if( strncmp("-jobad", *tmp, strlen(*tmp)) ) {
				invalid( *tmp );
			} 
			tmp++;
			if( ! (tmp && *tmp) ) {
				another( "-jobad" );
			}
			if (jobad_path) {
				free(jobad_path);
			}
			jobad_path = strdup( *tmp );
			break;

		case 'k':
			if( cmd != CA_ACTIVATE_CLAIM ) {
				invalid( *tmp );
			}
			if( strncmp("-keyword", *tmp, strlen(*tmp)) ) {
				invalid( *tmp );
			} 
			tmp++;
			if( ! (tmp && *tmp) ) {
				another( "-keyword" );
			}
			if (job_keyword) {
				free(job_keyword);
			}
			job_keyword = strdup( *tmp );
			break;

				// // // // // // // // // // // // // // // // // // 
				// P and C are complicated, since they are ambiguous
				// in the case of activate, but not others.  so, they
				// have their own methods to make it easier to
				// understand what the hell's going on. :)
				// // // // // // // // // // // // // // // // // //

		case 'l':
			if( strncmp("-lease", *tmp, strlen(*tmp)) == 0 ) {
				if( cmd != CA_REQUEST_CLAIM ) {
					invalid( *tmp );
				}
				tmp++;
				if( ! (tmp && *tmp) ) {
					another( "-lease" );
				}
				lease_time = atoi( *tmp );
			}
			else {
				invalid( *tmp );
			}
			break;

		case 't':
			if( strncmp("-timeout", *tmp, strlen(*tmp)) ) {
				invalid( *tmp );
			} 
			tmp++;
			if( ! (tmp && *tmp) ) {
				another( "-timeout" );
			}
			timeout = atoi( *tmp );
			break;

	    case 'x':
			if( strncmp("-x509proxy", *tmp, strlen(*tmp)) ) {
				invalid( *tmp );
			} 
			tmp++;
			if( ! (tmp && *tmp) ) {
				another( "-x509proxy" );
			}
			proxy_file = *tmp;
			break;

		case 'p':
			parsePOpt( tmp[0], tmp[1] );
			tmp++;
			break;

		case 'c':
			parseCOpt( tmp[0], tmp[1] );
			tmp++;
			break;

		default:
			invalid( *tmp );

		}
	}

		// Now that we're done parsing, make sure it all makes sense

	if( needs_id && ! claim_id ) {
		fprintf( stderr,  "ERROR: You must specify a ClaimID with "
				 "-id for %s\n", my_name );
		usage( my_name );
	}

	if( addr && name ) {
		fprintf( stderr, 
				 "ERROR: You cannot specify both -name and -address\n" );
		usage( my_name );
	}

	if( addr ) {
		target = addr;
	} else if( name ) {
		target = name;
	} else if( claim_id ) {
			// This is the last resort, because claim ids are
			// no longer considered to be the correct place to
			// get the startd's address.
		target = getAddrFromClaimId( claim_id );
	} else { 
			// local startd
		target = NULL;
	}

	if( cmd == CA_ACTIVATE_CLAIM && ! (job_keyword || jobad_path) ) { 
		fprintf( stderr,
				 "ERROR: You must specify -keyword or -jobad for %s\n",
				 my_name );
		usage( my_name );
	}

	if (cmd == DELEGATE_GSI_CRED_STARTD && !proxy_file) {
		proxy_file = get_x509_proxy_filename();
		if (!proxy_file) {
			fprintf( stderr,
					 "\nERROR: can't determine proxy filename to delegate\n" );
			exit(1);
		}
	}

	if( jobad_path ) {
		if( ! strcmp(jobad_path, "-") ) {
			JOBAD_PATH = stdin;
		} else {
			JOBAD_PATH = safe_fopen_wrapper_follow( jobad_path, "r" );
			if( !JOBAD_PATH ) {
				fprintf( stderr,
						 "ERROR: failed to open '%s': errno %d (%s)\n",
						 jobad_path, errno, strerror(errno) );
				exit( 1 );
			}
		}
	}

	if( classad_path ) { 
		CA_PATH = safe_fopen_wrapper_follow( classad_path, "w" );
		if( !CA_PATH ) {
			fprintf( stderr, 
					 "ERROR: failed to open '%s': errno %d (%s)\n",
					 classad_path, errno, strerror(errno) );
			exit( 1 );
		}
	}
}
コード例 #19
0
JobInfoCommunicator*
parseArgs( int argc, char* argv [] )
{
	JobInfoCommunicator* jic = NULL;
	char* job_input_ad = NULL; 
	char* job_output_ad = NULL; 
	char* job_keyword = NULL; 
	int job_cluster = -1;
	int job_proc = -1;
	int job_subproc = -1;
	char* shadow_host = NULL;
	char* job_stdin = NULL;
	char* job_stdout = NULL;
	char* job_stderr = NULL;
	char* schedd_addr = NULL;

	bool warn_multi_keyword = false;
	bool warn_multi_input_ad = false;
	bool warn_multi_output_ad = false;
	bool warn_multi_cluster = false;
	bool warn_multi_proc = false;
	bool warn_multi_subproc = false;
	bool warn_multi_stdin = false;
	bool warn_multi_stdout = false;
	bool warn_multi_stderr = false;

	char *opt, *arg;
	int opt_len;

	char _jobinputad[] = "-job-input-ad";
	char _joboutputad[] = "-job-output-ad";
	char _jobkeyword[] = "-job-keyword";
	char _jobcluster[] = "-job-cluster";
	char _jobproc[] = "-job-proc";
	char _jobsubproc[] = "-job-subproc";
	char _jobstdin[] = "-job-stdin";
	char _jobstdout[] = "-job-stdout";
	char _jobstderr[] = "-job-stderr";
	char _header[] = "-header";
	char _gridshell[] = "-gridshell";
	char _schedd_addr[] = "-schedd-addr";
	char* target = NULL;

	ASSERT( argc >= 2 );
	
	char** tmp = argv;
	for( tmp++; *tmp; tmp++ ) {
		target = NULL;
		opt = tmp[0];
		arg = tmp[1];
		opt_len = strlen( opt );

		if( opt[0] != '-' ) {
				// this must be a hostname...
			free( shadow_host );
			shadow_host = strdup( opt );
			continue;
		}

		if( ! strncmp(opt, _header, opt_len) ) { 
			if( ! arg ) {
				another( _header );
			}
			dprintf_header = strdup( arg );
			DebugId = display_dprintf_header;
			tmp++;	// consume the arg so we don't get confused 
			continue;
		}

		if( ! strncmp(opt, _gridshell, opt_len) ) { 
				// just skip this one, we already processed this in
				// main_pre_dc_init()  
			ASSERT( is_gridshell );
			continue;
		}

		if( ! strncmp(opt, _schedd_addr, opt_len) ) { 
			if( ! arg ) {
				another( _schedd_addr );
			}
			free( schedd_addr );
			schedd_addr = strdup( arg );
			tmp++;	// consume the arg so we don't get confused 
			continue;
		}

		if( strncmp( "-job-", opt, MIN(opt_len,5)) ) {
			invalid( opt );
		}
		if( opt_len < 6 ) {
			ambiguous( opt );
		}
		switch( opt[5] ) {

		case 'c':
			if( strncmp(_jobcluster, opt, opt_len) ) {
				invalid( opt );
			} 
			target = _jobcluster;
			break;

		case 'k':
			if( strncmp(_jobkeyword, opt, opt_len) ) {
				invalid( opt );
			} 
			target = _jobkeyword;
			break;

		case 'i':
			if( strncmp(_jobinputad, opt, opt_len) ) {
				invalid( opt );
			} 
			target = _jobinputad;
			break;

		case 'o':
			if( strncmp(_joboutputad, opt, opt_len) ) {
				invalid( opt );
			} 
			target = _joboutputad;
			break;

		case 'p':
			if( strncmp(_jobproc, opt, opt_len) ) {
				invalid( opt );
			} 
			target = _jobproc;
			break;

		case 's':
			if( !strncmp(_jobsubproc, opt, opt_len) ) {
				target = _jobsubproc;
				break;
			} else if( !strncmp(_jobstdin, opt, opt_len) ) {
				target = _jobstdin;
				break;
			} else if( !strncmp(_jobstdout, opt, opt_len) ) {
				target = _jobstdout;
				break;
			} else if( !strncmp(_jobstderr, opt, opt_len) ) {
				target = _jobstderr;
				break;
			}

			invalid( opt );
			break;

		default:
			invalid( opt );
			break;

		}
			// now, make sure we got the arg
		if( ! arg ) {
			another( target );
		} else {
				// consume it for the purposes of the for() loop
			tmp++;
		}
		if( target == _jobkeyword ) {
				// we can check like that, since we're setting target to
				// point to it, so we don't have to do a strcmp().
			if( job_keyword ) {
				warn_multi_keyword = true;
				free( job_keyword );
			}
			job_keyword = strdup( arg );
		} else if( target == _jobinputad ) {
			if( job_input_ad ) {
				warn_multi_input_ad = true;
				free( job_input_ad );
			}
			job_input_ad = strdup( arg );
		} else if( target == _joboutputad ) {
			if( job_output_ad ) {
				warn_multi_output_ad = true;
				free( job_output_ad );
			}
			job_output_ad = strdup( arg );
		} else if( target == _jobstdin ) {
			if( job_stdin ) {
				warn_multi_stdin = true;
				free( job_stdin );
			}
			job_stdin = strdup( arg );
		} else if( target == _jobstdout ) {
			if( job_stdout ) {
				warn_multi_stdout = true;
				free( job_stdout );
			}
			job_stdout = strdup( arg );
		} else if( target == _jobstderr ) {
			if( job_stderr ) {
				warn_multi_stderr = true;
				free( job_stderr );
			}
			job_stderr = strdup( arg );
		} else if( target == _jobcluster ) {
			if( job_cluster >= 0 ) {
				warn_multi_cluster = true;
			}
			job_cluster = atoi( arg );
			if( job_cluster < 0 ) {
				dprintf( D_ALWAYS, 
						 "ERROR: Invalid value for '%s': \"%s\"\n",
						 _jobcluster, arg );
				usage();
			}
		} else if( target == _jobproc ) {
			if( job_proc >= 0 ) {
				warn_multi_proc = true;
			}
			job_proc = atoi( arg );
			if( job_proc < 0 ) {
				dprintf( D_ALWAYS, 
						 "ERROR: Invalid value for '%s': \"%s\"\n",
						 _jobproc, arg );
				usage();
			}
		} else if( target == _jobsubproc ) {
			if( job_subproc >= 0 ) {
				warn_multi_subproc = true;
			}
			job_subproc = atoi( arg );
			if( job_subproc < 0 ) {
				dprintf( D_ALWAYS, 
						 "ERROR: Invalid value for '%s': \"%s\"\n",
						 _jobsubproc, arg );
				usage();
			}
		} else {
				// Should never get here, since we'll hit usage above
				// if we don't know what target option we're doing...
			EXCEPT( "Programmer error in parsing arguments" );
		}
	}

	if( job_stdin && job_stdin[0] == '-' && ! job_stdin[1] &&
		job_input_ad && job_input_ad[0] == '-' && ! job_input_ad[1] ) { 
		dprintf( D_ALWAYS, "ERROR: Cannot use starter's stdin for both "
				 "the job stdin (%s) and to define the job ClassAd (%s). "
				 "Please do not use '-' for one of these two flags and "
				 "try again.\n", _jobstdin, _jobinputad );
		usage();
	}

	if( job_output_ad && job_output_ad[0] == '-' && ! job_output_ad[1] &&
		job_stdout && job_stdout[0] == '-' && ! job_stdout[1] ) {
		dprintf( D_ALWAYS, "ERROR: Cannot use starter's stdout for both the "
				 "job stdout (%s) and to write the job's output ClassAd "
				 "(%s). Please do not use '-' for one of these two flags "
				 "and try again.\n", _jobstdout, _joboutputad );
		usage();
	}

	if( warn_multi_keyword ) {
		dprintf( D_ALWAYS, "WARNING: "
				 "multiple '%s' options given, using \"%s\"\n",
				 _jobkeyword, job_keyword );
	}
	if( warn_multi_input_ad ) {
		dprintf( D_ALWAYS, "WARNING: "
				 "multiple '%s' options given, using \"%s\"\n",
				 _jobinputad, job_input_ad );
	}
	if( warn_multi_output_ad ) {
		dprintf( D_ALWAYS, "WARNING: "
				 "multiple '%s' options given, using \"%s\"\n",
				 _joboutputad, job_output_ad );
	}
	if( warn_multi_stdin ) {
		dprintf( D_ALWAYS, "WARNING: "
				 "multiple '%s' options given, using \"%s\"\n",
				 _jobstdin, job_stdin );
	}
	if( warn_multi_stdout ) {
		dprintf( D_ALWAYS, "WARNING: "
				 "multiple '%s' options given, using \"%s\"\n",
				 _jobstdout, job_stdout );
	}
	if( warn_multi_stderr ) {
		dprintf( D_ALWAYS, "WARNING: "
				 "multiple '%s' options given, using \"%s\"\n",
				 _jobstderr, job_stderr );
	}
	if( warn_multi_cluster ) {
		dprintf( D_ALWAYS, "WARNING: "
				 "multiple '%s' options given, using \"%d\"\n",
				 _jobcluster, job_cluster );
	}
	if( warn_multi_proc ) {
		dprintf( D_ALWAYS, "WARNING: "
				 "multiple '%s' options given, using \"%d\"\n",
				 _jobproc, job_proc );
	}
	if( warn_multi_subproc ) {
		dprintf( D_ALWAYS, "WARNING: "
				 "multiple '%s' options given, using \"%d\"\n",
				 _jobsubproc, job_subproc );
	}

	if( shadow_host ) {
		if( job_keyword ) {
			dprintf( D_ALWAYS, "You cannot use '%s' and specify a "
					 "shadow host\n", _jobkeyword );
			usage();
		}
		if( job_input_ad ) {
			dprintf( D_ALWAYS, "You cannot use '%s' and specify a "
					 "shadow host\n", _jobinputad );
			usage();
		}
		jic = new JICShadow( shadow_host );
		free( shadow_host );
		shadow_host = NULL;
		free( schedd_addr );
		free( job_output_ad );
		free( job_stdin );
		free( job_stdout );
		free( job_stderr );
		return jic;
	}

	if( ! (job_keyword || job_input_ad) ) {
		dprintf( D_ALWAYS, "ERROR: You must specify either '%s' or '%s'\n",
				 _jobkeyword, _jobinputad ); 
		usage();
	}

		// If the user didn't specify it, use -1 for cluster and/or
		// proc, and the JIC subclasses will know they weren't on the
		// command-line.
	if( schedd_addr ) {
		if( ! job_input_ad ) {
			dprintf( D_ALWAYS, "ERROR: You must specify '%s' with '%s'\n",
					 _jobinputad, _schedd_addr ); 
			usage();
		}
		jic = new JICLocalSchedd( job_input_ad, schedd_addr,
								  job_cluster, job_proc, job_subproc );
	} else if( job_input_ad ) {
		if( job_keyword ) {
			jic = new JICLocalFile( job_input_ad, job_keyword, 
									job_cluster, job_proc, job_subproc );
		} else {
			jic = new JICLocalFile( job_input_ad, job_cluster, job_proc,
									job_subproc );
		}
	} else {
		ASSERT( job_keyword );
		jic = new JICLocalConfig( job_keyword, job_cluster, job_proc, 
								  job_subproc );
	}
	if( job_keyword ) {
		free( job_keyword );
	}
	if( job_input_ad ) {
		free( job_input_ad );
	}
	if( job_output_ad ) {
        jic->setOutputAdFile( job_output_ad );		
		free( job_output_ad );
	}
	if( job_stdin ) {
        jic->setStdin( job_stdin );		
		free( job_stdin );
	}
	if( job_stdout ) {
        jic->setStdout( job_stdout );		
		free( job_stdout );
	}
	if( job_stderr ) {
        jic->setStderr( job_stderr );		
		free( job_stderr );
	}
	if( schedd_addr ) {
		free( schedd_addr );
	}
	return jic;
}