1 Debian patch touch this file
| 1 | /* |
| 2 | * This file is part of Arduino. |
| 3 | * |
| 4 | * Arduino is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | * |
| 18 | * As a special exception, you may use this file as part of a free software |
| 19 | * library without restriction. Specifically, if other files instantiate |
| 20 | * templates or use macros or inline functions from this file, or you compile |
| 21 | * this file and link it with other files to produce an executable, this |
| 22 | * file does not by itself cause the resulting executable to be covered by |
| 23 | * the GNU General Public License. This exception does not however |
| 24 | * invalidate any other reasons why the executable file might be covered by |
| 25 | * the GNU General Public License. |
| 26 | * |
| 27 | * Copyright 2015 Arduino LLC (http://www.arduino.cc/) |
| 28 | */ |
| 29 | |
| 30 | package cc.arduino.packages.formatter; |
| 31 | |
| 32 | import processing.app.Base; |
| 33 | import processing.app.helpers.OSUtils; |
| 34 | |
| 35 | import java.io.File; |
| 36 | |
| 37 | public class AStyleInterface { |
| 38 | |
| 39 | static { |
| 40 | if (OSUtils.isWindows()) { |
| 41 | loadLib(Base.getContentFile(System.mapLibraryName("msvcp100"))); |
| 42 | loadLib(Base.getContentFile(System.mapLibraryName("msvcr100"))); |
| 43 | } |
| •44 | System.loadLibrary("astylej"); |
| 45 | } |
| 46 | |
| 47 | private static void loadLib(File lib) { |
| 48 | try { |
| 49 | System.load(lib.getAbsolutePath()); |
| 50 | } catch (UnsatisfiedLinkError e) { |
| 51 | e.printStackTrace(); |
| 52 | System.out.println(e.getMessage()); |
| 53 | System.out.println("Cannot load native library " + lib.getAbsolutePath()); |
| 54 | System.out.println("The program has terminated!"); |
| 55 | System.exit(1); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Calls the AStyleMain function in Artistic Style. |
| 61 | * |
| 62 | * @param textIn A string containing the source code to be formatted. |
| 63 | * @param options A string of options to Artistic Style. |
| 64 | * @return A String containing the formatted source from Artistic Style. |
| 65 | */ |
| 66 | public native String AStyleMain(String textIn, String options); |
| 67 | |
| 68 | /** |
| 69 | * Calls the AStyleGetVersion function in Artistic Style. |
| 70 | * |
| 71 | * @return A String containing the version number of Artistic Style. |
| 72 | */ |
| 73 | public native String AStyleGetVersion(); |
| 74 | |
| 75 | /** |
| 76 | * Error handler for messages from Artistic Style. |
| 77 | * This method is called only if there are errors when AStyleMain is called. |
| 78 | * This is for debugging and there should be no errors when the calling |
| 79 | * parameters are correct. |
| 80 | * Changing the method name requires changing Artistic Style. |
| 81 | * Signature: (ILjava/lang/String;)V. |
| 82 | * |
| 83 | * @param errorNumber The error number from Artistic Style. |
| 84 | * @param errorMessage The error message from Artistic Style. |
| 85 | */ |
| 86 | private void ErrorHandler(int errorNumber, String errorMessage) { |
| 87 | System.out.println("AStyle error " + String.valueOf(errorNumber) + " - " + errorMessage); |
| 88 | } |
| 89 | |
| 90 | } |