]> git.saurik.com Git - apple/icu.git/blob - icuSources/tools/gencmn/gencmn.c
ICU-57163.0.1.tar.gz
[apple/icu.git] / icuSources / tools / gencmn / gencmn.c
1 /*
2 *******************************************************************************
3 *
4 * Copyright (C) 1999-2016, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 *******************************************************************************
8 * file name: gencmn.c
9 * encoding: US-ASCII
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 1999nov01
14 * created by: Markus W. Scherer
15 *
16 * This program reads a list of data files and combines them
17 * into one common, memory-mappable file.
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include "unicode/utypes.h"
23 #include "unicode/putil.h"
24 #include "cmemory.h"
25 #include "cstring.h"
26 #include "filestrm.h"
27 #include "toolutil.h"
28 #include "unicode/uclean.h"
29 #include "unewdata.h"
30 #include "uoptions.h"
31 #include "putilimp.h"
32 #include "pkg_gencmn.h"
33
34 static UOption options[]={
35 /*0*/ UOPTION_HELP_H,
36 /*1*/ UOPTION_HELP_QUESTION_MARK,
37 /*2*/ UOPTION_VERBOSE,
38 /*3*/ UOPTION_COPYRIGHT,
39 /*4*/ UOPTION_DESTDIR,
40 /*5*/ UOPTION_DEF( "comment", 'C', UOPT_REQUIRES_ARG),
41 /*6*/ UOPTION_DEF( "name", 'n', UOPT_REQUIRES_ARG),
42 /*7*/ UOPTION_DEF( "type", 't', UOPT_REQUIRES_ARG),
43 /*8*/ UOPTION_DEF( "source", 'S', UOPT_NO_ARG),
44 /*9*/ UOPTION_DEF( "entrypoint", 'e', UOPT_REQUIRES_ARG),
45 /*10*/UOPTION_SOURCEDIR,
46 };
47
48 extern int
49 main(int argc, char* argv[]) {
50 UBool sourceTOC, verbose;
51 uint32_t maxSize;
52
53 U_MAIN_INIT_ARGS(argc, argv);
54
55 /* preset then read command line options */
56 argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options);
57
58 /* error handling, printing usage message */
59 if(argc<0) {
60 fprintf(stderr,
61 "error in command line argument \"%s\"\n",
62 argv[-argc]);
63 } else if(argc<2) {
64 argc=-1;
65 }
66
67 if(argc<0 || options[0].doesOccur || options[1].doesOccur) {
68 FILE *where = argc < 0 ? stderr : stdout;
69
70 /*
71 * Broken into chucks because the C89 standard says the minimum
72 * required supported string length is 509 bytes.
73 */
74 fprintf(where,
75 "%csage: %s [ -h, -?, --help ] [ -v, --verbose ] [ -c, --copyright ] [ -C, --comment comment ] [ -d, --destdir dir ] [ -n, --name filename ] [ -t, --type filetype ] [ -S, --source tocfile ] [ -e, --entrypoint name ] maxsize listfile\n", argc < 0 ? 'u' : 'U', *argv);
76 if (options[0].doesOccur || options[1].doesOccur) {
77 fprintf(where, "\n"
78 "Read the list file (default: standard input) and create a common data\n"
79 "file from specified files. Omit any files larger than maxsize, if maxsize > 0.\n");
80 fprintf(where, "\n"
81 "Options:\n"
82 "\t-h, -?, --help this usage text\n"
83 "\t-v, --verbose verbose output\n"
84 "\t-c, --copyright include the ICU copyright notice\n"
85 "\t-C, --comment comment include a comment string\n"
86 "\t-d, --destdir dir destination directory\n");
87 fprintf(where,
88 "\t-n, --name filename output filename, without .type extension\n"
89 "\t (default: " U_ICUDATA_NAME ")\n"
90 "\t-t, --type filetype type of the destination file\n"
91 "\t (default: \" dat \")\n"
92 "\t-S, --source tocfile write a .c source file with the table of\n"
93 "\t contents\n"
94 "\t-e, --entrypoint name override the c entrypoint name\n"
95 "\t (default: \"<name>_<type>\")\n");
96 }
97 return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
98 }
99
100 sourceTOC=options[8].doesOccur;
101
102 verbose = options[2].doesOccur;
103
104 maxSize=(uint32_t)uprv_strtoul(argv[1], NULL, 0);
105
106 createCommonDataFile(options[4].doesOccur ? options[4].value : NULL,
107 options[6].doesOccur ? options[6].value : NULL,
108 options[9].doesOccur ? options[9].value : options[6].doesOccur ? options[6].value : NULL,
109 options[7].doesOccur ? options[7].value : NULL,
110 options[10].doesOccur ? options[10].value : NULL,
111 options[3].doesOccur ? U_COPYRIGHT_STRING : options[5].doesOccur ? options[5].value : NULL,
112 argc == 2 ? NULL : argv[2],
113 maxSize, sourceTOC, verbose, NULL);
114
115 return 0;
116 }
117 /*
118 * Hey, Emacs, please set the following:
119 *
120 * Local Variables:
121 * indent-tabs-mode: nil
122 * End:
123 *
124 */