From a8fb5e38cc90e6a988bc2d31616ad1dea99a66ea Mon Sep 17 00:00:00 2001 From: visor Date: Mon, 3 May 2010 23:55:22 +0900 Subject: [PATCH] wiki-output function. --- lib/motorenv.cc | 1 + lib/motorenv.h | 2 ++ modules/ml-wiki.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++-- modules/ml-wiki.h | 1 + wiki/wikicmd.cc | 23 ++++++++++++++++++++++- wiki/wikicmd.h | 1 + wiki/wikiformat.cc | 6 ++++++ wiki/wikiformat.h | 17 +++++++++++++---- 8 files changed, 90 insertions(+), 7 deletions(-) diff --git a/lib/motorenv.cc b/lib/motorenv.cc index 34b320a..c6d006c 100644 --- a/lib/motorenv.cc +++ b/lib/motorenv.cc @@ -24,6 +24,7 @@ MotorEnv::MotorEnv (AppEnv* ae, CGIFormFile* fm, HTMLMotor* m, MotorOutput* out) form = fm; motor = m; output = out; + wikioutput = NULL; log = &std::cerr; mlPool = new MlPool; mlFTable = new MlFTable; diff --git a/lib/motorenv.h b/lib/motorenv.h index 6645e8d..868f07f 100644 --- a/lib/motorenv.h +++ b/lib/motorenv.h @@ -20,12 +20,14 @@ class MlPool; class MlFTable; class MlEnv; class WikiEnv; +class WikiMotorOutputString; class MotorEnv { public: AppEnv* appenv; CGIFormFile* form; HTMLMotor* motor; MotorOutput* output; + WikiMotorOutputString* wikioutput; HTTPResponse http; ustring datastore; diff --git a/modules/ml-wiki.cc b/modules/ml-wiki.cc index 668401c..dcdfe65 100644 --- a/modules/ml-wiki.cc +++ b/modules/ml-wiki.cc @@ -213,7 +213,6 @@ MNode* ml_defun_wiki_link (MNode* cell, MlEnv* mlenv) { MNode* sexp = NULL; checkDefun (cell->cdr (), name, sexp); -// mlenv->env->wikienv->wikiLink_setVar (name, newLambda (sexp)); mlenv->env->wikienv->wikiLink.setVar (name, newLambda (sexp)); return NULL; @@ -231,7 +230,6 @@ MNode* ml_defun_wiki_command (MNode* cell, MlEnv* mlenv) { MNode* sexp = NULL; checkDefun (cell->cdr (), name, sexp); -// mlenv->env->wikienv->wikiCmd_setVar (name, newLambda (sexp)); mlenv->env->wikienv->wikiCmd.setVar (name, newLambda (sexp)); return NULL; @@ -275,3 +273,47 @@ MNode* ml_wiki_guestuser_function (MNode* cell, MlEnv* mlenv) { return NULL; } + +/*DOC: +===wiki-output=== + (wiki-output TEXT... [#flush | :flush BOOL]) -> NIL + +*/ +//#AFUNC wiki-output ml_wiki_output +MNode* ml_wiki_output (MNode* cell, MlEnv* mlenv) { + MNode* arg = cell->cdr (); + ustring text; + MNode* a; + ustring* u; + +#if 0 + if (! mlenv->env->responseDone) + mlenv->env->standardResponse (); +#endif + assert (mlenv->env->wikioutput); + while (arg) { + a = arg->car (); + if (a && a->isSym ()) { + u = a->sym; + if (match ((*u), CharConst (":flush"))) { + nextNodeNonNil (arg); + if (eval_bool (arg->car (), mlenv)) { + mlenv->env->wikioutput->flush (true); + } + nextNode (arg); + } else if (match ((*u), CharConst ("#flush"))) { + nextNode (arg); + mlenv->env->wikioutput->flush (true); + } else { + mlenv->env->wikioutput->out_toText (eval_str (arg->car (), mlenv)); + nextNode (arg); + } + } else { + mlenv->env->wikioutput->out_toText (eval_str (arg->car (), mlenv)); + nextNode (arg); + } + } + + return NULL; +} + diff --git a/modules/ml-wiki.h b/modules/ml-wiki.h index f922b04..071f2c4 100644 --- a/modules/ml-wiki.h +++ b/modules/ml-wiki.h @@ -14,5 +14,6 @@ MNode* ml_defun_wiki_link (MNode* cell, MlEnv* mlenv); MNode* ml_defun_wiki_command (MNode* cell, MlEnv* mlenv); MNode* ml_get_wiki_command (MNode* cell, MlEnv* mlenv); MNode* ml_wiki_guestuser_function (MNode* cell, MlEnv* mlenv); +MNode* ml_wiki_output (MNode* cell, MlEnv* mlenv); #endif /* ML_WIKI_H */ diff --git a/wiki/wikicmd.cc b/wiki/wikicmd.cc index 4821099..c0b3311 100644 --- a/wiki/wikicmd.cc +++ b/wiki/wikicmd.cc @@ -518,13 +518,19 @@ void wc_call_defun (WikiLine* wl, WikiFormat* wiki) { objv2.splitCharA (':', argsv); vargs = wiki->buildArgs (argsv.begin (), argsv.end ()); { +#ifdef WIKICOMPAT MotorOutputString out; MotorOutput* back = wiki->env->output; - WikiLine::linevec bl; +#endif + WikiMotorOutputString* wikiback = wiki->env->wikioutput; + WikiMotorOutputString wikiout (wiki); MNodePtr node; MNodePtr bcell; + wiki->env->wikioutput = &wikiout; +#ifdef WIKICOMPAT wiki->env->output = &out; +#endif bcell = wiki->env->mlenv->currentCell; wiki->env->mlenv->currentCell = NULL; try { @@ -533,11 +539,20 @@ void wc_call_defun (WikiLine* wl, WikiFormat* wiki) { wiki->logLispFunctionError (msg, ustring (wl->begin, wl->end)); } wiki->env->mlenv->currentCell = bcell; + if (wikiout.ans.length () > 0) { + WikiLine::linevec bl; + wiki->pass1 (wikiout.ans, &bl, wl->fsuper); + do_linevec (&bl, wiki); + } + wiki->env->wikioutput = wikiback; +#ifdef WIKICOMPAT if (out.ans.length () > 0) { + WikiLine::linevec bl; wiki->pass1 (out.ans, &bl, wl->fsuper); do_linevec (&bl, wiki); } wiki->env->output = back; +#endif } } else { WikiLine::linevec bl; @@ -551,4 +566,10 @@ void wc_call_defun (WikiLine* wl, WikiFormat* wiki) { } } +void wikiOutput (const ustring& text, bool fsuper, WikiFormat* wiki) { + WikiLine::linevec bl; + wiki->pass1 (text, &bl, fsuper); + do_linevec (&bl, wiki); +} + /* ============================================================ */ diff --git a/wiki/wikicmd.h b/wiki/wikicmd.h index 2a25ada..ddeae60 100644 --- a/wiki/wikicmd.h +++ b/wiki/wikicmd.h @@ -16,5 +16,6 @@ void wc_insert (WikiLine* wl, WikiFormat* wiki); void wc_data (WikiLine* wl, WikiFormat* wiki); void wc_local (WikiLine* wl, WikiFormat* wiki); void wc_call_defun (WikiLine* wl, WikiFormat* wiki); +void wikiOutput (const ustring& text, bool fsuper, WikiFormat* wiki); #endif /* WIKICMD_H */ diff --git a/wiki/wikiformat.cc b/wiki/wikiformat.cc index fa6bae3..f8670b7 100644 --- a/wiki/wikiformat.cc +++ b/wiki/wikiformat.cc @@ -100,6 +100,12 @@ ustring WikiMlEnv::wikiVarName (const ustring& name) { } /* ============================================================ */ +void WikiMotorOutputString::flush (bool fsuper) { + wikiOutput (ans, fsuper, wiki); + ans.resize (0); +} + +/* ============================================================ */ bool WikiAttrib1::readAttrib1 (WikiMotorObjVec* cell, bool& rc) { ustring key; WikiMotorObjVec vval; diff --git a/wiki/wikiformat.h b/wiki/wikiformat.h index 1fcb9f4..138e739 100644 --- a/wiki/wikiformat.h +++ b/wiki/wikiformat.h @@ -35,6 +35,15 @@ class WikiMlEnv: public MlEnv { virtual ustring wikiVarName (const ustring& name); }; +class WikiMotorOutputString: public MotorOutputString { + public: + WikiFormat* wiki; + + WikiMotorOutputString (WikiFormat* _wiki): wiki (_wiki) {}; + virtual ~WikiMotorOutputString () {}; + virtual void flush (bool fsuper); +}; + class WikiLine { public: typedef boost::ptr_vector linevec; @@ -47,22 +56,22 @@ class WikiLine { WikiLine* block2; bool fsuper; - WikiLine (uiterator b, uiterator e, bool f) { + WikiLine (uiterator b, uiterator e, bool _fsuper) { begin0 = begin = b; end = e; fn = NULL; block = NULL; block2 = NULL; - fsuper = f; + fsuper = _fsuper; }; - WikiLine (uiterator b0, uiterator b, uiterator e, bool f) { + WikiLine (uiterator b0, uiterator b, uiterator e, bool _fsuper) { begin0 = b0; begin = b; end = e; fn = NULL; block = NULL; block2 = NULL; - fsuper = f; + fsuper = _fsuper; }; virtual ~WikiLine () { delete block; -- 2.11.0