From 278a36481782d417a6f6b0655e8e14f502433677 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Mon, 8 May 2023 19:01:59 -0600 Subject: [PATCH 1/2] Making registry work in out of source build --- tools/gen_streams.c | 4 +++- tools/reg_parse.c | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/gen_streams.c b/tools/gen_streams.c index f93cf3989d..e6cbda002d 100644 --- a/tools/gen_streams.c +++ b/tools/gen_streams.c @@ -607,12 +607,14 @@ gen_med_find_esmf_coupling ( FILE *fp ) for each stream. This file is then included by the registry.io_boilerplate file when the registry actually runs. As with the other mods above, this allows a variable, compile-time number of io streams. Note that this one is self contained and dirname is hard-coded. + AI: In an effort to delineate true source files from autogen stuff this is now not going into hard-coded + Registry so that we can use ./ as an alternate include location */ int gen_io_boilerplate () { FILE * fp ; - char * dirname = "Registry" ; + char * dirname = "./" ; char fname[NAMELEN] ; char * fn ; char * aux , *streamtype , streamno[5] ; diff --git a/tools/reg_parse.c b/tools/reg_parse.c index 01176c0ea4..5321b58402 100644 --- a/tools/reg_parse.c +++ b/tools/reg_parse.c @@ -116,21 +116,28 @@ pre_parse( char * dir, FILE * infile, FILE * outfile ) for ( p = inln ; ( *p == ' ' || *p == ' ' ) && *p != '\0' ; p++ ) ; if ( !strncmp( p , "include", 7 ) && ! ( ifdef_stack_ptr >= 0 && ! ifdef_stack[ifdef_stack_ptr] ) ) { FILE *include_fp ; + char include_file_name_dir[128] ; char include_file_name[128] ; p += 7 ; for ( ; ( *p == ' ' || *p == ' ' ) && *p != '\0' ; p++ ) ; if ( strlen( p ) > 127 ) { fprintf(stderr,"Registry warning: invalid include file name: %s\n", p ) ; } else { - sprintf( include_file_name , "%s/%s", dir , p ) ; + + sprintf( include_file_name, "%s", p ) ; if ( (p=index(include_file_name,'\n')) != NULL ) *p = '\0' ; + sprintf( include_file_name_dir, "%s/%s", dir , include_file_name ) ; + fprintf(stderr,"opening %s\n",include_file_name) ; - if (( include_fp = fopen( include_file_name , "r" )) != NULL ) { + if ( ( ( include_fp = fopen( include_file_name, "r" ) ) != NULL ) || // Use short circuit logic here to try both sequentially + ( ( include_fp = fopen( include_file_name_dir, "r" ) ) != NULL ) ) + { fprintf(stderr,"including %s\n",include_file_name ) ; pre_parse( dir , include_fp , outfile ) ; fclose( include_fp ) ; - } else { - fprintf(stderr,"Registry warning: cannot open %s. Ignoring.\n", include_file_name ) ; + } + else { + fprintf(stderr,"Registry warning: cannot open %s. Tried %s and %s Ignoring.\n", include_file_name, include_file_name, include_file_name_dir ) ; } } } From 484cba66b3f48ed28c2bd5db2b199f05c6a1a824 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Thu, 11 Jan 2024 16:09:41 -0700 Subject: [PATCH 2/2] Output boiler plate back under Registry, but add ./Registry as alternate search path --- tools/gen_streams.c | 4 +--- tools/reg_parse.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/gen_streams.c b/tools/gen_streams.c index e6cbda002d..f93cf3989d 100644 --- a/tools/gen_streams.c +++ b/tools/gen_streams.c @@ -607,14 +607,12 @@ gen_med_find_esmf_coupling ( FILE *fp ) for each stream. This file is then included by the registry.io_boilerplate file when the registry actually runs. As with the other mods above, this allows a variable, compile-time number of io streams. Note that this one is self contained and dirname is hard-coded. - AI: In an effort to delineate true source files from autogen stuff this is now not going into hard-coded - Registry so that we can use ./ as an alternate include location */ int gen_io_boilerplate () { FILE * fp ; - char * dirname = "./" ; + char * dirname = "Registry" ; char fname[NAMELEN] ; char * fn ; char * aux , *streamtype , streamno[5] ; diff --git a/tools/reg_parse.c b/tools/reg_parse.c index 5321b58402..4578d7b202 100644 --- a/tools/reg_parse.c +++ b/tools/reg_parse.c @@ -116,19 +116,21 @@ pre_parse( char * dir, FILE * infile, FILE * outfile ) for ( p = inln ; ( *p == ' ' || *p == ' ' ) && *p != '\0' ; p++ ) ; if ( !strncmp( p , "include", 7 ) && ! ( ifdef_stack_ptr >= 0 && ! ifdef_stack[ifdef_stack_ptr] ) ) { FILE *include_fp ; - char include_file_name_dir[128] ; + char include_file_name_local_registry[128] ; char include_file_name[128] ; p += 7 ; for ( ; ( *p == ' ' || *p == ' ' ) && *p != '\0' ; p++ ) ; if ( strlen( p ) > 127 ) { fprintf(stderr,"Registry warning: invalid include file name: %s\n", p ) ; } else { - sprintf( include_file_name, "%s", p ) ; + sprintf( include_file_name_local_registry, "./Registry/%s", p ) ; + sprintf( include_file_name, "%s/%s", dir , p ) ; + + if ( (p=index(include_file_name_local_registry,'\n')) != NULL ) *p = '\0' ; if ( (p=index(include_file_name,'\n')) != NULL ) *p = '\0' ; - sprintf( include_file_name_dir, "%s/%s", dir , include_file_name ) ; - + fprintf(stderr,"opening %s\n",include_file_name) ; - if ( ( ( include_fp = fopen( include_file_name, "r" ) ) != NULL ) || // Use short circuit logic here to try both sequentially - ( ( include_fp = fopen( include_file_name_dir, "r" ) ) != NULL ) ) + if ( ( ( include_fp = fopen( include_file_name_local_registry, "r" ) ) != NULL ) || // Use short circuit logic here to try both sequentially + ( ( include_fp = fopen( include_file_name, "r" ) ) != NULL ) ) { fprintf(stderr,"including %s\n",include_file_name ) ; @@ -137,7 +139,7 @@ pre_parse( char * dir, FILE * infile, FILE * outfile ) fclose( include_fp ) ; } else { - fprintf(stderr,"Registry warning: cannot open %s. Tried %s and %s Ignoring.\n", include_file_name, include_file_name, include_file_name_dir ) ; + fprintf(stderr,"Registry warning: cannot open %s. Tried %s and %s Ignoring.\n", include_file_name, include_file_name, include_file_name_local_registry ) ; } } }