- if (ac > 1) {
- bad_arg = FALSE;
- for (++av; ac > 1 && *av[0]; av++, ac--)
- if (av[0][0] != '-')
- if (isdigit((unsigned char)av[0][0]))
- Max_per_uid = atoi(av[0]);
- else {
- Scorefile = av[0];
- if (score_wfd >= 0)
- close(score_wfd);
- score_wfd = open(Scorefile, O_RDWR);
- if (score_wfd < 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
- }
- else
- for (sp = &av[0][1]; *sp; sp++)
- switch (*sp) {
- case 'A':
- Auto_bot = TRUE;
- break;
- case 's':
- show_only = TRUE;
- break;
- case 'r':
- Real_time = TRUE;
- break;
- case 'a':
- Start_level = 4;
- break;
- case 'n':
- Num_games++;
- break;
- case 'j':
- Jump = TRUE;
- break;
- case 't':
- Teleport = TRUE;
- break;
-
- default:
- fprintf(stderr, "robots: unknown option: %c\n", *sp);
- bad_arg = TRUE;
- break;
- }
- if (bad_arg) {
- exit(1);
- /* NOTREACHED */
+
+ 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