#!/usr/bin/perl -w # # perl script to extract macros and background menu commands from the NEdit # configuration. # # Copyright (c) 2000 Joor Loohuis and Philippe Couton. All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # Based on nxlang from Joor Loohuis (joor@nl.linux.org), which do the same for # a language mode. # # revision history: # date author/comment # 2000/10/31 v0.10, Philippe Couton (philippe.couton@sercel.fr) # original version: rewrite of nxlang to extract macros and # background menu commands rather than a language mode. # use strict; use NEdit::Config; use Getopt::Long; use vars qw( $comment $list $version $infile $outfile $mac $VERSION $version_string $instructions $usage %export $out ); $VERSION = 0.10; my($tool) = /\// ? ($0 =~ m/\/([^\/]+)$/) : $0; $version_string = sprintf "%s %.2f", $tool, $VERSION; $instructions =< ! ! Then, check that the macros and/or background menu commands were loaded ! correctly, and choose Save Defaults from the Preferences menu. The new ! macros and/or background menu commands will now be incorporated into your ! own .nedit file, so the next time you start NEdit, you will no longer need ! to use -import. ! ! These comments will not appear in your ~/.nedit ! EOF # extracted using 'pod2usage -v 1' $usage =<<'EOF'; Usage: nxmacs [-c] [-l] [-V] [-i file] [-o file] macros_list Options: -c, --comment Prepend a comment area with import instructions to the output. -l, --list List all available macros and background menu commands and exit. -V, --version Write the version and exit. -i file, --input file Read the configuration from a file other than $HOME/.nedit. -o file, --output file Write the output to the specified file. Writes to STDOUT by default. EOF $infile = "$ENV{HOME}/.nedit"; # default input $outfile = "-"; # default output GetOptions("c|comment" => \$comment, # prepend instructions "l|list" => \$list, # list macros names and exit "V|version" => \$version, # print version number and exit "i|input=s" => \$infile, # provide input filename "o|output=s" => \$outfile # provide output filename ); # send output to STDOUT unless a file is specified die "$version_string\n" if (defined $version); # get the language data tie my %config, "Tie::IxHash", read_config($infile) or die "failed to open $infile: $!\n"; tie my %macros, "Tie::IxHash", %{$config{'macroCommands'}}; tie my %bgMenu, "Tie::IxHash", %{$config{'bgMenuCommands'}}; if ($list) { die "available macros:\n\t", join("\n\t", keys %macros), "\n\n", "available background menu commands:\n\t", join("\n\t", keys %bgMenu), "\n"; } # get the macros and background menu commands, and add them to the output die $usage if (@ARGV == 0); while ($mac = shift) { my($found) = 0; my($regex) = $mac; $regex =~ s/\?/./g; $regex =~ s/\*/.*/g; # Process background menu if (exists $bgMenu{$mac}) { # Try regular name first $export{'bgMenuCommands'}->{$mac} = $bgMenu{$mac}; $found = 1; } elsif ($mac =~ /[?*[]/) { # Regular name not found, try regexp my($key); foreach $key (keys %bgMenu) { if ($key =~ $regex) { $export{'bgMenuCommands'}->{$key} = $bgMenu{$key}; $found = 1; } } } # Process macros if (exists $macros{$mac}) { # Try regular name first $export{'macroCommands'}->{$mac} = $macros{$mac}; $found = 1; } elsif ($mac =~ /[?*[]/) { # Regular name not found, try regexp my($key); foreach $key (keys %macros) { if ($key =~ $regex) { $export{'macroCommands'}->{$key} = $macros{$key}; $found = 1; } } } $found or die "unknown macro '$mac'\n"; } # add the NEdit version for the configuration, if it exists $export{'fileVersion'} = $config{'fileVersion'} if $config{'fileVersion'}; # write the output open(STDOUT, "> $outfile") or die "can't write to $outfile: $!\n"; print STDOUT "! Macros and background menu commands for NEdit\n!\n"; print STDOUT $instructions if (defined $comment); print STDOUT format_config(\%export); print STDOUT "\n! generated with $version_string\n"; close STDOUT; =pod =head1 NAME nxmacs - extract a set of macros and/or background menu commands from the NEdit configuration =head1 SYNOPSIS nxmacs [-c] [-l] [-V] [-i file] [-o file] macros_list =head1 DESCRIPTION nxmacs reads C<$HOME/.nedit> and extracts the requested macros and/or background menu commands. The output is a file that can be used with the C<-import> option that NEdit provides. Each name specified in the list is searched literally. If it is not found, a second search is tried, assuming the name contains wildcards. These wildcards are used like within a shell: "?" match any single character, "*" match any sequence of characters, even empty, and "[...]" match any single character specified in the range. This two stage search allows to extract names containing characters like '*' without side-effects due to wildcards matching. The search is done twice: once within the macros and once within the background menu commands. =head1 OPTIONS =over 4 =item -c, --comment Prepend a comment area with import instructions to the output. =item -l, --list List all available macros and exit. =item -V, --version Write the version and exit. =item -i file, --input file Read the configuration from a file other than $HOME/.nedit. =item -o file, --output file Write the output to the specified file. Writes to STDOUT by default. =back =head1 AUTHOR Joor Loohuis, joor@nl.linux.org and Philippe Couton, philippe.couton@sercel.fr Copyright (c) 2000 Joor Loohuis and Philippe Couton. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO perl(1), nxlang(1), nxshell(1), NEdit::Config(3). =cut