[Kst] branches/work/kst/1.6/kst/src/libkstmath
Andrew Walker
arwalker at sumusltd.com
Tue Sep 25 23:31:57 CEST 2007
SVN commit 717035 by arwalker:
BUG:150169 allow the user to enter the readable name of a c-style plugin in an equation. This is the more intuitive name to enter as it is the only one the user ever sees in the ui
M +34 -15 enodes.cpp
M +4 -4 enodes.h
M +53 -52 escan.c
M +1 -1 escan.l
--- branches/work/kst/1.6/kst/src/libkstmath/enodes.cpp #717034:717035
@@ -402,7 +402,7 @@
_outVectors = 0L;
_inArrayLens = 0L;
_outArrayLens = 0L;
- _outputIndex = -424242;
+ _outputIndex = EQ_INDEX_ERROR;
_localData = 0L;
_outputVectorCnt = 0;
_inputVectorCnt = 0;
@@ -415,6 +415,19 @@
// first check for the C-style plugins...
//
_cStylePlugin = PluginCollection::self()->plugin(pn->name());
+ if (!_cStylePlugin) {
+ //
+ // the user may be using the readable name -
+ // we should certainly support this as it is the only name the user ever sees...
+ //
+ QMap<QString,QString>::ConstIterator rc;
+
+ rc = PluginCollection::self()->readableNameList().find(pn->name());
+ if (rc != PluginCollection::self()->readableNameList().end()) {
+ _cStylePlugin = PluginCollection::self()->plugin(*rc);
+ }
+ }
+
if (_cStylePlugin) {
const QValueList<Plugin::Data::IOValue>& itable = _cStylePlugin->data()._inputs;
const QValueList<Plugin::Data::IOValue>& otable = _cStylePlugin->data()._outputs;
@@ -514,14 +527,14 @@
Identifier *pn = dynamic_cast<Identifier*>(_args->node(cnt + 1));
if (pn && 0 == strcmp(pn->name(), "x")) {
if (!ctx->xVector) {
- _outputIndex = -424242;
+ _outputIndex = EQ_INDEX_ERROR;
// hope we recover later
return KstObject::NO_CHANGE;
}
_inVectors[vitcnt] = ctx->xVector->value();
_inArrayLens[vitcnt++] = ctx->xVector->length();
} else {
- _outputIndex = -424242;
+ _outputIndex = EQ_INDEX_ERROR;
KstDebug::self()->log(i18n("Plugin %2 failed when called from equation. Argument %1 was not found.").arg(cnt + 1).arg(_cStylePlugin->data()._name), KstDebug::Warning);
return KstObject::NO_CHANGE;
}
@@ -544,7 +557,7 @@
rc = _cStylePlugin->call(_inVectors, _inArrayLens, _inScalars, _outVectors, _outArrayLens, _outScalars);
}
- _outputIndex = -424242;
+ _outputIndex = EQ_INDEX_ERROR;
if (rc != 0) {
KstDebug::self()->log(i18n("Plugin %1 failed when called from equation.").arg(_cStylePlugin->data()._name), KstDebug::Warning);
return KstObject::NO_CHANGE;
@@ -569,7 +582,7 @@
}
}
- if (_outputIndex == -424242) {
+ if (_outputIndex == EQ_INDEX_ERROR) {
if (_outputVectorCnt > 0) {
if (_outVectors[0] && _outArrayLens[0] > 1) {
_outputIndex = 0;
@@ -601,13 +614,13 @@
Identifier *pn = dynamic_cast<Identifier*>(_args->node(cnt + 1));
if (pn && 0 == strcmp(pn->name(), "x")) {
if (!ctx->xVector) {
- _outputIndex = -424242;
+ _outputIndex = EQ_INDEX_ERROR;
// hope we recover later
return KstObject::NO_CHANGE;
}
_dataObjectPlugin->setInputVector(*it, ctx->xVector);
} else {
- _outputIndex = -424242;
+ _outputIndex = EQ_INDEX_ERROR;
KstDebug::self()->log(i18n("Plugin %2 failed when called from equation. Argument %1 was not found.").arg(cnt + 1).arg(_dataObjectPlugin->tagName()), KstDebug::Warning);
return KstObject::NO_CHANGE;
}
@@ -638,10 +651,10 @@
_dataObjectPlugin->update(counter);
}
- _outputIndex = -424242;
+ _outputIndex = EQ_INDEX_ERROR;
outVectors = _dataObjectPlugin->outputVectorList();
- if (_outputIndex == -424242) {
+ if (_outputIndex == EQ_INDEX_ERROR) {
if (outVectors.count() > 0) {
KstVectorPtr vectorOut = _dataObjectPlugin->outputVector(outVectors.first());
@@ -678,7 +691,7 @@
double Function::evaluateCStylePlugin(Context *ctx) {
if (_outputIndex >= 0) {
return ::kstInterpolate(_outVectors[_outputIndex], _outArrayLens[_outputIndex], ctx->i, ctx->sampleCount);
- } else if (_outputIndex == -424242) {
+ } else if (_outputIndex == EQ_INDEX_ERROR) {
return ctx->noPoint;
} else { // make sense?
return _outScalars[abs(_outputIndex) - 1];
@@ -689,7 +702,7 @@
double Function::evaluateDataObjectPlugin(Context *ctx) {
- if (_outputIndex == -424242) {
+ if (_outputIndex == EQ_INDEX_ERROR) {
return ctx->noPoint;
} else if (_outputIndex >= 0) {
if (int(_dataObjectPlugin->outputVectorList().count()) > _outputIndex) {
@@ -786,9 +799,11 @@
double ArgumentList::at(int arg, Context *ctx) {
- Node *n = _args.at(arg);
- if (n) {
- return n->value(ctx);
+ if (arg < (int)_args.count()) {
+ Node *n = _args.at(arg);
+ if (n) {
+ return n->value(ctx);
+ }
}
return ctx->noPoint;
}
@@ -823,7 +838,11 @@
Node *ArgumentList::node(int idx) {
- return _args.at(idx);
+ if (idx < (int)_args.count()) {
+ return _args.at(idx);
+ } else {
+ return 0L;
+ }
}
--- branches/work/kst/1.6/kst/src/libkstmath/enodes.h #717034:717035
@@ -25,9 +25,9 @@
class Plugin;
-#define EQ_FALSE 0.0
-#define EQ_TRUE 1.0
-
+#define EQ_FALSE 0.0
+#define EQ_TRUE 1.0
+#define EQ_INDEX_ERROR -424242
namespace Equation {
/* Global lock for the parser */
@@ -147,7 +147,7 @@
int *_inArrayLens, *_outArrayLens;
double *_inScalars, *_outScalars;
double **_inVectors, **_outVectors;
- int _outputIndex; // -1 = scalar 0, -424242 = none/error, +0...n = vector
+ int _outputIndex; // -1 = scalar 0, EQ_INDEX_ERROR = none/error, +0...n = vector
void *_localData;
int _argCount;
};
--- branches/work/kst/1.6/kst/src/libkstmath/escan.c #717034:717035
@@ -1,4 +1,3 @@
-#line 2 "escan.c"
/* A lexical scanner generated by flex*/
/* Scanner skeleton version:
@@ -297,13 +296,13 @@
#define YY_NUM_RULES 29
#define YY_END_OF_BUFFER 30
-static yyconst short int yy_accept[44] =
+static yyconst short int yy_accept[45] =
{ 0,
0, 0, 0, 0, 30, 28, 27, 29, 6, 22,
7, 24, 25, 20, 18, 26, 19, 28, 21, 1,
11, 15, 13, 2, 4, 5, 23, 8, 3, 17,
- 9, 1, 1, 1, 0, 12, 16, 14, 2, 10,
- 0, 1, 0
+ 9, 1, 1, 1, 0, 12, 16, 14, 0, 2,
+ 10, 0, 1, 0
} ;
static yyconst int yy_ec[256] =
@@ -311,17 +310,17 @@
1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 4, 1, 1, 1, 5, 6, 1, 7,
- 8, 9, 10, 11, 12, 13, 14, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 1, 1, 16,
- 17, 18, 1, 1, 19, 19, 19, 19, 20, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 21, 1, 22, 23, 1, 1, 19, 19, 19, 19,
+ 1, 4, 5, 1, 1, 1, 6, 7, 1, 8,
+ 9, 10, 11, 12, 13, 14, 15, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 1, 1, 17,
+ 18, 19, 1, 1, 20, 20, 20, 20, 21, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 22, 1, 23, 24, 1, 1, 20, 20, 20, 20,
- 20, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 1, 24, 1, 1, 1, 1, 1, 1,
+ 21, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+ 20, 20, 1, 25, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -338,53 +337,55 @@
1, 1, 1, 1, 1
} ;
-static yyconst int yy_meta[25] =
+static yyconst int yy_meta[26] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1
+ 1, 1, 1, 1, 1
} ;
-static yyconst short int yy_base[45] =
+static yyconst short int yy_base[46] =
{ 0,
- 0, 0, 51, 50, 52, 55, 55, 55, 34, 55,
- 44, 55, 55, 55, 55, 55, 55, 34, 55, 12,
- 31, 30, 29, 9, 55, 55, 55, 21, 55, 55,
- 55, 11, 15, 21, 27, 55, 55, 55, 24, 55,
- 25, 23, 55, 32
+ 0, 0, 57, 56, 58, 61, 61, 61, 39, 61,
+ 49, 61, 61, 61, 61, 61, 61, 39, 61, 12,
+ 36, 33, 32, 23, 61, 61, 61, 24, 61, 61,
+ 61, 13, 14, 24, 26, 61, 61, 61, 27, 32,
+ 61, 30, 25, 61, 31
} ;
-static yyconst short int yy_def[45] =
+static yyconst short int yy_def[46] =
{ 0,
- 43, 1, 44, 44, 43, 43, 43, 43, 43, 43,
- 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
- 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
- 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
- 43, 43, 0, 43
+ 44, 1, 45, 45, 44, 44, 44, 44, 44, 44,
+ 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
+ 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
+ 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
+ 44, 44, 44, 0, 44
} ;
-static yyconst short int yy_nxt[80] =
+static yyconst short int yy_nxt[87] =
{ 0,
- 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 24,
- 25, 26, 27, 28, 33, 32, 34, 39, 39, 32,
- 35, 35, 29, 33, 35, 34, 41, 42, 41, 42,
- 35, 42, 39, 39, 40, 38, 37, 36, 32, 31,
- 30, 43, 8, 8, 5, 43, 43, 43, 43, 43,
- 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
- 43, 43, 43, 43, 43, 43, 43, 43, 43
+ 6, 7, 8, 7, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 24, 25, 26, 27, 28, 33, 39, 34, 32, 32,
+ 39, 29, 35, 35, 35, 39, 42, 33, 42, 34,
+ 43, 43, 40, 40, 35, 43, 40, 40, 41, 38,
+ 37, 40, 40, 36, 32, 31, 30, 44, 8, 8,
+ 5, 44, 44, 44, 44, 44, 44, 44, 44, 44,
+ 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
+ 44, 44, 44, 44, 44, 44
} ;
-static yyconst short int yy_chk[80] =
+static yyconst short int yy_chk[87] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 20, 32, 20, 24, 24, 33,
- 32, 20, 44, 34, 33, 34, 35, 42, 35, 41,
- 34, 35, 39, 39, 28, 23, 22, 21, 18, 11,
- 9, 5, 4, 3, 43, 43, 43, 43, 43, 43,
- 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
- 43, 43, 43, 43, 43, 43, 43, 43, 43
+ 1, 1, 1, 1, 1, 20, 24, 20, 32, 33,
+ 39, 45, 20, 32, 33, 40, 35, 34, 35, 34,
+ 43, 35, 24, 24, 34, 42, 39, 39, 28, 23,
+ 22, 40, 40, 21, 18, 11, 9, 5, 4, 3,
+ 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
+ 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
+ 44, 44, 44, 44, 44, 44
} ;
static yy_state_type yy_last_accepting_state;
@@ -413,7 +414,7 @@
char *dataSpecPtr;
void yyerror(const char *s);
-#line 417 "escan.c"
+#line 418 "lex.yy.c"
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -567,7 +568,7 @@
#line 19 "escan.l"
-#line 571 "escan.c"
+#line 572 "lex.yy.c"
if ( yy_init )
{
@@ -618,13 +619,13 @@
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 44 )
+ if ( yy_current_state >= 45 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
- while ( yy_base[yy_current_state] != 55 );
+ while ( yy_base[yy_current_state] != 61 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
@@ -860,7 +861,7 @@
#line 140 "escan.l"
ECHO;
YY_BREAK
-#line 864 "escan.c"
+#line 865 "lex.yy.c"
case YY_END_OF_BUFFER:
{
@@ -1150,7 +1151,7 @@
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 44 )
+ if ( yy_current_state >= 45 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -1185,11 +1186,11 @@
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 44 )
+ if ( yy_current_state >= 45 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- yy_is_jam = (yy_current_state == 43);
+ yy_is_jam = (yy_current_state == 44);
return yy_is_jam ? 0 : yy_current_state;
}
--- branches/work/kst/1.6/kst/src/libkstmath/escan.l #717034:717035
@@ -14,7 +14,7 @@
%}
Number ([0-9]*\.?[0-9]+|[0-9]+\.)([eE][-+]?[0-9]+)?
-Id [A-Za-z]+
+Id [A-Za-z]([A-Za-z ]*[A-Za-z])?
%%
More information about the Kst
mailing list