Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 2c9d30f3cf217a6cae41860ebc0d6704 > files > 201

libid3lib3.8_0-devel-3.8.0-0.pre2.1.1mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>src/tag_parse_v1.cpp Source File</title>
<link href="id3lib.css" rel="stylesheet" type="text/css">
</head><body bgcolor="#ffffff">
<!-- Generated by Doxygen 1.2.12 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
<hr><h1>src/tag_parse_v1.cpp</h1><a href="tag__parse__v1_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// $Id: tag_parse_v1.cpp,v 1.19 2001/12/16 11:44:24 shadrack Exp $</font>
00002 
00003 <font class="comment">// id3lib: a C++ library for creating and manipulating id3v1/v2 tags</font>
00004 <font class="comment">// Copyright 1999, 2000  Scott Thomas Haug</font>
00005 
00006 <font class="comment">// This library is free software; you can redistribute it and/or modify it</font>
00007 <font class="comment">// under the terms of the GNU Library General Public License as published by</font>
00008 <font class="comment">// the Free Software Foundation; either version 2 of the License, or (at your</font>
00009 <font class="comment">// option) any later version.</font>
00010 <font class="comment">//</font>
00011 <font class="comment">// This library is distributed in the hope that it will be useful, but WITHOUT</font>
00012 <font class="comment">// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</font>
00013 <font class="comment">// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public</font>
00014 <font class="comment">// License for more details.</font>
00015 <font class="comment">//</font>
00016 <font class="comment">// You should have received a copy of the GNU Library General Public License</font>
00017 <font class="comment">// along with this library; if not, write to the Free Software Foundation,</font>
00018 <font class="comment">// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</font>
00019 
00020 <font class="comment">// The id3lib authors encourage improvements and optimisations to be sent to</font>
00021 <font class="comment">// the id3lib coordinator.  Please see the README file for details on where to</font>
00022 <font class="comment">// send such submissions.  See the AUTHORS file for a list of people who have</font>
00023 <font class="comment">// contributed to id3lib.  See the ChangeLog file for a list of changes to</font>
00024 <font class="comment">// id3lib.  These files are distributed with id3lib at</font>
00025 <font class="comment">// http://download.sourceforge.net/id3lib/</font>
00026 
00027 <font class="preprocessor">#if defined HAVE_CONFIG_H</font>
00028 <font class="preprocessor"></font><font class="preprocessor">#include &lt;config.h&gt;</font>
00029 <font class="preprocessor">#endif</font>
00030 <font class="preprocessor"></font>
00031 
00032 <font class="preprocessor">#include "<a class="code" href="tag__impl_8h.html">tag_impl.h</a>"</font>
00033 <font class="preprocessor">#include "helpers.h"</font>
00034 <font class="preprocessor">#include "utils.h"</font>
00035 <font class="preprocessor">#include "io_decorators.h"</font>
00036 <font class="preprocessor">#include "io_helpers.h"</font>
00037 <font class="preprocessor">#include "io_strings.h"</font>
00038 
00039 <font class="keyword">using</font> <font class="keyword">namespace </font>dami;
00040 
00041 <font class="keywordtype">bool</font> id3::v1::parse(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>&amp; tag, <a class="code" href="class_i_d3___reader.html">ID3_Reader</a>&amp; reader)
00042 {
00043   io::ExitTrigger et(reader);
00044   
00045   <a class="code" href="class_i_d3___reader.html#s2">ID3_Reader::pos_type</a> <a class="code" href="class_i_d3___tag_impl.html#a35">end</a> = reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>();
00046   <font class="comment">// posn ourselves at 128 bytes from the current position</font>
00047   <font class="keywordflow">if</font> (<a class="code" href="class_i_d3___tag_impl.html#a35">end</a> &lt; reader.<a class="code" href="class_i_d3___reader.html#a1">getBeg</a>() + <a class="code" href="globals_8h.html#a220a173">ID3_V1_LEN</a>)
00048   {
00049     ID3D_NOTICE( <font class="stringliteral">"id3::v1::parse: not enough bytes to parse, pos = "</font> &lt;&lt; <a class="code" href="class_i_d3___tag_impl.html#a35">end</a> );
00050     <font class="keywordflow">return</font> <font class="keyword">false</font>;
00051   }
00052   reader.<a class="code" href="class_i_d3___reader.html#a4">setCur</a>(<a class="code" href="class_i_d3___tag_impl.html#a35">end</a> - <a class="code" href="globals_8h.html#a220a173">ID3_V1_LEN</a>);
00053   <a class="code" href="class_i_d3___reader.html#s2">ID3_Reader::pos_type</a> beg = reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>();
00054   <font class="comment">//file.seekg(-static_cast&lt;long&gt;(ID3_V1_LEN), ios::cur);</font>
00055   <font class="keywordflow">if</font> (<a class="code" href="class_i_d3___tag_impl.html#a35">end</a> != beg + <a class="code" href="globals_8h.html#a220a173">ID3_V1_LEN</a>)
00056   {
00057     ID3D_WARNING( <font class="stringliteral">"id3::v1::parse: failed to reposition "</font> &lt;&lt; <a class="code" href="globals_8h.html#a220a173">ID3_V1_LEN</a> &lt;&lt; 
00058                   <font class="stringliteral">" bytes"</font> );
00059     <font class="keywordflow">return</font> <font class="keyword">false</font>;
00060   }
00061   
00062   <font class="comment">// read the next 128 bytes in;</font>
00063   String id = io::readText(reader, <a class="code" href="globals_8h.html#a220a174">ID3_V1_LEN_ID</a>);
00064   
00065   <font class="comment">// check to see if it was a tag</font>
00066   <font class="keywordflow">if</font> (id != <font class="stringliteral">"TAG"</font>)
00067   {
00068     <font class="keywordflow">return</font> <font class="keyword">false</font>;
00069   }
00070   et.setExitPos(beg);
00071   
00072   <font class="comment">// guess so, let's start checking the v2 tag for frames which are the</font>
00073   <font class="comment">// equivalent of the v1 fields.  When we come across a v1 field that has</font>
00074   <font class="comment">// no current equivalent v2 frame, we create the frame, copy the data</font>
00075   <font class="comment">// from the v1 frame and attach it to the tag</font>
00076 
00077   <font class="comment">// (Scott Wheeler) The above comment was nice in theory, but it wasn't</font>
00078   <font class="comment">// first checking (before my hacks) to see if there already was v2 data.</font>
00079 
00080   ID3D_NOTICE(<font class="stringliteral">"id3::v1::parse: read bytes: "</font> &lt;&lt; reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() - beg);
00081   String title = io::readTrailingSpaces(reader, <a class="code" href="globals_8h.html#a220a175">ID3_V1_LEN_TITLE</a>);
00082   <font class="keywordflow">if</font> (title.size() &gt; 0 &amp;&amp; !id3::v2::hasTitle(tag))
00083   {
00084     id3::v2::setTitle(tag, title);
00085   }
00086   ID3D_NOTICE( <font class="stringliteral">"id3::v1::parse: title = \""</font> &lt;&lt; title &lt;&lt; <font class="stringliteral">"\""</font> );
00087   
00088   ID3D_NOTICE(<font class="stringliteral">"id3::v1::parse: read bytes: "</font> &lt;&lt; reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() - beg);
00089   String artist = io::readTrailingSpaces(reader, <a class="code" href="globals_8h.html#a220a176">ID3_V1_LEN_ARTIST</a>);
00090   <font class="keywordflow">if</font> (artist.size() &gt; 0 &amp;&amp; !id3::v2::hasArtist(tag))
00091   {
00092     id3::v2::setArtist(tag, artist);
00093   }
00094   ID3D_NOTICE( <font class="stringliteral">"id3::v1::parse: artist = \""</font> &lt;&lt; artist &lt;&lt; <font class="stringliteral">"\""</font> );
00095   
00096   ID3D_NOTICE(<font class="stringliteral">"id3::v1::parse: read bytes: "</font> &lt;&lt; reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() - beg);
00097   String album = io::readTrailingSpaces(reader, <a class="code" href="globals_8h.html#a220a177">ID3_V1_LEN_ALBUM</a>);
00098   <font class="keywordflow">if</font> (album.size() &gt; 0 &amp;&amp; !id3::v2::hasAlbum(tag)) 
00099   {
00100     id3::v2::setAlbum(tag, album);
00101   }
00102   ID3D_NOTICE( <font class="stringliteral">"id3::v1::parse: album = \""</font> &lt;&lt; title &lt;&lt; <font class="stringliteral">"\""</font> );
00103   
00104   ID3D_NOTICE(<font class="stringliteral">"id3::v1::parse: read bytes: "</font> &lt;&lt; reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() - beg);
00105   String year = io::readTrailingSpaces(reader, <a class="code" href="globals_8h.html#a220a178">ID3_V1_LEN_YEAR</a>);
00106   <font class="keywordflow">if</font> (year.size() &gt; 0 &amp;&amp; !id3::v2::hasYear(tag))
00107   {
00108     id3::v2::setYear(tag, year);
00109   }
00110   ID3D_NOTICE( <font class="stringliteral">"id3::v1::parse: year = \""</font> &lt;&lt; year &lt;&lt; <font class="stringliteral">"\""</font> );
00111   
00112   ID3D_NOTICE(<font class="stringliteral">"id3::v1::parse: read bytes: "</font> &lt;&lt; reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() - beg);
00113   String comment = io::readTrailingSpaces(reader, <a class="code" href="globals_8h.html#a220a179">ID3_V1_LEN_COMMENT</a>);
00114   <font class="keywordflow">if</font> (comment.length() == <a class="code" href="globals_8h.html#a220a179">ID3_V1_LEN_COMMENT</a>  &amp;&amp;
00115       <font class="charliteral">'\0'</font> == comment[<a class="code" href="globals_8h.html#a220a179">ID3_V1_LEN_COMMENT</a> - 2] ||
00116       <font class="charliteral">'\0'</font> != comment[<a class="code" href="globals_8h.html#a220a179">ID3_V1_LEN_COMMENT</a> - 1])
00117   {
00118     <font class="comment">// This is an id3v1.1 tag.  The last byte of the comment is the track</font>
00119     <font class="comment">// number.  </font>
00120     size_t track = comment[<a class="code" href="globals_8h.html#a220a179">ID3_V1_LEN_COMMENT</a> - 1];
00121     <font class="keywordflow">if</font> (track &gt; 0 &amp;&amp; !id3::v2::hasTrack(tag))
00122     {
00123       id3::v2::setTrack(tag, track, 0);
00124     }
00125     ID3D_NOTICE( <font class="stringliteral">"id3::v1::parse: track = \""</font> &lt;&lt; track &lt;&lt; <font class="stringliteral">"\""</font> );
00126 
00127     ID3D_NOTICE( <font class="stringliteral">"id3::v1::parse: comment length = \""</font> &lt;&lt; comment.length() &lt;&lt; <font class="stringliteral">"\""</font> );
00128     io::StringReader sr(comment);
00129     comment = io::readTrailingSpaces(sr, <a class="code" href="globals_8h.html#a220a179">ID3_V1_LEN_COMMENT</a> - 2);
00130   }
00131   ID3D_NOTICE( <font class="stringliteral">"id3::v1::parse: comment = \""</font> &lt;&lt; comment &lt;&lt; <font class="stringliteral">"\""</font> );
00132   <font class="keywordflow">if</font> (comment.size() &gt; 0)
00133   {
00134     id3::v2::setComment(tag, comment, <a class="code" href="globals_8h.html#a6">STR_V1_COMMENT_DESC</a>, <font class="stringliteral">"XXX"</font>);
00135   }
00136   
00137   ID3D_NOTICE(<font class="stringliteral">"id3::v1::parse: read bytes: "</font> &lt;&lt; reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() - beg);
00138   <font class="comment">// the GENRE field/frame</font>
00139   <a class="code" href="globals_8h.html#a33">uchar</a> genre = reader.<a class="code" href="class_i_d3___reader.html#a5">readChar</a>();
00140   <font class="keywordflow">if</font> (genre != 0xFF &amp;&amp; !id3::v2::hasGenre(tag)) 
00141   {
00142     id3::v2::setGenre(tag, genre);
00143   }
00144   ID3D_NOTICE( <font class="stringliteral">"id3::v1::parse: genre = \""</font> &lt;&lt; (<font class="keywordtype">int</font>) genre &lt;&lt; <font class="stringliteral">"\""</font> );
00145 
00146   ID3D_NOTICE(<font class="stringliteral">"id3::v1::parse: read bytes: "</font> &lt;&lt; reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() - beg);
00147   <font class="keywordflow">return</font> <font class="keyword">true</font>;
00148 }
</pre></div><hr><address><small>Generated on Thu Jan 3 07:35:56 2002 for id3lib by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.gif" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.12 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>,
 &copy;&nbsp;1997-2001</small></address>
</body>
</html>