📄 struct2desc
字号:
#!/usr/bin/perluse strict;my %mapit = ( "int" => "SINT32", "__s32" => "SINT32", "__u32" => "UINT32", "__s16" => "SINT16", "__u16" => "UINT16", "__s8" => "SINT8", "__u8" => "UINT8",);my $struct = 0;my $enum = 0;while (my $line = <>) { # start of struct if ($line =~ m/^struct\s+(\w+)/) { die "--\n$line\nstruct is 1" if $struct == 1; $struct = 1; print "\n"; print "struct struct_desc desc_$1\[\] = {{\n"; next; } next if ($struct == 1 && $line =~ /^\{/); # end of struct if ($struct == 1 && $line =~ m/^\};/) { $struct = 0; print " .type = END_OF_LIST,\n"; print "}};\n"; next; } # struct elements if ($struct == 1 && $line =~ m/^\s+(int|__u32|__s32|__u16|__s16|__u8|__s8)\s+(\w+);/) { print " .type = $mapit{$1},\n"; print " .name = \"$2\",\n"; print "},{\n"; next; } if ($struct == 1 && $line =~ m/^\s+(char|__u8)\s+(\w+)\[(\d+)\];/) { print " .type = STRING,\n"; print " .name = \"$2\",\n"; print " .length = $3,\n"; print "},{\n"; next; } if ($struct == 1 && $line =~ m/^\s+enum\s+(\w+)\s+(\w+);/) { print " .type = ENUM,\n"; print " .name = \"$2\",\n"; print " .enums = desc_$1,\n"; print "},{\n"; next; } # start of enum if ($line =~ m/^enum\s+(\w+)/) { die "--\n$line\nenum is 1" if $enum == 1; $enum = 1; print "\n"; print "char desc_$1\[\] = {\n"; next; } # end of enum if ($enum == 1 && $line =~ m/^\};/) { $enum = 0; print "};\n"; next; } # enum elements if ($enum == 1 && $line =~ m/^\s+(\w+)/) { print " [$1] = \"$1\",\n"; next; } next if $line =~ m/#define/; next if $struct == 0; chomp $line; print "/* FIXME $line */\n";}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -