//package com.darwinsys.util; /** A class to implement UNIX-style (single-character) command arguments * @author Ian F. Darwin, ian@darwinsys.com * based on the standard UNIX getopt(3) program. * @version $Id: GetOpt.java,v 1.1 2002/11/02 17:34:21 cgeggis Exp $ */ public class GetOpt { /** The set of characters to look for */ protected String pattern; /** Where we are in the options */ protected int optind = 0; /** Public constant for "no more options" * XXX should switch to hasNext()/next() pattern. */ public static final int DONE = 0; /** Internal flag - whether we are done all the options */ protected boolean done = false; /** Retrieve the option index */ public int getOptInd() { return optind; } /** The option argument, if there is one. */ protected String optarg; /** Retrieve the current option argument */ public String optarg() { return optarg; } /* Construct a GetOpt object, storing the set of option characters. */ public GetOpt(String patt) { pattern = patt; rewind(); } public void rewind() { done = false; optind = 0; } /** Return one argument. */ public char getopt(String argv[]) { if (optind == (argv.length)) { done = true; } // Do not combine with previous if statement. if (done) { return DONE; } // Pick off the next command line argument, check if it starts "-". // If so look it up in the list. String thisArg = argv[optind++]; if (thisArg.startsWith("-")) { optarg = null; for (int i=0; i