<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">argc</span><spanclass="operator">!=</span><spanclass="literal number integer">2</span><spanclass="punctuation">)</span>
<spanclass="name">fprintf</span><spanclass="punctuation">(</span><spanclass="name">stderr</span><spanclass="punctuation">,</span><spanclass="literal string">"failed to open listen socket: %s</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span><spanclass="punctuation">,</span><spanclass="name">ec</span><spanclass="punctuation">.</span><spanclass="name">message</span><spanclass="punctuation">().</span><spanclass="name">c_str</span><spanclass="punctuation">());</span>
<spanclass="keyword">return</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="name">p</span><spanclass="punctuation">.</span><spanclass="name">ti</span><spanclass="operator">=</span><spanclass="name">boost</span><spanclass="operator">::</span><spanclass="name">make_shared</span><spanclass="operator"><</span><spanclass="name">torrent_info</span><spanclass="operator">></span><spanclass="punctuation">(</span><spanclass="name">std</span><spanclass="operator">::</span><spanclass="name">string</span><spanclass="punctuation">(</span><spanclass="name">argv</span><spanclass="punctuation">[</span><spanclass="literal number integer">1</span><spanclass="punctuation">]),</span><spanclass="name">boost</span><spanclass="operator">::</span><spanclass="name">ref</span><spanclass="punctuation">(</span><spanclass="name">ec</span><spanclass="punctuation">),</span><spanclass="literal number integer">0</span><spanclass="punctuation">);</span>
<spanclass="keyword type">int</span><spanclass="name">r</span><spanclass="operator">=</span><spanclass="name">fseek</span><spanclass="punctuation">(</span><spanclass="name">f</span><spanclass="punctuation">,</span><spanclass="literal number integer">0</span><spanclass="punctuation">,</span><spanclass="name">SEEK_END</span><spanclass="punctuation">);</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">r</span><spanclass="operator">!=</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">s</span><spanclass="operator"><</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="name">r</span><spanclass="operator">=</span><spanclass="name">fseek</span><spanclass="punctuation">(</span><spanclass="name">f</span><spanclass="punctuation">,</span><spanclass="literal number integer">0</span><spanclass="punctuation">,</span><spanclass="name">SEEK_SET</span><spanclass="punctuation">);</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">r</span><spanclass="operator">!=</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">s</span><spanclass="operator">==</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="keyword">return</span><spanclass="literal number integer">0</span><spanclass="punctuation">;</span>
<spanclass="punctuation">}</span>
<spanclass="name">r</span><spanclass="operator">=</span><spanclass="name">fread</span><spanclass="punctuation">(</span><spanclass="operator">&</span><spanclass="name">v</span><spanclass="punctuation">[</span><spanclass="literal number integer">0</span><spanclass="punctuation">],</span><spanclass="literal number integer">1</span><spanclass="punctuation">,</span><spanclass="name">v</span><spanclass="punctuation">.</span><spanclass="name">size</span><spanclass="punctuation">(),</span><spanclass="name">f</span><spanclass="punctuation">);</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">r</span><spanclass="operator"><</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">r</span><spanclass="operator">!=</span><spanclass="name">s</span><spanclass="punctuation">)</span><spanclass="keyword">return</span><spanclass="operator">-</span><spanclass="literal number integer">3</span><spanclass="punctuation">;</span>
<spanclass="keyword">return</span><spanclass="literal number integer">0</span><spanclass="punctuation">;</span>
<spanclass="punctuation">}</span>
<spanclass="comment single">// do not include files and folders whose
<spanclass="literal string">"Generates a torrent file from the specified file</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">"or directory and writes it to standard out</span><spanclass="literal string escape">\n\n</span><spanclass="literal string">"</span>
<spanclass="literal string">" the resulting full merkle tree is written to</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">" the specified file</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">"-f include sha-1 file hashes in the torrent</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">" other networks</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">"-w url adds a web seed to the torrent with</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">" the specified url</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">"-t url adds the specified tracker to the</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">"-c comment sets the comment to the specified string</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">"-C creator sets the created-by field to the specified string</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">" than bytes will be piece-aligned</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">"-s bytes specifies a piece size for the torrent</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">" This has to be a multiple of 16 kiB</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">" links in the torrent file</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">"-o file specifies the output filename of the torrent file</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">" If this is not specified, the torrent file is</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">" printed to the standard out, except on windows</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">" where the filename defaults to a.torrent</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">"-r file add root certificate to the torrent, to verify</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="literal string">" the HTTPS tracker</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">argc</span><spanclass="operator"><</span><spanclass="literal number integer">2</span><spanclass="punctuation">)</span>
<spanclass="keyword type">int</span><spanclass="name">pad_file_limit</span><spanclass="operator">=</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="keyword type">int</span><spanclass="name">piece_size</span><spanclass="operator">=</span><spanclass="literal number integer">0</span><spanclass="punctuation">;</span>
<spanclass="keyword type">int</span><spanclass="name">flags</span><spanclass="operator">=</span><spanclass="literal number integer">0</span><spanclass="punctuation">;</span>
<spanclass="keyword">for</span><spanclass="punctuation">(</span><spanclass="keyword type">int</span><spanclass="name">i</span><spanclass="operator">=</span><spanclass="literal number integer">2</span><spanclass="punctuation">;</span><spanclass="name">i</span><spanclass="operator"><</span><spanclass="name">argc</span><spanclass="punctuation">;</span><spanclass="operator">++</span><spanclass="name">i</span><spanclass="punctuation">)</span>
<spanclass="punctuation">{</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">argv</span><spanclass="punctuation">[</span><spanclass="name">i</span><spanclass="punctuation">][</span><spanclass="literal number integer">0</span><spanclass="punctuation">]</span><spanclass="operator">!=</span><spanclass="literal string char">'-'</span><spanclass="punctuation">)</span>
<spanclass="keyword">return</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="punctuation">}</span>
<spanclass="keyword">switch</span><spanclass="punctuation">(</span><spanclass="name">argv</span><spanclass="punctuation">[</span><spanclass="name">i</span><spanclass="punctuation">][</span><spanclass="literal number integer">1</span><spanclass="punctuation">])</span>
<spanclass="name">std</span><spanclass="operator">::</span><spanclass="name">string</span><spanclass="name">full_path</span><spanclass="operator">=</span><spanclass="name">libtorrent</span><spanclass="operator">::</span><spanclass="name">complete</span><spanclass="punctuation">(</span><spanclass="name">argv</span><spanclass="punctuation">[</span><spanclass="literal number integer">1</span><spanclass="punctuation">]);</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">fs</span><spanclass="punctuation">.</span><spanclass="name">num_files</span><spanclass="punctuation">()</span><spanclass="operator">==</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="keyword type">int</span><spanclass="name">tier</span><spanclass="operator">=</span><spanclass="literal number integer">0</span><spanclass="punctuation">;</span>
<spanclass="name">load_file</span><spanclass="punctuation">(</span><spanclass="name">root_cert</span><spanclass="punctuation">,</span><spanclass="name">pem</span><spanclass="punctuation">,</span><spanclass="name">ec</span><spanclass="punctuation">,</span><spanclass="literal number integer">10000</span><spanclass="punctuation">);</span>
<spanclass="name">fprintf</span><spanclass="punctuation">(</span><spanclass="name">stderr</span><spanclass="punctuation">,</span><spanclass="literal string">"failed to load root certificate for tracker: %s</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span><spanclass="punctuation">,</span><spanclass="name">ec</span><spanclass="punctuation">.</span><spanclass="name">message</span><spanclass="punctuation">().</span><spanclass="name">c_str</span><spanclass="punctuation">());</span>
<spanclass="punctuation">}</span>
<spanclass="keyword">else</span>
<spanclass="punctuation">{</span>
<spanclass="name">t</span><spanclass="punctuation">.</span><spanclass="name">set_root_cert</span><spanclass="punctuation">(</span><spanclass="name">std</span><spanclass="operator">::</span><spanclass="name">string</span><spanclass="punctuation">(</span><spanclass="operator">&</span><spanclass="name">pem</span><spanclass="punctuation">[</span><spanclass="literal number integer">0</span><spanclass="punctuation">],</span><spanclass="name">pem</span><spanclass="punctuation">.</span><spanclass="name">size</span><spanclass="punctuation">()));</span>
<spanclass="punctuation">}</span>
<spanclass="punctuation">}</span>
<spanclass="comment single">// create the torrent and print it to stdout
<spanclass="keyword">return</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="punctuation">}</span>
<spanclass="name">fwrite</span><spanclass="punctuation">(</span><spanclass="operator">&</span><spanclass="name">torrent</span><spanclass="punctuation">[</span><spanclass="literal number integer">0</span><spanclass="punctuation">],</span><spanclass="literal number integer">1</span><spanclass="punctuation">,</span><spanclass="name">torrent</span><spanclass="punctuation">.</span><spanclass="name">size</span><spanclass="punctuation">(),</span><spanclass="name">output</span><spanclass="punctuation">);</span>
<spanclass="keyword">return</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="punctuation">}</span>
<spanclass="keyword type">int</span><spanclass="name">ret</span><spanclass="operator">=</span><spanclass="name">fwrite</span><spanclass="punctuation">(</span><spanclass="operator">&</span><spanclass="name">t</span><spanclass="punctuation">.</span><spanclass="name">merkle_tree</span><spanclass="punctuation">()[</span><spanclass="literal number integer">0</span><spanclass="punctuation">],</span><spanclass="literal number integer">20</span><spanclass="punctuation">,</span><spanclass="name">t</span><spanclass="punctuation">.</span><spanclass="name">merkle_tree</span><spanclass="punctuation">().</span><spanclass="name">size</span><spanclass="punctuation">(),</span><spanclass="name">output</span><spanclass="punctuation">);</span>
<spanclass="keyword">return</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="punctuation">}</span>
<spanclass="keyword type">int</span><spanclass="name">r</span><spanclass="operator">=</span><spanclass="name">fseek</span><spanclass="punctuation">(</span><spanclass="name">f</span><spanclass="punctuation">,</span><spanclass="literal number integer">0</span><spanclass="punctuation">,</span><spanclass="name">SEEK_END</span><spanclass="punctuation">);</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">r</span><spanclass="operator">!=</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">s</span><spanclass="operator"><</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="keyword">return</span><spanclass="operator">-</span><spanclass="literal number integer">2</span><spanclass="punctuation">;</span>
<spanclass="punctuation">}</span>
<spanclass="name">r</span><spanclass="operator">=</span><spanclass="name">fseek</span><spanclass="punctuation">(</span><spanclass="name">f</span><spanclass="punctuation">,</span><spanclass="literal number integer">0</span><spanclass="punctuation">,</span><spanclass="name">SEEK_SET</span><spanclass="punctuation">);</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">r</span><spanclass="operator">!=</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">s</span><spanclass="operator">==</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="keyword">return</span><spanclass="literal number integer">0</span><spanclass="punctuation">;</span>
<spanclass="punctuation">}</span>
<spanclass="name">r</span><spanclass="operator">=</span><spanclass="name">fread</span><spanclass="punctuation">(</span><spanclass="operator">&</span><spanclass="name">v</span><spanclass="punctuation">[</span><spanclass="literal number integer">0</span><spanclass="punctuation">],</span><spanclass="literal number integer">1</span><spanclass="punctuation">,</span><spanclass="name">v</span><spanclass="punctuation">.</span><spanclass="name">size</span><spanclass="punctuation">(),</span><spanclass="name">f</span><spanclass="punctuation">);</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">r</span><spanclass="operator"><</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">r</span><spanclass="operator">!=</span><spanclass="name">s</span><spanclass="punctuation">)</span><spanclass="keyword">return</span><spanclass="operator">-</span><spanclass="literal number integer">3</span><spanclass="punctuation">;</span>
<spanclass="keyword">return</span><spanclass="literal number integer">0</span><spanclass="punctuation">;</span>
<spanclass="keyword type">int</span><spanclass="name">line_len</span><spanclass="operator">=</span><spanclass="literal number integer">0</span><spanclass="punctuation">;</span>
<spanclass="name">line_len</span><spanclass="operator">+=</span><spanclass="literal number integer">4</span><spanclass="punctuation">;</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">line_len</span><spanclass="operator">></span><spanclass="name">limit</span><spanclass="punctuation">)</span><spanclass="keyword">return</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="keyword">for</span><spanclass="punctuation">(</span><spanclass="keyword type">int</span><spanclass="name">i</span><spanclass="operator">=</span><spanclass="literal number integer">0</span><spanclass="punctuation">;</span><spanclass="name">i</span><spanclass="operator"><</span><spanclass="name">e</span><spanclass="punctuation">.</span><spanclass="name">list_size</span><spanclass="punctuation">();</span><spanclass="operator">++</span><spanclass="name">i</span><spanclass="punctuation">)</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">ret</span><spanclass="operator">==</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">)</span><spanclass="keyword">return</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="name">line_len</span><spanclass="operator">+=</span><spanclass="name">ret</span><spanclass="operator">+</span><spanclass="literal number integer">2</span><spanclass="punctuation">;</span>
<spanclass="name">line_len</span><spanclass="operator">+=</span><spanclass="literal number integer">4</span><spanclass="punctuation">;</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">line_len</span><spanclass="operator">></span><spanclass="name">limit</span><spanclass="punctuation">)</span><spanclass="keyword">return</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="keyword">for</span><spanclass="punctuation">(</span><spanclass="keyword type">int</span><spanclass="name">i</span><spanclass="operator">=</span><spanclass="literal number integer">0</span><spanclass="punctuation">;</span><spanclass="name">i</span><spanclass="operator"><</span><spanclass="name">e</span><spanclass="punctuation">.</span><spanclass="name">dict_size</span><spanclass="punctuation">();</span><spanclass="operator">++</span><spanclass="name">i</span><spanclass="punctuation">)</span>
<spanclass="punctuation">{</span>
<spanclass="name">line_len</span><spanclass="operator">+=</span><spanclass="literal number integer">4</span><spanclass="operator">+</span><spanclass="name">e</span><spanclass="punctuation">.</span><spanclass="name">dict_at</span><spanclass="punctuation">(</span><spanclass="name">i</span><spanclass="punctuation">).</span><spanclass="name">first</span><spanclass="punctuation">.</span><spanclass="name">size</span><spanclass="punctuation">();</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">line_len</span><spanclass="operator">></span><spanclass="name">limit</span><spanclass="punctuation">)</span><spanclass="keyword">return</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">ret</span><spanclass="operator">==</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">)</span><spanclass="keyword">return</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="name">line_len</span><spanclass="operator">+=</span><spanclass="name">ret</span><spanclass="operator">+</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="name">line_len</span><spanclass="operator">+=</span><spanclass="literal number integer">3</span><spanclass="operator">+</span><spanclass="name">e</span><spanclass="punctuation">.</span><spanclass="name">string_length</span><spanclass="punctuation">();</span>
<spanclass="keyword">while</span><spanclass="punctuation">(</span><spanclass="name">val</span><spanclass="operator">></span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">line_len</span><spanclass="operator">></span><spanclass="name">limit</span><spanclass="punctuation">)</span><spanclass="keyword">return</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">argc</span><spanclass="operator"><</span><spanclass="literal number integer">2</span><spanclass="operator">||</span><spanclass="name">argc</span><spanclass="operator">></span><spanclass="literal number integer">4</span><spanclass="punctuation">)</span>
<spanclass="keyword">return</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="punctuation">}</span>
<spanclass="keyword type">int</span><spanclass="name">item_limit</span><spanclass="operator">=</span><spanclass="literal number integer">1000000</span><spanclass="punctuation">;</span>
<spanclass="keyword type">int</span><spanclass="name">depth_limit</span><spanclass="operator">=</span><spanclass="literal number integer">1000</span><spanclass="punctuation">;</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">argc</span><spanclass="operator">></span><spanclass="literal number integer">2</span><spanclass="punctuation">)</span><spanclass="name">item_limit</span><spanclass="operator">=</span><spanclass="name">atoi</span><spanclass="punctuation">(</span><spanclass="name">argv</span><spanclass="punctuation">[</span><spanclass="literal number integer">2</span><spanclass="punctuation">]);</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">argc</span><spanclass="operator">></span><spanclass="literal number integer">3</span><spanclass="punctuation">)</span><spanclass="name">depth_limit</span><spanclass="operator">=</span><spanclass="name">atoi</span><spanclass="punctuation">(</span><spanclass="name">argv</span><spanclass="punctuation">[</span><spanclass="literal number integer">3</span><spanclass="punctuation">]);</span>
<spanclass="keyword type">int</span><spanclass="name">ret</span><spanclass="operator">=</span><spanclass="name">load_file</span><spanclass="punctuation">(</span><spanclass="name">argv</span><spanclass="punctuation">[</span><spanclass="literal number integer">1</span><spanclass="punctuation">],</span><spanclass="name">buf</span><spanclass="punctuation">,</span><spanclass="name">ec</span><spanclass="punctuation">,</span><spanclass="literal number integer">40</span><spanclass="operator">*</span><spanclass="literal number integer">1000000</span><spanclass="punctuation">);</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">ret</span><spanclass="operator">==</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">)</span>
<spanclass="punctuation">{</span>
<spanclass="name">fprintf</span><spanclass="punctuation">(</span><spanclass="name">stderr</span><spanclass="punctuation">,</span><spanclass="literal string">"file too big, aborting</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span><spanclass="punctuation">);</span>
<spanclass="keyword">return</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="punctuation">}</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">ret</span><spanclass="operator">!=</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="punctuation">{</span>
<spanclass="name">fprintf</span><spanclass="punctuation">(</span><spanclass="name">stderr</span><spanclass="punctuation">,</span><spanclass="literal string">"failed to load file: %s</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span><spanclass="punctuation">,</span><spanclass="name">ec</span><spanclass="punctuation">.</span><spanclass="name">message</span><spanclass="punctuation">().</span><spanclass="name">c_str</span><spanclass="punctuation">());</span>
<spanclass="keyword">return</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="keyword type">int</span><spanclass="name">pos</span><spanclass="operator">=</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="name">ret</span><spanclass="operator">=</span><spanclass="name">lazy_bdecode</span><spanclass="punctuation">(</span><spanclass="operator">&</span><spanclass="name">buf</span><spanclass="punctuation">[</span><spanclass="literal number integer">0</span><spanclass="punctuation">],</span><spanclass="operator">&</span><spanclass="name">buf</span><spanclass="punctuation">[</span><spanclass="literal number integer">0</span><spanclass="punctuation">]</span><spanclass="operator">+</span><spanclass="name">buf</span><spanclass="punctuation">.</span><spanclass="name">size</span><spanclass="punctuation">(),</span><spanclass="name">e</span><spanclass="punctuation">,</span><spanclass="name">ec</span><spanclass="punctuation">,</span><spanclass="operator">&</span><spanclass="name">pos</span>
<spanclass="name">printf</span><spanclass="punctuation">(</span><spanclass="literal string">"</span><spanclass="literal string escape">\n\n</span><spanclass="literal string">----- raw info -----</span><spanclass="literal string escape">\n\n</span><spanclass="literal string">%s</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span><spanclass="punctuation">,</span><spanclass="name">print_entry</span><spanclass="punctuation">(</span><spanclass="name">e</span><spanclass="punctuation">).</span><spanclass="name">c_str</span><spanclass="punctuation">());</span>
<spanclass="keyword">if</span><spanclass="punctuation">(</span><spanclass="name">ret</span><spanclass="operator">!=</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span>
<spanclass="punctuation">{</span>
<spanclass="name">fprintf</span><spanclass="punctuation">(</span><spanclass="name">stderr</span><spanclass="punctuation">,</span><spanclass="literal string">"failed to decode: '%s' at character: %d</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span><spanclass="punctuation">,</span><spanclass="name">ec</span><spanclass="punctuation">.</span><spanclass="name">message</span><spanclass="punctuation">().</span><spanclass="name">c_str</span><spanclass="punctuation">(),</span><spanclass="name">pos</span><spanclass="punctuation">);</span>
<spanclass="keyword">return</span><spanclass="literal number integer">1</span><spanclass="punctuation">;</span>
<spanclass="keyword type">char</span><spanclass="name">ih</span><spanclass="punctuation">[</span><spanclass="literal number integer">41</span><spanclass="punctuation">];</span>
<spanclass="name">to_hex</span><spanclass="punctuation">((</span><spanclass="keyword type">char</span><spanclass="keyword">const</span><spanclass="operator">*</span><spanclass="punctuation">)</span><spanclass="operator">&</span><spanclass="name">t</span><spanclass="punctuation">.</span><spanclass="name">info_hash</span><spanclass="punctuation">()[</span><spanclass="literal number integer">0</span><spanclass="punctuation">],</span><spanclass="literal number integer">20</span><spanclass="punctuation">,</span><spanclass="name">ih</span><spanclass="punctuation">);</span>
<spanclass="name">printf</span><spanclass="punctuation">(</span><spanclass="literal string">"number of pieces: %d</span><spanclass="literal string escape">\n</span><spanclass="literal string">"</span>
<spanclass="keyword">for</span><spanclass="punctuation">(</span><spanclass="keyword type">int</span><spanclass="name">i</span><spanclass="operator">=</span><spanclass="literal number integer">0</span><spanclass="punctuation">;</span><spanclass="name">i</span><spanclass="operator"><</span><spanclass="name">st</span><spanclass="punctuation">.</span><spanclass="name">num_files</span><spanclass="punctuation">();</span><spanclass="operator">++</span><spanclass="name">i</span><spanclass="punctuation">)</span>
<spanclass="punctuation">{</span>
<spanclass="keyword type">int</span><spanclass="name">first</span><spanclass="operator">=</span><spanclass="name">st</span><spanclass="punctuation">.</span><spanclass="name">map_file</span><spanclass="punctuation">(</span><spanclass="name">i</span><spanclass="punctuation">,</span><spanclass="literal number integer">0</span><spanclass="punctuation">,</span><spanclass="literal number integer">0</span><spanclass="punctuation">).</span><spanclass="name">piece</span><spanclass="punctuation">;</span>
<spanclass="keyword type">int</span><spanclass="name">last</span><spanclass="operator">=</span><spanclass="name">st</span><spanclass="punctuation">.</span><spanclass="name">map_file</span><spanclass="punctuation">(</span><spanclass="name">i</span><spanclass="punctuation">,</span><spanclass="punctuation">(</span><spanclass="name">std</span><spanclass="operator">::</span><spanclass="name">max</span><spanclass="punctuation">)(</span><spanclass="name">size_type</span><spanclass="punctuation">(</span><spanclass="name">st</span><spanclass="punctuation">.</span><spanclass="name">file_size</span><spanclass="punctuation">(</span><spanclass="name">i</span><spanclass="punctuation">))</span><spanclass="operator">-</span><spanclass="literal number integer">1</span><spanclass="punctuation">,</span><spanclass="name">size_type</span><spanclass="punctuation">(</span><spanclass="literal number integer">0</span><spanclass="punctuation">)),</span><spanclass="literal number integer">0</span><spanclass="punctuation">).</span><spanclass="name">piece</span><spanclass="punctuation">;</span>
<spanclass="punctuation">,</span><spanclass="name">st</span><spanclass="punctuation">.</span><spanclass="name">hash</span><spanclass="punctuation">(</span><spanclass="name">i</span><spanclass="punctuation">)</span><spanclass="operator">!=</span><spanclass="name">sha1_hash</span><spanclass="punctuation">(</span><spanclass="literal number integer">0</span><spanclass="punctuation">)</span><spanclass="operator">?</span><spanclass="name">to_hex</span><spanclass="punctuation">(</span><spanclass="name">st</span><spanclass="punctuation">.</span><spanclass="name">hash</span><spanclass="punctuation">(</span><spanclass="name">i</span><spanclass="punctuation">).</span><spanclass="name">to_string</span><spanclass="punctuation">()).</span><spanclass="name">c_str</span><spanclass="punctuation">()</span><spanclass="operator">:</span><spanclass="literal string">""</span>