diff options
author | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-10-24 19:52:52 +0000 |
---|---|---|
committer | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-10-24 19:52:52 +0000 |
commit | 3b0a0ea158df599e3fd87ab5100bf8e4344b322b (patch) | |
tree | 45b1871ce3dd0aea172d523eae037f39c775e166 | |
parent | ca0c6e7de53d3f3b9c9e98615ff8cbad9a0ae521 (diff) |
Put an extern "C" around the parameter structure in header files.
Some tidying up.
Tom
git-svn-id: http://svn.cactuscode.org/flesh/trunk@1100 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rw-r--r-- | lib/sbin/CreateParameterBindings.pl | 183 | ||||
-rw-r--r-- | lib/sbin/create_c_stuff.pl | 202 |
2 files changed, 39 insertions, 346 deletions
diff --git a/lib/sbin/CreateParameterBindings.pl b/lib/sbin/CreateParameterBindings.pl index 19102754..a2646107 100644 --- a/lib/sbin/CreateParameterBindings.pl +++ b/lib/sbin/CreateParameterBindings.pl @@ -5,6 +5,7 @@ # @desc # Parameter binding stuff # @enddesc +# @version $Header$ #@@*/ #/*@@ @@ -191,28 +192,21 @@ sub CreateParameterBindings $dataout = ""; -$dataout .= "\#include <stdio.h>\n"; -$dataout .= "\#include <stdlib.h>\n"; -$dataout .= "\#include <string.h>\n"; -$dataout .= "\#include \"config.h\"\n"; -$dataout .= "\#include \"cctk_Misc.h\"\n"; -$dataout .= "\#include \"cctk_WarnLevel.h\"\n"; + $dataout .= "\#include <stdio.h>\n"; + $dataout .= "\#include <stdlib.h>\n"; + $dataout .= "\#include <string.h>\n"; + $dataout .= "\#include \"config.h\"\n"; + $dataout .= "\#include \"cctk_Misc.h\"\n"; + $dataout .= "\#include \"cctk_WarnLevel.h\"\n"; foreach $routine ((keys %routines), "CCTK_BindingsParametersGlobal") { $dataout .= "int $routine"."Initialise(void);\n"; -# print OUT "int $routine"."Set(const char *param, const char *value);\n"; -# print OUT "int $routine"."Get(const char *param, void **data);\n"; $dataout .= "int $routine"."Help(const char *param, const char *format, FILE *file);\n"; } -$dataout .= "int CCTKi_BindingsParametersInitialise(void)\n"; -$dataout .= "\{\n\n"; - -# foreach $routine (keys %routines, "CCTK_BindingsParametersGlobal") -# { -# print OUT " $routine"."Initialise();\n"; -# } + $dataout .= "int CCTKi_BindingsParametersInitialise(void)\n"; + $dataout .= "\{\n\n"; foreach $thorn (split(" ",$interface_database{"THORNS"})) { @@ -224,145 +218,42 @@ $dataout .= "\{\n\n"; $dataout .= " CCTKi_Bindings$thorn"."ParameterExtensions();\n\n"; } -$dataout .= "return 0;\n"; -$dataout .= "}\n\n"; - -#int CCTKi_BindingsParameterSet(const char *identifier, const char *value) -#{ -# int retval = 1; -# int temp_retval; -# char *implementation = NULL; -# char *param_name = NULL; - -# Util_SplitString(&implementation, ¶m_name, identifier, "::"); - -# if(!implementation) -# { -# retval = CCTK_BindingsParametersGlobalSet(identifier, value); -# } -# else -# { - -# if(CCTK_IsThornActive(implementation) || -# CCTK_IsImplementationActive(implementation)) -# { -#EOT - -# foreach $routine (keys %routines, "CCTK_BindingsParametersGlobal") -# { -# -# print OUT <<EOT; -# -# if(CCTK_Equals(implementation, \"$routines{$routine}\")) -# { -#EOT -# print OUT " temp_retval = $routine"."Set(param_name, value);"; -# -# print OUT <<EOT; -# -# if(!temp_retval) -# { -# retval = 0; -# } -# } -#EOT -# } - -# print OUT <<EOT; -# } -# else -# { -# char *message = malloc( (200+strlen(param_name)+strlen(implementation))*sizeof(char) ); -# sprintf(message, "Can't set %s - %s is not active", param_name, implementation); -# CCTK_Warn(0,__LINE__,__FILE__,"CactusBindings",message); -# free(message); -# retval = -2; -# } -# } -# -# free(implementation); -# free(param_name); -# return retval; -#} - -#int CCTKi_BindingsParameterGet(const char *identifier, void **value) -#{ -# int retval = 1; -# int temp_retval; -# char *implementation = NULL; -# char *param_name = NULL; -# -# Util_SplitString(&implementation, ¶m_name, identifier, "::"); -# -# if(!implementation) -# { -# retval = CCTK_BindingsParametersGlobalGet(identifier, value); -# } -# else -# { -#EOT -# -# foreach $routine (keys %routines, "CCTK_BindingsParametersGlobal") -# { -# -# print OUT <<EOT; -# -# if(CCTK_Equals(implementation, \"$routines{$routine}\")) -# { -#EOT -# print OUT " temp_retval = $routine"."Get(param_name, value);"; -# -# print OUT <<EOT; -# -# if(!temp_retval) -# { -# retval = 0; -# } -# } -#EOT -# } -# -# print OUT <<EOT; -# } -# -# free(implementation); -# free(param_name); -# return retval; -#} - -$dataout .= "int CCTKi_BindingsParameterHelp(const char *identifier, const char *format, FILE *file)\n"; -$dataout .= "{\n"; -$dataout .=" int retval = 1;\n"; -$dataout .=" int temp_retval;\n"; -$dataout .=" char *implementation = NULL;\n"; -$dataout .=" char *param_name = NULL;\n\n"; - -$dataout .=" if(! identifier )\n"; -$dataout .=" {\n"; -$dataout .=" retval = CCTK_BindingsParametersGlobalHelp(identifier, format, file);\n\n"; + $dataout .= "return 0;\n"; + $dataout .= "}\n\n"; + + $dataout .= "int CCTKi_BindingsParameterHelp(const char *identifier, const char *format, FILE *file)\n"; + $dataout .= "{\n"; + $dataout .=" int retval = 1;\n"; + $dataout .=" int temp_retval;\n"; + $dataout .=" char *implementation = NULL;\n"; + $dataout .=" char *param_name = NULL;\n\n"; + + $dataout .=" if(! identifier )\n"; + $dataout .=" {\n"; + $dataout .=" retval = CCTK_BindingsParametersGlobalHelp(identifier, format, file);\n\n"; foreach $routine (keys %routines, "CCTK_BindingsParametersGlobal") { $dataout .= " temp_retval = $routine"."Help(param_name, format, file);"; -$dataout .= "\n"; -$dataout .=" if(!temp_retval)\n"; -$dataout .=" {\n"; -$dataout .=" retval = 0;\n"; -$dataout .=" }\n"; + $dataout .= "\n"; + $dataout .=" if(!temp_retval)\n"; + $dataout .=" {\n"; + $dataout .=" retval = 0;\n"; + $dataout .=" }\n"; } -$dataout .=" }\n\n"; - -$dataout .=" Util_SplitString(\&implementation, ¶m_name, identifier, \"::\");\n\n"; - -$dataout .=" if(!implementation)\n"; -$dataout .=" {\n"; -$dataout .=" retval = CCTK_BindingsParametersGlobalHelp(identifier, format, file);\n"; -$dataout .=" }\n"; -$dataout .=" else\n"; -$dataout .=" { \n"; + $dataout .=" }\n\n"; + + $dataout .=" Util_SplitString(\&implementation, ¶m_name, identifier, \"::\");\n\n"; + + $dataout .=" if(!implementation)\n"; + $dataout .=" {\n"; + $dataout .=" retval = CCTK_BindingsParametersGlobalHelp(identifier, format, file);\n"; + $dataout .=" }\n"; + $dataout .=" else\n"; + $dataout .=" { \n"; foreach $routine (keys %routines, "CCTK_BindingsParametersGlobal") { diff --git a/lib/sbin/create_c_stuff.pl b/lib/sbin/create_c_stuff.pl index e7027311..3616a366 100644 --- a/lib/sbin/create_c_stuff.pl +++ b/lib/sbin/create_c_stuff.pl @@ -81,69 +81,6 @@ sub CreateParameterBindingFile push(@data, ""); - # Initialisation subroutine -# push(@data, ("int $prefix"."Initialise(void)", "{")); -# -# foreach $parameter (sort(keys %parameters)) -# { -# -# push(@data, &set_parameter_default($structure,$parameters{$parameter}, -# $parameter, %parameter_database)); -# -# push(@data, ""); -# -# push(@data, &create_parameter_code($structure,$parameters{$parameter}, -# $parameter, %parameter_database)); -# -# push(@data, ""); -# -# } -# -# push(@data, " return 0;"); -# push(@data, "}"); -# -# push(@data, ""); - - # Setting subroutine - -# push(@data, ("int $prefix"."Set(const char *param, const char *value)", "{")); -# push(@data, (" int retval;", " retval = 1;", "")); -# -# -# foreach $parameter (sort(keys %parameters)) -# { -# push(@data, &set_parameter_code($structure,$parameters{$parameter}, -# $parameter, %parameter_database)); -# push(@data, ""); -# -# } -# -# push(@data, " return retval;"); -# -# push(@data, "}"); -# -# push(@data, ""); - - # Getting subroutine - -# push(@data, ("int $prefix"."Get(const char *param, void **value)", "{")); -# push(@data, (" int retval;", " retval = 1;", "")); -# -# -# foreach $parameter (sort(keys %parameters)) -# { -# push(@data, &get_parameter_code($structure,$parameters{$parameter}, -# $parameter, %parameter_database)); -# push(@data, ""); -# -# } -# -# push(@data, " return retval;"); -# -# push(@data, "}"); -# -# push(@data, ""); - # Help subroutine push(@data, ("int $prefix"."Help(const char *param, const char *format, FILE *file)", "{")); @@ -169,143 +106,6 @@ sub CreateParameterBindingFile #/*@@ -# @routine set_parameter_code -# @date Wed Jan 20 15:21:31 1999 -# @author Tom Goodale -# @desc -# Sets the value of a parameter. -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -#@@*/ - -sub set_parameter_code -{ - local($structure, $implementation,$parameter, %parameter_database) = @_; - local($type, $type_string); - local($line, @lines); - local($range); - local($quoted_range); - - $type = $parameter_database{"\U$implementation $parameter\E type"}; - $n_ranges = $parameter_database{"\U$implementation $parameter\E ranges"}; - - push(@lines,(" if(CCTK_Equals(param, \"$parameter\"))", " {")); - - if( $type ne "STRING" && $type ne "SENTENCE" && $type ne "BOOLEAN") - { - if( $type eq "KEYWORD") - { - $line = " retval = CCTK_SetKeywordInRangeList(\&($structure.$parameter), value, $n_ranges" ; - } - elsif($type eq "INT") - { - $line = " retval = CCTK_SetIntInRangeList(\&($structure.$parameter),value, $n_ranges" ; - } - elsif($type eq "REAL") - { - $line = " retval = CCTK_SetDoubleInRangeList(\&($structure.$parameter),value, $n_ranges" ; - } - for($range=1; $range <= $n_ranges; $range++) - { - $quoted_range = $parameter_database{"\U$implementation $parameter\E range $range range"}; - - #$quoted_range =~ s:\":\\\":g; - $quoted_range =~ s:\"::g; - $quoted_range =~ s:^\s*::; - $quoted_range =~ s:\s*$::; - - $line .= ",\"".$quoted_range."\""; - - } - $line .= ");"; - } - elsif( $type eq "STRING" || $type eq "SENTENCE") - { - $line = " retval = CCTK_SetString(\&($structure.$parameter),value);" ; - } - elsif( $type eq "BOOLEAN") - { - $line = " retval = CCTK_SetLogical(\&($structure.$parameter), value);" ; - - } - else - { - print "Unknown parameter type $type\n"; - } - - push(@lines, ($line, " }")); - - return @lines; -} - - - -#/*@@ -# @routine set_parameter_default -# @date Mon Jan 11 15:33:26 1999 -# @author Tom Goodale -# @desc -# Set the default value of a parameter -# @enddesc -# @calls -# @calledby -# @history -# -# @endhistory -#@@*/ - -sub set_parameter_default -{ - local($structure, $implementation,$parameter, %parameter_database) = @_; - local($type, $type_string); - local($line, @lines); - local($default); - local($temp_default); - - $default = $parameter_database{"\U$implementation $parameter\E default"}; - $type = $parameter_database{"\U$implementation $parameter\E type"}; - - $type_string = &get_c_type_string($type); - - if($type_string eq "char *") - { - $line = " $structure" .".$parameter = malloc(" - . (length($default)-1). "\*sizeof(char));"; - push(@lines, $line); - - $line = " if($structure.$parameter)"; - push(@lines, $line); - - $line = " strcpy($structure.$parameter, $default);"; - push(@lines, $line); - } - elsif($type eq "BOOLEAN") - { - # Logicals need to be done specially. - - # Strip out any quote marks, and spaces at start and end. - $temp_default = $default; - $temp_default =~ s:\"::g; - $temp_default =~ s:\s*$:: ; - $temp_default =~ s:^\s*:: ; - - $line = " CCTK_SetLogical(\&($structure.$parameter),\"$temp_default\");"; - push(@lines, $line); - } - else - { - $line = " $structure.$parameter = $default;"; - push(@lines, $line); - } - - return @lines; -} - -#/*@@ # @routine get_c_type_string # @date Mon Jan 11 15:33:50 1999 # @author Tom Goodale @@ -425,6 +225,7 @@ sub CreateCStructureParameterHeader # Create the structure + push(@data,("#ifdef __cplusplus", "extern \"C\"", "{", "#endif")); push(@data,( "extern struct ", "{")); foreach $parameter (&order_params(scalar(keys %parameters), %parameters,%parameter_database)) @@ -451,6 +252,7 @@ sub CreateCStructureParameterHeader push(@data, "} $structure;"); push(@data, ""); + push(@data,("#ifdef __cplusplus", "}", "#endif")); push(@data, "#define DECLARE_$structure"."_PARAMS \\"); |