This is the mail archive of the frysk@sourceware.org mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: Add Option Groups


Thanks!

I've also applied it locally.

Andrew

Tom Tromey wrote:
"Andrew" == Andrew Cagney <cagney@redhat.com> writes:

[ Parser and OptionGroup ] Andrew> I'm not sure if its an interface restriction, or a bug; either way it Andrew> leads to a confusing client problem.

I checked in a fix to the Classpath repository.
I've appended it as well.

Tom

ChangeLog:
2008-03-20  Tom Tromey  <tromey@redhat.com>

	* tools/gnu/classpath/tools/getopt/Parser.java (options): Don't
	initialize.
	(add, addFinal): Don't update options.
	(requireOptions): New method.
	(printHelp): Synchronize.  Call requireOptions.
	(parse): Call requireOptions.

Index: tools/gnu/classpath/tools/getopt/Parser.java
===================================================================
RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/getopt/Parser.java,v
retrieving revision 1.9
diff -u -r1.9 Parser.java
--- tools/gnu/classpath/tools/getopt/Parser.java 22 Sep 2006 01:01:26 -0000 1.9
+++ tools/gnu/classpath/tools/getopt/Parser.java 20 Mar 2008 18:02:58 -0000
@@ -1,5 +1,5 @@
/* Parser.java - parse command line options
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2008 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -66,7 +66,9 @@
private boolean longOnly;
- private ArrayList options = new ArrayList();
+ // All of the options. This is null initially; users must call
+ // requireOptions before access.
+ private ArrayList options;
private ArrayList optionGroups = new ArrayList();
@@ -218,7 +220,6 @@
*/
public synchronized void add(Option opt)
{
- options.add(opt);
defaultGroup.add(opt);
}
@@ -230,7 +231,6 @@
*/
protected synchronized void addFinal(Option opt)
{
- options.add(opt);
finalGroup.add(opt);
}
@@ -242,7 +242,6 @@
*/
public synchronized void add(OptionGroup group)
{
- options.addAll(group.options);
// This ensures that the final group always appears at the end
// of the options.
if (optionGroups.isEmpty())
@@ -251,13 +250,29 @@
optionGroups.add(optionGroups.size() - 1, group);
}
+ // Make sure the 'options' field is properly initialized.
+ private void requireOptions()
+ {
+ if (options != null)
+ return;
+ options = new ArrayList();
+ Iterator it = optionGroups.iterator();
+ while (it.hasNext())
+ {
+ OptionGroup group = (OptionGroup) it.next();
+ options.addAll(group.options);
+ }
+ }
+
public void printHelp()
{
this.printHelp(System.out);
}
- void printHelp(PrintStream out)
+ synchronized void printHelp(PrintStream out)
{
+ requireOptions();
+
if (headerText != null)
{
formatText(out, headerText);
@@ -417,6 +432,7 @@
*/
public synchronized void parse(String[] inArgs, FileArgumentCallback files)
{
+ requireOptions();
try
{
args = inArgs;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]