📄 parserm84cmn.pl
字号:
#!/usr/bin/perlmy $type_file;my $out_file;sub parse_args { if (scalar @ARGV != 2) { print "parserm84cmn: <typedef file> <out file>\n"; print "\ttypedef file : file containing all the enum properties\n"; print "\tout file : generated file\n"; exit(1); } else { $type_file = $ARGV[0]; $out_file = $ARGV[1]; } }# sub parsedefines# {# open F, $def_file;# while (<F>) {# if (/^\#define\s+(\w+)\s*(\w*)$/) {# my $macro = $1;# my $value = $2;# if ($macro =~ /RMDISABLE_(\w+)/) {# $prop{$1} = "disable";# }# elsif ($macro =~ /(\w+)_RMuint32_(\d+)_(\d+)/) {# $prop{$1} = "(RMuint32)\t[$2,$3]";# }# elsif ($macro =~ /(\w+)_(\w+)/) {# $key = $1;# $setval = $2;# if (!exists $prop{$key}) {# $prop{$key} = "set\t{}";# }# if ($value =~ /\w+/) {# $prop{$key} =~ s/}/, \"$setval\"}/;# $prop{$key} =~ s/{, /{/;# }# }# }# else {# push @lines, $_;# }# }# close F;# }sub parsetypes { my $state=0; ## state value ## ## 0 look for typedef ## 1 inside a typedef and look for } my $in_comment = 0; my $in_doxygen_comment = 0; my $status = system "touch $out_file"; if ($status != 0) { exit 1; } open G, $type_file; open F, ">$out_file"; while (<G>) { ## output all /** ... */ doxygen comment in one line if (/\/\*\* .*\*\//) { if ($state == 1) { $doxy = $_; } next; } ## output /** ... */ doxygen comment in multiple lines if ($in_doxygen_comment == 0) { if (/\/\*\* .*$/) { $in_doxygen_comment = 1; $doxy = $_; } } elsif (/.*\*\//) { $in_doxygen_comment = 0; $doxy .= $_; } else { $doxy .= $_; next; } ## remove // coments s/\/\/.*$//; ## remove all /* ... */ comments in one line while (s/\/\*.*\*\///) { } ## remove /* in multiple lines if ($in_comment == 0) { if (s/\/\*.*$//) { $in_comment = 1; } } elsif (s/.*\*\///) { $in_comment = 0; } else { next; } ## look for the token << typedef enum >> if ($state == 0) { if (s/\s*typedef\s+enum\s*{//) { $state = 1; next; } } ## look for << } name ; >> if ($state == 1) { if (/}\s*(\w+)_ID\s*;/) { $state = 0; $sub_set = $1; @elts = split ',', $elt_list; foreach $i (@elts) { $doxy = $doxy_comment{$i}; print F $doxy; print F "RM_DEFINE_FULL_PROPERTY(HWLIB, $sub_set, $i)\n"; } print F "\n/*****************************************************/\n\n"; $elt_list = ""; %doxy_comment = (); } elsif (/}\s*(\w+)\s*;/) { $state = 0; $elt_list = ""; %doxy_comment = (); } else { ## remove #defines lines s/^\s*\#define\s+.*$//; ## remove = value s/=\s*\d+//; ## remove leading white spaces s/^\s*//; ## remove trailing white spaces s/\s*$//; ## remove spaces between word and comma s/\s*,/,/; ## if there is an enum insert it if (/\w+/) { $elt_list .= $_; $key = $_; $key =~ y/,//d; $doxy_comment{$key} = $doxy; $doxy = ""; } } } } close F; }parse_args();parsetypes();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -