Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21352
Modified Files: Tag: desiredata m_binbuf.c Log Message: reformatting and removing GG_ESCAPE_HACK
Index: m_binbuf.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_binbuf.c,v retrieving revision 1.4.4.1.2.8.2.6 retrieving revision 1.4.4.1.2.8.2.7 diff -C2 -d -r1.4.4.1.2.8.2.6 -r1.4.4.1.2.8.2.7 *** m_binbuf.c 20 Dec 2006 05:03:54 -0000 1.4.4.1.2.8.2.6 --- m_binbuf.c 20 Dec 2006 08:27:17 -0000 1.4.4.1.2.8.2.7 *************** *** 68,162 **** int nalloc = 16, natom = 0;
- #ifdef GG_ESCAPE_HACK - int escape = 0; /* GG: escape mechanism */ - #endif - t_freebytes(x->b_vec, x->b_n * sizeof(*x->b_vec)); x->b_vec = (t_atom *)t_getbytes(nalloc * sizeof(*x->b_vec)); ap = x->b_vec; x->b_n = 0; ! while (1) ! { ! int type; ! /* skip leading space */ ! while ((textp != etext) && (*textp == ' ' || *textp == '\n' ! || *textp == '\r' || *textp == '\t')) textp++; ! ! #ifdef GG_ESCAPE_HACK ! /* GG: escape mechanism */ ! if (*textp == '"') escape = !escape,textp++; ! while ((textp != etext) && !escape && (*textp == ' ' || *textp == '\n' || *textp == '\r' || *textp == '\t')) ! textp++; ! #endif if (textp == etext) break; if (*textp == ';') SETSEMI(ap), textp++; else if (*textp == ',') SETCOMMA(ap), textp++; ! else ! { ! /* it's an atom other than a comma or semi */ char c; ! int floatstate = 0, slash = 0, lastslash = 0, dollar = 0; bufp = buf; ! do ! { c = *bufp = *textp++; lastslash = slash; slash = (c == '\'); ! ! if (floatstate >= 0) ! { ! int digit = (c >= '0' && c <= '9'), ! dot = (c == '.'), minus = (c == '-'), ! plusminus = (minus || (c == '+')), ! expon = (c == 'e' || c == 'E'); ! if (floatstate == 0) /* beginning */ ! { ! if (minus) floatstate = 1; ! else if (digit) floatstate = 2; ! else if (dot) floatstate = 3; ! else floatstate = -1; ! } ! else if (floatstate == 1) /* got minus */ ! { ! if (digit) floatstate = 2; ! else if (dot) floatstate = 3; ! else floatstate = -1; ! } ! else if (floatstate == 2) /* got digits */ ! { ! if (dot) floatstate = 4; ! else if (expon) floatstate = 6; ! else if (!digit) floatstate = -1; ! } ! else if (floatstate == 3) /* got '.' without digits */ ! { ! if (digit) floatstate = 5; ! else floatstate = -1; ! } ! else if (floatstate == 4) /* got '.' after digits */ ! { ! if (digit) floatstate = 5; ! else if (expon) floatstate = 6; ! else floatstate = -1; ! } ! else if (floatstate == 5) /* got digits after . */ ! { ! if (expon) floatstate = 6; ! else if (!digit) floatstate = -1; ! } ! else if (floatstate == 6) /* got 'e' */ ! { ! if (plusminus) floatstate = 7; ! else if (digit) floatstate = 8; ! else floatstate = -1; ! } ! else if (floatstate == 7) /* got plus or minus */ ! { ! if (digit) floatstate = 8; ! else floatstate = -1; ! } ! else if (floatstate == 8) /* got digits */ ! { ! if (!digit) floatstate = -1; } } --- 68,111 ---- int nalloc = 16, natom = 0;
t_freebytes(x->b_vec, x->b_n * sizeof(*x->b_vec)); x->b_vec = (t_atom *)t_getbytes(nalloc * sizeof(*x->b_vec)); ap = x->b_vec; x->b_n = 0; ! while (1) { ! /* skip leading space */ ! while ((textp != etext) && (*textp == ' ' || *textp == '\n' || *textp == '\r' || *textp == '\t')) textp++; if (textp == etext) break; if (*textp == ';') SETSEMI(ap), textp++; else if (*textp == ',') SETCOMMA(ap), 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 = (c >= '0' && c <= '9'), dot = (c == '.'), minus = (c == '-'), ! plusminus = (minus || (c == '+')), expon = (c == 'e' || c == 'E'); ! if (q == 0) { /* beginning */ ! if (minus) q = 1; else if (digit) q = 2; else if (dot) q = 3; else q = -1; ! } else if (q == 1) { /* got minus */ ! if (digit) q = 2; else if (dot) q = 3; else q = -1; ! } else if (q == 2) { /* got digits */ ! if (dot) q = 4; else if (expon) q = 6; else if (!digit) q = -1; ! } else if (q == 3) { /* got '.' without digits */ ! if (digit) q = 5; else q = -1; ! } else if (q == 4) { /* got '.' after digits */ ! if (digit) q = 5; else if (expon) q = 6; else q = -1; ! } else if (q == 5) { /* got digits after . */ ! if (expon) q = 6; else if (!digit) q = -1; ! } else if (q == 6) { /* got 'e' */ ! if (plusminus) q = 7; else if (digit) q = 8; else q = -1; ! } else if (q == 7) { /* got plus or minus */ ! if (digit) q = 8; else q = -1; ! } else if (q == 8) { /* got digits */ ! if (!digit) q = -1; } } *************** *** 168,183 **** while (textp != etext && bufp != ebuf && (slash || (*textp != ' ' && *textp != '\n' && *textp != '\r' ! && *textp != '\t' &&*textp != ',' && *textp != ';' ! #ifdef GG_ESCAPE_HACK ! && *textp != '"') || (escape && (*textp != '"') /* GG: */ ! #endif ! ))); *bufp = 0; ! #if 0 ! post("binbuf_text: buf %s", buf); ! #endif ! if (floatstate == 2 || floatstate == 4 || floatstate == 5 || ! floatstate == 8) ! SETFLOAT(ap, atof(buf)); /* LATER try to figure out how to mix "$" and "$" correctly; here, the backslashes were already stripped so we assume all --- 117,123 ---- while (textp != etext && bufp != ebuf && (slash || (*textp != ' ' && *textp != '\n' && *textp != '\r' ! && *textp != '\t' &&*textp != ',' && *textp != ';'))); *bufp = 0; ! if (q == 2 || q == 4 || q == 5 || q == 8) SETFLOAT(ap, atof(buf)); /* LATER try to figure out how to mix "$" and "$" correctly; here, the backslashes were already stripped so we assume all *************** *** 310,346 **** symbols ";", "'",; the symbol ";" goes to ";", etc. */
! void binbuf_addbinbuf(t_binbuf *x, t_binbuf *y) ! { t_binbuf *z = binbuf_new(); int i; t_atom *ap; binbuf_add(z, y->b_n, y->b_vec); ! for (i = 0, ap = z->b_vec; i < z->b_n; i++, ap++) ! { char tbuf[MAXPDSTRING]; ! switch (ap->a_type) ! { ! case A_FLOAT: ! break; ! case A_SEMI: ! SETSYMBOL(ap, gensym(";")); ! break; ! case A_COMMA: ! SETSYMBOL(ap, gensym(",")); ! break; ! case A_DOLLAR: ! sprintf(tbuf, "$%d", ap->a_w.w_index); ! SETSYMBOL(ap, gensym(tbuf)); ! break; ! case A_DOLLSYM: ! atom_string(ap, tbuf, MAXPDSTRING); ! SETSYMBOL(ap, gensym(tbuf)); ! break; case A_SYMBOL: ! /* FIXME make this general */ ! if (!strcmp(ap->a_w.w_symbol->s_name, ";")) ! SETSYMBOL(ap, gensym(";")); ! else if (!strcmp(ap->a_w.w_symbol->s_name, ",")) ! SETSYMBOL(ap, gensym(",")); break; default: --- 250,270 ---- symbols ";", "'",; the symbol ";" goes to ";", etc. */
! void binbuf_addbinbuf(t_binbuf *x, t_binbuf *y) { t_binbuf *z = binbuf_new(); int i; t_atom *ap; binbuf_add(z, y->b_n, y->b_vec); ! for (i = 0, ap = z->b_vec; i < z->b_n; i++, ap++) { char tbuf[MAXPDSTRING]; ! switch (ap->a_type) { ! case A_FLOAT: break; ! case A_SEMI: SETSYMBOL(ap, gensym(";")); break; ! case A_COMMA: SETSYMBOL(ap, gensym(",")); break; ! case A_DOLLAR: sprintf(tbuf, "$%d", ap->a_w.w_index); SETSYMBOL(ap, gensym(tbuf)); break; ! case A_DOLLSYM: atom_string(ap, tbuf, MAXPDSTRING); SETSYMBOL(ap, gensym(tbuf)); break; case A_SYMBOL: ! /* FIXME make this general */ ! if (!strcmp(ap->a_w.w_symbol->s_name, ";")) SETSYMBOL(ap, gensym(";")); ! else if (!strcmp(ap->a_w.w_symbol->s_name, ",")) SETSYMBOL(ap, gensym(",")); break; default: *************** *** 348,357 **** } } - binbuf_add(x, z->b_n, z->b_vec); }
! void binbuf_addsemi(t_binbuf *x) ! { t_atom a; SETSEMI(&a); --- 272,279 ---- } } binbuf_add(x, z->b_n, z->b_vec); }
! void binbuf_addsemi(t_binbuf *x) { t_atom a; SETSEMI(&a); *************** *** 382,387 **** if (!strcmp(str, ";")) SETSEMI(ap); else if (!strcmp(str, ",")) SETCOMMA(ap); ! else if ((str2 = strchr(str, '$')) && str2[1] >= '0' ! && str2[1] <= '9') { int dollsym = 0; --- 304,308 ---- if (!strcmp(str, ";")) SETSEMI(ap); else if (!strcmp(str, ",")) SETCOMMA(ap); ! else if ((str2 = strchr(str, '$')) && str2[1] >= '0' && str2[1] <= '9') { int dollsym = 0; *************** *** 433,447 **** }
! int binbuf_getnatom(t_binbuf *x) ! { ! return (x->b_n); ! } ! ! t_atom *binbuf_getvec(t_binbuf *x) ! { ! return (x->b_vec); ! }
! int canvas_getdollarzero( void);
/* JMZ: --- 354,361 ---- }
! int binbuf_getnatom(t_binbuf *x) {return x->b_n;} ! t_atom *binbuf_getvec(t_binbuf *x) {return x->b_vec;}
! int canvas_getdollarzero(void);
/* JMZ: *************** *** 548,553 **** extern t_hash *object_table;
! void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv) ! { static t_atom mstack[MSTACKSIZE], *msp = mstack, *ems = mstack+MSTACKSIZE; t_atom *stackwas = msp; --- 462,466 ---- extern t_hash *object_table;
! void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv) { static t_atom mstack[MSTACKSIZE], *msp = mstack, *ems = mstack+MSTACKSIZE; t_atom *stackwas = msp; *************** *** 555,591 **** int ac = x->b_n; int nargs; ! while (1) ! { t_pd *nexttarget; ! /* get a target. */ ! while (!target) ! { t_symbol *s; ! while (ac && (at->a_type == A_SEMI || at->a_type == A_COMMA)) ! ac--, at++; if (!ac) break; ! if (at->a_type == A_DOLLAR) ! { ! if (at->a_w.w_index <= 0 || at->a_w.w_index > argc) ! { ! error("$%d: not enough arguments supplied", ! at->a_w.w_index); goto cleanup; ! } ! else if (argv[at->a_w.w_index-1].a_type != A_SYMBOL) ! { ! error("$%d: symbol needed as message destination", ! at->a_w.w_index); goto cleanup; ! } ! else s = argv[at->a_w.w_index-1].a_w.w_symbol; ! } ! else if (at->a_type == A_DOLLSYM) ! { ! if (!(s = binbuf_realizedollsym(at->a_w.w_symbol, ! argc, argv, 0))) ! { ! error("$%s: not enough arguments supplied", ! at->a_w.w_symbol->s_name); goto cleanup; } --- 468,488 ---- int ac = x->b_n; int nargs; ! while (1) { t_pd *nexttarget; ! while (!target) { t_symbol *s; ! while (ac && (at->a_type == A_SEMI || at->a_type == A_COMMA)) {ac--; at++;} if (!ac) break; ! if (at->a_type == A_DOLLAR) { ! if (at->a_w.w_index <= 0 || at->a_w.w_index > argc) { ! error("$%d: not enough arguments supplied", at->a_w.w_index); goto cleanup; ! } else if (argv[at->a_w.w_index-1].a_type != A_SYMBOL) { ! error("$%d: symbol needed as message destination", at->a_w.w_index); goto cleanup; ! } else s = argv[at->a_w.w_index-1].a_w.w_symbol; ! } else if (at->a_type == A_DOLLSYM) { ! if (!(s = binbuf_realizedollsym(at->a_w.w_symbol, argc, argv, 0))) { ! error("$%s: not enough arguments supplied", at->a_w.w_symbol->s_name); goto cleanup; } *************** *** 603,608 **** } } ! if (!target) ! { error("%s: no such object", s->s_name); cleanup: --- 500,504 ---- } } ! if (!target) { error("%s: no such object", s->s_name); cleanup: *************** *** 611,617 **** /* LATER eat args until semicolon and continue */ continue; ! } ! else ! { at++, ac--; break; --- 507,511 ---- /* LATER eat args until semicolon and continue */ continue; ! } else { at++, ac--; break; *************** *** 621,654 **** nargs = 0; nexttarget = target; ! while (1) ! { t_symbol *s9; if (!ac) goto gotmess; ! if (msp >= ems) ! { ! error("message stack overflow"); ! goto broken; ! } ! switch (at->a_type) ! { case A_SEMI: ! /* semis and commas in new message just get bashed to ! a symbol. This is needed so you can pass them to "expr." */ ! if (target == &pd_objectmaker) ! { ! SETSYMBOL(msp, gensym(";")); ! break; ! } ! else ! { ! nexttarget = 0; ! goto gotmess; ! } case A_COMMA: ! if (target == &pd_objectmaker) ! { ! SETSYMBOL(msp, gensym(",")); ! break; ! } else goto gotmess; case A_FLOAT: --- 515,530 ---- nargs = 0; nexttarget = target; ! while (1) { t_symbol *s9; if (!ac) goto gotmess; ! if (msp >= ems) {error("message stack overflow"); goto broken;} ! switch (at->a_type) { case A_SEMI: ! /* semis and commas in new message just get bashed to ! a symbol. This is needed so you can pass them to "expr." */ ! if (target == &pd_objectmaker) {SETSYMBOL(msp, gensym(";")); break;} ! else {nexttarget = 0; goto gotmess;} case A_COMMA: ! if (target == &pd_objectmaker) {SETSYMBOL(msp, gensym(",")); break;} else goto gotmess; case A_FLOAT: *************** *** 661,672 **** else if (at->a_w.w_index == 0) SETFLOAT(msp, canvas_getdollarzero()); ! else ! { ! if (target == &pd_objectmaker) ! SETFLOAT(msp, 0); ! else ! { ! error("$%d: argument number out of range", ! at->a_w.w_index); SETFLOAT(msp, 0); } --- 537,544 ---- else if (at->a_w.w_index == 0) SETFLOAT(msp, canvas_getdollarzero()); ! else { ! if (target == &pd_objectmaker) SETFLOAT(msp, 0); ! else { ! error("$%d: argument number out of range", at->a_w.w_index); SETFLOAT(msp, 0); } *************** *** 674,681 **** break; case A_DOLLSYM: ! s9 = binbuf_realizedollsym(at->a_w.w_symbol, argc, argv, ! target == &pd_objectmaker); ! if (!s9) ! { error("%s: argument number out of range", at->a_w.w_symbol->s_name); SETSYMBOL(msp, at->a_w.w_symbol); --- 546,551 ---- break; case A_DOLLSYM: ! s9 = binbuf_realizedollsym(at->a_w.w_symbol, argc, argv, target == &pd_objectmaker); ! if (!s9) { error("%s: argument number out of range", at->a_w.w_symbol->s_name); SETSYMBOL(msp, at->a_w.w_symbol); *************** *** 693,700 **** } gotmess: ! if (nargs) ! { ! switch (stackwas->a_type) ! { case A_SYMBOL: typedmess(target, stackwas->a_w.w_symbol, nargs-1, stackwas+1); --- 563,568 ---- } gotmess: ! if (nargs) { ! switch (stackwas->a_type) { case A_SYMBOL: typedmess(target, stackwas->a_w.w_symbol, nargs-1, stackwas+1); *************** *** 735,740 **** }
! int binbuf_read(t_binbuf *b, char *filename, char *dirname, int crflag) ! { long length; int fd; --- 603,607 ---- }
! int binbuf_read(t_binbuf *b, char *filename, char *dirname, int crflag) { long length; int fd; *************** *** 742,790 **** char *buf; char namebuf[MAXPDSTRING]; - namebuf[0] = 0; ! if (*dirname) ! strcat(namebuf, dirname), strcat(namebuf, "/"); strcat(namebuf, filename); ! ! if ((fd = binbuf_doopen(namebuf, 0)) < 0) ! { fprintf(stderr, "open: "); perror(namebuf); ! return (1); } if ((length = lseek(fd, 0, SEEK_END)) < 0 || lseek(fd, 0, SEEK_SET) < 0 ! || !(buf = (char *)t_getbytes(length))) ! { fprintf(stderr, "lseek: "); perror(namebuf); close(fd); ! return(1); } ! if ((readret = read(fd, buf, length)) < length) ! { fprintf(stderr, "read (%d %ld) -> %d\n", fd, length, readret); perror(namebuf); close(fd); t_freebytes(buf, length); ! return(1); } /* optionally map carriage return to semicolon */ ! if (crflag) ! { int i; ! for (i = 0; i < length; i++) ! if (buf[i] == '\n') ! buf[i] = ';'; } binbuf_text(b, buf, length); - - #if 0 - startpost("binbuf_read "); postatom(b->b_n, b->b_vec); endpost(); - #endif - t_freebytes(buf, length); close(fd); ! return (0); }
--- 609,643 ---- char *buf; char namebuf[MAXPDSTRING]; namebuf[0] = 0; ! if (*dirname) strcat(namebuf, dirname), strcat(namebuf, "/"); strcat(namebuf, filename); ! if ((fd = binbuf_doopen(namebuf, 0)) < 0) { fprintf(stderr, "open: "); perror(namebuf); ! return 1; } if ((length = lseek(fd, 0, SEEK_END)) < 0 || lseek(fd, 0, SEEK_SET) < 0 ! || !(buf = (char *)t_getbytes(length))) { fprintf(stderr, "lseek: "); perror(namebuf); close(fd); ! return 1; } ! if ((readret = read(fd, buf, length)) < length) { fprintf(stderr, "read (%d %ld) -> %d\n", fd, length, readret); perror(namebuf); close(fd); t_freebytes(buf, length); ! return 1; } /* optionally map carriage return to semicolon */ ! if (crflag) { int i; ! for (i = 0; i < length; i++) if (buf[i] == '\n') buf[i] = ';'; } binbuf_text(b, buf, length); t_freebytes(buf, length); close(fd); ! return 0; }