*/
-class opt_t {
- public:
- bool fvalue;
- bool ftextarea;
- bool nowhite;
- size_t max;
- ustring filter;
- MNodePtr errFilter;
- ustring defaultVal;
-
- opt_t () {
- fvalue = false;
- ftextarea = false;
- nowhite = false;
- max = 0;
- };
- virtual ~opt_t () {};
-};
-
-static MNode* stringNode (const ustring& val) {
+MNode* FormVarOp::stringNode (const ustring& val) {
return newMNode_str (new ustring (val));
}
-static MNode* intNode (const ustring& val) {
+MNode* FormVarOp::intNode (const ustring& val) {
long v = atol (val.c_str ());
return newMNode_num (v);
}
-static MNode* intBlankNode (const ustring& val) {
+MNode* FormVarOp::intBlankNode (const ustring& val) {
if (val.length () > 0)
return intNode (val);
else
return NULL;
}
-static MNode* doubleNode (const ustring& val) {
+MNode* FormVarOp::doubleNode (const ustring& val) {
double v = atof (val.c_str ());
return newMNode_num (v);
}
-static MNode* doubleBlankNode (const ustring& val) {
+MNode* FormVarOp::doubleBlankNode (const ustring& val) {
if (val.length () > 0)
return doubleNode (val);
else
return NULL;
}
-static MNode* boolNode (const ustring& val) {
+MNode* FormVarOp::boolNode (const ustring& val) {
return newMNode_bool (to_bool (val));
}
-static bool opt_filter (const ustring& name, ustring& val, opt_t& opt, MlEnv* mlenv) {
+bool FormVarOp::optFilter (const ustring& name, ustring& val, MlEnv* mlenv) {
bool ans = true;
- if (opt.filter.size () > 0) {
+ if (filter.size () > 0) {
boost::wsmatch m;
- if (wsearch_env (mlenv, val, m, opt.filter)) {
+ if (wsearch_env (mlenv, val, m, filter)) {
val = wtou (std::wstring (m[0].first, m[0].second));
} else {
val.resize (0);
ans = false;
}
}
- if (opt.nowhite) {
- if (opt.ftextarea) {
+ if (nowhite) {
+ if (ftextarea) {
clipNLEnd (val);
} else {
clipWhiteEnd (val);
}
}
- if (opt.max > 0) {
- substring (val, 0, opt.max, true, val);
+ if (max > 0) {
+ substring (val, 0, max, true, val);
}
- if (opt.errFilter ()) {
+ if (errFilter ()) {
MNodePtr ag;
MNodePtr v;
ag = new MNode;
- if (ans)
+ if (ans) {
ag ()->set_car (newMNode_str (new ustring (val)));
- v = execDefun (mlenv, opt.errFilter (), ag (), uEmpty);
- if (to_bool (v ())) {
+ v = execDefun (mlenv, errFilter (), ag (), uEmpty);
+ if (to_bool (v ())) {
+ mlenv->env->setErrorVar (name);
+ }
+ } else {
mlenv->env->setErrorVar (name);
}
}
- if (opt.defaultVal.size () > 0 && val.size () == 0) {
- val = opt.defaultVal;
+ if (defaultVal.size () > 0 && val.size () == 0) {
+ val = defaultVal;
ans = true;
}
return ans;
}
-static void formvar_input_readopt (MNode*& arg, MlEnv* mlenv, ustring& name, opt_t& opt) {
+static void formvar_input_readopt (MNode*& arg, MlEnv* mlenv, ustring& name, FormVarOp& opt) {
std::vector<MNode*> params;
std::vector<MNode*> keywords;
static paramList kwlist[] = {
throw (uErrorVarNameEmpty);
}
-static MNode* formvar_input_do (MlEnv* mlenv, ustring& name, opt_t& opt, ustring (*prefn)(const ustring&), MNode* (*postfn)(const ustring&)) {
+MNode* FormVarOp::input (MlEnv* mlenv, ustring& name, ustring (*prefn)(const ustring&), MNode* (FormVarOp::*postfn)(const ustring&)) {
MNodePtr h;
ustring val;
ustring aname;
if (checkAry (name, aname)) {
size_t i, n;
- if (opt.fvalue) {
+ if (fvalue) {
MNodeList ans;
n = mlenv->env->form->atSize (aname);
mlenv->env->form->at (aname, i, val);
if (prefn)
val = (*prefn) (val);
- if (opt_filter (aname, val, opt, mlenv))
- ans.append ((*postfn) (val));
+ if (optFilter (aname, val, mlenv))
+ ans.append ((this->*postfn) (val));
else
ans.append (NULL);
}
mlenv->env->form->at (aname, i, val);
if (prefn)
val = (*prefn) (val);
- if (opt_filter (aname, val, opt, mlenv))
- mlenv->setAry (aname, i + 1, (*postfn) (val));
+ if (optFilter (aname, val, mlenv))
+ mlenv->setAry (aname, i + 1, (this->*postfn) (val));
else
mlenv->setAry (aname, i + 1, NULL);
}
mlenv->env->form->at (name, val);
if (prefn)
val = (*prefn) (val);
- if (opt_filter (name, val, opt, mlenv)) {
- if (opt.fvalue) {
- return (*postfn) (val);
+ if (optFilter (name, val, mlenv)) {
+ if (fvalue) {
+ return (this->*postfn) (val);
} else {
- mlenv->setVar (name, (*postfn) (val));
+ mlenv->setVar (name, (this->*postfn) (val));
return NULL;
}
} else {
- if (opt.fvalue) {
+ if (fvalue) {
} else {
mlenv->setVar (name, NULL);
}
MNode* ml_formvar_input_text (MNode* cell, MlEnv* mlenv) {
MNode* arg = cell->cdr ();
ustring name;
- opt_t opt;
+ FormVarOp opt;
formvar_input_readopt (arg, mlenv, name, opt);
- return formvar_input_do (mlenv, name, opt, omitCtrl, stringNode);
+ return opt.input (mlenv, name, omitCtrl, &FormVarOp::stringNode);
}
//#AFUNC input-textarea ml_formvar_input_textarea
MNode* ml_formvar_input_textarea (MNode* cell, MlEnv* mlenv) {
MNode* arg = cell->cdr ();
ustring name;
- opt_t opt;
+ FormVarOp opt;
formvar_input_readopt (arg, mlenv, name, opt);
opt.ftextarea = true;
- return formvar_input_do (mlenv, name, opt, NULL, stringNode);
+ return opt.input (mlenv, name, NULL, &FormVarOp::stringNode);
}
//#AFUNC input-int ml_formvar_input_int
MNode* ml_formvar_input_int (MNode* cell, MlEnv* mlenv) {
MNode* arg = cell->cdr ();
ustring name;
- opt_t opt;
+ FormVarOp opt;
formvar_input_readopt (arg, mlenv, name, opt);
- return formvar_input_do (mlenv, name, opt, NULL, intNode);
+ return opt.input (mlenv, name, NULL, &FormVarOp::intNode);
}
//#AFUNC input-real ml_formvar_input_real
MNode* ml_formvar_input_real (MNode* cell, MlEnv* mlenv) {
MNode* arg = cell->cdr ();
ustring name;
- opt_t opt;
+ FormVarOp opt;
formvar_input_readopt (arg, mlenv, name, opt);
- return formvar_input_do (mlenv, name, opt, NULL, doubleNode);
+ return opt.input (mlenv, name, NULL, &FormVarOp::doubleNode);
}
//#AFUNC input-int-or-blank ml_formvar_input_int_blank
MNode* ml_formvar_input_int_blank (MNode* cell, MlEnv* mlenv) {
MNode* arg = cell->cdr ();
ustring name;
- opt_t opt;
+ FormVarOp opt;
formvar_input_readopt (arg, mlenv, name, opt);
- return formvar_input_do (mlenv, name, opt, NULL, intBlankNode);
+ return opt.input (mlenv, name, NULL, &FormVarOp::intBlankNode);
}
//#AFUNC input-real-or-blank ml_formvar_input_real_blank
MNode* ml_formvar_input_real_blank (MNode* cell, MlEnv* mlenv) {
MNode* arg = cell->cdr ();
ustring name;
- opt_t opt;
+ FormVarOp opt;
formvar_input_readopt (arg, mlenv, name, opt);
- return formvar_input_do (mlenv, name, opt, NULL, doubleBlankNode);
+ return opt.input (mlenv, name, NULL, &FormVarOp::doubleBlankNode);
}
//#AFUNC input-ascii ml_formvar_input_ascii
MNode* ml_formvar_input_ascii (MNode* cell, MlEnv* mlenv) {
MNode* arg = cell->cdr ();
ustring name;
- opt_t opt;
+ FormVarOp opt;
formvar_input_readopt (arg, mlenv, name, opt);
- return formvar_input_do (mlenv, name, opt, omitNonAscii, stringNode); // XXX jp
+ return opt.input (mlenv, name, omitNonAscii, &FormVarOp::stringNode); // XXX jp
}
//#AFUNC input-bool ml_formvar_input_bool
MNode* ml_formvar_input_bool (MNode* cell, MlEnv* mlenv) {
MNode* arg = cell->cdr ();
ustring name;
- opt_t opt;
+ FormVarOp opt;
formvar_input_readopt (arg, mlenv, name, opt);
- return formvar_input_do (mlenv, name, opt, NULL, boolNode);
+ return opt.input (mlenv, name, NULL, &FormVarOp::boolNode);
}
/*DOC:
MNode* arg = cell->cdr ();
ustring var;
ustring fname;
- opt_t opt;
+ FormVarOp opt;
// ustring val;
ustring tgt;
ustring filename;
#include "wikiformat.h"
#include "wikienv.h"
#include "wikimotor.h"
+#include "ml-formvar.h"
#include "ml.h"
#include "expr.h"
#include "motorenv.h"
}
/* ============================================================ */
+/*DOC:
+===$input-text, $input-textarea, $input-int, $input-real, $input-int-or-blank, $input-real-or-blank, $input-ascii, $input-bool===
+{div:pre
++$input-text:VARIABLE
++$input-textarea:VARIABLE
++$input-int:VARIABLE
++$input-real:VARIABLE
++$input-int-or-blank:VARIABLE
++$input-real-or-blank:VARIABLE
++$input-ascii:VARIABLE
++$input-bool:VARIABLE
+}
+
+*/
+//#WIKICMD $input-text wc_input_text
+//#WIKICMD $input-textarea wc_input_textarea
+//#WIKICMD $input-int wc_input_int
+//#WIKICMD $input-real wc_input_real
+//#WIKICMD $input-int-or-blank wc_input_int_or_blank
+//#WIKICMD $input-real-or-blank wc_input_real_or_blank
+//#WIKICMD $input-ascii wc_input_ascii
+//#WIKICMD $input-bool wc_input_bool
+static void wc_input_sub (WikiLine* wl, WikiFormat* wiki, ustring (*prefn)(const ustring&), MNode* (FormVarOp::*postfn)(const ustring&)) {
+ WikiMotor motor (wl->begin, wl->end, wiki);
+ WikiMotorObjVec objv;
+ WikiMotorObjVecVec args;
+
+#ifdef DEBUG
+ std::cerr << "(wiki):" << ustring (wl->begin0, wl->end) << "\n";
+#endif /* DEBUG */
+ motor.compile (objv);
+ objv.splitCharA (':', args);
+ ustring name;
+ int i;
+ FormVarOp opt;
+
+ if (args.size () > 0) {
+ name = args[0]->textOut (wiki);
+ for (i = 1; i < args.size (); i ++) {
+ if (args[i]->matchHead (CharConst ("max="))) {
+ ustring x, y;
+ args[i]->splitChar (wiki, '=', x, y);
+ opt.max = to_uint32 (y);
+ } else if (args[i]->match (CharConst ("nowhite"))) {
+ opt.nowhite = true;
+ } else if (args[i]->match (CharConst ("nw"))) {
+ opt.nowhite = true;
+ } else if (args[i]->matchHead (CharConst ("filter="))) {
+ ustring x, y;
+ args[i]->splitChar (wiki, '=', x, y);
+ opt.filter = y;
+ } else if (args[i]->matchHead (CharConst ("default="))) {
+ ustring x, y;
+ args[i]->splitChar (wiki, '=', x, y);
+ opt.defaultVal = y;
+ } else {
+ wiki->errorMsg.append (args[i]->textOut (wiki) + ustring (CharConst (": bad parameter.\n")));
+ }
+ }
+ opt.input (wiki->mlenv, name, prefn, postfn);
+ }
+}
+
+void wc_input_text (WikiLine* wl, WikiFormat* wiki) {
+ wc_input_sub (wl, wiki, omitCtrl, &FormVarOp::stringNode);
+}
+
+void wc_input_textarea (WikiLine* wl, WikiFormat* wiki) {
+ wc_input_sub (wl, wiki, NULL, &FormVarOp::stringNode);
+}
+
+void wc_input_int (WikiLine* wl, WikiFormat* wiki) {
+ wc_input_sub (wl, wiki, NULL, &FormVarOp::intNode);
+}
+
+void wc_input_real (WikiLine* wl, WikiFormat* wiki) {
+ wc_input_sub (wl, wiki, NULL, &FormVarOp::doubleNode);
+}
+
+void wc_input_int_or_blank (WikiLine* wl, WikiFormat* wiki) {
+ wc_input_sub (wl, wiki, NULL, &FormVarOp::intBlankNode);
+}
+
+void wc_input_real_or_blank (WikiLine* wl, WikiFormat* wiki) {
+ wc_input_sub (wl, wiki, NULL, &FormVarOp::doubleBlankNode);
+}
+
+void wc_input_ascii (WikiLine* wl, WikiFormat* wiki) {
+ wc_input_sub (wl, wiki, omitNonAscii, &FormVarOp::stringNode);
+}
+
+void wc_input_bool (WikiLine* wl, WikiFormat* wiki) {
+ wc_input_sub (wl, wiki, NULL, &FormVarOp::boolNode);
+}
+
+/* ============================================================ */
static void call_defun_wikicmd (ustring& name, MNode* wf, WikiMotorObjVec& objv2, WikiLine* wl, WikiFormat* wiki) {
WikiMotorObjVecVec argsv;
MNodePtr vargs;