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