getopt.java
来自「CmisJavaApi」· Java 代码 · 共 125 行
JAVA
125 行
/* * The contents of this file are subject to the Dyade Public License, * as defined by the file DYADE_PUBLIC_LICENSE.TXT * * You may not use this file except in compliance with the License. You may * obtain a copy of the License on the Dyade web site (www.dyade.fr). * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific terms governing rights and limitations under the License. * * The Original Code is CmisJava API, including the java package * fr.dyade.cmis, released September 5, 2000. * * The Initial Developer of the Original Code is Dyade. The Original Code and * portions created by Dyade are Copyright Bull and Copyright INRIA. * All Rights Reserved. *//* Copyright 1996-2000 by Institut National de Recherche en Informatique * et en Automatique (INRIA) * All rights reserved. See COPYRIGHT in top-level directory. * * Authors: Laurent Andrey, Eric Dillon, Olivier Festor */// $Id: GetOpt.java,v 1.2 2000/09/05 14:43:08 festor Exp $// $Source: /local/resedas/CVS-Repository/CmisJavaApi/src/fr/dyade/cmis/util/getopt/GetOpt.java,v $//package fr.dyade.cmis.util.getopt;import java.util.Vector;import java.util.Enumeration;public abstract class GetOpt { public void scan( String[] args ) { fArgs=args; fNextArgIdx=0; short state=ON_OPTION; shiftArg(); while (fLastArgType!=NO_MORE_ARGS_TYPE) { if (state==ON_PARAM) { fParams.addElement(fLastArg); } else { switch(fLastArgType) { case OPTION_TYPE: scanOption(); break; case END_OPTION_TYPE: state=ON_PARAM; default: fParams.addElement(fLastArg); break; } } shiftArg(); } } public abstract void usage(); private void scanOption() { OptionDescriptor optDesc; try { optDesc= (OptionDescriptor)getClass().getField(fLastArg.substring(1)).get(this); } catch (Exception e) { System.err.println(fLastArg+ ": illegal option"); usage(); return; } switch (optDesc.type()) { case OptionDescriptor.EXACT_COUNT_CODE: optDesc.optionSeen(); for (int i=0; i<optDesc.specifiedCount(); i++) { shiftArg(); optDesc.processOptionParam(fLastArg); } break; } } public Enumeration enumParams() { return fParams.elements(); } public String[] arrayParams () { // return (String[])fParams.toArray(); //JDK 1.2 String[] res=new String[fParams.size()]; fParams.copyInto(res); return res; } public int getParamCount() { return fParams.size(); } private void shiftArg() { if (fNextArgIdx<fArgs.length) { fLastArg=fArgs[fNextArgIdx]; if ("--".compareTo(fLastArg)==0) { fLastArgType=END_OPTION_TYPE; } else { if (fLastArg.charAt(0)=='-') { fLastArgType=OPTION_TYPE; } else { fLastArgType=PARAM_TYPE; } } } else { fLastArgType=NO_MORE_ARGS_TYPE; } fNextArgIdx++; } private final static short ON_OPTION=0; private final static short ON_PARAM=1; private static final short OPTION_TYPE=0; private static final short PARAM_TYPE=1; private static final short END_OPTION_TYPE=2; private static final short NO_MORE_ARGS_TYPE=3; private String[] fArgs; private Vector fParams=new Vector(); private int fNextArgIdx=0; private String fLastArg; private int fLastArgType=OPTION_TYPE; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?