    public static int Run(String args[]) {
        boolean rename = args.length > 1 && (args[1].equals(RenameCmd));
        boolean find = args.length > 1 && (args[1].equals(FindCmd));
        if (args.length < 4 || !CheckArgs(args) || (!rename && !find)) {
            PrintUsage();
            return -1;
        }
        boolean verbose = false;
        String outfile = null;
        List<String> params = new LinkedList<String>();
        for (int ii=2; ii<args.length; ++ii) {
            if (args[ii].equals("-o") && (ii+1)<args.length) {
                outfile = args[++ii];
                if (!rename) {
                    System.err.print("Warning: invalid argument -o for "+args[1]+" command, ignoring: -o "+outfile);
                    outfile = null;
                }
            }
            else if (args[ii].equals("-v"))
                verbose = true;
            else params.add(args[ii]);
        }
        int requiredArgs = rename ? 3 : 2;
        if (params.size() < requiredArgs) {
            PrintUsage();
            return 1;
        }
        if (params.size() > requiredArgs) {
            System.err.print("Warning: too many parameters, ignoring:");
            for (int ii=requiredArgs; ii<params.size(); ++ii)
                System.err.print(" "+params.get(ii));
            System.err.println();
        }
        String infile = params.get(0);
        String functionSig = params.get(1);
        String newName = rename ? params.get(2) : null;
        File in = new File(infile);
        File out = outfile!=null ? new File(outfile) : in;
        File temp = null;
        if (rename) {
            int tempCount = 0;
            while (temp == null) {
                temp = new File(out.getParentFile(),out.getName()+String.format(".temp%04d",tempCount++));
                if (temp.exists())
                    temp = null;
            }
        }
        int status = 0;
        try {
            if (verbose)
                System.out.println(CommandName+" processing file "+in.getPath()+"...");
            if (rename) {
                copyFile(in,temp);
                JNIRenamer renamer = new JNIRenamer(temp,in.getPath(),false);
                int count = renamer.findRenameFunc(functionSig, newName, System.out,
                                                   verbose ? System.out : null, System.err);
                renamer.close();
                if (count == 0)
                    System.err.println("ERROR: Found no matches.");
                if (count > 1)
                    System.err.println(String.format("Warning: Found and replaced %d matches?!",count));
                if (count >= 0) {
                    if (out.exists() && !out.delete()) {
                        System.err.println("Error clearing previous output file "+out.getPath());
                        status = -3;
                    }
                    else if ( !temp.renameTo(out) ) {
                        System.err.println("Error moving temporary file "+temp.getPath()+" to "+out.getPath());
                        status = -3;
                    }
                    System.out.println("Result written to "+out.getPath());
                } else status = -5;
            }
            else { 
                JNIRenamer renamer = new JNIRenamer(in,in.getPath(),true);
                int count = renamer.findRenameFunc(functionSig, newName, System.out,
                                                   verbose ? System.out : null, System.err);
                if (verbose && count == 0)
                    System.out.println("Found no matches.");
                if (verbose && count > 1)
                    System.out.println(String.format("Warning: Found more than one match (%d matches)",count));
                if (count > 0)
                    status = 0;
                else if (count == 0)
                    status = 1;
                else 
                    status = -5;
            }
        } catch (Exception e) {
            System.err.println("Error: "+e.getMessage());
            status = -3;
        } finally {
            if (temp!=null && temp.exists())
                temp.delete();
        }
        return status;
    }

    public static int Run(String args[]) {
        boolean rename = args.length > 1 && (args[1].equals(RenameCmd));
        boolean find = args.length > 1 && (args[1].equals(FindCmd));
        if (args.length < 4 || !CheckArgs(args) || (!rename && !find)) {
            PrintUsage();
            return -1;
        }
        boolean verbose = false;
        String outfile = null;
        List<String> params = new LinkedList<String>();
        for (int ii=2; ii<args.length; ++ii) {
            if (args[ii].equals("-o") && (ii+1)<args.length) {
                outfile = args[++ii];
                if (!rename) {
                    System.err.println("Warning: invalid argument -o for "+args[1]+" command, ignoring: -o "+outfile);
                    outfile = null;
                }
            }
            else if (args[ii].equals("-v"))
                verbose = true;
            else params.add(args[ii]);
        }
        int requiredArgs = rename ? 3 : 2;
        if (params.size() < requiredArgs) {
            PrintUsage();
            return 1;
        }
        if (params.size() > requiredArgs) {
            System.err.print("Warning: too many parameters, ignoring:");
            for (int ii=requiredArgs; ii<params.size(); ++ii)
                System.err.print(" "+params.get(ii));
            System.err.println();
        }
        String infile = params.get(0);
        String functionSig = params.get(1);
        String newName = rename ? params.get(2) : null;
        File in = new File(infile);
        File out = outfile!=null ? new File(outfile) : in;
        File temp = null;
        if (rename) {
            int tempCount = 0;
            while (temp == null) {
                temp = new File(out.getParentFile(),out.getName()+String.format(".temp%04d",tempCount++));
                if (temp.exists())
                    temp = null;
            }
        }
        int status = 0;
        try {
            if (verbose)
                System.out.println(CommandName+" processing file "+in.getPath()+"...");
            if (rename) {
                copyFile(in,temp);
                JNIRenamer renamer = new JNIRenamer(temp,in.getPath(),false);
                int count = renamer.findRenameFunc(functionSig, newName, System.out,
                                                   verbose ? System.out : null, System.err);
                renamer.close();
                if (count == 0)
                    System.err.println("ERROR: Found no matches.");
                if (count > 1)
                    System.err.println(String.format("Warning: Found and replaced %d matches?!",count));
                if (count >= 0) {
                    if (out.exists() && !out.delete()) {
                        System.err.println("Error clearing previous output file "+out.getPath());
                        status = -3;
                    }
                    else if ( !temp.renameTo(out) ) {
                        System.err.println("Error moving temporary file "+temp.getPath()+" to "+out.getPath());
                        status = -3;
                    }
                    System.out.println("Result written to "+out.getPath());
                } else status = -5;
            }
            else { 
                JNIRenamer renamer = new JNIRenamer(in,in.getPath(),true);
                int count = renamer.findRenameFunc(functionSig, newName, System.out,
                                                   verbose ? System.out : null, System.err);
                if (verbose && count == 0)
                    System.out.println("Found no matches.");
                if (verbose && count > 1)
                    System.out.println(String.format("Warning: Found more than one match (%d matches)",count));
                if (count > 0)
                    status = 0;
                else if (count == 0)
                    status = 1;
                else 
                    status = -5;
            }
        } catch (Exception e) {
            System.err.println("Error: "+e.getMessage());
            status = -3;
        } finally {
            if (temp!=null && temp.exists())
                temp.delete();
        }
        return status;
    }
