⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codeswitcher.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package codeswitcher;

/* Copyrights and Licenses
 *
 * This product includes Hypersonic SQL.
 * Originally developed by Thomas Mueller and the Hypersonic SQL Group. 
 *
 * Copyright (c) 1995-2000 by the Hypersonic SQL Group. All rights reserved. 
 * Redistribution and use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met: 
 *     -  Redistributions of source code must retain the above copyright notice, this list of conditions
 *         and the following disclaimer. 
 *     -  Redistributions in binary form must reproduce the above copyright notice, this list of
 *         conditions and the following disclaimer in the documentation and/or other materials
 *         provided with the distribution. 
 *     -  All advertising materials mentioning features or use of this software must display the
 *        following acknowledgment: "This product includes Hypersonic SQL." 
 *     -  Products derived from this software may not be called "Hypersonic SQL" nor may
 *        "Hypersonic SQL" appear in their names without prior written permission of the
 *         Hypersonic SQL Group. 
 *     -  Redistributions of any form whatsoever must retain the following acknowledgment: "This
 *          product includes Hypersonic SQL." 
 * This software is provided "as is" and any expressed or implied warranties, including, but
 * not limited to, the implied warranties of merchantability and fitness for a particular purpose are
 * disclaimed. In no event shall the Hypersonic SQL Group or its contributors be liable for any
 * direct, indirect, incidental, special, exemplary, or consequential damages (including, but
 * not limited to, procurement of substitute goods or services; loss of use, data, or profits;
 * or business interruption). However caused any on any theory of liability, whether in contract,
 * strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this
 * software, even if advised of the possibility of such damage. 
 * This software consists of voluntary contributions made by many individuals on behalf of the
 * Hypersonic SQL Group.
 *
 *
 * For work added by the HSQL Development Group:
 *
 * Copyright (c) 2001-2002, The HSQL Development Group
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer, including earlier
 * license statements (above) and comply with all above license conditions.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution, including earlier
 * license statements (above) and comply with all above license conditions.
 *
 * Neither the name of the HSQL Development Group nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, 
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * Work added by 3SP <a href="http://3sp.com">http://3sp.com</a> for 
 * the SSL-Explorer build system is licensed under the Apache license. See
 * APACHE_LICENSE.txt in the root of this build module. 
 */

import java.io.*;
import java.util.*;

// fredt@users 20020315 - patch 1.7.0 - minor fixes
// changed line separator to System based value
// moved the Profile class to org.hsqldb.test package
// fredt@users 20021020 - patch 1.7.1 - formatting fix
// avoid moving blank lines which would be interpreted as code change by CVS
// fredt@users 20021118 - patch 1.7.2 - no-change, no-save fix
// if the file contents do not change, do not save a new version of file

/**
 * Modifies the source code to support different JDK or profile settings. <p>
 * <pre>
 * Usage: java CodeSwitcher [paths] [labels] [+][-]
 * If no labels are specified then all used
 * labels in the source code are shown.
 * Use +MODE to switch on the things labeld MODE
 * Use -MODE to switch off the things labeld MODE
 * Path: Any number of path or files may be
 * specified. Use . for the current directory
 * (including sub-directories).
 * Example: java CodeSwitcher +JAVA2 .
 * This example switches on code labeled JAVA2
 * in all *.java files in the current directory
 * and all subdirectories.
 * java CodeSwitcher + .
 * Adds test code to the code.
 * java CodeSwitcher - .
 * Removes test code from the code
 * </pre>
 *
 * @version 1.7.0
 */
public class CodeSwitcher {

    private static final String ls = System.getProperty("line.separator",
    "\n");
    private Vector           vList;
    private Vector           vSwitchOn;
    private Vector           vSwitchOff;
    private Vector           vSwitches;
    private boolean          bAdd, bRemove;
    private static final int MAX_LINELENGTH = 82;
    private boolean comment = true;

    /**
     * Method declaration
     *
     *
     * @param a
     */
    public static void main(String a[]) {

        CodeSwitcher s = new CodeSwitcher();

        if (a.length == 0) {
            showUsage();

            return;
        }

        boolean path = false;

        for (int i = 0; i < a.length; i++) {
            String p = a[i];
            if (p.equalsIgnoreCase("/strip")) {
                System.err.println("WARNING: /STRIP is deprecated, now use #STRIP. ");
                s.comment = false;
            }
            else if (p.startsWith("#")) {
                String opt = p.substring(1);
                if(opt.equalsIgnoreCase("strip")) {
                    s.comment = false;
                }
            }
            else if (p.startsWith("+")) {
                if (p.length() == 1) {
                    s.bAdd = true;
                } else {
                    s.vSwitchOn.addElement(p.substring(1));
                }
            } else if (p.startsWith("-")) {
                if (p.length() == 1) {
                    s.bRemove = true;
                } else {
                    s.vSwitchOff.addElement(p.substring(1));
                }
            } else {
                s.addDir(p);

                path = true;
            }
        }

        if (!path) {
            printError("no path specified");
            showUsage();
        }

        s.process();

        if (s.vSwitchOff.size() == 0 && s.vSwitchOn.size() == 0) {
            s.printSwitches();
        }
    }

