[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.22 and 1.23

version 1.22, 2021/04/20 16:34:20 version 1.23, 2021/05/03 12:18:43
Line 35 
Line 35 
  * 1. multiline parsing - currently only single lines supported.   * 1. multiline parsing - currently only single lines supported.
  * 2. parsing for '(' and ')' throughout whole string and evaluate correctly.   * 2. parsing for '(' and ')' throughout whole string and evaluate correctly.
  * 3. conditional execution.   * 3. conditional execution.
  * 4. deal with special characters in a string: "x\" x" etc   * 4. have memory allocated dynamically for variable values.
  * 5. do symbol names need more complex regex patterns? [A-Za-z][.0-9_A-Z+a-z-]   * 5. do symbol names need more complex regex patterns? [A-Za-z][.0-9_A-Z+a-z-]
  *    at the moment.   *    at the moment.
  * 6. oh so many things....   * 6. oh so many things....
Line 94 
Line 94 
 };  };
   
 /*  /*
  * Structure for variables during buffer evaluation.  
  */  
 struct varentry {  
         SLIST_ENTRY(varentry) entry;  
         char     valbuf[BUFSIZE];  
         char    *name;  
         char    *vals;  
         int      count;  
         int      expctr;  
         int      blkid;  
 };  
 SLIST_HEAD(vlisthead, varentry) varhead = SLIST_HEAD_INITIALIZER(varhead);  
   
 /*  
  * Structure for scheme keywords.   * Structure for scheme keywords.
  */   */
 #define NUMSCHKEYS      4  #define NUMSCHKEYS      4
