Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added awk script that exports important C/C++ enums to the Java interface/wrapper #31

Closed
wants to merge 1 commit into from

3 participants

@gajop
Collaborator

Added awk script that exports important C/C++ enums (CommandTopic and UnitCommandOptions) to the Java interface and wrapper.

@gajop gajop Added awk script that exports important C/C++ enums (CommandTopic and…
… UnitCommandOptions) to the Java interface and wrapper
e97ec58
@abma
Owner

@hoijui @gajop:
any update on this?

@hoijui

no. still needs CMake integration. i said i would do it but did not yet :/

@abma abma referenced this pull request from a commit
@abma abma fix merge of pull request #31 6dc1e0b
@abma
Owner

sadly its broken for mawk, so merged but disabled. see:
0529ae3

with gawk it works fine

@abma abma closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 15, 2012
  1. @gajop

    Added awk script that exports important C/C++ enums (CommandTopic and…

    gajop authored
    … UnitCommandOptions) to the Java interface and wrapper
This page is out of date. Refresh to see the latest.
View
21 AI/Interfaces/Java/bin/build.xml
@@ -148,10 +148,29 @@
<arg value="${spring.ai.interface.home}/AISEvents.h"/>
</exec>
+ </target>
+
+
+ <target name="generate-src-commands" depends="generate-init">
+ <exec dir="${bin.dir}" executable="${awk.bin}"
+ failonerror="true" resolveexecutable="true" searchpath="true">
+ <arg value="-v"/><arg value="SPRING_SOURCE_DIR=${spring.home}"/>
+ <arg value="-v"/><arg value="INTERFACE_SOURCE_DIR=${src.java}"/>
+ <arg value="-v"/><arg value="GENERATED_SOURCE_DIR=${src.generated}"/>
+ <arg value="-v"/><arg value="NATIVE_GENERATED_SOURCE_DIR=${src.generated.native}"/>
+ <arg value="-v"/><arg value="JAVA_GENERATED_SOURCE_DIR=${src.generated.java}"/>
+
+ <arg value="-f"/><arg value="${awk.common.scripts.dir}/common.awk"/>
+ <arg value="-f"/><arg value="${awk.common.scripts.dir}/commonDoc.awk"/>
+
+ <arg value="-f"/><arg value="jni_wrappCommands.awk"/>
+
+ <arg value="${spring.ai.interface.home}/AISCommands.h"/>
+ </exec>
</target>
<target name="generate-src"
- depends="generate-src-events, generate-src-callback"/>
+ depends="generate-src-events, generate-src-callback, generate-src-commands"/>
<target name="compile" depends="generate-src">
View
184 AI/Interfaces/Java/bin/jni_wrappCommands.awk
@@ -0,0 +1,184 @@
+#!/usr/bin/awk -f
+#
+# This awk script creates a Java class containing important enumerations.
+# These enumerations are taken from: rts/ExternalAI/Interface/AISCommands.h
+# It currently only takes CommandTopic and UnitCommandOptions enumerations
+#
+# This script uses functions from the following files:
+# * common.awk
+# * commonDoc.awk
+# Variables that can be set on the command-line (with -v):
+# * GENERATED_SOURCE_DIR: the generated sources root dir
+#
+# usage:
+# awk -f thisScript.awk -f common.awk -f commonDoc.awk
+# awk -f thisScript.awk -f common.awk -f commonDoc.awk \
+# -v 'GENERATED_SOURCE_DIR=/tmp/build/AI/Interfaces/Java/src-generated/main'
+#
+
+BEGIN {
+ # initialize things
+
+ # define the field splitter(-regex)
+ FS = "[ \t]+";
+
+ # Used by other scripts
+ JAVA_MODE = 1;
+
+ # These vars can be assigned externally, see file header.
+ # Set the default values if they were not supplied on the command line.
+ if (!GENERATED_SOURCE_DIR) {
+ GENERATED_SOURCE_DIR = "../src-generated/main";
+ }
+ if (!JAVA_GENERATED_SOURCE_DIR) {
+ JAVA_GENERATED_SOURCE_DIR = GENERATED_SOURCE_DIR "/java";
+ }
+ if (!NATIVE_GENERATED_SOURCE_DIR) {
+ NATIVE_GENERATED_SOURCE_DIR = GENERATED_SOURCE_DIR "/native";
+ }
+
+ myPkgA = "com.springrts.ai";
+ myPkgD = convertJavaNameFormAToD(myPkgA);
+ myClass = "Enumerations";
+
+ #create empty arrays, holding names and values of the two enumerations
+ split("", cmdsTopicNames);
+ split("", cmdsTopicValues);
+ split("", unitCmdsTopicNames);
+ split("", unitCmdsTopicValues);
+}
+
+
+function createJavaFileName(fileName_fn) {
+ return JAVA_GENERATED_SOURCE_DIR "/" myPkgD "/" fileName_fn ".java";
+}
+
+function printGeneralJavaHeader(outFile_h, javaPkg_h, javaClassName_h) {
+
+ printCommentsHeader(outFile_h);
+ print("") >> outFile_h;
+ print("package " javaPkg_h ";") >> outFile_h;
+ print("") >> outFile_h;
+ print("") >> outFile_h;
+ print("/**") >> outFile_h;
+ print(" * These are the Java exposed enumerations.") >> outFile_h;
+ print(" * We are not calling the engine, this is a pure Java class.") >> outFile_h;
+ print(" *") >> outFile_h;
+ print(" * @author AWK wrapper script") >> outFile_h;
+ print(" * @version GENERATED") >> outFile_h;
+ print(" */") >> outFile_h;
+ print("public abstract class " javaClassName_h " {") >> outFile_h;
+ print("") >> outFile_h;
+}
+
+function printJavaHeader() {
+
+ outFile_i = createJavaFileName(myClass);
+
+ printGeneralJavaHeader(outFile_i, myPkgA, myClass);
+}
+
+function printJavaEnums(enums) {
+ printJavaEnum("CommandTopic", cmdsTopicNames, cmdsTopicValues);
+ print("") >> outFile_i;
+ printJavaEnum("UnitCommandOptions", unitCmdsTopicNames, unitCmdsTopicValues);
+}
+
+function printJavaEnum(enumName, names, values) {
+ outFile_i = createJavaFileName(myClass);
+ printEnumHeader(enumName);
+
+ # Prints the enum members and values
+ first = 0;
+ for (i=0; i<length(names);i++) {
+ if (first == 0) {
+ first = 1;
+ printf("\t\t") >> outFile_i;
+ } else {
+ printf(",\n\t\t") >> outFile_i;
+ }
+ printJavaEnumItem(names[i], values[i]);
+ }
+
+ if (first != 0) {
+ print(";\n") >> outFile_i;
+ }
+ printEnumEnd(enumName);
+}
+
+function printEnumHeader(name) {
+ outFile_i = createJavaFileName(myClass);
+
+ # Prints the enum start
+ print("\tpublic enum " name " {") >> outFile_i;
+}
+
+function printEnumEnd(name) {
+ outFile_i = createJavaFileName(myClass);
+
+ # Prints the enum end
+ print("\t\tprivate final int id;") >> outFile_i;
+ print("\t\t" name "(int id) { this.id = id; }") >> outFile_i;
+ print("\t\tpublic int getValue() { return id; }") >> outFile_i;
+ print("\t}") >> outFile_i;
+}
+
+function printJavaEnumItem(key, value) {
+ printf(key "(" value ")") >> outFile_i;
+}
+
+function printJavaEnd() {
+
+ outFile_i = createJavaFileName(myClass);
+
+ print("}") >> outFile_i;
+ print("") >> outFile_i;
+
+ close(outFile_i);
+}
+
+/^[ \t]*COMMAND_.*$/ {
+
+ doWrapp = !match(($0), /.*COMMAND_NULL.*/);
+ if (doWrapp) {
+ #parse enumeration of format x = number1,
+ sub(",", "", $4);
+ cmdsTopicNames[length(cmdsTopicNames)] = $2;
+ cmdsTopicValues[length(cmdsTopicValues)] = $4;
+ } else {
+ print("Java-AIInterface: NOTE: JNI level: COMMANDS: intentionally not wrapped: " $2);
+ }
+}
+
+/^[ \t]*UNIT_COMMAND_.*$/ {
+ doWrapp = !match(($0), /.*COMMAND_NULL.*/);
+ if (doWrapp) {
+ unitCmdsTopicNames[length(unitCmdsTopicNames)] = $2;
+ #parse enumeration of format x = (number1 << number2),
+ sub("[ \t]*//.*", "", $0);
+ sub(",", "", $0);
+ sub($3, "", $0);
+ sub($2, "", $0);
+ sub("[ \t]*", "", $0);
+ unitCmdsTopicValues[length(unitCmdsTopicValues)] = $0;
+ } else {
+ print("Java-AIInterface: NOTE: JNI level: UNIT_COMMANDS: intentionally not wrapped: " $2);
+ }
+}
+
+# This function has to return true (1) if a doc comment (eg: /** foo bar */)
+# can be deleted.
+# If there is no special condition you want to apply,
+# it should always return true (1),
+# cause there are additional mechanism to prevent accidential deleting.
+# see: commonDoc.awk
+function canDeleteDocumentation() {
+ return isInsideEvtStruct != 1;
+}
+
+END {
+ # finalize things
+ printJavaHeader();
+ printJavaEnums();
+ printJavaEnd();
+}
View
2  AI/Wrappers/JavaOO/bin/build.xml
@@ -130,6 +130,8 @@
<target name="compile" depends="generate-src">
+ <copy file="${spring.ai.interface.src.generated.dir}/${java.pkg.dir}/Enumerations.java" todir="${src.generated.java}/${java.pkg.oo.dir}"/>
+ <replace file="${src.generated.java}/${java.pkg.oo.dir}/Enumerations.java" token="com.springrts.ai;" value="com.springrts.ai.oo;"/>
<javac destdir="${classes.dir}">
<src refid="source.path.id"/>
<classpath refid="class.path.id"/>
Something went wrong with that request. Please try again.