[PD-cvs] pd/src kernel.c,1.1.2.12,1.1.2.13

Mathieu Bouchard matju at users.sourceforge.net
Thu Dec 28 19:30:20 CET 2006


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22967

Modified Files:
      Tag: desiredata
	kernel.c 
Log Message:
first (non-working) draft of new parser


Index: kernel.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/kernel.c,v
retrieving revision 1.1.2.12
retrieving revision 1.1.2.13
diff -C2 -d -r1.1.2.12 -r1.1.2.13
*** kernel.c	28 Dec 2006 06:49:20 -0000	1.1.2.12
--- kernel.c	28 Dec 2006 18:30:17 -0000	1.1.2.13
***************
*** 259,263 ****
  
  static int should_quote(char *s) {
! 	return *s==';' || *s==',' || *s=='\\' || (*s=='$' && s[1]>='0' && s[1]<='9');
  }
  
--- 259,263 ----
  
  static int should_quote(char *s) {
! 	return *s==';' || *s==',' || *s=='\\' || (*s=='$' && isdigit(s[1]));
  }
  
***************
*** 1784,1809 ****
  }
  
! /* convert text to a binbuf */
! void binbuf_text(t_binbuf *x, char *text, size_t size) {
      char buf[MAXPDSTRING+1], *bufp, *ebuf = buf+MAXPDSTRING;
      const char *textp = text, *etext = text+size;
      binbuf_clear(x);
-     binbuf_capa(x,16);
      x->n = 0;
      while (1) {
          /* skip leading space */
!         while ((textp != etext) && (*textp == ' ' || *textp == '\n' || *textp == '\r' || *textp == '\t')) textp++;
          if (textp == etext) break;
!         if      (*textp == ';') {binbuf_addv(x,";"); textp++;}
!         else if (*textp == ',') {binbuf_addv(x,","); textp++;}
          else {
              /* it's an atom other than a comma or semi */
-             char c;
              int q = 0, slash = 0, lastslash = 0, dollar = 0;
              bufp = buf;
              do {
!                 c = *bufp = *textp++;
                  lastslash = slash;
!                 slash = (c == '\\');
                  if (q >= 0) {
                      int digit = isdigit(c), dot=c=='.', minus=c=='-', plusminus=minus||c=='+', expon=c=='e'||c=='E';
--- 1784,1845 ----
  }
  
! /* convert text to binbuf, matju-style */
! void binbuf_text_matju(t_binbuf *x, char *text, size_t size) {
!     char buf[MAXPDSTRING+1], *bufp, *ebuf = buf+MAXPDSTRING;
!     const char *textp = text, *etext = text+size;
!     binbuf_clear(x);
!     x->n = 0;
!     while (1) {
! 	char *token;
! 	while (textp!=etext && isspace(*textp)) textp++;
! 	if (textp == etext) break;
! 	if (*textp==';') {binbuf_addv(x,";"); textp++; continue;}
! 	if (*textp==',') {binbuf_addv(x,","); textp++; continue;}
! 	if (*textp=='+' || *textp=='-' || *textp=='.' || isdigit(*textp)) {
! 	    double v = strtod(textp,&token);
! 	    if (isspace(*token)) {binbuf_addv(x,"f",v); continue;}
! 	    textp=token;
! 	}
! 	bufp = buf;
!         for (; textp!=etext && bufp!=ebuf && *textp!=',' && *textp!=';' && !isspace(*textp); bufp++) {
! 		if (*textp=='\\') {
! 			textp++;
! 			if (textp==etext) break;
! 			*bufp++ = *textp++;
! 		}
! 	}
! 	//if (c=='$' && textp!=etext && isdigit(textp[0])) dollar = 1;
! 	//if (!slash) bufp++;
! 	//*bufp = 0;
!         /*if (dollar) {
!                 if (buf[0] != '$') dollar = 0;
!                 for (bufp = buf+1; *bufp; bufp++) if (!isdigit(*bufp)) dollar = 0;
!                 if (dollar) binbuf_addv(x,"$",atoi(buf+1));
!                 else        binbuf_addv(x,"&",gensym(buf));
!             } else */       binbuf_addv(x,"s",gensym(buf));
!     }
!     binbuf_capa(x,x->n);
! }
! 
! /* convert text to binbuf, miller-style */
! void binbuf_text_miller(t_binbuf *x, char *text, size_t size) {
      char buf[MAXPDSTRING+1], *bufp, *ebuf = buf+MAXPDSTRING;
      const char *textp = text, *etext = text+size;
      binbuf_clear(x);
      x->n = 0;
      while (1) {
          /* skip leading space */
!         while (textp!=etext && isspace(*textp)) textp++;
          if (textp == etext) break;
!         if      (*textp==';') {binbuf_addv(x,";"); textp++;}
!         else if (*textp==',') {binbuf_addv(x,","); textp++;}
          else {
              /* it's an atom other than a comma or semi */
              int q = 0, slash = 0, lastslash = 0, dollar = 0;
              bufp = buf;
              do {
!                 char c = *bufp = *textp++;
                  lastslash = slash;
!                 slash = c=='\\';
                  if (q >= 0) {
                      int digit = isdigit(c), dot=c=='.', minus=c=='-', plusminus=minus||c=='+', expon=c=='e'||c=='E';
***************
*** 1837,1850 ****
              else if (dollar) {
                  if (buf[0] != '$') dollar = 0;
!                 for (bufp = buf+1; *bufp; bufp++) if (*bufp < '0' || *bufp > '9') dollar = 0;
                  if (dollar) binbuf_addv(x,"$",atoi(buf+1));
                  else        binbuf_addv(x,"&",gensym(buf));
              } else          binbuf_addv(x,"s",gensym(buf));
          }
-         if (textp == etext) break;
      }
      binbuf_capa(x,x->n);
  }
  
  /* convert a binbuf to text; no null termination. */
  void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp) {
--- 1873,1893 ----
              else if (dollar) {
                  if (buf[0] != '$') dollar = 0;
!                 for (bufp = buf+1; *bufp; bufp++) if (!isdigit(*bufp)) dollar = 0;
                  if (dollar) binbuf_addv(x,"$",atoi(buf+1));
                  else        binbuf_addv(x,"&",gensym(buf));
              } else          binbuf_addv(x,"s",gensym(buf));
          }
      }
      binbuf_capa(x,x->n);
  }
  
+ void binbuf_text(t_binbuf *x, char *text, size_t size) {
+ 	if (0) {
+ 		binbuf_text_matju(x,text,size);
+ 	} else {
+ 		binbuf_text_miller(x,text,size);
+ 	}
+ }
+ 
  /* convert a binbuf to text; no null termination. */
  void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp) {





More information about the Pd-cvs mailing list