Mailing List Archive

r3812 - in trunk: charmonizer charmonizer/bin perl/buildlib/Lucy
Author: creamyg
Date: 2008-09-04 20:43:29 -0700 (Thu, 04 Sep 2008)
New Revision: 3812

Added:
trunk/charmonizer/bin/metaquote
Removed:
trunk/charmonizer/bin/charmgather
Modified:
trunk/charmonizer/README
trunk/perl/buildlib/Lucy/Build.pm
Log:
Replace Charmonizer's "charmgather" utility with the less functional but less
fragile "metaquote" script. Unlike the old C metaquote, the new incarnation
is written in Perl and handles multiple files.


Modified: trunk/charmonizer/README
===================================================================
--- trunk/charmonizer/README 2008-08-31 23:16:55 UTC (rev 3811)
+++ trunk/charmonizer/README 2008-09-05 03:43:29 UTC (rev 3812)
@@ -16,7 +16,7 @@

The only prerequisite for the target machine is an ISO C90-compliant
compiler which can be invoked from C via the system() command. Your
- development environment must include Perl in order to run the charmgather
+ development environment must include Perl in order to run the metaquote
utility script, but no Perl programming is required.

PROBING
@@ -118,15 +118,11 @@
"METAQUOTE" tags. This is done for maintainability's sake, since
embedding C source code in C source code as string literals is very messy.

- To generate all the necessary Charmonizer .c/.h files, use the charmgather
+ To generate all the necessary Charmonizer .c/.h files, use the metaquote
utility.

- $ ./bin/charmgather --in=charmonize.c --out=/my/charm/dir
+ $ ./bin/metaquote --src=/path/to/charmonizer/src --out=/my/charm/dir

- It will scan your source file to discover which modules you are using, and
- extract all the necessary Charmonizer library files to the directory you
- specify, expanding "METAQUOTE" strings into ordinary C string literals.
-
SECURITY

Under no circumstances should input from untrusted users be supplied to

