Overview
Comment: | Uses pattern matching to apply any CRs (in perl format) specified on its command line to the text on standard input. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
c12dee9b4af28373d821594e5e8df706 |
User & Date: | geraint@users.sourceforge.net on 2004-08-30 23:07:58 |
Other Links: | branch diff | manifest | tags |
Context
2004-08-30
| ||
23:08:41 | Perl module implementing lin CR, for use with apply_cr.pl check-in: 647922f738 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
23:07:58 |
Uses pattern matching to apply any CRs (in perl format) specified on its command line to the text on standard input. check-in: c12dee9b4a user: geraint@users.sourceforge.net tags: origin/master, trunk | |
2004-08-29
| ||
18:01:46 |
Reads each CR name input and writes a directive to #include an equivalent CR.hh from $MTT_LIB/cr/hh. check-in: 9f2a0a7535 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
Changes
Added mttroot/mtt/lib/cr/perl/apply_cr.pl version [3ed2161205].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | #! /usr/bin/perl -w # # apply_cr.pl - apply specified CRs to text on standard input # Copyright (C) 2004 Geraint Paul Bevan # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # -------------------------- # Model Transformation Tools # -------------------------- # # #------------------------------------------------------------------------------- use strict; use Getopt::Long; my $cr_name=''; #------------------------------------------------------------------------------- # arguments and options #------------------------------------------------------------------------------- my $crlist = ''; my $debug = 0; my $help = 0; GetOptions ('debug' => \$debug, 'help' => \$help); #------------------------------------------------------------------------------- # globals #------------------------------------------------------------------------------- my @expressions; my @prefixes; my $expression; my $i = 0; #------------------------------------------------------------------------------- # subroutine declarations #------------------------------------------------------------------------------- sub substitute_subexpressions(); sub process_expression(); sub display_subexpressions(); sub reassemble_expression(); sub usage(); #------------------------------------------------------------------------------- # main #------------------------------------------------------------------------------- if ($help) { usage(); exit 1; } while (<STDIN>) { $expression = $_; print STDERR "Start Expression -> $expression\n" if $debug; $i = 0; @expressions = (); @prefixes = (); substitute_subexpressions(); display_subexpressions () if ($debug); for ($i = 0; $i <= $#expressions; $i++) { my $result = process_expression (); if ($result) { $prefixes[$i] = ""; $expressions[$i] = "$result"; } } display_subexpressions () if ($debug); reassemble_expression (); print STDOUT "$expression"; } #------------------------------------------------------------------------------- # subroutines #------------------------------------------------------------------------------- sub substitute_subexpressions() { while ($expression =~ /\(.*\)/) { $_ = $expression; # get a matched pair of brackets s/ (.*) ( \({1} [^\(\)]* \){1} ) (.*) /$1 : $2 : $3/x; my $extracted; my $remainder; my $skipped; ($skipped, $extracted, $remainder) = split (/ : /); $expressions[$i] = $extracted if $extracted; $_ = $skipped; s/(\s)//g; # strip whitespace s/ (.*?) (\w*)$ /$2/x; # get function name (if any) $prefixes[$i] = $_; $skipped =~ s/(.*)$prefixes[$i]$/$1/; $expression = "$skipped\{$i\}$remainder"; $i++; } $expressions[$i] = $expression; # $prefixes[$i] = ""; } #------------------------------------------------------------------------------- sub process_expression() { my $cr = ''; foreach my $cr_name (@ARGV) { if ($prefixes[$i]) { if ($prefixes[$i] eq $cr_name) { $cr = $cr_name; } } } if ($cr eq '') { return; } # call cr(arg1,arg2,...) no strict 'refs'; # allow symbolic references my $expr = $expressions[$i]; eval "require $cr"; $cr->import (@_[1 .. $#_]); &$cr ($expr); use strict 'refs'; } #------------------------------------------------------------------------------- sub display_subexpressions() { for ($i = 0; $i <= $#expressions; $i++) { my $prefix = " "; $prefix = $prefixes[$i] if ($prefixes[$i]); print STDERR "$i\t($prefix)\t$expressions[$i]\n\n"; } } #------------------------------------------------------------------------------- sub reassemble_expression () { $expression = $expressions[$#expressions]; for ($i = $#expressions; $i >= 0; $i--) { print STDERR "{$i}: $expressions[$i]\n" if $debug; $expression =~ s/\{$i\}/$prefixes[$i]$expressions[$i]/g; } print STDERR "Final expression -> $expression\n" if $debug; } #------------------------------------------------------------------------------- sub usage() { print STDOUT "\nUsage: $0 [options] crname1 crname2 ..\n" . "\n" . "\toptions:\n" . "\t--debug\n" . "\t--help\n" . "\n"; } |