[PD-cvs] externals/mrpeach/net udpsend.c,1.1,1.2

Martin Peach mrpeach at users.sourceforge.net
Tue Nov 7 22:20:22 CET 2006


Update of /cvsroot/pure-data/externals/mrpeach/net
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14375

Modified Files:
	udpsend.c 
Log Message:
added file send


Index: udpsend.c
===================================================================
RCS file: /cvsroot/pure-data/externals/mrpeach/net/udpsend.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** udpsend.c	24 Aug 2006 06:51:16 -0000	1.1
--- udpsend.c	7 Nov 2006 21:20:20 -0000	1.2
***************
*** 29,35 ****
  } t_udpsend;
  
- #ifdef MSW
- __declspec(dllexport)
- #endif
  void udpsend_setup(void);
  static void udpsend_free(t_udpsend *x);
--- 29,32 ----
***************
*** 108,113 ****
  static void udpsend_send(t_udpsend *x, t_symbol *s, int argc, t_atom *argv)
  {
!     static char    byte_buf[65536];// arbitrary maximum similar to max IP packet size
!     int            i, d;
      char           c;
      float          f, e;
--- 105,112 ----
  static void udpsend_send(t_udpsend *x, t_symbol *s, int argc, t_atom *argv)
  {
! #define BYTE_BUF_LEN 65536 // arbitrary maximum similar to max IP packet size
!     static char    byte_buf[BYTE_BUF_LEN];
!     int            d;
!     int            i, j;
      char           c;
      float          f, e;
***************
*** 120,123 ****
--- 119,124 ----
      double         timeafter;
      int            late;
+     char           fpath[MAX_PATH];
+     FILE           *fptr;
  
  #ifdef DEBUG
***************
*** 125,129 ****
      post("argc: %d", argc);
  #endif
!     for (i = 0; i < argc; ++i)
      {
          if (argv[i].a_type == A_FLOAT)
--- 126,130 ----
      post("argc: %d", argc);
  #endif
!     for (i = j = 0; i < argc; ++i)
      {
          if (argv[i].a_type == A_FLOAT)
***************
*** 146,159 ****
  	        post("udpsend_send: argv[%d]: %d", i, c);
  #endif
! 	        byte_buf[i] = c;
          }
          else
! 	    {
!             error("udpsend_send: item %d is not a float", i);
              return;
          }
      }
  
!     length = i;
      if ((x->x_fd >= 0) && (length > 0))
      {
--- 147,193 ----
  	        post("udpsend_send: argv[%d]: %d", i, c);
  #endif
! 	        byte_buf[j++] = c;
!         }
!         else if (argv[i].a_type == A_SYMBOL)
!         {
! 
!             atom_string(&argv[i], fpath, MAX_PATH);
! #ifdef DEBUG
!             post ("udpsend fname: %s", fpath);
! #endif
!             fptr = fopen(fpath, "rb");
!             if (fptr == NULL)
!             {
!                 post("udpsend: unable to open \"%s\"", fpath);
!                 return;
!             }
!             rewind(fptr);
! #ifdef DEBUG
!             post("udpsend: d is %d", d);
! #endif
!             while ((d = fgetc(fptr)) != EOF)
!             {
!                 byte_buf[j++] = (char)(d & 0x0FF);
! #ifdef DEBUG
!                 post("udpsend: byte_buf[%d] = %d", j-1, byte_buf[j-1]);
! #endif
!                 if (j >= BYTE_BUF_LEN)
!                 {
!                     post ("udpsend: file too long, truncating at %lu", BYTE_BUF_LEN);
!                     break;
!                 }
!             }
!             fclose(fptr);
!             fptr = NULL;
!             post("udpsend: read \"%s\" length %d byte%s", fpath, j, ((d==1)?"":"s"));
          }
          else
!         {
!             error("udpsend_send: item %d is not a float or a file name", i);
              return;
          }
      }
  
!     length = j;
      if ((x->x_fd >= 0) && (length > 0))
      {
***************
*** 196,202 ****
  }
  
- #ifdef MSW
- __declspec(dllexport)
- #endif
  void udpsend_setup(void)
  {
--- 230,233 ----





More information about the Pd-cvs mailing list