Esempio n. 1
0
int test () {

int test;

#if defined(GETOPT_COMPAT)
test = ((!(long_only)) || argv[optind][1] == '-' || argv[optind][0] == '+' || my_index (optstring, *nextchar) == NULL);
#endif

#if !defined(GETOPT_COMPAT)
test = ((!(long_only)) || argv[optind][1] == '-' || my_index (optstring, *nextchar) == NULL);
#endif

if ((test)){

}
}
Esempio n. 2
0
File: if.c Progetto: choppsv1/ircii
static int
charcount(u_char *string, int what)
{
	int	x = 0;
	u_char	*place = string - 1;

	while ((place = my_index(place + 1, what)))
		x++;
	return x;
}
Esempio n. 3
0
File: if.c Progetto: choppsv1/ircii
void
fec(u_char *command, u_char *args, u_char *subargs)
{
	u_char	*pointer;
	u_char	*list = NULL;
	u_char	*var = NULL;
	u_char	stuff[2];
	int	args_flag = 0;
	unsigned display;
	u_char	*sa, *todo;

	list = next_expr(&args, '(');		/* ) */
	if (list == NULL)
	{
		yell ("FEC: Missing List for /FEC");
		return;
	}

	sa = subargs ? subargs : empty_string();
	list = expand_alias(NULL, list, sa, &args_flag, NULL);
	pointer = list;

	var = next_arg(args, &args);
	args = my_index(args, '{');		/* } */

	if ((todo = next_expr(&args, '{')) == NULL)
	{
		yell ("FE: Missing }");
		return;
	}

	stuff[1] = '\0';

	while (*pointer)
	{
		display = set_display_off();
		stuff[0] = *pointer++;
		add_alias(VAR_ALIAS, var, stuff);
		set_display(display);
		parse_line(NULL, todo, 
		    subargs ? subargs : empty_string(), 0, 0, 0);
	}
	display = set_display_off();
	delete_alias(VAR_ALIAS, var);
	set_display(display);

	new_free(&list);
}
int main(){
  char *strings1[]={"Hallo","hallo","Hallali"};
  char *strings2[]= {"hello","Hallo","Hallo"};
  char chars[] = {'a','l','e'};

  int i;
  for(i = 0; i <= 2; i++){
    if(strcasecmp(strings1[i],strings2[i]) != my_strcasecmp(strings1[i],strings2[i])){
	printf("%s\n %s\n",strings1[i],strings2[i]);
    }else if(index(strings1[i],chars[i]) != my_index(strings1[i],chars[i])){
	 printf("%s\n %c\n",strings1[i],chars[i]);
    }else{
       printf("ALLES SUUUPER!!\n");
    }   
  }


  return 0;
}
Esempio n. 5
0
/*
 * display_msg: handles the displaying of messages from the variety of
 * possible formats that the irc server spits out.  you'd think someone would
 * simplify this 
 */
void
display_msg(u_char *from, u_char **ArgList)
{
	u_char	*ptr;
	u_char	*rest;

	rest = PasteArgs(ArgList, 0);
	if (from && (my_strnicmp(server_get_itsname(parsing_server()), from,
			my_strlen(server_get_itsname(parsing_server()))) == 0))
		from = NULL;
	if ((ptr = (u_char *) my_index(rest, ':')) != NULL)
	{
		*(ptr++) = (u_char) 0;
		if (my_strlen(rest))
		{
			if (from)
				put_it("%s %s: %s (from %s)", numeric_banner(),
					rest, ptr, from);
			else
				put_it("%s %s: %s", numeric_banner(), rest,
					ptr);
		}
		else
		{
			if (from)
				put_it("%s %s (from %s)", numeric_banner(),
					ptr, from);
			else
				put_it("%s %s", numeric_banner(), ptr);
		}
	}
	else
	{
		if (from)
			put_it("%s %s (from %s)", numeric_banner(), rest, from);
		else
			put_it("%s %s", numeric_banner(), rest);
	}
}
Esempio n. 6
0
int
_getopt_internal ( int argc,
     char *const *argv,
     const char *optstring,
     const struct option *longopts,
     int *longind,
     int long_only)

