Sign in Join
FPDoc Onlineexperiment

getopts unit

GNU compatible access to command-line options.

This document describes the GETOPTS unit for Free Pascal. It was written for Linux by Michael Van Canneyt. It now also works for all supported platforms.

The getopts unit provides a mechanism to handle command-line options in a structured way, much like the GNU getopts mechanism. It allows you to define the valid options for you program, and the unit will then parse the command-line options for you, and inform you of any errors.

Classes and records

TOptionrecordLong option description record.

Procedures and functions

GetLongOptsfunctionReturn next long option.
GetOptfunctionGet next short option.

Types

OrderingsenumerationCommand-line ordering options.
POptiontypePointer to record.

Constants

EndOfOptionsconstantReturned by , to indicate that there are no more options.
No_ArgumentconstantSpecifies that a long option does not take an argument.
Optional_ArgumentconstantSpecifies that a long option optionally takes an argument.
OptSpecifierconstantCharacter indicating an option on the command-line.
Required_ArgumentconstantSpecifies that a long option needs an argument.

Variables

OptArgvariableSet to the argument of an option, if the option needs one.
OptErrvariableIndicates whether getopt() prints error messages.
OptIndvariableIndex of the current paramstr().
OptOptvariableIn case of an error, contains the character causing the error.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.