Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | ** File: plgetopt.h |
michael@0 | 8 | ** Description: utilities to parse argc/argv |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #if defined(PLGETOPT_H_) |
michael@0 | 12 | #else |
michael@0 | 13 | #define PLGETOPT_H_ |
michael@0 | 14 | |
michael@0 | 15 | #include "prtypes.h" |
michael@0 | 16 | |
michael@0 | 17 | PR_BEGIN_EXTERN_C |
michael@0 | 18 | |
michael@0 | 19 | typedef struct PLOptionInternal PLOptionInternal; |
michael@0 | 20 | |
michael@0 | 21 | typedef enum |
michael@0 | 22 | { |
michael@0 | 23 | PL_OPT_OK, /* all's well with the option */ |
michael@0 | 24 | PL_OPT_EOL, /* end of options list */ |
michael@0 | 25 | PL_OPT_BAD /* invalid option (and value) */ |
michael@0 | 26 | } PLOptStatus; |
michael@0 | 27 | |
michael@0 | 28 | typedef struct PLLongOpt |
michael@0 | 29 | { |
michael@0 | 30 | const char * longOptName; /* long option name string */ |
michael@0 | 31 | PRIntn longOption; /* value put in PLOptState for this option. */ |
michael@0 | 32 | PRBool valueRequired; /* If option name not followed by '=', */ |
michael@0 | 33 | /* value is the next argument from argv. */ |
michael@0 | 34 | } PLLongOpt; |
michael@0 | 35 | |
michael@0 | 36 | typedef struct PLOptState |
michael@0 | 37 | { |
michael@0 | 38 | char option; /* the name of the option */ |
michael@0 | 39 | const char *value; /* the value of that option | NULL */ |
michael@0 | 40 | |
michael@0 | 41 | PLOptionInternal *internal; /* private processing state */ |
michael@0 | 42 | |
michael@0 | 43 | PRIntn longOption; /* value from PLLongOpt put here */ |
michael@0 | 44 | PRIntn longOptIndex; /* index into caller's array of PLLongOpts */ |
michael@0 | 45 | } PLOptState; |
michael@0 | 46 | |
michael@0 | 47 | /* |
michael@0 | 48 | * PL_CreateOptState |
michael@0 | 49 | * |
michael@0 | 50 | * The argument "options" points to a string of single-character option |
michael@0 | 51 | * names. Option names that may have an option argument value must be |
michael@0 | 52 | * followed immediately by a ':' character. |
michael@0 | 53 | */ |
michael@0 | 54 | PR_EXTERN(PLOptState*) PL_CreateOptState( |
michael@0 | 55 | PRIntn argc, char **argv, const char *options); |
michael@0 | 56 | |
michael@0 | 57 | /* |
michael@0 | 58 | * PL_CreateLongOptState |
michael@0 | 59 | * |
michael@0 | 60 | * Alternative to PL_CreateOptState. |
michael@0 | 61 | * Allows caller to specify BOTH a string of single-character option names, |
michael@0 | 62 | * AND an array of structures describing "long" (keyword) option names. |
michael@0 | 63 | * The array is terminated by a structure in which longOptName is NULL. |
michael@0 | 64 | * Long option values (arguments) may always be given as "--name=value". |
michael@0 | 65 | * If PLLongOpt.valueRequired is not PR_FALSE, and the option name was not |
michael@0 | 66 | * followed by '=' then the next argument from argv is taken as the value. |
michael@0 | 67 | */ |
michael@0 | 68 | PR_EXTERN(PLOptState*) PL_CreateLongOptState( |
michael@0 | 69 | PRIntn argc, char **argv, const char *options, |
michael@0 | 70 | const PLLongOpt *longOpts); |
michael@0 | 71 | /* |
michael@0 | 72 | * PL_DestroyOptState |
michael@0 | 73 | * |
michael@0 | 74 | * Call this to destroy the PLOptState returned from PL_CreateOptState or |
michael@0 | 75 | * PL_CreateLongOptState. |
michael@0 | 76 | */ |
michael@0 | 77 | PR_EXTERN(void) PL_DestroyOptState(PLOptState *opt); |
michael@0 | 78 | |
michael@0 | 79 | /* |
michael@0 | 80 | * PL_GetNextOpt |
michael@0 | 81 | * |
michael@0 | 82 | * When this function returns PL_OPT_OK, |
michael@0 | 83 | * - opt->option will hold the single-character option name that was parsed, |
michael@0 | 84 | * or zero. |
michael@0 | 85 | * When opt->option is zero, the token parsed was either a "long" (keyword) |
michael@0 | 86 | * option or a positional parameter. |
michael@0 | 87 | * For a positional parameter, |
michael@0 | 88 | * - opt->longOptIndex will contain -1, and |
michael@0 | 89 | * - opt->value will point to the positional parameter string. |
michael@0 | 90 | * For a long option name, |
michael@0 | 91 | * - opt->longOptIndex will contain the non-negative index of the |
michael@0 | 92 | * PLLongOpt structure in the caller's array of PLLongOpt structures |
michael@0 | 93 | * corresponding to the long option name, and |
michael@0 | 94 | * For a single-character or long option, |
michael@0 | 95 | * - opt->longOption will contain the value of the single-character option |
michael@0 | 96 | * name, or the value of the longOption from the PLLongOpt structure |
michael@0 | 97 | * for that long option. See notes below. |
michael@0 | 98 | * - opt->value will point to the argument option string, or will |
michael@0 | 99 | * be NULL if option does not require argument. If option requires |
michael@0 | 100 | * argument but it is not provided, PL_OPT_BAD is returned. |
michael@0 | 101 | * When opt->option is non-zero, |
michael@0 | 102 | * - opt->longOptIndex will be -1 |
michael@0 | 103 | * When this function returns PL_OPT_EOL, or PL_OPT_BAD, the contents of |
michael@0 | 104 | * opt are undefined. |
michael@0 | 105 | * |
michael@0 | 106 | * Notes: It is possible to ignore opt->option, and always look at |
michael@0 | 107 | * opt->longOption instead. opt->longOption will contain the same value |
michael@0 | 108 | * as opt->option for single-character option names, and will contain the |
michael@0 | 109 | * value of longOption from the PLLongOpt structure for long option names. |
michael@0 | 110 | * This means that it is possible to equivalence long option names to |
michael@0 | 111 | * single character names by giving the longOption in the PLLongOpt struct |
michael@0 | 112 | * the same value as the single-character option name. |
michael@0 | 113 | * For long options that are NOT intended to be equivalent to any single- |
michael@0 | 114 | * character option, the longOption value should be chosen to not match |
michael@0 | 115 | * any possible single character name. It might be advisable to choose |
michael@0 | 116 | * longOption values greater than 0xff for such long options. |
michael@0 | 117 | */ |
michael@0 | 118 | PR_EXTERN(PLOptStatus) PL_GetNextOpt(PLOptState *opt); |
michael@0 | 119 | |
michael@0 | 120 | PR_END_EXTERN_C |
michael@0 | 121 | |
michael@0 | 122 | #endif /* defined(PLGETOPT_H_) */ |
michael@0 | 123 | |
michael@0 | 124 | /* plgetopt.h */ |
michael@0 | 125 |