getopts.xml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?xml version="1.0" encoding="ISO8859-1"?>
  2. <fpdoc-descriptions>
  3. <!--
  4. $Id$
  5. This file is part of the FPC documentation.
  6. Copyright (C) 1997, by Michael Van Canneyt
  7. The FPC documentation is free text; you can redistribute it and/or
  8. modify it under the terms of the GNU Library General Public License as
  9. published by the Free Software Foundation; either version 2 of the
  10. License, or (at your option) any later version.
  11. The FPC Documentation is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with the FPC documentation; see the file COPYING.LIB. If not,
  17. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18. Boston, MA 02111-1307, USA.
  19. -->
  20. <package name="rtl">
  21. <module name="getopts">
  22. <short>GNU compatible access to command-line options.</short>
  23. <!-- \FPCexampledir{optex} -->
  24. <descr>
  25. <p>
  26. This document describes the GETOPTS unit for Free Pascal. It was written for
  27. linux by Michael Van Canneyt. It now also works for all supported platforms.
  28. </p>
  29. <p>
  30. The getopts unit provides a mechanism to handle command-line options in
  31. a structured way, much like the GNU getopts mechanism. It allows you to
  32. define the valid options for you program, and the unit will then parse the
  33. command-line options for you, and inform you of any errors.
  34. </p>
  35. </descr>
  36. <element name="OptSpecifier">
  37. <short>Character indicating an option on the command-line.</short>
  38. </element>
  39. <element name="Orderings">
  40. <short>Command-line ordering options.</short>
  41. </element>
  42. <element name="Orderings.require_order">
  43. <short>Don't touch the ordering of the command-line options</short>
  44. </element>
  45. <element name="Orderings.permute">
  46. <short>Change command-line options.</short>
  47. </element>
  48. <element name="Orderings.return_in_order">
  49. <short>Return options in the correct order.</short>
  50. </element>
  51. <element name="No_Argument">
  52. <short>Specifies that a long option does not take an argument.</short>
  53. </element>
  54. <element name="Required_Argument">
  55. <short>Specifies that a long option needs an argument.</short>
  56. </element>
  57. <element name="Optional_Argument">
  58. <short>Specifies that a long option optionally takes an argument.</short>
  59. </element>
  60. <element name="EndOfOptions">
  61. <short>Returned by <link id="getopt"/>,<link id="getlongopts"/> to indicate that
  62. there are no more options.</short>
  63. </element>
  64. <element name="TOption">
  65. <short>Long option description record</short>
  66. <descr>
  67. The <var>TOption</var> type is used to communicate the long options to
  68. <link id="GetLongOpts"/>.
  69. The <var>Name</var> field is the name of the option. <var>Has_arg</var>
  70. specifies if the option
  71. wants an argument, <var>Flag</var> is a pointer to a <var>char</var>, which
  72. is set to
  73. <var>Value</var>, if it is non-<var>nil</var>.
  74. </descr>
  75. </element>
  76. <element name="TOption.Name">
  77. <short>Long option name</short>
  78. </element>
  79. <element name="TOption.Has_arg">
  80. <short>Does the option have arguments (values)</short>
  81. </element>
  82. <element name="TOption.Flag">
  83. <short>Flag</short>
  84. </element>
  85. <element name="TOption.Value">
  86. <short>Value to return when option is encountered</short>
  87. </element>
  88. <element name="POption">
  89. <short>Pointer to <link id="TOption"/> record.</short>
  90. </element>
  91. <element name="OptArg">
  92. <short>Set to the argument of an option, if the option needs one.</short>
  93. </element>
  94. <element name="Optind">
  95. <short>Index of the current <var>paramstr()</var>.</short>
  96. <descr>
  97. when all options have been processed, <var>optind</var> is the index of the first
  98. non-option parameter. This is a read-only variable. Note that it can become
  99. equal to <var>paramcount+1</var>.
  100. </descr>
  101. </element>
  102. <element name="OptErr">
  103. <short>Indicates whether <var>getopt()</var> prints error messages.</short>
  104. </element>
  105. <element name="OptOpt">
  106. <short>In case of an error, contains the character causing the error.</short>
  107. </element>
  108. <element name="GetLongOpts">
  109. <short>Return next long option.</short>
  110. <descr>
  111. <p>
  112. Returns the next option found on the command-line, taking into account long
  113. options as well. If no more options are
  114. found, returns <var>EndOfOptions</var>. If the option requires an argument, it is
  115. returned in the <var>OptArg</var> variable.
  116. </p>
  117. <p>
  118. <var>ShortOptions</var> is a string containing all possible one-letter options.
  119. (see <link id="Getopt"/> for its description and use)
  120. <var>LongOpts</var> is a pointer to the first element of an array of <var>Option</var>
  121. records, the last of which needs a name of zero length.
  122. </p>
  123. <p>
  124. The function tries to match the names even partially (i.e. <var>--app</var>
  125. will match e.g. the <var>append</var> option), but will report an error in case of
  126. ambiguity.
  127. If the option needs an argument, set <var>Has_arg</var> to
  128. <var>Required_argument</var>, if the option optionally has an argument, set
  129. <var>Has_arg</var> to <var>Optional_argument</var>. If the option needs no argument,
  130. set <var>Has_arg</var> to zero.
  131. </p>
  132. <p>
  133. Required arguments can be specified in two ways :
  134. </p>
  135. <ol>
  136. <li>Pasted to the option : <var>--option=value</var></li>
  137. <li>As a separate argument : <var>--option value</var></li>
  138. </ol>
  139. <p>
  140. Optional arguments can only be specified through the first method.
  141. </p>
  142. </descr>
  143. <errors>
  144. see <link id="Getopt"/>.
  145. </errors>
  146. <seealso>
  147. <link id="Getopt"/>
  148. </seealso>
  149. </element>
  150. <element name="Getopt">
  151. <short>Get next short option.</short>
  152. <descr>
  153. <p>
  154. Returns the next option found on the command-line. If no more options are
  155. found, returns <var>EndOfOptions</var>. If the option requires an argument, it is
  156. returned in the <var>OptArg</var> variable.
  157. </p>
  158. <p>
  159. <var>ShortOptions</var> is a string containing all possible one-letter options.
  160. If a letter is followed by a colon (:), then that option needs an argument.
  161. If a letter is followed by 2 colons, the option has an optional argument.
  162. If the first character of <var>shortoptions</var> is a <var>'+'</var> then options following a non-option are
  163. regarded as non-options (standard Unix behavior). If it is a <var>'-'</var>,
  164. then all non-options are treated as arguments of a option with character
  165. <var>#0</var>. This is useful for applications that require their options in
  166. the exact order as they appear on the command-line.
  167. If the first character of <var>shortoptions</var> is none of the above, options
  168. and non-options are permuted, so all non-options are behind all options.
  169. This allows options and non-options to be in random order on the command
  170. line.
  171. </p>
  172. </descr>
  173. <errors>
  174. Errors are reported through giving back a <var>'?'</var> character. <var>OptOpt</var>
  175. then gives the character which caused the error. If <var>OptErr</var> is
  176. <var>True</var> then getopt prints an error-message to <var>stdout</var>.
  177. </errors>
  178. <seealso>
  179. <link id="GetLongOpts"/>
  180. </seealso>
  181. <example file="optex/optex"/>
  182. </element>
  183. </module>
  184. </package>
  185. </fpdoc-descriptions>