[vorbis-dev] bugfix + vorbiscomment newline quoting patch

Cherniavsky Beni scben at techst02.technion.ac.il
Sun Oct 6 11:49:04 PDT 2002


First, a bug: `vorbiscomment -R' writes tags instead of listing them!  
The break between case 'R' and case 'w' is missing so it falls through...  
If you apply the patch below it also fixes this. 
 
On 27 Aug 2002 I wrote on vorbis:  
  
> On 2002-08-23, xdfisl wrote:    
>     
> > Okay, so --raw makes round-tripping okay for weird and non-standard    
> > characters but the problem with line endings is still present    
> > regardless of whether you specify --raw or not?    
> >    
> Exactly.  It can't go away without introducing some quoting    
> mechanism (because the comment can contaqin anything, even zero    
> bytes...).    
>     
> Now, since vorbiscomment is very useful in a unix enviroment in    
> combination with line-based tools like grep, I believe it's best    
> to quote the newlines in a comment so it all fits on one line.    
>     
> One possible syntax is the obvoius '\','n' sequence for a newline and    
> '\','\' for a single backslash.  This has slight chance of comment    
> mutation when working with older tools.  Still, enabling this by default    
> is reasonable IMHO (but for one problem: loss of readability when    
> invoked    
> from command line - would some --noquote option be that hard to type?).    
> I'll try to write a patch in the next days.  Side effect: users of    
> single-line vorbiscomment frontends will be able to type `\n' ;-)    
>     
> Another, arguably simpler (1 to 1 char translation), way is to replace    
> newlines by character 255, which is illegal in UTF-8.  This is even    
> nicer    
> for unix processing (think tr, etc.) but it is only good with --raw (not    
> a    
> big problem, you should use --raw anyway ;-) and it could choke utf-8    
> parsers of unprepared apps.  Should this be an option too?    
>     
> BTW, there are several line separators, especially with unicode, see    
>  
>   http://www.xiph.org/archives/vorbis-dev/200108/0233.html    
>  
> Only the raw \n needs quoting in unix.  Should \r be quoted for windows    
> users or silently converted to \n (it has really no place in the vorbis    
> comment header)?  In any case, they should all be converted to \n in the    
> non-quoted form for normal screen output.    
>     
 
The attached patch implements both quoting styles on one option 
-Q, --quoting-style=STYLE 
where STYLE can be `none' (current behaviour), `escape' - c-style \n, 
\\, \0 and \r (to avoid lossages even with bogus windows tools) or 
`255' for mapping null bytes to 254 and newlines to 255.  See manpage 
changes for details. 
 
I attempted not to harm the educational style of the code... 
 
The quoting/unquoting is done right before/after accessing the vc struct, 
so it would even work with encodings where \ or n have different values :-) 
More importantly, it allows to read/write null bytes but writing them still 
doesn't work because vorbis_comment_add_tag has a null-terminated interface 
(instead of getting a length parameter).  This can be solved by directly 
accessing the comments...  BTW, why split the comment on `=' only to have 
vorbis_comment_add_tag join it back? 
 
Feel free to choose a shorter option name ;-) or split it into separate 
options instead of the style parameter.  Also, making the `escape' style 
the default behaviour is probably more useful than the current. 
 
I documented the additions in the manpage and the usage message.  I also 
took the liberty of documenting the missing -R and the long names of all 
options in the manpage.  BTW, -t and -a lack long names. 
 
The patch is against last Friday's cvs snapshot; apply from inside the 
vorbis-tools/vorbiscomment directory. 
 

-- 
Beni Cherniavsky <cben at tx.technion.ac.il>  
 
"Windows Media Player 9 instaltion failed." 
[Check disk space, admin. permissions... - all was fine.] 
"The comuputer must be rebooted" [a single Finish (i.e. Reboot) button]!!! 
I killed the installer and WMP worked without a reboot... 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch
Type: text/x-diff
Size: 13731 bytes
Desc: patch
Url : http://lists.xiph.org/pipermail/vorbis-dev/attachments/20021006/eb4f2ebc/patch-0001.bin


More information about the Vorbis-dev mailing list