SUGGESTED FIX
========================================> /gafter/neal-gjc/src/share/javac/com/sun/tools/javac/Main.java
------- Main.java -------
*** /tmp/dL.aG4W Fri Oct 27 10:46:16 2000
--- Main.java Wed Oct 25 17:22:18 2000
***************
*** 17,23 ****
*/
public static void main(String[] args) {
com.sun.tools.javac.v8.Main compiler =
! new com.sun.tools.javac.v8.Main("javac", false);
System.exit(compiler.compile(args));
}
--- 17,23 ----
*/
public static void main(String[] args) {
com.sun.tools.javac.v8.Main compiler =
! new com.sun.tools.javac.v8.Main("javac");
System.exit(compiler.compile(args));
}
***************
*** 26,32 ****
*/
public static int compile(String[] args) {
com.sun.tools.javac.v8.Main compiler =
! new com.sun.tools.javac.v8.Main("javac", false);
return compiler.compile(args);
}
}
--- 26,32 ----
*/
public static int compile(String[] args) {
com.sun.tools.javac.v8.Main compiler =
! new com.sun.tools.javac.v8.Main("javac");
return compiler.compile(args);
}
}
========================================> /gafter/neal-gjc/src/share/javac/com/sun/tools/javac/GJMain.java
------- GJMain.java -------
*** /tmp/dpbaa5W Fri Oct 27 10:46:16 2000
--- GJMain.java Wed Oct 25 17:21:52 2000
***************
*** 17,23 ****
*/
public static void main(String[] args) {
com.sun.tools.javac.v8.Main compiler =
! new com.sun.tools.javac.v8.Main("gjc", true);
System.exit(compiler.compile(args));
}
--- 17,23 ----
*/
public static void main(String[] args) {
com.sun.tools.javac.v8.Main compiler =
! new com.sun.tools.javac.v8.Main("gjc");
System.exit(compiler.compile(args));
}
***************
*** 26,32 ****
*/
public int compile(String[] args) {
com.sun.tools.javac.v8.Main compiler =
! new com.sun.tools.javac.v8.Main("gjc", true);
return compiler.compile(args);
}
}
--- 26,32 ----
*/
public int compile(String[] args) {
com.sun.tools.javac.v8.Main compiler =
! new com.sun.tools.javac.v8.Main("gjc");
return compiler.compile(args);
}
}
========================================> /gafter/neal-gjc/src/share/javac/com/sun/tools/javac/v8/Main.java
------- Main.java -------
*** /tmp/dteaW5W Fri Oct 27 10:46:16 2000
--- Main.java Fri Oct 27 10:28:05 2000
***************
*** 10,19 ****
package com.sun.tools.javac.v8;
import java.io.IOException;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
- import java.text.MessageFormat;
import com.sun.tools.javac.v8.util.*;
import com.sun.tools.javac.v8.code.*;
--- 10,21 ----
package com.sun.tools.javac.v8;
+ import java.io.FileOutputStream;
import java.io.IOException;
+ import java.io.PrintStream;
+ import java.text.MessageFormat;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import com.sun.tools.javac.v8.util.*;
import com.sun.tools.javac.v8.code.*;
***************
*** 43,48 ****
--- 45,57 ----
EXIT_SYSERR = 3, // System error or resource exhaustion.
EXIT_ABNORMAL = 4; // Compiler terminated abnormally
+ /** Options type
+ */
+ private static final String
+ OPT_STANDARD = "S", // normal, documented options
+ OPT_NONSTANDARD = "N", // documentation available via -X
+ OPT_SECRET = "S"; // secret, never-documented options
+
/** A three-column matrix describing all possible options.
* First column: The option's name
* Second column: The key to locate the option's argument, "" if there
***************
*** 49,123 ****
* is none.
* Third column: The key to locate the internationalized string which
* describes the option.
*
* The first and second columns are important internally, since they
* are used to construct the table of actual options that's passed
* as an argument to the JavaCompiler constructor.
*/
! static String[][] standardOptions = {
! {"-g", "", "opt.g"},
! {"-g:none", "", "opt.g.none"},
! {"-g:{lines,vars,source}", "", "opt.g.lines.vars.source"},
! {"-O", "", "opt.O"},
! {"-nowarn", "", "opt.nowarn"},
! {"-verbose", "", "opt.verbose"},
! {"-deprecation", "", "opt.deprecation"},
! {"-classpath", "opt.arg.path", "opt.classpath"},
! {"-sourcepath", "opt.arg.path", "opt.sourcepath"},
! {"-bootclasspath", "opt.arg.path", "opt.bootclasspath"},
! {"-extdirs", "opt.arg.dirs", "opt.extdirs"},
! {"-d", "opt.arg.directory", "opt.d"},
! {"-encoding", "opt.arg.encoding", "opt.encoding"},
! {"-source", "opt.arg.release", "opt.source"},
! {"-target", "opt.arg.release", "opt.target"}};
!
! //GJ options:
!
/*if_not[PUREJAVA]*/
! static String[][] extendedOptions = {
! {"-gj", "", "opt.gj"},
! {"-moreinfo", "", "opt.moreinfo"},
! {"-printflat", "", "opt.printflat"},
! {"-printsearch", "", "opt.printsearch"},
! {"-prompt", "", "opt.prompt"},
! {"-retrofit", "opt.arg.pathname", "opt.retrofit"},
! {"-s", "", "opt.s"},
! {"-scramble", "", "opt.scramble"},
! {"-scrambleall", "", "opt.scrambleall"},
! {"-switchcheck", "", "opt.switchcheck"},
! {"-warnunchecked", "", "opt.warnunchecked"},
! {"-version", "", "opt.version"}};
/*end[PUREJAVA]*/
- /** Command-line options currently available.
- */
- String[][] enabledOptions;
-
/**
* Construct a compiler instance.
*/
! public Main(String name, boolean gjEnabled) {
ownName = name;
- /*if_not[PUREJAVA]*/
- if (gjEnabled) {
- int stdLen = standardOptions.length;
- int optLen = stdLen + extendedOptions.length;
- enabledOptions = new String[optLen][];
- int i = 0;
- while (i < stdLen) {
- enabledOptions[i] = standardOptions[i];
- i++;
- }
- while (i < optLen) {
- enabledOptions[i] = extendedOptions[i-stdLen];
- i++;
- }
- } else {
- /*end[PUREJAVA]*/
- enabledOptions = standardOptions;
- /*if_not[PUREJAVA]*/
- }
- /*end[PUREJAVA]*/
}
/** A table of all options that's passed to the JavaCompiler constructor.
--- 58,110 ----
* is none.
* Third column: The key to locate the internationalized string which
* describes the option.
+ * Fourth column: A single-letter string that distinguishes option type
+ * from among "S"tandard, "N"onstandard, and "S"ecret.
*
* The first and second columns are important internally, since they
* are used to construct the table of actual options that's passed
* as an argument to the JavaCompiler constructor.
*/
! private static String[][] optionStrings = {
! {"-g", "", "opt.g", OPT_STANDARD},
! {"-g:none", "", "opt.g.none", OPT_STANDARD},
! {"-g:{lines,vars,source}", "", "opt.g.lines.vars.source", OPT_STANDARD},
! {"-O", "", "opt.O", OPT_STANDARD},
! {"-nowarn", "", "opt.nowarn", OPT_STANDARD},
! {"-verbose", "", "opt.verbose", OPT_STANDARD},
! {"-deprecation", "", "opt.deprecation", OPT_STANDARD},
! {"-classpath", "opt.arg.path", "opt.classpath", OPT_STANDARD},
! {"-sourcepath", "opt.arg.path", "opt.sourcepath", OPT_STANDARD},
! {"-bootclasspath", "opt.arg.path", "opt.bootclasspath", OPT_STANDARD},
! {"-extdirs", "opt.arg.dirs", "opt.extdirs", OPT_STANDARD},
! {"-d", "opt.arg.directory", "opt.d", OPT_STANDARD},
! {"-encoding", "opt.arg.encoding", "opt.encoding", OPT_STANDARD},
! {"-source", "opt.arg.release", "opt.source", OPT_STANDARD},
! {"-target", "opt.arg.release", "opt.target", OPT_STANDARD},
! {"-help", "", "opt.help", OPT_STANDARD},
/*if_not[PUREJAVA]*/
! {"-gj", "", "opt.gj", OPT_STANDARD},
! {"-moreinfo", "", "opt.moreinfo", OPT_STANDARD},
! {"-printflat", "", "opt.printflat", OPT_STANDARD},
! {"-printsearch", "", "opt.printsearch", OPT_STANDARD},
! {"-prompt", "", "opt.prompt", OPT_STANDARD},
! {"-retrofit", "opt.arg.pathname", "opt.retrofit", OPT_STANDARD},
! {"-s", "", "opt.s", OPT_STANDARD},
! {"-scramble", "", "opt.scramble", OPT_STANDARD},
! {"-scrambleall", "", "opt.scrambleall", OPT_STANDARD},
! {"-switchcheck", "", "opt.switchcheck", OPT_STANDARD},
! {"-warnunchecked", "", "opt.warnunchecked", OPT_STANDARD},
! {"-version", "", "opt.version", OPT_STANDARD},
/*end[PUREJAVA]*/
+ {"-Xstdout", "opt.arg.file", "opt.Xstdout", OPT_NONSTANDARD},
+ {"-X", "", "opt.X", OPT_NONSTANDARD}
+ };
/**
* Construct a compiler instance.
*/
! public Main(String name) {
ownName = name;
}
/** A table of all options that's passed to the JavaCompiler constructor.
***************
*** 129,149 ****
/** Print a string that explains usage.
*/
! void help() {
! System.err.println(getLocalizedString("msg.usage.header", ownName));
! for (int i = 0; i < enabledOptions.length; i++) {
! // Allow for undocumented '-X' options.
! if (!enabledOptions[i][0].startsWith("-X")) {
! // Documented option.
! String s = " " + enabledOptions[i][0] + " ";
! if (!enabledOptions[i][1].equals(""))
! s += getLocalizedString(enabledOptions[i][1]);
System.err.print(s);
for (int j = s.length(); j < 28; j++) System.err.print(" ");
! System.err.println(getLocalizedString(enabledOptions[i][2]));
}
}
System.err.println();
}
/** Report a usage error.
--- 116,138 ----
/** Print a string that explains usage.
*/
! void help(String kind) {
! if (kind == OPT_STANDARD)
! System.err.println(getLocalizedString("msg.usage.header", ownName));
! for (int i = 0; i < optionStrings.length; i++) {
! if (optionStrings[i][3] == kind) {
! // we only document the kind asked for
! String s = " " + optionStrings[i][0] + " ";
! if (!optionStrings[i][1].equals(""))
! s += getLocalizedString(optionStrings[i][1]);
System.err.print(s);
for (int j = s.length(); j < 28; j++) System.err.print(" ");
! System.err.println(getLocalizedString(optionStrings[i][2]));
}
}
System.err.println();
+ if (kind == OPT_NONSTANDARD)
+ System.err.println(getLocalizedString("msg.usage.nonstandard.footer"));
}
/** Report a usage error.
***************
*** 150,162 ****
*/
void error(String key, String arg) {
System.err.println(ownName + ": "
! + getLocalizedString(key, arg));
! help();
}
/** Does argument string match option pattern?
* @param pattern The option pattern, as found in the first column of
! * the enabledOptions matrix.
* @param arg The command line argument string.
*/
private boolean matches(String pattern, String arg) {
--- 139,159 ----
*/
void error(String key, String arg) {
System.err.println(ownName + ": "
! + getLocalizedString(key, arg, null));
! help(OPT_STANDARD);
}
+ /** Report a usage error.
+ */
+ void error(String key, String arg0, String arg1) {
+ System.err.println(ownName + ": "
+ + getLocalizedString(key, arg0, arg1));
+ help(OPT_STANDARD);
+ }
+
/** Does argument string match option pattern?
* @param pattern The option pattern, as found in the first column of
! * the optionStrings matrix.
* @param arg The command line argument string.
*/
private boolean matches(String pattern, String arg) {
***************
*** 207,219 ****
ac++;
if (arg.startsWith("-")) {
int j = 0;
! while (j < enabledOptions.length &&
! !matches(enabledOptions[j][0], arg)) j++;
! if (j == enabledOptions.length) {
error("err.invalid.flag", arg);
return null;
}
! String operand = enabledOptions[j][1];
if (operand.length() != 0) {
if (ac == args.length) {
error("err.req.arg", arg);
--- 204,216 ----
ac++;
if (arg.startsWith("-")) {
int j = 0;
! while (j < optionStrings.length &&
! !matches(optionStrings[j][0], arg)) j++;
! if (j == optionStrings.length) {
error("err.invalid.flag", arg);
return null;
}
! String operand = optionStrings[j][1];
if (operand.length() != 0) {
if (ac == args.length) {
error("err.req.arg", arg);
***************
*** 224,229 ****
--- 221,239 ----
}
if (arg.equals("-moreinfo")) {
Type.moreInfo = true;
+ } else if (arg.equals("-X")) {
+ help(OPT_NONSTANDARD);
+ } else if (arg.equals("-help")) {
+ help(OPT_STANDARD);
+ } else if (arg.equals("-Xstdout")) {
+ try {
+ PrintStream out = new PrintStream(new FileOutputStream(operand));
+ System.setOut(out);
+ System.setErr(out);
+ } catch (java.io.FileNotFoundException e) {
+ error("err.error.writing.file", operand, e.toString());
+ return null;
+ }
} else if (arg.equals("-version")) {
System.err.println(
ownName + " " + JavaCompiler.version() + ", " +
***************
*** 265,271 ****
JavaCompiler comp = null;
try {
if (args.length == 0) {
! help();
return EXIT_CMDERR;
}
--- 275,281 ----
JavaCompiler comp = null;
try {
if (args.length == 0) {
! help(OPT_STANDARD);
return EXIT_CMDERR;
}
***************
*** 368,380 ****
* @param key The key for the localized string.
*/
private static String getLocalizedString(String key) {
! return getText("javac." + key, null);
}
private static String getLocalizedString(String key, String arg0) {
! return getText("javac." + key, arg0);
}
private static final String javacRB = "com.sun.tools.javac.v8.resources.javac";
private static ResourceBundle messageRB;
--- 378,394 ----
* @param key The key for the localized string.
*/
private static String getLocalizedString(String key) {
! return getText("javac." + key, null, null);
}
private static String getLocalizedString(String key, String arg0) {
! return getText("javac." + key, arg0, null);
}
+ private static String getLocalizedString(String key, String arg0, String arg1) {
+ return getText("javac." + key, arg0, arg1);
+ }
+
private static final String javacRB = "com.sun.tools.javac.v8.resources.javac";
private static ResourceBundle messageRB;
***************
*** 393,409 ****
/** Get and format message string from resource.
*/
! private static String getText(String key, String arg0) {
if (messageRB == null)
initResource();
try {
! String [] args = {arg0};
return MessageFormat.format(messageRB.getString(key), args);
} catch (MissingResourceException e) {
if (arg0 == null) arg0 = "null";
! String [] args = {key, arg0};
String msg = "javac message file b
|