Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d171ffd
SetVar.cc:VerfiyVal(): Use supplied functionals for matching and
sanbee Mar 23, 2026
5efa90f
clgetBaseCode.h: Added the dbg parameter for clgetNValBaseCode.
sanbw Mar 23, 2026
070c0af
clgetBaseCode.h: Added the dbg parameter in clgetNValBaseCode(),
sanbee Mar 24, 2026
54baa84
Merge branch 'verifyval_lambda' of github.com:sanbee/parafeed into ve…
sanbee Mar 24, 2026
fde6f70
clparseVal.{cc,h}: clparseVal() is now templated to work
sanbee Mar 24, 2026
8c8d6af
General cleanup, and further refactoring in clgetValp.cc.
sanbw Mar 24, 2026
94c0d6e
Minor mods and cleanup in ErrorObj.{cc,h}
sanbw Mar 24, 2026
8cd5f06
Revert "Minor mods and cleanup in ErrorObj.{cc,h}"
sanbw Mar 24, 2026
52d3370
clgetValp.cc: Fix in clgetValpVec(), where val.push_back(d) does not …
sanbw Mar 25, 2026
46b1315
Added the missing cldbg*getValp() functions with SMap.
sanbw Mar 25, 2026
7a18c63
Removed unnecessary #include <shell.h>
sanbw Mar 25, 2026
1eeae03
Fix in CMakeLists.txt for installing GTest.
sanbw Mar 27, 2026
3258248
test_parafeed_noninterative.cpp: Enabled the WrongDataType test.
sanbw Mar 27, 2026
2c48209
SearchSymb.cc,cl.h: Added SearchVSymb() function to the low-level API.
sanbee Mar 27, 2026
f53fc30
Merge branch 'template_refact' of github.com:sanbee/parafeed into tem…
sanbee Mar 27, 2026
f803d9b
cl.h, shell.l: Added get/set_shell_input() functions to get/set
sanbee Mar 30, 2026
3736ae4
ParafeedTest.h: Factored out the ParafeedTest class.
sanbee Mar 31, 2026
4443074
Added the Interactive test where some working of the interactive
sanbw Apr 1, 2026
fc5317f
test_parafeed_noninteractive.cpp: Fixed the ParsesClgetValpParameters…
sanbw Apr 1, 2026
bbce2f1
clgetValp.cc: The dbg parameter in clgetValVec() was not forwarded to
sanbw Apr 2, 2026
7875aff
cl.h: Added the missing wrappers to translate dbgclget*() cldbgget*()
sanbw Apr 2, 2026
02a4966
ParafeedTest.h: Applied the patch suggested in PR #33.
sanbw Apr 2, 2026
550837b
Fixed the CI unit test failures by making clTextColouring() robust wh…
agawatw Apr 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions code/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- cmake -*-
# /*
# * Copyright (c) 2000-2021, 2022 S. Bhatnagar (bhatnagar dot sanjay at gmail dot com)
# * Copyright (c) 2000-2025, 2026 S. Bhatnagar (bhatnagar dot sanjay at gmail dot com)
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -70,7 +70,6 @@ set(header_list
support.h
iosupport.h
SymbTab.h
clparseVal.h
clgetValp.h
clgetValp.cc
)
Expand Down
1 change: 0 additions & 1 deletion code/GetStdString.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
/* $Id: clstrtStream.c,v 2.0 1998/11/11 07:13:02 sanjay Exp $ */
#include <stdio.h>
#include <cllib.h>
#include <shell.h>

