1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#!/usr/bin/awk -f
#
# This awk script creates function impls that can be used in the C callbacks
# with some little adjustments; eg:
# rts/ExternalAI/SSkirmishAICallbackImpl.cpp
# rts/ExternalAI/SAIInterfaceCallbackImpl.cpp
#
# Accepts input like this:
# [code]
# bool allowTeamColors;
#
# // construction related fields
# /// Should constructions without builders decay?
# bool constructionDecay;
# [/code]
#
# use like this:
# awk -f yourScript.awk -f common.awk -f commonDoc.awk [additional-params]
# this should work with all flavours of AWK (eg. gawk, mawk, nawk, ...)
#
BEGIN {
# initialize things
# define the field splitter(-regex)
#FS="[ \t]+"
# 0 -> print impl
# 1 -> print impl header
# 2 -> print interface header
printingHeader = 1;
}
function getCType(gct_type) {
if (match(gct_type, /string/)) {
return "const char* const";
} else {
return gct_type;
}
}
function getToCTypeConv(gtctc_type) {
if (match(gtctc_type, /string/)) {
return ".c_str()";
} else {
return "";
}
}
function getFuncPrefix(gfp_type) {
#if (match(gfp_type, /bool/)) {
# return "is";
#} else {
return "get";
#}
}
function printFunc(pf_fieldName, pf_type, pf_header) {
pf_cType = getCType(pf_type);
pf_toCTypeConv = getToCTypeConv(pf_type);
pf_funcPrefix = getFuncPrefix(pf_type);
if (pf_header == 2 && hasStoredDoc()) {
printStoredDoc("");
}
if (pf_header != 0) {
pf_firstLineEnd = ";";
pf_sizeToFill = length("const char* const") - length(pf_cType);
if (pf_sizeToFill < 0) {
pf_sizeToFill = 0;
}
pf_filler = "";
for (pf_i = 0; pf_i < pf_sizeToFill; pf_i++) {
pf_filler = pf_filler " ";
}
} else {
pf_firstLineEnd = " {";
pf_filler = "";
}
if (pf_header == 2) {
print(pf_cType pf_filler " (CALLING_CONV *PreFixName_" pf_funcPrefix capitalize(pf_fieldName) ")(int teamId)" pf_firstLineEnd);
} else {
print("EXPORT(" pf_cType pf_filler ") PreFixName_" pf_funcPrefix capitalize(pf_fieldName) "(int teamId)" pf_firstLineEnd);
}
if (!pf_header) {
print("\t" "return modInfo->" pf_fieldName pf_toCTypeConv ";");
print("}");
}
}
# needed by commonDoc.awk
function canDeleteDocumentation() {
return 1;
}
{
line = trim($0);
if (line == "") {
print(line);
} else if (!isInsideDoc()) {
sub(/\;$/, "", line);
name = line;
sub(/^.*[ \t]/, "", name);
cppType = line;
sub(name, "", cppType);
cppType = rtrim(cppType);
printFunc(name, cppType, printingHeader);
}
}
END {
# finalize things
}
|