]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/mkcommandlist.pl
trusts changes
[irc/quakenet/newserv.git] / chanserv / mkcommandlist.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my @cmdnames;
6 my @cmdlevels;
7 my @cmdargs;
8 my @cmddesc;
9 my @cmdfunc;
10 my @protos;
11 my @files;
12 my @help;
13
14 my @filelist = <*.c>;
15
16 my $modname;
17
18 unless (@ARGV) {
19 print "Usage: $0 <module name>\n";
20 exit(0);
21 } else {
22 $modname=$ARGV[0];
23 }
24
25 my $smallname;
26 $smallname=$modname;
27 $smallname=~s/\.so$//;
28
29 my $cname;
30 $cname=$smallname . ".c";
31 $smallname=~s/^chanserv_//;
32
33
34 for (@filelist) {
35 next if (/commandlist.c/);
36 next if ($_ eq $cname);
37
38 my $fname = $_;
39 my ($cn, $cl, $ca, $cd, $cf, $cp, $ch);
40 $ch="";
41
42 open INFILE,"<$fname";
43
44 while(<INFILE>) {
45 chomp;
46
47 if (/CMDNAME: (.*)/) {
48 $cn=$1;
49 }
50
51 if (/CMDLEVEL: (.*)/) {
52 $cl=$1;
53 }
54
55 if (/CMDARGS: (.*)/) {
56 $ca=$1;
57 }
58
59 if (/CMDDESC: (.*)/) {
60 $cd=$1;
61 }
62
63 if (/CMDFUNC: (.*)/) {
64 $cf=$1;
65 }
66
67 if (/CMDPROTO: (.*)/) {
68 $cp=$1;
69 }
70
71 if (/CMDHELP: (.*)/) {
72 $ch.=$1."\\n";
73 }
74 }
75
76 if (defined $cn and defined $cl and defined $ca and defined $cd and defined $cf and defined $cp) {
77 # valid command found
78 push @files, $fname;
79 push @cmdnames, $cn;
80 push @cmdlevels, $cl;
81 push @cmdargs, $ca;
82 push @cmddesc, $cd;
83 push @cmdfunc, $cf;
84 push @protos, $cp;
85 push @help, $ch;
86 } else {
87 print "Warning: found source file $fname without complete tags, skipping...\n";
88 }
89 }
90
91 if (@files < 1) {
92 print "No commands found - are you in the right directory?\n";
93 print "Exiting before I destroy something important.\n";
94 exit(0);
95 }
96
97
98 open CL, ">commandlist.c";
99
100 print CL "/* Automatically generated by mkcommandlist.pl, do not edit. */\n\n";
101 print CL "#include \"../chanserv.h\"\n\n";
102
103 # Print prototypes
104 print CL "/* Prototypes */\n";
105 foreach (@protos) {
106 print CL "$_\n";
107 }
108
109 my @names2 = @cmdnames;
110 my @func2 = @cmdfunc;
111
112 print CL "void ".$smallname."_init(void);\n";
113 print CL "void ".$smallname."_fini(void);\n\n";
114
115 print CL "\nvoid _init() {\n";
116 print CL " ".$smallname."_init();\n";
117
118 while (my $cn = shift @cmdnames) {
119 print CL " chanservaddcommand(\"".$cn."\", ".(shift @cmdlevels).", ".(shift @cmdargs).", ";
120 print CL (shift @cmdfunc).", \"".(shift @cmddesc)."\", \"".(shift @help),"\");\n";
121 }
122
123 print CL "}\n\nvoid _fini() {\n";
124 print CL " ".$smallname."_fini();\n";
125
126 while (my $cn = shift @names2) {
127 print CL " chanservremovecommand(\"".$cn."\", ".(shift @func2).");\n";
128 }
129
130 print CL "}\n";
131
132 close CL;
133
134 open MF,">autobuild.mk";
135
136 print MF "# Automatically generated Makefile, do not edit.\n";
137
138 print MF "\n$modname: ";
139
140 push @files,"commandlist.c";
141
142 push @files,$cname;
143
144 foreach (@files) {
145 s/.c$/.o/;
146 print MF "$_ ";
147 }
148
149 print MF "\n";
150
151 close MF;