From a5554988d7b607ddb66ac499f3f9ceb74a35f31d Mon Sep 17 00:00:00 2001 From: schnetter Date: Fri, 23 Jun 2006 04:16:13 +0000 Subject: Add a new command line option to select the buffering mode of stdout. The option is "-b ", or "-buffering=", where mode can be "no", "line", or "full". This option uses the ANSI C function call setvbuf() to select the corresponding buffering mode. The buffering mode can be selected only once in a portable programme, and it has to be selected before the first output occurs. This means that it has to be implemented in the flesh. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4329 17b73243-c579-4c4c-a9d2-2d5706c11dac --- src/main/CommandLine.c | 46 ++++++++++++++++++++++++++++++++++++++++--- src/main/ProcessCommandLine.c | 4 +++- 2 files changed, 46 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/CommandLine.c b/src/main/CommandLine.c index 4451949c..bfad972d 100644 --- a/src/main/CommandLine.c +++ b/src/main/CommandLine.c @@ -68,6 +68,7 @@ int cctki_onlyprintschedule = 0; */ #define CACTUS_COMMANDLINE_OPTIONS \ "[-h] [-O] [-o paramname] [-L n] [-W n] [-E n] [-r[o|e|oe|eo]] " \ + "[-b [no|line|full]] " \ "[-S] [-T] [-t name] [-parameter-level ] [-v] " \ "" @@ -415,8 +416,8 @@ void CCTKi_CommandLineParameterLevel (const char *argument) else { CCTK_VWarn (1, __LINE__, __FILE__, "Cactus", - "CCTKi_CommandLineParameterLevel: Parameter checking level " - "'%s' not recognized, defaulting to normal", argument); + "Parameter checking level '%s' not recognised, " + "defaulting to normal", argument); parameterlevel = CCTK_PARAMETER_NORMAL; } @@ -425,7 +426,7 @@ void CCTKi_CommandLineParameterLevel (const char *argument) /*@@ - @routine CCTKi_CommandLineRedirectStdout + @routine CCTKi_CommandLineRedirect @date Fri Jul 23 11:32:46 1999 @author Tom Goodale @desc @@ -460,6 +461,44 @@ void CCTKi_CommandLineRedirect (const char *argument) } } } + /*@@ + @routine CCTKi_CommandLineSetBuffering + @date 2006-05-27 + @author Erik Schnetter + @desc + Set stdout buffering. (stderr is always unbuffered.) + @enddesc + + @var argument + @vdesc option argument + @vtype const char * + @vio in + @endvar +@@*/ +void CCTKi_CommandLineSetBuffering (const char *argument) +{ + if (! strcmp (argument, "no")) + { + /* Switch to unbuffered mode (best for debugging) */ + setvbuf (stdout, NULL, _IONBF, 0); + } + else if (! strcmp (argument, "line")) + { + /* Switch to line buffered mode (good for screen output) */ + setvbuf (stdout, NULL, _IOLBF, 0); + } + else if (! strcmp (argument, "full")) + { + /* Switch to fully buffered mode (fastest) */ + setvbuf (stdout, NULL, _IOFBF, 0); + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, "Cactus", + "Stdout buffering mode '%s' not recognised, " + "not changing the default setting", argument); + } +} /*@@ @@ -562,6 +601,7 @@ void CCTKi_CommandLineHelp (void) "-E, -error-level : Sets the error level to n.\n" "-r, -redirect [o|e|oe|eo] : Redirects standard output and/or standard\n" " error to files.\n" + "-b, -buffering [no|line|full] : Set stdout buffering mode.\n" "-S, -print-schedule : Print the schedule tree, then exit.\n" "-T, -list-thorns : Lists the compiled-in thorns.\n" "-t, -test-thorn-compiled : Tests for the presence of thorn .\n" diff --git a/src/main/ProcessCommandLine.c b/src/main/ProcessCommandLine.c index 3c19b6c6..57543700 100644 --- a/src/main/ProcessCommandLine.c +++ b/src/main/ProcessCommandLine.c @@ -135,6 +135,7 @@ int CCTKi_ProcessCommandLine(int *inargc, char ***inargv, tFleshConfig *ConfigDa {"error-level", required_argument, NULL, 'E'}, {"parameter-level", required_argument, NULL, 256}, {"redirect", optional_argument, NULL, 'r'}, + {"buffering", required_argument, NULL, 'b'}, {"print-schedule", no_argument, NULL, 'S'}, {"list-thorns", no_argument, NULL, 'T'}, {"test-thorn-compiled", required_argument, NULL, 't'}, @@ -143,7 +144,7 @@ int CCTKi_ProcessCommandLine(int *inargc, char ***inargv, tFleshConfig *ConfigDa {0, 0, 0, 0} }; - c = getopt_long_only (argc, argv, "hO::o:x::L:W:E:r::STt:vi", + c = getopt_long_only (argc, argv, "hO::o:x::L:W:E:r::b:STt:vi", long_options, &option_index); if (c == -1) break; @@ -161,6 +162,7 @@ int CCTKi_ProcessCommandLine(int *inargc, char ***inargv, tFleshConfig *ConfigDa case 'E': CCTKi_CommandLineErrorLevel(optarg); break; case 256: CCTKi_CommandLineParameterLevel(optarg); break; case 'r': CCTKi_CommandLineRedirect(optarg); break; + case 'b': CCTKi_CommandLineSetBuffering(optarg); break; case 'S': CCTKi_CommandLinePrintSchedule(); break; case 'T': CCTKi_CommandLineListThorns(); break; case 'v': CCTKi_CommandLineVersion(); break; -- cgit v1.2.3