PageRenderTime 38ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/plgetopt.h

http://firefox-mac-pdf.googlecode.com/
C Header | 156 lines | 35 code | 17 blank | 104 comment | 0 complexity | 12dbe90d6f14e5dfa5283d4ed4ab5526 MD5 | raw file
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is the Netscape Portable Runtime (NSPR).
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998-2000
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. /*
  38. ** File: plgetopt.h
  39. ** Description: utilities to parse argc/argv
  40. */
  41. #if defined(PLGETOPT_H_)
  42. #else
  43. #define PLGETOPT_H_
  44. #include "prtypes.h"
  45. PR_BEGIN_EXTERN_C
  46. typedef struct PLOptionInternal PLOptionInternal;
  47. typedef enum
  48. {
  49. PL_OPT_OK, /* all's well with the option */
  50. PL_OPT_EOL, /* end of options list */
  51. PL_OPT_BAD /* invalid option (and value) */
  52. } PLOptStatus;
  53. typedef struct PLLongOpt
  54. {
  55. const char * longOptName; /* long option name string */
  56. PRIntn longOption; /* value put in PLOptState for this option. */
  57. PRBool valueRequired; /* If option name not followed by '=', */
  58. /* value is the next argument from argv. */
  59. } PLLongOpt;
  60. typedef struct PLOptState
  61. {
  62. char option; /* the name of the option */
  63. const char *value; /* the value of that option | NULL */
  64. PLOptionInternal *internal; /* private processing state */
  65. PRIntn longOption; /* value from PLLongOpt put here */
  66. PRIntn longOptIndex; /* index into caller's array of PLLongOpts */
  67. } PLOptState;
  68. /*
  69. * PL_CreateOptState
  70. *
  71. * The argument "options" points to a string of single-character option
  72. * names. Option names that may have an option argument value must be
  73. * followed immediately by a ':' character.
  74. */
  75. PR_EXTERN(PLOptState*) PL_CreateOptState(
  76. PRIntn argc, char **argv, const char *options);
  77. /*
  78. * PL_CreateLongOptState
  79. *
  80. * Alternative to PL_CreateOptState.
  81. * Allows caller to specify BOTH a string of single-character option names,
  82. * AND an array of structures describing "long" (keyword) option names.
  83. * The array is terminated by a structure in which longOptName is NULL.
  84. * Long option values (arguments) may always be given as "--name=value".
  85. * If PLLongOpt.valueRequired is not PR_FALSE, and the option name was not
  86. * followed by '=' then the next argument from argv is taken as the value.
  87. */
  88. PR_EXTERN(PLOptState*) PL_CreateLongOptState(
  89. PRIntn argc, char **argv, const char *options,
  90. const PLLongOpt *longOpts);
  91. /*
  92. * PL_DestroyOptState
  93. *
  94. * Call this to destroy the PLOptState returned from PL_CreateOptState or
  95. * PL_CreateLongOptState.
  96. */
  97. PR_EXTERN(void) PL_DestroyOptState(PLOptState *opt);
  98. /*
  99. * PL_GetNextOpt
  100. *
  101. * When this function returns PL_OPT_OK,
  102. * - opt->option will hold the single-character option name that was parsed,
  103. * or zero.
  104. * When opt->option is zero, the token parsed was either a "long" (keyword)
  105. * option or a positional parameter.
  106. * For a positional parameter,
  107. * - opt->longOptIndex will contain -1, and
  108. * - opt->value will point to the positional parameter string.
  109. * For a long option name,
  110. * - opt->longOptIndex will contain the non-negative index of the
  111. * PLLongOpt structure in the caller's array of PLLongOpt structures
  112. 8 corresponding to the long option name, and
  113. * For a single-character or long option,
  114. * - opt->longOption will contain the value of the single-character option
  115. * name, or the value of the longOption from the PLLongOpt structure
  116. * for that long option. See notes below.
  117. * - opt->value will point to the argument option string, or will
  118. * be NULL if no argument option string was given.
  119. * When opt->option is non-zero,
  120. * - opt->longOptIndex will be -1
  121. * When this function returns PL_OPT_EOL, or PL_OPT_BAD, the contents of
  122. * opt are undefined.
  123. *
  124. * Notes: It is possible to ignore opt->option, and always look at
  125. * opt->longOption instead. opt->longOption will contain the same value
  126. * as opt->option for single-character option names, and will contain the
  127. * value of longOption from the PLLongOpt structure for long option names.
  128. * This means that it is possible to equivalence long option names to
  129. * single character names by giving the longOption in the PLLongOpt struct
  130. * the same value as the single-character option name.
  131. * For long options that are NOT intended to be equivalent to any single-
  132. * character option, the longOption value should be chosen to not match
  133. * any possible single character name. It might be advisable to choose
  134. * longOption values greater than 0xff for such long options.
  135. */
  136. PR_EXTERN(PLOptStatus) PL_GetNextOpt(PLOptState *opt);
  137. PR_END_EXTERN_C
  138. #endif /* defined(PLGETOPT_H_) */
  139. /* plgetopt.h */