< prev index next >

src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTY.java

Print this page
rev 48074 : 8189102: All tools should support -?, -h and --help
Reviewed-by: kvn, jjg, weijun, alanb, rfield, ksrini
   1 /*
   2  * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 774                     ln = lastLine + ln.substring(2);
 775                     MessageOutput.printDirectln(ln);// Special case: use printDirectln()
 776                 }
 777 
 778                 StringTokenizer t = new StringTokenizer(ln);
 779                 if (t.hasMoreTokens()) {
 780                     lastLine = ln;
 781                     executeCommand(t);
 782                 } else {
 783                     MessageOutput.printPrompt();
 784                 }
 785             }
 786         } catch (VMDisconnectedException e) {
 787             handler.handleDisconnectedException();
 788         }
 789     }
 790 
 791     private static void usage() {
 792         MessageOutput.println("zz usage text", new Object [] {progname,
 793                                                      File.pathSeparator});
 794         System.exit(1);
 795     }
 796 
 797     static void usageError(String messageKey) {
 798         MessageOutput.println(messageKey);
 799         MessageOutput.println();
 800         usage();
 801     }
 802 
 803     static void usageError(String messageKey, String argument) {
 804         MessageOutput.println(messageKey, argument);
 805         MessageOutput.println();
 806         usage();
 807     }
 808 
 809     private static boolean supportsSharedMemory() {
 810         for (Connector connector :
 811                  Bootstrap.virtualMachineManager().allConnectors()) {
 812             if (connector.transport() == null) {
 813                 continue;
 814             }


 990             } else if (token.equals("-listconnectors")) {
 991                 Commands evaluator = new Commands();
 992                 evaluator.commandConnectors(Bootstrap.virtualMachineManager());
 993                 return;
 994             } else if (token.equals("-connect")) {
 995                 /*
 996                  * -connect allows the user to pick the connector
 997                  * used in bringing up the target VM. This allows
 998                  * use of connectors other than those in the reference
 999                  * implementation.
1000                  */
1001                 if (connectSpec != null) {
1002                     usageError("cannot redefine existing connection", token);
1003                     return;
1004                 }
1005                 if (i == (argv.length - 1)) {
1006                     usageError("No connect specification.");
1007                     return;
1008                 }
1009                 connectSpec = argv[++i];
1010             } else if (token.equals("-help")) {




1011                 usage();
1012             } else if (token.equals("-version")) {
1013                 Commands evaluator = new Commands();
1014                 evaluator.commandVersion(progname,
1015                                          Bootstrap.virtualMachineManager());
1016                 System.exit(0);
1017             } else if (token.startsWith("-")) {
1018                 usageError("invalid option", token);
1019                 return;
1020             } else {
1021                 // Everything from here is part of the command line
1022                 cmdLine = addArgument("", token);
1023                 for (i++; i < argv.length; i++) {
1024                     cmdLine = addArgument(cmdLine, argv[i]);
1025                 }
1026                 break;
1027             }
1028         }
1029 
1030         /*


   1 /*
   2  * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 774                     ln = lastLine + ln.substring(2);
 775                     MessageOutput.printDirectln(ln);// Special case: use printDirectln()
 776                 }
 777 
 778                 StringTokenizer t = new StringTokenizer(ln);
 779                 if (t.hasMoreTokens()) {
 780                     lastLine = ln;
 781                     executeCommand(t);
 782                 } else {
 783                     MessageOutput.printPrompt();
 784                 }
 785             }
 786         } catch (VMDisconnectedException e) {
 787             handler.handleDisconnectedException();
 788         }
 789     }
 790 
 791     private static void usage() {
 792         MessageOutput.println("zz usage text", new Object [] {progname,
 793                                                      File.pathSeparator});
 794         System.exit(0);
 795     }
 796 
 797     static void usageError(String messageKey) {
 798         MessageOutput.println(messageKey);
 799         MessageOutput.println();
 800         usage();
 801     }
 802 
 803     static void usageError(String messageKey, String argument) {
 804         MessageOutput.println(messageKey, argument);
 805         MessageOutput.println();
 806         usage();
 807     }
 808 
 809     private static boolean supportsSharedMemory() {
 810         for (Connector connector :
 811                  Bootstrap.virtualMachineManager().allConnectors()) {
 812             if (connector.transport() == null) {
 813                 continue;
 814             }


 990             } else if (token.equals("-listconnectors")) {
 991                 Commands evaluator = new Commands();
 992                 evaluator.commandConnectors(Bootstrap.virtualMachineManager());
 993                 return;
 994             } else if (token.equals("-connect")) {
 995                 /*
 996                  * -connect allows the user to pick the connector
 997                  * used in bringing up the target VM. This allows
 998                  * use of connectors other than those in the reference
 999                  * implementation.
1000                  */
1001                 if (connectSpec != null) {
1002                     usageError("cannot redefine existing connection", token);
1003                     return;
1004                 }
1005                 if (i == (argv.length - 1)) {
1006                     usageError("No connect specification.");
1007                     return;
1008                 }
1009                 connectSpec = argv[++i];
1010             } else if (token.equals("-?") ||
1011                        token.equals("-h") ||
1012                        token.equals("--help") ||
1013                        // -help: legacy.
1014                        token.equals("-help")) {
1015                 usage();
1016             } else if (token.equals("-version")) {
1017                 Commands evaluator = new Commands();
1018                 evaluator.commandVersion(progname,
1019                                          Bootstrap.virtualMachineManager());
1020                 System.exit(0);
1021             } else if (token.startsWith("-")) {
1022                 usageError("invalid option", token);
1023                 return;
1024             } else {
1025                 // Everything from here is part of the command line
1026                 cmdLine = addArgument("", token);
1027                 for (i++; i < argv.length; i++) {
1028                     cmdLine = addArgument(cmdLine, argv[i]);
1029                 }
1030                 break;
1031             }
1032         }
1033 
1034         /*


< prev index next >