summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorlanfer <lanfer@17b73243-c579-4c4c-a9d2-2d5706c11dac>2000-02-01 16:34:11 +0000
committerlanfer <lanfer@17b73243-c579-4c4c-a9d2-2d5706c11dac>2000-02-01 16:34:11 +0000
commit579b25d7bf4edd7f1cee89140336a73a08d5ae6a (patch)
tree78e39cf21df3707c2c3479862911ffb8ea7df93c /lib
parentb80d45cdc7fb5d3e76c78d495fe362b15c96f917 (diff)
This script is run as part of the perl precprocessor.
# It also the C source and adds the USE macros, which perform # a dummy assignment. This avoid ugly warnings on some compilers. # This auto adding was tested on all C-thorns. Since this # does not match the full C syntax, there can pathological cases, where # this script will not be able to put the USE stuff in the right place. # There is a switch to turn this auto-adding off: place the string # "CCTK_NO_AUTOUSE_MACRO" somewhere at the top (within a comment). # Everything after will not be matched. git-svn-id: http://svn.cactuscode.org/flesh/trunk@1331 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib')
-rw-r--r--lib/sbin/c_file_processor.pl108
1 files changed, 99 insertions, 9 deletions
diff --git a/lib/sbin/c_file_processor.pl b/lib/sbin/c_file_processor.pl
index 12602011..9764e6ca 100644
--- a/lib/sbin/c_file_processor.pl
+++ b/lib/sbin/c_file_processor.pl
@@ -2,10 +2,19 @@
#/*@@
# @file c_file_processor.pl
# @date Fri Jan 22 18:09:47 1999
-# @author Tom Goodale
+# @author Tom Goodale / Gerd Lanfermann
# @desc
# Processes a c file replacing certain strings which can't be dealt
# with by the normal c preprocessor.
+#
+# It also parses the C source and adds the USE macros, which perform
+# a dummy assign. This avoid ugky warnings on some compilers.
+# This auto adding was tested on all C-thorns and it worked. Since this
+# does not match the full C syntax, there can pathological cases, where
+# this script will not be able to put the USE stuff in the right place.
+# There is a switch to turn this auto-adding off: place the string
+# "CCTK_NO_AUTOUSE_MACRO" somewhere at the top (within a comment).
+# Everything after will not be matched.
# @enddesc
#@@*/
@@ -20,35 +29,116 @@ if (! -e "$fortran_name_file" )
require "$fortran_name_file";
-$/ = ";";
+$/ = ";\n";
$*=1;
+$checkfor1 = "DECLARE_CCTK_PARAMETERS";
+$addmacro1 = "USE_CCTK_PARAMETERS";
+$domacro1 = 0;
+$done1 = 0;
+$checkfor2 = "DECLARE_CCTK_CARGUMENTS";
+$addmacro2 = "USE_CCTK_CARGUMENTS";
+$domacro2 = 0;
+$done2 = 0;
+
+$skip = 0;
+$skipstring= "CCTK_NO_AUTOUSE_MACRO";
+
while(<>)
{
- $line = $_;
+ @lines = split("\n",$_);
+ foreach $mline (@lines)
+ {
+ if ($mline=~/$skipstring/)
+ {
+ $skip=1;
+ }
+ if ($skip==0) {
+
+ if ($mline=~/$checkfor1/) {
+ $domacro1 = 1;
+ }
+ if ($mline=~/$checkfor2/) {
+ $domacro2 = 1;
+ }
+
+ while ($mline=~m/(})/g) {
+ $par = $par."c";
+ }
+ while ($mline=~m/({)/g) {
+ $par = $par."o";
+ }
+ 0 while $par =~s/oc//g;
+
+# print ">>$mline<< $par";
+
+
+ if (($par eq "o")&&($mline=~m/return.*;/)&&(($domacro1==1)||($domacro2==1)))
+ {
+ $frag1="\nif(1)\n{ \n";
+ $frag2="}";
+ if ($domacro1==1)
+ {
+ $frag1.="$addmacro1\n";
+ $done1 =1;
+ $domacro1=0;
+ }
+ if ($domacro2==1)
+ {
+ $frag1.="$addmacro2\n";
+ $done2 =1;
+ $domacro2=0;
+ }
+ $mline=~s/(return.*)/$frag1$1\n$frag2/;
+
+ }
+ if (($par eq "") &&($mline=~/}/)&&(($domacro1==1)||($domacro2==1)))
+ {
+ $frag1="\n/* DUMMY MACROS STARTX */\n";
+ $frag2="/* DUMMY MACROS ENDX */ ";
+ if ($domacro1==1)
+ {
+ $frag1.="$addmacro1\n";
+ $done1 =1;
+ $domacro1=0;
+ }
+ if ($domacro2==1)
+ {
+ $frag1.="$addmacro2\n";
+ $done2 =1;
+ $domacro2=0;
+ }
+ $mline=~s/(.*)(}.*)/$1$frag1$frag2$2/;
+ }
+ }
+ $line.=$mline."\n";
+ }
+
while($line =~ m:FORTRAN_NAME\s*\(([^\)]*)\):)
{
$arglist = $1;
$arglist =~ s:[\s\n\t]+::g;
- @args = split(",", $arglist );
+ @args = split(",", $arglist );
- $new = &fortran_name($args[$#args]);
+ $new = &fortran_name($args[$#args]);
- $line =~ s:FORTRAN_NAME\s*\(([^\)]*)\):$new:;
+ $line =~ s:FORTRAN_NAME\s*\(([^\)]*)\):$new:;
}
while($line =~ m:FORTRAN_COMMON_NAME\s*\(([^\)]*)\):)
{
$arglist = $1;
$arglist =~ s:[\s\n\t]+::g;
- @args = split(",", $arglist );
+ @args = split(",", $arglist );
- $new = &fortran_common_name($args[$#args]);
+ $new = &fortran_common_name($args[$#args]);
- $line =~ s:FORTRAN_COMMON_NAME\s*\(([^\)]*)\):$new:;
+ $line =~ s:FORTRAN_COMMON_NAME\s*\(([^\)]*)\):$new:;
}
print $line;
+ $line ="";
}
+