~ubuntu-branches/ubuntu/gutsy/icu/gutsy

« back to all changes in this revision

Viewing changes to source/tools/toolutil/uoptions.h

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

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