[PD-cvs] externals/zexy/src fwriteln.c,1.8,1.9

Franz Zotter fzotter at users.sourceforge.net
Sun Sep 23 21:14:56 CEST 2007


Update of /cvsroot/pure-data/externals/zexy/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9317

Modified Files:
	fwriteln.c 
Log Message:
made the best out of "fwriteln": now accepts also arguments "f" "g" and "e" as floating point formats and is verbose in case of erroneous usage.


Index: fwriteln.c
===================================================================
RCS file: /cvsroot/pure-data/externals/zexy/src/fwriteln.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** fwriteln.c	23 Sep 2007 10:54:56 -0000	1.8
--- fwriteln.c	23 Sep 2007 19:14:54 -0000	1.9
***************
*** 45,50 ****
     char linebreak_chr[3];
     char format_string_afloats[10];
-    int  width;
-    int  precision;
  } t_fwriteln;
  
--- 45,48 ----
***************
*** 120,125 ****
           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);
--- 118,123 ----
           switch (argv->a_type) {
              case A_FLOAT:
!                snprintf(text,MAXPDSTRING,x->format_string_afloats,
! 		     atom_getfloat(argv));
                 text[MAXPDSTRING-1]=0;
                 length=strlen(text);
***************
*** 187,215 ****
  {
     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,"%*.*g ");
     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,"%-*.*g ");
        }
        else if (atom_getsymbol(&argv[k])==gensym("+")) {
! 	 strcpy(x->format_string_afloats,"%+*.*g ");
        }
     }
     return (void *)x;
  }
--- 185,243 ----
  {
     int k;
+    int width;
+    int precision;
+    char float_format[3]="g ";
+    char width_str[3]="";
+    char precision_str[4]="";
+    char prefix[2]="%";
     t_fwriteln *x = (t_fwriteln *)pd_new(fwriteln_class);
     x->x_filename=0;
     x->x_file=0;
     x->x_textbuf=0;
     for (k=0; k<argc; k++) {
!       if (atom_getsymbol(&argv[k])==gensym("p")) {
!          if ((k+1>=argc)||(argv[k+1].a_type!=A_FLOAT)) {
!             post("fwriteln: no value given for precision!");
!          }
!          else {
!             precision=atom_getint(&argv[++k]);
!             precision=(precision<0)?0:precision;
!             precision=(precision>30)?30:precision;
!             snprintf(precision_str,4,".%d",precision);
!          }
        }
!       else if (atom_getsymbol(&argv[k])==gensym("w")) {
!          if ((k+1>=argc)||(argv[k+1].a_type!=A_FLOAT)) {
!             post("fwriteln: no value given for width!");
!          }
!          else {
!             width=atom_getint(&argv[++k]);
!             width=(width<1)?1:width;
!             width=(width>40)?40:width;
!             snprintf(width_str,3,"%d",width);
!          }
!       }
!       else if (atom_getsymbol(&argv[k])==gensym("g")) {
!             float_format[0]='g';
!       }
!       else if (atom_getsymbol(&argv[k])==gensym("f")) {
!             float_format[0]='f';
!       }
!       else if (atom_getsymbol(&argv[k])==gensym("e")) {
!             float_format[0]='e';
        }
        else if (atom_getsymbol(&argv[k])==gensym("-")) {
! 	 strcpy(prefix,"%-");
        }
        else if (atom_getsymbol(&argv[k])==gensym("+")) {
! 	 strcpy(prefix,"%+");
        }
     }
+    x->format_string_afloats[0]='\0';
+    strncat(x->format_string_afloats,prefix,2);
+    strncat(x->format_string_afloats,width_str,2);
+    strncat(x->format_string_afloats,precision_str,3);
+    strncat(x->format_string_afloats,float_format,2);
+    //post("format string: \"%s\"\n",x->format_string_afloats);
     return (void *)x;
  }





More information about the Pd-cvs mailing list