Deleted: trunk/charmonizer/bin/charmgather
===================================================================
--- trunk/charmonizer/bin/charmgather 2008-08-31 23:16:55 UTC (rev 3811)
+++ trunk/charmonizer/bin/charmgather 2008-09-05 03:43:29 UTC (rev 3812)
@@ -1,189 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-
-use Getopt::Long;
-use File::Spec;
-use File::Find qw( find );
-use File::Path qw( mkpath );
-
-my %done;
-my ( @infiles, $outdir, $charm_src );
-
-GetOptions(
- 'in=s' => \@infiles,
- 'out=s' => \$outdir,
- 'src=s' => \$charm_src,
-);
-$charm_src ||= File::Spec->rel2abs('dev');
-
-# Validate Charmonizer source dir.
-my $probe_path
- = File::Spec->catfile( $charm_src, 'Charmonizer', 'Probe.harm' );
-die("Can't find Charmonizer source tree -- was 'src' specified correctly?")
- unless -e $probe_path;
-
-# Validate infiles.
-die "Must specify at least one input file" unless @infiles;
-for my $infile (@infiles) {
- die "Can't find '$infile'" unless -e $infile;
-}
-
-# Verify/create output directory.
-die "Must specify output directory" unless defined $outdir;
-mkpath($outdir) unless -d $outdir;
-
-# Transfer all core Charmonizer files first.
-my @core_files;
-find(
- { wanted => sub {
- my $name = $File::Find::name;
- return unless $name =~ s/.*?(Charmonizer.+Core.+\.c?harm$)/$1/;
- push @core_files, $name;
- },
- no_chdir => 1,
- },
- $charm_src,
-);
-process_file($_) for @core_files;
-
-for my $infile (@infiles) {
- my $content = slurp_file($infile);
- my @deps = scan_deps($content);
- process_file($_) for @deps;
-}
-
-sub scan_deps {
- my $content = shift;
- my @deps;
- my %got;
- while ( $content =~ m{#include\s+"(Charmonizer/[^"]+)\.h"}g ) {
- my $filename = $1 . ".harm";
- my @components = split( /\//, $filename );
- $filename = File::Spec->catfile(@components);
- next if $got{$filename};
- $got{$filename} = 1;
- push @deps, $filename;
-
- # Grab corresponding .c file if it exists.
- $filename =~ s/harm$/charm/ or die "no match";
- my $fullpath = File::Spec->catfile( $charm_src, $filename );
- next unless -e $fullpath;
- push @deps, $filename;
-
- # The AllTests header is special.
- if ( $filename =~ /AllTests/ ) {
- my $tests_dir
- = File::Spec->catdir( $charm_src, 'Charmonizer', 'Test' );
- opendir( my $dh, $tests_dir )
- or die "Can't opendir '$tests_dir': $!";
- for my $testfile ( readdir $dh ) {
- next unless $testfile =~ /\.c?harm$/;
- my @components = split( /\//, $filename );
- $testfile
- = File::Spec->catfile( 'Charmonizer', 'Test', $testfile );
- next if $got{$testfile};
- $got{$testfile} = 1;
- push @deps, $testfile;
- }
- }
- }
- return @deps;
-}
-
-# Transfer a Charmonizer source file to the destination, transforming it from
-# a .charm/.harm to a .c/.h and replacing all metaquotes.
-sub process_file {
- my $rel_path = shift;
- return if $done{$rel_path};
- my $src_path = File::Spec->catfile( $charm_src, $rel_path );
- my $content = slurp_file($src_path);
- my @deps = scan_deps($content);
- $content = replace_metaquotes($content);
- my $dest_path = File::Spec->catfile( $outdir, $rel_path );
- $dest_path =~ s/(\.[ch])[^.]+$/$1/ or die "No match";
- print "Writing $dest_path\n";
- spit_file( $dest_path, $content );
- $done{$rel_path} = 1;
-
- for my $dep (@deps) {
- next if $done{$dep};
- process_file($dep);
- }
-}
-
-sub replace_metaquotes {
- my $content = shift;
- while ( $content =~ m/METAQUOTE(.+?)METAQUOTE/s ) {
- my $metaquoted = $1;
- $metaquoted =~ s/\\/\\\\/g;
- $metaquoted =~ s/"/\\"/g;
- $metaquoted =~ s/\n/\\n"\n "/mg;
- $content =~ s/METAQUOTE(.+?)METAQUOTE/"$metaquoted"/s
- or die "no match";
- }
- return $content;
-}
-
-sub slurp_file {
- my $path = shift;
- open( my $fh, '<', $path ) or die "Can't open '$path': $!";
- my $content = do { local $/; <$fh> };
- close $fh or die "Can't close '$path': $!";
- return $content;
-}
-
-sub spit_file {
- my ( $path, $content ) = @_;
- my ( undef, $dest_dir, undef ) = File::Spec->splitpath($path);
- mkpath($dest_dir);
- open( my $fh, '>', $path ) or die "Can't open '$path': $!";
- binmode $fh;
- print $fh $content;
- close $fh or die "Can't close '$path': $!";
-}
-
-
-__END__
-
-=head1 NAME
-
-charmgather - Scan an input and collect/extract required Charmonizer modules.
-
-=head1 SYNOPSIS
-
- $ ./bin/charmgather --in=charmonize.c --in=charm_test.c \
- --out=/path/to/output_charm_dir
-
-=head1 DESCRIPTION
-
-=head2 ARGUMENTS
-
-C<charmgather> must be invoked with valid values for C<in> and C<out>.
-
-=over
-
-=item --in=SOURCE_FILE
-
-A C source file which has pound-include directives for Charmonizer modules.
-Multiple values may be specified.
-
-=item --out=DEST_DIR
-
-The directory where the extracted .c/.h Charmonizer module files will be
-written.
-
-=back
-
-=head1 AUTHOR
-
-Marvin Humphrey
-
-=head1 COPYRIGHT & LICENSE
-
-Copyright 2006-2007 Marvin Humphrey
-
-This program is free software; you can redistribute it and/or modify it
-under the same terms as Perl itself.
-
-=cut

Copied: trunk/charmonizer/bin/metaquote (from rev 3808, trunk/charmonizer/bin/charmgather)
===================================================================
--- trunk/charmonizer/bin/metaquote (rev 0)
+++ trunk/charmonizer/bin/metaquote 2008-09-05 03:43:29 UTC (rev 3812)
@@ -0,0 +1,132 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use Getopt::Long;
+use File::Spec;
+use File::Find qw( find );
+use File::Path qw( mkpath );
+
+my %done;
+my ( $outdir, $charm_src );
+
+GetOptions(
+ 'out=s' => \$outdir,
+ 'src=s' => \$charm_src,
+);
+$charm_src ||= File::Spec->rel2abs('dev');
+
+# Validate Charmonizer source dir.
+my $probe_path
+ = File::Spec->catfile( $charm_src, 'Charmonizer', 'Probe.harm' );
+die("Can't find Charmonizer source tree -- was 'src' specified correctly?")
+ unless -e $probe_path;
+
+# Verify/create output directory.
+die "Must specify output directory" unless defined $outdir;
+mkpath($outdir) unless -d $outdir;
+
+# Accumulate list of .harm/.charm files.
+my @charm_files;
+find(
+ { wanted => sub {
+ my $name = $File::Find::name;
+ return unless $name =~ s/.*?(Charmonizer.+\.c?harm$)/$1/;
+ push @charm_files, $name;
+ },
+ no_chdir => 1,
+ },
+ $charm_src,
+);
+
+# Process all source files.
+process_file($_) for @charm_files;
+exit;
+
+# Transfer a Charmonizer source file to the destination, transforming it from
+# a .charm/.harm to a .c/.h and replacing all metaquotes.
+sub process_file {
+ my $rel_path = shift;
+ return if $done{$rel_path};
+ my $src_path = File::Spec->catfile( $charm_src, $rel_path );
+ my $content = slurp_file($src_path);
+ $content = replace_metaquotes($content);
+ my $dest_path = File::Spec->catfile( $outdir, $rel_path );
+ $dest_path =~ s/(\.[ch])[^.]+$/$1/ or die "No match";
+ print "Writing $dest_path\n";
+ spit_file( $dest_path, $content );
+ $done{$rel_path} = 1;
+}
+
+sub replace_metaquotes {
+ my $content = shift;
+ while ( $content =~ m/METAQUOTE(.+?)METAQUOTE/s ) {
+ my $metaquoted = $1;
+ $metaquoted =~ s/\\/\\\\/g;
+ $metaquoted =~ s/"/\\"/g;
+ $metaquoted =~ s/\n/\\n"\n "/mg;
+ $content =~ s/METAQUOTE(.+?)METAQUOTE/"$metaquoted"/s
+ or die "no match";
+ }
+ return $content;
+}
+
+sub slurp_file {
+ my $path = shift;
+ open( my $fh, '<', $path ) or die "Can't open '$path': $!";
+ my $content = do { local $/; <$fh> };
+ close $fh or die "Can't close '$path': $!";
+ return $content;
+}
+
+sub spit_file {
+ my ( $path, $content ) = @_;
+ my ( undef, $dest_dir, undef ) = File::Spec->splitpath($path);
+ mkpath($dest_dir);
+ open( my $fh, '>', $path ) or die "Can't open '$path': $!";
+ binmode $fh;
+ print $fh $content;
+ close $fh or die "Can't close '$path': $!";
+}
+
+
+__END__
+
+=head1 NAME
+
+metaquote - Translate Charmonizer modules to C.
+
+=head1 SYNOPSIS
+
+ $ ./bin/metaquote --out=/path/to/output_charm_dir \
+ > --src=/path/to/charmonizer/src
+
+=head1 DESCRIPTION
+
+The C<metaquote> utility processes a directory of Charmonizer .harm/.charm
+source files, replacing METAQUOTE-delimited text with legal C double-quoted
+text and generating .h/.c files.
+
+=head1 ARGUMENTS
+
+=over
+
+=item --out=DEST_DIR
+
+The directory where the extracted .c/.h Charmonizer module files will be
+written.
+
+=item --src=SOURCE_DIR
+
+The Charmonizer source directory.
+
+=back
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2006-2008 Marvin Humphrey
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut

Modified: trunk/perl/buildlib/Lucy/Build.pm
===================================================================
--- trunk/perl/buildlib/Lucy/Build.pm 2008-08-31 23:16:55 UTC (rev 3811)
+++ trunk/perl/buildlib/Lucy/Build.pm 2008-09-05 03:43:29 UTC (rev 3812)
@@ -124,12 +124,9 @@
or die "Copy failed: $!";
copy( $charm_test_c_orig, $charm_test_c )
or die "Copy failed: $!";
- my $charmgather = catfile( $charm_orig_dir, qw( bin charmgather ) );
+ my $metaquote = catfile( $charm_orig_dir, qw( bin metaquote ) );
my $charm_dev_dir = catdir( $charm_orig_dir, 'dev' );
- my $command
- = "$^X $charmgather --src=$charm_dev_dir "
- . "--in=$charmonize_c --in=$charm_test_c "
- . "--out=charmonizer";
+ my $command = "$^X $metaquote --src=$charm_dev_dir --out=charmonizer";
system($command);
}



_______________________________________________
kinosearch-commits mailing list
kinosearch-commits@rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch-commits