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