OSDN Git Service

fix keyword parameter processing.
authorvisor <visor@users.sourceforge.jp>
Sat, 11 May 2013 10:56:31 +0000 (19:56 +0900)
committervisor <visor@users.sourceforge.jp>
Sat, 11 May 2013 10:56:31 +0000 (19:56 +0900)
lib/expr.cc
lib/ml.h
modules/ml-apache.cc
modules/ml-db.cc
modules/ml-formvar.cc
modules/ml-http.cc
modules/ml-motor.cc
modules/ml-sendmail.cc
modules/ml-store.cc
modules/ml-string.cc
modules/ml-struct.cc

index fff0675..2223c18 100644 (file)
@@ -97,38 +97,36 @@ MNode*  eval (MNode* cell, MlEnv* mlenv) {
 
 double  eval_double (MNode* cell, MlEnv* mlenv) {
     MNodePtr  p;
-
     p = eval (cell, mlenv);
-    if (p ())
-       return p ()->to_double ();
-    else
-       return 0.;
+    return to_double (p ());
 }
 
 int  eval_int (MNode* cell, MlEnv* mlenv) {
-    return (int) eval_double (cell, mlenv);
+    MNodePtr  p;
+    p = eval (cell, mlenv);
+    return to_int (p ());
 }
 
 ustring  eval_str (MNode* cell, MlEnv* mlenv) {
     MNodePtr  p;
-
     p = eval (cell, mlenv);
     return to_string (p ());
 }
 
 ustring  eval_text1 (MNode* cell, MlEnv* mlenv) {
-    ustring  ans = eval_str (cell, mlenv);
-    return omitCtrl (ans);
+    MNodePtr  p;
+    p = eval (cell, mlenv);
+    return to_text1 (p ());
 }
 
 ustring  eval_asciiword (MNode* cell, MlEnv* mlenv) {
-    ustring  ans = eval_str (cell, mlenv);
-    return omitNonAsciiWord (ans);
+    MNodePtr  p;
+    p = eval (cell, mlenv);
+    return to_asciiword (p ());
 }
 
 bool  eval_bool (MNode* cell, MlEnv* mlenv) {
     MNodePtr  p;
-
     p = eval (cell, mlenv);
     return to_bool (p ());
 }
index 152ad41..3163e19 100644 (file)
--- a/lib/ml.h
+++ b/lib/ml.h
@@ -2,6 +2,7 @@
 #define ML_H
 
 #include "util_const.h"
+#include "util_string.h"
 #include "ustring.h"
 #include <iostream>
 #include <assert.h>
@@ -171,7 +172,11 @@ inline double  to_double (MNode* c) {
 }
 
 inline int  to_int (MNode* c) {
-    return (int)to_double (c);
+    if (c) {
+       return (int)(c->to_double ());
+    } else {
+       return 0;
+    }
 }
 
 bool  to_bool (const ustring& v);
@@ -189,6 +194,20 @@ inline ustring  to_string (MNode* c) {
        return uEmpty;
 }
 
+inline ustring  to_text1 (MNode* c) {
+    if (c)
+       return omitCtrl (c->to_string ());
+    else
+       return uEmpty;
+}
+
+inline ustring  to_asciiword (MNode* c) {
+    if (c)
+       return omitNonAsciiWord (c->to_string ());
+    else
+       return uEmpty;
+}
+
 inline ustring  dump_to_sexp (MNode* c) {
     if (c)
        return c->to_sexp ();
@@ -381,4 +400,6 @@ template <class T> inline T*  MObjRef (MLFunc* mobj, int id) {
 void  nextNode (MNode*& arg);
 void  nextNodeNonNil (MNode*& arg);
 
+#define  evkw(n,v)     (keywords[n] && ! isNil (v = eval (keywords[n], mlenv)))
+
 #endif /* ML_H */
index b4dc122..ecc5f56 100644 (file)
@@ -247,6 +247,7 @@ MNode*  ml_absolute_url (MNode* cell, MlEnv* mlenv) {
     ustring*  u;
     int  n;
     ustring*  ans;
+    MNodePtr  t;
     static paramList  kwlist[] = {
        {CharConst ("http"), true},
        {CharConst ("https"), true},
@@ -261,12 +262,12 @@ MNode*  ml_absolute_url (MNode* cell, MlEnv* mlenv) {
 
     setParams (arg, 1, &params, kwlist, &keywords, NULL);
     url = eval_text1 (params[0], mlenv);
-    if (eval_bool (keywords[0], mlenv))
+    if (keywords[0] && eval_bool (keywords[0], mlenv))
        proto = PROTO_HTTP;
-    if (eval_bool (keywords[1], mlenv))
+    if (keywords[1] && eval_bool (keywords[1], mlenv))
        proto = PROTO_HTTPS;
-    if (eval_bool (keywords[2], mlenv)) {
-       n = eval_int (keywords[2], mlenv);
+    if (evkw (2, t)) {
+       n = to_int (t ());
        if (1 <= n && n <= 65535)
            port = n;
     }
index ef46152..7522df8 100644 (file)
@@ -136,6 +136,7 @@ static MNode*  ml_db_sub (MNode* cell, MlEnv* mlenv, MLDb* obj, DBFUNC fn) {
     ustring  name;
     bool  fxserial = false;
     MNodePtr  errfn;
+    MNodePtr  t;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     MNode*  rest;
@@ -151,12 +152,13 @@ static MNode*  ml_db_sub (MNode* cell, MlEnv* mlenv, MLDb* obj, DBFUNC fn) {
 
     setParams (arg, 1, &params, kwlist, &keywords, &rest);
     name = eval_str (params[0], mlenv);
-    if (keywords[0])
-       obj->limit = eval_int (keywords[0], mlenv);
-    if (obj->limit <= 0)
-       obj->limit = 1;
-    if (obj->limit > kARRAYMAX)
-       obj->limit = kARRAYMAX;
+    if (evkw (0, t)) {
+       obj->limit = to_int (t ());
+       if (obj->limit <= 0)
+           obj->limit = 1;
+       if (obj->limit > kARRAYMAX)
+           obj->limit = kARRAYMAX;
+    }
     if (keywords[1])
        fxserial = eval_bool (keywords[1], mlenv);
     if (keywords[2])
index e6ac863..68a7dd7 100644 (file)
@@ -140,6 +140,7 @@ bool  FormVarOp::optFilter (const ustring& name, ustring& val, MlEnv* mlenv) {
 }
 
 static void  formvar_input_readopt (MNode*& arg, MlEnv* mlenv, ustring& name, FormVarOp& opt) {
+    MNodePtr  t;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     static paramList  kwlist[] = {
@@ -159,23 +160,21 @@ static void  formvar_input_readopt (MNode*& arg, MlEnv* mlenv, ustring& name, Fo
     if (opt.max < 0)
        opt.max = 0;
     opt.nowhite = eval_bool (keywords[1], mlenv) || eval_bool (keywords[2], mlenv);
-    if (keywords[3])
-       opt.filter.assign (eval_str (keywords[3], mlenv));
-    if (keywords[4]) {
-       MNodePtr  f;
+    if (evkw (3, t))
+       opt.filter.assign (to_string (t ()));
+    if (evkw (4, t)) {
        ustring  n;
        MNode*  p = NULL;
 
-       f = eval (keywords[4], mlenv);
-       checkDefun (f (), n, p);
+       checkDefun (t (), n, p);
        if (n == uLambda) {
-           opt.errFilter = f ();
+           opt.errFilter = t ();
        }
     }
     if (keywords[5])
        opt.fvalue = eval_bool (keywords[5], mlenv);
-    if (keywords[6])
-       opt.defaultVal = eval_str (keywords[6], mlenv);
+    if (evkw (6, t))
+       opt.defaultVal = to_string (t ());
 
     if (name.size () == 0)
        throw (uErrorVarNameEmpty);
@@ -345,6 +344,7 @@ MNode*  ml_formvar_input_file (MNode* cell, MlEnv* mlenv) {
     ustring  tgt;
     ustring  filename;
     int  idx;
+    MNodePtr  t;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     static paramList  kwlist[] = {
@@ -361,17 +361,15 @@ MNode*  ml_formvar_input_file (MNode* cell, MlEnv* mlenv) {
     opt.max = eval_int (keywords[0], mlenv);
     if (opt.max < 0)
        opt.max = 0;
-    if (keywords[1])
-       opt.filter.assign (eval_str (keywords[1], mlenv));
-    if (keywords[2]) {
-       MNodePtr  f;
+    if (evkw (1, t))
+       opt.filter.assign (to_string (t ()));
+    if (evkw (2, t)) {
        ustring  n;
        MNode*  p = NULL;
 
-       f = eval (keywords[2], mlenv);
-       checkDefun (f (), n, p);
+       checkDefun (t (), n, p);
        if (n == uLambda) {
-           opt.errFilter = f ();
+           opt.errFilter = t ();
        }
     }
     if (keywords[3])
index 091dfbc..07b617e 100644 (file)
@@ -411,6 +411,7 @@ MNode*  ml_build_url (MNode* cell, MlEnv* mlenv) {
     MNodePtr  query;
     AutoDelete<ustring>  ans;
     ustring  u;
+    MNodePtr  t;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     static paramList  kwlist[] = {
@@ -432,8 +433,8 @@ MNode*  ml_build_url (MNode* cell, MlEnv* mlenv) {
        pwd = eval (keywords[1], mlenv);
     if (keywords[2])           // pw
        pwd = eval (keywords[2], mlenv);
-    if (keywords[3])           // port
-       port = eval_int (keywords[3], mlenv);
+    if (evkw (3, t))           // port
+       port = to_int (t ());
     if (keywords[4])           // query
        query = eval (keywords[4], mlenv);
 
@@ -481,12 +482,21 @@ MNode*  ml_build_url_path (MNode* cell, MlEnv* mlenv) {
     MNode*  arg = cell->cdr ();
     AutoDelete<ustring>  ans;
     ustring  u;
+    MNodePtr  t;
+    int  c = 0;
 
     ans = new ustring;
     while (arg) {
-       u = eval_str (arg->car (), mlenv);
-       if (u.length () > 0)
-           ans ()->append (uSlash).append (urlencode (u.begin (), u.end ()));
+       t = eval (arg->car (), mlenv);
+       if (! isNil (t ())) {
+           u = to_string (t ());
+           if (c == 0) {
+               ans ()->append (urlencode (u.begin (), u.end ()));
+               c ++;
+           } else {
+               ans ()->append (uSlash).append (urlencode (u.begin (), u.end ()));
+           }
+       }
        nextNode (arg);
     }
 
@@ -527,6 +537,7 @@ MNode*  ml_http_get (MNode* cell, MlEnv* mlenv) {
     std::vector<MNode*>  keywords;
     MNode*  rest;
     MNodePtr  ans;
+    MNodePtr  t;
     static paramList  kwlist[] = {
        {CharConst ("get"), true},      // 0
        {CharConst ("post"), true},     // 1
@@ -569,8 +580,8 @@ MNode*  ml_http_get (MNode* cell, MlEnv* mlenv) {
        obj.http = new HTTPSendIConv ("SHIFT_JIS");
     else if (keywords[21] && eval_bool (keywords[21], mlenv)) // euc-jp
        obj.http = new HTTPSendIConv ("EUC-JP");
-    else if (keywords[22]) {
-       ustring  code = eval_str (keywords[22], mlenv);
+    else if (evkw (22, t)) {
+       ustring  code = to_string (t ());
        static uregex  re ("^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$");
        umatch  m;
        if (usearch (code, m, re)) {
@@ -590,60 +601,55 @@ MNode*  ml_http_get (MNode* cell, MlEnv* mlenv) {
        obj.http->setMethod (HTTPSend::M_DELETE);
     if (keywords[4] && eval_bool (keywords[4], mlenv)) // file
        obj.http->setPostFileMethod ();
-    if (keywords[5])           // id
-       obj.http->id = omitCtrl (eval_str (keywords[5], mlenv));
-    if (keywords[6])           // password
-       obj.http->pw = omitCtrl (eval_str (keywords[6], mlenv));
-    if (keywords[7])           // pw
-       obj.http->pw = omitCtrl (eval_str (keywords[7], mlenv));
-    if (keywords[8])           // query
-       obj.http->params = eval (keywords[8], mlenv);
-    if (keywords[9])           // get-query
-       obj.http->getparams = eval (keywords[9], mlenv);
-    if (keywords[10])          // post-file-serial
-       obj.http->fileparams_store = eval (keywords[10], mlenv);
-    if (keywords[11])          // post-file-named
-       obj.http->fileparams_storage = eval (keywords[11], mlenv);
-    if (keywords[12])          // post-file-static
-       obj.http->fileparams_static = eval (keywords[12], mlenv);
-    // post-file-static
-    if (keywords[13])          // cookie
-       cookie = eval (keywords[13], mlenv);
-    if (keywords[14])          // header
-       headerquery = eval (keywords[14], mlenv);
-    if (keywords[15]) {                // proxy-host
-       MNodePtr  h;
-       h = eval (keywords[15], mlenv);
-       if (! isNil (h ())) {
-           obj.http->host.host = omitNonAsciiWord (to_string (h ()));
-           obj.http->useproxy = true;
-           if (keywords[16])           // proxy-port
-               obj.http->host.port = to_uint32 (eval_str (keywords[16], mlenv));
-           if (keywords[17])           // proxy-id
-               obj.http->proxyid = omitCtrl (eval_str (keywords[17], mlenv));
-           if (keywords[18])           // proxy-password
-               obj.http->proxypw = omitCtrl (eval_str (keywords[18], mlenv));
-           if (keywords[19])           // proxy-pw
-               obj.http->proxypw = omitCtrl (eval_str (keywords[19], mlenv));
-       }
+    if (evkw (5, t))           // id
+       obj.http->id = omitCtrl (to_string (t ()));
+    if (evkw (6, t))           // password
+       obj.http->pw = omitCtrl (to_string (t ()));
+    if (evkw (7, t))           // pw
+       obj.http->pw = omitCtrl (to_string (t ()));
+    if (evkw (8, t))           // query
+       obj.http->params = t ();
+    if (evkw (9, t))           // get-query
+       obj.http->getparams = t ();
+    if (evkw (10, t))          // post-file-serial
+       obj.http->fileparams_store = t ();
+    if (evkw (11, t))          // post-file-named
+       obj.http->fileparams_storage = t ();
+    if (evkw (12, t))          // post-file-static
+       obj.http->fileparams_static = t ();
+    if (evkw (13, t))          // cookie
+       cookie = t ();
+    if (evkw (14, t))          // header
+       headerquery = t ();
+    if (evkw (15, t)) {                // proxy-host
+       obj.http->host.host = omitNonAsciiWord (to_string (t ()));
+       obj.http->useproxy = true;
+       if (evkw (16, t))               // proxy-port
+           obj.http->host.port = to_uint32 (to_string (t ()));
+       if (evkw (17, t))               // proxy-id
+           obj.http->proxyid = omitCtrl (to_string (t ()));
+       if (evkw (18, t))               // proxy-password
+           obj.http->proxypw = omitCtrl (to_string (t ()));
+       if (evkw (19, t))               // proxy-pw
+           obj.http->proxypw = omitCtrl (to_string (t ()));
     }
     if (keywords[23])
        errfn = eval (keywords[23], mlenv);
     if (keywords[24])
        fnoverify = eval_bool (keywords[24], mlenv);
-    if (keywords[25])
-       obj.http->rawquery = eval_str (keywords[25], mlenv);
-    if (keywords[26]) {
-       obj.http->querytype = eval_str (keywords[26], mlenv);
+    if (evkw (25, t))
+       obj.http->rawquery = to_string (t ());
+    if (evkw (26, t)) {
+       obj.http->querytype = to_string (t ());
        if (!checkASCII (obj.http->querytype))
            throw (obj.http->querytype + ustring (CharConst (": bad type")));
     }
-    if (keywords[27])          // raw-file-serial
-       obj.http->rawqueryfile = mlenv->env->path_store_file (eval_str (keywords[27], mlenv));
-    if (keywords[28])          // raw-file-named
-       obj.http->rawqueryfile = mlenv->env->path_storage_file (eval_str (keywords[28], mlenv));
-    if (keywords[29])          // raw-file-static
-       obj.http->rawqueryfile = mlenv->env->path_static_file (eval_str (keywords[29], mlenv));
+    if (evkw (27, t))          // raw-file-serial
+       obj.http->rawqueryfile = mlenv->env->path_store_file (to_string (t ()));
+    if (evkw (28, t))          // raw-file-named
+       obj.http->rawqueryfile = mlenv->env->path_storage_file (to_string (t ()));
+    if (evkw (29, t))          // raw-file-static
+       obj.http->rawqueryfile = mlenv->env->path_static_file (to_string (t ()));
     if (keywords[30])          // no-encode
        fnoencode = eval_bool (keywords[30], mlenv);
     
index fe39d9c..e06ad73 100644 (file)
@@ -30,6 +30,7 @@ MNode*  ml_output_header (MNode* cell, MlEnv* mlenv) {
     bool  finline = false;
     ustring  name;
     ustring  charset;
+    MNodePtr  t;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     static paramList  kwlist[] = {
@@ -43,10 +44,10 @@ MNode*  ml_output_header (MNode* cell, MlEnv* mlenv) {
     type = eval_asciiword (params[0], mlenv);
     if (keywords[0])
        finline = eval_bool (keywords[0], mlenv);
-    if (keywords[1])
-       name = eval_text1 (keywords[1], mlenv);
-    if (keywords[2])
-       charset = eval_asciiword (keywords[2], mlenv);
+    if (evkw (1, t))
+       name = to_text1 (t ());
+    if (evkw (2, t))
+       charset = to_asciiword (t ());
 
     if (type.empty ())
        throw (ustring (CharConst ("missing type.")));
@@ -76,6 +77,7 @@ MNode*  ml_motor_file (MNode* cell, MlEnv* mlenv) {
     ustring  encoding;
     bool  cflag = false;
     StoreType  storetype (mlenv);
+    MNodePtr  t;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     static paramList  kwlist[] = {
@@ -92,15 +94,15 @@ MNode*  ml_motor_file (MNode* cell, MlEnv* mlenv) {
     storetype.setStatic ();
     setParams (arg, 1, &params, kwlist, &keywords, NULL, true);
     file = eval_str (params[0], mlenv);
-    if (keywords[0]) {         // type
-       type = eval_asciiword (keywords[0], mlenv);
+    if (evkw (0, t)) {         // type
+       type = to_asciiword (t ());
        if (! checkMimeType (type))
            type.resize (0);
     }
     if (keywords[1])           // error
        ferr = eval_bool (keywords[1], mlenv);
-    if (keywords[2])           // code
-       encoding = eval_str (keywords[2], mlenv);
+    if (evkw (2, t))           // code
+       encoding = to_string (t ());
     if (keywords[3] && eval_bool (keywords[3], mlenv)) // continue
        cflag = true;
     if (keywords[4] && eval_bool (keywords[4], mlenv)) // serial
@@ -289,6 +291,7 @@ MNode*  ml_set_cookie (MNode* cell, MlEnv* mlenv) {
     time_t  span = 0;
     time_t  limit = 0;
     bool  fsecure = false;
+    MNodePtr  t;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     static paramList  kwlist[] = {
@@ -303,17 +306,17 @@ MNode*  ml_set_cookie (MNode* cell, MlEnv* mlenv) {
     setParams (arg, 2, &params, kwlist, &keywords, NULL);
     name = eval_asciiword (params[0], mlenv);
     value = eval_str (params[1], mlenv);
-    if (keywords[0])
-       path = eval_asciiword (keywords[0], mlenv);
-    if (keywords[1])
-       domain = eval_asciiword (keywords[1], mlenv);
-    if (keywords[2]) {
-       span = eval_int (keywords[2], mlenv);
+    if (evkw (0, t))
+       path = to_asciiword (t ());
+    if (evkw (1, t))
+       domain = to_asciiword (t ());
+    if (evkw (2, t)) {
+       span = to_int (t ());
        if (span < 0)
            span = 0;
     }
-    if (keywords[3]) {
-       limit = eval_int (keywords[3], mlenv);
+    if (evkw (3, t)) {
+       limit = to_int (t ());
        if (limit < 0)
            limit = 0;
     }
index 1cd6ca6..2ccec4b 100644 (file)
@@ -186,7 +186,8 @@ MNode*  ml_mail (MNode* cell, MlEnv* mlenv) {
     std::vector<ustring>  taddr;
     ustring  subject;
     MNodePtr  tolist;
-    ustring  t;
+    ustring  u;
+    MNodePtr  t;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     static paramList  kwlist[] = {
@@ -201,8 +202,8 @@ MNode*  ml_mail (MNode* cell, MlEnv* mlenv) {
     setParams (arg, 1, &params, kwlist, &keywords, NULL, true);
     storetype.setStatic ();
     file = eval_str (params[0], mlenv);
-    if (keywords[0])
-       faddr = eval_str (keywords[0], mlenv);
+    if (evkw (0, t))
+       faddr = to_string (t ());
     if (keywords[1])
        tolist = eval (keywords[1], mlenv);
     if (keywords[2] && eval_bool (keywords[2], mlenv))         // serial
@@ -221,31 +222,26 @@ MNode*  ml_mail (MNode* cell, MlEnv* mlenv) {
     if (tolist () && tolist ()->isCons ()) {
        MNode*  a = tolist ();
        while (a) {
-           t = to_string (a->car ());
-           if (checkMailAddr (t)) {
-               taddr.push_back (t);
+           u = to_string (a->car ());
+           if (checkMailAddr (u)) {
+               taddr.push_back (u);
            }
            nextNode (a);                   
        }
     } else {
-       t = to_string (tolist ());
-       if (! checkMailAddr (t)) {
+       u = to_string (tolist ());
+       if (! checkMailAddr (u)) {
            if (mlenv->log)
-               *mlenv->log << t << uErrorBadMailAddr << "\n";
+               *mlenv->log << u << uErrorBadMailAddr << "\n";
        } else {
-           taddr.push_back (t);
+           taddr.push_back (u);
        }
     }
     if (taddr.size () > TO_LIST_MAX)
        throw (ustring ("too many addresses"));
 
-//    if (file.size () == 0)
-//     throw (uErrorFilenameEmpty);
-//    if (! checkResourceName (file))
-//     throw (file + uErrorBadFile);
     if (faddr.size () > 0 && taddr.size () > 0) {
        ustring  f;
-//     if (mlenv->env->path_resource (file, f))
        f = storetype.src (mlenv, file);
        sendmail (faddr, taddr, f, mlenv);
     } else {
index 61ae1b1..ff67340 100644 (file)
@@ -555,6 +555,7 @@ MNode*  ml_read_file (MNode* cell, MlEnv* mlenv) {
     StoreType  storetype (mlenv);
     ustring  encoding;
     ustring  data;
+    MNodePtr  t;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     static paramList  kwlist[] = {
@@ -567,8 +568,8 @@ MNode*  ml_read_file (MNode* cell, MlEnv* mlenv) {
 
     setParams (arg, 1, &params, kwlist, &keywords, NULL);
     name = eval_str (params[0], mlenv);
-    if (keywords[0])
-       encoding = eval_str (keywords[0], mlenv);
+    if (evkw (0, t))
+       encoding = to_string (t ());
     if (keywords[1] && eval_bool (keywords[1], mlenv)) // serial
        storetype.setSerial ();
     if (keywords[2] && eval_bool (keywords[2], mlenv)) // named
@@ -605,6 +606,7 @@ MNode*  ml_write_file (MNode* cell, MlEnv* mlenv) {
     ustring  encoding;
     bool  fcrlf = false;
     ustring  data;
+    MNodePtr  t;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     static paramList  kwlist[] = {
@@ -618,8 +620,8 @@ MNode*  ml_write_file (MNode* cell, MlEnv* mlenv) {
     setParams (arg, 2, &params, kwlist, &keywords, NULL);
     name = eval_str (params[0], mlenv);
     data = eval_str (params[1], mlenv);
-    if (keywords[0])
-       encoding = eval_str (keywords[0], mlenv);
+    if (evkw (0, t))
+       encoding = to_string (t ());
     if (keywords[1])
        fcrlf = eval_bool (keywords[1], mlenv);
     if (keywords[2] && eval_bool (keywords[2], mlenv)) // serial
@@ -1016,6 +1018,7 @@ public:
     void  proc (MNode* cell, MlEnv* mlenv, bool fmotor) {
        MNode*  arg = cell->cdr ();
        ustring  filename;
+       MNodePtr  t;
        std::vector<MNode*>  params;
        std::vector<MNode*>  keywords;
        static paramList  kwlist_motor[] = {
@@ -1048,15 +1051,15 @@ public:
            storetype.setNamed ();
        if (keywords[2] && eval_bool (keywords[2], mlenv))      // static
            storetype.setStatic ();
-       if (keywords[3])                        // type
-           type = eval_str (keywords[3], mlenv);
+       if (evkw (3, t))                        // type
+           type = to_string (t ());
        if (keywords[4] && eval_bool (keywords[4], mlenv))      // continue
            cflag = true;
        if (! fmotor) {
            if (keywords[5])
                finline = eval_bool (keywords[5], mlenv); // inline
-           if (keywords[6])
-               dispname = omitCtrl (eval_str (keywords[6], mlenv)); // name
+           if (evkw (6, t))
+               dispname = to_text1 (t ());     // name
        }
 
        if (type.empty ()) {
index 0a8d40b..359d8a7 100644 (file)
@@ -142,7 +142,7 @@ MNode*  ml_regexp_match (MNode* cell, MlEnv* mlenv) {
     setParams (arg, 2, &params, kwlist, &keywords, NULL);
     reg = eval_str (params[0], mlenv);
     text = eval_str (params[1], mlenv);
-    if (eval_bool (keywords[0], mlenv))
+    if (keywords[0] && eval_bool (keywords[0], mlenv))
        f |= boost::regex_constants::icase;
 
     ans = wsearch_env (mlenv, text, reg, f);
@@ -226,9 +226,10 @@ MNode*  ml_postmatch (MNode* cell, MlEnv* mlenv) {
 MNode*  ml_string_filter (MNode* cell, MlEnv* mlenv) {
     MNode*  arg = cell->cdr ();
     ustring  reg;
-    ustring  t;
+    ustring  text;
     boost::wregex::flag_type  f = boost::regex_constants::normal;
     size_t  max = 0;
+    MNodePtr  t;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     static paramList  kwlist[] = {
@@ -239,16 +240,16 @@ MNode*  ml_string_filter (MNode* cell, MlEnv* mlenv) {
 
     setParams (arg, 2, &params, kwlist, &keywords, NULL);
     reg = eval_str (params[0], mlenv);
-    t = eval_str (params[1], mlenv);
-    if (eval_bool (keywords[0], mlenv))
+    text = eval_str (params[1], mlenv);
+    if (keywords[0] && eval_bool (keywords[0], mlenv))
        f |= boost::regex_constants::icase;
-    if (eval_bool (keywords[1], mlenv)) {
-       max = eval_int (keywords[1], mlenv);
+    if (evkw (1, t)) {
+       max = to_int (t ());
        if (max < 0)
            max = 0;
     }
 
-    if (wsearch_env (mlenv, t, reg, f)) {
+    if (wsearch_env (mlenv, text, reg, f)) {
        ustring  ans = wtou (std::wstring (mlenv->regmatch[0].first, mlenv->regmatch[0].second));
        if (max > 0) {
            substring (ans, 0, max, true, ans);
@@ -288,11 +289,11 @@ MNode*  ml_regexp_replace (MNode* cell, MlEnv* mlenv) {
     reg = eval_str (params[0], mlenv);
     to = eval_str (params[1], mlenv);
     text = eval_str (params[2], mlenv);
-    if (eval_bool (keywords[0], mlenv))
+    if (keywords[0] && eval_bool (keywords[0], mlenv))
        f |= boost::regex_constants::icase;
-    if (eval_bool (keywords[1], mlenv))
+    if (keywords[1] && eval_bool (keywords[1], mlenv))
        fglobal = true;
-    if (eval_bool (keywords[2], mlenv))
+    if (keywords[2] && eval_bool (keywords[2], mlenv))
        fglobal = true;
 
     if (! fglobal)
@@ -325,7 +326,7 @@ MNode*  ml_regexp_split (MNode* cell, MlEnv* mlenv) {
     setParams (arg, 2, &params, kwlist, &keywords, NULL);
     reg = eval_str (params[0], mlenv);
     text = eval_str (params[1], mlenv);
-    if (eval_bool (keywords[0], mlenv))
+    if (keywords[0] && eval_bool (keywords[0], mlenv))
        f |= boost::regex_constants::icase;
 
     if (wsearch_env (mlenv, text, reg, f)) {
@@ -887,9 +888,9 @@ MNode*  ml_sort_string (MNode* cell, MlEnv* mlenv) {
 
     setParams (arg, 1, &params, kwlist, &keywords, NULL);
     h = eval (params[0], mlenv);
-    if (eval_bool (keywords[0], mlenv))
+    if (keywords[0] && eval_bool (keywords[0], mlenv))
        fdesc = false;
-    if (eval_bool (keywords[1], mlenv))
+    if (keywords[1] && eval_bool (keywords[1], mlenv))
        fdesc = true;
 
     a = h ();
index 4024768..a4b8624 100644 (file)
@@ -265,10 +265,10 @@ MNode*  ml_repeat (MNode* cell, MlEnv* mlenv) {
     double  step = 1.;
     std::vector<ustring>  lv;
     double  i;
-    MNodePtr  h;
     MNodePtr  ans;
     int  j;
     bool  kp;
+    MNodePtr  t;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     MNode*  rest;
@@ -284,10 +284,9 @@ MNode*  ml_repeat (MNode* cell, MlEnv* mlenv) {
     to = eval_double (params[2], mlenv);
     if (keywords[0])
        step = eval_double (keywords[0], mlenv);
-    if (keywords[1]) {
+    if (evkw (1, t)) {
        MNode*  a;
-       h = eval (keywords[1], mlenv);
-       a = h ();
+       a = t ();
        if (a && a->isSym ()) {
            lv.push_back (a->to_string ());
        } else if (a && a->isCons ()) {
@@ -296,7 +295,7 @@ MNode*  ml_repeat (MNode* cell, MlEnv* mlenv) {
                nextNode (a);
            }
        } else {
-           throw (to_string (h ()) + ustring (": bad argument."));
+           throw (to_string (t ()) + ustring (": bad argument."));
        }
     }
 
@@ -308,8 +307,8 @@ MNode*  ml_repeat (MNode* cell, MlEnv* mlenv) {
        if (step > 0) {
            kp = true;
            for (i = from; kp && i <= to; i += step) {
-               h = newMNode_num (i);
-               mlenv->setVar (iv, h ());
+               t = newMNode_num (i);
+               mlenv->setVar (iv, t ());
                if (i > 0)
                    for (j = 0; j < lv.size (); j ++)
                        mlenv->setVar (lv[j], mlenv->getAry (lv[j], (size_t)i));
@@ -328,8 +327,8 @@ MNode*  ml_repeat (MNode* cell, MlEnv* mlenv) {
        } else if (step < 0) {
            kp = true;
            for (i = from; kp && i >= to; i += step) {
-               h = newMNode_num (i);
-               mlenv->setVar (iv, h ());
+               t = newMNode_num (i);
+               mlenv->setVar (iv, t ());
                if (i > 0)
                    for (j = 0; j < lv.size (); j ++)
                        mlenv->setVar (lv[j], mlenv->getAry (lv[j], (size_t)i));
@@ -363,13 +362,12 @@ MNode*  ml_doarray (MNode* cell, MlEnv* mlenv) {
     MNode*  arg = cell->cdr ();
     std::vector<ustring>  lv;
     std::vector<ustring>  setvar;
-    MNodePtr  vlist;
     ustring  iv;
     size_t  i, n;
     int  it, nlv, nsv;
     ustring  val;
     MNodePtr  ans;
-    MNodePtr  h;
+    MNodePtr  t;
     bool  kp;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
@@ -381,32 +379,31 @@ MNode*  ml_doarray (MNode* cell, MlEnv* mlenv) {
     };
 
     setParams (arg, 1, &params, kwlist, &keywords, &rest);
-    vlist = eval (params[0], mlenv);
-    if (vlist () && vlist ()->isSym ()) {
-       lv.push_back (vlist ()->to_string ());
-    } else if (vlist () && vlist ()->isCons ()) {
-       MNode*  a = vlist ();
+    t = eval (params[0], mlenv);
+    if (t () && t ()->isSym ()) {
+       lv.push_back (t ()->to_string ());
+    } else if (t () && t ()->isCons ()) {
+       MNode*  a = t ();
        while (a && a->isCons ()) {
            lv.push_back (to_string (a->car ()));
            nextNode (a);
        }
     } else {
-       throw (to_string (vlist ()) + ustring (": bad argument."));
+       throw (dump_to_sexp (t ()) + ustring (": bad argument."));
     }
-    if (keywords[0])
-       iv = eval_str (keywords[0], mlenv);
-    if (keywords[1]) {
-       vlist = eval (keywords[1], mlenv);
-       if (vlist () && vlist ()->isSym ()) {
-           setvar.push_back (to_string (vlist ()));
-       } else if (vlist () && vlist ()->isCons ()) {
-           MNode*  a = vlist ();
+    if (evkw (0, t))
+       iv = to_string (t ());
+    if (evkw (1, t)) {
+       if (t () && t ()->isSym ()) {
+           setvar.push_back (to_string (t ()));
+       } else if (t () && t ()->isCons ()) {
+           MNode*  a = t ();
            while (a && a->isCons ()) {
                setvar.push_back (to_string (a->car ()));
                nextNode (a);
            }
        } else {
-           throw (ustring (CharConst (":setvar ")) + to_string (vlist ()) + ustring (": bad argument."));
+           throw (ustring (CharConst (":setvar ")) + dump_to_sexp (t ()) + ustring (": bad argument."));
        }
     }
 
@@ -438,12 +435,11 @@ MNode*  ml_doarray (MNode* cell, MlEnv* mlenv) {
                    }
                }
                if (iv.size () > 0) {
-                   h = newMNode_num (i);
-                   mlenv->setVar (iv, h ());
+                   t = newMNode_num (i);
+                   mlenv->setVar (iv, t ());
                }
                ans = progn (rest, mlenv);
                if (mlenv->breaksym ()) {
-//                 if (mlenv->breaksym ()->isNil () || eq (mlenv->breaksym (), cell->car ())) mlenv->setBreaksym (NULL);
                    mlenv->stopBreak (cell->car ());
                    kp = false;
                }