[paranoia-dev] patch to output to cdda2wav-alike filenames

The Anarcat anarcat at anarcat.ath.cx
Tue Apr 15 15:36:17 PDT 2003


Hi!

Recently, my cdda2wav output broke terribly since I upgraded to
FreeBSD 5.0-RELEASE. So I switched to cdparanoia. Unfortunatly,
cdparanoia doesn't give out cdrecord-compatible .info files, so I
still need cdda2wav to make "perfect" (gapless, etc) cd copies.

I had to hack cdparanoia to be able to customize the output filename
in batch mode. I have attached the patch. It cleans up a lot (IMHO)
the way the filename argument is handled. Also note that the argument
isn't documented in the man page, so I think it shouldn't be so bad to
modify its behavior which is, btw, backward compatible.

All it does it that instead of taking "filename" as a suffix to add to
track_%02d., it takes it as the whole format argument. The general
behavior is changed only in the case where a "filename" is specified.

Comments are welcome, please CC, I'm not on the list.

A.

--- main.c	2003-03-31 13:54:29-05	1.1
+++ main.c	2003-03-31 15:56:36-05	1.3
@@ -1070,46 +1070,48 @@
         
         /* argv[optind] is the span, argv[optind+1] (if exists) is outfile */
         
-	if(optind+1<argc){
-	  if(!strcmp(argv[optind+1],"-")){
+	if((optind+1<argc) && (!strcmp(argv[optind+1],"-"))){
             out=dup(fileno(stdout));
             if(batch)report("Are you sure you wanted 'batch' "
                             "(-B) output with stdout?");
             report("outputting to stdout\n");
             outfile_name[0]='\0';
-	  }else{
-	    char path[256];
+        } else {
+            char path_fmt[256] = "track%02d.cdda"; /* default */
+            if (optind+1<argc) {
+                char path[256];
+                
+                char *post=strrchr(argv[optind+1],'/');
+                int pos=(post?post-argv[optind+1]+1:0);
+                char *file=argv[optind+1]+pos;
+                
+                path[0]='\0';
+                
+                if(pos)
+                    strncat(path,argv[optind+1],pos>256?256:pos);
+            
+                snprintf(path_fmt,246,"%s%s",path,file);
+            }
+            
+            if (batch)
+                sprintf(outfile_name,path_fmt,batch_track);
+            else
+                sprintf(outfile_name,"cdda");
 
-	    char *post=strrchr(argv[optind+1],'/');
-	    int pos=(post?post-argv[optind+1]+1:0);
-	    char *file=argv[optind+1]+pos;
-	    
-	    path[0]='\0';
-
-	    if(pos)
-	      strncat(path,argv[optind+1],pos>256?256:pos);
-
-	    if(batch)
-	      snprintf(outfile_name,246,"%strack%02d.%s",path,batch_track,file);
-	    else
-	      snprintf(outfile_name,246,"%s%s",path,file);
-
-	    if(file[0]=='\0'){
               switch(output_type){
               case 0: /* raw */
-		strcat(outfile_name,"cdda.raw");
+		strcat(outfile_name,".raw");
                 break;
               case 1:
-		strcat(outfile_name,"cdda.wav");
+		strcat(outfile_name,".wav");
                 break;
               case 2:
-		strcat(outfile_name,"cdda.aifc");
+		strcat(outfile_name,".aifc");
                 break;
               case 3:
-		strcat(outfile_name,"cdda.aiff");
+		strcat(outfile_name,".aiff");
                 break;
               }
-	    }
             
             out=open(outfile_name,O_RDWR|O_CREAT|O_TRUNC,0666);
             if(out==-1){
@@ -1120,40 +1122,8 @@
               exit(1);
             }
             report2("outputting to %s\n",outfile_name);
-	  }
-	}else{
-	  /* default */
-	  if(batch)
-	    sprintf(outfile_name,"track%02d.",batch_track);
-	  else
-	    outfile_name[0]='\0';
-	  
-	  switch(output_type){
-	  case 0: /* raw */
-	    strcat(outfile_name,"cdda.raw");
-	    break;
-	  case 1:
-	    strcat(outfile_name,"cdda.wav");
-	    break;
-	  case 2:
-	    strcat(outfile_name,"cdda.aifc");
-	    break;
-	  case 3:
-	    strcat(outfile_name,"cdda.aiff");
-	    break;
-	  }
-	  
-	  out=open(outfile_name,O_RDWR|O_CREAT|O_TRUNC,0666);
-	  if(out==-1){
-	    report3("Cannot open default output file %s: %s",outfile_name,
-		    strerror(errno));
-	    cdda_close(d);
-	    d=NULL;
-	    exit(1);
-	  }
-	  report2("outputting to %s\n",outfile_name);
-	}
-	
+        }
+        
         switch(output_type){
         case 0: /* raw */
           break;

<p>
-- 
The idea that Bill Gates has appeared like a knight in shining armour to
lead all customers out of a mire of technological chaos neatly ignores
the fact that it was he who, by peddling second-rate technology, led
them into it in the first place. - Douglas Adams (1952-2001)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: part
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
Url : http://lists.xiph.org/pipermail/paranoia-dev/attachments/20030415/1834c2fe/part.pgp


More information about the Paranoia-dev mailing list