Update of /cvsroot/pure-data/externals/zexy/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11851
Modified Files:
msgfile.c
Log Message:
use pd_error() to make errors findable;
changed behaviour of "read" message (no more appending of file to current buffer)
added "read2" message (appends file to current buffer == old "read" behaviour)
Index: msgfile.c
===================================================================
RCS file: /cvsroot/pure-data/externals/zexy/src/msgfile.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** msgfile.c 5 Jul 2006 15:14:50 -0000 1.14
--- msgfile.c 10 Oct 2006 15:04:55 -0000 1.15
***************
*** 287,291 ****
static void msgfile_delete(t_msgfile *x, t_symbol *s, int ac, t_atom *av)
{
- ZEXY_USEVAR(s);
if (ac==1) {
int pos = atom_getfloat(av);
--- 287,290 ----
***************
*** 313,317 ****
static void msgfile_add(t_msgfile *x, t_symbol *s, int ac, t_atom *av)
{
- ZEXY_USEVAR(s);
msgfile_end(x);
add_currentnode(x);
--- 312,315 ----
***************
*** 320,324 ****
static void msgfile_add2(t_msgfile *x, t_symbol *s, int ac, t_atom *av)
{
- ZEXY_USEVAR(s);
msgfile_end(x);
if (x->current->previous) x->current = x->current->previous;
--- 318,321 ----
***************
*** 328,332 ****
static void msgfile_append(t_msgfile *x, t_symbol *s, int ac, t_atom *av)
{
- ZEXY_USEVAR(s);
add_currentnode(x);
write_currentnode(x, ac, av);
--- 325,328 ----
***************
*** 340,344 ****
{
t_msglist *cur = x->current;
- ZEXY_USEVAR(s);
insert_currentnode(x);
write_currentnode(x, ac, av);
--- 336,339 ----
***************
*** 348,352 ****
{
t_msglist *cur = x->current;
- ZEXY_USEVAR(s);
if ((x->current) && (x->current->previous)) x->current = x->current->previous;
write_currentnode(x, ac, av);
--- 343,346 ----
***************
*** 362,366 ****
static void msgfile_replace(t_msgfile *x, t_symbol *s, int ac, t_atom *av)
{
- ZEXY_USEVAR(s);
freebytes(x->current->thislist, sizeof(x->current->thislist));
x->current->thislist = 0;
--- 356,359 ----
***************
*** 520,524 ****
}
! static void msgfile_read(t_msgfile *x, t_symbol *filename, t_symbol *format)
{
int rmode = 0;
--- 513,517 ----
}
! static void msgfile_read2(t_msgfile *x, t_symbol *filename, t_symbol *format)
{
int rmode = 0;
***************
*** 546,550 ****
if((fd=open(filename->s_name, rmode)) < 0) {
! error("%s: can't open in %s", filename->s_name, dirname);
return;
}
--- 539,543 ----
if((fd=open(filename->s_name, rmode)) < 0) {
! pd_error(x, "%s: can't open in %s", filename->s_name, dirname);
return;
}
***************
*** 561,565 ****
dollarmode=1;
} else if (*format->s_name)
! error("msgfile_read: unknown flag: %s", format->s_name);
switch (mode) {
--- 554,558 ----
dollarmode=1;
} else if (*format->s_name)
! pd_error(x, "msgfile_read: unknown flag: %s", format->s_name);
switch (mode) {
***************
*** 580,584 ****
if ((length = lseek(fd, 0, SEEK_END)) < 0 || lseek(fd, 0,SEEK_SET) < 0
|| !(readbuf = t_getbytes(length))) {
! error("msgfile_read: unable to lseek %s", filnam);
close(fd);
return;
--- 573,577 ----
if ((length = lseek(fd, 0, SEEK_END)) < 0 || lseek(fd, 0,SEEK_SET) < 0
|| !(readbuf = t_getbytes(length))) {
! pd_error(x, "msgfile_read: unable to lseek %s", filnam);
close(fd);
return;
***************
*** 587,591 ****
/* read */
if ((readlength = read(fd, readbuf, length)) < length) {
! error("msgfile_read: unable to read %s", filnam);
close(fd);
t_freebytes(readbuf, length);
--- 580,584 ----
/* read */
if ((readlength = read(fd, readbuf, length)) < length) {
! pd_error(x, "msgfile_read: unable to read %s", filnam);
close(fd);
t_freebytes(readbuf, length);
***************
*** 609,613 ****
while (readlength--) {
if(pos>=length+MSGFILE_HEADROOM){
! error("msgfile: read error (headroom %d too small!)", MSGFILE_HEADROOM);
goto read_error;
break;
--- 602,606 ----
while (readlength--) {
if(pos>=length+MSGFILE_HEADROOM){
! pd_error(x, "msgfile: read error (headroom %d too small!)", MSGFILE_HEADROOM);
goto read_error;
break;
***************
*** 639,642 ****
--- 632,640 ----
t_freebytes(charbinbuf, length+MSGFILE_HEADROOM);
}
+ static void msgfile_read(t_msgfile *x, t_symbol *filename, t_symbol *format)
+ {
+ msgfile_clear(x);
+ msgfile_read2(x, filename, format);
+ }
static void msgfile_write(t_msgfile *x, t_symbol *filename, t_symbol *format)
***************
*** 669,683 ****
buf, MAXPDSTRING);
! if(gensym("cr")==format) {
! mode = CR_MODE;
! } else if(gensym("csv")==format) {
! mode = CSV_MODE;
! } else if(gensym("pd")==format) {
! mode = PD_MODE;
! } else if(gensym("$$")==format) {
! mode = PD_MODE;
! dollarmode=1;
! } else if(format&&format->s_name) {
! error("msgfile_write: ignoring unknown flag: %s", format->s_name);
}
--- 667,683 ----
buf, MAXPDSTRING);
! if(format&&gensym("")!=format) {
! if(gensym("cr")==format) {
! mode = CR_MODE;
! } else if(gensym("csv")==format) {
! mode = CSV_MODE;
! } else if(gensym("pd")==format) {
! mode = PD_MODE;
! } else if(gensym("$$")==format) {
! mode = PD_MODE;
! dollarmode=1;
! } else if(format&&format->s_name) {
! pd_error(x, "msgfile_write: ignoring unknown flag: %s", format->s_name);
! }
}
***************
*** 706,710 ****
else if ((*dumtext==';') && (dumtext[1]=='\n'))
*dumtext = eol;
! else if(dollarmode && (*dumtext=='$') && (dumtext[1]=='$'))
*dumtext='\\';
dumtext++;
--- 706,710 ----
else if ((*dumtext==';') && (dumtext[1]=='\n'))
*dumtext = eol;
! else if(dollarmode && (*dumtext=='$') && (dumtext[1]=='$')) /* only works with pd<0.40 */
*dumtext='\\';
dumtext++;
***************
*** 714,722 ****
sys_bashfilename(filename->s_name, filnam);
if (!(f = fopen(filnam, "w"))) {
! error("msgfile : failed to open %s", filnam);
} else {
/* write */
if (fwrite(mytext, textlen*sizeof(char), 1, f) < 1) {
! error("msgfile : failed to write %s", filnam);
}
}
--- 714,722 ----
sys_bashfilename(filename->s_name, filnam);
if (!(f = fopen(filnam, "w"))) {
! pd_error(x, "msgfile : failed to open %s", filnam);
} else {
/* write */
if (fwrite(mytext, textlen*sizeof(char), 1, f) < 1) {
! pd_error(x, "msgfile : failed to write %s", filnam);
}
}
***************
*** 729,733 ****
static void msgfile_help(t_msgfile *x)
{
- ZEXY_USEVAR(x);
post("\n%c msgfile\t:: handle and store files of lists", HEARTSYMBOL);
post("goto <n>\t: goto line <n>"
--- 729,732 ----
***************
*** 770,793 ****
{
t_msgfile *x = (t_msgfile *)pd_new(msgfile_class);
- ZEXY_USEVAR(s);
/* an empty node indicates the end of our listbuffer */
x->current = 0;
! /*
! x->curent = (t_msglist *)getbytes(sizeof(t_msglist));
! x->current->n = 0;
! x->current->thislist = 0;
! x->current->previous = x->current->next = 0;
! */
if ((argc==1) && (argv->a_type == A_SYMBOL)) {
! if (!strcmp(argv->a_w.w_symbol->s_name, "cr")) x->mode = CR_MODE;
! else if (!strcmp(argv->a_w.w_symbol->s_name, "csv")) x->mode = CSV_MODE;
! else if (!strcmp(argv->a_w.w_symbol->s_name, "pd")) x->mode = PD_MODE;
else {
! error("msgfile: unknown argument %s", argv->a_w.w_symbol->s_name);
! x->mode = PD_MODE;
}
! } else x->mode = PD_MODE;
outlet_new(&x->x_obj, &s_list);
--- 769,786 ----
{
t_msgfile *x = (t_msgfile *)pd_new(msgfile_class);
/* an empty node indicates the end of our listbuffer */
x->current = 0;
! x->mode=PD_MODE; /* that's the default */
if ((argc==1) && (argv->a_type == A_SYMBOL)) {
! t_symbol*mode=atom_getsymbol(argv);
! if (gensym("cr") == mode) x->mode = CR_MODE;
! else if (gensym("csv")== mode) x->mode = CSV_MODE;
! else if (gensym("pd") == mode) x->mode = PD_MODE;
else {
! pd_error(x, "msgfile: unknown argument %s", argv->a_w.w_symbol->s_name);
}
! }
outlet_new(&x->x_obj, &s_list);
***************
*** 832,835 ****
--- 825,829 ----
class_addmethod(msgfile_class, (t_method)msgfile_read, gensym("read"), A_SYMBOL, A_DEFSYM, 0);
+ class_addmethod(msgfile_class, (t_method)msgfile_read2, gensym("read2"), A_SYMBOL, A_DEFSYM, 0);
class_addmethod(msgfile_class, (t_method)msgfile_write, gensym("write"), A_SYMBOL, A_DEFSYM, 0);
class_addmethod(msgfile_class, (t_method)msgfile_print, gensym("print"), 0);