/* * Created on Feb 28, 2005 */ package fr.lifl.stc.stan.tools; import fr.lifl.stc.stan.signature.Signature; import fr.lifl.stc.stan.signature.SignatureDictionary; import gnu.getopt.Getopt; import gnu.getopt.LongOpt; import java.io.FileNotFoundException; import java.io.IOException; /** * @author yann */ public class Extracter { private static String meth = null; private static SignatureDictionary dict = null; private static SignatureDictionary target = null; private static void printHelp() { System.out.println("-h/--help : print this help"); System.out.println("-d/--dictionary : use as source dictionary"); System.out.println("-t/--target : use as target dictionary"); System.out.println("-m/--method : transfer signature for this method"); } public static void main(String[] args) { int c; //String arg; LongOpt[] longopts = new LongOpt[4]; longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'); longopts[1] = new LongOpt("dictionary", LongOpt.REQUIRED_ARGUMENT, null, 'd'); longopts[2] = new LongOpt("method", LongOpt.REQUIRED_ARGUMENT, null, 'm'); longopts[3] = new LongOpt("target", LongOpt.REQUIRED_ARGUMENT, null, 't'); Getopt g = new Getopt("Displayer", args, "-:hd:m:t:W;", longopts); try { while ((c = g.getopt()) != -1) switch (c) { case 'h': printHelp(); System.exit(0); break; case 'd': dict = new SignatureDictionary(g.getOptarg()); break; case 'm': meth = g.getOptarg(); break; case 't': target = new SignatureDictionary(g.getOptarg()); break; case 'W': System.out .println("You tried a -W with an incorrect long option name"); break; case ':': System.out.println("You need an argument for option " + (char) g.getOptopt()); break; case '?': System.out.println("The option '" + (char) g.getOptopt() + "' is not valid"); break; default: System.out.println("getopt(): unknown option " + c); break; } if (dict == null) { System.err.println("You must provide a source dictionary"); System.exit(1); } if (meth == null) { System.err.println("You must provide a method"); System.exit(1); } if (target == null) { System.err.println("You must provide a target dictionary"); System.exit(1); } Signature sign; sign = dict.findSignature(meth,true); if (sign == null) { System.err.println("Error: no such method \"" + meth + "\"in dictionary"); System.exit(1); } //FIXME is this "true" ? target.putSignatureForcively(meth,sign, true); target.dump(); } catch (ClassNotFoundException e) { System.err.println("Error: Dictionary contains unknown classes"); System.exit(1); } catch (FileNotFoundException e) { System.err.println("Error: Dictionary file not found"); System.exit(1); } catch (IOException e) { System.err.println("Error: IO error"); System.exit(1); } } }