[PD-cvs] externals/miXed/shared/common binport.c,1.3,1.4 binport.h,1.2,1.3 loud.c,1.2,1.3 loud.h,1.2,1.3 port.c,1.8,1.9

Krzysztof Czaja krzyszcz at users.sourceforge.net
Sat Apr 17 19:45:30 CEST 2004


Update of /cvsroot/pure-data/externals/miXed/shared/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14365/shared/common

Modified Files:
	binport.c binport.h loud.c loud.h port.c 
Log Message:
importing ints

Index: port.c
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/shared/common/port.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** port.c	7 Apr 2004 19:57:12 -0000	1.8
--- port.c	17 Apr 2004 17:45:28 -0000	1.9
***************
*** 28,31 ****
--- 28,32 ----
  //#define PORT_DEBUG
  #define PORT_LOG
+ #define PORT_DUMP  /* fill separate files with ignored data, e.g. pictures */
  
  #define PORT_INISTACK  256  /* LATER rethink */
***************
*** 52,57 ****
  typedef struct _port
  {
[...1180 lines suppressed...]
! 	}		
! 	binbuf_free(inbb);
  #ifdef PORT_LOG
! 	if (outbb) binbuf_write(outbb, "import-result.pd", "", 0);
  #endif
!     }
!     else if (ftype == BINPORT_PDFILE)
! 	outbb = inbb;
!     else
!     {
!     	perror(fn);  /* FIXME */
! 	binbuf_free(inbb);
! 	outbb = 0;
!     }
!     if (outbb)
!     {
! 	binbuf_eval(outbb, 0, 0, 0);
! 	binbuf_free(outbb);
      }
      port_free(x);

Index: loud.h
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/shared/common/loud.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** loud.h	11 Sep 2003 09:04:32 -0000	1.2
--- loud.h	17 Apr 2004 17:45:28 -0000	1.3
***************
*** 22,26 ****
  int loud_checkint(t_pd *x, t_float f, int *valuep, t_symbol *mess);
  void loud_classarg(t_class *c);
! void loud_warning(t_pd *x, char *fmt, ...);
  void loud_notimplemented(t_pd *x, char *name);
  void loud_incompatible(t_class *c, char *fmt, ...);
--- 22,26 ----
  int loud_checkint(t_pd *x, t_float f, int *valuep, t_symbol *mess);
  void loud_classarg(t_class *c);
! void loud_warning(t_pd *x, char *who, char *fmt, ...);
  void loud_notimplemented(t_pd *x, char *name);
  void loud_incompatible(t_class *c, char *fmt, ...);

Index: binport.h
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/shared/common/binport.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** binport.h	7 Apr 2004 19:57:12 -0000	1.2
--- binport.h	17 Apr 2004 17:45:28 -0000	1.3
***************
*** 11,14 ****
--- 11,15 ----
  #ifndef BINPORT_STANDALONE
  int binport_read(t_binbuf *bb, char *filename, char *dirname);
+ void binport_write(t_binbuf *bb, char *filename, char *dirname);
  #endif
  

Index: binport.c
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/shared/common/binport.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** binport.c	7 Apr 2004 19:57:12 -0000	1.3
--- binport.c	17 Apr 2004 17:45:28 -0000	1.4
***************
*** 11,16 ****
  #include <math.h>
  
! #define BINPORT_MAXSTRING  256
! #define BINPORT_SYMGROW     64
  
  #ifndef BINPORT_STANDALONE
--- 11,16 ----
  #include <math.h>
  
! #define BINPORT_MAXSTRING  1000
! #define BINPORT_SYMGROW      64
  
  #ifndef BINPORT_STANDALONE
***************
*** 439,442 ****
--- 439,452 ----
  }
  
