GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
AG_GETOPT(3) FreeBSD Library Functions Manual AG_GETOPT(3)

AG_Getoptagar incremental argument list parser

#include <agar/core.h>

The AG_Getopt interface parses command-line arguments.

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

The () 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 expected 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, () always returns -1.

The following program uses AG_Getopt() to parse its command-line options:

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);
}

AG_Intro(3)

The AG_Getopt interface first appeared in Agar 1.4.0.

December 21, 2022 Agar 1.7

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.