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