diff options
author | Michael Bien <[email protected]> | 2009-09-23 01:32:54 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2009-09-23 01:32:54 +0200 |
commit | 0ac4a12fb74de16f41ee9ad46e917b45523bbac4 (patch) | |
tree | d9072115c60805c0f50df2ae4cd90227e6c10cea /etc | |
parent | 8ba956a7df1b98ed2957a932debfce4c6d4cb848 (diff) |
splitted binding in core (CL) and CL-GL interop. (CLGLI)
began with custom impl. for functions with c -> java callbacks
added an utility which uncomments function parameter names in headers
Diffstat (limited to 'etc')
-rw-r--r-- | etc/FunctionParamUncommenter.java | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/etc/FunctionParamUncommenter.java b/etc/FunctionParamUncommenter.java new file mode 100644 index 00000000..e774121f --- /dev/null +++ b/etc/FunctionParamUncommenter.java @@ -0,0 +1,94 @@ + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import static java.util.regex.Pattern.*; + +/** + * Build setup utility. Uncomments funcion param names in header files. + * + * before: + * foo(int /x bar x/ ) + * + * after: + * foo(int bar ) + * + * @author Michael Bien + */ +public class FunctionParamUncommenter { +//(\(.*\))* cl\w+\(([^\)]+)\) + +// final static String x = "\\s*(const)?\\w+\\s* \\**\\s+ (/\\*) \\s+[^\\*]+ (\\*/)"; + + final static Pattern PARAMS_PATTERN + = compile("cl\\w+ \\( ( \\s* [^\\)]+ ) \\)", MULTILINE|COMMENTS); + + final static Pattern COMMENT_PATTERN + = compile("\\s*(const)?\\w+\\s* \\**\\s+ (/\\*) \\s+[^\\*]+ (\\*/)", MULTILINE|COMMENTS); + + public static void main(String[] args) throws FileNotFoundException, IOException { + uncomment("/home/mbien/NetBeansProjects/JOGL/jocl/resources/CL/cl.h", false); + uncomment("/home/mbien/NetBeansProjects/JOGL/jocl/resources/CL/cl_gl.h", false); + } + + private static void uncomment(String file, boolean replace) throws FileNotFoundException, IOException { + + System.out.println("- - - begin uncomment - - -"); + + StringBuilder src = readSourceFile(new File(file)); + Matcher matcher = PARAMS_PATTERN.matcher(src); + + // iterate through funcions + while (matcher.find()) { + + StringBuilder params = new StringBuilder(matcher.group(1)); +// System.out.println("- - - - "); +// System.out.println(params.toString()); +// System.out.println("- - - - "); + + //iterate through params + Matcher m = COMMENT_PATTERN.matcher(params); + while(m.find()) { + //uncomment param + params.replace(m.start(2), m.end(2), " "); + params.replace(m.start(3), m.end(3), " "); + } + + //replace old params with uncommented params + src.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()); + out.close(); + }else{ + System.out.println(src); + } + + System.out.println("- - - done - - -"); + } + + + private static StringBuilder readSourceFile(File file) throws FileNotFoundException, IOException { + + char[] buffer = new char[(int)file.length()]; + FileReader reader = new FileReader(file); + int length = reader.read(buffer); + if(reader != null) { + reader.close(); + } + + StringBuilder sb = new StringBuilder(); + sb.append(buffer, 0, length); + + return sb; + } + +} |