Update of /cvsroot/pure-data/externals/zexy/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22281
Modified Files:
freadln.c fwriteln.c zexyconf.h
Log Message:
freadln:
repaired the file read error in freadln
and added the textfile/msgfile mode with ";"
fwriteln:
added the textfile/msgfile compatible mode with ";"
Index: freadln.c
===================================================================
RCS file: /cvsroot/pure-data/externals/zexy/src/freadln.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** freadln.c 21 May 2007 12:03:39 -0000 1.2
--- freadln.c 16 Aug 2007 22:23:41 -0000 1.3
***************
*** 18,32 ****
#include "zexy.h"
#include <stdio.h>
#include <string.h>
! #include <stdarg.h>
! #include <fcntl.h>
! #ifdef __WIN32__
! # include <io.h>
! #else
! # include <sys/types.h>
! # include <unistd.h>
! #endif
#define MIN_FREADLN_LENGTH 10
--- 18,36 ----
#include "zexy.h"
+ #ifdef __WIN32__
+ # define snprintf _snprintf
+ #endif
+
#include <stdio.h>
#include <string.h>
! //#include <stdarg.h>
! //#include <fcntl.h>
! //#ifdef __WIN32__
! //# include <io.h>
! //#else
! //# include <sys/types.h>
! //# include <unistd.h>
! //#endif
#define MIN_FREADLN_LENGTH 10
***************
*** 49,55 ****
char *x_filename;
char *x_textbuf;
! int x_textbuf_length;
t_outlet *x_message_outlet;
t_outlet *x_readybang_outlet;
} t_freadln;
--- 53,63 ----
char *x_filename;
char *x_textbuf;
! int x_textbuf_length;
t_outlet *x_message_outlet;
t_outlet *x_readybang_outlet;
+
+ char linebreak_chr[3];
+
+ t_canvas *x_canvas;
} t_freadln;
***************
*** 72,95 ****
{
char filenamebuf[MAXPDSTRING], *filenamebufptr;
! int fd;
freadln_close(x);
! if(type!=gensym("cr")) {
pd_error(x, "currently only 'cr' type files are implemented!");
return;
! }
// directory, filename, extension, dirresult, nameresult, unsigned int size, int bin
! if ((fd=open_via_path("",s->s_name,"", filenamebuf, &filenamebufptr, MAXPDSTRING,0))==-1) {
! pd_error(x, "failed to open %128s", filenamebuf);
! close(fd);
return;
}
close(fd);
! if (!(x->x_file=fopen(filenamebuf, "r"))) {
! pd_error(x, "failed to open %128s",filenamebuf);
! return;
! }
! if (!(x->x_filename=(char*)getbytes(sizeof(char)*strlen(filenamebuf)))) {
pd_error(x, "out of memory");
freadln_close(x);
--- 80,107 ----
{
char filenamebuf[MAXPDSTRING], *filenamebufptr;
! char*dirname=canvas_getdir(x->x_canvas)->s_name;
! int fd, len;
!
freadln_close(x);
! /* if(type!=gensym("cr")) {
pd_error(x, "currently only 'cr' type files are implemented!");
return;
! }*/
! if (type==gensym("cr"))
! strcpy(x->linebreak_chr,"\n");
! else
! strcpy(x->linebreak_chr,";\n");
!
// directory, filename, extension, dirresult, nameresult, unsigned int size, int bin
! if ((fd=open_via_path(dirname,
! s->s_name,"", filenamebuf, &filenamebufptr, MAXPDSTRING,0)) < 0 ) {
! pd_error(x, "%s: failed to open %s", s->s_name, filenamebuf);
return;
}
close(fd);
! len=strlen(filenamebuf);
! if (!(x->x_filename=(char*)getbytes(sizeof(char)*(len+strlen(s->s_name)+2)))) {
pd_error(x, "out of memory");
freadln_close(x);
***************
*** 97,100 ****
--- 109,118 ----
}
strcpy(x->x_filename,filenamebuf);
+ strcpy(x->x_filename+len,"/");
+ strcpy(x->x_filename+len+1,s->s_name);
+ if (!(x->x_file=fopen(x->x_filename, "r"))) {
+ pd_error("freadln: failed to open %128s",filenamebuf);
+ return;
+ }
if (!(x->x_textbuf = (char *) getbytes (MIN_FREADLN_LENGTH * sizeof(char)))) {
pd_error(x, "out of memory");
***************
*** 138,148 ****
{
int min_length=(x->x_textbuf_length < 1)?1:x->x_textbuf_length;
! int ret_pos=0;
t_binbuf *bbuf;
t_atom *abuf;
int abuf_length;
t_symbol *s;
! if (!x->x_file) {
pd_error(x, "no file opened for reading");
return;
--- 156,168 ----
{
int min_length=(x->x_textbuf_length < 1)?1:x->x_textbuf_length;
! int linebreak_pos=0;
! int items_read;
t_binbuf *bbuf;
t_atom *abuf;
int abuf_length;
t_symbol *s;
+ int rewind_after;
! if (x->x_file < 0) {
pd_error(x, "no file opened for reading");
return;
***************
*** 150,156 ****
do {
! if (ret_pos==-1) {
! min_length++;
! fseek(x->x_file,-(long)(x->x_textbuf_length-1),SEEK_CUR);
}
if (!enlarge_cstr_if_required((const char**) &x->x_textbuf, &x->x_textbuf_length, min_length)) {
--- 170,176 ----
do {
! if (linebreak_pos==-1) {
! min_length<<=1;
! fseek(x->x_file,-(long)(x->x_textbuf_length),SEEK_CUR);
}
if (!enlarge_cstr_if_required((const char**) &x->x_textbuf, &x->x_textbuf_length, min_length)) {
***************
*** 160,170 ****
return;
}
! if (!(fgets(x->x_textbuf, x->x_textbuf_length, x->x_file))) {
! freadln_close(x);
! outlet_bang(x->x_readybang_outlet);
! return;
}
! } while ((ret_pos=cstr_char_pos(x->x_textbuf,'\n'))==-1);
! x->x_textbuf[ret_pos-1]='\0';
//post("analyzing \"%s\"",x->x_textbuf);
if (!(bbuf=binbuf_new())) {
--- 180,200 ----
return;
}
! if (!(items_read=fread(x->x_textbuf,sizeof(char),x->x_textbuf_length,x->x_file))) {
! freadln_close(x);
! outlet_bang(x->x_readybang_outlet);
! return;
}
! x->x_textbuf[x->x_textbuf_length-1]=0;
! } while (((linebreak_pos=cstr_char_pos(x->x_textbuf,x->linebreak_chr[0]))==-1) &&
! !(items_read < x->x_textbuf_length));
!
! if (linebreak_pos-1 < items_read - strlen(x->linebreak_chr)) {
! rewind_after=items_read-linebreak_pos;
! post("rewinding by %d", rewind_after);
! fseek(x->x_file,-(long)(rewind_after),SEEK_CUR);
! }
! if (linebreak_pos==-1)
! linebreak_pos=items_read;
! x->x_textbuf[linebreak_pos-1]='\0';
//post("analyzing \"%s\"",x->x_textbuf);
if (!(bbuf=binbuf_new())) {
***************
*** 173,177 ****
return;
}
! binbuf_text(bbuf, x->x_textbuf, ret_pos-1);
abuf = binbuf_getvec(bbuf);
abuf_length = binbuf_getnatom(bbuf);
--- 203,207 ----
return;
}
! binbuf_text(bbuf, x->x_textbuf, linebreak_pos-1);
abuf = binbuf_getvec(bbuf);
abuf_length = binbuf_getnatom(bbuf);
***************
*** 208,211 ****
--- 238,242 ----
x->x_file=0;
x->x_textbuf=0;
+ x->x_canvas = canvas_getcurrent();
return (void *)x;
}
Index: fwriteln.c
===================================================================
RCS file: /cvsroot/pure-data/externals/zexy/src/fwriteln.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** fwriteln.c 5 Jul 2007 14:51:23 -0000 1.3
--- fwriteln.c 16 Aug 2007 22:23:41 -0000 1.4
***************
*** 43,46 ****
--- 43,47 ----
char *x_filename;
char *x_textbuf;
+ char linebreak_chr[3];
} t_fwriteln;
***************
*** 66,73 ****
fwriteln_close (x);
! if(0==type || type!=gensym("cr")) {
pd_error(x, "unknown type '%s'", (type)?type->s_name:"");
return;
! }
if (!(x->x_file=fopen(filename, "w"))) {
--- 67,79 ----
fwriteln_close (x);
! /* if(0==type || type!=gensym("cr")) {
pd_error(x, "unknown type '%s'", (type)?type->s_name:"");
return;
! }*/
!
! if (type==gensym("cr"))
! strcpy(x->linebreak_chr,"\n");
! else
! strcpy(x->linebreak_chr,";\n");
if (!(x->x_file=fopen(filename, "w"))) {
***************
*** 145,149 ****
}
! snprintf(text,MAXPDSTRING,"\n");
length=strlen(text);
if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) {
--- 151,155 ----
}
! snprintf(text,MAXPDSTRING,x->linebreak_chr);
length=strlen(text);
if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) {
Index: zexyconf.h
===================================================================
RCS file: /cvsroot/pure-data/externals/zexy/src/zexyconf.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** zexyconf.h 5 Jul 2007 14:52:13 -0000 1.6
--- zexyconf.h 16 Aug 2007 22:23:41 -0000 1.7
***************
*** 4,8 ****
/* Define if you have the <regex.h> header file. */
! //#define HAVE_REGEX_H 1
/* Define if you have the <alloca.h> header file. */
--- 4,8 ----
/* Define if you have the <regex.h> header file. */
! #define HAVE_REGEX_H 1
/* Define if you have the <alloca.h> header file. */
***************
*** 16,20 ****
* you need Z_WANT_LPT for this to have an effect !
*/
! //#define HAVE_LINUX_PPDEV_H 1
#endif /* _ZEXYCONF_H_ */
--- 16,20 ----
* you need Z_WANT_LPT for this to have an effect !
*/
! #define HAVE_LINUX_PPDEV_H 1
#endif /* _ZEXYCONF_H_ */