]> jfr.im git - irc/quakenet/newserv.git/blobdiff - chanserv/mkcommandlist.pl
A4STATS: remove E style escapes and switch to createtable for indices
[irc/quakenet/newserv.git] / chanserv / mkcommandlist.pl
index 180b4c0cecf421bc2361f4dfe8cd7f3924887fed..00f6bde6133d87559c83bc612f747cecaffb97d0 100755 (executable)
@@ -9,11 +9,15 @@ my @cmddesc;
 my @cmdfunc;
 my @protos;
 my @files;
+my @help;
+my @cmdaliases;
 
 my @filelist = <*.c>;
 
 my $modname;
 
+my %cmdhash;
+
 unless (@ARGV) {
   print "Usage: $0 <module name>\n";
   exit(0);
@@ -21,11 +25,30 @@ unless (@ARGV) {
   $modname=$ARGV[0];
 }
 
+my $rootpath;
+if($#ARGV >= 1) {
+  $rootpath=$ARGV[1];
+} else {
+  $rootpath="..";
+}
+
+my $smallname;
+$smallname=$modname;
+$smallname=~s/\.so$//;
+
+my $cname;
+$cname=$smallname . ".c";
+$smallname=~s/^chanserv_//;
+
+
 for (@filelist) {
   next if (/commandlist.c/);
+  next if ($_ eq $cname);
   
   my $fname = $_;
-  my ($cn, $cl, $ca, $cd, $cf, $cp);
+  my ($cn, $cl, $ca, $cd, $cf, $cp, $ch, $cal);
+  $ch="";
+  $cal="";
 
   open INFILE,"<$fname";
   
@@ -55,10 +78,20 @@ for (@filelist) {
     if (/CMDPROTO: (.*)/) {
       $cp=$1;
     }
+    
+    if (/CMDHELP: (.*)/) {
+      $ch.=$1."\\n";
+    }
+
+    if (/CMDALIASES: (.*)/) {
+      $cal=$1;
+    }
   }
   
   if (defined $cn and defined $cl and defined $ca and defined $cd and defined $cf and defined $cp) {
     # valid command found 
+    $cmdhash{$cn} = scalar @cmdnames;
+
     push @files, $fname;
     push @cmdnames, $cn;
     push @cmdlevels, $cl;
@@ -66,6 +99,8 @@ for (@filelist) {
     push @cmddesc, $cd;
     push @cmdfunc, $cf;
     push @protos, $cp;
+    push @help, $ch;
+    push @cmdaliases, $cal;
   } else {
     print "Warning: found source file $fname without complete tags, skipping...\n";
   }
@@ -81,7 +116,7 @@ if (@files < 1) {
 open CL, ">commandlist.c";
 
 print CL "/* Automatically generated by mkcommandlist.pl, do not edit. */\n\n";
-print CL "#include \"../chanserv.h\"\n\n";
+print CL "#include \"".$rootpath."/chanserv.h\"\n\n";
 
 # Print prototypes
 print CL "/* Prototypes */\n";
@@ -89,47 +124,86 @@ foreach (@protos) {
   print CL "$_\n";
 }
 
-my @names2 = @cmdnames;
-my @func2 = @cmdfunc;
+print CL "void ".$smallname."_init(void);\n";
+print CL "void ".$smallname."_fini(void);\n\n";
 
 print CL "\nvoid _init() {\n";
+print CL "  ".$smallname."_init();\n";
+
+sub generate_help_text {
+  my ($cn, $ch) = @_;
+
+  my %SUBS;
+
+  $SUBS{"COMMAND"} = $cn;
+  $SUBS{"UCOMMAND"} = uc($cn);
+
+  my %realsubs;
+  while(my ($key, $value) = each(%SUBS)) {
+    $key = '@'.quotemeta($key).'@';
+    $value = quotemeta($value);
+    $ch =~ s/$key/$value/g;
+  }
 
-while (my $cn = shift @cmdnames) {
-  print CL "  chanservaddcommand(\"".$cn."\", ".(shift @cmdlevels).", ".(shift @cmdargs).", ";
-  print CL (shift @cmdfunc).", \"".(shift @cmddesc)."\");\n";
+  return $ch;
 }
 
-print CL "}\n\nvoid _fini() {\n";
+sub writecmd {
+  my ($cn, $i, $isalias) = @_;
+
+  my $cl = $cmdlevels[$i];
+  if ($isalias) {
+    $cl .= " | " if ($cl ne "");
+    $cl .= "QCMD_ALIAS";
+  }
 
-while (my $cn = shift @names2) {
-  print CL "  chanservremovecommand(\"".$cn."\", ".(shift @func2).");\n";
+  print CL "  chanservaddcommand(\"".$cn."\", ".($cl).", ".($cmdargs[$i]).", ";
+  print CL ($cmdfunc[$i]).", \"".($cmddesc[$i])."\", \"".(generate_help_text($cn,$help[$i])),"\");\n";
 }
 
-print CL "}\n";
+for (my $i=0;$i<scalar @cmdnames;$i++) {
+  writecmd($cmdnames[$i], $i, 0);
 
-close CL;
+  foreach (split / /, $cmdaliases[$i]) {
+    writecmd($_, $i, 1);
+  }
+}
 
-open MF,">Makefile";
+print CL "}\n\nvoid _fini() {\n";
+print CL "  ".$smallname."_fini();\n";
 
-print MF "# Automatically generated Makefile, do not edit.\n\n";
+sub writercmd {
+  my ($cn, $i) = @_;
+  print CL "  chanservremovecommand(\"".$cn."\", ".($cmdfunc[$i]).");\n";
+}
 
-print MF ".PHONY: all Makefile\n";
+for (my $i=0;$i<scalar @cmdnames;$i++) {
+  writercmd($cmdnames[$i], $i);
 
-print MF "all: Makefile $modname\n\n";
+  foreach (split / /, $cmdaliases[$i]) {
+    writercmd($_, $i);
+  }
+}
+
+print CL "}\n";
 
-print MF "Makefile:\n";
-print MF "\t../mkcommandlist.pl $modname\n";
+close CL;
+
+open MF,">.autobuild.mk";
+
+print MF "# Automatically generated Makefile, do not edit.\n";
 
 print MF "\n$modname: ";
 
 push @files,"commandlist.c";
 
+push @files,$cname;
+
 foreach (@files) {
   s/.c$/.o/;
   print MF "$_ ";
 }
 
 print MF "\n";
-print MF "\t ld -shared -Bdynamic -o \$\@ \$\^ \n";
 
 close MF;