home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for NON-COMMERCIAL purposes and without
- * fee is hereby granted provided that this copyright notice
- * appears in all copies. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
- class ParseCmdLine {
- public static void main(String args[]) {
-
- int i = 0, j;
- String arg;
- char flag;
- boolean vflag = false;
- String outputfile = "";
-
- while (i < args.length && args[i].startsWith("-")) {
- arg = args[i++];
-
- // use this type of check for "wordy" arguments
- if (arg.equals("-verbose")) {
- System.out.println("verbose mode on");
- vflag = true;
- }
-
- // use this type of check for arguments that require arguments
- else if (arg.equals("-output")) {
- if (i < args.length)
- outputfile = args[i++];
- else
- System.err.println("-output requires a filename");
- if (vflag)
- System.out.println("output file = " + outputfile);
- }
-
- // use this type of check for a series of flag arguments
- else {
- for (j = 1; j < arg.length(); j++) {
- flag = arg.charAt(j);
- switch (flag) {
- case 'x':
- if (vflag) System.out.println("Option x");
- break;
- case 'n':
- if (vflag) System.out.println("Option n");
- break;
- default:
- System.err.println("ParseCmdLine: illegal option " + flag);
- break;
- }
- }
- }
- }
- if (i == args.length)
- System.err.println("Usage: ParseCmdLine [-verbose] [-xn] [-output afile] filename");
- else
- System.out.println("Success!");
- }
- }
-