diff options
author | Michael Bien <[email protected]> | 2009-11-02 01:41:14 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2009-11-02 01:41:14 +0100 |
commit | 1690ead6c21b61bd337706b836c04164940eed69 (patch) | |
tree | b7aee403be08f0ee1f38a1b05c2e0f3827fa7c60 /etc | |
parent | 675ab3939df505941fed5483007100af7f01fd46 (diff) |
integrated function parameter name uncommenter in build process for easier readable parameter names in generated code.
Diffstat (limited to 'etc')
-rw-r--r-- | etc/src/com/mbien/ant/FunctionParamUncommenter.java (renamed from etc/FunctionParamUncommenter.java) | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/etc/FunctionParamUncommenter.java b/etc/src/com/mbien/ant/FunctionParamUncommenter.java index 9296895e..df69471e 100644 --- a/etc/FunctionParamUncommenter.java +++ b/etc/src/com/mbien/ant/FunctionParamUncommenter.java @@ -1,3 +1,4 @@ +package com.mbien.ant; import java.io.BufferedWriter; import java.io.File; @@ -7,6 +8,8 @@ import java.io.FileWriter; import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; import static java.util.regex.Pattern.*; /** @@ -20,7 +23,7 @@ import static java.util.regex.Pattern.*; * * @author Michael Bien */ -public class FunctionParamUncommenter { +public class FunctionParamUncommenter extends Task { final static Pattern PARAMS_PATTERN = compile("cl\\w+ \\( ( \\s* [^;]+ ) \\)", MULTILINE|COMMENTS); @@ -28,20 +31,26 @@ public class FunctionParamUncommenter { final static Pattern COMMENT_PATTERN = compile("\\s*(const)?\\w+\\s* \\**\\s+ (/\\*) \\s+[^\\*\\[]+ (\\*/)", MULTILINE|COMMENTS); //^ array size in param name causes some problems - - //TODO integrate in build... - public static void main(String[] args) throws FileNotFoundException, IOException { - String path = "/home/mbien/NetBeansProjects/JOGL/jocl/resources/includes/CL/"; - uncomment(path + "cl.h", false); - uncomment(path + "cl_gl.h", false); + private String src; + private String dest; + + @Override + public void execute() throws BuildException { + try { + uncomment(src, dest, true); + } catch (FileNotFoundException ex) { + throw new BuildException(ex); + } catch (IOException ex) { + throw new BuildException(ex); + } } - private static void uncomment(String file, boolean replace) throws FileNotFoundException, IOException { + private final void uncomment(String srcFile, String destFile, boolean replace) throws FileNotFoundException, IOException { - System.out.println("- - - begin uncomment - - -"); + System.out.println("uncommenting params in "+srcFile); - StringBuilder src = readSourceFile(new File(file)); - Matcher matcher = PARAMS_PATTERN.matcher(src); + StringBuilder headerSrc = readSourceFile(new File(srcFile)); + Matcher matcher = PARAMS_PATTERN.matcher(headerSrc); // iterate through funcions while (matcher.find()) { @@ -60,23 +69,21 @@ public class FunctionParamUncommenter { } //replace old params with uncommented params - src.replace(matcher.start(1), matcher.end(1), params.toString()); + headerSrc.replace(matcher.start(1), matcher.end(1), params.toString()); } if(replace) { //replace old file - BufferedWriter out = new BufferedWriter(new FileWriter(file)); - out.write(src.toString()); + BufferedWriter out = new BufferedWriter(new FileWriter(destFile)); + out.write(headerSrc.toString()); out.close(); }else{ - System.out.println(src); + System.out.println(headerSrc); } - - System.out.println("- - - done - - -"); } - private static StringBuilder readSourceFile(File file) throws FileNotFoundException, IOException { + private final StringBuilder readSourceFile(File file) throws FileNotFoundException, IOException { char[] buffer = new char[(int)file.length()]; FileReader reader = new FileReader(file); @@ -91,4 +98,12 @@ public class FunctionParamUncommenter { return sb; } + public void setSrc(String src) { + this.src = src; + } + + public void setDest(String dest) { + this.dest = dest; + } + } |