]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/tools/icupkg/icupkg.cpp
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / tools / icupkg / icupkg.cpp
index 4ae7ac4983eee9c3849a583db578991b5ab1f6fc..ea7be4a90923fd7adda726a46c63928892522b7c 100644 (file)
@@ -1,12 +1,14 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2005-2012, International Business Machines
+*   Copyright (C) 2005-2014, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   file name:  icupkg.cpp
-*   encoding:   US-ASCII
+*   encoding:   UTF-8
 *   tab size:   8 (not used)
 *   indentation:4
 *
@@ -47,8 +49,6 @@ U_NAMESPACE_USE
 
 // general definitions ----------------------------------------------------- ***
 
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
-
 // main() ------------------------------------------------------------------ ***
 
 static void
@@ -59,6 +59,7 @@ printUsage(const char *pname, UBool isHelp) {
             "%csage: %s [-h|-?|--help ] [-tl|-tb|-te] [-c] [-C comment]\n"
             "\t[-a list] [-r list] [-x list] [-l [-o outputListFileName]]\n"
             "\t[-s path] [-d path] [-w] [-m mode]\n"
+            "\t[--auto_toc_prefix] [--auto_toc_prefix_with_type] [--toc_prefix]\n"
             "\tinfilename [outfilename]\n",
             isHelp ? 'U' : 'u', pname);
     if(isHelp) {
@@ -118,6 +119,31 @@ printUsage(const char *pname, UBool isHelp) {
             "\t-m mode or --matchmode mode  set the matching mode for item names with\n"
             "\t                             wildcards\n"
             "\t        noslash: the '*' wildcard does not match the '/' tree separator\n");
+        fprintf(where,
+            "\n"
+            "\tIn the .dat package, the Table of Contents (ToC) contains an entry\n"
+            "\tfor each item of the form prefix/tree/itemname .\n"
+            "\tThe prefix normally matches the package basename, and icupkg checks that,\n"
+            "\tbut this is not necessary when ICU need not find and load the package by filename.\n"
+            "\tICU package names end with the platform type letter, and thus differ\n"
+            "\tbetween platform types. This is not required for user data packages.\n");
+        fprintf(where,
+            "\n"
+            "\t--auto_toc_prefix            automatic ToC entries prefix\n"
+            "\t                             Uses the prefix of the first entry of the\n"
+            "\t                             input package, rather than its basename.\n"
+            "\t                             Requires a non-empty input package.\n"
+            "\t--auto_toc_prefix_with_type  auto_toc_prefix + adjust platform type\n"
+            "\t                             Same as auto_toc_prefix but also checks that\n"
+            "\t                             the prefix ends with the input platform\n"
+            "\t                             type letter, and modifies it to the output\n"
+            "\t                             platform type letter.\n"
+            "\t                At most one of the auto_toc_prefix options\n"
+            "\t                can be used at a time.\n"
+            "\t--toc_prefix prefix          ToC prefix to be used in the output package\n"
+            "\t                             Overrides the package basename\n"
+            "\t                             and --auto_toc_prefix.\n"
+            "\t                             Cannot be combined with --auto_toc_prefix_with_type.\n");
         /*
          * Usage text columns, starting after the initial TAB.
          *      1         2         3         4         5         6         7         8
@@ -150,8 +176,10 @@ printUsage(const char *pname, UBool isHelp) {
             "\t-s path or --sourcedir path  directory for the --add items\n"
             "\t-d path or --destdir path    directory for the --extract items\n"
             "\n"
-            "\t-l or --list                 list the package items to stdout or to output list file\n"
-            "\t                             (after modifying the package)\n");
+            "\t-l or --list                 list the package items\n"
+            "\t                             (after modifying the package)\n"
+            "\t                             to stdout or to output list file\n"
+            "\t-o path or --outlist path    path/filename for the --list output\n");
     }
 }
 
@@ -175,8 +203,11 @@ static UOption options[]={
     UOPTION_DEF("extract", 'x', UOPT_REQUIRES_ARG),
 
     UOPTION_DEF("list", 'l', UOPT_NO_ARG),
-    
-    UOPTION_DEF("outlist", 'o', UOPT_REQUIRES_ARG)
+    UOPTION_DEF("outlist", 'o', UOPT_REQUIRES_ARG),
+
+    UOPTION_DEF("auto_toc_prefix", '\1', UOPT_NO_ARG),
+    UOPTION_DEF("auto_toc_prefix_with_type", '\1', UOPT_NO_ARG),
+    UOPTION_DEF("toc_prefix", '\1', UOPT_REQUIRES_ARG)
 };
 
 enum {
@@ -199,9 +230,12 @@ enum {
     OPT_EXTRACT_LIST,
 
     OPT_LIST_ITEMS,
-    
     OPT_LIST_FILE,
 
+    OPT_AUTO_TOC_PREFIX,
+    OPT_AUTO_TOC_PREFIX_WITH_TYPE,
+    OPT_TOC_PREFIX,
+
     OPT_COUNT
 };
 
@@ -232,16 +266,12 @@ main(int argc, char *argv[]) {
     /* get the program basename */
     pname=findBasename(argv[0]);
 
-    argc=u_parseArgs(argc, argv, LENGTHOF(options), options);
+    argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options);
     isHelp=options[OPT_HELP_H].doesOccur || options[OPT_HELP_QUESTION_MARK].doesOccur;
     if(isHelp) {
         printUsage(pname, TRUE);
         return U_ZERO_ERROR;
     }
-    if(argc<2 || 3<argc) {
-        printUsage(pname, FALSE);
-        return U_ILLEGAL_ARGUMENT_ERROR;
-    }
 
     pkg=new Package;
     if(pkg==NULL) {
@@ -250,6 +280,25 @@ main(int argc, char *argv[]) {
     }
     isModified=FALSE;
 
+    int autoPrefix=0;
+    if(options[OPT_AUTO_TOC_PREFIX].doesOccur) {
+        pkg->setAutoPrefix();
+        ++autoPrefix;
+    }
+    if(options[OPT_AUTO_TOC_PREFIX_WITH_TYPE].doesOccur) {
+        if(options[OPT_TOC_PREFIX].doesOccur) {
+            fprintf(stderr, "icupkg: --auto_toc_prefix_with_type and also --toc_prefix\n");
+            printUsage(pname, FALSE);
+            return U_ILLEGAL_ARGUMENT_ERROR;
+        }
+        pkg->setAutoPrefixWithType();
+        ++autoPrefix;
+    }
+    if(argc<2 || 3<argc || autoPrefix>1) {
+        printUsage(pname, FALSE);
+        return U_ILLEGAL_ARGUMENT_ERROR;
+    }
+
     if(options[OPT_SOURCEDIR].doesOccur) {
         sourcePath=options[OPT_SOURCEDIR].value;
     } else {
@@ -264,6 +313,11 @@ main(int argc, char *argv[]) {
     }
 
     if(0==strcmp(argv[1], "new")) {
+        if(autoPrefix) {
+            fprintf(stderr, "icupkg: --auto_toc_prefix[_with_type] but no input package\n");
+            printUsage(pname, FALSE);
+            return U_ILLEGAL_ARGUMENT_ERROR;
+        }
         inFilename=NULL;
         isPackage=TRUE;
     } else {
@@ -479,6 +533,9 @@ main(int argc, char *argv[]) {
             }
             outFilename=outFilenameBuffer;
         }
+        if(options[OPT_TOC_PREFIX].doesOccur) {
+            pkg->setPrefix(options[OPT_TOC_PREFIX].value);
+        }
         result = writePackageDatFile(outFilename, outComment, NULL, NULL, pkg, outType);
     }