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 | /* |
michael@0 | 2 | ******************************************************************************* |
michael@0 | 3 | * |
michael@0 | 4 | * Copyright (C) 2000-2011, International Business Machines |
michael@0 | 5 | * Corporation and others. All Rights Reserved. |
michael@0 | 6 | * |
michael@0 | 7 | ******************************************************************************* |
michael@0 | 8 | * file name: uoptions.h |
michael@0 | 9 | * encoding: US-ASCII |
michael@0 | 10 | * tab size: 8 (not used) |
michael@0 | 11 | * indentation:4 |
michael@0 | 12 | * |
michael@0 | 13 | * created on: 2000apr17 |
michael@0 | 14 | * created by: Markus W. Scherer |
michael@0 | 15 | * |
michael@0 | 16 | * This file provides a command line argument parser. |
michael@0 | 17 | */ |
michael@0 | 18 | |
michael@0 | 19 | #ifndef __UOPTIONS_H__ |
michael@0 | 20 | #define __UOPTIONS_H__ |
michael@0 | 21 | |
michael@0 | 22 | #include "unicode/utypes.h" |
michael@0 | 23 | |
michael@0 | 24 | /* This should usually be called before calling u_parseArgs */ |
michael@0 | 25 | /*#if U_PLATFORM == U_PF_OS390 && (U_CHARSET_FAMILY == U_ASCII_FAMILY)*/ |
michael@0 | 26 | /* translate args from EBCDIC to ASCII */ |
michael@0 | 27 | /*# define U_MAIN_INIT_ARGS(argc, argv) __argvtoascii_a(argc, argv)*/ |
michael@0 | 28 | /*#elif defined(XP_MAC_CONSOLE)*/ |
michael@0 | 29 | #if defined(XP_MAC_CONSOLE) |
michael@0 | 30 | # include <console.h> |
michael@0 | 31 | /* Get the arguments from the GUI, since old Macs don't have a console Window. */ |
michael@0 | 32 | # define U_MAIN_INIT_ARGS(argc, argv) argc = ccommand((char***)&argv) |
michael@0 | 33 | #else |
michael@0 | 34 | /* Normally we do nothing. */ |
michael@0 | 35 | # define U_MAIN_INIT_ARGS(argc, argv) |
michael@0 | 36 | #endif |
michael@0 | 37 | |
michael@0 | 38 | |
michael@0 | 39 | |
michael@0 | 40 | /* forward declarations for the function declaration */ |
michael@0 | 41 | struct UOption; |
michael@0 | 42 | typedef struct UOption UOption; |
michael@0 | 43 | |
michael@0 | 44 | /* function to be called for a command line option */ |
michael@0 | 45 | typedef int UOptionFn(void *context, UOption *option); |
michael@0 | 46 | |
michael@0 | 47 | /* values of UOption.hasArg */ |
michael@0 | 48 | enum { UOPT_NO_ARG, UOPT_REQUIRES_ARG, UOPT_OPTIONAL_ARG }; |
michael@0 | 49 | |
michael@0 | 50 | /* structure describing a command line option */ |
michael@0 | 51 | struct UOption { |
michael@0 | 52 | const char *longName; /* "foo" for --foo */ |
michael@0 | 53 | const char *value; /* output placeholder, will point to the argument string, if any */ |
michael@0 | 54 | UOptionFn *optionFn; /* function to be called when this option occurs */ |
michael@0 | 55 | void *context; /* parameter for the function */ |
michael@0 | 56 | char shortName; /* 'f' for -f */ |
michael@0 | 57 | char hasArg; /* enum value: option takes no/requires/may have argument */ |
michael@0 | 58 | char doesOccur; /* boolean for "this one occured" */ |
michael@0 | 59 | }; |
michael@0 | 60 | |
michael@0 | 61 | /* macro for an entry in a declaration of UOption[] */ |
michael@0 | 62 | #define UOPTION_DEF(longName, shortName, hasArg) \ |
michael@0 | 63 | { longName, NULL, NULL, NULL, shortName, hasArg, 0 } |
michael@0 | 64 | |
michael@0 | 65 | /* ICU Tools option definitions */ |
michael@0 | 66 | #define UOPTION_HELP_H UOPTION_DEF("help", 'h', UOPT_NO_ARG) |
michael@0 | 67 | #define UOPTION_HELP_QUESTION_MARK UOPTION_DEF("help", '?', UOPT_NO_ARG) |
michael@0 | 68 | #define UOPTION_VERBOSE UOPTION_DEF("verbose", 'v', UOPT_NO_ARG) |
michael@0 | 69 | #define UOPTION_QUIET UOPTION_DEF("quiet", 'q', UOPT_NO_ARG) |
michael@0 | 70 | #define UOPTION_VERSION UOPTION_DEF("version", 'V', UOPT_NO_ARG) |
michael@0 | 71 | #define UOPTION_COPYRIGHT UOPTION_DEF("copyright", 'c', UOPT_NO_ARG) |
michael@0 | 72 | |
michael@0 | 73 | #define UOPTION_DESTDIR UOPTION_DEF("destdir", 'd', UOPT_REQUIRES_ARG) |
michael@0 | 74 | #define UOPTION_SOURCEDIR UOPTION_DEF("sourcedir", 's', UOPT_REQUIRES_ARG) |
michael@0 | 75 | #define UOPTION_ENCODING UOPTION_DEF("encoding", 'e', UOPT_REQUIRES_ARG) |
michael@0 | 76 | #define UOPTION_ICUDATADIR UOPTION_DEF("icudatadir", 'i', UOPT_REQUIRES_ARG) |
michael@0 | 77 | #define UOPTION_WRITE_JAVA UOPTION_DEF("write-java", 'j', UOPT_OPTIONAL_ARG) |
michael@0 | 78 | #define UOPTION_PACKAGE_NAME UOPTION_DEF("package-name", 'p', UOPT_REQUIRES_ARG) |
michael@0 | 79 | #define UOPTION_BUNDLE_NAME UOPTION_DEF("bundle-name", 'b', UOPT_REQUIRES_ARG) |
michael@0 | 80 | |
michael@0 | 81 | /** |
michael@0 | 82 | * C Command line argument parser. |
michael@0 | 83 | * |
michael@0 | 84 | * This function takes the argv[argc] command line and a description of |
michael@0 | 85 | * the program's options in form of an array of UOption structures. |
michael@0 | 86 | * Each UOption defines a long and a short name (a string and a character) |
michael@0 | 87 | * for options like "--foo" and "-f". |
michael@0 | 88 | * |
michael@0 | 89 | * Each option is marked with whether it does not take an argument, |
michael@0 | 90 | * requires one, or optionally takes one. The argument may follow in |
michael@0 | 91 | * the same argv[] entry for short options, or it may always follow |
michael@0 | 92 | * in the next argv[] entry. |
michael@0 | 93 | * |
michael@0 | 94 | * An argument is in the next argv[] entry for both long and short name |
michael@0 | 95 | * options, except it is taken from directly behind the short name in |
michael@0 | 96 | * its own argv[] entry if there are characters following the option letter. |
michael@0 | 97 | * An argument in its own argv[] entry must not begin with a '-' |
michael@0 | 98 | * unless it is only the '-' itself. There is no restriction of the |
michael@0 | 99 | * argument format if it is part of the short name options's argv[] entry. |
michael@0 | 100 | * |
michael@0 | 101 | * The argument is stored in the value field of the corresponding |
michael@0 | 102 | * UOption entry, and the doesOccur field is set to 1 if the option |
michael@0 | 103 | * is found at all. |
michael@0 | 104 | * |
michael@0 | 105 | * Short name options without arguments can be collapsed into a single |
michael@0 | 106 | * argv[] entry. After an option letter takes an argument, following |
michael@0 | 107 | * letters will be taken as its argument. |
michael@0 | 108 | * |
michael@0 | 109 | * If the same option is found several times, then the last |
michael@0 | 110 | * argument value will be stored in the value field. |
michael@0 | 111 | * |
michael@0 | 112 | * For each option, a function can be called. This could be used |
michael@0 | 113 | * for options that occur multiple times and all arguments are to |
michael@0 | 114 | * be collected. |
michael@0 | 115 | * |
michael@0 | 116 | * All options are removed from the argv[] array itself. If the parser |
michael@0 | 117 | * is successful, then it returns the number of remaining non-option |
michael@0 | 118 | * strings (including argv[0]). |
michael@0 | 119 | * argv[0], the program name, is never read or modified. |
michael@0 | 120 | * |
michael@0 | 121 | * An option "--" ends option processing; everything after this |
michael@0 | 122 | * remains in the argv[] array. |
michael@0 | 123 | * |
michael@0 | 124 | * An option string "-" alone is treated as a non-option. |
michael@0 | 125 | * |
michael@0 | 126 | * If an option is not recognized or an argument missing, then |
michael@0 | 127 | * the parser returns with the negative index of the argv[] entry |
michael@0 | 128 | * where the error was detected. |
michael@0 | 129 | * |
michael@0 | 130 | * The OS/400 compiler requires that argv either be "char* argv[]", |
michael@0 | 131 | * or "const char* const argv[]", and it will not accept, |
michael@0 | 132 | * "const char* argv[]" as a definition for main(). |
michael@0 | 133 | * |
michael@0 | 134 | * @param argv This parameter is modified |
michael@0 | 135 | * @param options This parameter is modified |
michael@0 | 136 | */ |
michael@0 | 137 | U_CAPI int U_EXPORT2 |
michael@0 | 138 | u_parseArgs(int argc, char* argv[], |
michael@0 | 139 | int optionCount, UOption options[]); |
michael@0 | 140 | |
michael@0 | 141 | #endif |