0N/A/*
2362N/A * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage build.tools.javazic;
0N/A
0N/Aimport java.util.ArrayList;
0N/Aimport java.util.Iterator;
0N/Aimport java.util.List;
0N/A
0N/A/**
0N/A * Main class for the javazic time zone data compiler.
0N/A *
0N/A * @since 1.4
0N/A */
0N/Apublic class Main {
0N/A
0N/A private static boolean verbose = false;
0N/A static boolean outputDoc = false;
0N/A
0N/A private List<String> ziFiles = new ArrayList<String>();
0N/A private static String zoneNamesFile = null;
0N/A private static String versionName = "unknown";
0N/A private static String outputDir = "zoneinfo";
0N/A private static String mapFile = null;
0N/A
0N/A /**
0N/A * Parses the specified arguments and sets up the variables.
0N/A * @param argv the arguments
0N/A */
0N/A void processArgs(String[] argv) {
0N/A for (int i = 0; i < argv.length; i++) {
0N/A String arg = argv[i];
0N/A if (arg.startsWith("-h")) {
0N/A usage();
0N/A System.exit(0);
0N/A } else if (arg.equals("-d")) {
0N/A outputDir = argv[++i];
0N/A } else if (arg.equals("-v")) {
0N/A verbose = true;
0N/A } else if (arg.equals("-V")) {
0N/A versionName = argv[++i];
0N/A } else if (arg.equals("-doc")) {
0N/A outputDoc = true;
0N/A } else if (arg.equals("-map")) {
0N/A outputDoc = true;
0N/A mapFile = argv[++i];
0N/A } else if (arg.equals("-f")) {
0N/A zoneNamesFile = argv[++i];
0N/A } else if (arg.equals("-S")) {
0N/A try {
0N/A Zoneinfo.setYear(Integer.parseInt(argv[++i]));
0N/A } catch (Exception e) {
0N/A error("invalid year: " + argv[i]);
0N/A usage();
0N/A System.exit(1);
0N/A }
0N/A } else {
0N/A boolean isStartYear = arg.equals("-s");
0N/A if (isStartYear || arg.equals("-e")) {
0N/A try {
0N/A int year = Integer.parseInt(argv[++i]);
0N/A if (isStartYear) {
0N/A Zoneinfo.setStartYear(year);
0N/A } else {
0N/A Zoneinfo.setEndYear(year);
0N/A }
0N/A } catch (Exception e) {
0N/A error("invalid year: " + argv[i]);
0N/A usage();
0N/A System.exit(1);
0N/A }
0N/A } else {
0N/A // the rest of args are zoneinfo source files
0N/A while (i < argv.length) {
0N/A ziFiles.add(argv[i++]);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Parses zoneinfo source files
0N/A */
0N/A int compile() {
0N/A int nFiles = ziFiles.size();
0N/A int status = 0;
0N/A Mappings maps = new Mappings();
0N/A BackEnd backend = BackEnd.getBackEnd();
0N/A
0N/A for (int i = 0; i < nFiles; i++) {
0N/A Zoneinfo frontend = Zoneinfo.parse(ziFiles.get(i));
0N/A
0N/A for (String key : frontend.getZones().keySet()) {
0N/A info(key);
0N/A
0N/A Timezone tz = frontend.phase2(key);
0N/A status |= backend.processZoneinfo(tz);
0N/A }
0N/A
0N/A maps.add(frontend);
0N/A }
0N/A
0N/A // special code for dealing with the conflicting name "MET"
0N/A Zone.addMET();
0N/A
0N/A maps.resolve();
0N/A
0N/A status |= backend.generateSrc(maps);
0N/A
0N/A return status;
0N/A }
0N/A
0N/A public static void main(String[] argv) {
0N/A Main zic = new Main();
0N/A
0N/A /*
0N/A * Parse args
0N/A */
0N/A zic.processArgs(argv);
0N/A
0N/A /*
0N/A * Read target zone names
0N/A */
0N/A if (zoneNamesFile != null) {
0N/A Zone.readZoneNames(zoneNamesFile);
0N/A }
0N/A
0N/A int status = zic.compile();
0N/A
0N/A System.exit(status);
0N/A }
0N/A
0N/A void usage() {
0N/A System.err.println("Usage: javazic [options] file...\n"+
0N/A " -f namefile file containing zone names\n"+
0N/A " to be generated (ie, generating subset)\n"+
0N/A " -d dir output directory\n"+
0N/A " -v verbose\n"+
0N/A " -V datavers specifies the tzdata version string\n"+
0N/A " (eg, \"tzdata2000g\")"+
0N/A " -S year output only SimleTimeZone data of that year\n"+
0N/A " -s year start year (default: 1900)\n"+
0N/A " -e year end year (default: 2037)\n"+
0N/A " -doc generates HTML documents\n"+
0N/A " -map mapfile generates HTML documents with map information\n"+
0N/A " file... zoneinfo source file(s)");
0N/A }
0N/A
0N/A /**
0N/A * @return the output directory path name
0N/A */
0N/A static String getOutputDir() {
0N/A return outputDir;
0N/A }
0N/A
0N/A /**
0N/A * @return the map file's path and name
0N/A */
0N/A static String getMapFile() {
0N/A return mapFile;
0N/A }
0N/A
0N/A /**
0N/A * Returns the time zone data version string specified by the -V
0N/A * option. If it is not specified, "unknown" is returned.
0N/A * @return the time zone data version string
0N/A */
0N/A static String getVersionName() {
0N/A return versionName;
0N/A }
0N/A
0N/A /**
0N/A * Prints out the specified fatal error message and calls {@link
0N/A * java.lang.System#exit System.exit(1)}.
0N/A * @param msg the fatal error message
0N/A */
0N/A static void panic(String msg) {
0N/A printMessage("fatal error", msg);
0N/A System.exit(1);
0N/A }
0N/A
0N/A /**
0N/A * Prints out the specified error message.
0N/A * @param msg the error message
0N/A */
0N/A static void error(String msg) {
0N/A printMessage("error", msg);
0N/A }
0N/A
0N/A /**
0N/A * Prints out the specified warning message.
0N/A * @param msg the warning message
0N/A */
0N/A static void warning(String msg) {
0N/A printMessage("warning", msg);
0N/A }
0N/A
0N/A /**
0N/A * Prints out the informative message.
0N/A * @param msg the informative message
0N/A */
0N/A static void info(String msg) {
0N/A if (verbose) {
0N/A printMessage(null, msg);
0N/A }
0N/A }
0N/A
0N/A private static void printMessage(String type, String msg) {
0N/A if (type != null) {
0N/A type += ": ";
0N/A } else {
0N/A type = "";
0N/A }
0N/A System.err.println("javazic: " + type + msg);
0N/A }
0N/A}