• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 *
6 *   Copyright (C) 1999-2016, International Business Machines
7 *   Corporation and others.  All Rights Reserved.
8 *
9 *******************************************************************************
10 *   file name:  gencmn.c
11 *   encoding:   UTF-8
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"
30 #include "unicode/uclean.h"
31 #include "unewdata.h"
32 #include "uoptions.h"
33 #include "putilimp.h"
34 #include "pkg_gencmn.h"
35 
36 static 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),
46 /*9*/ UOPTION_DEF( "entrypoint", 'e', UOPT_REQUIRES_ARG),
47 /*10*/UOPTION_SOURCEDIR,
48 };
49 
50 extern int
main(int argc,char * argv[])51 main(int argc, char* argv[]) {
52     UBool sourceTOC, verbose;
53     uint32_t maxSize;
54 
55     U_MAIN_INIT_ARGS(argc, argv);
56 
57     /* preset then read command line options */
58     argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options);
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     }
68 
69     if(argc<0 || options[0].doesOccur || options[1].doesOccur) {
70         FILE *where = argc < 0 ? stderr : stdout;
71 
72         /*
73          * Broken into chucks because the C89 standard says the minimum
74          * required supported string length is 509 bytes.
75          */
76         fprintf(where,
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);
78         if (options[0].doesOccur || options[1].doesOccur) {
79             fprintf(where, "\n"
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");
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"
91             "\t                            (default: " U_ICUDATA_NAME ")\n"
92             "\t-t, --type filetype         type of the destination file\n"
93             "\t                            (default: \" dat \")\n"
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 
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);
116 
117     return 0;
118 }
119 /*
120  * Hey, Emacs, please set the following:
121  *
122  * Local Variables:
123  * indent-tabs-mode: nil
124  * End:
125  *
126  */
127