intl/icu/source/tools/toolutil/uoptions.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/tools/toolutil/uoptions.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,141 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 2000-2011, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +*******************************************************************************
    1.11 +*   file name:  uoptions.h
    1.12 +*   encoding:   US-ASCII
    1.13 +*   tab size:   8 (not used)
    1.14 +*   indentation:4
    1.15 +*
    1.16 +*   created on: 2000apr17
    1.17 +*   created by: Markus W. Scherer
    1.18 +*
    1.19 +*   This file provides a command line argument parser.
    1.20 +*/
    1.21 +
    1.22 +#ifndef __UOPTIONS_H__
    1.23 +#define __UOPTIONS_H__
    1.24 +
    1.25 +#include "unicode/utypes.h"
    1.26 +
    1.27 +/* This should usually be called before calling u_parseArgs */
    1.28 +/*#if U_PLATFORM == U_PF_OS390 && (U_CHARSET_FAMILY == U_ASCII_FAMILY)*/
    1.29 +    /* translate args from EBCDIC to ASCII */
    1.30 +/*#   define U_MAIN_INIT_ARGS(argc, argv) __argvtoascii_a(argc, argv)*/
    1.31 +/*#elif defined(XP_MAC_CONSOLE)*/
    1.32 +#if defined(XP_MAC_CONSOLE)
    1.33 +#   include <console.h>
    1.34 +    /* Get the arguments from the GUI, since old Macs don't have a console Window. */
    1.35 +#   define U_MAIN_INIT_ARGS(argc, argv) argc = ccommand((char***)&argv)
    1.36 +#else
    1.37 +    /* Normally we do nothing. */
    1.38 +#   define U_MAIN_INIT_ARGS(argc, argv)
    1.39 +#endif
    1.40 +
    1.41 +
    1.42 +
    1.43 +/* forward declarations for the function declaration */
    1.44 +struct UOption;
    1.45 +typedef struct UOption UOption;
    1.46 +
    1.47 +/* function to be called for a command line option */
    1.48 +typedef int UOptionFn(void *context, UOption *option);
    1.49 +
    1.50 +/* values of UOption.hasArg */
    1.51 +enum { UOPT_NO_ARG, UOPT_REQUIRES_ARG, UOPT_OPTIONAL_ARG };
    1.52 +
    1.53 +/* structure describing a command line option */
    1.54 +struct UOption {
    1.55 +    const char *longName;   /* "foo" for --foo */
    1.56 +    const char *value;      /* output placeholder, will point to the argument string, if any */
    1.57 +    UOptionFn *optionFn;    /* function to be called when this option occurs */
    1.58 +    void *context;          /* parameter for the function */
    1.59 +    char shortName;         /* 'f' for -f */
    1.60 +    char hasArg;            /* enum value: option takes no/requires/may have argument */
    1.61 +    char doesOccur;         /* boolean for "this one occured" */
    1.62 +};
    1.63 +
    1.64 +/* macro for an entry in a declaration of UOption[] */
    1.65 +#define UOPTION_DEF(longName, shortName, hasArg) \
    1.66 +    { longName, NULL, NULL, NULL, shortName, hasArg, 0 }
    1.67 +
    1.68 +/* ICU Tools option definitions */
    1.69 +#define UOPTION_HELP_H              UOPTION_DEF("help", 'h', UOPT_NO_ARG)
    1.70 +#define UOPTION_HELP_QUESTION_MARK  UOPTION_DEF("help", '?', UOPT_NO_ARG)
    1.71 +#define UOPTION_VERBOSE             UOPTION_DEF("verbose", 'v', UOPT_NO_ARG)
    1.72 +#define UOPTION_QUIET               UOPTION_DEF("quiet", 'q', UOPT_NO_ARG)
    1.73 +#define UOPTION_VERSION             UOPTION_DEF("version", 'V', UOPT_NO_ARG)
    1.74 +#define UOPTION_COPYRIGHT           UOPTION_DEF("copyright", 'c', UOPT_NO_ARG)
    1.75 +
    1.76 +#define UOPTION_DESTDIR             UOPTION_DEF("destdir", 'd', UOPT_REQUIRES_ARG)
    1.77 +#define UOPTION_SOURCEDIR           UOPTION_DEF("sourcedir", 's', UOPT_REQUIRES_ARG)
    1.78 +#define UOPTION_ENCODING            UOPTION_DEF("encoding", 'e', UOPT_REQUIRES_ARG)
    1.79 +#define UOPTION_ICUDATADIR          UOPTION_DEF("icudatadir", 'i', UOPT_REQUIRES_ARG)
    1.80 +#define UOPTION_WRITE_JAVA          UOPTION_DEF("write-java", 'j', UOPT_OPTIONAL_ARG)
    1.81 +#define UOPTION_PACKAGE_NAME        UOPTION_DEF("package-name", 'p', UOPT_REQUIRES_ARG)
    1.82 +#define UOPTION_BUNDLE_NAME         UOPTION_DEF("bundle-name", 'b', UOPT_REQUIRES_ARG)
    1.83 +
    1.84 +/**
    1.85 + * C Command line argument parser.
    1.86 + *
    1.87 + * This function takes the argv[argc] command line and a description of
    1.88 + * the program's options in form of an array of UOption structures.
    1.89 + * Each UOption defines a long and a short name (a string and a character)
    1.90 + * for options like "--foo" and "-f".
    1.91 + *
    1.92 + * Each option is marked with whether it does not take an argument,
    1.93 + * requires one, or optionally takes one. The argument may follow in
    1.94 + * the same argv[] entry for short options, or it may always follow
    1.95 + * in the next argv[] entry.
    1.96 + *
    1.97 + * An argument is in the next argv[] entry for both long and short name
    1.98 + * options, except it is taken from directly behind the short name in
    1.99 + * its own argv[] entry if there are characters following the option letter.
   1.100 + * An argument in its own argv[] entry must not begin with a '-'
   1.101 + * unless it is only the '-' itself. There is no restriction of the
   1.102 + * argument format if it is part of the short name options's argv[] entry.
   1.103 + *
   1.104 + * The argument is stored in the value field of the corresponding
   1.105 + * UOption entry, and the doesOccur field is set to 1 if the option
   1.106 + * is found at all.
   1.107 + *
   1.108 + * Short name options without arguments can be collapsed into a single
   1.109 + * argv[] entry. After an option letter takes an argument, following
   1.110 + * letters will be taken as its argument.
   1.111 + *
   1.112 + * If the same option is found several times, then the last
   1.113 + * argument value will be stored in the value field.
   1.114 + *
   1.115 + * For each option, a function can be called. This could be used
   1.116 + * for options that occur multiple times and all arguments are to
   1.117 + * be collected.
   1.118 + *
   1.119 + * All options are removed from the argv[] array itself. If the parser
   1.120 + * is successful, then it returns the number of remaining non-option
   1.121 + * strings (including argv[0]).
   1.122 + * argv[0], the program name, is never read or modified.
   1.123 + *
   1.124 + * An option "--" ends option processing; everything after this
   1.125 + * remains in the argv[] array.
   1.126 + *
   1.127 + * An option string "-" alone is treated as a non-option.
   1.128 + *
   1.129 + * If an option is not recognized or an argument missing, then
   1.130 + * the parser returns with the negative index of the argv[] entry
   1.131 + * where the error was detected.
   1.132 + *
   1.133 + * The OS/400 compiler requires that argv either be "char* argv[]",
   1.134 + * or "const char* const argv[]", and it will not accept, 
   1.135 + * "const char* argv[]" as a definition for main().
   1.136 + *
   1.137 + * @param argv This parameter is modified
   1.138 + * @param options This parameter is modified
   1.139 + */
   1.140 +U_CAPI int U_EXPORT2
   1.141 +u_parseArgs(int argc, char* argv[],
   1.142 +            int optionCount, UOption options[]);
   1.143 +
   1.144 +#endif

mercurial