diff options
author | Franz Zotter <fzotter@users.sourceforge.net> | 2007-08-21 09:57:37 +0000 |
---|---|---|
committer | Franz Zotter <fzotter@users.sourceforge.net> | 2007-08-21 09:57:37 +0000 |
commit | 18715f3ae7adb4d9927ee08ff1c4bb7e7ee9a756 (patch) | |
tree | 249b493fe07dc231dad50ed823e57f8ee44702a5 /src | |
parent | d440632e4fb8b62f6ffb7a9b2a989d8a1f2daba0 (diff) |
added a format string for writing floats with fwriteln
maybe a dangerous option....?
svn path=/trunk/externals/zexy/; revision=8679
Diffstat (limited to 'src')
-rw-r--r-- | src/fwriteln.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/fwriteln.c b/src/fwriteln.c index 0525433..57a6351 100644 --- a/src/fwriteln.c +++ b/src/fwriteln.c @@ -43,6 +43,7 @@ typedef struct fwriteln char *x_filename; char *x_textbuf; char linebreak_chr[3]; + char format_string_afloats[20]; } t_fwriteln; @@ -105,7 +106,7 @@ static void fwriteln_write (t_fwriteln *x, t_symbol *s, int argc, t_atom *argv) { switch (argv->a_type) { case A_FLOAT: - snprintf(text,MAXPDSTRING,"%.16g ", atom_getfloat(argv)); + snprintf(text,MAXPDSTRING,x->format_string_afloats, atom_getfloat(argv)); text[MAXPDSTRING-1]=0; length=strlen(text); if (fwrite(text, length*sizeof(char),1,x->x_file) < 1) { @@ -168,19 +169,26 @@ static void fwriteln_free (t_fwriteln *x) fwriteln_close(x); } -static void *fwriteln_new(void) +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; } void fwriteln_setup(void) { fwriteln_class = class_new(gensym("fwriteln"), (t_newmethod)fwriteln_new, - (t_method) fwriteln_free, sizeof(t_fwriteln), 0, 0); + (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); class_addanything(fwriteln_class, (t_method)fwriteln_write); |