Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
AG_GETOPT(3)		    Library Functions Manual		  AG_GETOPT(3)

NAME
       AG_Getopt -- agar incremental argument list parser

SYNOPSIS
       #include	<agar/core.h>

DESCRIPTION
       The AG_Getopt interface parses command-line arguments.

INTERFACE
       int  AG_Getopt(int  argc,  char	* const	argv[],	const char *optstring,
       char **pOptArg, int *pOptInd)

       The AG_Getopt() function	incrementally  parses  command-line  arguments
       argv and	returns	the next known option character.  A known character is
       one that	occurs in the dictionary specified by the optstring argument.

       If  a  character	 is  followed by ":" in	optstring then a string	is ex-
       pected to follow	the option character in	 the  command-line  arguments.
       This string is returned into pOptArg, if	not NULL.

       The  index of the last argument processed by AG_Getopt is returned into
       pOptInd,	if not NULL.

       On  platforms  where  command-line   arguments	are   not   supported,
       AG_Getopt() always returns -1.

EXAMPLES
       The  following  program	uses AG_Getopt() to parse its command-line op-
       tions:

	     static int	debug =	0;

	     int
	     main(int argc, char *argv[])
	     {
		     char *optArg, *filename;
		     int c, optInd, i;

		     while ((c = AG_Getopt(argc, argv, "df:?h",
					   &optArg, &optInd)) != -1) {
			     switch (c)	{
			     case 'd':
				     debug = 1;
				     break;
			     case 'f':
				     filename =	optArg;
				     break;
			     default:
				     printf("Usage: my-program [-d] "
					    "[-f filename] [...]\n")
				     return (1);
			     }
		     }

		     for (i = optInd; i	< argc;	i++)
			     printf("Extra argument: %s\n", argv[i]);

		     return (0);
	     }

SEE ALSO
       AG_Intro(3)

HISTORY
       The AG_Getopt interface first appeared in Agar 1.4.0.

Agar 1.7		       December	21, 2022		  AG_GETOPT(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=AG_Getopt&sektion=3&manpath=FreeBSD+Ports+14.3.quarterly>

home | help