Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27478
Modified Files:
Tag: impd_0_37
m_pd.h m_binbuf.c
Log Message:
splitting binbuf_write in two (new binbuf_write2 works with a FILE*)
Index: m_pd.h
===================================================================
RCS file: /cvsroot/pure-data/pd/src/m_pd.h,v
retrieving revision 1.1.1.4.2.10.2.8
retrieving revision 1.1.1.4.2.10.2.9
diff -C2 -d -r1.1.1.4.2.10.2.8 -r1.1.1.4.2.10.2.9
*** m_pd.h 3 May 2004 19:49:34 -0000 1.1.1.4.2.10.2.8
--- m_pd.h 10 May 2004 16:04:15 -0000 1.1.1.4.2.10.2.9
***************
*** 9,14 ****
#endif
- #define MATJU1
-
#define PD_VERSION 0.37 /* oops, don't use this... */ */
#define PD_MAJOR_VERSION 0 /* ... use these two instead. */
--- 9,12 ----
***************
*** 29,32 ****
--- 27,32 ----
#endif
+ #include <stdio.h>
+
#if !defined(_SIZE_T) && !defined(_SIZE_T_)
#include <stddef.h> /* just for size_t -- how lame! */
***************
*** 277,282 ****
EXTERN int binbuf_read_via_path(t_binbuf *b, char *filename, char *dirname,
int crflag);
! EXTERN int binbuf_write(t_binbuf *x, char *filename, char *dir,
! int crflag);
EXTERN void binbuf_evalfile(t_symbol *name, t_symbol *dir);
EXTERN t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av,
--- 277,283 ----
EXTERN int binbuf_read_via_path(t_binbuf *b, char *filename, char *dirname,
int crflag);
! EXTERN int binbuf_write(t_binbuf *x, char *filename, char *dir, int crflag);
! EXTERN int binbuf_write2(t_binbuf *x, char *filename, FILE *f, int crflag,
! int is_pat);
EXTERN void binbuf_evalfile(t_symbol *name, t_symbol *dir);
EXTERN t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av,
Index: m_binbuf.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/m_binbuf.c,v
retrieving revision 1.1.1.4.2.4.2.3
retrieving revision 1.1.1.4.2.4.2.4
diff -C2 -d -r1.1.1.4.2.4.2.3 -r1.1.1.4.2.4.2.4
*** m_binbuf.c 3 May 2004 15:39:45 -0000 1.1.1.4.2.4.2.3
--- m_binbuf.c 10 May 2004 16:04:15 -0000 1.1.1.4.2.4.2.4
***************
*** 707,736 ****
static t_binbuf *binbuf_convert(t_binbuf *oldb, int maxtopd);
! /* write a binbuf to a text file. If "crflag" is set we suppress
! semicolons. */
int binbuf_write(t_binbuf *x, char *filename, char *dir, int crflag)
{
FILE *f = 0;
! char sbuf[WBUFSIZE], fbuf[MAXPDSTRING], *bp = sbuf, *ep = sbuf + WBUFSIZE;
! t_atom *ap;
! int indx, deleteit = 0;
! int ncolumn = 0;
!
! fbuf[0] = 0;
! if (*dir)
! strcat(fbuf, dir), strcat(fbuf, "/");
strcat(fbuf, filename);
! if (!strcmp(filename + strlen(filename) - 4, ".pat"))
! {
! x = binbuf_convert(x, 0);
! deleteit = 1;
! }
!
! if (!(f = binbuf_dofopen(fbuf, "w")))
! {
fprintf(stderr, "open: ");
sys_unixerror(fbuf);
! goto fail;
}
for (ap = x->b_vec, indx = x->b_n; indx--; ap++)
{
--- 707,736 ----
static t_binbuf *binbuf_convert(t_binbuf *oldb, int maxtopd);
! /* write a binbuf to a text file. If "crflag" is set we suppress
! semicolons. */
int binbuf_write(t_binbuf *x, char *filename, char *dir, int crflag)
{
+ char fbuf[MAXPDSTRING];
FILE *f = 0;
! int is_pat = !strcmp(filename+strlen(filename)-4, ".pat");
! if (*dir) sprintf(fbuf,"%s/",dir);
strcat(fbuf, filename);
! f=binbuf_dofopen(fbuf, "w");
! if (!f) {
fprintf(stderr, "open: ");
sys_unixerror(fbuf);
! return 1;
}
+ return binbuf_write2(x,fbuf,f,crflag,is_pat);
+ }
+
+ /* writes to f; the filename (fbuf) is only for error messages */
+ int binbuf_write2(t_binbuf *x, char *fbuf, FILE *f, int crflag, int is_pat)
+ {
+ char sbuf[WBUFSIZE], *bp = sbuf, *ep = sbuf + WBUFSIZE;
+ t_atom *ap;
+ int indx, deleteit = 0;
+ int ncolumn = 0;
+ if (is_pat) {x=binbuf_convert(x, 0); deleteit=1;}
for (ap = x->b_vec, indx = x->b_n; indx--; ap++)
{
***************
*** 743,751 ****
if (ep - bp < length)
{
! if (fwrite(sbuf, bp-sbuf, 1, f) < 1)
! {
! sys_unixerror(fbuf);
! goto fail;
! }
bp = sbuf;
}
--- 743,747 ----
if (ep - bp < length)
{
! if (fwrite(sbuf,bp-sbuf,1,f)<1) {sys_unixerror(fbuf); goto fail;}
bp = sbuf;
}
***************
*** 770,788 ****
}
}
! if (fwrite(sbuf, bp-sbuf, 1, f) < 1)
! {
! sys_unixerror(fbuf);
! goto fail;
! }
! if (deleteit)
! binbuf_free(x);
fclose(f);
! return (0);
fail:
! if (deleteit)
! binbuf_free(x);
! if (f)
! fclose(f);
! return (1);
}
--- 766,777 ----
}
}
! if (fwrite(sbuf,bp-sbuf,1,f)<1) {sys_unixerror(fbuf); goto fail;}
! if (deleteit) binbuf_free(x);
fclose(f);
! return 0;
fail:
! if (deleteit) binbuf_free(x);
! if (f) fclose(f);
! return 1;
}