rem: int match, thislen; char *equals;   if (argv[from][1] == '-' && argv[from][2] == 0) {  for (; from < argc; from++)
add: options[from] = -1; priority[from] = 0; if(argv[from][0] == '-')
context: sort_args (int argc, char **argv){  char **newargv = (char **) malloc (sizeof (char *) * argc);  /* For each element of argv,     the corresponding element of options is:     0 for an option that takes no arguments,     1 for an option that takes one argument, etc.     -1 for an ordinary non-option argument.  */  int *options = (int *) malloc (sizeof (int) * argc);  int *priority = (int *) malloc (sizeof (int) * argc);  int to = 1;  int incoming_used = 1;  int from;  int i;  //int end_of_options = argc;  /* Categorize all the options,     and figure out which argv elts are option arguments.  */  for (from = 1; from < argc; from++)    {      options[from] = -1;      priority[from] = 0;      if (argv[from][0] == '-')	{	  int match, thislen;	  char *equals;	  /* If we have found "--", don't consider	     any more arguments as options.  */	  if (argv[from][1] == '-' && argv[from][2] == 0)	    {	      /* Leave the "--", and everything following it, at the end.  */	      for (; from < argc; from++)		{		  priority[from] = -100;		  options[from] = -1;		}	      break;	    }	  /* Look for a match with a known old-fashioned option.  */	  for (i = 0;	       i < (int)(sizeof (standard_args) / sizeof (standard_args[0]));	       i++)	    if (!strcmp (argv[from], standard_args[i].name))	      {		options[from] = standard_args[i].nargs;		priority[from] = standard_args[i].priority;		if (from + standard_args[i].nargs >= argc)		  fprintf (stderr, "Option `%s' requires an argument\n", argv[from]);		from += standard_args[i].nargs;		goto done;	      }	  /* Look for a match with a known long option.	     MATCH is -1 if no match so far, -2 if two or more matches so far,	     >= 0 (the table index of the match) if just one match so far.  */	  if (argv[from][1] == '-')	    {	      match = -1;	      thislen = strlen(argv[from]);	      equals = strchr(argv[from], '=');	      if (equals != 0)		thislen = equals - argv[from];	      for (i = 0;		   i < (int )(sizeof (standard_args) / sizeof (standard_args[0]));		   i++)		if (standard_args[i].longname		    && !strncmp (argv[from], standard_args[i].longname,				 thislen))		  {		    if (match == -1)		      match = i;		    else		      match = -2;		  }	      /* If we found exactly one match, use that.  */	      if (match >= 0)		{		  options[from] = standard_args[match].nargs;		  priority[from] = standard_args[match].priority;		  /* If --OPTION=VALUE syntax is used,		     this option uses just one argv element.  */		  if (equals != 0)		    options[from] = 0;		  if (from + options[from] >= argc)		    fprintf (stderr, "Option `%s' requires an argument\n", argv[from]);		  from += options[from];		}	    }	done: ;	}    }  /* Copy the arguments, in order of decreasing priority, to NEW.  */  newargv[0] = argv[0];  while (incoming_used < argc)    {      int best = -1;      int best_priority = -9999;      /* Find the highest priority remaining option.	 If several have equal priority, take the first of them.  */      for (from = 1; from < argc; from++)	{	  if (argv[from] != 0 && priority[from] > best_priority)	    {	      best_priority = priority[from];	      best = from;	    }	  /* Skip option arguments--they are tied to the options.  */	  if (options[from] > 0)	    from += options[from];	}	          if (best < 0)	abort ();      /* Copy the highest priority remaining option, with its args, to NEW.         Unless it is a duplicate of the previous one.  */      if (! (options[best] == 0	     && ! strcmp (newargv[to - 1], argv[best])))	{	  newargv[to++] = argv[best];	  for (i = 0; i < options[best]; i++)	    newargv[to++] = argv[best + i + 1];	}      incoming_used += 1 + (options[best] > 0 ? options[best] : 0);      /* Clear out this option in ARGV.  */      argv[best] = 0;      for (i = 0; i < options[best]; i++)	argv[best + i + 1] = 0;    }  /* If duplicate options were deleted, fill up extra space with null ptrs.  */  while (to < argc)    newargv[to++] = 0;  memcpy(argv, newargv, sizeof (char *) * argc);  free(options);  free(newargv);  free(priority);}