PageRenderTime 228ms CodeModel.GetById 100ms app.highlight 5ms RepoModel.GetById 116ms 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/*
 39** File:          plgetopt.h
 40** Description:   utilities to parse argc/argv
 41*/
 42
 43#if defined(PLGETOPT_H_)
 44#else
 45#define PLGETOPT_H_
 46
 47#include "prtypes.h"
 48
 49PR_BEGIN_EXTERN_C
 50
 51typedef struct PLOptionInternal PLOptionInternal; 
 52
 53typedef enum
 54{
 55        PL_OPT_OK,              /* all's well with the option */
 56        PL_OPT_EOL,             /* end of options list */
 57        PL_OPT_BAD              /* invalid option (and value) */
 58} PLOptStatus;
 59
 60typedef struct PLLongOpt
 61{
 62    const char * longOptName;   /* long option name string                  */
 63    PRIntn       longOption;    /* value put in PLOptState for this option. */
 64    PRBool       valueRequired; /* If option name not followed by '=',      */
 65                                /* value is the next argument from argv.    */
 66} PLLongOpt;
 67
 68typedef struct PLOptState
 69{
 70    char option;                /* the name of the option */
 71    const char *value;          /* the value of that option | NULL */
 72
 73    PLOptionInternal *internal; /* private processing state */
 74
 75    PRIntn   longOption;        /* value from PLLongOpt put here */
 76    PRIntn   longOptIndex;      /* index into caller's array of PLLongOpts */
 77} PLOptState;
 78
 79/*
 80 * PL_CreateOptState
 81 *
 82 * The argument "options" points to a string of single-character option 
 83 * names.  Option names that may have an option argument value must be 
 84 * followed immediately by a ':' character.  
 85 */
 86PR_EXTERN(PLOptState*) PL_CreateOptState(
 87        PRIntn argc, char **argv, const char *options);
 88
 89/* 
 90 * PL_CreateLongOptState
 91 *
 92 * Alternative to PL_CreateOptState.  
 93 * Allows caller to specify BOTH a string of single-character option names, 
 94 * AND an array of structures describing "long" (keyword) option names.  
 95 * The array is terminated by a structure in which longOptName is NULL.  
 96 * Long option values (arguments) may always be given as "--name=value".
 97 * If PLLongOpt.valueRequired is not PR_FALSE, and the option name was not 
 98 * followed by '=' then the next argument from argv is taken as the value.  
 99 */
100PR_EXTERN(PLOptState*) PL_CreateLongOptState(
101        PRIntn argc, char **argv, const char *options, 
102        const PLLongOpt *longOpts);
103/*
104 * PL_DestroyOptState
105 *
106 * Call this to destroy the PLOptState returned from PL_CreateOptState or
107 * PL_CreateLongOptState.
108 */
109PR_EXTERN(void) PL_DestroyOptState(PLOptState *opt);
110
111/*
112 * PL_GetNextOpt
113 *
114 * When this function returns PL_OPT_OK, 
115 * - opt->option will hold the single-character option name that was parsed, 
116 *   or zero.  
117 * When opt->option is zero, the token parsed was either a "long" (keyword) 
118 *   option or a positional parameter.  
119 * For a positional parameter, 
120 * - opt->longOptIndex will contain -1, and
121 * - opt->value will point to the positional parameter string.
122 * For a long option name, 
123 * - opt->longOptIndex will contain the non-negative index of the 
124 *   PLLongOpt structure in the caller's array of PLLongOpt structures 
125 8   corresponding to the long option name, and 
126 * For a single-character or long option, 
127 * - opt->longOption will contain the value of the single-character option
128 *   name, or the value of the longOption from the PLLongOpt structure
129 *   for that long option.  See notes below.
130 * - opt->value will point to the argument option string, or will
131 *   be NULL if no argument option string was given.
132 * When opt->option is non-zero, 
133 * - opt->longOptIndex will be -1
134 * When this function returns PL_OPT_EOL, or PL_OPT_BAD, the contents of
135 *   opt are undefined.
136 *
137 * Notes: It is possible to ignore opt->option, and always look at 
138 *   opt->longOption instead.  opt->longOption will contain the same value
139 *   as opt->option for single-character option names, and will contain the
140 *   value of longOption from the PLLongOpt structure for long option names.
141 * This means that it is possible to equivalence long option names to 
142 *   single character names by giving the longOption in the PLLongOpt struct
143 *   the same value as the single-character option name.  
144 * For long options that are NOT intended to be equivalent to any single-
145 *   character option, the longOption value should be chosen to not match 
146 *   any possible single character name.  It might be advisable to choose
147 *   longOption values greater than 0xff for such long options.
148 */
149PR_EXTERN(PLOptStatus) PL_GetNextOpt(PLOptState *opt);
150
151PR_END_EXTERN_C
152
153#endif /* defined(PLGETOPT_H_) */
154
155/* plgetopt.h */
156