[SCM] Gerris Flow Solver branch, upstream, updated. b3aa46814a06c9cb2912790b23916ffb44f1f203
Stephane Popinet
popinet at users.sf.net
Fri May 15 02:54:34 UTC 2009
The following commit has been merged in the upstream branch:
commit bfd2c7b436f498a8f3762cc3e255510d5cb17c35
Author: Stephane Popinet <popinet at users.sf.net>
Date: Wed Sep 5 10:30:59 2007 +1000
Macro support in parameter files
darcs-hash:20070905003059-d4795-176c0efe902937021f29f60f375763f4782cb106.gz
diff --git a/configure.in b/configure.in
index 9f5c69a..668837d 100644
--- a/configure.in
+++ b/configure.in
@@ -13,7 +13,7 @@ dnl are available for $ac_help expansion (don't we all *love* autoconf?)
#
GFS_MAJOR_VERSION=1
GFS_MINOR_VERSION=1
-GFS_MICRO_VERSION=0
+GFS_MICRO_VERSION=1
GFS_INTERFACE_AGE=0
GFS_BINARY_AGE=0
GFS_VERSION=$GFS_MAJOR_VERSION.$GFS_MINOR_VERSION.$GFS_MICRO_VERSION
@@ -260,6 +260,17 @@ else
AC_DEFINE(HAVE_PKG_CONFIG, 0)
fi
+# checks for awk and m4
+AC_CHECK_PROG(have_awk, awk, yes, no)
+if test "$have_awk" = "yes"; then
+ AC_CHECK_PROG(have_m4, m4, yes, no)
+ if test "$have_m4" = "yes"; then
+ AC_DEFINE(HAVE_M4, 1, [Define to 1 if awk and m4 are available.])
+ else
+ AC_DEFINE(HAVE_M4, 0)
+ fi
+fi
+
# check if module support is disabled
AC_ARG_ENABLE(modules,
[ --disable-modules link modules statically with the executables],
diff --git a/debian/control.sh b/debian/control.sh
index 83bf127..e4220b4 100644
--- a/debian/control.sh
+++ b/debian/control.sh
@@ -12,7 +12,7 @@ Package: gerris-snapshot
Section: math
Priority: extra
Architecture: any
-Depends: libgts-snapshot-dev (>= $GTS_VERSION), pkg-config, gcc, sed, gawk
+Depends: libgts-snapshot-dev (>= $GTS_VERSION), pkg-config, gcc, sed, gawk, m4
Conflicts: gerris
Replaces: gerris
Recommends: gfsview-snapshot, imagemagick, ffmpeg
diff --git a/src/Makefile.am b/src/Makefile.am
index 15b694d..57b9774 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,6 +14,7 @@ gerris3D.pc: gerris3D.pc.in
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = gerris2D.pc gerris3D.pc gerris2D3.pc
+pkglib_DATA = m4.awk
lib_LTLIBRARIES = libgfs2D.la libgfs3D.la libgfs2D3.la
@@ -123,7 +124,8 @@ CLEANFILES = $(BUILT_SOURCES)
EXTRA_DIST = \
mpi_boundary.c \
mpi_boundary.h \
- ftt_internal.c
+ ftt_internal.c \
+ m4.awk
bin_PROGRAMS = gerris2D gerris3D gerris2D3
diff --git a/src/gerris.c b/src/gerris.c
index 5134dbd..ae6b241 100644
--- a/src/gerris.c
+++ b/src/gerris.c
@@ -50,6 +50,7 @@ int main (int argc, char * argv[])
guint split = 0;
guint npart = 0;
gboolean profile = FALSE;
+ gchar * m4_options = g_strdup ("-P");
gfs_init (&argc, &argv);
@@ -60,15 +61,16 @@ int main (int argc, char * argv[])
{"split", required_argument, NULL, 's'},
{"partition", required_argument, NULL, 'p'},
{"profile", no_argument, NULL, 'P'},
+ {"define", required_argument, NULL, 'D'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{ NULL }
};
int option_index = 0;
- switch ((c = getopt_long (argc, argv, "hVs:p:P",
+ switch ((c = getopt_long (argc, argv, "hVs:p:PD:",
long_options, &option_index))) {
#else /* not HAVE_GETOPT_LONG */
- switch ((c = getopt (argc, argv, "hVs:p:P"))) {
+ switch ((c = getopt (argc, argv, "hVs:p:PD:"))) {
#endif /* not HAVE_GETOPT_LONG */
case 'P': /* profile */
profile = TRUE;
@@ -79,16 +81,28 @@ int main (int argc, char * argv[])
case 's': /* split */
split = atoi (optarg);
break;
+ case 'D': { /* define */
+ gchar * tmp = g_strjoin (" ", m4_options, "-D", optarg, NULL);
+ g_free (m4_options);
+ m4_options = tmp;
+ break;
+ }
case 'h': /* help */
fprintf (stderr,
"Usage: gerris [OPTION] FILE\n"
"The Gerris flow solver simulation engine.\n"
"\n"
- " -s N --split=N splits the domain N times and returns\n"
- " the corresponding simulation\n"
- " -p N --partition=N partition the domain in 2^N subdomains and returns\n"
- " the corresponding simulation\n"
- " -P --profile profiles calls to boundary conditions\n"
+ " -s N --split=N splits the domain N times and returns\n"
+ " the corresponding simulation\n"
+ " -p N --partition=N partition the domain in 2^N subdomains and returns\n"
+ " the corresponding simulation\n"
+ " -P --profile profiles calls to boundary conditions\n"
+#ifdef HAVE_M4
+ " -DNAME Defines NAME as a macro expanding to VALUE\n"
+ " -DNAME=VALUE\n"
+ " --define=NAME\n"
+ " --define=NAME=VALUE\n"
+#endif /* have m4 */
" -h --help display this help and exit\n"
" -V --version output version information and exit\n"
"\n"
@@ -123,14 +137,26 @@ int main (int argc, char * argv[])
return 1; /* failure */
}
+#ifdef HAVE_M4
+ const gchar awk[] = "awk -f " GFS_MODULES_DIR "/m4.awk ";
+ gchar * command;
+
+ if (!strcmp (argv[optind], "-"))
+ command = g_strjoin (NULL, awk, "| m4 ", m4_options, NULL);
+ else
+ command = g_strjoin (NULL, awk, argv[optind], " | m4 ", m4_options, NULL);
+ fptr = popen (command, "r");
+ g_free (command);
+ g_free (m4_options);
+#else /* do not have m4 */
if (!strcmp (argv[optind], "-"))
fptr = stdin;
- else {
+ else
fptr = fopen (argv[optind], "r");
- if (fptr == NULL) {
- fprintf (stderr, "gerris: unable to open file `%s'\n", argv[optind]);
- return 1;
- }
+#endif /* do not have m4 */
+ if (fptr == NULL) {
+ fprintf (stderr, "gerris: unable to open file `%s'\n", argv[optind]);
+ return 1;
}
fp = gts_file_new (fptr);
@@ -143,8 +169,13 @@ int main (int argc, char * argv[])
return 1;
}
gts_file_destroy (fp);
+
+#ifdef HAVE_M4
+ pclose (fptr);
+#else /* do not have m4 */
if (fptr != stdin)
fclose (fptr);
+#endif /* do not have m4 */
if (npart > 0) {
guint nmin = 1000;
diff --git a/src/m4.awk b/src/m4.awk
new file mode 100644
index 0000000..4d82049
--- /dev/null
+++ b/src/m4.awk
@@ -0,0 +1,23 @@
+function replace_params(s, b, i)
+{
+ for (i in b)
+ gsub(b[i], "($" i ")", s);
+ return s;
+}
+
+{
+ if ($1 == "Define") {
+ macro = $2;
+ delete b;
+ if (match(macro, "([a-zA-Z_]+)\\((([a-zA-Z_]+|,)+)\\)", a)) {
+ macro = a[1];
+ split(a[2],b,",");
+ }
+ printf ("m4_define(`%s',`%s", macro, replace_params($3, b));
+ for (i = 4; i <= NF; i++)
+ printf (" %s", replace_params($i, b));
+ printf ("')\n");
+ }
+ else
+ print $0;
+}
--
Gerris Flow Solver
More information about the debian-science-commits
mailing list