michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 1999-2008, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * file name: gencmn.c michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 1999nov01 michael@0: * created by: Markus W. Scherer michael@0: * michael@0: * This program reads a list of data files and combines them michael@0: * into one common, memory-mappable file. michael@0: */ michael@0: michael@0: #include michael@0: #include michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/putil.h" michael@0: #include "cmemory.h" michael@0: #include "cstring.h" michael@0: #include "filestrm.h" michael@0: #include "toolutil.h" michael@0: #include "unicode/uclean.h" michael@0: #include "unewdata.h" michael@0: #include "uoptions.h" michael@0: #include "putilimp.h" michael@0: #include "pkg_gencmn.h" michael@0: michael@0: static UOption options[]={ michael@0: /*0*/ UOPTION_HELP_H, michael@0: /*1*/ UOPTION_HELP_QUESTION_MARK, michael@0: /*2*/ UOPTION_VERBOSE, michael@0: /*3*/ UOPTION_COPYRIGHT, michael@0: /*4*/ UOPTION_DESTDIR, michael@0: /*5*/ UOPTION_DEF( "comment", 'C', UOPT_REQUIRES_ARG), michael@0: /*6*/ UOPTION_DEF( "name", 'n', UOPT_REQUIRES_ARG), michael@0: /*7*/ UOPTION_DEF( "type", 't', UOPT_REQUIRES_ARG), michael@0: /*8*/ UOPTION_DEF( "source", 'S', UOPT_NO_ARG), michael@0: /*9*/ UOPTION_DEF( "entrypoint", 'e', UOPT_REQUIRES_ARG), michael@0: /*10*/UOPTION_SOURCEDIR, michael@0: }; michael@0: michael@0: extern int michael@0: main(int argc, char* argv[]) { michael@0: UBool sourceTOC, verbose; michael@0: uint32_t maxSize; michael@0: michael@0: U_MAIN_INIT_ARGS(argc, argv); michael@0: michael@0: /* preset then read command line options */ michael@0: argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options); michael@0: michael@0: /* error handling, printing usage message */ michael@0: if(argc<0) { michael@0: fprintf(stderr, michael@0: "error in command line argument \"%s\"\n", michael@0: argv[-argc]); michael@0: } else if(argc<2) { michael@0: argc=-1; michael@0: } michael@0: michael@0: if(argc<0 || options[0].doesOccur || options[1].doesOccur) { michael@0: FILE *where = argc < 0 ? stderr : stdout; michael@0: michael@0: /* michael@0: * Broken into chucks because the C89 standard says the minimum michael@0: * required supported string length is 509 bytes. michael@0: */ michael@0: fprintf(where, michael@0: "%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); michael@0: if (options[0].doesOccur || options[1].doesOccur) { michael@0: fprintf(where, "\n" michael@0: "Read the list file (default: standard input) and create a common data\n" michael@0: "file from specified files. Omit any files larger than maxsize, if maxsize > 0.\n"); michael@0: fprintf(where, "\n" michael@0: "Options:\n" michael@0: "\t-h, -?, --help this usage text\n" michael@0: "\t-v, --verbose verbose output\n" michael@0: "\t-c, --copyright include the ICU copyright notice\n" michael@0: "\t-C, --comment comment include a comment string\n" michael@0: "\t-d, --destdir dir destination directory\n"); michael@0: fprintf(where, michael@0: "\t-n, --name filename output filename, without .type extension\n" michael@0: "\t (default: " U_ICUDATA_NAME ")\n" michael@0: "\t-t, --type filetype type of the destination file\n" michael@0: "\t (default: \" dat \")\n" michael@0: "\t-S, --source tocfile write a .c source file with the table of\n" michael@0: "\t contents\n" michael@0: "\t-e, --entrypoint name override the c entrypoint name\n" michael@0: "\t (default: \"_\")\n"); michael@0: } michael@0: return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; michael@0: } michael@0: michael@0: sourceTOC=options[8].doesOccur; michael@0: michael@0: verbose = options[2].doesOccur; michael@0: michael@0: maxSize=(uint32_t)uprv_strtoul(argv[1], NULL, 0); michael@0: michael@0: createCommonDataFile(options[4].doesOccur ? options[4].value : NULL, michael@0: options[6].doesOccur ? options[6].value : NULL, michael@0: options[9].doesOccur ? options[9].value : options[6].doesOccur ? options[6].value : NULL, michael@0: options[7].doesOccur ? options[7].value : NULL, michael@0: options[10].doesOccur ? options[10].value : NULL, michael@0: options[3].doesOccur ? U_COPYRIGHT_STRING : options[5].doesOccur ? options[5].value : NULL, michael@0: argc == 2 ? NULL : argv[2], michael@0: maxSize, sourceTOC, verbose, NULL); michael@0: michael@0: return 0; michael@0: } michael@0: /* michael@0: * Hey, Emacs, please set the following: michael@0: * michael@0: * Local Variables: michael@0: * indent-tabs-mode: nil michael@0: * End: michael@0: * michael@0: */