{
  int option_index;

  optarg = 0;

  /* Initialize the internal data when the first call is made.
     Start processing options with ARGV-element 1 (since ARGV-element 0
     is the program name); the sequence of previously skipped
     non-option ARGV-elements is empty.  */

  if (optind == 0)
    {
      first_nonopt = last_nonopt = optind = 1;

      nextchar = NULL;

      /* Determine how to handle the ordering of options and nonoptions.  */

      if (optstring[0] == '-')
	{
	  ordering = RETURN_IN_ORDER;
	  ++optstring;
	}
      else if (optstring[0] == '+')
	{
	  ordering = REQUIRE_ORDER;
	  ++optstring;
	}
   #ifndef _WIN32
      else if (getenv ("POSIXLY_CORRECT") != NULL)
	ordering = REQUIRE_ORDER;
   #endif
      else
	ordering = PERMUTE;
    }

  if (nextchar == NULL || *nextchar == '\0')
    {
      if (ordering == PERMUTE)
	{
	  /* If we have just processed some options following some non-options,
	     exchange them so that the options come first.  */

	  if (first_nonopt != last_nonopt && last_nonopt != optind)
	    exchange ((char **) argv);
	  else if (last_nonopt != optind)
	    first_nonopt = optind;

	  /* Now skip any additional non-options
	     and extend the range of non-options previously skipped.  */

	  while (optind < argc
		 && (argv[optind][0] != '-' || argv[optind][1] == '\0')
#ifdef GETOPT_COMPAT
		 && (longopts == NULL
		     || argv[optind][0] != '+' || argv[optind][1] == '\0')
#endif				/* GETOPT_COMPAT */
		 )
	    optind++;
	  last_nonopt = optind;
	}

      /* Special ARGV-element `--' means premature end of options.
	 Skip it like a null option,
	 then exchange with previous non-options as if it were an option,
	 then skip everything else like a non-option.  */

      if (optind != argc && !strcmp (argv[optind], "--"))
	{
	  optind++;

	  if (first_nonopt != last_nonopt && last_nonopt != optind)
	    exchange ((char **) argv);
	  else if (first_nonopt == last_nonopt)
	    first_nonopt = optind;
	  last_nonopt = argc;

	  optind = argc;
	}

      /* If we have done all the ARGV-elements, stop the scan
	 and back over any non-options that we skipped and permuted.  */

      if (optind == argc)
	{
	  /* Set the next-arg-index to point at the non-options
	     that we previously skipped, so the caller will digest them.  */
	  if (first_nonopt != last_nonopt)
	    optind = first_nonopt;
	  return EOF;
	}

      /* If we have come to a non-option and did not permute it,
	 either stop the scan or describe it to the caller and pass it by.  */

      if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
#ifdef GETOPT_COMPAT
	  && (longopts == NULL
	      || argv[optind][0] != '+' || argv[optind][1] == '\0')
#endif				/* GETOPT_COMPAT */
	  )
	{
	  if (ordering == REQUIRE_ORDER)
	    return EOF;
	  optarg = argv[optind++];
	  return 1;
	}

      /* We have found another option-ARGV-element.
	 Start decoding its characters.  */

      nextchar = (argv[optind] + 1
		  + (longopts != NULL && argv[optind][1] == '-'));
    }

  if (longopts != NULL
      && ((argv[optind][0] == '-'
	   && (argv[optind][1] == '-' || long_only))
#ifdef GETOPT_COMPAT
	  || argv[optind][0] == '+'
#endif				/* GETOPT_COMPAT */
	  ))
    {
      const struct option *p;
      char *s = nextchar;
      int exact = 0;
      int ambig = 0;
      const struct option *pfound = NULL;
      int indfound = 0;

      while (*s && *s != '=')
	s++;

      /* Test all options for either exact match or abbreviated matches.  */
      for (p = longopts, option_index = 0; p->name;
	   p++, option_index++)
	if (!strncmp (p->name, nextchar, s - nextchar))
	  {
	    if (s - nextchar == my_strlen (p->name))
	      {
		/* Exact match found.  */
		pfound = p;
		indfound = option_index;
		exact = 1;
		break;
	      }
	    else if (pfound == NULL)
	      {
		/* First nonexact match found.  */
		pfound = p;
		indfound = option_index;
	      }
	    else
	      /* Second nonexact match found.  */
	      ambig = 1;
	  }

      if (ambig && !exact)
	{
	  if (opterr)
	    fprintf (stderr, "%s: option `%s' is ambiguous\n",
		     argv[0], argv[optind]);
	  nextchar += my_strlen (nextchar);
	  optind++;
	  return BAD_OPTION;
	}

      if (pfound != NULL)
	{
	  option_index = indfound;
	  optind++;
	  if (*s)
	    {
	      /* Don't test has_arg with >, because some C compilers don't
		 allow it to be used on enums.  */
	      if (pfound->has_arg)
		optarg = s + 1;
	      else
		{
		  if (opterr)
		    {
		      if (argv[optind - 1][1] == '-')
			/* --option */
			fprintf (stderr,
				 "%s: option `--%s' doesn't allow an argument\n",
				 argv[0], pfound->name);
		      else
			/* +option or -option */
			fprintf (stderr,
			     "%s: option `%c%s' doesn't allow an argument\n",
			     argv[0], argv[optind - 1][0], pfound->name);
		    }
		  nextchar += my_strlen (nextchar);
		  return BAD_OPTION;
		}
	    }
	  else if (pfound->has_arg == 1)
	    {
	      if (optind < argc)
		optarg = argv[optind++];
	      else
		{
		  if (opterr)
		    fprintf (stderr, "%s: option `%s' requires an argument\n",
			     argv[0], argv[optind - 1]);
		  nextchar += my_strlen (nextchar);
		  return optstring[0] == ':' ? ':' : BAD_OPTION;
		}
	    }
	  nextchar += my_strlen (nextchar);
	  if (longind != NULL)
	    *longind = option_index;
	  if (pfound->flag)
	    {
	      *(pfound->flag) = pfound->val;
	      return 0;
	    }
	  return pfound->val;
	}
      /* Can't find it as a long option.  If this is not getopt_long_only,
	 or the option starts with '--' or is not a valid short
	 option, then it's an error.
	 Otherwise interpret it as a short option.  */
      if (!long_only || argv[optind][1] == '-'
#ifdef GETOPT_COMPAT
	  || argv[optind][0] == '+'
#endif				/* GETOPT_COMPAT */
	  || my_index (optstring, *nextchar) == NULL)
	{
	  if (opterr)
	    {
	      if (argv[optind][1] == '-')
		/* --option */
		fprintf (stderr, "%s: unrecognized option `--%s'\n",
			 argv[0], nextchar);
	      else
		/* +option or -option */
		fprintf (stderr, "%s: unrecognized option `%c%s'\n",
			 argv[0], argv[optind][0], nextchar);
	    }
	  nextchar = (char *) "";
	  optind++;
	  return BAD_OPTION;
	}
    }

  /* Look at and handle the next option-character.  */

  {
    char c = *nextchar++;
    char *temp = my_index (optstring, c);

    /* Increment `optind' when we start to process its last character.  */
    if (*nextchar == '\0')
      ++optind;

    if (temp == NULL || c == ':')
      {
	if (opterr)
	  {
#if 0
	    if (c < 040 || c >= 0177)
	      fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
		       argv[0], c);
	    else
	      fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
#else
	    /* 1003.2 specifies the format of this message.  */
	    fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
#endif
	  }
	optopt = c;
	return BAD_OPTION;
      }
    if (temp[1] == ':')
      {
	if (temp[2] == ':')
	  {
	    /* This is an option that accepts an argument optionally.  */
	    if (*nextchar != '\0')
	      {
		optarg = nextchar;
		optind++;
	      }
	    else
	      optarg = 0;
	    nextchar = NULL;
	  }
	else
	  {
	    /* This is an option that requires an argument.  */
	    if (*nextchar != '\0')
	      {
		optarg = nextchar;
		/* If we end this ARGV-element by taking the rest as an arg,
		   we must advance to the next element now.  */
		optind++;
	      }
	    else if (optind == argc)
	      {
		if (opterr)
		  {
#if 0
		    fprintf (stderr, "%s: option `-%c' requires an argument\n",
			     argv[0], c);
#else
		    /* 1003.2 specifies the format of this message.  */
		    fprintf (stderr, "%s: option requires an argument -- %c\n",
			     argv[0], c);
#endif
		  }
		optopt = c;
		if (optstring[0] == ':')
		  c = ':';
		else
		  c = BAD_OPTION;
	      }
	    else
	      /* We already incremented `optind' once;
		 increment it again when taking next ARGV-elt as argument.  */
	      optarg = argv[optind++];
	    nextchar = NULL;
	  }
      }
    return c;
  }
}
Esempio n. 7
0
int _getopt_internal(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, int long_only)
{

	if (argc < 1)
		return -1;

	optarg = NULL;

	if (optind == 0 || !__getopt_initialized) {
		if (optind == 0)
			optind = 1;			/* Don't scan ARGV[0], the program name.  */
		optstring = _getopt_initialize(argc, argv, optstring);
		__getopt_initialized = 1;
	}

	/* Test whether ARGV[optind] points to a non-option argument.
	   Either it does not have option syntax, or there is an environment flag
	   from the shell indicating it is not an option.  The later information
	   is only used when the used in the GNU libc.  */
#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')

	if (nextchar == NULL || *nextchar == '\0') {
		/* Advance to the next ARGV-element.  */

		/* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
		   moved back by the user (who may also have changed the arguments).  */
		if (last_nonopt > optind)
			last_nonopt = optind;
		if (first_nonopt > optind)
			first_nonopt = optind;

		if (ordering == PERMUTE) {
			/* If we have just processed some options following some non-options,
			   exchange them so that the options come first.  */

			if (first_nonopt != last_nonopt && last_nonopt != optind)
				exchange((char **) argv);
			else if (last_nonopt != optind)
				first_nonopt = optind;

			/* Skip any additional non-options
			   and extend the range of non-options previously skipped.  */

			while (optind < argc && NONOPTION_P)
				optind++;
			last_nonopt = optind;
		}

		/* The special ARGV-element `--' means premature end of options.
		   Skip it like a null option,
		   then exchange with previous non-options as if it were an option,
		   then skip everything else like a non-option.  */

		if (optind != argc && !strcmp(argv[optind], "--")) {
			optind++;

			if (first_nonopt != last_nonopt && last_nonopt != optind)
				exchange((char **) argv);
			else if (first_nonopt == last_nonopt)
				first_nonopt = optind;
			last_nonopt = argc;

			optind = argc;
		}

		/* If we have done all the ARGV-elements, stop the scan
		   and back over any non-options that we skipped and permuted.  */

		if (optind == argc) {
			/* Set the next-arg-index to point at the non-options
			   that we previously skipped, so the caller will digest them.  */
			if (first_nonopt != last_nonopt)
				optind = first_nonopt;
			return -1;
		}

		/* If we have come to a non-option and did not permute it,
		   either stop the scan or describe it to the caller and pass it by.  */

		if (NONOPTION_P) {
			if (ordering == REQUIRE_ORDER)
				return -1;
			optarg = argv[optind++];
			return 1;
		}

		/* We have found another option-ARGV-element.
		   Skip the initial punctuation.  */

		nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-'));
	}

	/* Decode the current option-ARGV-element.  */

	/* Check whether the ARGV-element is a long option.

	   If long_only and the ARGV-element has the form "-f", where f is
	   a valid short option, don't consider it an abbreviated form of
	   a long option that starts with f.  Otherwise there would be no
	   way to give the -f short option.

	   On the other hand, if there's a long option "fubar" and
	   the ARGV-element is "-fu", do consider that an abbreviation of
	   the long option, just like "--fu", and not "-f" with arg "u".

	   This distinction seems to be the most useful approach.  */

	if (longopts != NULL && (argv[optind][1] == '-' || (long_only && (argv[optind][2]
																	  || !my_index(optstring, argv[optind][1]))))) {
		char *nameend;
		const struct option *p;
		const struct option *pfound = NULL;
		int exact = 0;
		int ambig = 0;
		int indfound = -1;
		int option_index;

		for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
			/* Do nothing.  */ ;

		/* Test all long options for either exact match
		   or abbreviated matches.  */
		for (p = longopts, option_index = 0; p->name; p++, option_index++)
			if (!strncmp(p->name, nextchar, nameend - nextchar)) {
				if ((UINT) (nameend - nextchar)
					== (UINT) strlen(p->name)) {
					/* Exact match found.  */
					pfound = p;
					indfound = option_index;
					exact = 1;
					break;
				} else if (pfound == NULL) {
					/* First nonexact match found.  */
					pfound = p;
					indfound = option_index;
				} else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val)
					/* Second or later nonexact match found.  */
					ambig = 1;
			}

		if (ambig && !exact) {
			PRINT_ERROR( "%s: option `%s' is ambiguous\n", argv[0], argv[optind]);
			nextchar += strlen(nextchar);
			optind++;
			optopt = 0;
			return '?';
		}

		if (pfound != NULL) {
			option_index = indfound;
			optind++;
			if (*nameend) {
				/* Don't test has_arg with >, because some C compilers don't
				   allow it to be used on enums.  */
				if (pfound->has_arg)
					optarg = nameend + 1;
				else {
					if (argv[optind - 1][1] == '-') {
						/* --option */
						PRINT_ERROR( "%s: option `--%s' doesn't allow an argument\n", argv[0], pfound->name);
					} else {
						/* +option or -option */
						PRINT_ERROR("%s: option `%c%s' doesn't allow an argument\n", argv[0], argv[optind - 1][0], pfound->name);
					}
					nextchar += strlen(nextchar);

					optopt = pfound->val;
					return '?';
				}
			} else if (pfound->has_arg == 1) {
				if (optind < argc)
					optarg = argv[optind++];
				else {
					PRINT_ERROR("%s: option `%s' requires an argument\n", argv[0], argv[optind - 1]);
					nextchar += strlen(nextchar);
					optopt = pfound->val;
					return optstring[0] == ':' ? ':' : '?';
				}
			}
			nextchar += strlen(nextchar);
			if (longind != NULL)
				*longind = option_index;
			if (pfound->flag) {
				*(pfound->flag) = pfound->val;
				return 0;
			}
			return pfound->val;
		}

		/* Can't find it as a long option.  If this is not getopt_long_only,
		   or the option starts with '--' or is not a valid short
		   option, then it's an error.
		   Otherwise interpret it as a short option.  */
		if (!long_only || argv[optind][1] == '-' || my_index(optstring, *nextchar) == NULL) {
			if (argv[optind][1] == '-') {
				/* --option */
				PRINT_ERROR("%s: unrecognized option `--%s'\n", argv[0], nextchar);
			} else {
				/* +option or -option */
				PRINT_ERROR("%s: unrecognized option `%c%s'\n", argv[0], argv[optind][0], nextchar);
			}
			nextchar = (char *) "";
			optind++;
			optopt = 0;
			return '?';
		}
	}

	/* Look at and handle the next short option-character.  */

	{
		char c = *nextchar++;
		char *temp = my_index(optstring, c);

		/* Increment `optind' when we start to process its last character.  */
		if (*nextchar == '\0')
			++optind;

		if (temp == NULL || c == ':') {
			/* 1003.2 specifies the format of this message.  */
			PRINT_ERROR("%s: illegal option -- %c\n", argv[0], c);
			optopt = c;
			return '?';
		}
#ifdef SPECIAL_TREATMENT_FOR_W
		/* Convenience. Treat POSIX -W foo same as long option --foo */
		if (temp[0] == 'W' && temp[1] == ';') {
			char *nameend;
			const struct option *p;
			const struct option *pfound = NULL;
			int exact = 0;
			int ambig = 0;
			int indfound = 0;
			int option_index;

			/* This is an option that requires an argument.  */
			if (*nextchar != '\0') {
				optarg = nextchar;
				/* If we end this ARGV-element by taking the rest as an arg,
				   we must advance to the next element now.  */
				optind++;
			} else if (optind == argc) {
				/* 1003.2 specifies the format of this message.  */
				PRINT_ERROR("%s: option requires an argument -- %c\n", argv[0], c);
				optopt = c;
				if (optstring[0] == ':')
					c = ':';
				else
					c = '?';
				return c;
			} else
				/* We already incremented `optind' once;
				   increment it again when taking next ARGV-elt as argument.  */
				optarg = argv[optind++];

			/* optarg is now the argument, see if it's in the
			   table of longopts.  */

			for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
				/* Do nothing.  */ ;

			/* Test all long options for either exact match
			   or abbreviated matches.  */
			for (p = longopts, option_index = 0; p->name; p++, option_index++)
				if (!strncmp(p->name, nextchar, nameend - nextchar)) {
					if ((UINT) (nameend - nextchar) == strlen(p->name)) {
						/* Exact match found.  */
						pfound = p;
						indfound = option_index;
						exact = 1;
						break;
					} else if (pfound == NULL) {
						/* First nonexact match found.  */
						pfound = p;
						indfound = option_index;
					} else
						/* Second or later nonexact match found.  */
						ambig = 1;
				}
			if (ambig && !exact) {
				PRINT_ERROR("%s: option `-W %s' is ambiguous\n", argv[0], argv[optind]);
				nextchar += strlen(nextchar);
				optind++;
				return '?';
			}
			if (pfound != NULL) {
				option_index = indfound;
				if (*nameend) {
					/* Don't test has_arg with >, because some C compilers don't
					   allow it to be used on enums.  */
					if (pfound->has_arg)
						optarg = nameend + 1;
					else {
						PRINT_ERROR("%s: option `-W %s' doesn't allow an argument\n", argv[0], pfound->name);
						nextchar += strlen(nextchar);
						return '?';
					}
				} else if (pfound->has_arg == 1) {
					if (optind < argc)
						optarg = argv[optind++];
					else {
						PRINT_ERROR("%s: option `%s' requires an argument\n", argv[0], argv[optind - 1]);
						nextchar += strlen(nextchar);
						return optstring[0] == ':' ? ':' : '?';
					}
				}
				nextchar += strlen(nextchar);
				if (longind != NULL)
					*longind = option_index;
				if (pfound->flag) {
					*(pfound->flag) = pfound->val;
					return 0;
				}
				return pfound->val;
			}
			nextchar = NULL;
			return 'W';			/* Let the application handle it.   */
		}
#endif
		if (temp[1] == ':') {
			if (temp[2] == ':') {
				/* This is an option that accepts an argument optionally.  */
				if (*nextchar != '\0') {
					optarg = nextchar;
					optind++;
				} else
					optarg = NULL;
				nextchar = NULL;
			} else {
				/* This is an option that requires an argument.  */
				if (*nextchar != '\0') {
					optarg = nextchar;
					/* If we end this ARGV-element by taking the rest as an arg,
					   we must advance to the next element now.  */
					optind++;
				} else if (optind == argc) {
					/* 1003.2 specifies the format of this message.  */
					PRINT_ERROR("%s: option requires an argument -- %c\n", argv[0], c);
					optopt = c;
					if (optstring[0] == ':')
						c = ':';
					else
						c = '?';
				} else
					/* We already incremented `optind' once;
					   increment it again when taking next ARGV-elt as argument.  */
					optarg = argv[optind++];
				nextchar = NULL;
			}
		}
		return c;
	}
}
Esempio n. 8
0
File: if.c Progetto: choppsv1/ircii
/*  I suppose someone could make a case that since the
 *  foreach_handler() routine weeds out any for command that doesnt have
 *  two commands, that checking for those 2 commas is a waste.  I suppose.
 */
