#!/usr/bin/perl -w # # perl script to extract a language mode from the # NEdit configuration, including patterns and non-default styles # # Copyright (c) 2000 Joor Loohuis. All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # revision history: # date author/comment # Sep 26, 2001 v1.10, Joor Loohuis # added multiple language export # 2000/07/18 v1.00, Joor Loohuis # added config file version output # changed the name # declared 'stable' # some programming style fixes # 2000/03/27 v0.10, Joor Loohuis (joor@nl.linux.org) # original version # use strict; use NEdit::Config; use Getopt::Long; use vars qw( $comment $list $version $infile $outfile $lang $VERSION $version_string $instructions $usage %export $out ); $VERSION = 1.10; my($tool) = ($0 =~ m/\/([^\/]+)$/); $version_string = sprintf "%s %.2f", $tool, $VERSION; $instructions =< ! ! Then, check that the patterns were loaded correctly, and choose Save Defaults ! from the Preferences menu. The new patterns 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: nxlang [-c] [-l] [-V] [-i file] [-o file] language [language...] Options: -c, --comment Prepend a comment area with import instructions to the output. -l, --list List all available languages 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 language 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 %modes, "Tie::IxHash", %{$config{'languageModes'}}; tie my %default_styles, "Tie::IxHash", %{$DEFAULT_CONFIG{'styles'}}; if ($list) { die "available language modes:\n\t", join("\n\t", keys %modes), "\n"; } # get the language mode, and add it to the output my $export; @ARGV or die $usage; while (@ARGV) { $lang = shift; my $mode = $modes{$lang} or die "unknown language '$lang'\n"; # add the mode to the output tie my %mode, "Tie::IxHash", %$mode; $export{'languageModes'}->{$lang} = \%mode; my $pats = $config{'highlightPatterns'}->{$lang}; # check if custom patterns exist (ref $pats) or die "$lang uses default (built-in) patterns\n"; # add the patterns to the output tie my %pats, "Tie::IxHash", %{$pats}; $export{'highlightPatterns'}->{$lang} = \%pats; # check if any non-default styles are used tie my %patterns, "Tie::IxHash", %{$pats{'patterns'}}; for (keys %patterns) { my $style = $patterns{$_}->{'style'}; if (not exists $default_styles{$style}) { $export{'styles'}->{$style} = $config{'styles'}->{$style}; } } } # write the output open(STDOUT, "> $outfile") or die "can't write to $outfile: $!\n"; print STDOUT "! Syntax highlighting patterns for ", join(", ", keys %{$export{'languageModes'}}), "\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 nxlang - extract a set of language patterns from the NEdit configuration =head1 SYNOPSIS nxlang [-c] [-l] [-V] [-i file] [-o file] language [language...] =head1 DESCRIPTION nxlang reads C<$HOME/.nedit> and extracts the patterns and the language mode of the requested language. It checks whether the patterns rely on non-default styles, and includes any that are encountered. The output is a file that can be used with the C<-import> option that NEdit provides. =head1 OPTIONS =over 4 =item -c, --comment Prepend a comment area with import instructions to the output. =item -l, --list List all available languages 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 Copyright (c) 2000 Joor Loohuis. 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), nxmacs(1), nxshell(1), NEdit::Config(3). =cut