    /**
     * Method declaration
     *
     */
    static void showUsage() {

        System.out.print("Usage: java CodeSwitcher [paths] [labels] [+][-]\n"
                + "If no labels are specified then all used\n"
                + "labels in the source code are shown.\n"
                + "Use +MODE to switch on the things labeld MODE\n"
                + "Use -MODE to switch off the things labeld MODE\n"
                + "Path: Any number of path or files may be\n"
                + "specified. Use . for the current directory\n"
                + "(including sub-directories).\n"
                + "Example: java CodeSwitcher +JAVA2 .\n"
                + "This example switches on code labeled JAVA2\n"
                + "in all *.java files in the current directory\n"
                + "and all subdirectories.\n"
                + "java CodeSwitcher + .\n"
                + "Adds test code to the code.\n"
                + "java CodeSwitcher - .\n"
                + "Removed test code from the code.\n");
    }

    /**
     * Constructor declaration
     *
     */
    CodeSwitcher() {

        vList      = new Vector();
        vSwitchOn  = new Vector();
        vSwitchOff = new Vector();
        vSwitches  = new Vector();
    }

    /**
     * Method declaration
     *
     */
    void process() {

        int len = vList.size();

        for (int i = 0; i < len; i++) {
//            System.out.print(".");

            String file = (String) vList.elementAt(i);

            if (bAdd || bRemove) {
                int maxlen = testFile(file);

                if (bAdd &&!bRemove) {
                    addTest(file, maxlen);
                } else {
                    removeTest(file);
                }
            } else {
                if (!processFile(file)) {
                    printError("in file " + file + " !");
                }
            }
        }

        System.out.println("");
    }

    /**
     * Method declaration
     *
     */
    void printSwitches() {

        System.out.println("Used labels:");

        for (int i = 0; i < vSwitches.size(); i++) {
            System.out.println((String) (vSwitches.elementAt(i)));
        }
    }

    /**
     * Method declaration
     *
     *
     * @param path
     */
    void addDir(String path) {
        File f = new File(path);

        if (f.isFile() && path.endsWith(".java")) {
            vList.addElement(path);
        } else if (f.isDirectory()) {
            String list[] = f.list();

            for (int i = 0; i < list.length; i++) {
                addDir(path + File.separatorChar + list[i]);
            }
        }
    }

    /**
     * Method declaration
     *
     *
     * @param name
     */
    void removeTest(String name) {

        File f    = new File(name);
        File fnew = new File(name + ".new");
        
        LineNumberReader read =  null;
        FileWriter write = null;

        try {
            read  = new LineNumberReader(new FileReader(f));
            write = new FileWriter(fnew);

            while (true) {
                String line = read.readLine();

                if (line == null) {
                    break;
                }

                if (line.startsWith("Profile.visit(")) {
                    int s = line.indexOf(';');

                    line = line.substring(s + 1);
                }

                write.write(line + ls);
            }

            read.close();
            read  = null;
            write.flush();
            write.close();
            write = null;

            File fbak = new File(name + ".bak");

            fbak.delete();
            f.renameTo(fbak);

            File fcopy = new File(name);

            fnew.renameTo(fcopy);
            fbak.delete();
        } catch (Exception e) {
            printError(e.getMessage());
        }
        finally {
            if(read != null) {
                try {
                    read.close();
                } catch (IOException e1) {
                }
            }
            if(write != null) {
                try {
                    write.close();
                } catch (IOException e1) {
                }
            }
        }
    }

    /**
     * Method declaration
     *
     *
     * @param name
     * @param maxline
     */
    void addTest(String name, int maxline) {

        File   f    = new File(name);
        File   fnew = new File(name + ".new");
        String key  = name;

        key = key.replace('\\', '.');
        LineNumberReader read  = null;
        FileWriter       write    = null;

        try {
            read = new LineNumberReader(new FileReader(f));
            write    = new FileWriter(fnew);
            int              l        = 0;
            boolean          longline = false;

            while (true) {
                String line = read.readLine();

                if (line == null) {
                    break;
                }

                if (line.startsWith(" ")) {
                    int spaces = 0;

                    for (; spaces < line.length(); spaces++) {
                        if (line.charAt(spaces) != ' ') {
                            break;
                        }
                    }

                    if (spaces > 3 && testLine(line) &&!longline) {
                        line = "org.hsqldb.test.Profile.visit(\"" + key
                        + "\"," + l + "," + maxline + ");" + line;

                        l++;
                    } else if (isLongline(line)) {
                        longline = true;
                    } else {
                        longline = false;
                    }
                }

                write.write(line + ls);
            }

            read.close();
            read =  null;
            write.flush();
            write.close();
            write = null;

            File fbak = new File(name + ".bak");

            fbak.delete();
            f.renameTo(fbak);

            File fcopy = new File(name);

            fnew.renameTo(fcopy);
            fbak.delete();
        } catch (Exception e) {
            printError(e.getMessage());
        }
        finally {

            if(read != null) {
                try {
                    read.close();
                } catch (IOException e1) {
                }
            }
            if(write != null) {
                try {
                    write.close();
                } catch (IOException e1) {
                }
            }
        }
    }

    /**
     * Method declaration
     *
     *
     * @param name
     *
     * @return
     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -