Browse Source

trunk->1.0: merged [169] [187], fix the parsing of c headers to build on some rare header

git-svn-id: svn://svn.lighttpd.net/xcache/branches/1.0@237 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
1.0
Xuefer 15 years ago
parent
commit
d8097b10e0
  1. 61
      mkstructinfo.awk

61
mkstructinfo.awk

@ -2,8 +2,35 @@
# vim:ts=4:sw=4
BEGIN {
brace = 0;
incomment = 0;
buffer_len = 0;
}
# multiline comment handling
{
# removes one line comment
gsub(/\/\*(.+?)\*\//, " ");
}
/\*\// {
if (incomment) {
sub(/.*\*\//, "");
incomment = 0;
}
}
incomment {
next;
}
/\/\*/ {
sub(/\/\*.*/, "");
incomment = 1;
# fall through
}
# skip file/line mark here to be faster
/^#/ {
next;
}
/^}.*;/ {
if (instruct) {
sub(";", "");
@ -50,6 +77,7 @@ BEGIN {
{
if (brace == 1 && instruct) {
gsub(/(^[\t ]+|[\t ]+$)/, ""); # trim whitespaces
sub(/.*[{}]/, "");
gsub(/\[[^\]]+\]/, ""); # ignore [...]
gsub(/:[0-9]+/, ""); # ignore struct bit
@ -62,38 +90,57 @@ BEGIN {
buffer_len ++;
}
else {
# process normal variables
# ignore any ()s
while (gsub(/(\([^)]*\))/, "")) {
}
if (match($0, /[()]/)) {
next;
}
# unsigned int *a, b; int c;
gsub(/[*]/, " ");
# unsigned int a, b; int c;
gsub(/ +/, " ");
# unsigned int a, b; int c;
gsub(/ *[,;]/, ";");
# unsigned int a; b; int c;
if (!match($0, /;/)) {
next;
}
# print "=DEBUG=" $0 "==";
split($0, chunks, ";");
# get var of "int *var, var;" etc
for (i in chunks) {
# [unsigned int a, b, c]
for (i = 1; i in chunks; i ++) {
if (chunks[i] == "") {
delete chunks[i];
continue;
}
split(chunks[i], pieces, " ");
# [unsigned, int, a]
# [b]
# [c]
for (j in pieces) {
last_piece = "";
for (j = 1; j in pieces; j ++) {
last_piece = pieces[j];
delete pieces[i];
delete pieces[j];
}
if (last_piece == "") {
print "=====" chunks[i];
# print "=ERROR=" chunks[i] "==";
delete chunks[i];
continue;
}
# a
# b
# c
buffer[buffer_len] = last_piece;
buffer_len ++;
delete chunks[i];
delete chunks[i]
}
last_piece = "";
}
next;
}
@ -104,7 +151,7 @@ BEGIN {
typedefs[$3] = $4;
next;
}
/^typedef struct .*\{/ {
/^typedef struct .*\{[^}]*$/ {
brace = 1;
instruct = 1;
next;

Loading…
Cancel
Save