#ifdef __cplusplus
extern "C" {
Expand Down
7 changes: 6 additions & 1 deletion code/SearchSymb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern "C" {
return t;
}
/*----------------------------------------------------------------------*/
Symbol *SearchVSymb(const char *Name, Symbol *Tab)
Symbol *SearchVSymb(const char *Name, Symbol *Tab=cl_SymbTab)
{
return minmatch(Name,Tab);
}
Expand All @@ -56,3 +56,8 @@ extern "C" {
#ifdef __cplusplus
}
#endif
/*----------------------------------------------------------------------*/
Symbol *SearchVSymb(const char *Name)
{
return SearchVSymb(Name,cl_SymbTab);
}
103 changes: 56 additions & 47 deletions code/SetVar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <sstream>
#include <algorithm>
#include <cctype>
#include <functional>
extern "C" {

/* #define getmem(a,b) malloc((a))*/
Expand Down Expand Up @@ -112,23 +113,62 @@ int UnsetVar(Symbol *S, int setFactoryDefaults)
// Count the number of commas. Strip off leading and trailing white
// spaces from val, copy into another buffer, take comma seperated
// tokens from the new buffer and put it in Tab.
// try
{
vector<string> tokens = clstrtokp(trim(string(val)),',',CL_ESC);
unsigned ntokens=tokens.size();
pos->NVals=ntokens;
pos->Val.resize(pos->NVals);
for (unsigned i=0;i<ntokens;i++)
SetVal(tokens[i].c_str(),pos,i);
}
vector<string> valBackup=pos->Val;
try
{
vector<string> tokens = clstrtokp(trim(string(val)),',',CL_ESC);
unsigned ntokens=tokens.size();
pos->NVals=ntokens;
pos->Val.resize(pos->NVals);
for (unsigned i=0;i<ntokens;i++)
SetVal(tokens[i].c_str(),pos,i);
}
catch(clError& x)
{
pos->NVals=valBackup.size();
pos->Val=valBackup;
throw(x);
}
}

if (dodoinp) doinp((char *)(string("-t ")+key).c_str());

return ret;
}

/*----------------------------------------------------------------------*/
void VerifyVal(const char *v, Symbol *S,string& newval)
bool matchOpts(const std::string& val,const Symbol& S)
{
bool Matched=false;
for(auto opt : S.Options)
if (opt == val)
{
Matched=true;
break;
}
return Matched;
};

void noMatchException(const Symbol& S)
{
string msg;
msg = "###Warning: Value did not match any factory supplied options for keyword \"";
msg += S.Name; msg += "\"";
clError errObj;
errObj << msg.c_str() << endl;
if (!S.Options.empty())
{
msg = "###Informational: Valid options are ";
for(auto opt : S.Options)
{msg += "\"" + opt;msg += "\" ";}
errObj << msg.c_str() << endl;
}
};
std::function<void(const Symbol&)> noMatchExceptionLambda_ptr=noMatchException;
/*----------------------------------------------------------------------*/
void VerifyVal(const char *v, Symbol *S,string& newval,
std::function<bool(const std::string&, const Symbol& )> matchOptsLambda=matchOpts,
std::function<void(const Symbol&)> noMatchExceptionLambda=noMatchException)
{
int n = S->Options.size();
int Matched=1;
Expand Down Expand Up @@ -181,25 +221,11 @@ int UnsetVar(Symbol *S, int setFactoryDefaults)
}
else if (n > 0)
{
Matched=0;
for(int i=0; i<n; i++)
if (S->Options[i] == v)
{Matched=1;break;}
Matched=matchOptsLambda(std::string(v),*S);
}
if (!Matched)
{
string msg;
msg = "###Warning: Value did not match any factory supplied options for keyword \"";
msg += S->Name; msg += "\"";
clError errObj;
errObj << msg.c_str() << endl;
if (n>0)
{
msg = "###Informational: Valid options are ";
for(int i=0; i<n; i++)
{msg += "\"" + S->Options[i];msg += "\" ";}
errObj << msg.c_str() << endl;
}
noMatchExceptionLambda(*S);
}
}
/*----------------------------------------------------------------------*/
Expand All @@ -210,11 +236,13 @@ void SetVal(const char *v, Symbol *S, int i)

try
{
VerifyVal(trimmed.c_str(),S,vv);
VerifyVal(trimmed.c_str(),S,vv,matchOpts);
}
catch (clError& x)
{
cerr << x.what() << " " << S->Val[i] << endl;
// Same as cerr << x.what(), except that the output
// stream is centrally specified in clError.
x << x << " at position " << i << endl;
throw(x);
}

