[med-svn] [cnrun] 09/25: update libstilton; begin using cnrun namespace; drop logging facility
andrei zavada
hmmr-guest at moszumanska.debian.org
Thu Nov 6 22:08:30 UTC 2014
This is an automated email from the git hooks/post-receive script.
hmmr-guest pushed a commit to branch WIP
in repository cnrun.
commit d960e21a8a46312b4817c03a61db35f4e45609e8
Author: Andrei Zavada <johnhommer at gmail.com>
Date: Sun Mar 30 00:49:46 2014 +0200
update libstilton; begin using cnrun namespace; drop logging facility
---
.../src/cnrun/runner-interpreter-completions.cc | 28 +-
upstream/src/cnrun/runner-interpreter.cc | 192 +++++++------
upstream/src/cnrun/runner-main.cc | 59 ++--
upstream/src/cnrun/runner.hh | 23 +-
upstream/src/libcn/hosted-neurons.cc | 2 +-
upstream/src/libcn/model-cycle.cc | 2 +-
upstream/src/libcn/model-struct.cc | 10 +-
upstream/src/libcn/types.cc | 10 +-
upstream/src/libstilton/Makefile.am | 17 +-
upstream/src/libstilton/alg.hh | 103 +++++++
upstream/src/libstilton/containers.hh | 67 +++++
upstream/src/libstilton/exprparser.cc | 6 +-
upstream/src/libstilton/exprparser.hh | 3 +-
upstream/src/libstilton/gcc-builtins.hh | 43 ---
upstream/src/libstilton/lang.hh | 87 ++++++
upstream/src/libstilton/libcommon.cc | 303 +++++++++++++++++++++
upstream/src/libstilton/log-facility.cc | 147 ----------
upstream/src/libstilton/log-facility.hh | 76 ------
upstream/src/libstilton/pointaligned-s.cc | 79 ------
upstream/src/libstilton/pointaligned-s.hh | 26 --
upstream/src/libstilton/string.hh | 118 ++++++++
21 files changed, 850 insertions(+), 551 deletions(-)
diff --git a/upstream/src/cnrun/runner-interpreter-completions.cc b/upstream/src/cnrun/runner-interpreter-completions.cc
index 72a4e9b..3609ee1 100644
--- a/upstream/src/cnrun/runner-interpreter-completions.cc
+++ b/upstream/src/cnrun/runner-interpreter-completions.cc
@@ -11,14 +11,17 @@
#include <stdio.h>
-#include "config.h"
+#if HAVE_CONFIG_H && !defined(VERSION)
+# include "config.h"
+#endif
+
#ifdef HAVE_LIBREADLINE
# if defined(HAVE_READLINE_READLINE_H)
# include <readline/readline.h>
# elif defined(HAVE_READLINE_H)
# include <readline.h>
-# endif /* !defined(HAVE_READLINE_H) */
-#endif /* HAVE_LIBREADLINE */
+# endif
+#endif
#ifdef HAVE_READLINE_HISTORY
# if defined(HAVE_READLINE_HISTORY_H)
@@ -26,25 +29,19 @@
# elif defined(HAVE_HISTORY_H)
# include <history.h>
# endif
-#endif /* HAVE_READLINE_HISTORY */
+#endif
#include "runner.hh"
#include "libcn/model.hh"
-#if HAVE_CONFIG_H && !defined(VERSION)
-# include "config.h"
-#endif
-
using namespace std;
-using namespace Stilton;
-
+using namespace cnrun;
static char*
cnrun_null_generator( const char* text, int state)
{
-// printf( "No completion in this context\n");
return nullptr;
}
@@ -154,7 +151,7 @@ cnrun_syn_type_generator( const char *text, int state)
-bool regenerate_unit_labels = true;
+bool cnrun::regenerate_unit_labels = true;
#define GENERATE_NEURONS 1
#define GENERATE_SYNAPSES 2
@@ -204,7 +201,7 @@ cnrun_unit_label_generator( const char *text, int state)
-bool regenerate_var_names = true;
+bool cnrun::regenerate_var_names = true;
static char*
cnrun_var_names_generator( const char *text, int state)
@@ -247,7 +244,7 @@ cnrun_var_names_generator( const char *text, int state)
-bool regenerate_source_ids = true;
+bool cnrun::regenerate_source_ids = true;
static char*
cnrun_source_id_generator( const char *text, int state)
@@ -363,6 +360,7 @@ rl_point_at_word()
char**
+cnrun::
cnrun_completion( const char *text, int start, int end)
{
if ( start == 0 )
@@ -451,6 +449,4 @@ cnrun_completion( const char *text, int start, int end)
}
-
-
// EOF
diff --git a/upstream/src/cnrun/runner-interpreter.cc b/upstream/src/cnrun/runner-interpreter.cc
index 3521279..9aaa464 100644
--- a/upstream/src/cnrun/runner-interpreter.cc
+++ b/upstream/src/cnrun/runner-interpreter.cc
@@ -17,33 +17,32 @@
#include <list>
#include <initializer_list>
-#include "config.h"
+#if HAVE_CONFIG_H && !defined(VERSION)
+# include "config.h"
+#endif
#if defined(HAVE_READLINE_READLINE_H)
# include <readline/readline.h>
#elif defined(HAVE_READLINE_H)
# include <readline.h>
-#endif /* !defined(HAVE_READLINE_H) */
+#endif
#if defined(HAVE_READLINE_HISTORY_H)
# include <readline/history.h>
#elif defined(HAVE_HISTORY_H)
# include <history.h>
-# endif
+#endif
+#include "libstilton/string.hh"
#include "runner.hh"
#include "libstilton/exprparser.hh"
#include "libcn/integrate-rk65.hh"
#include "libcn/base-unit.hh"
-#if HAVE_CONFIG_H && !defined(VERSION)
-# include "config.h"
-#endif
-
using namespace std;
+using namespace cnrun;
-
-const char* const cnrun_cmd[] = {
+const char* const cnrun::cnrun_cmd[] = {
"new_model",
"load_nml",
"merge_nml",
@@ -86,29 +85,23 @@ const char* const cnrun_cmd[] = {
-list<SVariable> *current_shell_variables;
+list<SVariable> *cnrun::current_shell_variables;
namespace {
void
-LOG( const char *fname, int lineno, int vrb, const char* fmt, ...)
+report_script_issue( const char *fname, int lineno, int vrb, const char* fmt, ...)
{
va_list ap;
va_start (ap, fmt);
-
- char *buf1 = const_cast<char*>(""), *buf2;
- if ( lineno > 0 )
- assert (asprintf( &buf1, "%s:%d: ", fname, lineno) > 0);
- assert (vasprintf( &buf2, fmt, ap) > 0);
+ string body = str::svasprintf( fmt, ap);
va_end (ap);
- Log->msg( vrb, "CNrun", "%s%s", buf1, buf2);
-
- if ( lineno > 0 )
- free( buf1);
- free( buf2);
+ string pre = ( lineno > 0 )
+ ? str::sasprintf( "%s:%d: %s", fname, lineno, body.c_str())
+ : str::sasprintf( "%s: %s", fname, body.c_str());
}
int do_single_cmd( const char*,
@@ -142,18 +135,18 @@ new_model( const char *model_name, const char *fname, unsigned lineno)
(Options.display_progress_percent ? CN_MDL_DISPLAY_PROGRESS_PERCENT : 0) |
(Options.display_progress_time ? CN_MDL_DISPLAY_PROGRESS_TIME : 0) |
(Options.dont_coalesce ? CN_MDL_DONT_COALESCE : 0))) ) {
- LOG( fname, lineno, -1, "Failed to create a model");
+ report_script_issue( fname, lineno, -1, "Failed to create model");
return CN_INTERP_SYSFAIL;
}
Model->verbosely = Options.verbosely;
Model->listen_dt = Options.listen_dt;
Model->spike_threshold = Options.spike_threshold /*, Model->spike_lapse = Options.spike_lapse */;
- Log->msg( 3, nullptr,
- "generator type: %s\n"
- " seed = %lu\n"
- " first value = %lu\n",
- gsl_rng_name (Model->_rng), gsl_rng_default_seed, gsl_rng_get (Model->_rng));
+ lprintf( 3,
+ "generator type: %s\n"
+ " seed = %lu\n"
+ " first value = %lu\n",
+ gsl_rng_name (Model->_rng), gsl_rng_default_seed, gsl_rng_get (Model->_rng));
return 0;
}
@@ -177,14 +170,14 @@ do_single_cmd( const char* raw,
#define CHECK_MODEL \
if ( !Model ) { \
- LOG( fname, lineno, -1, "No model loaded"); \
+ report_script_issue( fname, lineno, -1, "No model loaded"); \
return CN_INTERP_WARN; \
}
if ( strcmp( cmd, cnrun_cmd[CNCMD_new_model]) == 0 ) {
if ( !operand ) {
- LOG( fname, lineno, -1, "Missing a name for the new model");
+ report_script_issue( fname, lineno, -1, "Missing a name for the new model");
return CN_INTERP_PARSEERROR;
}
delete Model;
@@ -195,7 +188,7 @@ do_single_cmd( const char* raw,
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_load_nml]) == 0 ) {
struct stat s;
if ( stat( operand, &s) ) {
- LOG( fname, lineno, -1, "No such file: \"%s\"", operand);
+ report_script_issue( fname, lineno, -1, "No such file: \"%s\"", operand);
return CN_INTERP_SYSFAIL;
}
@@ -204,7 +197,7 @@ do_single_cmd( const char* raw,
return retval;
if ( Model->import_NetworkML( operand, false) < 0 ) {
- LOG( fname, lineno, -1, "Failed to create model topology from \"%s\"", operand);
+ report_script_issue( fname, lineno, -1, "Failed to create model topology from \"%s\"", operand);
delete Model;
Model = nullptr;
return CN_INTERP_SYSFAIL;
@@ -218,11 +211,11 @@ do_single_cmd( const char* raw,
CHECK_MODEL;
struct stat s;
if ( stat( operand, &s) ) {
- LOG( fname, lineno, -1, "No such file: \"%s\"", operand);
+ report_script_issue( fname, lineno, -1, "No such file: \"%s\"", operand);
return CN_INTERP_SYSFAIL;
}
if ( Model->import_NetworkML( operand, true) < 0 ) {
- LOG( fname, lineno, -1, "Failed to import topology from \"%s\"", operand);
+ report_script_issue( fname, lineno, -1, "Failed to import topology from \"%s\"", operand);
return CN_INTERP_SYSFAIL;
}
@@ -235,11 +228,11 @@ do_single_cmd( const char* raw,
if ( !operand ||
!(type_s = (strtok( operand, " \t"))) ||
!(label_s = strtok( nullptr, "\n")) ) {
- LOG( fname, lineno, -1, "Missing neuron type and/or label in `add_neuron'");
+ report_script_issue( fname, lineno, -1, "Missing neuron type and/or label in `add_neuron'");
return CN_INTERP_PARSEERROR;
}
if ( !Model->add_neuron_species( type_s, label_s, true) ) {
- LOG( fname, lineno, -1, "`add_neuron' failed");
+ report_script_issue( fname, lineno, -1, "`add_neuron' failed");
return CN_INTERP_PARSEERROR;
}
regenerate_unit_labels = true;
@@ -253,17 +246,17 @@ do_single_cmd( const char* raw,
!(src_s = strtok( nullptr, " \t")) ||
!(tgt_s = strtok( nullptr, " \t")) ||
!(g_s = strtok( nullptr, "\n")) ) {
- LOG( fname, lineno, -1, "Missing synapse type, source or target label, and/or gsyn in `add_synapse'");
+ report_script_issue( fname, lineno, -1, "Missing synapse type, source or target label, and/or gsyn in `add_synapse'");
return CN_INTERP_PARSEERROR;
}
double g;
if ( expr( g_s, g, &varlist) ) {
- LOG( fname, lineno, -1, "Bad value for gsyn in `add_synapse'");
+ report_script_issue( fname, lineno, -1, "Bad value for gsyn in `add_synapse'");
return CN_INTERP_PARSEERROR;
}
if ( !Model->add_synapse_species( type_s, src_s, tgt_s, g, true, true) ) {
- LOG( fname, lineno, -1, "`add_synapse' failed (reason given above)", operand);
+ report_script_issue( fname, lineno, -1, "`add_synapse' failed (reason given above)", operand);
return CN_INTERP_SYSFAIL;
}
regenerate_unit_labels = true;
@@ -273,12 +266,12 @@ do_single_cmd( const char* raw,
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_reset]) == 0 ) {
CHECK_MODEL;
Model->reset();
- Log->msg( 0, nullptr, "Reset model and state all units");
+ lprintf( 0, "Reset model and state of all units");
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_reset_revert_params]) == 0 ) {
CHECK_MODEL;
Model->reset( true);
- Log->msg( 0, nullptr, "Reset model and reverted all units' state and parameters");
+ lprintf( 0, "Reset model and reverted all units' state and parameters");
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_reset_state_units]) == 0 ) {
CHECK_MODEL;
@@ -286,7 +279,7 @@ do_single_cmd( const char* raw,
operand = const_cast<char*>(".*");
regex_t RE;
if ( 0 != regcomp( &RE, operand, REG_EXTENDED | REG_NOSUB) ) {
- LOG( fname, lineno, -1, "Invalid regexp for `reset_state_units' arg");
+ report_script_issue( fname, lineno, -1, "Invalid regexp for `reset_state_units' arg");
return CN_INTERP_PARSEERROR;
}
size_t cnt = 0;
@@ -296,18 +289,18 @@ do_single_cmd( const char* raw,
++cnt;
}
if ( cnt )
- Log->msg( 0, nullptr, "Reset %zd unit(s)", cnt);
+ lprintf( 0, "Reset %zd unit(s)", cnt);
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_advance_until]) == 0 ) {
CHECK_MODEL;
expr.silent = true;
if ( !operand || expr( operand, result, &varlist) ) {
- LOG( fname, lineno, -1, "No or bad time value for `advance_until'");
+ report_script_issue( fname, lineno, -1, "No or bad time value for `advance_until'");
return CN_INTERP_PARSEERROR;
}
if ( Model->model_time() > result ) {
- LOG( fname, lineno, 0, "Cannot go back in time (now is %g)", Model->model_time());
+ report_script_issue( fname, lineno, 0, "Cannot go back in time (now is %g)", Model->model_time());
return CN_INTERP_WARN;
}
@@ -319,7 +312,7 @@ do_single_cmd( const char* raw,
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_advance]) == 0 ) {
CHECK_MODEL;
if ( !operand || expr( operand, result, &varlist) ) {
- LOG( fname, lineno, -1, "No or bad time value for `advance'");
+ report_script_issue( fname, lineno, -1, "No or bad time value for `advance'");
return CN_INTERP_PARSEERROR;
}
@@ -333,7 +326,7 @@ do_single_cmd( const char* raw,
char *label_s;
if ( !operand ||
!(label_s = (strtok( operand, " \t"))) ) {
- LOG( fname, lineno, -1, "Missing label in `putout'");
+ report_script_issue( fname, lineno, -1, "Missing label in `putout'");
return CN_INTERP_PARSEERROR;
}
@@ -350,15 +343,15 @@ do_single_cmd( const char* raw,
if ( !operand ||
!(label_s = (strtok( operand, " \t"))) ||
!(frac_s = (strtok( nullptr, "\n"))) ) {
- LOG( fname, lineno, -1, "Missing fraction or label in `decimate'");
+ report_script_issue( fname, lineno, -1, "Missing fraction or label in `decimate'");
return CN_INTERP_PARSEERROR;
}
if ( expr( frac_s, result, &varlist) ) {
- LOG( fname, lineno, -1, "Unparsable expression for decimation fraction: \"%s\"", operand);
+ report_script_issue( fname, lineno, -1, "Unparsable expression for decimation fraction: \"%s\"", operand);
return CN_INTERP_PARSEERROR;
}
if ( result < 0. || result > 1. ) {
- LOG( fname, lineno, -1, "Decimation fraction outside [0..1]");
+ report_script_issue( fname, lineno, -1, "Decimation fraction outside [0..1]");
return CN_INTERP_PARSEERROR;
}
@@ -373,7 +366,7 @@ do_single_cmd( const char* raw,
CHECK_MODEL;
if ( !operand ||
!(operand = (strtok( operand, " \t")) ) ) {
- LOG( fname, lineno, -1, "Missing label in `start_listen'");
+ report_script_issue( fname, lineno, -1, "Missing label in `start_listen'");
return CN_INTERP_PARSEERROR;
}
list<CModel::STagGroupListener> tags;
@@ -387,7 +380,7 @@ do_single_cmd( const char* raw,
CHECK_MODEL;
if ( !operand ||
!(operand = (strtok( operand, " \t"))) ) {
- LOG( fname, lineno, -1, "Missing label in `stop_listen'");
+ report_script_issue( fname, lineno, -1, "Missing label in `stop_listen'");
return CN_INTERP_PARSEERROR;
}
list<CModel::STagGroupListener> tags;
@@ -397,11 +390,11 @@ do_single_cmd( const char* raw,
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_listen_dt]) == 0 ) {
if ( !operand ) {
- Log->msg( 0, nullptr, "listen_dt is %g", Options.listen_dt);
+ lprintf( 0, "listen_dt is %g", Options.listen_dt);
return 0;
}
if ( expr( operand, result, &varlist) ) {
- LOG( fname, lineno, -1, "Unparsable expression for value in `listen_dt'");
+ report_script_issue( fname, lineno, -1, "Unparsable expression for value in `listen_dt'");
return CN_INTERP_PARSEERROR;
}
if ( Model )
@@ -410,7 +403,7 @@ do_single_cmd( const char* raw,
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_listen_mode]) == 0 ) {
if ( !operand )
- Log->msg( 0, nullptr, "listen mode is 1%sd%sb%s (%s%s%s)",
+ lprintf( 0, "listen mode is 1%sd%sb%s (%s%s%s)",
Options.listen_1varonly ? "+" : "",
Options.listen_deferwrite ? "+" : "",
Options.listen_binary ? "+" : "",
@@ -426,11 +419,11 @@ do_single_cmd( const char* raw,
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_integration_dt_min]) == 0 ) {
if ( !operand ) {
- Log->msg( 0, nullptr, "integration_dt_min is %g", Options.integration_dt_min);
+ lprintf( 0, "integration_dt_min is %g", Options.integration_dt_min);
return 0;
}
if ( expr( operand, result, &varlist) ) {
- LOG( fname, lineno, -1, "Unparsable expression for value in `integration_dt_min'");
+ report_script_issue( fname, lineno, -1, "Unparsable expression for value in `integration_dt_min'");
return CN_INTERP_PARSEERROR;
}
Options.integration_dt_min = result;
@@ -439,11 +432,11 @@ do_single_cmd( const char* raw,
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_integration_dt_max]) == 0 ) {
if ( !operand ) {
- Log->msg( 0, nullptr, "integration_dt_max is %g", Options.integration_dt_max);
+ lprintf( 0, "integration_dt_max is %g", Options.integration_dt_max);
return 0;
}
if ( expr( operand, result, &varlist) ) {
- LOG( fname, lineno, -1, "Unparsable expression for value in `integration_dt_max'");
+ report_script_issue( fname, lineno, -1, "Unparsable expression for value in `integration_dt_max'");
return CN_INTERP_PARSEERROR;
}
Options.integration_dt_max = result;
@@ -452,11 +445,11 @@ do_single_cmd( const char* raw,
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_integration_dt_cap]) == 0 ) {
if ( !operand ) {
- Log->msg( 0, nullptr, "integration_dt_cap is %g", Options.integration_dt_max_cap);
+ lprintf( 0, "integration_dt_cap is %g", Options.integration_dt_max_cap);
return 0;
}
if ( expr( operand, result, &varlist) ) {
- LOG( fname, lineno, -1, "Unparsable expression for value in `integration_dt_cap'");
+ report_script_issue( fname, lineno, -1, "Unparsable expression for value in `integration_dt_cap'");
return CN_INTERP_PARSEERROR;
}
Options.integration_dt_max_cap = result;
@@ -466,13 +459,13 @@ do_single_cmd( const char* raw,
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_set_sxf_params]) == 0 ) {
if ( !operand ) {
- Log->msg( 0, nullptr, "sxf_start_delay:sxf_period:sdf_sigma is %g:%g:%g",
+ lprintf( 0, "sxf_start_delay:sxf_period:sdf_sigma is %g:%g:%g",
Options.sxf_start_delay, Options.sxf_sample, Options.sdf_sigma);
return 0;
}
if ( sscanf( operand, "%g:%g:%g",
&Options.sxf_start_delay, &Options.sxf_sample, &Options.sdf_sigma) < 3 ) {
- LOG( fname, lineno, -1, "Expecting <double>:<double>:<double> with set_sxf_params");
+ report_script_issue( fname, lineno, -1, "Expecting <double>:<double>:<double> with set_sxf_params");
return CN_INTERP_PARSEERROR;
}
@@ -482,11 +475,11 @@ do_single_cmd( const char* raw,
char *label_s;
if ( !operand ||
!(label_s = (strtok( operand, " \t"))) ) {
- LOG( fname, lineno, -1, "Missing label in `start_log_spikes'");
+ report_script_issue( fname, lineno, -1, "Missing label in `start_log_spikes'");
return CN_INTERP_PARSEERROR;
}
if ( Options.sxf_sample <= 0. || Options.sdf_sigma <= 0. ) {
- LOG( fname, lineno, 1, "SDF parameters not set up, will only log spike times");
+ report_script_issue( fname, lineno, 1, "SDF parameters not set up, will only log spike times");
}
list<CModel::STagGroupSpikelogger> specs;
specs.push_back( CModel::STagGroupSpikelogger (label_s, true,
@@ -498,7 +491,7 @@ do_single_cmd( const char* raw,
char *label_s;
if ( !operand ||
!(label_s = (strtok( operand, " \t"))) ) {
- LOG( fname, lineno, -1, "Missing label in `stop_log_spikes'");
+ report_script_issue( fname, lineno, -1, "Missing label in `stop_log_spikes'");
return CN_INTERP_PARSEERROR;
}
list<CModel::STagGroupSpikelogger> specs;
@@ -513,11 +506,11 @@ do_single_cmd( const char* raw,
!(label_s = (strtok( operand, " \t"))) ||
!(parm_s = strtok( nullptr, " \t")) ||
!(value_s = strtok( nullptr, "\n")) ) {
- LOG( fname, lineno, -1, "Missing label, parameter or value in `set_parm_neuron'");
+ report_script_issue( fname, lineno, -1, "Missing label, parameter or value in `set_parm_neuron'");
return CN_INTERP_PARSEERROR;
}
if ( expr( value_s, result, &varlist) ) {
- LOG( fname, lineno, -1, "Unparsable expression for value in `set_parm_neuron'");
+ report_script_issue( fname, lineno, -1, "Unparsable expression for value in `set_parm_neuron'");
return CN_INTERP_PARSEERROR;
}
list<CModel::STagGroupNeuronParmSet> specs = { CModel::STagGroupNeuronParmSet (label_s, true, parm_s, result) };
@@ -532,11 +525,11 @@ do_single_cmd( const char* raw,
!(tgt_s = (strtok( nullptr, " \t"))) ||
!(parm_s = strtok( nullptr, " \t")) ||
!(value_s = strtok( nullptr, "\n")) ) {
- LOG( fname, lineno, -1, "Missing source or target label, parameter and/or value in `set_parm_synapse'");
+ report_script_issue( fname, lineno, -1, "Missing source or target label, parameter and/or value in `set_parm_synapse'");
return CN_INTERP_PARSEERROR;
}
if ( expr( value_s, result, &varlist) ) {
- LOG( fname, lineno, -1, "Unparsable value in `set_parm_synapse'");
+ report_script_issue( fname, lineno, -1, "Unparsable value in `set_parm_synapse'");
return CN_INTERP_PARSEERROR;
}
list<CModel::STagGroupSynapseParmSet> specs = { CModel::STagGroupSynapseParmSet (src_s, tgt_s, true, parm_s, result) };
@@ -549,19 +542,19 @@ do_single_cmd( const char* raw,
if ( !operand ||
!(type_s = (strtok( operand, " \t"))) ||
!(name_s = (strtok( nullptr, " \t"))) ) {
- LOG( fname, lineno, -1, "Missing source type or name in `new_source'");
+ report_script_issue( fname, lineno, -1, "Missing source type or name in `new_source'");
return CN_INTERP_PARSEERROR;
}
if ( Model->source_by_id( name_s) ) {
- LOG( fname, lineno, -1, "A source named \"%s\" already exists", name_s);
+ report_script_issue( fname, lineno, -1, "A source named \"%s\" already exists", name_s);
return CN_INTERP_PARSEERROR;
}
char *arg1, *arg2;
if ( strcmp( type_s, __SourceTypes[SRC_TAPE]) == 0 ) {
if ( !(arg1 = strtok( nullptr, "\n")) ) {
- LOG( fname, lineno, -1, "Missing filename for a Tape source in `new_source'");
+ report_script_issue( fname, lineno, -1, "Missing filename for a Tape source in `new_source'");
return CN_INTERP_PARSEERROR;
} else {
CSourceTape *source = new CSourceTape( name_s, arg1);
@@ -569,18 +562,18 @@ do_single_cmd( const char* raw,
if ( count( Model->Sources.begin(), Model->Sources.end(), source) == 0 )
Model->Sources.push_back( source);
else {
- LOG( fname, lineno, -1, "Duplicate name (\"%s\") for a source", arg1);
+ report_script_issue( fname, lineno, -1, "Duplicate name (\"%s\") for a source", arg1);
return CN_INTERP_SYSFAIL;
}
else {
delete source;
- LOG( fname, lineno, -1, "Failed to set up a Tape source from \"%s\"", arg1);
+ report_script_issue( fname, lineno, -1, "Failed to set up a Tape source from \"%s\"", arg1);
return CN_INTERP_SYSFAIL;
}
}
} else if ( strcmp( type_s, __SourceTypes[SRC_PERIODIC]) == 0 ) {
if ( !(arg1 = strtok( nullptr, "\n")) ) {
- LOG( fname, lineno, -1, "Missing filename for a Periodic source in `new_source'");
+ report_script_issue( fname, lineno, -1, "Missing filename for a Periodic source in `new_source'");
return CN_INTERP_PARSEERROR;
} else {
CSourcePeriodic *source = new CSourcePeriodic( name_s, arg1);
@@ -588,25 +581,25 @@ do_single_cmd( const char* raw,
if ( count( Model->Sources.begin(), Model->Sources.end(), source) == 0 )
Model->Sources.push_back( source);
else {
- LOG( fname, lineno, -1, "Duplicate name (\"%s\") for a source", arg1);
+ report_script_issue( fname, lineno, -1, "Duplicate name (\"%s\") for a source", arg1);
return CN_INTERP_SYSFAIL;
}
else {
delete source;
- LOG( fname, lineno, -1, "Failed to set up a Periodic source from \"%s\"", arg1);
+ report_script_issue( fname, lineno, -1, "Failed to set up a Periodic source from \"%s\"", arg1);
return CN_INTERP_SYSFAIL;
}
}
} else if ( strcmp( type_s, __SourceTypes[SRC_NOISE]) == 0 ) {
if ( !(arg1 = strtok( nullptr, ":")) ||
!(arg2 = strtok( nullptr, "\n")) ) {
- LOG( fname, lineno, -1, "Incomplete min:max set for a Noise source in `new_source'");
+ report_script_issue( fname, lineno, -1, "Incomplete min:max set for a Noise source in `new_source'");
return CN_INTERP_PARSEERROR;
} else {
double _min, _max;
if ( expr( arg1, _min, &varlist) ||
expr( arg2, _max, &varlist) ) {
- LOG( fname, lineno, -1, "Bad min:max values for a Noise source");
+ report_script_issue( fname, lineno, -1, "Bad min:max values for a Noise source");
return CN_INTERP_PARSEERROR;
}
CSourceNoise *source = new CSourceNoise( name_s, _min, _max);
@@ -614,15 +607,15 @@ do_single_cmd( const char* raw,
Model->Sources.push_back( source);
} else {
delete source;
- LOG( fname, lineno, -1, "Failed to set up a Noise source");
+ report_script_issue( fname, lineno, -1, "Failed to set up a Noise source");
return CN_INTERP_SYSFAIL;
}
}
} else if ( strcmp( type_s, __SourceTypes[SRC_FUNCTION]) == 0 ) {
- LOG( fname, lineno, -1, "Go code, Chris!");
+ report_script_issue( fname, lineno, -1, "Go code, Chris!");
return CN_INTERP_SYSFAIL;
} else {
- LOG( fname, lineno, -1, "Unrecognised source type in `new_source'");
+ report_script_issue( fname, lineno, -1, "Unrecognised source type in `new_source'");
return CN_INTERP_PARSEERROR;
}
@@ -642,12 +635,12 @@ do_single_cmd( const char* raw,
!(source_s = strtok( operand, " \t")) ||
!(label_s = strtok( nullptr, " \t")) ||
!(parm_s = strtok( nullptr, "\n")) ) {
- LOG( fname, lineno, -1, "Missing source id, unit label and/or parameter in `connect_source'");
+ report_script_issue( fname, lineno, -1, "Missing source id, unit label and/or parameter in `connect_source'");
return CN_INTERP_PARSEERROR;
}
C_BaseSource *source = Model->source_by_id( source_s);
if ( !source ) {
- LOG( fname, lineno, -1, "Unknown source \"%s\"", source_s);
+ report_script_issue( fname, lineno, -1, "Unknown source \"%s\"", source_s);
return CN_INTERP_PARSEERROR;
}
@@ -663,12 +656,12 @@ do_single_cmd( const char* raw,
!(label_s = (strtok( operand, " \t"))) ||
!(parm_s = strtok( nullptr, " \t")) ||
!(source_s = strtok( nullptr, "\n")) ) {
- LOG( fname, lineno, -1, "Missing label, parameter or source in `disconnect_source'");
+ report_script_issue( fname, lineno, -1, "Missing label, parameter or source in `disconnect_source'");
return CN_INTERP_PARSEERROR;
}
C_BaseSource *source = Model->source_by_id( source_s);
if ( !source ) {
- LOG( fname, lineno, -1, "Unknown source \"%s\"", source_s);
+ report_script_issue( fname, lineno, -1, "Unknown source \"%s\"", source_s);
return CN_INTERP_PARSEERROR;
}
@@ -695,7 +688,7 @@ do_single_cmd( const char* raw,
regex_t RE;
if ( 0 != regcomp( &RE, operand, REG_EXTENDED | REG_NOSUB) ) {
- LOG( fname, lineno, -1, "Invalid regexp for `show_units' arg");
+ report_script_issue( fname, lineno, -1, "Invalid regexp for `show_units' arg");
return CN_INTERP_PARSEERROR;
}
size_t cnt = 0;
@@ -705,7 +698,7 @@ do_single_cmd( const char* raw,
cnt++;
}
if ( cnt )
- Log->msg_( 0, nullptr, "------------\n%zd units total\n", cnt);
+ lprintf( 0, "------------\n%zd units total\n", cnt);
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_exec]) == 0 ) {
return interpreter_run( operand, level+1, Options.interp_howstrict,
@@ -714,9 +707,9 @@ do_single_cmd( const char* raw,
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_verbosity]) == 0 ) {
if ( !operand )
- Log->msg( 0, nullptr, "verbosity level is %d", Options.verbosely);
+ lprintf( 0, "verbosity level is %d", Options.verbosely);
else if ( sscanf( operand, "%d", &Options.verbosely) < 1 ) {
- LOG( fname, lineno, -1, "Bad value for `verbosity'");
+ report_script_issue( fname, lineno, -1, "Bad value for `verbosity'");
return CN_INTERP_PARSEERROR;
}
if ( Model )
@@ -736,7 +729,7 @@ do_single_cmd( const char* raw,
operand = const_cast<char*>(".*");
regex_t RE;
if ( 0 != regcomp( &RE, operand, REG_EXTENDED | REG_NOSUB) ) {
- LOG( fname, lineno, -1, "Invalid regexp for `show_vars' arg");
+ report_script_issue( fname, lineno, -1, "Invalid regexp for `show_vars' arg");
return CN_INTERP_PARSEERROR;
}
size_t cnt = 0;
@@ -747,11 +740,11 @@ do_single_cmd( const char* raw,
longest_id = strlen( V.name);
for ( auto& V : varlist )
if ( regexec( &RE, V.name, 0, 0, 0) == 0 ) {
- Log->msg( 0, nullptr, " %*s = %g", longest_id, V.name, V.value);
+ lprintf( 0, " %*s = %g", (int)longest_id, V.name, V.value);
++cnt;
}
if ( cnt > 1 )
- Log->msg_( 0, nullptr, "---------- %u variables\n", cnt);
+ lprintf( 0, "---------- %zu variables\n", cnt);
} else if ( strcmp( cmd, cnrun_cmd[CNCMD_clear_vars]) == 0 ) {
@@ -760,7 +753,7 @@ do_single_cmd( const char* raw,
else {
regex_t RE;
if ( 0 != regcomp( &RE, operand, REG_EXTENDED | REG_NOSUB) ) {
- LOG( fname, lineno, -1, "Invalid regexp for `clear_vars' arg");
+ report_script_issue( fname, lineno, -1, "Invalid regexp for `clear_vars' arg");
return CN_INTERP_PARSEERROR;
}
for ( list<SVariable>::iterator V = varlist.begin(); V != varlist.end(); V++ )
@@ -779,7 +772,7 @@ do_single_cmd( const char* raw,
if ( expr( operand, s, &varlist) )
return CN_INTERP_PARSEERROR;
if ( s < 0 ) {
- Log->msg( 0, nullptr, "Can't sleep backwards in time");
+ lprintf( 0, "Can't sleep backwards in time");
return CN_INTERP_WARN;
}
printf( "(Paused for %u sec)", (unsigned int)s); fflush(stdin);
@@ -792,11 +785,11 @@ do_single_cmd( const char* raw,
} else { // feed it to exprparser
if ( expr( raw, result, &varlist) ) {
- LOG( fname, lineno, -1, "%s", expr.status_s());
+ report_script_issue( fname, lineno, -1, "%s", expr.status_s());
return CN_INTERP_PARSEERROR;
}
if ( expr.toplevel_op != '=' )
- Log->msg( 0, nullptr, "%g", result);
+ lprintf( 0, "%g", result);
regenerate_var_names = true;
}
@@ -811,6 +804,7 @@ do_single_cmd( const char* raw,
int
+cnrun::
interpreter_run( const char *script_fname, int level, int howstrict,
bool env_import, bool env_export, list<SVariable> &varlist)
{
@@ -827,10 +821,10 @@ interpreter_run( const char *script_fname, int level, int howstrict,
if ( script_fname && strlen(script_fname) > 0 ) {
ifstream script_stream( script_fname);
if ( !script_stream.good() ) {
- Log->msg( -1, "CNrun", "Failed to open script file \"%s\"", script_fname);
+ lprintf( -1, "Failed to open script file \"%s\"", script_fname);
return -1;
}
- Log->msg( 1, nullptr, "execing %s\n", script_fname);
+ lprintf( 1, "execing %s\n", script_fname);
unsigned lineno = 0;
string buf;
diff --git a/upstream/src/cnrun/runner-main.cc b/upstream/src/cnrun/runner-main.cc
index 20fb705..1d2dd2c 100644
--- a/upstream/src/cnrun/runner-main.cc
+++ b/upstream/src/cnrun/runner-main.cc
@@ -9,6 +9,7 @@
*/
+#include <cstdarg>
#include <unistd.h>
#include <list>
@@ -21,14 +22,26 @@
using namespace std;
-using namespace Stilton;
+using namespace cnrun;
-CLogFacility *Log;
-CModel *Model;
+void
+cnrun::
+lprintf( int level, const char* fmt, ...)
+{
+ if ( level > Options.verbosely ) {
+ va_list ap;
+ va_start (ap, fmt);
+ vprintf( fmt, ap);
+ va_end (ap);
+ }
+}
-SCNRunnerOptions Options;
+CModel *cnrun::Model;
+
+
+SCNRunnerOptions cnrun::Options;
const char *ScriptFileName = ""; // CNRUN_DEFAULT_SCRIPT;
@@ -47,18 +60,6 @@ static void usage( const char *argv0);
#define CNRUN_ETRIALFAIL -3
-namespace {
-void LOG( int vrb, const char* fmt, ...) __attribute__ ((format (printf, 2, 3)));
-void LOG( int vrb, const char* fmt, ...)
-{
- va_list ap;
- va_start (ap, fmt);
-
- Log->msgv( vrb, "CNrun", fmt, ap);
- va_end (ap);
-}
-}
-
void print_version( const char* appname);
@@ -69,20 +70,16 @@ main( int argc, char *argv[])
int retval = 0;
- Log = new CLogFacility( nullptr, 0, Options.verbosely, 0, 0|STILTON_LOG_NOLOCK);
-
list<SVariable> Variables;
switch ( parse_options( argc, argv, Variables) ) {
case CNRUN_CLPARSE_ERROR:
- LOG( -1, "Problem parsing command line or sanitising values; try -h for help");
+ fprintf( stderr, "Problem parsing command line or sanitising values; try -h for help\n");
return CNRUN_EARGS;
case CNRUN_CLPARSE_HELP_REQUEST:
usage( argv[0]);
return 0;
}
- Log->log_threshold = Options.verbosely;
-
// purely informational, requires no model
if ( Options.list_units ) {
cnmodel_dump_available_units();
@@ -94,7 +91,7 @@ main( int argc, char *argv[])
if ( Options.working_dir ) {
pwd = getcwd( nullptr, 0);
if ( chdir( Options.working_dir) ) {
- LOG( -1, "Failed to cd to \"%s\"", Options.working_dir);
+ fprintf( stderr, "Failed to cd to \"%s\"", Options.working_dir);
return CNRUN_EARGS;
}
}
@@ -130,18 +127,18 @@ parse_options( int argc, char **argv, list<SVariable>& Variables)
case 't': switch ( optarg[0] ) {
case 'T': if ( sscanf( optarg+1, "%lg", &Options.integration_dt_max) != 1 ) {
- LOG( -1, "-tT takes a double");
+ fprintf( stderr, "-tT takes a double");
return CNRUN_CLPARSE_ERROR;
} break;
case 't': if ( sscanf( optarg+1, "%lg", &Options.integration_dt_min) != 1 ) {
- LOG( -1, "-tt takes a double");
+ fprintf( stderr, "-tt takes a double");
return CNRUN_CLPARSE_ERROR;
} break;
case 'x': if ( sscanf( optarg+1, "%lg", &Options.integration_dt_max_cap) != 1 ) {
- LOG( -1, "-tx takes a double");
+ fprintf( stderr, "-tx takes a double");
return CNRUN_CLPARSE_ERROR;
} break;
- default: LOG( -1, "Unrecognised option modifier for -i");
+ default: fprintf( stderr, "Unrecognised option modifier for -i");
return CNRUN_CLPARSE_ERROR;
} break;
@@ -155,11 +152,11 @@ parse_options( int argc, char **argv, list<SVariable>& Variables)
Options.log_dt = true; break;
case 'E': if ( sscanf( optarg, "%g", &Options.listen_dt) != 1 ) {
- LOG( -1, "-E takes a double");
+ fprintf( stderr, "-E takes a double");
return CNRUN_CLPARSE_ERROR;
} break;
case 'g': if ( sscanf( optarg, "%u", &Options.precision) != 1 ) {
- LOG( -1, "-g takes a short unsigned int");
+ fprintf( stderr, "-g takes a short unsigned int");
return CNRUN_CLPARSE_ERROR;
} break;
@@ -171,10 +168,10 @@ parse_options( int argc, char **argv, list<SVariable>& Variables)
case '0': Options.log_spikers_use_serial_id = true; break;
case 'l': Options.log_spikers_use_serial_id = false; break;
case 'S': if ( sscanf( optarg+1, "%g", &Options.spike_threshold) != 1 ) {
- LOG( -1, "-kS takes a double");
+ fprintf( stderr, "-kS takes a double");
return CNRUN_CLPARSE_ERROR;
}
- default: LOG( -1, "Expecting 0, l, or S<double> after -k");
+ default: fprintf( stderr, "Expecting 0, l, or S<double> after -k");
return CNRUN_CLPARSE_ERROR;
} break;
@@ -190,7 +187,7 @@ parse_options( int argc, char **argv, list<SVariable>& Variables)
double unused;
CExpression expr;
if ( expr( optarg, unused, &Variables) ) {
- LOG( -1, "Malformed variable assignment with -D");
+ fprintf( stderr, "Malformed variable assignment with -D");
return CNRUN_CLPARSE_ERROR;
}
}
diff --git a/upstream/src/cnrun/runner.hh b/upstream/src/cnrun/runner.hh
index 6fcaef6..a98488b 100644
--- a/upstream/src/cnrun/runner.hh
+++ b/upstream/src/cnrun/runner.hh
@@ -15,7 +15,6 @@
#include <list>
#include <iostream>
-#include "libstilton/log-facility.hh"
#include "libstilton/exprparser.hh"
#include "libcn/model.hh"
@@ -25,8 +24,7 @@
# include "config.h"
#endif
-using namespace CNRun;
-using namespace Stilton;
+namespace cnrun {
enum {
CN_INTRP_STRICT,
@@ -88,14 +86,12 @@ struct SCNRunnerOptions {
extern SCNRunnerOptions Options;
-extern Stilton::CLogFacility *Log;
-
extern CModel *Model;
int interpreter_run( const char *script_fname, int level, int howstrict,
- bool env_import, bool env_export, list<SVariable> &varlist);
+ bool env_import, bool env_export, list<cnrun::SVariable> &varlist);
enum {
@@ -148,8 +144,19 @@ extern bool regenerate_source_ids;
char** cnrun_completion( const char *text, int start, int end);
-extern list<SVariable> *current_shell_variables;
+extern list<cnrun::SVariable> *current_shell_variables;
+
+
+void lprintf( int level, const char* fmt, ...) __attribute__ ((format (printf, 2, 3)));
+
+
+} // namespace cnrun
#endif
-// EOF
+// Local Variables:
+// Mode: c++
+// indent-tabs-mode: nil
+// tab-width: 8
+// c-basic-offset: 8
+// End:
diff --git a/upstream/src/libcn/hosted-neurons.cc b/upstream/src/libcn/hosted-neurons.cc
index 74d0eaa..ac5445b 100644
--- a/upstream/src/libcn/hosted-neurons.cc
+++ b/upstream/src/libcn/hosted-neurons.cc
@@ -12,7 +12,7 @@
#include <cmath>
#include <iostream>
-#include "../libstilton/gcc-builtins.hh"
+#include "libstilton/lang.hh"
#include "param-unit-literals.hh"
#include "types.hh"
diff --git a/upstream/src/libcn/model-cycle.cc b/upstream/src/libcn/model-cycle.cc
index 32b2098..083b27d 100644
--- a/upstream/src/libcn/model-cycle.cc
+++ b/upstream/src/libcn/model-cycle.cc
@@ -14,7 +14,7 @@
#include <ctime>
#include <cstdlib>
-#include "../libstilton/gcc-builtins.hh"
+#include "libstilton/lang.hh"
#include "integrate-rk65.hh"
#include "model.hh"
diff --git a/upstream/src/libcn/model-struct.cc b/upstream/src/libcn/model-struct.cc
index 83f3703..cecf467 100644
--- a/upstream/src/libcn/model-struct.cc
+++ b/upstream/src/libcn/model-struct.cc
@@ -16,7 +16,7 @@
#include <regex.h>
-#include "libstilton/pointaligned-s.hh"
+#include "libstilton/string.hh"
#include "model.hh"
@@ -1386,14 +1386,14 @@ dump_units( FILE *strm)
if ( *(*U)->param_sym(p) != '.' || verbosely > 5 )
fprintf( strm, "%2d: %-5s\t= %s %s\n",
p, (*U)->param_sym(p),
- Stilton::double_dot_aligned_s( (*U)->param_value(p), 4, 6),
+ cnrun::str::double_dot_aligned_s( (*U)->param_value(p), 4, 6).c_str(),
(*U)->param_name(p));
fprintf( strm, "Variables: ---\n");
for ( p = 0; p < (*U)->v_no(); p++ )
if ( *(*U)->var_sym(p) != '.' || verbosely > 5 )
fprintf( strm, "%2d: %-5s\t= %s %s\n",
p, (*U)->var_sym(p),
- Stilton::double_dot_aligned_s( (*U)->var_value(p), 4, 6),
+ cnrun::str::double_dot_aligned_s( (*U)->var_value(p), 4, 6).c_str(),
(*U)->var_name(p));
}
fprintf( strm, "\n===== Synapses:\n");
@@ -1408,14 +1408,14 @@ dump_units( FILE *strm)
if ( *(*U)->param_sym(p) != '.' || verbosely > 5 )
fprintf( strm, "%2d: %-5s\t= %s %s\n",
p, (*U)->param_sym(p),
- Stilton::double_dot_aligned_s( (*U)->param_value(p), 4, 6),
+ cnrun::str::double_dot_aligned_s( (*U)->param_value(p), 4, 6).c_str(),
(*U)->param_name(p));
fprintf( strm, "Variables: ---\n");
for ( p = 0; p < (*U)->v_no(); p++ )
if ( *(*U)->var_sym(p) != '.' || verbosely > 5 )
fprintf( strm, "%2d: %-5s\t= %s %s\n",
p, (*U)->var_sym(p),
- Stilton::double_dot_aligned_s( (*U)->var_value(p), 4, 6),
+ cnrun::str::double_dot_aligned_s( (*U)->var_value(p), 4, 6).c_str(),
(*U)->var_name(p));
}
diff --git a/upstream/src/libcn/types.cc b/upstream/src/libcn/types.cc
index 610f0fa..76c2694 100644
--- a/upstream/src/libcn/types.cc
+++ b/upstream/src/libcn/types.cc
@@ -15,7 +15,7 @@
#include <cstring>
#include <iostream>
-#include "libstilton/pointaligned-s.hh"
+#include "libstilton/string.hh"
#include "types.hh"
@@ -480,14 +480,14 @@ cnmodel_dump_available_units()
for ( p = 0; p < U.pno; p++ ) {
printf( "%4zu: %-5s\t= %s %s\n",
p, U.stock_param_syms[p],
- Stilton::double_dot_aligned_s( U.stock_param_values[p], 4, 8),
+ cnrun::str::double_dot_aligned_s( U.stock_param_values[p], 4, 8).c_str(),
U.stock_param_names[p]);
}
printf( "Variables:\n");
for ( p = 0; p < U.vno; p++ ) {
printf( "%4zu: %-5s\t= %s %s\n",
p, U.stock_var_syms[p],
- Stilton::double_dot_aligned_s( U.stock_var_values[p], 4, 8),
+ cnrun::str::double_dot_aligned_s( U.stock_var_values[p], 4, 8).c_str(),
U.stock_var_names[p]);
}
cout << endl;
@@ -502,14 +502,14 @@ cnmodel_dump_available_units()
for ( p = 0; p < U.pno; p++ ) {
printf( "%4zu: %-5s\t= %s %s\n",
p, U.stock_param_syms[p],
- Stilton::double_dot_aligned_s( U.stock_param_values[p], 4, 8),
+ cnrun::str::double_dot_aligned_s( U.stock_param_values[p], 4, 8).c_str(),
U.stock_param_names[p]);
}
cout << "Variables:\n";
for ( p = 0; p < U.vno; p++ ) {
printf( "%4zu: %-5s\t= %s %s\n",
p, U.stock_var_syms[p],
- Stilton::double_dot_aligned_s( U.stock_var_values[p], 4, 8),
+ cnrun::str::double_dot_aligned_s( U.stock_var_values[p], 4, 8).c_str(),
U.stock_var_names[p]);
}
cout << endl;
diff --git a/upstream/src/libstilton/Makefile.am b/upstream/src/libstilton/Makefile.am
index 9bff333..75f6417 100644
--- a/upstream/src/libstilton/Makefile.am
+++ b/upstream/src/libstilton/Makefile.am
@@ -4,13 +4,12 @@ pkglib_LTLIBRARIES = \
libstilton.la
libstilton_la_SOURCES = \
+ alg.hh \
+ containers.hh \
+ lang.hh \
exprparser.hh \
- pointaligned-s.hh \
- gcc-builtins.hh \
- log-facility.hh \
exprparser.cc \
- pointaligned-s.cc \
- log-facility.cc
+ libcommon.cc
libstilton_la_LDFLAGS = \
-avoid-version \
@@ -19,10 +18,10 @@ libstilton_la_LDFLAGS = \
if DO_PCH
BUILT_SOURCES = \
- exprparser.hh.gch \
- pointaligned-s.hh.gch \
- gcc-builtins.hh.gch \
- log-facility.hh.gch
+ alg.hh.gch \
+ containers.hh.gch \
+ lang.hh.gch \
+ exprparser.hh.gch
CLEANFILES = $(BUILT_SOURCES)
endif
diff --git a/upstream/src/libstilton/alg.hh b/upstream/src/libstilton/alg.hh
new file mode 100644
index 0000000..f24cba2
--- /dev/null
+++ b/upstream/src/libstilton/alg.hh
@@ -0,0 +1,103 @@
+/*
+ * File name: libstilton/alg.hh
+ * Project: cnrun
+ * Author: Andrei Zavada <johnhommer at gmail.com>
+ * Initial version: 2014-03-23
+ *
+ * Purpose: misc supporting algorithms
+ *
+ * License: GPL
+ */
+
+#ifndef _CNRUN_LIBSTILTON_ALG_H
+#define _CNRUN_LIBSTILTON_ALG_H
+
+
+#if HAVE_CONFIG_H && !defined(VERSION)
+# include "config.h"
+#endif
+
+using namespace std;
+
+namespace cnrun {
+namespace alg {
+
+/// uncomment on demand
+
+// template <typename T>
+// inline void
+// __attribute__ ((pure))
+// pod_swap( T&& a, T&& b)
+// {
+// T&& tmp = move(a);
+// a = move(b);
+// b = move(tmp);
+// }
+
+
+
+template <typename T>
+inline bool
+__attribute__ ((pure))
+overlap( const T& a, const T& b,
+ const T& c, const T& d)
+{
+ return not ((a < c && b < c) || (a > d && b > d));
+}
+
+template <typename T>
+inline bool
+__attribute__ ((pure))
+between( const T& a, const T& b, const T&c)
+{
+ return a <= b && b <= c;
+}
+
+
+
+template <typename T>
+int
+__attribute__ ((pure))
+sign( T x)
+{
+ return (x > 0) ? 1 : (x == 0) ? 0 : -1;
+}
+
+
+template <typename T>
+void
+__attribute__ ((pure))
+ensure_within( T& v, const T& l, const T& h)
+{
+ if ( v < l )
+ v = l;
+ else if ( v > h )
+ v = h;
+}
+
+template <typename T>
+T
+__attribute__ ((pure))
+value_within( const T& v, const T& l, const T& h)
+{
+ T o {v};
+ if ( v < l )
+ o = l;
+ else if ( v > h )
+ o = h;
+ return o;
+}
+
+// for more, check this file in Aghermann
+
+} // namespace alg
+} // namespace cnrun
+
+#endif
+
+// Local Variables:
+// Mode: c++
+// indent-tabs-mode: nil
+// tab-width: 8
+// c-basic-offset: 8
+// End:
diff --git a/upstream/src/libstilton/containers.hh b/upstream/src/libstilton/containers.hh
new file mode 100644
index 0000000..eb3bfb6
--- /dev/null
+++ b/upstream/src/libstilton/containers.hh
@@ -0,0 +1,67 @@
+/*
+ * File name: libstilton/containers.hh
+ * Project: cnrun
+ * Author: Andrei Zavada <johnhommer at gmail.com>
+ * Initial version: 2014-03-23
+ *
+ * Purpose: misc supporting algorithms (containers, Erlangish aliases)
+ *
+ * License: GPL
+ */
+
+#ifndef _CNRUN_LIBSTILTON_CONTAINERS_H
+#define _CNRUN_LIBSTILTON_CONTAINERS_H
+
+#include <list>
+#include <forward_list>
+#include <vector>
+#include <map>
+
+#if HAVE_CONFIG_H && !defined(VERSION)
+# include "config.h"
+#endif
+
+using namespace std;
+
+namespace cnrun {
+namespace alg {
+
+template <typename T>
+bool
+member( const T& x, const list<T>& v)
+{
+ return any( v.begin(), v.end(), x);
+}
+
+template <typename T>
+bool
+member( const T& x, const forward_list<T>& v)
+{
+ return any( v.begin(), v.end(), x);
+}
+
+template <typename T>
+bool
+member( const T& x, const vector<T>& v)
+{
+ return any( v.begin(), v.end(), x);
+}
+
+template <typename K, typename V>
+bool
+member( const K& x, const map<K, V>& m)
+{
+ return m.find(x) != m.end();
+}
+
+} // namespace alg
+} // namespace cnrun
+
+#endif
+
+// Local Variables:
+// Mode: c++
+// indent-tabs-mode: nil
+// tab-width: 8
+// c-basic-offset: 8
+// End:
diff --git a/upstream/src/libstilton/exprparser.cc b/upstream/src/libstilton/exprparser.cc
index 1d8f051..fc7d9f6 100644
--- a/upstream/src/libstilton/exprparser.cc
+++ b/upstream/src/libstilton/exprparser.cc
@@ -24,7 +24,7 @@
using namespace std;
-const char* const Stilton::__exparse_error_strings[] = {
+const char* const cnrun::__exparse_error_strings[] = {
"",
"Missing operand",
"Unbalanced parentheses",
@@ -84,8 +84,8 @@ array<SOp, n_ops> Ops = {
-Stilton::TExprParserError
-Stilton::CExpression::
+cnrun::TExprParserError
+cnrun::CExpression::
_do_parse( const char *str, double& parsed, list<SVariable> *varlist)
{
if ( !str ) {
diff --git a/upstream/src/libstilton/exprparser.hh b/upstream/src/libstilton/exprparser.hh
index e89d4c2..9620d88 100644
--- a/upstream/src/libstilton/exprparser.hh
+++ b/upstream/src/libstilton/exprparser.hh
@@ -20,10 +20,9 @@
# include "config.h"
#endif
-namespace Stilton {
+namespace cnrun {
using namespace std;
-using namespace Stilton;
enum TExprParserError {
diff --git a/upstream/src/libstilton/gcc-builtins.hh b/upstream/src/libstilton/gcc-builtins.hh
deleted file mode 100644
index c5e1143..0000000
--- a/upstream/src/libstilton/gcc-builtins.hh
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Author: Andrei Zavada <johnhommer at gmail.com>
- *
- * License: GPL-2+
- *
- * Initial version: 2008-11-18
- *
- */
-
-#ifndef CNAUX_GCC_BUILTINS_H
-#define CNAUX_GCC_BUILTINS_H
-
-#if __GNUC__ >= 3
-//# define inline inline __attribute__ ((always_inline))
-// # define __pure __attribute__ ((pure))
-// # define __const __attribute__ ((const))
-// # define __noreturn __attribute__ ((noreturn))
-// # define __malloc __attribute__ ((malloc))
-// # define __must_check __attribute__ ((warn_unused_result))
-// # define __deprecated __attribute__ ((deprecated))
-// # define __used __attribute__ ((used))
-// # define __unused __attribute__ ((unused))
-// # define __packed __attribute__ ((packed))
-# define likely(x) __builtin_expect (!!(x), 1)
-# define unlikely(x) __builtin_expect (!!(x), 0)
-#else
-// # define inline /* no inline */
-// # define __pure /* no pure */
-// # define __const /* no const */
-// # define __noreturn /* no noreturn */
-// # define __malloc /* no malloc */
-// # define __must_check /* no warn_unused_result */
-// # define __deprecated /* no deprecated */
-// # define __used /* no used */
-// # define __unused /* no unused */
-// # define __packed /* no packed */
-# define likely(x) (x)
-# define unlikely(x) (x)
-#endif
-
-#endif
-
-// EOF
diff --git a/upstream/src/libstilton/lang.hh b/upstream/src/libstilton/lang.hh
new file mode 100644
index 0000000..eb941ec
--- /dev/null
+++ b/upstream/src/libstilton/lang.hh
@@ -0,0 +1,87 @@
+/*
+ * File name: libstilton/lang.hh
+ * Project: cnrun
+ * Author: Andrei Zavada <johnhommer at gmail.com>
+ * Initial version: 2014-03-23
+ *
+ * Purpose: language and gcc macros
+ *
+ * License: GPL
+ */
+
+#ifndef _CNRUN_LIBSTILTON_LANG_H
+#define _CNRUN_LIBSTILTON_LANG_H
+
+#if HAVE_CONFIG_H && !defined(VERSION)
+# include "config.h"
+#endif
+
+#include <cfloat>
+#include <cmath>
+#include <unistd.h>
+#include <stdio.h>
+
+using namespace std;
+
+namespace agh {
+
+// for functions to suppress some possibly benign exceptions:
+enum class TThrowOption {
+ do_throw,
+ no_throw,
+};
+
+typedef unsigned long hash_t;
+
+inline int dbl_cmp( double x, double y) __attribute__ ((pure));
+inline int dbl_cmp( double x, double y) // optional precision maybe?
+{
+ if ( fabs(x - y) > DBL_EPSILON )
+ return (x > y) ? 1 : -1;
+ else
+ return 0;
+}
+
+
+// g++ bits
+
+#define MAKE_UNIQUE_CHARP(p) \
+ unique_ptr<void,void(*)(void*)> p##_pp(p,free);
+
+
+#define DELETE_DEFAULT_METHODS(T) \
+ T () = delete; \
+ T (const T&) = delete; \
+ void operator=( const T&) = delete;
+
+
+
+
+// gcc bits
+
+// # define __pure __attribute__ ((pure))
+// # define __const __attribute__ ((const))
+// # define __noreturn __attribute__ ((noreturn))
+// # define __malloc __attribute__ ((malloc))
+// # define __must_check __attribute__ ((warn_unused_result))
+// # define __deprecated __attribute__ ((deprecated))
+// # define __used __attribute__ ((used))
+// # define __unused __attribute__ ((unused))
+// # define __packed __attribute__ ((packed))
+#define likely(x) __builtin_expect (!!(x), 1)
+#define unlikely(x) __builtin_expect (!!(x), 0)
+
+
+#define FABUF printf( __FILE__ ":%d (%s): %s\n", __LINE__, __FUNCTION__, __buf__);
+#define FAFA printf( __FILE__ ":%d (%s): fafa\n", __LINE__, __FUNCTION__);
+
+} // namespace agh
+
+#endif
+
+// Local Variables:
+// Mode: c++
+// indent-tabs-mode: nil
+// tab-width: 8
+// c-basic-offset: 8
+// End:
diff --git a/upstream/src/libstilton/libcommon.cc b/upstream/src/libstilton/libcommon.cc
new file mode 100644
index 0000000..d1344b5
--- /dev/null
+++ b/upstream/src/libstilton/libcommon.cc
@@ -0,0 +1,303 @@
+/*
+ * File name: libstilton/libcommon.cc
+ * Project: cnrun
+ * Author: Andrei Zavada <johnhommer at gmail.com>
+ * Initial version: 2014-03-23
+ *
+ * Purpose: sundry bits too big for inlining
+ *
+ * License: GPL
+ */
+
+
+#include <cmath>
+#include <cstring>
+#include <string>
+#include <list>
+
+#include <stdarg.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "string.hh"
+#include "alg.hh"
+
+
+#if HAVE_CONFIG_H && !defined(VERSION)
+# include "config.h"
+#endif
+
+using namespace std;
+
+
+string
+cnrun::str::
+svasprintf( const char* fmt, va_list ap)
+{
+ char *_;
+ if (vasprintf( &_, fmt, ap) <= 0)
+ abort();
+ string ret {_};
+ free( (void*)_);
+ return move(ret);
+}
+
+
+
+string
+cnrun::str::
+sasprintf( const char* fmt, ...)
+{
+ char *_;
+ va_list ap;
+ va_start (ap, fmt);
+ if (vasprintf( &_, fmt, ap) <= 0)
+ abort();
+ va_end (ap);
+
+ string ret {_};
+ free( (void*)_);
+ return move(ret);
+}
+
+
+
+string
+cnrun::str::
+trim( const string& r0)
+{
+ string r (r0);
+ auto rsize = r.size();
+ if ( rsize == 0 )
+ return r;
+ while ( rsize > 0 && r[rsize-1] == ' ' )
+ --rsize;
+ r.resize( rsize);
+ r.erase( 0, r.find_first_not_of(" \t"));
+ return move(r);
+}
+
+string
+cnrun::str::
+pad( const string& r0, size_t to)
+{
+ string r (to, ' ');
+ memcpy( (void*)r.data(), (const void*)r0.data(), min( to, r0.size()));
+ return move(r);
+}
+
+
+
+list<string>
+cnrun::str::
+tokens_trimmed( const string& s_, const char* sep)
+{
+ string s {s_};
+ list<string> acc;
+ char *pp,
+ *p = strtok_r( &s[0], sep, &pp);
+ while ( p ) {
+ acc.emplace_back( trim(p));
+ p = strtok_r( NULL, sep, &pp);
+ }
+ return move(acc);
+}
+
+list<string>
+cnrun::str::
+tokens( const string& s_, const char* sep)
+{
+ string s {s_};
+ list<string> acc;
+ char *pp,
+ *p = strtok_r( &s[0], sep, &pp);
+ while ( p ) {
+ acc.emplace_back( p);
+ p = strtok_r( NULL, sep, &pp);
+ }
+ return move(acc);
+}
+
+
+
+
+void
+cnrun::str::
+decompose_double( double value, double *mantissa, int *exponent)
+{
+ char buf[32];
+ snprintf( buf, 31, "%e", value);
+ *strchr( buf, 'e') = '|';
+ sscanf( buf, "%lf|%d", mantissa, exponent);
+}
+
+
+
+
+string&
+cnrun::str::
+homedir2tilda( string& inplace)
+{
+ const char *home = getenv("HOME");
+ if ( home )
+ if ( inplace.compare( 0, strlen(home), home) == 0 )
+ inplace.replace( 0, strlen(home), "~");
+ return inplace;
+}
+
+string
+cnrun::str::
+homedir2tilda( const string& v)
+{
+ string inplace (v);
+ const char *home = getenv("HOME");
+ if ( home )
+ if ( inplace.compare( 0, strlen(home), home) == 0 )
+ inplace.replace( 0, strlen(home), "~");
+ return inplace;
+}
+
+string&
+cnrun::str::
+tilda2homedir( string& inplace)
+{
+ const char *home = getenv("HOME");
+ if ( home ) {
+ size_t at;
+ while ( (at = inplace.find( '~')) < inplace.size() )
+ inplace.replace( at, 1, home);
+ }
+ return inplace;
+}
+
+string
+cnrun::str::
+tilda2homedir( const string& v)
+{
+ string inplace (v);
+ const char *home = getenv("HOME");
+ if ( home ) {
+ size_t at;
+ while ( (at = inplace.find( '~')) < inplace.size() )
+ inplace.replace( at, 1, home);
+ }
+ return inplace;
+}
+
+
+
+string
+cnrun::str::
+dhms( double seconds, int dd)
+{
+ bool positive = seconds >= 0.;
+ if ( not positive )
+ seconds = -seconds;
+
+ int s = (int)seconds % 60,
+ m = (int)seconds/60 % 60,
+ h = (int)seconds/60/60 % (60*60),
+ d = (int)seconds/60/60/24 % (60*60*24);
+ double f = seconds - floor(seconds);
+
+ using cnrun::str::sasprintf;
+ string f_ = ( dd == 0 )
+ ? ""
+ : sasprintf( ".%0*d", dd, (int)(f*pow(10, dd)));
+ return ( d > 0 )
+ ? sasprintf( "%dd %dh %dm %d%ss", d, h, m, s, f_.c_str())
+ : ( h > 0 )
+ ? sasprintf( "%dh %dm %d%ss", h, m, s, f_.c_str())
+ : ( m > 0 )
+ ? sasprintf( "%dm %d%ss", m, s, f_.c_str())
+ : sasprintf( "%d%ss", s, f_.c_str());
+}
+
+string
+cnrun::str::
+dhms_colon( double seconds, int dd)
+{
+ bool positive = seconds >= 0.;
+ if ( not positive )
+ seconds = -seconds;
+
+ int s = (int)seconds % 60,
+ m = (int)seconds/60 % 60,
+ h = (int)seconds/60/60 % (60*60),
+ d = (int)seconds/60/60/24 % (60*60*24);
+ double f = seconds - floor(seconds);
+
+ using cnrun::str::sasprintf;
+ string f_ = ( dd == 0 )
+ ? ""
+ : sasprintf( ".%0*d", dd, (int)(f*pow(10, dd)));
+
+ return sasprintf( "%dd %02d:%02d:%02d%ss", d, h, m, s, f_.c_str());
+}
+
+
+
+
+
+inline namespace {
+int
+n_frac_digits( double v)
+{
+ int d = 0;
+ double dummy;
+ while ( fabs( modf( v, &dummy)) > 1e-6 ) {
+ v *= 10.;
+ ++d;
+ }
+ return d;
+}
+}
+
+string
+cnrun::str::
+double_dot_aligned_s( double val, int int_width, int frac_width)
+{
+ char buf[40];
+
+ if ( int_width + frac_width > 39 )
+ int_width = 8, frac_width = 8;
+
+ val = round(val * pow(10.,frac_width)) / pow(10.,frac_width);
+
+ double intval;
+ double fracval = modf( val, &intval);
+ int frac_digits = n_frac_digits( val);
+ int frac_pad = frac_width - frac_digits;
+ if ( frac_pad < 1 )
+ frac_pad = 1;
+
+ if ( frac_digits )
+ if ( (int)intval )
+ snprintf( buf, 40, "% *d.%0*ld%*s",
+ int_width, int(intval),
+ frac_digits, (long)round(pow(10., frac_digits) * fabs( fracval)),
+ frac_pad, " ");
+ else
+ snprintf( buf, 40, "%*s.%0*ld%*s",
+ int_width, " ",
+ frac_digits, (long)round(pow(10., frac_digits) * fabs( fracval)),
+ frac_pad, " ");
+
+ else
+ if ( (int)intval )
+ snprintf( buf, 40, "%*d.%-*s",
+ int_width, int(intval), frac_width, " ");
+ else
+ snprintf( buf, 40, "%-*s0%-*s",
+ int_width, " ", frac_width, " ");
+
+ return {buf};
+}
+
+
+// Local Variables:
+// Mode: c++
+// indent-tabs-mode: nil
+// tab-width: 8
+// c-basic-offset: 8
+// End:
diff --git a/upstream/src/libstilton/log-facility.cc b/upstream/src/libstilton/log-facility.cc
deleted file mode 100644
index 7b9cce2..0000000
--- a/upstream/src/libstilton/log-facility.cc
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Author: Andrei Zavada <johnhommer at gmail.com>
- *
- * License: GPL-2+
- *
- * Initial version: 2009-06-28
- *
- */
-
-#include <sys/time.h>
-#include <cstdarg>
-#include <cstring>
-#include <cmath>
-#include <fstream>
-
-#include "log-facility.hh"
-
-#if HAVE_CONFIG_H && !defined(VERSION)
-# include "config.h"
-#endif
-
-using namespace std;
-
-
-Stilton::CLogFacility::
-CLogFacility( const char *log_fname,
- int inlog_threshold,
- int instdout_tee_threshold,
- unsigned short insec_dec_place,
- int bits,
- size_t buf_size)
- : status (bits),
- log_threshold (inlog_threshold),
- stdout_tee_threshold (instdout_tee_threshold),
- sec_dec_places (insec_dec_place)
-{
- _line_buf = new char[_buf_size = buf_size];
- if ( log_fname && strlen(log_fname) ) {
- _log_fname = string(log_fname);
- _log_strm.open( log_fname);
- unitbuf( _log_strm);
- }
-}
-
-Stilton::CLogFacility::
-~CLogFacility()
-{
- if ( _log_fname.size() )
- _log_strm.close();
- delete[] _line_buf;
-}
-
-
-void
-Stilton::CLogFacility::
-msg( int vrb, const char *client_name, const char* fmt, ...)
-{
- va_list ap;
- va_start (ap, fmt);
- msgv( vrb, client_name, fmt, ap);
- va_end (ap);
-}
-
-
-void
-Stilton::CLogFacility::
-msgv( int vrb, const char *client_name, const char* fmt, va_list ap)
-{
-// if ( status & STILTON_LOG_NOLOCK )
-// boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> L( _log_lock);
-
- if ( log_threshold < vrb && stdout_tee_threshold < vrb )
- return;
-
- char timestampbuf[32];
- time_t timestamp; time( ×tamp);
- struct timeval tp; gettimeofday( &tp, nullptr);
- strftime( timestampbuf, 31, "%F %T", localtime( ×tamp));
- char secfracbuf[sec_dec_places+3];
- snprintf( secfracbuf, sec_dec_places+2, ".%0*u", sec_dec_places,
- (unsigned)round( tp.tv_usec / pow( 10., 6-sec_dec_places-1)));
-
- vsnprintf( _line_buf, _buf_size, fmt, ap);
-
- char *line = strtok( _line_buf, "\n");
- do {
- if ( vrb < 0 )
- printf( "%s%sError: %s\n", client_name ? client_name : "", (client_name && strlen(client_name)) ? ": " : "", line);
- else if ( stdout_tee_threshold >= vrb )
- printf( "%s%s%s\n", client_name ? client_name : "", (client_name && strlen(client_name)) ? ": " : "", line);
-
- if ( log_threshold >= vrb && _log_fname.size() )
- _log_strm << timestampbuf << (sec_dec_places > 0 ? secfracbuf : "") << ' '
- << client_name << ": "
- << (vrb < 0 ? "Error: " : "") << line << endl;
- } while ( (line = strtok( nullptr, "\n")) );
-
- if ( _log_fname.size() )
- _log_strm.flush();
-}
-
-
-
-// a one-liner, possibly unterminated by \n
-void
-Stilton::CLogFacility::
-msg_( int vrb, const char *client_name, const char* fmt, ...)
-{
- va_list ap;
- va_start (ap, fmt);
- msgv_( vrb, client_name, fmt, ap);
- va_end (ap);
-}
-
-void
-Stilton::CLogFacility::
-msgv_( int vrb, const char *client_name, const char* fmt, va_list ap)
-{
-// if ( status & STILTON_LOG_NOLOCK )
-// boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> L( _log_lock);
-
- if ( log_threshold < vrb && stdout_tee_threshold < vrb )
- return;
-
- char timestampbuf[32];
- time_t timestamp; time( ×tamp);
- struct timeval tp; gettimeofday( &tp, nullptr);
- strftime( timestampbuf, 31, "%F %T", localtime( ×tamp));
- char secfracbuf[sec_dec_places+3];
- snprintf( secfracbuf, sec_dec_places+2, ".%0*u", sec_dec_places,
- (unsigned)round( tp.tv_usec / pow( 10., 6-sec_dec_places-1)));
-
- vsnprintf( _line_buf, _buf_size, fmt, ap);
-
- if ( vrb < 0 )
- printf( "%s%sError: %s", client_name ? client_name : "", (client_name && strlen(client_name)) ? ": " : "", _line_buf);
- else if ( stdout_tee_threshold >= vrb )
- printf( "%s%s%s", client_name ? client_name : "", (client_name && strlen(client_name)) ? ": " : "", _line_buf);
-
- if ( log_threshold >= vrb && _log_fname.size() )
- _log_strm << timestampbuf << (sec_dec_places > 0 ? secfracbuf : "") << ' '
- << client_name << ": "
- << (vrb < 0 ? "Error: " : "") << _line_buf << endl;
-}
-
-
-// eof
diff --git a/upstream/src/libstilton/log-facility.hh b/upstream/src/libstilton/log-facility.hh
deleted file mode 100644
index 6bd4b5b..0000000
--- a/upstream/src/libstilton/log-facility.hh
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Author: Andrei Zavada <johnhommer at gmail.com>
- *
- * License: GPL-2+
- *
- * Initial version: 2009-06-28
- *
- */
-
-#ifndef STILTON_LOG_FACILITY_H
-#define STILTON_LOG_FACILITY_H
-
-#include <cstdarg>
-#include <fstream>
-
-#if HAVE_CONFIG_H && !defined(VERSION)
-# include "config.h"
-#endif
-
-
-namespace Stilton {
-
-using namespace std;
-using namespace Stilton;
-
-
-// bitwise OR this with CLogFacility::status to prevent locking even if supported
-#define STILTON_LOG_NOLOCK 1
-
-class CLogFacility {
-
- public:
- CLogFacility( const char *log_fname,
- int log_threshold = 4,
- int stdout_tee_threshold = 2,
- unsigned short sec_dec_places = 2,
- int bits = 0,
- size_t buf_size = 2048);
-
- int status;
-
- int log_threshold,
- stdout_tee_threshold;
- unsigned short
- sec_dec_places;
- // full-featured; always terminating lines with a \n
- void msg( int vrb, const char *client_name, const char* fmt, ...);
- void msgv( int vrb, const char *client_name, const char* fmt, va_list);
- // raw output: no parsing, not timestamping each line
- void msg_( int vrb, const char *client_name, const char* fmt, ...);
- void msgv_( int vrb, const char *client_name, const char* fmt, va_list);
-
- const char *log_fname() const
- { return _log_fname.c_str(); }
- size_t buf_size() const
- { return _buf_size; }
-
- ~CLogFacility();
-
- private:
- string _log_fname;
- size_t _buf_size;
- ofstream
- _log_strm;
- char
- *_line_buf;
-// boost::interprocess::interprocess_mutex
-// _log_lock;
-};
-
-
-}
-
-#endif
-
-// EOF
diff --git a/upstream/src/libstilton/pointaligned-s.cc b/upstream/src/libstilton/pointaligned-s.cc
deleted file mode 100644
index 482f633..0000000
--- a/upstream/src/libstilton/pointaligned-s.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Author: Andrei Zavada <johnhommer at gmail.com>
- *
- * License: GPL-2+
- *
- * Initial version: 2008-11-18
- *
- */
-
-#include <cmath>
-#include <cfloat>
-#include <cstdio>
-
-#include "pointaligned-s.hh"
-
-#if HAVE_CONFIG_H && !defined(VERSION)
-# include "config.h"
-#endif
-
-using namespace std;
-
-inline namespace {
-int
-n_frac_digits( double v)
-{
- int d = 0;
- double dummy;
- while ( fabs( modf( v, &dummy)) > 1e-6 ) {
- v *= 10.; ++d;
- }
- return d;
-}
-} // inline namespace
-
-const char*
-Stilton::
-double_dot_aligned_s( double val, int int_width, int frac_width)
-{
- static char buf[40];
-
- if ( int_width + frac_width > 39 )
- int_width = 8, frac_width = 8;
-
- val = round(val * pow(10.,frac_width)) / pow(10.,frac_width);
-
- double intval;
- double fracval = modf( val, &intval);
- int frac_digits = n_frac_digits( val);
- int frac_pad = frac_width - frac_digits;
- if ( frac_pad < 1 )
- frac_pad = 1;
-
- if ( frac_digits )
- if ( (int)intval )
- snprintf( buf, 40, "% *d.%0*ld%*s",
- int_width, int(intval),
- frac_digits, (long)round(pow(10., frac_digits) * fabs( fracval)),
- frac_pad, " ");
- else
- snprintf( buf, 40, "%*s.%0*ld%*s",
- int_width, " ",
- frac_digits, (long)round(pow(10., frac_digits) * fabs( fracval)),
- frac_pad, " ");
-
- else
- if ( (int)intval )
- snprintf( buf, 40, "%*d.%-*s",
- int_width, int(intval), frac_width, " ");
- else
-// snprintf( buf, 40, "% *d.%-*d",
- snprintf( buf, 40, "%-*s0%-*s",
- int_width, " ", frac_width, " ");
-
- return buf;
-
-}
-
-
-// eof
diff --git a/upstream/src/libstilton/pointaligned-s.hh b/upstream/src/libstilton/pointaligned-s.hh
deleted file mode 100644
index a9e9d72..0000000
--- a/upstream/src/libstilton/pointaligned-s.hh
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Author: Andrei Zavada <johnhommer at gmail.com>
- *
- * License: GPL-2+
- *
- * Initial version: 2009-05-01
- *
- */
-
-#ifndef CNAUX_POINTALIGN_H
-#define CNAUX_POINTALIGN_H
-
-#if HAVE_CONFIG_H && !defined(VERSION)
-# include "config.h"
-#endif
-
-namespace Stilton {
-
-const char*
-double_dot_aligned_s( double val, int int_width = 8, int frac_width = 8);
-
-}
-
-#endif
-
-// EOF
diff --git a/upstream/src/libstilton/string.hh b/upstream/src/libstilton/string.hh
new file mode 100644
index 0000000..38e6bca
--- /dev/null
+++ b/upstream/src/libstilton/string.hh
@@ -0,0 +1,118 @@
+/*
+ * File name: libstilton/string.hh
+ * Project: cnrun
+ * Author: Andrei Zavada <johnhommer at gmail.com>
+ * Initial version: 2014-03-23
+ *
+ * Purpose: strings ops
+ *
+ * License: GPL
+ */
+
+#ifndef _CNRUN_LIBSTILTON_STRING_H
+#define _CNRUN_LIBSTILTON_STRING_H
+
+#include <cstdarg>
+#include <cstring>
+#include <string>
+#include <list>
+#include <sstream>
+
+#if HAVE_CONFIG_H && !defined(VERSION)
+# include "config.h"
+#endif
+
+using namespace std;
+
+namespace cnrun {
+namespace str {
+
+enum class TStrCmpCaseOption {
+ sensitive, insensitive
+};
+
+string sasprintf( const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
+string svasprintf( const char* fmt, va_list aaa);
+
+string trim( const string& r0);
+string pad( const string& r0, size_t to);
+
+template <typename C>
+string
+join( const C& l, const char* sep)
+{
+ if ( l.empty() )
+ return "";
+ ostringstream recv;
+ auto I = l.begin();
+ for ( ; next(I) != l.end(); ++I )
+ recv << *I << sep;
+ recv << *I;
+ return recv.str();
+}
+
+list<string> tokens( const string&, const char* sep);
+
+inline
+list<string>
+tokens( const string& s_, char c)
+{
+ char sep[2] = {c, '\0'};
+ return move(tokens( s_, sep));
+}
+
+list<string> tokens_trimmed( const string& s_, const char* sep);
+
+inline
+list<string>
+tokens_trimmed( const string& s_, char c)
+{
+ char sep[2] = {c, '\0'};
+ return move(tokens_trimmed( s_, sep));
+}
+
+
+
+inline
+bool
+has_suffix( const string& s, const string& suffix,
+ TStrCmpCaseOption case_option = TStrCmpCaseOption::sensitive)
+{
+ return suffix.size() <= s.size() and
+ 0 == (case_option == TStrCmpCaseOption::sensitive ? strcmp : strcasecmp)(
+ &s[s.size()-suffix.size()], &suffix[0]);
+}
+
+void decompose_double( double value, double *mantissa, int *exponent);
+
+
+
+string& homedir2tilda( string& inplace);
+string homedir2tilda( const string&);
+string& tilda2homedir( string& inplace);
+string tilda2homedir( const string&);
+
+string dhms( double seconds, int decimal_digits = 0) __attribute__ ((pure));
+string dhms_colon( double seconds, int decimal_digits = 0) __attribute__ ((pure));
+
+
+// unicode/wcs; uncomment on demand
+// wstring to_wstring( const string&, const char* charset = "UTF-8");
+// string from_wstring( const wstring&, const char* charset = "UTF-8");
+
+
+string
+double_dot_aligned_s( double val, int int_width = 8, int frac_width = 8);
+
+
+}
+}
+
+#endif
+
+// Local Variables:
+// Mode: c++
+// indent-tabs-mode: nil
+// tab-width: 8
+// c-basic-offset: 8
+// End:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/cnrun.git
More information about the debian-med-commit
mailing list