]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/mkcommandlist.pl
224ded30c4224bfad0d52f985f718be7c48f3023
[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 for (@filelist) {
26 next if (/commandlist.c/);
27
28 my $fname = $_;
29 my ($cn, $cl, $ca, $cd, $cf, $cp, $ch);
30 $ch="";
31
32 open INFILE,"<$fname";
33
34 while(<INFILE>) {
35 chomp;
36
37 if (/CMDNAME: (.*)/) {
38 $cn=$1;
39 }
40
41 if (/CMDLEVEL: (.*)/) {
42 $cl=$1;
43 }
44
45 if (/CMDARGS: (.*)/) {
46 $ca=$1;
47 }
48
49 if (/CMDDESC: (.*)/) {
50 $cd=$1;
51 }
52
53 if (/CMDFUNC: (.*)/) {
54 $cf=$1;
55 }
56
57 if (/CMDPROTO: (.*)/) {
58 $cp=$1;
59 }
60
61 if (/CMDHELP: (.*)/) {
62 $ch.=$1."\\n";
63 }
64 }
65
66 if (defined $cn and defined $cl and defined $ca and defined $cd and defined $cf and defined $cp) {
67 # valid command found
68 push @files, $fname;
69 push @cmdnames, $cn;
70 push @cmdlevels, $cl;
71 push @cmdargs, $ca;
72 push @cmddesc, $cd;
73 push @cmdfunc, $cf;
74 push @protos, $cp;
75 push @help, $ch;
76 } else {
77 print "Warning: found source file $fname without complete tags, skipping...\n";
78 }
79 }
80
81 if (@files < 1) {
82 print "No commands found - are you in the right directory?\n";
83 print "Exiting before I destroy something important.\n";
84 exit(0);
85 }
86
87
88 open CL, ">commandlist.c";
89
90 print CL "/* Automatically generated by mkcommandlist.pl, do not edit. */\n\n";
91 print CL "#include \"../chanserv.h\"\n\n";
92
93 # Print prototypes
94 print CL "/* Prototypes */\n";
95 foreach (@protos) {
96 print CL "$_\n";
97 }
98
99 my @names2 = @cmdnames;
100 my @func2 = @cmdfunc;
101
102 print CL "\nvoid _init() {\n";
103
104 while (my $cn = shift @cmdnames) {
105 print CL " chanservaddcommand(\"".$cn."\", ".(shift @cmdlevels).", ".(shift @cmdargs).", ";
106 print CL (shift @cmdfunc).", \"".(shift @cmddesc)."\", \"".(shift @help),"\");\n";
107 }
108
109 print CL "}\n\nvoid _fini() {\n";
110
111 while (my $cn = shift @names2) {
112 print CL " chanservremovecommand(\"".$cn."\", ".(shift @func2).");\n";
113 }
114
115 print CL "}\n";
116
117 close CL;
118
119 open MF,">Makefile";
120
121 print MF "# Automatically generated Makefile, do not edit.\n\n";
122
123 print MF ".PHONY: all Makefile\n";
124
125 print MF "all: Makefile $modname\n\n";
126
127 print MF "Makefile:\n";
128 print MF "\t../mkcommandlist.pl $modname\n";
129
130 print MF "\n$modname: ";
131
132 push @files,"commandlist.c";
133
134 foreach (@files) {
135 s/.c$/.o/;
136 print MF "$_ ";
137 }
138
139 print MF "\n";
140 print MF "\t ld -shared -Bdynamic -o \$\@ \$\^ \n";
141
142 close MF;