cvsimport
[fvwm.git] / perllib / FVWM / create-commands
blobb6d611390854b96da18f064a4efef8f1bd50f66c
1 #!/usr/bin/perl -w
3 use FindBin;
4 use lib "$FindBin::Bin/..";
5 use General::FileSystem;
6 use POSIX;
8 chdir($FindBin::Bin) || die "Can't chmod $FindBin::Bin: $!\n";
10 my $functable_src = "../../fvwm/functable.c";
11 my $content_ref = load_file($functable_src);
12 die "No commands found, so Commands.pm is not generated.\n" unless $content_ref;
14 my $command_entries_code = "";
15 foreach my $entry ($$content_ref =~
16 m{(?:/\* )?CMD_ENT\(\s*(?:"|PRE_).*?\),(?: \*/)?.*?/\* .*?- .*? \*/}sg)
18 my ($name, $flags, $cursor, $name2, $descr) = $entry =~ m{
20 .*? CMD_(\w+) ,
21 .*? ,
22 .*? ([\w\s|]+?) ,
23 .*? (?:CRS_)?(\w+)
24 .*? \) ,
25 .*? /\*\s (?:(.+)\s)? -\s (.*?) \s\*/
26 }xs;
27 $name = $name2 if $name2;
28 my $window = $flags =~ FUNC_NEEDS_WINDOW? 1: 0;
29 $cursor = "" if $cursor eq "0";
30 $command_entries_code .=
31 "\t{\n\t\tname => '$name',\n\t\tcursor => '$cursor',\n" .
32 "\t\twindow => $window,\n\t\tdescr => q{$descr},\n\t},\n";
35 my $version = `egrep '^VERSION = |^VERSIONINFO = ' Makefile | cut -d"=" -f2 \\
36 | perl -pe 's/^ //;s/\\n//'`;
37 my $time = time;
39 my $output = <<ENDOUTPUT;
40 # Autogenerated from the fvwm sources.
42 package FVWM::Commands;
44 use vars qw(\$VERS \$TIME \@LIST);
46 \$VERS = '$version';
47 \$TIME = $time;
49 \@LIST = (
50 $command_entries_code);
54 __END__
56 =head1 NAME
58 FVWM::Commands - lists all available fvwm commands
60 =head1 DESCRIPTION
62 This class is autogenerated from the fvwm sources.
64 It may be used to get a list of all available fvwm commands including the
65 command name, its short description and some other command properties.
67 =head1 USAGE
69 use lib `fvwm-perllib dir`;
70 use FVWM::Commands;
71 use POSIX;
73 my \$date = strftime("%d-%b-%Y", gmtime(\$FVWM::Commands::TIME));
74 my \$version = \$FVWM::Commands::VERS;
75 print "The recognized commands for fvwm \$version as of \$date:\\n\\n";
76 foreach my \$command (\@FVWM::Commands::LIST) {
77 printf " %-21s - %s\\n", \$command->{name}, \$command->{descr};
80 =head1 PUBLIC CONSTANTS
82 =over 4
84 =item \$VERS
86 The fvwm version number at the generation time like "2.6.0" plus the info
87 that may indicate that this is not a final version, but a cvs snapshot.
89 =item \$TIME
91 The unix time of the command list generation.
93 Example:
95 print "The fvwm command list found on your system was generated "
96 . (time() - \$FVWM::Commands::TIME) / 86400 . " days ago\\n";
98 =item \@LIST
100 The command list that is an array of hashes with keys I<name>, I<cursor>,
101 I<descr> (string) and I<window> (boolean).
103 I<name> may be special, like "+", "#" and "*". Other names usually contain
104 only isalpha characters, like B<Move>, B<SendToModule>.
106 I<cursor> may be either empty or the cursor context used in B<CursorStyle>
107 (like "SELECT" or "MOVE"), associated with the command.
109 I<descr> is a short one line description of the command.
111 I<window> is true for commands that need a window.
113 Example:
115 # get command names only
116 \@command_names = map { \$_->{name} } \@FVWM::Commands::LIST;
118 =back
120 =head1 AUTHOR
122 Mikhael Goikhman <migo\@homemail.com>.
124 =head1 SEE ALSO
126 For more information about the commands themselves, see fvwm(1).
128 =cut
129 ENDOUTPUT
131 # ---------------------------------
132 print "Creating Commands.pm\n";
133 save_file("Commands.pm", \$output);
135 # ---------------------------------
136 print "Testing Commands.pm\n";
137 eval qq{
138 use lib '$FindBin::Bin/..';
139 use FVWM::Commands;
141 die $@ if $@;
142 $FVWM::Commands::TIME ||= 0; # avoid "used once" warning
144 my $date = strftime("%d-%b-%Y", gmtime($FVWM::Commands::TIME));
145 my $cmds = "The recognized commands for fvwm $version as of $date:\n\n";
146 foreach my $command (@FVWM::Commands::LIST = @FVWM::Commands::LIST) {
147 $cmds .= sprintf " %-21s - %s\n", $command->{name}, $command->{descr};
150 # ---------------------------------
151 print "Creating ../../docs/COMMANDS\n";
152 save_file("../../docs/COMMANDS", \$cmds);