summaryrefslogtreecommitdiff
path: root/java/demo/Freeze/library/RunParser.java
blob: 1fc0e095c7d6e46571ef09b97a8fc9becd1626bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// **********************************************************************
//
// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

import Demo.*;

class RunParser
{
    static void
    usage(String appName)
    {
        System.err.println("Usage: " + appName + " [options] [file...]\n");
        System.err.print(
            "Options:\n" +
            "-h, --help           Show this message.\n");
        //"-v, --version        Display the Ice version.\n"
    }

    static int
    runParser(String appName, String[] args, Ice.Communicator communicator)
    {
        String file = null;
        int idx = 0;

        while(idx < args.length)
        {
            if(args[idx].equals("-h") | args[idx].equals("--help"))
            {
                usage(appName);
                return 0;
            }
/*
  else if(args[idx].equals("-v") || args[idx].equals("--version"))
  {
  cout + ICE_STRING_VERSION + endl;
  return 0;
  }
*/
            else if(args[idx].charAt(0) == '-')
            {
                System.err.println(appName + ": unknown option `" + args[idx] + "'");
                usage(appName);
                return 1;
            }
            else
            {
                if(file == null)
                {
                    file = args[idx];
                }
                else
                {
                    System.err.println(appName + ": only one file is supported.");
                    usage(appName);
                    return 1;
                }
                ++idx;
            }
        }

        Ice.ObjectPrx base = communicator.propertyToProxy("Library.Proxy");
        LibraryPrx library = LibraryPrxHelper.checkedCast(base);
        if(library == null)
        {
            System.err.println(appName + ": invalid object reference");
            return 1;
        }

        Parser parser = new Parser(communicator, library);
        int status;

        if(file == null)
        {
            status = parser.parse();
        }
        else
        {
            try
            {
                status = parser.parse(new java.io.BufferedReader(new java.io.FileReader(file)));
            }
            catch(java.io.IOException ex)
            {
                status = 1;
                ex.printStackTrace();
            }
        }

        return status;
    }
}