<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Blog</title><link href="https://blog.tblein.eu/" rel="alternate"></link><link href="https://blog.tblein.eu/feeds/development.atom.xml" rel="self"></link><id>https://blog.tblein.eu/</id><updated>2016-11-12T00:00:00+01:00</updated><entry><title>Installing a specific version of Bioconductor</title><link href="https://blog.tblein.eu/development/2016/installing-a-specific-version-of-bioconductor/" rel="alternate"></link><published>2016-11-12T00:00:00+01:00</published><author><name>Thomas Blein</name></author><id>tag:blog.tblein.eu,2016-11-12:development/2016/installing-a-specific-version-of-bioconductor/</id><summary type="html">&lt;p&gt;&lt;a class="reference external" href="https://bioconductor.org"&gt;Bioconductor&lt;/a&gt; provide a list of R packages to
analyse high-throughput genomic data. Every six months a new version of
Bioconductor is released fixing the version of the included packages.
It is always nice to come back to the same version of packages that generated the
results.&lt;/p&gt;
&lt;p&gt;Bioconductor versions are bound to R versions. So depending of the version of
R you are using a limited number of Bioconductor versions are available. Using
the default installation method of the Bioconductor the last version available
for the R version is installed. We will see how to install a different version.&lt;/p&gt;
&lt;div class="section" id="install-a-specific-version-of-bioconductor"&gt;
&lt;h2&gt;Install a specific version of Bioconductor&lt;/h2&gt;
&lt;p&gt;To install a specific version of Bioconductor, we need to use the installer of
that version. To do so, we need to install the installer of the wondered
version. The installer is in the &lt;code&gt;BiocInstaller&lt;/code&gt; package we just need to
use the correct repository to install it.&lt;/p&gt;
&lt;p&gt;For example to install Bioconductor 3.1:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;install.packages&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;BiocInstaller&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 repos&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;http://bioconductor.org/packages/3.1/bioc&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then load the &lt;code&gt;BiocInstaller&lt;/code&gt; package as usual with &lt;code&gt;library&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;library&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;BiocInstaller&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then install Bioconductor packages as usual with then &lt;code&gt;biocLite()&lt;/code&gt;
function.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="downgrade-of-already-installed-packages"&gt;
&lt;h2&gt;Downgrade of already installed packages&lt;/h2&gt;
&lt;p&gt;In case you already install a more recent version of Bioconductor you can easily
downgrade the packages to fit the Bioconductor version.&lt;/p&gt;
&lt;p&gt;After loading the &lt;code&gt;BiocInstaller&lt;/code&gt; you can have information about the
Bioconductor installation with the &lt;code&gt;biocValid()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For example&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;&amp;gt; &lt;/span&gt;biocValid&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="go"&gt;* sessionInfo()&lt;/span&gt;

&lt;span class="go"&gt;R version 3.2.4 Revised (2016-03-16 r70336)&lt;/span&gt;
&lt;span class="go"&gt;Platform: x86_64-pc-linux-gnu (64-bit)&lt;/span&gt;
&lt;span class="go"&gt;Running under: Debian GNU/Linux 8 (jessie)&lt;/span&gt;

&lt;span class="go"&gt;locale:&lt;/span&gt;
&lt;span class="go"&gt; [1] LC_CTYPE=fr_FR.UTF-8       LC_NUMERIC=C&lt;/span&gt;
&lt;span class="go"&gt; [3] LC_TIME=fr_FR.UTF-8        LC_COLLATE=fr_FR.UTF-8&lt;/span&gt;
&lt;span class="go"&gt; [5] LC_MONETARY=fr_FR.UTF-8    LC_MESSAGES=fr_FR.UTF-8&lt;/span&gt;
&lt;span class="go"&gt; [7] LC_PAPER=fr_FR.UTF-8       LC_NAME=C&lt;/span&gt;
&lt;span class="go"&gt; [9] LC_ADDRESS=C               LC_TELEPHONE=C&lt;/span&gt;
&lt;span class="go"&gt;[11] LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C&lt;/span&gt;

&lt;span class="go"&gt;attached base packages:&lt;/span&gt;
&lt;span class="go"&gt;[1] stats     graphics  grDevices utils     datasets  methods   base&lt;/span&gt;

&lt;span class="go"&gt;other attached packages:&lt;/span&gt;
&lt;span class="go"&gt;[1] BiocInstaller_1.18.5&lt;/span&gt;

&lt;span class="go"&gt;loaded via a namespace (and not attached):&lt;/span&gt;
&lt;span class="go"&gt;[1] tools_3.2.4&lt;/span&gt;

&lt;span class="go"&gt;* Packages too new for Bioconductor version &amp;#39;3.1&amp;#39;&lt;/span&gt;

