]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 1 | #!/usr/bin/perl -w |
2 | ||
3 | my @includes; | |
4 | ||
5 | my %cmdnames; | |
6 | my %cmdlevels; | |
7 | my %cmdargs; | |
8 | my %cmddesc; | |
9 | my %protos; | |
10 | ||
11 | my $infunc = 0; | |
12 | ||
13 | while (<>) { | |
14 | chomp; | |
15 | ||
16 | if (/^#include (.*)$/) { | |
17 | # print "Adding include: $1\n"; | |
18 | push @includes, $1; | |
19 | next; | |
20 | } | |
21 | ||
22 | if (/chanservaddcommand\((.*)\)/) { | |
23 | # print "Found \"addcommand\" stanza\n"; | |
24 | my $args=$1; | |
25 | ||
26 | unless ($args =~ m!^\s*"([^"]+)"\s*,\s*([^,]+?)\s*,\s*(\d+)\s*,\s*([^, ]+)\s*,\s*"([^"]+)! ) { | |
27 | print "Can't decode addcommand() args: $args\n"; | |
28 | next; | |
29 | } | |
30 | # print "Command function is: $4\n"; | |
31 | ||
32 | $cmdnames{$4} = $1; | |
33 | $cmdlevels{$4} = $2; | |
34 | $cmdargs{$4} = $3; | |
35 | $cmddesc{$4} = $5; | |
36 | } | |
37 | ||
38 | if (/^int (.*?)\(.*;/) { | |
39 | print "Found prototype for function: $1\n"; | |
40 | $protos{$1}=$_; | |
41 | } | |
42 | ||
43 | if (/^int (\S+)\s*\(.*{/) { | |
44 | print "Found start of function declaration: $1\n"; | |
45 | unless (defined $cmdnames{$1}) { | |
46 | print "Found function $1 without definition, skipping ...\n"; | |
47 | next; | |
48 | } | |
49 | ||
50 | my $fname = $cmdnames{$1}.".c"; | |
51 | ||
52 | open CMDF, ">".$fname; | |
53 | ||
54 | print CMDF "/* Automatically generated by refactor.pl.\n *\n *\n"; | |
55 | print CMDF " * CMDNAME: $cmdnames{$1}\n"; | |
56 | print CMDF " * CMDLEVEL: $cmdlevels{$1}\n"; | |
57 | print CMDF " * CMDARGS: $cmdargs{$1}\n"; | |
58 | print CMDF " * CMDDESC: $cmddesc{$1}\n"; | |
59 | print CMDF " * CMDFUNC: $1\n"; | |
60 | print CMDF " * CMDPROTO: $protos{$1}\n"; | |
61 | print CMDF " */\n\n"; | |
62 | ||
63 | for (@includes) { | |
64 | print CMDF "#include $_\n"; | |
65 | } | |
66 | ||
67 | print CMDF "\n"; | |
68 | print CMDF "$_\n"; | |
69 | ||
70 | $infunc=1; | |
71 | next; | |
72 | } | |
73 | ||
74 | if ($infunc) { | |
75 | print CMDF "$_\n"; | |
76 | if (/^}/) { | |
77 | close CMDF; | |
78 | $infunc=0; | |
79 | } | |
80 | } | |
81 | } |