Update of /cvsroot/pure-data/externals/zexy/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28828
Modified Files: fwriteln.c Log Message: added a more stable version of float formatting to [fwriteln] with the arguments e.g. [fwriteln w 10 p 2] for minimum width 10 and precision 2.
Index: fwriteln.c =================================================================== RCS file: /cvsroot/pure-data/externals/zexy/src/fwriteln.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** fwriteln.c 21 Aug 2007 09:57:37 -0000 1.5 --- fwriteln.c 24 Aug 2007 14:26:44 -0000 1.6 *************** *** 44,48 **** char *x_textbuf; char linebreak_chr[3]; ! char format_string_afloats[20]; } t_fwriteln;
--- 44,50 ---- char *x_textbuf; char linebreak_chr[3]; ! char format_string_afloats[10]; ! int width; ! int precision; } t_fwriteln;
*************** *** 107,111 **** switch (argv->a_type) { case A_FLOAT: ! snprintf(text,MAXPDSTRING,x->format_string_afloats, atom_getfloat(argv)); text[MAXPDSTRING-1]=0; length=strlen(text); --- 109,114 ---- switch (argv->a_type) { case A_FLOAT: ! snprintf(text,MAXPDSTRING,x->format_string_afloats, ! x->width,x->precision,atom_getfloat(argv)); text[MAXPDSTRING-1]=0; length=strlen(text); *************** *** 170,186 **** }
! static void *fwriteln_new(t_symbol *s) { t_fwriteln *x = (t_fwriteln *)pd_new(fwriteln_class); x->x_filename=0; x->x_file=0; x->x_textbuf=0; ! if (s!=gensym("")) { ! strcpy(x->format_string_afloats,s->s_name); ! strcpy(x->format_string_afloats+strlen(s->s_name)," "); } - else - strcpy(x->format_string_afloats,"%.16g "); - post("fwriteln: float format string "%s%"",x->format_string_afloats); return (void *)x; } --- 173,204 ---- }
! static void *fwriteln_new(t_symbol *s, int argc, t_atom *argv) { + int k; t_fwriteln *x = (t_fwriteln *)pd_new(fwriteln_class); x->x_filename=0; x->x_file=0; x->x_textbuf=0; ! x->width=5; ! x->precision=2; ! strcpy(x->format_string_afloats,"%*.*f "); ! for (k=0; k<argc; k++) { ! if ((atom_getsymbol(&argv[k])==gensym("p"))&&(k+1<argc)) { ! x->precision=atom_getint(&argv[++k]); ! x->precision=(x->precision<0)?0:x->precision; ! x->precision=(x->precision>30)?30:x->precision; ! } ! else if ((atom_getsymbol(&argv[k])==gensym("w"))&&(k+1<argc)) { ! x->width=atom_getint(&argv[++k]); ! x->width=(x->width<1)?1:x->width; ! x->width=(x->width>40)?40:x->width; ! } ! else if (atom_getsymbol(&argv[k])==gensym("-")) { ! strcpy(x->format_string_afloats,"%-*.*f "); ! } ! else if (atom_getsymbol(&argv[k])==gensym("+")) { ! strcpy(x->format_string_afloats,"%+*.*f "); ! } } return (void *)x; } *************** *** 189,193 **** { fwriteln_class = class_new(gensym("fwriteln"), (t_newmethod)fwriteln_new, ! (t_method) fwriteln_free, sizeof(t_fwriteln), CLASS_DEFAULT, A_DEFSYM, 0); class_addmethod(fwriteln_class, (t_method)fwriteln_open, gensym("open"), A_SYMBOL, A_DEFSYM, 0); class_addmethod(fwriteln_class, (t_method)fwriteln_close, gensym("close"), A_NULL, 0); --- 207,211 ---- { fwriteln_class = class_new(gensym("fwriteln"), (t_newmethod)fwriteln_new, ! (t_method) fwriteln_free, sizeof(t_fwriteln), CLASS_DEFAULT, A_GIMME, 0); class_addmethod(fwriteln_class, (t_method)fwriteln_open, gensym("open"), A_SYMBOL, A_DEFSYM, 0); class_addmethod(fwriteln_class, (t_method)fwriteln_close, gensym("close"), A_NULL, 0);