&lt;span class="go"&gt;                  Version  LibPath&lt;/span&gt;
&lt;span class="go"&gt;annotate          &amp;quot;1.48.0&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;AnnotationDbi     &amp;quot;1.32.3&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;Biobase           &amp;quot;2.30.0&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;BiocGenerics      &amp;quot;0.16.1&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;BiocParallel      &amp;quot;1.4.3&amp;quot;  &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;Biostrings        &amp;quot;2.38.4&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;DESeq2            &amp;quot;1.10.1&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;genefilter        &amp;quot;1.52.1&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;geneplotter       &amp;quot;1.48.0&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;GenomeInfoDb      &amp;quot;1.6.3&amp;quot;  &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;GenomicAlignments &amp;quot;1.6.3&amp;quot;  &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;GenomicRanges     &amp;quot;1.22.4&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;IRanges           &amp;quot;2.4.8&amp;quot;  &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;Rsamtools         &amp;quot;1.22.0&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;rtracklayer       &amp;quot;1.30.4&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;S4Vectors         &amp;quot;0.8.11&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;XVector           &amp;quot;0.10.0&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;
&lt;span class="go"&gt;zlibbioc          &amp;quot;1.16.0&amp;quot; &amp;quot;/home/tblein/bin/R_3.2.4/lib/R/library&amp;quot;&lt;/span&gt;

&lt;span class="go"&gt;downgrade with biocLite(c(&amp;quot;annotate&amp;quot;, &amp;quot;AnnotationDbi&amp;quot;, &amp;quot;Biobase&amp;quot;, &amp;quot;BiocGenerics&amp;quot;,&lt;/span&gt;
&lt;span class="go"&gt;  &amp;quot;BiocParallel&amp;quot;, &amp;quot;Biostrings&amp;quot;, &amp;quot;DESeq2&amp;quot;, &amp;quot;genefilter&amp;quot;, &amp;quot;geneplotter&amp;quot;,&lt;/span&gt;
&lt;span class="go"&gt;  &amp;quot;GenomeInfoDb&amp;quot;, &amp;quot;GenomicAlignments&amp;quot;, &amp;quot;GenomicRanges&amp;quot;, &amp;quot;IRanges&amp;quot;, &amp;quot;Rsamtools&amp;quot;,&lt;/span&gt;
&lt;span class="go"&gt;  &amp;quot;rtracklayer&amp;quot;, &amp;quot;S4Vectors&amp;quot;, &amp;quot;XVector&amp;quot;, &amp;quot;zlibbioc&amp;quot;))&lt;/span&gt;

