1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17package com.android.inputmethod.latin.maketext;
18
19import java.util.Arrays;
20import java.util.LinkedList;
21import java.util.NoSuchElementException;
22import java.util.jar.JarFile;
23
24public class LabelText {
25    static class Options {
26        private static final String OPTION_JAVA = "-java";
27
28        public final String mJava;
29
30        public static void usage(String message) {
31            if (message != null) {
32                System.err.println(message);
33            }
34            System.err.println("usage: makelabel " + OPTION_JAVA + " <java_output_dir>");
35            System.exit(1);
36        }
37
38        public Options(final String[] argsArray) {
39            final LinkedList<String> args = new LinkedList<String>(Arrays.asList(argsArray));
40            String arg = null;
41            String java = null;
42            try {
43                while (!args.isEmpty()) {
44                    arg = args.removeFirst();
45                    if (arg.equals(OPTION_JAVA)) {
46                        java = args.removeFirst();
47                    } else {
48                        usage("Unknown option: " + arg);
49                    }
50                }
51            } catch (NoSuchElementException e) {
52                usage("Option " + arg + " needs argument");
53            }
54
55            mJava = java;
56        }
57    }
58
59    public static void main(final String[] args) {
60        final Options options = new Options(args);
61        final JarFile jar = JarUtils.getJarFile(LabelText.class);
62        final MoreKeysResources resources = new MoreKeysResources(jar);
63        resources.writeToJava(options.mJava);
64    }
65}
66