Expand All @@ -223,25 +251,6 @@ void SetVal(const char *v, Symbol *S, int i)
S->NVals=S->Val.size();
S->Val[i]=vv;
S->Used=0;

/* if ((unsigned int)i >= S->NVals) */
/* { */
/* S->Val = (char **)realloc(S->Val,sizeof(char **)*(i+1)); */
/* len = S->NVals; */
/* do S->Val[len++]=NULL; while (len < i); */
/* } */

/* len=strlen(vv.c_str()); */

/* S->Val[i] = (char *)realloc(S->Val[i],len+1); */

/* if (strlen(vv.c_str())) */
/* { */
/* strncpy(S->Val[i],vv.c_str(),len+1); */
/* S->Val[i][len] = '\0'; */
/* if ((unsigned int)i>=S->NVals) S->NVals++; */
/* S->Used=0; */
/* } */
}

}
Expand Down
136 changes: 96 additions & 40 deletions code/cl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/* $Id: cl.h,v 2.0 1998/11/11 07:12:46 sanjay Exp sanjay $ */
#if !defined(CL_H)
#define CL_H

#include <functional>
/*
Names of the environment variables and other default values used for
user customizaion.
Expand Down Expand Up @@ -130,7 +130,7 @@ extern int add_history(char *);
Symbol *AddQKey(const char *Name, const char *Type,
Symbol **Head, Symbol **Tail);
int ParseCmdLine(int, char **);
vector<string> clMakeArgvFromFile(const string& Name);
std::vector<std::string> clMakeArgvFromFile(const std::string& Name);

int startShell();
void clLoadSymb();
Expand Down Expand Up @@ -165,10 +165,10 @@ int clgetNBVal(char *Name, bool *Val, int *N);
int dbgclgetNBVal(char *Name, bool *Val, int *N);

#ifdef __cplusplus
int clTgetOptp(const string& Name, string& Type);
int clgetOptp(const string& Name);
int clgetNValsp(const string& Name);
int clSetOptions(const string& Name, const VString& options);
int clTgetOptp(const std::string& Name, std::string& Type);
int clgetOptp(const std::string& Name);
int clgetNValsp(const std::string& Name);
int clSetOptions(const std::string& Name, const VString& options);
#endif

void clRestartShell();
Expand All @@ -184,9 +184,9 @@ int clclearOptsList(char ***,int);
int clloadConfig(char *);
void clCleanUp();
#ifdef __cplusplus
int clBoolCmp(const string&, const bool& cmpVal);
int clIsTrue(const string&);
int clIsFalse(const string&);
int clBoolCmp(const std::string&, const bool& cmpVal);
int clIsTrue(const std::string&);
int clIsFalse(const std::string&);
#endif
void clReset();
void clRetry();
Expand Down Expand Up @@ -252,7 +252,9 @@ int UnsetVar(Symbol *,int);
int SetVar(char *Name, char *val, Symbol *tab,short int force, short int fullmatch, short int doinp);
//void SetVal(const char *, Symbol *, int);
#ifdef __cplusplus
void VerifyVal(const char *, Symbol *,string &);
void VerifyVal(const char *, Symbol *,std::string &,
std::function<bool(const std::string&, const Symbol& S )> matchOptsLambda,
std::function<void(const Symbol&)> noMatchExceptionLambda);
#endif
int CopyVSymb(Symbol *, Symbol *,int);
int FreeVSymb(Symbol *);
Expand All @@ -269,43 +271,97 @@ void clSetPrompt(const bool& prompt);
}
#endif
#ifdef __cplusplus
int clgetFullp(const string& Arg, int &N);
int clgetFullValp(const string& Name, string& Val);
int dbgclgetFullValp(const string& Name, string& Val);
Symbol *SearchVSymb(const char *Name);

int clgetBaseCore(const std::string& Name, int& Val, int& N, SMap &smap);
int clgetFullValp(const std::string& Name, std::string& Val);
int dbgclgetFullValp(const std::string& Name, std::string& Val);
int clgetFullp(const std::string& Arg, int &N);
//
//------------------------------------------------------------------------------------------------
// Wrappers for clgetValp(...,T& val,...) and clgetValp(...,vector<T>&,...)
//
int clgetIValp(const std::string& Name, int& Val, int& N);
int clgetFValp(const std::string& Name, float& Val, int& N);
int clgetBValp(const std::string& Name, bool& val, int& N);
int clgetSValp(const std::string& Name, std::string& Val, int& N);
//------------------------------------------------------------------------------------------------
int clgetNIValp(const std::string& Key, std::vector<int>& Val, int& m);
int clgetNFValp(const std::string& Name, std::vector<float>& Val, int& N);
int clgetNBValp(const std::string& Name, std::vector<bool>& val, int& N);
int clgetNSValp(const std::string& Name, std::vector<std::string>& Val, int& N);
//
//------------------------------------------------------------------------------------------------
// Wrappers for clgetValp(...,T&,..., SMap&) and clgetValp(...,vector<T>&,...,SMap&)
//
int clgetIValp(const std::string& Name, int& Val, int& N, SMap &smap);
int clgetFValp(const std::string& Name, float& Val, int& N, SMap &smap);
int clgetBValp(const std::string& Name, bool& Val, int& N, SMap &smap);
int clgetSValp(const std::string& Name, std::string& Val, int& N, SMap &smap);
//------------------------------------------------------------------------------------------------
int clgetNIValp(const std::string& Name, std::vector<int>& Val, int& N, SMap &smap);
int clgetNFValp(const std::string& Name, std::vector<float>& Val, int& N, SMap &smap);
int clgetNBValp(const std::string& Name, std::vector<bool>& Val, int& N, SMap &smap);
int clgetNSValp(const std::string& Name, std::vector<std::string>& Val, int& N, SMap& smap);
//
//------------------------------------------------------------------------------------------------
// Wrappers for clgetValp(...,T&,...,bool dbg=true) and clgetValp(...,vector<T>&,...,bool dbg=true)
//
int dbgclgetIValp(const std::string& Name, int& Val, int& N);
int dbgclgetFValp(const std::string& Name, float& Val, int& N);
int dbgclgetBValp(const std::string& Name, bool& val, int& N);
int dbgclgetSValp(const std::string& Name, std::string& Val, int& N);
//------------------------------------------------------------------------------------------------
int dbgclgetNIValp(const std::string& Key, std::vector<int>& Val, int& m);
int dbgclgetNFValp(const std::string& Name, std::vector<float>& Val, int& N);
int dbgclgetNBValp(const std::string& Name, std::vector<bool>& val, int& N);
int dbgclgetNSValp(const std::string& Name, std::vector<std::string>& Val, int& N);
//
//------------------------------------------------------------------------------------------------
// Wrappers for clgetValp(...,T&,...,SMap&, bool dbg=true) and clgetValp(...,vector<T>&,...,SMap&, bool dbg=true)
//
int dbgclgetIValp(const std::string& Name, int& Val, int& N, SMap &smap);
int dbgclgetFValp(const std::string& Name, float& Val, int& N, SMap &smap);
int dbgclgetBValp(const std::string& Name, bool& val, int& N, SMap &smap);
int dbgclgetSValp(const std::string& Name, std::string& Val, int& N, SMap &smap);
//------------------------------------------------------------------------------------------------
int dbgclgetNIValp(const std::string& Key, std::vector<int>& Val, int& N, SMap &smap);
int dbgclgetNFValp(const std::string& Name, std::vector<float>& Val, int& N, SMap &smap);
int dbgclgetNBValp(const std::string& Name, std::vector<bool>& val, int& N, SMap &smap);
int dbgclgetNSValp(const std::string& Name, std::vector<std::string>& Val, int& N, SMap &smap);
//
//------------------------------------------------------------------------------------------------
// Wrappers to translate dbgclget*() to cldbgget*()
//
int cldbggetIValp(const std::string& Name, int& val, int& n);
int cldbggetFValp(const std::string& Name, float& val, int& n);
int cldbggetBValp(const std::string& Name, bool& val, int& n);
int cldbggetSValp(const std::string& Name, std::string& val, int& n);

int clgetIValp(const string& Name, int& Val, int& N);
int dbgclgetIValp(const string& Name, int& Val, int& N);
int clgetNIValp(const string& Key, vector<int>& Val, int& m);
int dbgclgetNIValp(const string& Key, int& Val, int& m);
int cldbggetIValp(const std::string& Name, int& val, int& n, SMap& smap);
int cldbggetFValp(const std::string& Name, float& val, int& n, SMap& smap);
int cldbggetBValp(const std::string& Name, bool& val, int& n, SMap& smap);
int cldbggetSValp(const std::string& Name, std::string& val, int& n, SMap& smap);

int clgetBValp(const string& Name, bool& val, int& N);
int dbgclgetBValp(const string& Name, bool& val, int& N);
int clgetNBValp(const string& Name, bool& val, int& N);
int dbgclgetNBValp(const string& Name, bool& val, int& N);
int cldbggetNIValp(const std::string& Key, std::vector<int>& val, int& m);
int cldbggetNFValp(const std::string& Key, std::vector<float>& val, int& m);
int cldbggetNBValp(const std::string& Key, std::vector<bool>& val, int& m);
int cldbggetNSValp(const std::string& Key, std::vector<std::string>& val, int& m);

int clgetFValp(const string& Name, float& Val, int& N);
int dbgclgetFValp(const string& Name, float& Val, int& N);
int clgetNFValp(const string& Name, vector<float>& Val, int& N);
int dbgclgetNFValp(const string& Name, float& Val, int& N);
int cldbggetNIValp(const std::string& Key, std::vector<int>& val, int& m, SMap& smap);
int cldbggetNFValp(const std::string& Key, std::vector<float>& val, int& m, SMap& smap);
int cldbggetNBValp(const std::string& Key, std::vector<bool>& val, int& m, SMap& smap);
int cldbggetNSValp(const std::string& Key, std::vector<std::string>& val, int& m, SMap& smap);

int clgetSValp(const string& Name, string& Val, int& N);
int dbgclgetSValp(const string& Name, string& Val, int& N);
int clgetNSValp(const string& Name, vector<string>& Val, int& N);
int dbgclgetNSValp(const string& Name, vector<string>& Val, int& N);
int clgetSValp(const string& Name, string& Val, int& N, SMap &smap);
int clgetFValp(const string& Name, float& Val, int& N, SMap &smap);
int clgetBValp(const string& Name, bool& Val, int& N, SMap &smap);
int clgetIValp(const string& Name, int& Val, int& N, SMap &smap);

//int clgetNSValp(const string& Name, string& Val, int& N, SMap &smap);
int clgetNFValp(const string& Name, float& Val, int& N, SMap &smap);
int clgetNBValp(const string& Name, bool& Val, int& N, SMap &smap);
int clgetNIValp(const string& Name, int& Val, int& N, SMap &smap);
int clgetBaseCore(const string& Name, int& Val, int& N, SMap &smap);
void clTextColouring(const string& text, const unsigned int textType, string& startSeq, string& endSeq);
void clTextColouring(const std::string& text, const unsigned int textType,
std::string& startSeq, string& endSeq);

extern std::function<int (char *, size_t)> cl_shell_input_g;
void set_shell_input(std::function<int (char *, size_t)> inp_func);
std::function<int (char *, size_t)> get_shell_input();
#endif
#if !defined(FORTRAN)
#include <clconvert.h>
#endif
#endif

2 changes: 1 addition & 1 deletion code/clMakeArgvFromFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <fstream>
#include <string>
#include <algorithm>
#include <shell.h>
#include <clhashdefines.h>
#include <shell.tab.h>

#ifdef __cplusplus
Expand Down
1 change: 0 additions & 1 deletion code/clReset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <string.h>
#include <stdio.h>
#include <shell.h>
#include <cllib.h>

#ifdef __cplusplus
Expand Down
Loading
Loading