diff --git a/applets/cdecl.pl b/applets/cdecl.pl index 48fe9c44..737409bb 100755 --- a/applets/cdecl.pl +++ b/applets/cdecl.pl @@ -1,27 +1,60 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # SPDX-FileCopyrightText: 2009-2023 Pragmatic Software # SPDX-License-Identifier: MIT -# quick and dirty by :pragma +use warnings; +use strict; + +use Getopt::Long qw/GetOptionsFromString/; + +my $usage = "Usage: cdecl , see http://linux.die.net/man/1/cdecl (Don't use this command. Use `english` instead.)\n"; my $command = join(' ', @ARGV); - -my @args = split(' ', $command); # because @ARGV may be one quoted argument -if (@args < 2) { - print "Usage: cdecl , see http://linux.die.net/man/1/cdecl (Don't use this command. Use `english` instead.)\n"; - die; -} - $command = quotemeta($command); $command =~ s/\\ / /g; +$command =~ s/^\s+|\s+$//g; +$command =~ s/\s+--\s+/ /g; + +{ + my $opt_err; + local $SIG{__WARN__} = sub { + $opt_err = shift; + chomp $opt_err; + }; + + Getopt::Long::Configure('no_auto_abbrev', 'no_ignore_case'); + + my %h; + my @allowed = qw/language=s x=s version v/; + my ($ret, $rest) = GetOptionsFromString($command, \%h, @allowed); + + if ($opt_err) { + print "$opt_err\n"; + exit 1; + } + + if ($ret != 1) { + print "Error parsing options.\n"; + exit 1; + } + + if (not @$rest) { + print $usage; + exit 1; + } + + my @commands = qw/cast declare expand define explain enum show/; + push @commands, '#define'; + + if (!grep { $rest->[0] eq $_ } @commands) { + print $usage; + exit 1; + } +} my $result = `cdecl $command`; chomp $result; $result =~ s/\n/, /g; - -print $result; -print " (Don't use this command. It can only handle C90 declarations -- poorly. Use `english` instead, which can translate any complete C11 code.)" - if $result =~ m/^declare/; -print "\n"; +print "$result (Don't use this command. It can only handle C90 declarations -- poorly. Use `english` instead, which can translate any complete C11 code.)\n" diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index a3b822ed..a416ce69 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,7 +25,7 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4877, + BUILD_REVISION => 4878, BUILD_DATE => "2025-07-20", };