Line 135 
Line 121 
 {  {
         const char      *lrp = NULL;          const char      *lrp = NULL;
         char            *p, *begp = NULL, *endp = NULL, *regs;          char            *p, *begp = NULL, *endp = NULL, *regs;
         int              i, ret, pctr, expctr, blkid, inquote;          int              i, ret, pctr, expctr, blkid, inquote, esc;
   
         pctr = expctr = inquote = 0;          pctr = expctr = inquote = esc = 0;
         blkid = 1;          blkid = 1;
   
         /*          /*
Line 169 
Line 155 
         p = funstr;          p = funstr;
   
         for (i = 0; i < llen; ++i, p++) {          for (i = 0; i < llen; ++i, p++) {
                 if (*p == '(') {                  if (*p == '\\') {
                         if (inquote == 1) {                          esc = 1;
                   } else if (*p == '(') {
                           if (inquote != 0) {
                                 cleanup();                                  cleanup();
                                 return(dobeep_msg("Opening and closing quote "\                                  return(dobeep_msg("Opening and closing quote "\
                                     "char error"));                                      "char error"));
Line 190 
Line 178 
                         lrp = &lp;                          lrp = &lp;
                         begp = endp = NULL;                          begp = endp = NULL;
                         pctr++;                          pctr++;
                           esc = 0;
                 } else if (*p == ')') {                  } else if (*p == ')') {
                         if (inquote == 1) {                          if (inquote != 0) {
                                 cleanup();                                  cleanup();
                                 return(dobeep_msg("Opening and closing quote "\                                  return(dobeep_msg("Opening and closing quote "\
                                     "char error"));                                      "char error"));
Line 211 
Line 200 
                         lrp = &rp;                          lrp = &rp;
                         begp = endp = NULL;                          begp = endp = NULL;
                         pctr--;                          pctr--;
                           esc = 0;
                 } else if (*p != ' ' && *p != '\t') {                  } else if (*p != ' ' && *p != '\t') {
                         if (begp == NULL)                          if (begp == NULL)
                                 begp = p;                                  begp = p;
                         if (*p == '"') {                          if (*p == '"') {
                                 if (inquote == 0)                                  if (inquote == 0 && esc == 0)
                                         inquote = 1;                                          inquote++;
                                   else if (inquote > 0 && esc == 1)
                                           esc = 0;
                                 else                                  else
                                         inquote = 0;                                          inquote--;
                         }                          }
                         endp = NULL;                          endp = NULL;
                 } else if (endp == NULL && (*p == ' ' || *p == '\t')) {                  } else if (endp == NULL && (*p == ' ' || *p == '\t')) {
                         *p = ' ';                          *p = ' ';
                         endp = p;                          endp = p;
                 } else if (*p == '\t')                          esc = 0;
                   } else if (*p == '\t') {
                         if (inquote == 0)                          if (inquote == 0)
                                 *p = ' ';                                  *p = ' ';
                           esc = 0;
                   }
   
                 if (pctr == 0) {                  if (pctr == 0) {
                         blkid++;                          blkid++;
Line 495 
Line 490 
         mglog_isvar(*varbuf, *argp, sizof);          mglog_isvar(*varbuf, *argp, sizof);
 #endif  #endif
         SLIST_FOREACH(v1, &varhead, entry) {          SLIST_FOREACH(v1, &varhead, entry) {
                 if (strcmp(*argp, v1->name) == 0) {                  if (strcmp(*argp, v1->v_name) == 0) {
                         (void)(strlcpy(*varbuf, v1->valbuf, sizof) >= sizof);                          (void)(strlcpy(*varbuf, v1->v_buf, sizof) >= sizof);
                         return (TRUE);                          return (TRUE);
                 }                  }
         }          }
Line 551 
Line 546 
   
         if (!SLIST_EMPTY(&varhead)) {          if (!SLIST_EMPTY(&varhead)) {
                 SLIST_FOREACH_SAFE(v1, &varhead, entry, vt) {                  SLIST_FOREACH_SAFE(v1, &varhead, entry, vt) {
                         if (strcmp(vnamep, v1->name) == 0)                          if (strcmp(vnamep, v1->v_name) == 0)
                                 SLIST_REMOVE(&varhead, v1, varentry, entry);                                  SLIST_REMOVE(&varhead, v1, varentry, entry);
                 }                  }
         }          }
         if ((v1 = malloc(sizeof(struct varentry))) == NULL)          if ((v1 = malloc(sizeof(struct varentry))) == NULL)
                 return (ABORT);                  return (ABORT);
         SLIST_INSERT_HEAD(&varhead, v1, entry);          SLIST_INSERT_HEAD(&varhead, v1, entry);
         if ((v1->name = strndup(vnamep, BUFSIZE)) == NULL)          if ((v1->v_name = strndup(vnamep, BUFSIZE)) == NULL)
                 return(dobeep_msg("strndup error"));                  return(dobeep_msg("strndup error"));
         vnamep = v1->name;          vnamep = v1->v_name;
         v1->count = 0;          v1->v_count = 0;
         v1->expctr = expctr;          v1->v_vals = NULL;
         v1->blkid = blkid;          v1->v_buf[0] = '\0';
         v1->vals = NULL;  
         v1->valbuf[0] = '\0';  
   
         defnam = v1->valbuf;          defnam = v1->v_buf;
   
         if (hasval) {          if (hasval) {
                 valp = skipwhite(vendp + 1);                  valp = skipwhite(vendp + 1);
Line 670 
Line 663 
                         if (strlcat(bp, argp, BUFSIZE) >= BUFSIZE) {                          if (strlcat(bp, argp, BUFSIZE) >= BUFSIZE) {
                                 return (dobeep_msg("strlcat error"));                                  return (dobeep_msg("strlcat error"));
                         }                          }
 /*                      v1->count++;*/  /*                      v1->v_count++;*/
   
                         if (fin)                          if (fin)
                                 break;                                  break;
Line 686 
Line 679 
  * Finished with buffer evaluation, so clean up any vars.   * Finished with buffer evaluation, so clean up any vars.
  * Perhaps keeps them in mg even after use,...   * Perhaps keeps them in mg even after use,...
  */   */
 static int  /*static int
 clearvars(void)  clearvars(void)
 {  {
         struct varentry *v1 = NULL;          struct varentry *v1 = NULL;
Line 694 
Line 687 
         while (!SLIST_EMPTY(&varhead)) {          while (!SLIST_EMPTY(&varhead)) {
                 v1 = SLIST_FIRST(&varhead);                  v1 = SLIST_FIRST(&varhead);
                 SLIST_REMOVE_HEAD(&varhead, entry);                  SLIST_REMOVE_HEAD(&varhead, entry);
 /*              free(v1->vals);*/                  free(v1->v_name);
                 free(v1->name);  
                 free(v1);                  free(v1);
         }          }
         return (FALSE);          return (FALSE);
 }  }
   */
 /*  /*
  * Finished with block evaluation, so clean up any expressions.   * Finished with block evaluation, so clean up any expressions.
  */   */
Line 727 
Line 719 
         defnam = NULL;          defnam = NULL;
   
         clearexp();          clearexp();
         clearvars();  /*      clearvars();*/
 }  }
   
 /*  /*

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.23