#!/usr/bin/perl # # --- GSMP-COPYRIGHT-NOTE-BEGIN --- # # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # Please add additional copyright information _after_ the line containing # the GSMP-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by # the ./scripts/Create-CopyPatch script. Do not edit this copyright text! # # GSMP: dam/script/generate_tmpl.pl # General Sound Manipulation Program is Copyright (C) 2000 - 2004 # Valentin Ziegler and René Rebe # # 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; version 2. A copy of the GNU General # Public License can be found in the file LICENSE. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANT- # ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # --- GSMP-COPYRIGHT-NOTE-END --- $max_templates = 7; $dev_mode = false; if ($ARGV[0] eq "-d") { $dev_mode = true; shift; } $file = "\"$ARGV[0]\""; sub print_location() { if ($dev_mode eq true) { $incline = $line + 1; $ret = "#line $incline $file\n" }; $print_location = $ret; } sub do_list() { $ret = ""; for ($lsub_number = 1; $lsub_number <= $number; $lsub_number += 1) { if (($2) and (not (($1 eq "+") and ($lsub_number eq 1)))) { $ret .= $2 }; $copy = $3; $copy =~ s/__lno/$lsub_number/g; $ret .= $copy; } $list = $ret; } sub do_forallparams { $ret = ""; for ($sub_number = 1; $sub_number <= $number; $sub_number += 1) { $copy = $1; $copy =~ s/__no/$sub_number/g; $ret .= $copy; } $do_forallparams = $ret; } sub expand_lists { $typelist .= ", " if $number > 1; $typelist .= "typename T$number"; $typelist .= $typelist_optional; $arglist .= ", " if $number > 1; $arglist .= "T$number p$number"; $typerep .= ", " if $number > 1; $typerep .= "T$number"; $argrep .= ", " if $number > 1; $argrep .= "p$number"; } sub reset_lists { $typelist_optional = ""; $typelist = ""; $arglist = ""; $typerep = ""; $argrep = ""; } sub do_NO { expand_lists (); $data = $exp_data; $data =~ s/\/\*zero\*\/.*?\/\*\!zero\*\///sg; $data =~ s/\/\*nonzero\*\/(.*?)\/\*\!nonzero\*\//$1/sg; $data =~ s/__NO/$number/g; $data =~ s/\/\*ForAllParams\*\/(.*?)\/\*!ForAllParams\*\//do_forallparams()/seg; $data =~ s/\/\*List\s*?(.)\[(.*?)\]\*\/([^\n]*)\/\*!List\*\//do_list()/eg; if ($convenience && $number != $max_templates) { $data =~ s/__SpTypeRep<(.*?)>/if ($1){"<$1, $typerep>"} else {"<$typerep>"}/eg; } else { $data =~ s/__SpTypeRep<.*?>//eg; } $data =~ s/__TypeList<(.*?)>/if ($1){"template <$1, $typelist>"} else {"template <$typelist>"}/eg; $data =~ s/__TypeRep<(.*?)>/if ($1){"<$1, $typerep>"} else {"<$typerep>"}/eg; $data =~ s/__ArgList/$arglist/g; $data =~ s/__ArgRep/$argrep/g; print $data; print "\n"; } sub do_Zero () { $data = $exp_data; $data =~ s/\/\*zero\*\/(.*?)\/\*\!zero\*\//$1/sg; $data =~ s/\/\*nonzero\*\/.*?\/\*\!nonzero\*\///sg; $data =~ s/__NO/0/g; $data =~ s/\/\*ForAllParams\*\/.*?\/\*!ForAllParams\*\///sg; $data =~ s/\/\*List\s*?.\[.*?\]\*\/[^\n]*\/\*!List\*\///sg; $data =~ s/__TypeList<(.*?)>/if ($1 || $convenience){"template <$1>"}/eg; $data =~ s/__SpTypeRep<(.*?)>/<$1>/sg; $data =~ s/__TypeRep<(.*?)>/if ($1){"<$1>"}/eg; $data =~ s/\,(\s*?)__ArgList//g; $data =~ s/__ArgList//g; $data =~ s/\,(\s*?)__ArgRep//g; $data =~ s/__ArgRep//g; print "#ifdef $encin\n" if ($encapsulate); print $data; print "#endif // $encin\n" if ($encapsulate); } $do_expand = false; $line = 1; print "/*********** This code was auto-generated from $file. Please do not edit !! **************/\n\n\n"; print print_location(); while (<>) { if (/\/\*Expand\*\//) { $do_expand = true; $exp_data = print_location (); $convenience = /Convenience/; $nozero = /NoZero/; $encapsulate = /Encap\((.*?)\)/; $encin = $1; } else {if (/\/\*!Expand\*\//) { $do_expand = false; if ($convenience) { $opt_decrease = 1; reset_lists (); $typelist_optional = " = nil"; for ($number = 1; $number <= $max_templates - $opt_decrease; $number += 1) { expand_lists (); } $number = $max_templates; do_NO (); } reset_lists (); if (not $nozero) { do_Zero (); } for ($number = 1; $number <= $max_templates - $opt_decrease; $number += 1) { do_NO (); } } else {if ($do_expand eq true) { $exp_data .= $_; $exp_data .= print_location () if (/\/\*.?ForAllParams\*\//); } else { print; } } } $line += 1; }