summaryrefslogtreecommitdiff
path: root/java/demo/Freeze/library/RunParser.java
blob: 8554817359bfa8f54309e691467b77f947b6ffac (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
97
98
99
100
101
102
103
104
105
106
107
108
// **********************************************************************
//
// Copyright (c) 2002
// ZeroC, Inc.
// Billerica, MA, USA
//
// All Rights Reserved.
//
// Ice is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License version 2 as published by
// the Free Software Foundation.
//
// **********************************************************************

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.Properties properties = communicator.getProperties();
	String refProperty = "Library.Proxy";
	String ref = properties.getProperty(refProperty);
	if(ref.length() == 0)
	{
	    System.err.println(appName +  ": property `" + refProperty + "' not set");
	    return 1;
	}

	Ice.ObjectPrx base = communicator.stringToProxy(ref);
	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;
    }
}