void
forcmd(u_char *command, u_char *args, u_char *subargs)
{
	u_char	*working = NULL;
	u_char	*commence = NULL;
	u_char	*evaluation = NULL;
	u_char	*lameeval = NULL;
	u_char	*iteration = NULL;
	u_char	*sa = NULL;
	int	argsused = 0;
	u_char	*line = NULL;
	u_char	*commands = NULL;

	/* Get the whole () thing */
	if ((working = next_expr(&args, '(')) == NULL)	/* ) */
	{
		yell("FOR: missing closing parenthesis");
		return;
	}
	malloc_strcpy(&commence, working);

	/* Find the beginning of the second expression */
	evaluation = my_index(commence, ',');
	if (!evaluation)
	{
		yell("FOR: no components!");
		new_free(&commence);
		return;
	}
	do 
		*evaluation++ = '\0';
	while (isspace(*evaluation));

	/* Find the beginning of the third expression */
	iteration = my_index(evaluation, ',');
	if (!iteration)
	{
		yell("FOR: Only two components!");
		new_free(&commence);
		return;
	}
	do 
	{
		*iteration++ = '\0';
	}
	while (isspace(*iteration));

	working = args;
	while (isspace(*working))
		*working++ = '\0';

	if ((working = next_expr(&working, '{')) == NULL)	/* } */
	{
		yell("FOR: badly formed commands");
		new_free(&commence);
		return;
	}

	malloc_strcpy(&commands, working);

	sa = subargs ? subargs : empty_string();
	parse_line(NULL, commence, sa, 0, 0, 0);

	while (1)
	{
		malloc_strcpy(&lameeval, evaluation);
		line = parse_inline(lameeval, sa, &argsused);
		if (*line && *line != '0')
		{
			new_free(&line);
			parse_line(NULL, commands, sa, 0, 0, 0);
			parse_line(NULL, iteration, sa, 0, 0, 0);
		}
		else break;
	}
	new_free(&line);
	new_free(&lameeval);
	new_free(&commence);
	new_free(&commands);
}
Esempio n. 9
0
File: if.c Progetto: choppsv1/ircii
void
fe(u_char *command, u_char *args, u_char *subargs)
{
	u_char	*list = NULL,
		*templist = NULL,
		*placeholder,
		*oldlist = NULL,
		*sa,
		*vars,
		*var[255],
		*word = NULL,
		*todo = NULL;
	int	ind, x, y, count, args_flag;
	unsigned display;

	for (x = 0; x < 255; var[x++] = NULL)
		;

	list = next_expr(&args, '(');	/* ) */
	if (!list)
	{
		yell ("FE: Missing List for /FE");
		return;
	}

	sa = subargs ? subargs : (u_char *) " ";
	malloc_strcpy(&templist, list);
	do 
	{
		malloc_strcpy(&oldlist, templist);
		new_free(&templist);
		templist = expand_alias(NULL, oldlist, sa, &args_flag, NULL);
	} while (my_strcmp(templist, oldlist));

	new_free(&oldlist);

	if (*templist == '\0')
	{
		new_free(&templist);
		return;
	}

	vars = args;
	if (!(args = my_index(args, '{')))		/* } */
	{
		yell ("FE: Missing commands");
		new_free(&templist);
		return;
	}
	*(args-1) = '\0';
	ind = 0;
	while ((var[ind++] = next_arg(vars, &vars)))
	{
		if (ind == 255)
		{
			yell ("FE: Too many variables");
			new_free(&templist);
			return;
		}
	}
	ind = ind ? ind - 1: 0;

	if (!(todo = next_expr(&args, '{')))		/* } { */
	{
		yell ("FE: Missing }");		
		new_free(&templist);
		return;
	}

	count = word_count(templist);
	display = get_display();
	placeholder = templist;
	for (x = 0; x < count;)
	{
		set_display_off();
		for (y = 0; y < ind; y++)
		{
			word = ((x + y) < count)
			    ? next_arg(templist, &templist)
			    : NULL;
			add_alias(VAR_ALIAS, var[y], word);
		}
		set_display(display);
		x += ind;
		parse_line(NULL, todo, 
		    subargs ? subargs : empty_string(), 0, 0, 0);
	}
	set_display_off();
	for (y = 0; y < ind; y++)  {
		delete_alias(VAR_ALIAS, var[y]);
	}
	set_display(display);
	new_free(&placeholder);
}
Esempio n. 10
0
// Scan elements of ARGV (whose length is ARGC) for option characters given in OPTSTRING.
//
// If an element of ARGV starts with '-', and is not exactly "-" or "--", then it is an option
// element.  The characters of this element (aside from the initial '-') are option characters.  If
// `getopt' is called repeatedly, it returns successively each of the option characters from each of
// the option elements.
//
// If `getopt' finds another option character, it returns that character, updating `woptind' and
// `nextchar' so that the next call to `getopt' can resume the scan with the following option
// character or ARGV-element.
//
// If there are no more option characters, `getopt' returns `EOF'. Then `woptind' is the index in
// ARGV of the first ARGV-element that is not an option.  (The ARGV-elements have been permuted so
// that those that are not options now come last.)
//
// OPTSTRING is a string containing the legitimate option characters. If an option character is seen
// that is not listed in OPTSTRING, return '?' after printing an error message.  If you set
// `wopterr' to zero, the error message is suppressed but we still return '?'.
//
// If a char in OPTSTRING is followed by a colon, that means it wants an arg, so the following text
// in the same ARGV-element, or the text of the following ARGV-element, is returned in `optarg'.
// Two colons mean an option that wants an optional arg; if there is text in the current
// ARGV-element, it is returned in `w.woptarg', otherwise `w.woptarg' is set to zero.
//
// If OPTSTRING starts with `-' or `+', it requests different methods of handling the non-option
// ARGV-elements. See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
//
// Long-named options begin with `--' instead of `-'. Their names may be abbreviated as long as the
// abbreviation is unique or is an exact match for some defined option.  If they have an argument,
// it follows the option name in the same ARGV-element, separated from the option name by a `=', or
// else the in next ARGV-element. When `getopt' finds a long-named option, it returns 0 if that
// option's `flag' field is nonzero, the value of the option's `val' field if the `flag' field is
// zero.
//
// LONGOPTS is a vector of `struct option' terminated by an element containing a name which is zero.
//
// LONGIND returns the index in LONGOPT of the long-named option found. It is only valid when a
// long-named option has been found by the most recent call.
//
// If LONG_ONLY is nonzero, '-' as well as '--' can introduce long-named options.
int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *optstring,
                                   const struct woption *longopts, int *longind, int long_only) {
    woptarg = NULL;

    if (woptind == 0) optstring = _wgetopt_initialize(optstring);

    if (nextchar == NULL || *nextchar == '\0') {
        // Advance to the next ARGV-element.
        if (ordering == PERMUTE) {
            // If we have just processed some options following some non-options, exchange them so
            // that the options come first.
            if (first_nonopt != last_nonopt && last_nonopt != woptind)
                exchange(argv);
            else if (last_nonopt != woptind)
                first_nonopt = woptind;

            // Skip any additional non-options and extend the range of non-options previously
            // skipped.
            while (woptind < argc && (argv[woptind][0] != '-' || argv[woptind][1] == '\0'))
                woptind++;
            last_nonopt = woptind;
        }

        // The special ARGV-element `--' means premature end of options. Skip it like a null option,
        // then exchange with previous non-options as if it were an option, then skip everything
        // else like a non-option.
        if (woptind != argc && !wcscmp(argv[woptind], L"--")) {
            woptind++;

            if (first_nonopt != last_nonopt && last_nonopt != woptind)
                exchange(argv);
            else if (first_nonopt == last_nonopt)
                first_nonopt = woptind;
            last_nonopt = argc;

            woptind = argc;
        }

        // If we have done all the ARGV-elements, stop the scan and back over any non-options that
        // we skipped and permuted.

        if (woptind == argc) {
            // Set the next-arg-index to point at the non-options that we previously skipped, so the
            // caller will digest them.
            if (first_nonopt != last_nonopt) woptind = first_nonopt;
            return EOF;
        }

        // If we have come to a non-option and did not permute it, either stop the scan or describe
        // it to the caller and pass it by.
        if ((argv[woptind][0] != '-' || argv[woptind][1] == '\0')) {
            if (ordering == REQUIRE_ORDER) return EOF;
            woptarg = argv[woptind++];
            return 1;
        }

        // We have found another option-ARGV-element. Skip the initial punctuation.
        nextchar = (argv[woptind] + 1 + (longopts != NULL && argv[woptind][1] == '-'));
    }

    // Decode the current option-ARGV-element.

    // Check whether the ARGV-element is a long option.
    //
    // If long_only and the ARGV-element has the form "-f", where f is a valid short option, don't
    // consider it an abbreviated form of a long option that starts with f.  Otherwise there would
    // be no way to give the -f short option.
    //
    // On the other hand, if there's a long option "fubar" and the ARGV-element is "-fu", do
    // consider that an abbreviation of the long option, just like "--fu", and not "-f" with arg
    // "u".
    //
    // This distinction seems to be the most useful approach.
    if (longopts != NULL &&
            (argv[woptind][1] == '-' ||
             (long_only && (argv[woptind][2] || !my_index(optstring, argv[woptind][1]))))) {
        wchar_t *nameend;
        const struct woption *p;
        const struct woption *pfound = NULL;
        int exact = 0;
        int ambig = 0;
        int indfound = 0;  // set to zero by Anton
        int option_index;

        for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
            ;  //!OCLINT(empty body)

        // Test all long options for either exact match or abbreviated matches.
        for (p = longopts, option_index = 0; p->name; p++, option_index++)
            if (!wcsncmp(p->name, nextchar, nameend - nextchar)) {
                if ((unsigned int)(nameend - nextchar) == (unsigned int)wcslen(p->name)) {
                    // Exact match found.
                    pfound = p;
                    indfound = option_index;
                    exact = 1;
                    break;
                } else if (pfound == NULL) {
                    // First nonexact match found.
                    pfound = p;
                    indfound = option_index;
                } else
                    // Second or later nonexact match found.
                    ambig = 1;
            }

        if (ambig && !exact) {
            if (wopterr)
                fwprintf(stderr, _(L"%ls: Option '%ls' is ambiguous\n"), argv[0], argv[woptind]);
            nextchar += wcslen(nextchar);
            woptind++;
            return '?';
        }

        if (pfound != NULL) {
            option_index = indfound;
            woptind++;
            if (*nameend) {
                // Don't test has_arg with >, because some C compilers don't allow it to be used on
                // enums.
                if (pfound->has_arg)
                    woptarg = nameend + 1;
                else {
                    if (wopterr) {
                        if (argv[woptind - 1][1] == '-')  // --option
                            fwprintf(stderr, _(L"%ls: Option '--%ls' doesn't allow an argument\n"),
                                     argv[0], pfound->name);
                        else
                            // +option or -option
                            fwprintf(stderr, _(L"%ls: Option '%lc%ls' doesn't allow an argument\n"),
                                     argv[0], argv[woptind - 1][0], pfound->name);
                    }
                    nextchar += wcslen(nextchar);
                    return '?';
                }
            } else if (pfound->has_arg == 1) {
                if (woptind < argc)
                    woptarg = argv[woptind++];
                else {
                    if (wopterr)
                        fwprintf(stderr, _(L"%ls: Option '%ls' requires an argument\n"), argv[0],
                                 argv[woptind - 1]);
                    nextchar += wcslen(nextchar);
                    return optstring[0] == ':' ? ':' : '?';
                }
            }
            nextchar += wcslen(nextchar);
            if (longind != NULL) *longind = option_index;
            if (pfound->flag) {
                *(pfound->flag) = pfound->val;
                return 0;
            }
            return pfound->val;
        }

        // Can't find it as a long option.  If this is not getopt_long_only, or the option starts
        // with '--' or is not a valid short option, then it's an error. Otherwise interpret it as a
        // short option.
        if (!long_only || argv[woptind][1] == '-' || my_index(optstring, *nextchar) == NULL) {
            if (wopterr) {
                if (argv[woptind][1] == '-')  // --option
                    fwprintf(stderr, _(L"%ls: Unrecognized option '--%ls'\n"), argv[0], nextchar);
                else
                    // +option or -option
                    fwprintf(stderr, _(L"%ls: Unrecognized option '%lc%ls'\n"), argv[0],
                             argv[woptind][0], nextchar);
            }
            nextchar = (wchar_t *)L"";
            woptind++;
            return '?';
        }
    }

    // Look at and handle the next short option-character.
    {
        wchar_t c = *nextchar++;
        wchar_t *temp = const_cast<wchar_t *>(my_index(optstring, c));

        // Increment `woptind' when we start to process its last character.
        if (*nextchar == '\0') ++woptind;

        if (temp == NULL || c == ':') {
            if (wopterr) {
                fwprintf(stderr, _(L"%ls: Invalid option -- %lc\n"), argv[0], (wint_t)c);
            }
            woptopt = c;

            if (*nextchar != '\0') woptind++;

            return '?';
        }
        if (temp[1] == ':') {
            if (temp[2] == ':') {
                // This is an option that accepts an argument optionally.
                if (*nextchar != '\0') {
                    woptarg = nextchar;
                    woptind++;
                } else
                    woptarg = NULL;
                nextchar = NULL;
            } else {
                // This is an option that requires an argument.
                if (*nextchar != '\0') {
                    woptarg = nextchar;
                    // If we end this ARGV-element by taking the rest as an arg, we must advance to
                    // the next element now.
                    woptind++;
                } else if (woptind == argc) {
                    if (wopterr) {
                        // 1003.2 specifies the format of this message.
                        fwprintf(stderr, _(L"%ls: Option requires an argument -- %lc\n"), argv[0],
                                 (wint_t)c);
                    }
                    woptopt = c;
                    if (optstring[0] == ':')
                        c = ':';
                    else
                        c = '?';
                } else
                    // We already incremented `woptind' once; increment it again when taking next
                    // ARGV-elt as argument.
                    woptarg = argv[woptind++];
                nextchar = NULL;
            }
        }
        return c;
    }
}
Esempio n. 11
0
static	int _getopt_internal(	int			 argc,
				char *const	 	*argv,
				const char	 	*optstring,
				const struct option	*longopts,
				int			*longind,
				int			 long_only)
{
    optarg = NULL;

#ifdef _MODULES_DEF_H
#  if WITH_DEBUGGING_INIT
    ErrorLogger( NO_ERR_START, LOC, _proc_getopt_internal, NULL);
#  endif
#endif

    /**
     **  Initialization
     **/

    if( optind == 0) {
	optstring = _getopt_initialize( optstring);
	optind = 1;		/** Don't scan ARGV[0], the program name.    **/
    }

    if( nextchar == NULL || *nextchar == '\0') {

	/**
	 **  Advance to the next ARGV-element.
	 **/

	if( ordering == PERMUTE) {

	    /**
	     **  If we have just processed some options following some non-
	     **  options, exchange them so that the options come first. 
	     **/

	    if( first_nonopt != last_nonopt && last_nonopt != optind)
		exchange( (char **) argv);
	    else if( last_nonopt != optind)
		first_nonopt = optind;

	    /**
	     **  Skip any additional non-options and extend the range of
	     **  non-options previously skipped. 
	     **/

	    while( optind < argc &&
		  ( argv[optind][0] != '-' || argv[optind][1] == '\0'))
		optind++;

	    last_nonopt = optind;
	}

	/**
	 **  The special ARGV-element `--' means premature end of options.
	 **  Skip it like a null option, then exchange with previous non-
	 **  options **  as if it were an option, then skip everything else
	 **  like a non-option. 
	 **/

	if( optind != argc && !strcmp( argv[optind], "--")) {

	    optind++;

	    if( first_nonopt != last_nonopt && last_nonopt != optind)
		exchange((char **) argv);
	    else if( first_nonopt == last_nonopt)
		first_nonopt = optind;

	    last_nonopt = argc;

	    optind = argc;
	}

	/**
	 **  If we have done all the ARGV-elements, stop the scan and back
	 **  over any non-options that we skipped and permuted. 
	 **/

	if( optind == argc) {

	    /**
	     **  Set the next-arg-index to point at the non-options that we
	     **  previously skipped, so the caller will digest them. 
	     **/

	    if( first_nonopt != last_nonopt)
		optind = first_nonopt;

	    return( EOF);
	}

	/**
	 **  If we have come to a non-option and did not permute it,
	 **  either stop the scan or describe it to the caller and pass it by. 
	 **/

	if( argv[optind][0] != '-' || argv[optind][1] == '\0') {

	    if( ordering == REQUIRE_ORDER)
		return EOF;
	    optarg = argv[optind++];

	    return( 1);
	}

	/**
	 **  We have found another option-ARGV-element. 
	 **  Skip the initial punctuation. 
	 **/

	nextchar =( argv[optind] + 1 +
	   ( longopts != NULL && argv[optind][1] == '-'));
    }

    /**
     **    Decode the current option-ARGV-element. 
     **/

    /**
     **  Check whether the ARGV-element is a long option.
     **
     **  If long_only and the ARGV-element has the form "-f", where f is
     **  a valid short option, don't consider it an abbreviated form of
     **  a long option that starts with f.  Otherwise there would be no
     **  way to give the -f short option.
     **
     **  On the other hand, if there's a long option "fubar" and
     **  the ARGV-element is "-fu", do consider that an abbreviation of
     **  the long option, just like "--fu", and not "-f" with arg "u".
     **
     **  This distinction seems to be the most useful approach. 
     **/

    if( longopts != NULL &&( argv[optind][1] == '-'     ||
       (  long_only &&
	 (  argv[optind][2] || !my_index (optstring, argv[optind][1]))))) {

	char *nameend;
	const struct option *p;
	const struct option *pfound = NULL;
	int exact = 0;
	int ambig = 0;
	int indfound;
	int option_index;

	/**
	 **  Skip the remaining characters of the long option upt to its
	 **  names end( End of the option itsself or the '=' sign)
	 **/

	for( nameend = nextchar; *nameend && *nameend != '='; nameend++);

	/**
	 **  Test all long options for either exact match or abbreviated
	 **  matches.
	 **/

	for( p = longopts, option_index = 0; p->name; p++, option_index++) {
	    if( !strncmp( p->name, nextchar, nameend - nextchar)) {

		if( nameend - nextchar == strlen( p->name)) {

		    /**
		     ** Exact match found. 
		     **/

		    pfound = p;
		    indfound = option_index;
		    exact = 1;
		    break;

		} else if( pfound == NULL) {

		    /**
		     **  First nonexact match found.
		     **/

		    pfound = p;
		    indfound = option_index;

		} else

		    /**
		     **  Second or later nonexact match found. 
		     **/

		    ambig = 1;

	    } /** if( !strncmp) **/
	} /** for **/

	/**
	 **  Print an error message for ambigious abbreviations and exit
	 **  on error
	 **/

	if( ambig && !exact) {

	    if( opterr)
#ifdef	_MODULES_DEF_H
		ErrorLogger( ERR_OPT_AMBIG, LOC, argv[optind], NULL);
#else
		fprintf( stderr, _("%s: option `%s' is ambiguous\n"),
		    argv[0], argv[optind]);
#endif

	    nextchar += strlen( nextchar);
	    optind++;
	    return( '?');
	}

	/**
	 **  Longname found ?
	 **/

	if( pfound != NULL) {

	    option_index = indfound;
	    optind++;

	    /**
	     **  *nameend is != NULL if there is a value specified for
	     **  the option: '--option=value' -> *nameend = '='
	     **/

	    if( *nameend) {

		/**
		 **  Don't test has_arg with >, because some C compilers don't
		 **  allow it to be used on enums. 
		 **/

		if( pfound->has_arg)
		    optarg = nameend + 1;

		else {
		    	  
		    if( opterr)

			/**
			 **  ERROR: --option w/o argument
			 **/

			if( argv[optind - 1][1] == '-')
#ifdef	_MODULES_DEF_H
			    ErrorLogger( ERR_OPT_NOARG, LOC, pfound->name, NULL);
#else
			    fprintf( stderr,
				_("%s: option `--%s' doesn't allow an argument\n"),
				argv[0], pfound->name);
#endif

			/**
			 **  ERROR: +option or -option w/o argument
			 **/

			else {
#ifdef	_MODULES_DEF_H
			    char buffer[ BUFSIZ];
			    sprintf( buffer, "%c%s", argv[optind - 1][0], pfound->name);
			    ErrorLogger( ERR_OPT_NOARG, LOC, buffer, NULL);
#else
			    fprintf( stderr,
				_("%s: option `%c%s' doesn't allow an argument\n"),
				argv[0], argv[optind - 1][0], pfound->name);
#endif
			}

		    nextchar += strlen( nextchar);
		    return( '?');
		}

	    /**
	     **  Options with arguments
	     **/

	    } else if( pfound->has_arg == 1) {
Esempio n. 12
0
int _getopt_internal (int argc, char *const *argv, const char *optstring, 
                  const struct option *longopts, int *longind, int long_only)
{
  optarg = NULL;
  
  if (optind == 0)
  {
    optstring = _getopt_initialize (optstring);
    optind = 1;		/* Don't scan ARGV[0], the program name.  */
  }
  
  if (nextchar == NULL || *nextchar == '\0')
  {
    /* Advance to the next ARGV-element.  */
    
    if (ordering == PERMUTE)
    {
    /* If we have just processed some options following some non-options,
	     exchange them so that the options come first.  */
      
      if (first_nonopt != last_nonopt && last_nonopt != optind)
        exchange ((char **) argv);
      else if (last_nonopt != optind)
        first_nonopt = optind;
      
        /* Skip any additional non-options
	     and extend the range of non-options previously skipped.  */
      
      while (optind < argc
        && (argv[optind][0] != '-' || argv[optind][1] == '\0'))
        optind++;
      last_nonopt = optind;
    }
    
    /* The special ARGV-element `--' means premature end of options.
    Skip it like a null option,
    then exchange with previous non-options as if it were an option,
    then skip everything else like a non-option.  */
    
    if (optind != argc && !strcmp (argv[optind], "--"))
    {
      optind++;
      
      if (first_nonopt != last_nonopt && last_nonopt != optind)
        exchange ((char **) argv);
      else if (first_nonopt == last_nonopt)
        first_nonopt = optind;
      last_nonopt = argc;
      
      optind = argc;
    }
    
    /* If we have done all the ARGV-elements, stop the scan
    and back over any non-options that we skipped and permuted.  */
    
    if (optind == argc)
    {
    /* Set the next-arg-index to point at the non-options
	     that we previously skipped, so the caller will digest them.  */
      if (first_nonopt != last_nonopt)
        optind = first_nonopt;
      return EOF;
    }
    
    /* If we have come to a non-option and did not permute it,
    either stop the scan or describe it to the caller and pass it by.  */
    
    if ((argv[optind][0] != '-' || argv[optind][1] == '\0'))
    {
      if (ordering == REQUIRE_ORDER)
        return EOF;
      optarg = argv[optind++];
      return 1;
    }
    
    /* We have found another option-ARGV-element.
    Skip the initial punctuation.  */
    
    nextchar = (argv[optind] + 1
      + (longopts != NULL && argv[optind][1] == '-'));
  }
  
  /* Decode the current option-ARGV-element.  */
  
  /* Check whether the ARGV-element is a long option.
  
    If long_only and the ARGV-element has the form "-f", where f is
    a valid short option, don't consider it an abbreviated form of
    a long option that starts with f.  Otherwise there would be no
    way to give the -f short option.
    
      On the other hand, if there's a long option "fubar" and
      the ARGV-element is "-fu", do consider that an abbreviation of
      the long option, just like "--fu", and not "-f" with arg "u".
      
  This distinction seems to be the most useful approach.  */
  
  if (longopts != NULL
    && (argv[optind][1] == '-'
    || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
  {
    char *nameend;
    const struct option *p;
    const struct option *pfound = NULL;
    int exact = 0;
    int ambig = 0;
    int indfound;
    int option_index;
    
    for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
      /* Do nothing.  */ ;
      
      /* Test all long options for either exact match
      or abbreviated matches.  */
      for (p = longopts, option_index = 0; p->name; p++, option_index++)
        if (!strncmp (p->name, nextchar, nameend - nextchar))
        {
          if ((unsigned int)(nameend - nextchar) == strlen (p->name))
          {
            /* Exact match found.  */
            pfound = p;
            indfound = option_index;
            exact = 1;
            break;
          }
          else if (pfound == NULL)
          {
            /* First nonexact match found.  */
            pfound = p;
            indfound = option_index;
          }
          else
            /* Second or later nonexact match found.  */
            ambig = 1;
        }
        
        if (ambig && !exact)
        {
          if (opterr)
            fprintf (stderr, gettext ("%s: option `%s' is ambiguous\n"),
            argv[0], argv[optind]);
          nextchar += strlen (nextchar);
          optind++;
          return '?';
        }
        
        if (pfound != NULL)
        {
          option_index = indfound;
          optind++;
          if (*nameend)
          {
          /* Don't test has_arg with >, because some C compilers don't
            allow it to be used on enums.  */
            if (pfound->has_arg)
              optarg = nameend + 1;
            else
            {
              if (opterr)
                if (argv[optind - 1][1] == '-')
                  /* --option */
                  fprintf (stderr,
                  gettext ("%s: option `--%s' doesn't allow an argument\n"),
                  argv[0], pfound->name);
                else
                  /* +option or -option */
                  fprintf (stderr,
                  gettext ("%s: option `%c%s' doesn't allow an argument\n"),
                  argv[0], argv[optind - 1][0], pfound->name);
                
                nextchar += strlen (nextchar);
                return '?';
            }
          }
          else if (pfound->has_arg == 1)
          {
            if (optind < argc)
              optarg = argv[optind++];
            else
            {
              if (opterr)
                fprintf (stderr,
                gettext ("%s: option `%s' requires an argument\n"),
                argv[0], argv[optind - 1]);
              nextchar += strlen (nextchar);
              return optstring[0] == ':' ? ':' : '?';
            }
          }
          nextchar += strlen (nextchar);
          if (longind != NULL)
            *longind = option_index;
          if (pfound->flag)
          {
            *(pfound->flag) = pfound->val;
            return 0;
          }
          return pfound->val;
        }
        
        /* Can't find it as a long option.  If this is not getopt_long_only,
        or the option starts with '--' or is not a valid short
        option, then it's an error.
        Otherwise interpret it as a short option.  */
        if (!long_only || argv[optind][1] == '-'
          || my_index (optstring, *nextchar) == NULL)
        {
          if (opterr)
          {
            if (argv[optind][1] == '-')
              /* --option */
              fprintf (stderr, gettext ("%s: unrecognized option `--%s'\n"),
              argv[0], nextchar);
            else
              /* +option or -option */
              fprintf (stderr, gettext ("%s: unrecognized option `%c%s'\n"),
              argv[0], argv[optind][0], nextchar);
          }
          nextchar = (char *) "";
          optind++;
          return '?';
        }
    }
    
    /* Look at and handle the next short option-character.  */
    
  {
    char c = *nextchar++;
    char *temp = my_index (optstring, c);
    
    /* Increment `optind' when we start to process its last character.  */
    if (*nextchar == '\0')
      ++optind;
    
    if (temp == NULL || c == ':')
    {
      if (opterr)
      {
        if (posixly_correct)
          /* 1003.2 specifies the format of this message.  */
          fprintf (stderr, gettext ("%s: illegal option -- %c\n"),
          argv[0], c);
        else
          fprintf (stderr, gettext ("%s: invalid option -- %c\n"),
          argv[0], c);
      }
      optopt = c;
      return '?';
    }
    if (temp[1] == ':')
    {
      if (temp[2] == ':')
      {
        /* This is an option that accepts an argument optionally.  */
        if (*nextchar != '\0')
        {
          optarg = nextchar;
          optind++;
        }
        else
          optarg = NULL;
        nextchar = NULL;
      }
      else
      {
        /* This is an option that requires an argument.  */
        if (*nextchar != '\0')
        {
          optarg = nextchar;
          /* If we end this ARGV-element by taking the rest as an arg,
          we must advance to the next element now.  */
          optind++;
        }
        else if (optind == argc)
        {
          if (opterr)
          {
            /* 1003.2 specifies the format of this message.  */
            fprintf (stderr,
              gettext ("%s: option requires an argument -- %c\n"),
              argv[0], c);
          }
          optopt = c;
          if (optstring[0] == ':')
            c = ':';
          else
            c = '?';
        }
        else
        /* We already incremented `optind' once;
        increment it again when taking next ARGV-elt as argument.  */
        optarg = argv[optind++];
        nextchar = NULL;
      }
    }
    return c;
  }
}