Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv411
Modified Files: Tag: desiredata desire.h kernel.c Log Message: removed some MAXPDSTRING; added oprintf, which prints to a ostringstream&
Index: kernel.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/kernel.c,v retrieving revision 1.1.2.62 retrieving revision 1.1.2.63 diff -C2 -d -r1.1.2.62 -r1.1.2.63 *** kernel.c 18 Jul 2007 16:16:07 -0000 1.1.2.62 --- kernel.c 18 Jul 2007 20:23:15 -0000 1.1.2.63 *************** *** 1718,1724 **** }
- /* YOU WISH */ void oprintf(ostream &buf, const char *s, ...) { ! // lalalalalère... }
--- 1718,1729 ---- }
void oprintf(ostream &buf, const char *s, ...) { ! char *b; ! va_list args; ! va_start(args,s); ! vasprintf(&b,s,args); ! va_end(args); ! buf << b; ! free(b); }
*************** *** 1890,1894 **** * buf holds the expanded $arg * ! * if some error occured, "-1" is returned * * e.g. "$1-bla" with list "10 20 30" --- 1895,1899 ---- * buf holds the expanded $arg * ! * if some error occurred, "-1" is returned * * e.g. "$1-bla" with list "10 20 30" *************** *** 1897,1906 **** * return value = 1; (s+1=="-bla") */ ! static int binbuf_expanddollsym(char *s, char *buf, t_atom dollar0, int ac, t_atom *av, int tonew) { int argno=atol(s); int arglen=0; char*cs=s; char c=*cs; - *buf=0; while (c && isdigit(c)) { c=*cs++; --- 1902,1910 ---- * return value = 1; (s+1=="-bla") */ ! static int binbuf_expanddollsym(char *s, std::ostream &buf, t_atom dollar0, int ac, t_atom *av, int tonew) { int argno=atol(s); int arglen=0; char*cs=s; char c=*cs; while (c && isdigit(c)) { c=*cs++; *************** *** 1908,1919 **** } /* invalid $-expansion (like "$bla") */ ! if (cs==s) {sprintf(buf, "$"); return 0;} if (argno < 0 || argno > ac) { /* undefined argument */ if(!tonew) return 0; ! sprintf(buf, "$%d", argno); } else if (argno == 0) { /* $0 */ ! atom_string(&dollar0, buf, MAXPDSTRING/2-1); } else { /* fine! */ ! atom_string(av+(argno-1), buf, MAXPDSTRING/2-1); } return arglen-1; --- 1912,1923 ---- } /* invalid $-expansion (like "$bla") */ ! if (cs==s) {buf << "$"; return 0;} if (argno < 0 || argno > ac) { /* undefined argument */ if(!tonew) return 0; ! buf << "$" << argno; } else if (argno == 0) { /* $0 */ ! atom_ostream(&dollar0, buf); } else { /* fine! */ ! atom_ostream(av+(argno-1), buf); } return arglen-1; *************** *** 1922,1932 **** /* LATER remove the dependence on the current canvas for $0; should be another argument. */ t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av, int tonew) { ! char buf[MAXPDSTRING]; ! char buf2[MAXPDSTRING]; ! char*str=s->name; ! int next=0, i=MAXPDSTRING; t_atom dollarnull; SETFLOAT(&dollarnull, canvas_getdollarzero()); - while(i--)buf2[i]=0; /* JMZ: currently, a symbol is detected to be A_DOLLSYM if it starts with '$' * the leading $ is stripped and the rest stored in "s". i would suggest to NOT strip the leading $ --- 1926,1934 ---- /* LATER remove the dependence on the current canvas for $0; should be another argument. */ t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av, int tonew) { ! ostringstream buf2; ! char *str=s->name; ! int next=0; t_atom dollarnull; SETFLOAT(&dollarnull, canvas_getdollarzero()); /* JMZ: currently, a symbol is detected to be A_DOLLSYM if it starts with '$' * the leading $ is stripped and the rest stored in "s". i would suggest to NOT strip the leading $ *************** *** 1934,1958 **** char *substr=strchr(str, '$'); if(!substr || substr-str >= MAXPDSTRING) return s; ! strncat(buf2, str, (substr-str)); str=substr+1; ! while((next=binbuf_expanddollsym(str, buf, dollarnull, ac, av, tonew))>=0) { /* JMZ: i am not sure what this means, so i might have broken it. it seems like that if "tonew" is ! set and the $arg cannot be expanded (or the dollarsym is in reality a A_DOLLAR). ! 0 is returned from binbuf_realizedollsym; this happens when expanding in a message-box, ! but does not happen when the A_DOLLSYM is the name of a subpatch */ /* JMZ: this should mimick the original behaviour */ ! if(!tonew && !next && !*buf) return 0; ! strncat(buf2, buf, MAXPDSTRING/2-1); str+=next; substr=strchr(str, '$'); if(substr) { ! strncat(buf2, str, (substr-str)); str=substr+1; } else { ! strcat(buf2, str); ! return gensym(buf2); } } ! return gensym(buf2); }
--- 1936,1963 ---- char *substr=strchr(str, '$'); if(!substr || substr-str >= MAXPDSTRING) return s; ! oprintf(buf2,"%.*s",substr-str,str); str=substr+1; ! for (;;) { ! std::ostringstream buf; ! next=binbuf_expanddollsym(str, buf, dollarnull, ac, av, tonew); ! if (next<0) break; /* JMZ: i am not sure what this means, so i might have broken it. it seems like that if "tonew" is ! set and the $arg cannot be expanded (or the dollarsym is in reality a A_DOLLAR). ! 0 is returned from binbuf_realizedollsym; this happens when expanding in a message-box, ! but does not happen when the A_DOLLSYM is the name of a subpatch */ /* JMZ: this should mimick the original behaviour */ ! if(!tonew && !next && buf.str().size()==0) return 0; ! buf2 << buf; str+=next; substr=strchr(str, '$'); if(substr) { ! oprintf(buf2,"%.*s",substr-str,str); str=substr+1; } else { ! buf2 << str; ! return gensym(buf2.str().data()); } } ! return gensym(buf2.str().data()); }
Index: desire.h =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/desire.h,v retrieving revision 1.1.2.49.2.31 retrieving revision 1.1.2.49.2.32 diff -C2 -d -r1.1.2.49.2.31 -r1.1.2.49.2.32 *** desire.h 15 Jul 2007 05:37:09 -0000 1.1.2.49.2.31 --- desire.h 18 Jul 2007 20:23:15 -0000 1.1.2.49.2.32 *************** *** 325,331 **** --- 325,333 ----
#ifdef PD_PLUSPLUS_FACE + #include<iostream> template <class T> static T min(T a, T b) {return a<b?a:b;} template <class T> static T max(T a, T b) {return a>b?a:b;} template <class T> T clip(T a, T b, T c) {return min(max(a,b),c);} + void oprintf(std::ostream &buf, const char *s, ...); #endif