[BACK]Return to interpreter.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Diff for /src/usr.bin/mg/interpreter.c between version 1.6 and 1.7

version 1.6, 2021/02/24 14:17:18 version 1.7, 2021/03/02 19:50:52
Line 22 
Line 22 
  * 1. Give multiple arguments to a function that usually would accept only one:   * 1. Give multiple arguments to a function that usually would accept only one:
  * (find-file a.txt b.txt. c.txt)   * (find-file a.txt b.txt. c.txt)
  *   *
  * 2. Define a list:   * 2. Define a single value variable:
  * (define myfiles(list d.txt e.txt))   * (define myfile d.txt)
  *   *
  * 3. Use the previously defined list:   * 3. Define a list:
    * (define myfiles(list e.txt f.txt))
    *
    * 4. Use the previously defined variable or list:
  * (find-file myfiles)   * (find-file myfiles)
  *   *
  * To do:   * To do:
Line 56 
Line 59 
 static int       multiarg(char *);  static int       multiarg(char *);
 static int       isvar(char **, char **, int);  static int       isvar(char **, char **, int);
 static int       foundvar(char *);  static int       foundvar(char *);
 static int       foundlist(char *);  
   
   
 /*  /*
  * Structure for variables during buffer evaluation.   * Structure for variables during buffer evaluation.
  */   */
Line 268 
Line 269 
  * the issues.   * the issues.
  */   */
 static int  static int
 foundlist(char *defstr)  foundvar(char *defstr)
 {  {
         struct varentry *vt, *v1 = NULL;          struct varentry *vt, *v1 = NULL;
         const char       e[2] = "e", t[2] = "t";          const char       e[2] = "e", t[2] = "t";
         char            *p, *vnamep, *vendp = NULL, *valp, *o;          char            *p, *vnamep, *vendp = NULL, *valp, *o;
         int              spc;          int              spc, foundlist = 0;
   
   
         p = defstr + 1;         /* move past first '(' char.    */          p = defstr + 1;         /* move past first '(' char.    */
         p = skipwhite(p);       /* find first char of 'define'. */          p = skipwhite(p);       /* find first char of 'define'. */
         p = strstr(p, e);       /* find first 'e' in 'define'.  */          p = strstr(p, e);       /* find first 'e' in 'define'.  */
Line 287 
Line 287 
         /* now find the end of the list name */          /* now find the end of the list name */
         while (1) {          while (1) {
                 ++vendp;                  ++vendp;
                 if (*vendp == '(' || *vendp == ' ' || *vendp == '\t')                  if (*vendp == '(') {
                           foundlist = 1;
                         break;                          break;
                   } else if (*vendp == ' ' || *vendp == '\t')
                           break;
         }          }
         *vendp = '\0';          *vendp = '\0';
         /*          /*
Line 299 
Line 302 
                 return(dobeep_msgs("Variable/function name clash:", vnamep));                  return(dobeep_msgs("Variable/function name clash:", vnamep));
   
         p = ++vendp;          p = ++vendp;
         p = strstr(p, t);       /* find 't' in 'list'.  */          p = skipwhite(p);
         valp = skipwhite(++p);  /* find first value     */          if (foundlist) {
                   p = strstr(p, t);       /* find 't' in 'list'.  */
                   valp = skipwhite(++p);  /* find first value     */
           } else
                   valp = p;
         /*          /*
          * Now we have the name of the list starting at 'vnamep',           * Now we have the name of the list starting at 'vnamep',
          * and the first value is at 'valp', record the details           * and the first value is at 'valp', record the details
Line 345 
Line 352 
         if ((v1->vals = strndup(valp, BUFSIZE)) == NULL)          if ((v1->vals = strndup(valp, BUFSIZE)) == NULL)
                 return(dobeep_msg("strndup error"));                  return(dobeep_msg("strndup error"));
   
         return (TRUE);  #ifdef  MGLOG
 }          mglog_misc("var:%s\t#items:%d\tvals:%s\n", vnamep, v1->count, v1->vals);
   #endif
   
   
 /*  
  * to do  
  */  
 static int  
 foundvar(char *funstr)  
 {  
         ewprintf("to do");  
         return (TRUE);          return (TRUE);
 }  }
   
Line 398 
Line 398 
         }          }
         if (!regexec(&regex_buff, funstr, 0, NULL, 0)) {          if (!regexec(&regex_buff, funstr, 0, NULL, 0)) {
                 regfree(&regex_buff);                  regfree(&regex_buff);
                 return(foundlist(funstr));                  return(foundvar(funstr));
         }          }
         /* Does the line have a single variable 'define' like: */          /* Does the line have a single variable 'define' like: */
         /* (define i 0) */          /* (define i 0) */
Line 409 
Line 409 
         }          }
         if (!regexec(&regex_buff, funstr, 0, NULL, 0)) {          if (!regexec(&regex_buff, funstr, 0, NULL, 0)) {
                 regfree(&regex_buff);                  regfree(&regex_buff);
                 return(foundvar(funstr));                  return(foundvar(funstr)); /* now as 'list' above -??  */
         }          }
         /* Does the line have an unrecognised 'define' */          /* Does the line have an unrecognised 'define' */
         regs = "^[(][\t ]*define[\t ]+";          regs = "^[(][\t ]*define[\t ]+";

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7