FileDocCategorySizeDatePackage
GetOptDemo.javaAPI DocExample1467Thu Mar 08 12:44:28 GMT 2001None

GetOptDemo

public class GetOptDemo extends Object
Simple demonstration of GetOpt. Accept the '-n' and '-o outfile' options as shown for sort, and also -h for help.
author
Ian F. Darwin, ian@darwinsys.com
version
$Id: GetOptDemo.java,v 1.6 2001/03/08 17:44:28 ian Exp $

Fields Summary
Constructors Summary
Methods Summary
static voiddoFile(java.lang.String fileName)
Stub to demonstrate processine one file.

		System.out.println(fileName + ' ");
	
static voiddoHelp(int returnValue)
Stub for providing help on usage You can write a longer help than this, certainly.

		System.err.println("Usage: GetOptDemo [-h][-n][-o outfile] file ...");
		System.exit(returnValue);
	
public static voidmain(java.lang.String[] args)

		GetOpt go = new GetOpt("hno:");
		boolean numeric_option = false;
		String outFileName = "(standard output)";
		char c;
		while ((c = go.getopt(args)) != GetOpt.DONE) {
			switch(c) {
			case 'h":
				doHelp(0);
				break;
			case 'n":
				numeric_option = true;
				break;
			case 'o":
				outFileName = go.optarg();
				break;
			default:
				System.err.println("Unknown option character " + c);
				doHelp(1);
			}
		}
		System.out.print("Options: ");
		System.out.print("Numeric: " + numeric_option + ' ");
		System.out.print("Output: " + outFileName + "; ");
		System.out.println("Inputs: ");
		if (go.getOptInd()-1 == args.length) {
			doFile("(standard input)");
		} else for (int i=go.getOptInd()-1; i<args.length; i++)
			doFile(args[i]);