#!/usr/bin/perl use strict; open (fl,"src/mod/applications/mod_commands/mod_commands.c"); my $cont; { local $/ = undef; $cont = ; } close fl; my %DEFINES; my $reg_define = qr/[A-Za-z0-9_]+/; my $reg_function = qr/[A-Za-z0-9_]+/; my $reg_string_or_define = qr/(?:(?:$reg_define)|(?:"[^"]*"))/; #load defines while ($cont =~ / ^\s* \#define \s+ ($reg_define) \s+ \"([^"]*)\" /mgx){ warn "$1 is #defined multiple times" if ($DEFINES{$1}); $DEFINES{$1} = $2; } sub resolve_str_or_define($){ my ($str) = @_; if ($str =~ s/^"// && $str =~ s/"$//){ #if starts and ends with a quote strip them off and return the str return $str; } warn "Unable to resolve define: $str" if (! $DEFINES{$str}); return $DEFINES{$str}; } #parse commands while ($cont =~ / SWITCH_ADD_API \s* \( ([^,]+) #interface $1 ,\s* ($reg_string_or_define) # command $2 ,\s* ($reg_string_or_define) # command description $3 ,\s* ($reg_function) # function $4 ,\s* ($reg_string_or_define) # usage $5 \s*\); /sgx){ my ($interface,$command,$descr,$function,$usage) = ($1,$2,$3,$4,$5); $command = resolve_str_or_define($command); $descr = resolve_str_or_define($descr); $usage = resolve_str_or_define($usage); warn "Found a not command interface of: $interface for command: $command" if ($interface ne "commands_api_interface"); print "$command -- $descr -- $usage\n"; }