&lt;span class="go"&gt;Erreur : 18 package(s) too new&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;So as indicated by &lt;code&gt;biocValid()&lt;/code&gt;, to downgrade all the package you just
need to run the &lt;code&gt;biocLite()&lt;/code&gt; function with the packages you would like to
downgrade.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="sources"&gt;
&lt;h2&gt;Sources&lt;/h2&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="https://bioconductor.org"&gt;Bioconductor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://stackoverflow.com/questions/19589064/downgrade-r-version-and-r-package-bioconductor"&gt;Downgrade R version and R package Bioconductor [duplicate]&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</summary><category term="R"></category><category term="Bioconductor"></category><category term="Version"></category><category term="Downgrade."></category></entry><entry><title>How to organise the source code of "templates"</title><link href="https://blog.tblein.eu/development/2016/how-to-organise-the-source-code-of-templates/" rel="alternate"></link><published>2016-07-23T00:00:00+02:00</published><author><name>Thomas Blein</name></author><id>tag:blog.tblein.eu,2016-07-23:development/2016/how-to-organise-the-source-code-of-templates/</id><summary type="html">&lt;p&gt;In C and C++, we normally separate the declaration and the definition of
a function in two separated files: the header file contain the declaration of
the function (&lt;code&gt;.h&lt;/code&gt; or &lt;code&gt;.hh&lt;/code&gt; file) and the source code itself which
contain the definition of the function (&lt;code&gt;.c&lt;/code&gt; or &lt;code&gt;.cpp&lt;/code&gt; file). When
we would like to do the same with function containing template we get an error
of type &lt;code&gt;undefined reference to&lt;/code&gt; when the function is first used in code.&lt;/p&gt;
&lt;div class="section" id="an-example"&gt;
&lt;h2&gt;An example&lt;/h2&gt;
&lt;p&gt;For example let's suppose that the &lt;code&gt;addition&lt;/code&gt; function return the sum of
two numbers of same type.&lt;/p&gt;
&lt;p&gt;First the header file (&lt;code&gt;addition.hh&lt;/code&gt;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typename&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;addition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then the function source code (&lt;code&gt;addition.cc&lt;/code&gt;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typename&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;addition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Finally a small program using this function (&lt;code&gt;main.cc&lt;/code&gt;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;quot;addition.hh&amp;quot;&lt;/span&gt;&lt;span class="cp"&gt;&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;addition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;While the code looks correct, the links creation will broke with the following
error:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;/tmp/ccEpROXj.o&lt;span class="o"&gt;(&lt;/span&gt;.text+0x17c&lt;span class="o"&gt;)&lt;/span&gt;: In &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="sb"&gt;`&lt;/span&gt;main&lt;span class="s1"&gt;&amp;#39;:&lt;/span&gt;
&lt;span class="s1"&gt;: undefined reference to `addition(int, int)&amp;#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="why"&gt;
&lt;h2&gt;Why?&lt;/h2&gt;
&lt;p&gt;There are different reasons that this error appear. It is mainly because
a template is not a function but a model used to generate the function. When it
used by a program to generate the real function, the definition should be known
and not only it's declaration.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="how-to-solved-it"&gt;
&lt;h2&gt;How to solved it.&lt;/h2&gt;
&lt;p&gt;There is several solution to that problem.&lt;/p&gt;
&lt;div class="section" id="the-insertion-of-the-definition-in-the-header-file"&gt;
&lt;h3&gt;The insertion of the definition in the header file.&lt;/h3&gt;
&lt;p&gt;The first one is to include the definition in the header file. For that, we only
need to fuse the two files (header and source code) in only one file or to
include the source code file with an &lt;code&gt;include&lt;/code&gt; preprocessing command at
the end of the header file. This solution is the easiest one, but not the
results is not so clean. Indeed, some compilers can increase dramatically the
size of the resulting binary.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="adding-a-template-specialisation"&gt;
&lt;h3&gt;Adding a template specialisation&lt;/h3&gt;
&lt;p&gt;FIXME: To be confirmed&lt;/p&gt;
&lt;p&gt;We can also add the declaration of the specialisation that we want in the source
code of the function.&lt;/p&gt;
&lt;p&gt;For example, for the previous &lt;code&gt;addition&lt;/code&gt; function, we can specify the
declaration for types &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt; and &lt;code&gt;double&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typename&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;addition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;template&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;addition&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;template&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;addition&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;template&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;addition&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="by-using-the-export-keyword"&gt;
&lt;h3&gt;By using the &lt;code&gt;export&lt;/code&gt; keyword.&lt;/h3&gt;
&lt;p&gt;FIXME&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="sources"&gt;
&lt;h2&gt;Sources&lt;/h2&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12"&gt;[35.12] Why can't I separate the definition of my templates class from it's
declaration and put it inside a .cpp file?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.parashift.com/c++-faq-lite/templates.html#faq-35.13"&gt;[35.13] How can I avoid linker errors with my template functions?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.parashift.com/c++-faq-lite/templates.html#faq-35.14"&gt;[35.14] How does the C++ keyword export help with template linker errors?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</summary><category term="template"></category><category term="compilation error"></category><category term="C++"></category></entry><entry><title>abort: requirement 'fncache' not supported!</title><link href="https://blog.tblein.eu/development/2016/mercurial_fncache/" rel="alternate"></link><published>2016-07-23T00:00:00+02:00</published><author><name>Thomas Blein</name></author><id>tag:blog.tblein.eu,2016-07-23:development/2016/mercurial_fncache/</id><summary type="html">&lt;p&gt;It can append that when we try to access a &lt;a class="reference external" href="http://mercurial.selenic.com"&gt;Mercurial&lt;/a&gt; repository we got the following error:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;abort: requirement &lt;span class="s1"&gt;&amp;#39;fncache&amp;#39;&lt;/span&gt; not supported!
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It append when a &amp;quot;too old&amp;quot; version of &lt;a class="reference external" href="http://mercurial.selenic.com"&gt;Mercurial&lt;/a&gt; is used. Indeed, from version
1.1, &lt;a class="reference external" href="http://mercurial.selenic.com"&gt;Mercurial&lt;/a&gt; used a new repository format (&lt;code&gt;fncache&lt;/code&gt;), which is no more readable
by the former versions. The reverse is not true, and newer version are able to
read old repositories.&lt;/p&gt;
&lt;p&gt;To solve the problem we can use a version of &lt;a class="reference external" href="http://mercurial.selenic.com"&gt;Mercurial&lt;/a&gt; able to read the two type
of repository and convert it to the old format using the following command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;hg --config format.usefncache&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt; clone --pull A B
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;With &lt;code&gt;A&lt;/code&gt; the initial repository and &lt;code&gt;B&lt;/code&gt; the converted repository.&lt;/p&gt;
&lt;p&gt;To completely deactivate the new repository format, a modification the
configuration file of &lt;a class="reference external" href="http://mercurial.selenic.com"&gt;Mercurial&lt;/a&gt; is needed (&lt;code&gt;~/.hgrc&lt;/code&gt;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;[format]&lt;/span&gt;
&lt;span class="na"&gt;usefncache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;False&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="section" id="sources"&gt;
&lt;h2&gt;Sources&lt;/h2&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://mercurial.selenic.com/wiki/fncacheRepoFormat"&gt;fncacheRepoFormat&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</summary><category term="Mercurial"></category><category term="fncache"></category><category term="DVCS"></category></entry><entry><title>Unrealated repository fusion (mercurial abort: repository is unrelated)</title><link href="https://blog.tblein.eu/development/2016/mercurial_repositories_fusion/" rel="alternate"></link><published>2016-07-23T00:00:00+02:00</published><author><name>Thomas Blein</name></author><id>tag:blog.tblein.eu,2016-07-23:development/2016/mercurial_repositories_fusion/</id><summary type="html">&lt;p&gt;When we try to include a repository in an other while they never had any common
point we got the following error:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ hg push ../second
mercurial abort: repository is unrelated
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To go above it we need to force the fusion with the &lt;code&gt;-f&lt;/code&gt; option:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ hg push -f ../second
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="section" id="sources"&gt;
&lt;h2&gt;Sources&lt;/h2&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.selenic.com/mercurial/hg.1.html"&gt;hg man page&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</summary><category term="Mercurial"></category><category term="fusion"></category><category term="DVCS"></category></entry><entry><title>Deconnected subversion with SVK</title><link href="https://blog.tblein.eu/development/2016/svk/" rel="alternate"></link><published>2016-07-23T00:00:00+02:00</published><author><name>Thomas Blein</name></author><id>tag:blog.tblein.eu,2016-07-23:development/2016/svk/</id><summary type="html">&lt;div class="section" id="svk-installation"&gt;
&lt;h2&gt;SVK installation&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;apt-get install svk&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Create a local repository with the following command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;svk depotmap --init&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="create-a-local-repository-mirror"&gt;
&lt;h2&gt;Create a local repository mirror&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;svk mirror svn://adresse_du_depot_distant.ex //local/nom_local_du_depot&lt;/span&gt;
&lt;span class="go"&gt;svk sync //local/nom_local_du_depot&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Create a workingcopy from the local repository mirror:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;svk checkout //local/nom_local_du_depot repertoire&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="local-use-of-svk"&gt;
&lt;h2&gt;Local use of SVK&lt;/h2&gt;
&lt;p&gt;Add some files/folders to version control&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;svk add fichier&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Commit to the loacl repository mirror&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;svk commit&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Push the modifications of the local mirror repository to the distant repository:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;svk push&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="sources"&gt;
&lt;h2&gt;Sources&lt;/h2&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://articles.mongueurs.net/magazines/linuxmag94.html"&gt;SVK par les Mongueurs de Perl&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</summary><category term="SVN"></category><category term="DVCS"></category></entry><entry><title>po regex</title><link href="https://blog.tblein.eu/development/2012/po-regex/" rel="alternate"></link><published>2012-09-04T00:42:19+02:00</published><author><name>Thomas Blein</name></author><id>tag:blog.tblein.eu,2012-09-04:development/2012/po-regex/</id><summary type="html">&lt;p&gt;Some notes to be able to construct a small program able to apply a regex to
translated string of a po file&lt;/p&gt;
&lt;p&gt;Will be done certainly in python:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://pypi.python.org/pypi/polib"&gt;polib&lt;/a&gt; python module to be able to
handle the po files seems quite simple to use according to the &lt;a class="reference external" href="http://polib.readthedocs.org/en/latest/quickstart.html"&gt;Quick start
guide&lt;/a&gt;. In addition
&lt;a class="reference external" href="http://packages.debian.org/search?keywords=python-polib"&gt;polib is included in Debian
repository&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Finally the &lt;a class="reference external" href="http://docs.python.org/library/re.html"&gt;python regex module re&lt;/a&gt;. &lt;a class="reference external" href="http://docs.python.org/howto/regex"&gt;The official Howto on regex in
python&lt;/a&gt;. The regex are not set as in
perl but with a regex, the on the perl regex the two parts could be extract
easily.&lt;/li&gt;
&lt;li&gt;command line arguments parse with &lt;a class="reference external" href="http://docs.python.org/library/argparse"&gt;argparse&lt;/a&gt; as usual&lt;/li&gt;
&lt;/ul&gt;
</summary><category term="python"></category><category term="po"></category><category term="regex"></category></entry><entry><title>Redirecting sderr to a pipe</title><link href="https://blog.tblein.eu/development/2012/redirecting-sderr-to-a-pipe/" rel="alternate"></link><published>2012-07-31T11:36:06+02:00</published><author><name>Thomas Blein</name></author><id>tag:blog.tblein.eu,2012-07-31:development/2012/redirecting-sderr-to-a-pipe/</id><summary type="html">&lt;p&gt;Programs are sending message on two different steam of data: standard output and
standard error. Standard output, notes as &lt;code&gt;stdout&lt;/code&gt;,  is where the program
is writing the output data. Standard error or &lt;code&gt;stderr&lt;/code&gt; is to output the
error messages or diagnostics. With this two stream we can therefore separate
between these two kind of output and process them separately. A third stream of
data exist, that is standard input or stdin, which correspond to the entry of
data for a program.&lt;/p&gt;
&lt;p&gt;Classical shell programming involved to play with these different stream of
data, where the &lt;code&gt;stdout&lt;/code&gt; of one program is pipe to the &lt;code&gt;stdin&lt;/code&gt; of an
other program to get the desired functionality. One of this task is to filter
the output of a command with &lt;code&gt;grep&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$  ls -1
Desktop
Documents
Pictures
Videos
Download
Music
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$  ls -1 &lt;span class="p"&gt;|&lt;/span&gt; grep D
Desktop
Documents
Download
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;However, pipe is only for redirection of &lt;code&gt;stdout&lt;/code&gt; to the &lt;code&gt;stdin&lt;/code&gt;.
Sometime we would like to filter the &lt;code&gt;stderr&lt;/code&gt; and not the &lt;code&gt;sdtout&lt;/code&gt;.
Therefore we need to redirect the stream so they can be processed correcrtly.&lt;/p&gt;
&lt;p&gt;First we can redirect &lt;code&gt;stderr&lt;/code&gt; to &lt;code&gt;stdout&lt;/code&gt; and mix the two output
that will be then filtered:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ myprog 2&amp;gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; grep something
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In the same time we can destroy the output of &lt;code&gt;stdout&lt;/code&gt; and only keep
&lt;code&gt;stderr&lt;/code&gt; to be filtered:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ myprog 2&amp;gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &amp;gt; /dev/null &lt;span class="p"&gt;|&lt;/span&gt; grep something
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You have to be carefull in the order of the command since the following do not
seems to work as expected, both stream being redirected to /dev/null&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ myprog &amp;gt; /dev/null  2&amp;gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;1&lt;span class="p"&gt;|&lt;/span&gt; grep something
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="section" id="source"&gt;
&lt;h2&gt;Source&lt;/h2&gt;
&lt;p&gt;&lt;a class="reference external" href="http://mywiki.wooledge.org/BashFAQ/047"&gt;How can I redirect stderr to a pipe?&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
</summary><category term="pipe"></category><category term="bash"></category></entry><entry><title>po files handling</title><link href="https://blog.tblein.eu/development/2012/po_file_handling/" rel="alternate"></link><published>2012-07-05T22:41:31+02:00</published><author><name>Thomas Blein</name></author><id>tag:blog.tblein.eu,2012-07-05:development/2012/po_file_handling/</id><summary type="html">&lt;p&gt;po files are used by programs to translate the messages in different
languages. Thus they contain a list of all translatable strings
extracted from the code and their corresponding translation, in a given
language. Here are given some information to manipulate and few resources to
help the translation, mainly derived from experiments in for &lt;a class="reference external" href="http://www.debian.org/international/french/"&gt;Debian project
translation to French&lt;/a&gt;.&lt;/p&gt;
&lt;div class="section" id="file-formating"&gt;
&lt;h2&gt;File formating&lt;/h2&gt;
&lt;p&gt;For ease of reading text files on any type of screen it is common to limit the
size of their line to 80 characters. The following command allows to cut the
lines at 80 characters while maintaining the specific labeling of po files:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ msgcat fr.po -o fr.po
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can specify the length of a line to another value if necessary with the
&lt;code&gt;-w&lt;/code&gt; option. So to format a po file with 40 characters:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ msgcat -w40 fr.po -o fr.po
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="section" id="update-of-a-file-while-already-start-the-translation"&gt;
&lt;h3&gt;Update of a file while already start the translation&lt;/h3&gt;
&lt;p&gt;When translating sometimes the original po file have been updated while your
translation is not finished. The following command can update your po file
(fr.po) with new data from the new file (&lt;code&gt;fr.new.po&lt;/code&gt;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ msgmerge --update --previous fr.po fr.new.po
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can continue on your translation on the updated &lt;code&gt;fr.po&lt;/code&gt; file.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="resources"&gt;
&lt;h2&gt;Resources&lt;/h2&gt;
&lt;div class="section" id="general"&gt;
&lt;h3&gt;General&lt;/h3&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Translation proposition database based on already translated FLOSS projects: &lt;a class="reference external" href="http://open-tran.eu/"&gt;http://open-tran.eu/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class="section" id="debian-specific-french-translation-team"&gt;
&lt;h3&gt;Debian specific (French translation team)&lt;/h3&gt;
&lt;div class="section" id="help"&gt;
&lt;h4&gt;Help&lt;/h4&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.debian.org/international/french/lexique"&gt;English-French lexicon&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.debian.org/international/french/typographie"&gt;French Typography&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class="section" id="status-and-coordination"&gt;
&lt;h4&gt;Status and coordination&lt;/h4&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://i18n.debian.net/debian-l10n/french/fr.by_status.html"&gt;French status and coordination page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.debian.org/international/l10n/po/fr"&gt;Status of PO files for language code: fr – French&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.debian.org/international/l10n/po-debconf/fr"&gt;Status of Debconf templates l10n with PO files for language code: fr – French&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.debian.org/international/l10n/po-debconf/pot"&gt;PO files for Debconf templates — Original files&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.debian.org/intl/l10n/po4a/fr"&gt;Status of PO files managed with po4a for language code: fr — French&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</summary><category term="po"></category><category term="l10n"></category><category term="tips"></category><category term="Debian"></category></entry><entry><title>Perl and UTF-8</title><link href="https://blog.tblein.eu/development/2012/perl-and-utf-8/" rel="alternate"></link><published>2012-05-08T01:20:03+02:00</published><author><name>Thomas Blein</name></author><id>tag:blog.tblein.eu,2012-05-08:development/2012/perl-and-utf-8/</id><summary type="html">&lt;p&gt;Like with python, the handling of [[!wikipedia UTF-8]] string in perl is not
straight forward since this language was not originally design to handle Unicode
strings of characters.&lt;/p&gt;
&lt;div class="section" id="correct-length-of-utf-8-string"&gt;
&lt;h2&gt;Correct length of UTF-8 string&lt;/h2&gt;
&lt;p&gt;[[!wikipedia ASCII]] characters are coded on 8bits that is on one octet. That
explain the limited number of different characters and the different encodings
according to language. Unicode try to solve it by encoding it on several
a dynamic number of octet depending of the characters. Therefore some characters
are only coded on one octet (the one that are present in the [[!wikipedia
ASCII]] set) some other on two octets.&lt;/p&gt;
&lt;p&gt;By default in perl the strings are [[!wikipedia ASCII]] and therefore to
determine their length with the length function it only count the number of
octet. That fit perfectly when the characters are coded only on one octet but in
a lot of language the some used characters are coded on several octets. The
length is therefore longer, for example in the following script:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="ch"&gt;#! /usr/bin/env perl&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Ceci est une chaîne avec trois caractères codés sur deux octets&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nb"&gt;length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;\n&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ ./test.pl
66
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In fact there are 63 characters in this string.&lt;/p&gt;
&lt;p&gt;To get the real string length a conversion of the format is needed. For that the
Encode module need to be use to decode the [[!wikipedia UTF-8]] string before
measuring its length:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="ch"&gt;#! /usr/bin/env perl&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="n"&gt;Encode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;my&lt;/span&gt; &lt;span class="nv"&gt;$string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Ceci est une chaîne avec trois caractères codés sur deux octets&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nb"&gt;length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;Encode::&lt;/span&gt;&lt;span class="n"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;utf-8&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;$string&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;\n&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ ./test.pl
63
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This time the correct size of the string is returned&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="wide-character-in-print"&gt;
&lt;h2&gt;Wide character in print&lt;/h2&gt;
&lt;p&gt;When printing some [[!wikipedia UTF-8]] string on the console it may append that
the following error appear:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;Wide character in print at test.pl line 3.
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To remove of it just add the folling entry at the beginning of your script:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;utf-8&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="resources"&gt;
&lt;h2&gt;Resources&lt;/h2&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.linuxask.com/questions/wide-character-in-print-warning-in-perl"&gt;Wide character in print… warning in Perl&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</summary><category term="perl"></category><category term="utf-8"></category></entry><entry><title>Preventing multiple executions of a Makefile</title><link href="https://blog.tblein.eu/development/2012/preventing-multiple-executions-of-a-makefile/" rel="alternate"></link><published>2012-05-01T17:21:48+02:00</published><author><name>Thomas Blein</name></author><id>tag:blog.tblein.eu,2012-05-01:development/2012/preventing-multiple-executions-of-a-makefile/</id><summary type="html">&lt;p&gt;Often the automatic builds are controlled by the &lt;code&gt;make&lt;/code&gt; tools using the
rules defined in so named &lt;code&gt;Makefile&lt;/code&gt;. &lt;code&gt;make&lt;/code&gt; is very nice since it
allow a smooth control of the build with a direct link with dependencies.
Therefore only what is need to be build is built. A rule is executed only when the
dependencies are younger than the target for that rule.&lt;/p&gt;
&lt;p&gt;To automate the builds regularly the construction might be run regularly via
&lt;code&gt;cron&lt;/code&gt; jobs. However, if the time in between the &lt;code&gt;make&lt;/code&gt; runs is
smaller than the time required to perform a particular task, this task will be
run several time and filled the resources of the computer. To prevent it we can
setup a protection on the &lt;code&gt;Makefile&lt;/code&gt; to prevent it to be executed several
times at a given time.&lt;/p&gt;
&lt;div class="section" id="lock-file"&gt;
&lt;h2&gt;Lock file&lt;/h2&gt;
&lt;p&gt;To prevent the multiple execution of the &lt;code&gt;Makefile&lt;/code&gt; we will use a so called lock
file. When the &lt;code&gt;Makefile&lt;/code&gt; is execute it will create a file with a particular name.
This is our lock file. When it finish to execute, it just delete this file. In case
the &lt;code&gt;Makefile&lt;/code&gt; is run a second time in parallel, it will see that the lock file
exist and stop the processing.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="setting-up-lock-files-inside-a-makefile"&gt;
&lt;h2&gt;Setting up lock files inside a Makefile&lt;/h2&gt;
&lt;p&gt;To determine the existence of the file we will use the unix command &lt;code&gt;ls&lt;/code&gt;
that will return the name of the lock file if it exist else nothing. We will
catch it in a make variable:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;LOCKFILEEXIST&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;$(&lt;/span&gt;shell ls &lt;span class="k"&gt;$(&lt;/span&gt;LOCKFILE&lt;span class="k"&gt;)&lt;/span&gt; 2&amp;gt; /dev/null&lt;span class="k"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then we test if this variable is empty or not. In case it is not empty, we exit
with an error:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="cp"&gt;ifneq ($(LOCKFILEEXIST), )&lt;/span&gt;
&lt;span class="k"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;error&lt;/span&gt; &amp;quot;&lt;span class="nv"&gt;already&lt;/span&gt; &lt;span class="nv"&gt;running&lt;/span&gt;&amp;quot;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="cp"&gt;endif&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In case we the lock file does not exist we continue the process and set the lock
file.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;shell&lt;/span&gt; &lt;span class="nv"&gt;touch&lt;/span&gt; &lt;span class="k"&gt;$&lt;/span&gt;(&lt;span class="nv"&gt;LOCKFILE&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then follow the rest of the &lt;code&gt;Makefile&lt;/code&gt; like usual. We just need to remove the lock
file at the end of the rpocessing. For this we add it at the end of the all
rules that is the main run.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    @echo &lt;span class="s2"&gt;&amp;quot;processed&amp;quot;&lt;/span&gt;
    &lt;span class="k"&gt;$(&lt;/span&gt;shell rm -f &lt;span class="k"&gt;$(&lt;/span&gt;LOCKFILE&lt;span class="k"&gt;))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This command should be add to all rules that terminate the run, otherwise future
run might be blocked even no &lt;code&gt;Makefile&lt;/code&gt; is running&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="testing-it"&gt;
&lt;h2&gt;Testing it&lt;/h2&gt;
&lt;p&gt;The final test &lt;code&gt;Makefile&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c"&gt;# Definition of the lockfile&lt;/span&gt;
&lt;span class="nv"&gt;LOCKFILE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;test.lock&amp;quot;&lt;/span&gt;

&lt;span class="c"&gt;# Search for the lock file&lt;/span&gt;
&lt;span class="nv"&gt;LOCKFILEEXIST&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;$(&lt;/span&gt;shell ls &lt;span class="k"&gt;$(&lt;/span&gt;LOCKFILE&lt;span class="k"&gt;)&lt;/span&gt; 2&amp;gt; /dev/null&lt;span class="k"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# if the lock file exist exit&lt;/span&gt;
&lt;span class="cp"&gt;ifneq ($(LOCKFILEEXIST), )&lt;/span&gt;
&lt;span class="k"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;error&lt;/span&gt; &amp;quot;&lt;span class="nv"&gt;already&lt;/span&gt; &lt;span class="nv"&gt;running&lt;/span&gt;&amp;quot;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="cp"&gt;endif&lt;/span&gt;

&lt;span class="c"&gt;# Create the lock file&lt;/span&gt;
&lt;span class="k"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;shell&lt;/span&gt; &lt;span class="nv"&gt;touch&lt;/span&gt; &lt;span class="k"&gt;$&lt;/span&gt;(&lt;span class="nv"&gt;LOCKFILE&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# process and remove the lock file&lt;/span&gt;
&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    @echo &lt;span class="s2"&gt;&amp;quot;processed&amp;quot;&lt;/span&gt;
    &lt;span class="k"&gt;$(&lt;/span&gt;shell rm -f &lt;span class="k"&gt;$(&lt;/span&gt;LOCKFILE&lt;span class="k"&gt;))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Without any lock file the execution is done and like this several time:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ make all
processed
$ make all
processed
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;When a lock file exist the Makefile stop with an error:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ touch test.lock
$ make all
 Makefile:5: *** &lt;span class="s2"&gt;&amp;quot;already running&amp;quot;&lt;/span&gt;. Stop.
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
</summary><category term="Makefile"></category><category term="multiprocessing"></category></entry><entry><title>Writting UTF-8 strings in python</title><link href="https://blog.tblein.eu/development/2012/writting-utf-8-strings-in-python/" rel="alternate"></link><published>2012-05-01T14:48:48+02:00</published><author><name>Thomas Blein</name></author><id>tag:blog.tblein.eu,2012-05-01:development/2012/writting-utf-8-strings-in-python/</id><summary type="html">&lt;p&gt;When processing some strings in python you may have to deal with special
characters. You test your code with some output on the standard output and
everything is working. However when you want to write your string you have
complains like the following:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="ne"&gt;UnicodeError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ascii&lt;/span&gt; &lt;span class="n"&gt;codec&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;t decode byte 0x85 in position 255: oridinal not in range(128)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="section" id="what-is-the-problem"&gt;
&lt;h2&gt;What is the problem?&lt;/h2&gt;
&lt;p&gt;The problem comes from the fact that when writing in the file, python use the
[[!wikipedia ASCII]] coding that code characters on 8bits and have only 128
different characters, while your string is encodes with a higher number of
characters. On most current Unix the default character encoding is [[!wikipedia
UTF-8]] that code characters with a variable number of bits. So it may appends
that some of the characters you want to write are no more in the set of
[[!wikipedia ASCII]]. There is no problem when printing on the standard output,
because your console is certainly in [[!wikipedia UTF-8]] also.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="how-to-solve-it"&gt;
&lt;h2&gt;How to solve it?&lt;/h2&gt;
&lt;p&gt;In python there are to sort of structures that handle list of characters:
strings and unicode. The strings are using [[!wikipedia ASCII]] and unicode are
using Unicode as their name shows it.&lt;/p&gt;
&lt;p&gt;To be able to write a string encodes with [[!wikipedia UTF-8]] you first need to
transform it as unicode.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;my_utf8_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;A string with some UTF-8 characters °&amp;quot;&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;my_utf8_string&lt;/span&gt;
&lt;span class="s1"&gt;&amp;#39;A string with some UTF-8 characters &lt;/span&gt;&lt;span class="se"&gt;\xc2\xb0&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;converted_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;unicode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_utf8_string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;utf-8&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;converted_string&lt;/span&gt;
&lt;span class="s1"&gt;u&amp;#39;A string with some UTF-8 characters &lt;/span&gt;&lt;span class="se"&gt;\xb0&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then you need to open the file as [[!wikipedia UTF-8]] with the &lt;code&gt;codecs&lt;/code&gt;
python module and save your unicode string as with a normal file handling.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;codecs&lt;/span&gt;
&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;codecs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;/tmp/test&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;w&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;utf-8&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;outFile&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;outFile&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;converted_string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That's all.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="resources"&gt;
&lt;h2&gt;Resources&lt;/h2&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.evanjones.ca/python-utf8.html"&gt;How to Use UTF-8 with Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://docs.python.org/library/codecs.html"&gt;codecs — Codec registry and base classes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://docs.python.org/library/string.html"&gt;string — Common string operations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://docs.python.org/library/unicodedata.html"&gt;unicodedata — Unicode Database&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</summary><category term="python"></category><category term="UTF-8"></category></entry><entry><title>C++ links</title><link href="https://blog.tblein.eu/development/2010/c-links/" rel="alternate"></link><published>2010-09-09T00:00:00+02:00</published><author><name>Thomas Blein</name></author><id>tag:blog.tblein.eu,2010-02-09:development/2010/c-links/</id><summary type="html">&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.parashift.com/c++-faq-lite/index.html"&gt;C++ FAQ LITE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://stackoverflow.com/questions/9410/how-do-you-pass-a-function-as-a-parameter-in-c"&gt;How do you pass a function as a parameter in C?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</summary><category term="links"></category><category term="C++"></category></entry></feed>