]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/mkcommandlist.pl
Added built-in help support.
[irc/quakenet/newserv.git] / chanserv / mkcommandlist.pl
CommitLineData
1dd6d55d 1#!/usr/bin/perl -w
2
3use strict;
4
5my @cmdnames;
6my @cmdlevels;
7my @cmdargs;
8my @cmddesc;
9my @cmdfunc;
10my @protos;
11my @files;
12
13my @filelist = <*.c>;
14
15my $modname;
16
17unless (@ARGV) {
18 print "Usage: $0 <module name>\n";
19 exit(0);
20} else {
21 $modname=$ARGV[0];
22}
23
24for (@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
74if (@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
81open CL, ">commandlist.c";
82
83print CL "/* Automatically generated by mkcommandlist.pl, do not edit. */\n\n";
84print CL "#include \"../chanserv.h\"\n\n";
85
86# Print prototypes
87print CL "/* Prototypes */\n";
88foreach (@protos) {
89 print CL "$_\n";
90}
91
92my @names2 = @cmdnames;
93my @func2 = @cmdfunc;
94
95print CL "\nvoid _init() {\n";
96
97while (my $cn = shift @cmdnames) {
98 print CL " chanservaddcommand(\"".$cn."\", ".(shift @cmdlevels).", ".(shift @cmdargs).", ";
1f0d7c8b 99 print CL (shift @cmdfunc).", \"".(shift @cmddesc)."\", \"\");\n";
1dd6d55d 100}
101
102print CL "}\n\nvoid _fini() {\n";
103
104while (my $cn = shift @names2) {
105 print CL " chanservremovecommand(\"".$cn."\", ".(shift @func2).");\n";
106}
107
108print CL "}\n";
109
110close CL;
111
112open MF,">Makefile";
113
114print MF "# Automatically generated Makefile, do not edit.\n\n";
115
116print MF ".PHONY: all Makefile\n";
117
118print MF "all: Makefile $modname\n\n";
119
120print MF "Makefile:\n";
121print MF "\t../mkcommandlist.pl $modname\n";
122
123print MF "\n$modname: ";
124
125push @files,"commandlist.c";
126
127foreach (@files) {
128 s/.c$/.o/;
129 print MF "$_ ";
130}
131
132print MF "\n";
133print MF "\t ld -shared -Bdynamic -o \$\@ \$\^ \n";
134
135close MF;