+ static int binpold_nextatom(t_binpold *old, t_atom *ap)
+ {
+     if (old->o_ndx < old->o_natoms)
+     {
+ 	*ap = old->o_atombuf[old->o_ndx++];
+ 	return (1);
+     }
+     else return (0);
+ }
+ 
  static void binpold_free(t_binpold *old)
  {
***************
*** 485,488 ****
--- 495,499 ----
  {
      FILE       *b_fp;
+     int         b_ftype;
      int         b_nsymbols;
      int         b_symsize;
***************
*** 503,506 ****
--- 514,523 ----
  }
  
+ static void binport_setsymbol(t_atom *ap, t_symbol *s)
+ {
+     ap->a_type = A_SYMBOL;
+     ap->a_w.w_symbol = s;
+ }
+ 
  static t_symbol *binport_makesymbol(t_binport *bp, int id)
  {
***************
*** 535,549 ****
  }
  
! static t_symbol *binport_getsymbol(t_binport *bp, int id)
  {
      if (id < bp->b_nsymbols)
! 	return (bp->b_symtable[id]);
      else
! 	return (binport_makesymbol(bp, id));
! }
! 
! static int binport_setsymbol(t_binport *bp, t_atom *ap, int id)
! {
!     t_symbol *s = binport_getsymbol(bp, id);
      if (s)
      {
--- 552,562 ----
  }
  
! static int binport_setbysymtable(t_binport *bp, t_atom *ap, int id)
  {
+     t_symbol *s;
      if (id < bp->b_nsymbols)
! 	s = bp->b_symtable[id];
      else
! 	s = binport_makesymbol(bp, id);
      if (s)
      {
***************
*** 554,574 ****
  }
  
! static int binport_nextatom(t_binport *bp, t_atom *ap)
  {
!     unsigned char opcode;
!     int opval;
!     char buf[64];
!     t_binpold *old = bp->b_old;
!     if (old)
      {
! 	if (old->o_ndx < old->o_natoms)
  	{
! 	    *ap = old->o_atombuf[old->o_ndx++];
! 	    return (1);
  	}
! 	else return (0);
      }
      if (!binport_readbyte(bp->b_fp, &opcode))
! 	goto bad;
      opval = opcode & 0x0f;
      switch (opcode >> 4)
--- 567,703 ----
  }
  
! /* single pass of binbuf_text(), int-preserving version */
! static int maxtext_nextatom(FILE *fp, t_atom *ap)
  {
!     char buf[BINPORT_MAXSTRING + 1], *bufp, *ebuf = buf + BINPORT_MAXSTRING;
!     int ready;
!     unsigned char ch;
!     ap->a_type = A_NULL;
!     while ((ready = binport_readbyte(fp, &ch)) &&
! 	   (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'));
!     if (!ready)
! 	return (0);
!     if (ch == ';')
! 	ap->a_type = A_SEMI;
!     else if (ch == ',')
! 	ap->a_type = A_COMMA;
!     else
      {
! 	int floatstate = 0, slash = 0, lastslash = 0, firstslash = (ch == '\\');
! 	bufp = buf;
! 	do
  	{
! 	    *bufp = ch;
! 	    lastslash = slash;
! 	    slash = (ch == '\\');
! 
! 	    if (floatstate >= 0)
! 	    {
! 		int digit = (ch >= '0' && ch <= '9'),
! 		    dot = (ch == '.'), minus = (ch == '-'),
! 		    plusminus = (minus || (ch == '+')),
! 		    expon = (ch == 'e' || ch == '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;
! 		}
! 	    }
! 	    if (!slash) bufp++;
  	}
! 	while ((ready = binport_readbyte(fp, &ch)) && bufp != ebuf
! 	       && (slash || (ch != ' ' && ch != '\n' && ch != '\r'
! 			     && ch != '\t' && ch != ',' && ch != ';')));
! 	if (ready && (ch == ',' || ch == ';'))
! 	    ungetc(ch, fp);
! 	*bufp = 0;
! #if 0
! 	fprintf(stderr, "buf %s\n", buf);
! #endif
! 	if (*buf == '$' && buf[1] >= '0' && buf[1] <= '9' && !firstslash)
! 	{
! 	    for (bufp = buf+2; *bufp; bufp++)
! 	    {
! 		if (*bufp < '0' || *bufp > '9')
! 		{
! 		    ap->a_type = A_DOLLSYM;
! 		    ap->a_w.w_symbol = gensym(buf+1);
! 		    break;
! 		}
! 	    }
! 	    if (ap->a_type == A_NULL)
! 	    {
! 		ap->a_type = A_DOLLAR;
! 		ap->a_w.w_index = atoi(buf+1);
! 	    }
! 	}
! 	else if (floatstate == 2)
! 	    binport_setint(ap, atoi(buf));
! 	else if (floatstate == 4 || floatstate == 5 || floatstate == 8)
! 	    binport_setfloat(ap, atof(buf));
! 	else
! 	    binport_setsymbol(ap, gensym(buf));
      }
+     return (1);
+ }
+ 
+ static int binport_nextatom(t_binport *bp, t_atom *ap)
+ {
+     unsigned char opcode;
+     int opval;
+     char buf[64];
+ 
+     if (bp->b_ftype == BINPORT_MAXTEXT)
+ 	return (maxtext_nextatom(bp->b_fp, ap));
+     else if (bp->b_ftype == BINPORT_MAXOLD && bp->b_old)
+ 	return (binpold_nextatom(bp->b_old, ap));
+ 
      if (!binport_readbyte(bp->b_fp, &opcode))
! 	goto badbin;
      opval = opcode & 0x0f;
      switch (opcode >> 4)
***************
*** 577,581 ****
  			      opval: length (number of bytes that follow) */
  	if (!binport_readbuf(bp->b_fp, buf, opval))
! 	    goto bad;
  	else
  	{
--- 706,710 ----
  			      opval: length (number of bytes that follow) */
  	if (!binport_readbuf(bp->b_fp, buf, opval))
! 	    goto badbin;
  	else
  	{
***************
*** 591,595 ****
  				opval: length (number of bytes that follow) */
  	if (!binport_readbuf(bp->b_fp, buf, opval))
! 	    goto bad;
  	else
  	{
--- 720,724 ----
  				opval: length (number of bytes that follow) */
  	if (!binport_readbuf(bp->b_fp, buf, opval))
! 	    goto badbin;
  	else
  	{
***************
*** 603,607 ****
  			      opval: length (number of bytes that follow) */
  	if (!binport_readbuf(bp->b_fp, buf, opval))
! 	    goto bad;
  	else
  	{
--- 732,736 ----
  			      opval: length (number of bytes that follow) */
  	if (!binport_readbuf(bp->b_fp, buf, opval))
! 	    goto badbin;
  	else
  	{
***************
*** 609,614 ****
  	    int i = 0;
  	    while (opval--) i = (i << 8) | *--p;
! 	    if (!binport_setsymbol(bp, ap, i))
! 		goto bad;
  	}
  	break;
--- 738,743 ----
  	    int i = 0;
  	    while (opval--) i = (i << 8) | *--p;
! 	    if (!binport_setbysymtable(bp, ap, i))
! 		goto badbin;
  	}
  	break;
***************
*** 617,622 ****
  	break;
      case BINPORT_DEFSYMTYPE:  /* half-byte symbol id */
! 	if (!binport_setsymbol(bp, ap, opval))
! 	    goto bad;
  	break;
      case BINPORT_SEMITYPE:
--- 746,751 ----
  	break;
      case BINPORT_DEFSYMTYPE:  /* half-byte symbol id */
! 	if (!binport_setbysymtable(bp, ap, opval))
! 	    goto badbin;
  	break;
      case BINPORT_SEMITYPE:
***************
*** 638,642 ****
  				  opval: length (number of bytes that follow) */
  	if (!binport_readbuf(bp->b_fp, buf, opval))
! 	    goto bad;
  	else
  	{
--- 767,771 ----
  				  opval: length (number of bytes that follow) */
  	if (!binport_readbuf(bp->b_fp, buf, opval))
! 	    goto badbin;
  	else
  	{
***************
*** 644,649 ****
  	    int i = 0;
  	    while (opval--) i = (i << 8) | *--p;
! 	    if (!binport_setsymbol(bp, ap, i))
! 		goto bad;
  	}
  	sprintf(buf, "#%s", ap->a_w.w_symbol->s_name);
--- 773,778 ----
  	    int i = 0;
  	    while (opval--) i = (i << 8) | *--p;
! 	    if (!binport_setbysymtable(bp, ap, i))
! 		goto badbin;
  	}
  	sprintf(buf, "#%s", ap->a_w.w_symbol->s_name);
***************
*** 655,675 ****
      default:
  	binport_error("unknown opcode %x", (int)opcode);
! 	goto bad;
      }
      return (1);
! bad:
      return (0);
  }
  
! static int binport_binalike(char *header)
! {
!     static char binport_header[4] = { 2, 0, 0, 0 };  /* CHECKME any others? */
!     return (memcmp(header, binport_header, 4) == 0);
! }
! 
! static int binport_oldalike(char *header)
  {
!     static char binpold_header[4] = { 0, 0, 0, 1 };  /* CHECKME any others? */
!     return (memcmp(header, binpold_header, 4) == 0);
  }
  
--- 784,815 ----
      default:
  	binport_error("unknown opcode %x", (int)opcode);
! 	goto badbin;
      }
      return (1);
! badbin:
      return (0);
  }
  
! static int binport_alike(char *header, int *ftypep)
  {
!     static char bin_header[4] = { 2, 0, 0, 0 };  /* CHECKME any others? */
!     static char old_header[4] = { 0, 0, 0, 1 };  /* CHECKME any others? */
!     static char text_header[4] = { 'm', 'a', 'x', ' ' };
!     static char pd_header[3] = { '#', 'N', ' ' };  /* canvas or struct */
!     if (memcmp(header, bin_header, 4) == 0)
! 	*ftypep = BINPORT_OK;
!     else if (memcmp(header, text_header, 4) == 0)
! 	*ftypep = BINPORT_MAXTEXT;
!     else if (memcmp(header, old_header, 4) == 0)
! 	*ftypep = BINPORT_MAXOLD;
!     else
!     {
! 	if (memcmp(header, pd_header, 3) == 0)
! 	    *ftypep = BINPORT_PDFILE;
! 	else
! 	    *ftypep = BINPORT_INVALID;
! 	return (0);
!     }
!     return (1);
  }
  
***************
*** 689,794 ****
  static t_binport *binport_new(FILE *fp, int *ftypep)
  {
      char header[4];
-     *ftypep = BINPORT_INVALID;
      if (fread(header, 1, 4, fp) == 4)
      {
! 	if (binport_binalike(header))
! 	{
! 	    t_binport *bp = getbytes(sizeof(*bp));
! 	    bp->b_fp = fp;
! 	    bp->b_nsymbols = 0;
! 	    bp->b_symsize = BINPORT_SYMGROW;
! 	    bp->b_symtable = getbytes(bp->b_symsize * sizeof(*bp->b_symtable));
! 	    bp->b_old = 0;
! 	    *ftypep = BINPORT_OK;
! 	    return (bp);
! 	}
! 	else if (memcmp(header, "max", 3) == 0)
! 	    *ftypep = BINPORT_MAXTEXT;
! 	else if (binport_oldalike(header))
  	{
! 	    t_binport *bp = getbytes(sizeof(*bp));
  	    bp->b_fp = fp;
  	    bp->b_nsymbols = 0;
! 	    bp->b_symsize = 0;
! 	    bp->b_symtable = 0;
  	    bp->b_old = 0;
- 	    *ftypep = BINPORT_MAXOLD;
- 	    return (bp);
- 	}
- 	else
- 	{
- 	    if (header[0] == '#')  /* LATER rethink */
- 		*ftypep = BINPORT_PDFILE;
- 	    else binport_warning("unknown header: %x %x %x %x",
- 				 (int)header[0], (int)header[1],
- 				 (int)header[2], (int)header[3]);
  	}
      }
!     else binport_warning("file too short");
!     fclose(fp);
!     return (0);
! }
! 
! #ifndef BINPORT_STANDALONE
! 
! static int binport_tobinbuf(t_binport *bp, t_binbuf *bb)
! {
!     t_atom at;
!     if (bp->b_old)
! 	bp->b_old->o_ndx = 0;
!     while (binport_nextatom(bp, &at))
! 	if (at.a_type != A_NULL)
! 	    binbuf_add(bb, 1, &at);
!     return (1);
! }
! 
! /* LATER deal with corrupt binary files? */
! int binport_read(t_binbuf *bb, char *filename, char *dirname)
! {
!     FILE *fp;
!     char namebuf[MAXPDSTRING];
!     namebuf[0] = 0;
!     if (*dirname)
!     	strcat(namebuf, dirname), strcat(namebuf, "/");
!     strcat(namebuf, filename);
!     sys_bashfilename(namebuf, namebuf);
!     if (fp = fopen(namebuf, "rb"))
      {
! 	int ftype;
! 	t_binport *bp = binport_new(fp, &ftype);
! 	if (bp)
! 	{
! 	    int result;
! 	    if (ftype == BINPORT_OK)
! 		result = (binport_tobinbuf(bp, bb)
! 			  ? BINPORT_OK : BINPORT_CORRUPT);
! 	    else if (ftype == BINPORT_MAXOLD)
! 	    {
! 		t_binpold *old = binpold_new(fp);
! 		result = BINPORT_FAILED;
! 		if (old)
! 		{
! 		    bp->b_old = old;
! 		    if (binpold_load(old) && binport_tobinbuf(bp, bb))
! 			result = BINPORT_OK;
! 		}
! 		else binpold_failure(filename);
! 	    }
! 	    else result = BINPORT_FAILED;
! 	    binport_free(bp);
! 	    return (result);
! 	}
! 	else if (ftype == BINPORT_MAXTEXT || ftype == BINPORT_PDFILE)
! 	    return (ftype);
! 	else
! 	    binport_failure(filename);
      }
!     else binport_bug("cannot open file");
!     return (BINPORT_INVALID);
  }
  
- #else
- 
  static void binport_atomstring(t_atom *ap, char *buf, int bufsize)
  {
--- 829,870 ----
  static t_binport *binport_new(FILE *fp, int *ftypep)
  {
+     t_binport *bp = 0;
      char header[4];
      if (fread(header, 1, 4, fp) == 4)
      {
! 	int alike = binport_alike(header, ftypep);
! 	if (alike)
  	{
! 	    bp = getbytes(sizeof(*bp));
  	    bp->b_fp = fp;
+ 	    bp->b_ftype = *ftypep;
  	    bp->b_nsymbols = 0;
! 	    if (*ftypep == BINPORT_OK)
! 	    {
! 		bp->b_symsize = BINPORT_SYMGROW;
! 		bp->b_symtable =
! 		    getbytes(bp->b_symsize * sizeof(*bp->b_symtable));
! 	    }
! 	    else
! 	    {
! 		bp->b_symsize = 0;
! 		bp->b_symtable = 0;
! 	    }
  	    bp->b_old = 0;
  	}
+ 	else if (*ftypep != BINPORT_PDFILE)
+ 	    binport_warning("unknown header: %02x%02x%02x%02x",
+ 			    (int)header[0], (int)header[1],
+ 			    (int)header[2], (int)header[3]);
      }
!     else
      {
! 	binport_warning("file too short");
! 	*ftypep = BINPORT_INVALID;
      }
!     if (!bp) fclose(fp);
!     return (bp);
  }
  
  static void binport_atomstring(t_atom *ap, char *buf, int bufsize)
  {
***************
*** 837,845 ****
  }
  
! static void binport_print(t_binport *bp)
  {
      char buf[BINPORT_MAXSTRING];
      t_atom at;
!     int ac = 0;
      if (bp->b_old)
  	bp->b_old->o_ndx = 0;
--- 913,921 ----
  }
  
! static void binport_print(t_binport *bp, FILE *fp)
  {
      char buf[BINPORT_MAXSTRING];
      t_atom at;
!     int cnt = 0;
      if (bp->b_old)
  	bp->b_old->o_ndx = 0;
***************
*** 848,863 ****
  	if (at.a_type == A_SEMI)
  	{
! 	    fputs(";\n", stdout);
! 	    ac = 0;
  	}
  	else if (at.a_type != A_NULL)
  	{
! 	    if (ac++) fputc(' ', stdout);
  	    binport_atomstring(&at, buf, BINPORT_MAXSTRING);
! 	    fputs(buf, stdout);
  	}
      }
  }
  
  int main(int ac, char **av)
  {
--- 924,1051 ----
  	if (at.a_type == A_SEMI)
  	{
! 	    fputs(";\n", fp);
! 	    cnt = 0;
  	}
  	else if (at.a_type != A_NULL)
  	{
! 	    if (cnt++) fputc(' ', fp);
  	    binport_atomstring(&at, buf, BINPORT_MAXSTRING);
! 	    fputs(buf, fp);
  	}
      }
  }
  
+ #ifndef BINPORT_STANDALONE
+ 
+ static int binport_tobinbuf(t_binport *bp, t_binbuf *bb)
+ {
+     t_atom at;
+     if (bp->b_old)
+ 	bp->b_old->o_ndx = 0;
+     while (binport_nextatom(bp, &at))
+ 	if (at.a_type != A_NULL)
+ 	    binbuf_add(bb, 1, &at);
+     return (1);
+ }
+ 
+ /* LATER deal with corrupt binary files? */
+ int binport_read(t_binbuf *bb, char *filename, char *dirname)
+ {
+     int result;
+     FILE *fp;
+     char namebuf[MAXPDSTRING];
+     namebuf[0] = 0;
+     if (*dirname)
+     	strcat(namebuf, dirname), strcat(namebuf, "/");
+     strcat(namebuf, filename);
+     sys_bashfilename(namebuf, namebuf);
+     if (fp = fopen(namebuf, "rb"))
+     {
+ 	int ftype;
+ 	t_binport *bp = binport_new(fp, &ftype);
+ 	if (bp)
+ 	{
+ 	    if (ftype == BINPORT_OK)
+ 		result = (binport_tobinbuf(bp, bb)
+ 			  ? BINPORT_OK : BINPORT_CORRUPT);
+ 	    else if (ftype == BINPORT_MAXTEXT)
+ 	    {
+ 		t_atom at;
+ 		while (binport_nextatom(bp, &at))
+ 		    if (at.a_type == A_SEMI)
+ 			break;
+ 		binbuf_addv(bb, "ss;", gensym("max"), gensym("v2"));
+ 		result = (binport_tobinbuf(bp, bb)
+ 			  ? BINPORT_OK : BINPORT_CORRUPT);
+ 	    }
+ 	    else if (ftype == BINPORT_MAXOLD)
+ 	    {
+ 		t_binpold *old = binpold_new(fp);
+ 		result = BINPORT_FAILED;
+ 		if (old)
+ 		{
+ 		    bp->b_old = old;
+ 		    if (binpold_load(old) && binport_tobinbuf(bp, bb))
+ 			result = BINPORT_OK;
+ 		}
+ 		else binpold_failure(filename);
+ 	    }
+ 	    else result = BINPORT_FAILED;
+ 	    binport_free(bp);
+ 	}
+ 	else if (ftype == BINPORT_PDFILE)
+ 	    result = (binbuf_read(bb, filename, dirname, 0)
+ 		      ? BINPORT_FAILED : BINPORT_PDFILE);
+ 	else
+ 	{
+ 	    binport_failure(filename);
+ 	    result = BINPORT_INVALID;
+ 	}
+     }
+     else
+     {
+ 	binport_bug("cannot open file");
+ 	result = BINPORT_FAILED;
+     }
+     return (result);
+ }
+ 
+ /* save as MAXTEXT */
+ void binport_write(t_binbuf *bb, char *filename, char *dirname)
+ {
+     int result;
+     FILE *fp;
+     char namebuf[MAXPDSTRING];
+     namebuf[0] = 0;
+     if (*dirname)
+     	strcat(namebuf, dirname), strcat(namebuf, "/");
+     strcat(namebuf, filename);
+     sys_bashfilename(namebuf, namebuf);
+     if (fp = fopen(namebuf, "w"))
+     {
+ 	char buf[BINPORT_MAXSTRING];
+ 	t_atom *ap = binbuf_getvec(bb);
+ 	int cnt = 0, ac = binbuf_getnatom(bb);
+ 	while (ac--)
+ 	{
+ 	    if (ap->a_type == A_SEMI)
+ 	    {
+ 		fputs(";\n", fp);
+ 		cnt = 0;
+ 	    }
+ 	    else if (ap->a_type != A_NULL)
+ 	    {
+ 		if (cnt++) fputc(' ', fp);
+ 		binport_atomstring(ap, buf, BINPORT_MAXSTRING);
+ 		fputs(buf, fp);
+ 	    }
+ 	    ap++;
+ 	}
+ 	fclose(fp);
+     }
+ }
+ 
+ #else
+ 
  int main(int ac, char **av)
  {
***************
*** 872,876 ****
  	    {
  		if (ftype == BINPORT_OK)
! 		    binport_print(bp);
  		else if (ftype == BINPORT_MAXOLD)
  		{
--- 1060,1066 ----
  	    {
  		if (ftype == BINPORT_OK)
! 		    binport_print(bp, stdout);
! 		else if (ftype == BINPORT_MAXTEXT)
! 		    binport_warning("\"%s\" looks like a Max text file", av[1]);
  		else if (ftype == BINPORT_MAXOLD)
  		{
***************
*** 880,884 ****
  			bp->b_old = old;
  			if (binpold_load(old))
! 			    binport_print(bp);
  			else
  			    ftype = BINPORT_FAILED;
--- 1070,1074 ----
  			bp->b_old = old;
  			if (binpold_load(old))
! 			    binport_print(bp, stdout);
  			else
  			    ftype = BINPORT_FAILED;
***************
*** 889,894 ****
  		binport_free(bp);
  	    }
- 	    else if (ftype == BINPORT_MAXTEXT)
- 		binport_warning("\"%s\" looks like a Max text file", av[1]);
  	    else if (ftype == BINPORT_PDFILE)
  		binport_warning("\"%s\" looks like a Pd patch file", av[1]);
--- 1079,1082 ----

Index: loud.c
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/shared/common/loud.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** loud.c	11 Sep 2003 09:04:32 -0000	1.2
--- loud.c	17 Apr 2004 17:45:28 -0000	1.3
***************
*** 1,3 ****
! /* Copyright (c) 2002-2003 krzYszcz and others.
   * For information on usage and redistribution, and for a DISCLAIMER OF ALL
   * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
--- 1,3 ----
! /* Copyright (c) 2002-2004 krzYszcz and others.
   * For information on usage and redistribution, and for a DISCLAIMER OF ALL
   * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
***************
*** 128,136 ****
  }
  
! void loud_warning(t_pd *x, char *fmt, ...)
  {
      va_list ap;
      va_start(ap, fmt);
!     fprintf(stderr, "warning (%s): ", (x ? class_getname(*x) : "miXed"));
      vfprintf(stderr, fmt, ap);
      va_end(ap);
--- 128,137 ----
  }
  
! void loud_warning(t_pd *x, char *who, char *fmt, ...)
  {
      va_list ap;
      va_start(ap, fmt);
!     fprintf(stderr, "warning (%s): ",
! 	    (x ? class_getname(*x) : (who ? who : "miXed")));
      vfprintf(stderr, fmt, ap);
      va_end(ap);
***************
*** 141,147 ****
  {
      if (name)
! 	loud_warning(x, "\"%s\" method not implemented (yet)", name);
      else
! 	loud_warning(x, "not implemented (yet)");
  }
  
--- 142,148 ----
  {
      if (name)
! 	loud_warning(x, 0, "\"%s\" method not implemented (yet)", name);
      else
! 	loud_warning(x, 0, "not implemented (yet)");
  }
  
***************
*** 198,202 ****
  	    {
  		if (underaction & LOUD_CLIP)
! 		    loud_warning(&c, "%s rounded up to %g", what, minval);
  		else
  		    loud_incompatible(c, "less than %g %s requested",
--- 199,203 ----
  	    {
  		if (underaction & LOUD_CLIP)
! 		    loud_warning(&c, 0, "%s rounded up to %g", what, minval);
  		else
  		    loud_incompatible(c, "less than %g %s requested",
***************
*** 208,212 ****
  	    {
  		if (overaction & LOUD_CLIP)
! 		    loud_warning(&c, "%s truncated to %g", what, maxval);
  		else
  		    loud_incompatible(c, "more than %g %s requested",
--- 209,213 ----
  	    {
  		if (overaction & LOUD_CLIP)
! 		    loud_warning(&c, 0, "%s truncated to %g", what, maxval);
  		else
  		    loud_incompatible(c, "more than %g %s requested",





More information about the Pd-cvs mailing list