Fix move command parsing.
[fvwm.git] / modules / FvwmCommand / findcmd.pl
blob9086a9829b854b42279b6bc8045ac04c3f7aaa8c
1 #!/usr/bin/perl
2 # Find fvwm commands from functions.c struct functions
3 # Written by Toshi Isogai
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 sub getcmd {
20 $/ = "\n\n";
21 while(<STDIN>) {
22 #find "func_t func_config[] =" in various spacing
23 if (s/func_t.*\[\]\s*=(\s|\n)*\{// ) {
24 return listcmd();
27 print stderr "Can't find func_t\n";
28 exit 1;
31 sub listcmd {
32 my($cmd,@cmd);
34 while (/CMD_ENTRY/) {
35 $old = $_;
36 s/.*CMD_ENTRY[^,]*,\s*CMD_([^,]+).*/\1/s;
37 s/\s*$//;
38 if (!/^\+\s*$/) {
39 push @cmd, $_;
41 $_ = $old;
42 s/(.*)CMD_ENTRY.*/\1/s;
44 @cmd;
47 sub create_pm {
48 my( @cmd, $i, @ln );
49 my( $fvwmdir ) = $ARGV[0];
50 my( $pm ) = "FvwmCommand.pm";
52 @cmd = getcmd();
54 if ($ARGV[1] eq "-sh") {
55 print "# FvwmCommand.sh\n";
56 print "# Collection of fvwm builtin commands for FvwmCommand\n";
57 print "#\n";
58 print "alias FvwmCommand=\'$fvwmdir/FvwmCommand\'\n";
60 for( $i=0; $i<=$#cmd; $i++) {
61 print "$cmd[$i] () {\n";
62 print "\tFvwmCommand \"$cmd[$i] \$\*\"\n";
63 print "}\n";
66 print "AM () { \n";
67 print " FvwmCommand \"+ \$\*\"\n";
68 print "}\n";
70 else {
71 print "# $pm\n";
72 print "# Collection of fvwm builtin commands for FvwmCommand\n";
73 print "package FvwmCommand;\nuse Exporter;\n";
74 print "\@ISA=qw(Exporter);\n\@EXPORT=qw(";
75 for( $i=0; $i<=$#cmd; $i++) {
76 if( $i % 5 == 0 ) {
77 print "\n $cmd[$i]";
78 }else{
79 print " $cmd[$i]";
82 print "\n);\n";
83 print "\nsub FvwmCommand { system \"$fvwmdir/FvwmCommand '\@_'\"}\n\n";
84 foreach $i (@cmd) {
85 print "sub $i { FvwmCommand \"$i \@_ \" }\n";
87 print "sub AM { FvwmCommand \"+ \@_ \" }\n";
88 print "1;\n";
92 create_pm();