File: wgetopt.h

package info (click to toggle)
gnustep-examples 1%3A1.4.0%2Bgit20210703-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,164 kB
  • sloc: objc: 17,202; makefile: 56
file content (65 lines) | stat: -rw-r--r-- 1,002 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#if (defined __MINGW__)
/* A simple implementation of getopt() */
static int
indexof(char c, char *string)
{
  int i;

  for (i = 0; i < strlen(string); i++)
    {
      if (string[i] == c)
	{
	  return i;
	}
    }
  return -1;
}

static char *optarg;
static int optind;
static char
getopt(int argc, char **argv, char *options)
{
  static char	*arg;
  int		index;
  char		retval = '\0';

  optarg = NULL;
  if (optind == 0)
    {
      optind = 1;
    }
  while (optind < argc)
    {
      arg = argv[optind];
      if (strlen(arg) == 2)
	{
	  if (arg[0] == '-')
	    {
	      if ((index = indexof(arg[1], options)) != -1)
		{
		  retval = arg[1];
		  if (index < strlen(options))
		    {
		      if (options[index+1] == ':')
			{
			  if (optind < argc-1)
			    {
			      optind++;
			      optarg = argv[optind];
			    }
			  else
			    {
			      return -1; /* ':' given, but argv exhausted */
			    }
			}
		    }
		}
	    }
	}
      optind++;
      return retval;
    }
  return -1;
}
#endif