<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>mauke</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/mauke/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/mauke/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/mauke//343</id>
    <updated>2012-11-23T03:42:59Z</updated>
    <subtitle>A blog about stuff</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>Cool things you can do with Perl 5.14</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/mauke/2012/11/cool-things-you-can-do-with-perl-514.html" />
    <id>tag:blogs.perl.org,2012:/users/mauke//343.4062</id>

    <published>2012-11-23T03:38:28Z</published>
    <updated>2012-11-23T03:42:59Z</updated>

    <summary>Perl 5.12.0 introduced pluggable keywords. This feature lets a module author extend Perl by defining custom keywords, at least as long as that module author knows XS and how to construct OP trees manually. Perl 5.14.0 added many functions to...</summary>
    <author>
        <name>mauke</name>
        
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/mauke/">
        <![CDATA[<p>Perl 5.12.0 introduced
<a href="http://perldoc.perl.org/perl5120delta.html#Pluggable-keywords">pluggable keywords</a>.
This feature lets a module author extend Perl by defining custom keywords, at
least as long as that module author knows
<a href="http://perldoc.perl.org/perlxs.html">XS</a> and how to construct <code>OP</code> trees
manually.</p>

<p>Perl 5.14.0
<a href="http://perldoc.perl.org/perl5140delta.html#Internal-Changes">added many functions to the API</a>
that make custom keywords worthwhile (especially the ability to invoke the Perl
parser recursively in order to parse a custom syntax with embedded Perl
fragments).</p>

<p>So what can this be used for? In the following, I'm going to show you three
modules I've written that make heavy use of custom keywords.</p>
]]>
        <![CDATA[<h2><a href="https://metacpan.org/module/Quote::Code"><code>Quote::Code</code></a> - quoted strings with arbitrary code interpolation</h2>

<p>This module adds a new <code>qc</code> quoting operator similar to
<a href="http://perldoc.perl.org/perlop.html#Quote-Like-Operators"><code>q</code> and <code>qq</code></a>.
It gives you strings (as usual) but with the ability to interpolate arbitrary
expressions (such as method calls!) by wrapping them in <code>{ ... }</code>:</p>

<pre><code>print qc!2 + 2 = {2 + 2}\n!;
</code></pre>

<p>It also defines <code>qc_to</code> for heredocs with Ruby-esque <code>#{ ... }</code> interpolation:</p>

<pre><code>my $msg = qc_to &lt;&lt;'EOF';
\o/ His power level is #{$user-&gt;level + 1}! \o/
EOF
</code></pre>

<h2><a href="https://metacpan.org/module/Switch::Plain"><code>Switch::Plain</code></a> - a simple switch statement for Perl</h2>

<p>This module exists because I wanted something a lot less magical/crazy than
<a href="https://metacpan.org/module/Switch"><code>Switch</code></a> or
<a href="http://perldoc.perl.org/perlsyn.html#Switch-Statements"><code>given</code>/<code>when</code></a>.</p>

<p>It provides two keywords, <code>sswitch</code> and <code>nswitch</code>, for string and numeric
comparisons, respectively. It doesn't try to do anything "smart" or dynamic, it
just compares strings or numbers:</p>

<pre><code>nswitch ($input) {
    case 1: {
        foo();
    }
    case 2: {
        bar();
    }
    case 3: {
        baz();
    }
    default: {
        print "What's this, then?\n";
        return;
    }
}
</code></pre>

<h2><a href="https://metacpan.org/module/Function::Parameters"><code>Function::Parameters</code></a> - subroutine definitions with parameter lists</h2>

<p>This module is the original reason I started looking into pluggable keywords.
It extends Perl with the ability to define functions and methods with parameter
lists:</p>

<pre><code>fun foo($x, $y, $z) {
    ...
}

method bar($x, $y) {
    # $self automatically defined here
    $self-&gt;frobnicate($x, $y);
}
</code></pre>

<p>Or at least that's the short version. It optionally also</p>

<ul>
<li>allows for <a href="http://perldoc.perl.org/perlsub.html#Prototypes">prototypes</a></li>
<li>lets you specify default arguments</li>
<li>checks whether your functions were called with the right number of arguments</li>
<li>lets you rename $self (e.g. <code>method new($class: %args) { ... }</code>)</li>
<li>provides named parameters in addition to the positional parameters used
above: <code>fun foo(:$x, :$y) {}</code> (callable as <code>foo(y =&gt; 1, x =&gt; 2)</code>)</li>
<li>lets you add default
<a href="http://perldoc.perl.org/perlsub.html#Subroutine-Attributes">attributes</a> to
all functions you define (e.g. <code>:method</code> to all methods)</li>
</ul>

<p>... and a few other things I'm not going to list here.</p>

<h2>Conclusion</h2>

<p>I think all of the above modules are seriously cool (I know I wrote them, but
still!). If you agree, feel free to go ahead and give them a try. And if you
find any bugs,
please report them at the usual address (<a href="https://rt.cpan.org/Public/Bug/Report.html?Queue=Quote-Code">report a bug in
<code>Quote::Code</code></a>,
<a href="https://rt.cpan.org/Public/Bug/Report.html?Queue=Switch-Plain">report a bug in
<code>Switch::Plain</code></a>
<a href="https://rt.cpan.org/Public/Bug/Report.html?Queue=Function-Parameters">report a bug in
<code>Function::Parameters</code></a>).</p>

<p>If you've been looking for a reason to upgrade to Perl 5.14 or 5.16, maybe
these modules can help. ☺</p>

<p>And if this has given you ideas for your own keywords, give it a spin. This is
powerful stuff.</p>
]]>
    </content>
</entry>

<entry>
    <title>C Programming: What is the difference between an array and a pointer?</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/mauke/2012/11/c-programming-what-is-the-difference-between-an-array-and-a-pointer.html" />
    <id>tag:blogs.perl.org,2012:/users/mauke//343.4054</id>

    <published>2012-11-18T01:09:09Z</published>
    <updated>2012-11-23T01:49:27Z</updated>

    <summary>Why is a raven like a writing-desk? (Lewis Carroll) This is a copy of an article I wrote a long time ago. I&apos;m putting it here to give it a more permanent home. Sorry for being off topic again! Introduction...</summary>
    <author>
        <name>mauke</name>
        
    </author>
    
    <category term="array" label="array" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="c" label="C" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="pointer" label="pointer" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/mauke/">
        <![CDATA[<p><q>Why is a raven like a writing-desk?</q> (<cite>Lewis Carroll</cite>)</p>

<p><em>This is a copy of an article I wrote a long time ago. I'm putting it here to give it a more permanent home. Sorry for being off topic again!</em></p>

<h2>Introduction</h2>

<p>I'm glad you asked. The answer is surprisingly simple: almost everything. In
other words, they have almost nothing in common. To understand why, we'll take
a look at what they are and what operations they support.</p>
]]>
        <![CDATA[<h2>Arrays</h2>

<p>An array is a fixed-length collection of objects, which are stored sequentially
in memory. There are only three things you can do with an array:</p>

<ol>
<li><code>sizeof</code> - <em>get its size</em> <br />
You can apply <code>sizeof</code> to it. An array x of N elements of type T (<code>T x[N]</code>)
has the size <code>N * sizeof (T)</code>, which is what you should expect. For
example, if <code>sizeof (int) == 2</code> and <code>int arr[5];</code>, then
<code>sizeof arr == 10 == 5 * 2 == 5 * sizeof (int)</code>.</li>
<li><code>&amp;</code> - <em>get its address</em> <br />
You can take its address with <code>&amp;</code>, which results in a pointer to the entire array.</li>
<li>any other use - <em>implicit pointer conversion</em> <br />
Any other use of an array results in a pointer to the first array element
(the array "decays" to a pointer).</li>
</ol>

<p>That's all. Yes, this means arrays don't provide direct access to their
contents. More specifically, there is no array indexing operator.</p>

<h2>Pointers</h2>

<p>A pointer is a value that refers to another object (or function). You might say
it contains the object's address. Here are the operations that pointers
support:</p>

<ol>
<li><p><code>sizeof</code> - <em>get its size</em> <br />
Like arrays, pointers have a size that can be obtained with <code>sizeof</code>.  Note
that different pointer types can have different sizes.</p></li>
<li><p><code>&amp;</code> - <em>get its address</em> <br />
Assuming your pointer is an lvalue, you can take its address with <code>&amp;</code>. The
result is a pointer to a pointer.</p></li>
<li><p><code>*</code> - <em>dereference it</em> <br />
Assuming the base type of your pointer isn't an incomplete type, you can
dereference it; i.e., you can follow the pointer and get the object it
refers to. Incomplete types include <code>void</code> and predeclared <code>struct</code> types
that haven't been defined yet.</p></li>
<li><p><code>+</code>, <code>-</code> - <em>pointer arithmetic</em> <br />
If you have a pointer to an array element, you can add an integer amount to
it. This amount can be negative, and <code>ptr - n</code> is equivalent to <code>ptr + -n</code>
(and <code>-n + ptr</code>, since <code>+</code> is commutative, even with pointers). If <code>ptr</code> is
a pointer to the <code>i</code>'th element of an array, then <code>ptr + n</code> is a pointer to
the <code>(i + n)</code>'th array element, unless <code>i + n</code> is negative or greater than
the number of array elements, in which case the results are undefined. If
<code>i + n</code> is equal to the number of elements, the result is a pointer that
must not be dereferenced.</p></li>
</ol>

<p>That's it, really. However, there are a few other pointer operations defined in
terms of the above fundamental operations:</p>

<ol>
<li><p><code>-&gt;</code> - <em>struct dereference</em> <br />
<code>p-&gt;m</code> is equivalent to <code>(*p).m</code>, where <code>.</code> is the struct/union member
access operator. This means <code>p</code> must be a pointer to a struct or union.</p></li>
<li><p><code>[]</code> - <em>indexed dereference</em> <br />
<code>a[b]</code> is equivalent to <code>*(a + b)</code>. This means <code>a</code> and <code>b</code> must be a pointer
to an array element and an integer; not necessarily respectively, because
<code>a[b] == *(a + b) == *(b + a) == b[a]</code>. Another important equivalence is
<code>p[0] == 0[p] == *p</code>.</p></li>
</ol>

<h2>A quirk of parameter declarations</h2>

<p>However, there's one thing that confuses this issue. Whenever you declare a
function parameter to have an array type, it gets silently converted to a
pointer and any size information is ignored. Thus the following four
declarations are equivalent:</p>

<pre><code>void foo(int [42]);

void foo(int []);

typedef int t_array[23];
void foo(t_array);

void foo(int *);
</code></pre>

<p>A more common example is <code>int main(int argc, char *argv[])</code>, which is the same
as <code>int main(int argc, char **argv)</code>. However,
<code>int main(int argc, char argv[][])</code> would be an error because the above rule
isn't recursive; the result after conversion would be
<code>int main(int argc, char (*argv)[])</code>, i.e. <code>argv</code> would be a pointer to an
array of unknown size, not a pointer to a pointer.</p>

<h2>Conclusion</h2>

<p>Arrays by themselves are nearly useless in C. Even the fundamental <code>[]</code>
operator, which is used for getting at the array's contents, is an illusion:
it's defined on pointers and only happens to work with arrays because of the
rule that any use of an array outside of <code>sizeof</code> and <code>&amp;</code> yields a pointer.</p>
]]>
    </content>
</entry>

<entry>
    <title>Exit statuses and how $? works</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/mauke/2011/09/exit-statuses-and-how-works.html" />
    <id>tag:blogs.perl.org,2011:/users/mauke//343.2237</id>

    <published>2011-09-30T04:08:39Z</published>
    <updated>2011-09-30T05:21:01Z</updated>

    <summary>The other day I was wondering about $? in Perl and the shell and how exit statuses work. I did some digging and now I&apos;d like to talk a bit about exit statuses at the OS level and how Perl...</summary>
    <author>
        <name>mauke</name>
        
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/mauke/">
        <![CDATA[<p>The other day I was wondering about <code>$?</code> in Perl and the shell and how exit statuses work.
I did some digging and now I'd like to talk a bit about exit statuses at the OS level and how Perl and the shell deal with it.</p>

<p>First off, there are two ways a unix process can terminate.
One is by calling <a href="http://linux.die.net/man/2/_exit"><code>_exit</code></a>, the other is getting killed by a <a href="http://linux.die.net/man/7/signal">signal</a>.
In both cases the resources of the process (such as memory or file descriptors) are cleaned up.
All that remains is an entry in the process table (i.e. the <abbr title="process id">PID</abbr> is still taken) and some status information on how the process died.
This "stale" process table entry is called a <dfn>zombie process</dfn>.</p>

<p>After a process has terminated, it's its parent's job to clean up after it by calling <a href="http://linux.die.net/man/2/wait"><code>wait</code></a> or simply exiting itself (a process whose parent has died is known as an <dfn>orphan process</dfn>; it will be adopted and cleaned up by <code>init</code>, the process with id 1).</p>

<p>In C, a successful call to <code>wait</code> gives you a status value of type <code>int</code>.
The header <code>&lt;sys/wait.h&gt;</code> provides several macros to examine this status, such as:</p>

<ul>
<li><code>WIFEXITED</code> - true if the process died by calling <code>_exit</code></li>
<li><code>WEXITSTATUS</code> - the number passed to <code>_exit</code> (only valid if <code>WIFEXITED</code> is true)</li>
<li><code>WIFSIGNALED</code> - true if the process was killed by a signal</li>
<li><code>WTERMSIG</code> - the signal that killed it (only valid if <code>WIFSIGNALED</code> is true)</li>
</ul>

<p>Something that may not be obvious: the "exit status" consists of a single byte, so only the 8 lowest bits of the number you pass to <code>_exit</code> will be used.
In other words, <code>WEXITSTATUS</code> will always be in the range [0, 255].</p>

<p>The above interface is fairly abstract; it doesn't define the details of how signal numbers and exit statuses are encoded.
But there is a traditional way unix has done this, and it's also how Perl does it.</p>

<ul>
<li>The status value in <a href="http://perldoc.perl.org/perlvar.html#$CHILD_ERROR"><code>$?</code></a> is a 16-bit number.</li>
<li>The low 8 bits are set if the process died from a signal.</li>
<li>The low 7 bits are the signal number; bit 8 is set if the process dumped core.</li>
<li>Otherwise the exit status is stored in the high 8 bits.</li>
</ul>

<p>Perl always computes <code>$?</code> to look like this, even if your OS doesn't encode status information this way natively.
This means a C program may get different status bits from <code>wait</code> than what a Perl program would see in <code>$?</code>.
If you really need your OS's native status code in a Perl program, you can use <a href="http://perldoc.perl.org/perlvar.html#${^CHILD_ERROR_NATIVE}"><code>${^CHILD_ERROR_NATIVE}</code></a> and <a href="https://metacpan.org/module/POSIX#WAIT">the <code>W*</code> functions from POSIX</a>.</p>

<p><em>(The following information was taken from the <a href="http://www.gnu.org/software/bash/">bash</a> manual but it probably applies to all Bourne-style shells.)</em></p>

<p>Finally there is another <code>$?</code> variable in the shell.
It has the same name and function as Perl's, but its values work differently.
In particular, it's always an 8-bit number, not 16 bits as in Perl.</p>

<ul>
<li>If a process exits normally, its status is in <code>$?</code>.</li>
<li>If it is killed by a signal, <code>$?</code> is set to <code>128 + $signo</code> (where <code>$signo</code> is the signal's number).</li>
</ul>

<p>Example: On my system <code>SIGSEGV</code> is 11, so after a <a href="http://en.wikipedia.org/wiki/Segmentation_fault">segfault</a> the shell sets <code>$?</code> to 128 + 11 = 139.</p>

<p>Other synthetic <code>$?</code> values include 127 (command not found) and 126 (command found but it wasn't executable).</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Why you probably don&apos;t want to use claws-mail</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/mauke/2011/09/why-you-probably-shouldnt-use-claws-mail.html" />
    <id>tag:blogs.perl.org,2011:/users/mauke//343.2225</id>

    <published>2011-09-26T18:17:23Z</published>
    <updated>2011-09-28T01:24:26Z</updated>

    <summary>I&apos;ve been using claws-mail as my email client for a while. Today I wanted to search all of my messages for some text and look through the results. When I couldn&apos;t figure out how to do that even after consulting...</summary>
    <author>
        <name>mauke</name>
        
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/mauke/">
        <![CDATA[<p>I've been using claws-mail as my email client for a while.
Today I wanted to search all of my messages for some text and look through the results.
When I couldn't figure out how to do that even after consulting <a href="http://www.claws-mail.org/documentation.php">the claws manual</a>, I went to their official IRC channel.</p>

<p>For reference, here are some screenshots of the dialogs in question:
<a href="http://blogs.perl.org/users/mauke/claws-esearch-information-mtsucks.png"><img alt="claws-esearch-information-mtsucks.png" src="http://blogs.perl.org/users/mauke/assets_c/2011/09/claws-esearch-information-mtsucks-thumb-150x280-639.png" width="150" height="280" class="mt-image-left" style="float: left; margin: 0 20px 20px 0;" /></a><a href="http://blogs.perl.org/users/mauke/claws-esearch-edit.png"><img alt="claws-esearch-edit.png" src="http://blogs.perl.org/users/mauke/assets_c/2011/09/claws-esearch-edit-thumb-150x107-641.png" width="150" height="107" class="mt-image-left" style="float: left; margin: 0 20px 20px 0;" /></a><div style="clear:both;"></div></p>

<p>This is what happened:</p>

<pre><code>17:55 -!- .join mauke!~mauke@p3m/member/mauke #claws
17:55 -!- Irssi: #claws: Total of 33 nicks [8 ops, 0 halfops, 0 voices, 25 normal]
17:55 -!- Irssi: Join to #claws was synced in 1 secs
17:55 &lt;mauke&gt; hello, I am raging at claws-mail
18:08 &lt;mauke&gt; basically, the search feature is undocumented and I
              can't figure out how it works
18:15 &lt;mohaa&gt; "undocumented" ?
18:16 &lt;mauke&gt; yeah, like:  When in "Extended" mode, the "Information"
              button is visible, enabling you to see the search
              syntax.
18:17 &lt;mauke&gt; doesn't "enable" shit
18:17 &lt;mauke&gt; "Run on select" isn't even mentioned in the manual
18:17 &lt;mauke&gt; what is 'S' in the Information window?
18:18 &lt;mauke&gt; after I run a search, where are the results?
18:18 &lt;mauke&gt; what exactly does 'E' do and how is it useful?
18:19 &lt;mauke&gt; what is the unit of '#' in 'ag'?
18:19 &lt;mauke&gt; how is % supposed to be used?
18:19 &lt;mauke&gt; "all filtering expressions are allowed" - what are
              "filtering expressions" and what does "allowed" mean
              here?
18:20 &lt;mauke&gt; how is E different from X?
18:20 &lt;mauke&gt; are parens allowed? if not, how do expressions work?
18:21 &lt;mauke&gt; what's the unit of # in Se/Sg/Ss?
18:21 &lt;mauke&gt; why does the description of 'tg' ("messages which tags
              contain S") randomly use "which" instead of "whose"?
18:22 &lt;mauke&gt; how does 'k' work?
18:22 &lt;mauke&gt; are the colors numbers?
18:24 &lt;mohaa&gt; "parens" ?
18:24 &lt;mauke&gt; yes
18:25 -!- .join krayon!~fallen@pdpc/supporter/28for7/krayon #claws
18:25 &lt;mauke&gt; I mean, how else does grouping work?
18:47 -!- .join andyrtr_laptop!~andyrtr@f053200240.adsl.alicedsl.de #claws
19:12 -!- .quit andyrtr!~andyrtr@archlinux/developer/andyrtr [Quit: Ex-Chat]
19:22 -!- .join Columbo0815!~foobar@HSI-KBW-085-216-116-089.hsi.kabelbw.de #claws
19:24 -!- .join claws_!~claws@5ad1377a.bb.sky.com #claws
19:24 -!- .mode clunker3 #claws [+o claws_]
19:25 -!- .nick claws_ -&gt; claws
19:42 -!- .quit Columbo0815!~foobar@HSI-KBW-085-216-116-089.hsi.kabelbw.de [Quit: Verlassend]
19:43 &lt;@claws&gt; mauke: you're funny :)
19:44 &lt;mauke&gt; why?
19:45 &lt;@claws&gt; maybe you wouldn't rage so much if you'd never found
               the feature or the feature didn't exist
19:45 &lt;mauke&gt; no, my main problem is the lack of a good search feature
19:45 &lt;mauke&gt; that's how this all started
19:45 &lt;@claws&gt; anyway, ignore the information dialog and click the
               edit button - this is probably easier to digest
19:46 &lt;mauke&gt; no, the edit button seems to lack all features
19:46 &lt;@claws&gt; the quick search is a _very good_ search feature imo
19:46 &lt;@claws&gt; no, the edit button does not
19:46 &lt;mauke&gt; claws: yes, but I can't figure out how to use it
19:46 &lt;mauke&gt; see above
19:46 &lt;@claws&gt; have you worked out how to use Filtering in Claws?
19:46 &lt;mauke&gt; no
19:46 &lt;@claws&gt; heh, thought not
19:47 &lt;mauke&gt; btw, I blanked some spam pages in the wiki
19:47 &lt;@claws&gt; heh, yes. there are always new spam pages in the wiki
19:47 &lt;@claws&gt; thanks. saved me a job
19:48 &lt;@claws&gt; back to the quick search, what are you likely to want
               to search for?
19:48 &lt;mauke&gt; text
19:48 &lt;mauke&gt; I want a full text search over everything
19:48 &lt;@claws&gt; b 'my search term' in Extended mode
19:48 &lt;@claws&gt; b is for body
19:48 &lt;mauke&gt; what happens if I omit the quotes?
19:49 &lt;mauke&gt; what happens with double quotes?
19:49 &lt;mauke&gt; how do I search for '?
19:49 &lt;@claws&gt; the quickest way to find your answer is to try it
19:50 &lt;mauke&gt; I did, results make no sense
19:50 &lt;@claws&gt; is that possible, perhaps?
19:50 &lt;@claws&gt; made no sense? in what way?
19:50 &lt;mauke&gt; why can't I just read a reference manual?
19:50 &lt;@claws&gt; dunno ...because you wouldn't??
19:50 &lt;mauke&gt; well, first there's problem #1: &lt;mauke&gt; after I run a
              search, where are the results?
19:51 &lt;@claws&gt; because you haven't written it yet?
19:51 &lt;@claws&gt; the results are in the msg list - this list is
               shortened, based on the results
19:51 &lt;mauke&gt; what msg list?
19:51 &lt;@claws&gt; that's quite obvious, i think, no???
19:51 &lt;mauke&gt; I have a nested folder structure
19:51 &lt;@claws&gt; now, m[e]s[sa]ge list _is_ in the manual!!
19:52 &lt;@claws&gt; the message list is not the folder list
19:52 &lt;mauke&gt; message list is the contents of one folder
19:52 &lt;mauke&gt; this is useless
19:52 &lt;mauke&gt; I don't want to manually click through all folders just
              to see if one of them maybe contains some search results
19:53 &lt;@claws&gt; then search in the top-level folder and use a recursive
               search
19:53 &lt;mauke&gt; I did
19:53 &lt;@claws&gt; that's not useless
19:53 &lt;mauke&gt; where are my results?
19:54 &lt;@claws&gt; a folder which has results has its folder icon replaced
               with a magnifying glass. select that folder and you'll
               see your results
19:54 &lt;mauke&gt; so I still have to manually click through the folders?
19:54 &lt;mauke&gt; blargh
19:54 &lt;mauke&gt; who came up with this UI
19:54 &lt;@claws&gt; why do you ask?
19:55 &lt;mauke&gt; that was more of a rhetorical question
19:55 &lt;@claws&gt; more like a rude question, methinks
19:55 &lt;mauke&gt; the search seems to ignore everything after the first
              word
19:55 &lt;@claws&gt; then quote
19:55 &lt;mauke&gt; is that correct?
19:56 &lt;@claws&gt; doesn't a test answer your question?
19:56 &lt;mauke&gt; no
19:56 &lt;mauke&gt; I can't rule out that it has some effect I didn't notice
19:57 &lt;mauke&gt; hence "seems to ignore"
19:57 &lt;@claws&gt; is it me, but you seem to have an attitude??
19:58 &lt;mauke&gt; I do, but not where you think
19:58 &lt;mauke&gt; this confuses me a bit
19:59 &lt;@claws&gt; you do, but not where i think?? that confuses me
19:59 &lt;mauke&gt; I've been trying to be nice and civil at the end there
19:59 &lt;@claws&gt; maybe the beginning would have been better, but
               whatever!
19:59 &lt;@claws&gt; the quick search is good, it works. maybe it doesn't
               work how you want it to work, but there it is
20:00 &lt;mauke&gt; my main problem is not that it doesn't work how I want
              it to, it's that it's not documented
20:00 &lt;mauke&gt; so I don't even know if it does what I want
20:01 &lt;mauke&gt; the list at the beginning is the "obvious" questions I
              had when I saw the [Information] window
20:01 &lt;mauke&gt; the [Edit] dialog doesn't seem to allow a full text
              search
20:02 &lt;mauke&gt; and I didn't notice the folder icon change at all
20:02 &lt;mauke&gt; what I find weird is that you can't give me a straight
              answer as to what "b x y z" does
20:03 &lt;mauke&gt; normally I'd expect "RTFM" in response to that but there
              doesn't seem to be a FM
20:03 &lt;mauke&gt; you said I should try it; I did. now I'm simply asking
              for confirmation
20:04 &lt;mauke&gt; and all I get is "you seem to have an attitude"
20:08 &lt;@claws&gt; in the edit dialogue use phrase --&gt; in body part
20:08 &lt;mauke&gt; oh wow
20:09 &lt;@claws&gt; maybe that's "all" you get because that's "all" you
               gave?? :)
20:09 &lt;mauke&gt; I didn't even think to look there because Header, Age,
              Flags, ... are other top-level categories
20:09 &lt;@claws&gt; in this case it's not RTFM, it's WTFM :)
20:10 &lt;mauke&gt; so I in analogy to Header I was looking for Body or
              Message or whatever
20:10 &lt;mauke&gt; yeah, Phrase is the odd one out
20:10 &lt;mauke&gt; the other items specify which part/attribute of the
              message to search *in*; Phrase describes what kind of
              thing you're looking *for*
20:11 &lt;mauke&gt; claws: dude, I asked you a simple yes/no question
20:11 &lt;mauke&gt; you could answer 1) yes, 2) no, 3) rtfm at ...,
              4) you're stupid because ...
20:12 &lt;@claws&gt; but none of those fitted my answer
20:12 &lt;mauke&gt; but this "I don't like your attitude" bullshit is
              extremely annoying
20:12 &lt;@claws&gt; yep, i thought the same
20:12 &lt;mauke&gt; so why are you doing it?
20:13 &lt;@claws&gt; i'm not any more, i'm going to do something else
20:13 &lt;mauke&gt; sorry for assuming this program was meant to have users
</code></pre>

<p><strong>Update 1:</strong></p>

<ul>
<li>Changed the title from "shouldn't" to "don't want to" because that's closer to what I meant.</li>
<li>Reformatted the log a bit to prevent the right side being cut off.</li>
</ul>

<p><strong>Update 2:</strong></p>

<p>Oh wow, it keeps getting better.
I really wanted to know how this #!$@ actually works so I downloaded the source code.
It comes with a fairly long README that (among other things) explains Quick Search better than both the "user manual" and the built-in help system.
It even has examples!
First the filter engine syntax:</p>

<blockquote><pre>
    from regexpcase "foo"
    subject regexp "Bug" & to regexp "claws-mail"
</pre></blockquote>

<p>Then the extended patterns:</p>

<blockquote><pre>
    # means number
    S means regexp string
</pre></blockquote>

<blockquote><pre>
    f "john beavis"    messages from john beavis
    %f "John Beavis"   messages from John Beavis (case sensitive)
    ~s foo             messages which do not have foo in the subject
    f foo & ~s bar     messages from foo that do not have bar in thesubject
</pre></blockquote>

<p>Still missing:</p>

<ul>
<li>What units are the # numbers in?</li>
<li>What's the syntax for a "regexp string"?</li>
<li>What regexp flavor?</li>
</ul>

<p>But it does show that you can use double quotes and that the % should be placed immediately in front of one of the string operators.</p>

<p>(BTW, "<code>S means regexp string</code>" is the only occurrence of "regex" or "regul.*ex" in <code>README</code>, <code>doc/</code>, or <code>manual/</code>.)</p>

<p>...</p>

<p>Now I've looked at the source code.
Turns out claws-mail uses a rewriting system to convert "extended patterns" into "filter syntax" internally.
The actual syntax is a bit complicated:</p>

<ul>
<li>Tokens in the search expression are space separated.</li>
<li>Every term in the expression starts with an (optionally prefixed) command.</li>
<li>The prefixes are <code>!</code>, <code>~</code> and <code>%</code>.</li>
<li>You can have at most one of <code>!</code> and <code>~</code> (both mean "not"). If you have one, it must appear first.</li>
<li>You can also have <code>%</code> (it means "case sensitive").</li>
<li>If prefixes are present, they must appear in the above order with no whitespace in between (example: <code>!%f</code>).</li>
<li>Then comes the command code.</li>
<li>Then the argument (if the command takes one).</li>
<li>If the argument starts with a <code>"</code> (double quote), it ends at the next <code>"</code>.
There is no way to embed a <code>"</code> in the string.
Otherwise it ends at the next ' ' (space, ASCII 32) character (<em>not</em> the next whitespace character!).</li>
<li>As far as the rewriter is concerned, <code>&amp;</code> and <code>|</code> are just commands without arguments, not operators between commands.
That means there's no way to nest them (it also means <code>~&amp;</code> is accepted).</li>
</ul>

<p>Regarding regex syntax:</p>

<ul>
<li>It uses <code>regcomp</code> from <code>regex.h</code> with the <code>REG_EXTENDED</code> flag, so the flavor is <a href="http://linux.die.net/man/7/regex">POSIX Extended</a>.</li>
</ul>

<p>Regarding numeric units:</p>

<ul>
<li>Colors are something terrible (a message's "color value" is an integer whose parts are stored in different places; requires bitwise operations to reassemble).
I'm just going to assume that colors are numbered according to their appearance in the <code>Message</code> > <code>Color label</code> submenu.</li>
<li>Age is internally stored with a resolution of one second, but the search operators work in whole days.</li>
<li>Size is the raw message size in bytes.</li>
</ul>

<p><strong>Conclusion:</strong></p>

<p>If you're an end user, claws-mail may not be for you. Source diving seems to be the best way to get accurate and complete information on how the program works.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Two RegExp bugs in Internet Explorer 8</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/mauke/2010/11/two-regexp-bugs-in-internet-explorer-8.html" />
    <id>tag:blogs.perl.org,2010:/users/mauke//343.1196</id>

    <published>2010-11-23T06:24:32Z</published>
    <updated>2010-11-23T06:52:07Z</updated>

    <summary>It turns out there are at least two bugs in IE 8&apos;s Javascript regex engine. One of them is widely known, the other one doesn&apos;t seem to be. Testcase: /^(?:(?=(.))a|(?=(.))b|(?=(.))c)/.exec(&apos;bar&apos;) Correct result: [&apos;b&apos;, undefined, &apos;b&apos;, undefined] Actual result: [&apos;b&apos;, &apos;b&apos;,...</summary>
    <author>
        <name>mauke</name>
        
    </author>
    
    <category term="bug" label="bug" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="ie" label="IE" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="internetexplorer" label="Internet Explorer" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="javascript" label="Javascript" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="regex" label="regex" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="regexp" label="RegExp" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/mauke/">
        <![CDATA[<p>It turns out there are at least two bugs in IE 8's Javascript regex engine. One of them is widely known, the other one doesn't seem to be.</p>

<p>Testcase: <code>/^(?:(?=(.))a|(?=(.))b|(?=(.))c)/.exec('bar')</code> <br />
Correct result: <code>['b', undefined, 'b', undefined]</code> <br />
Actual result: <code>['b', 'b', 'b', '']</code></p>

<p>The last <code>''</code> is the known bug: capturing groups that don't participate in a successful match are set to <code>''</code> instead of <code>undefined</code>. Slightly annoying, but not too bad.</p>

<p>But the <code>'b'</code> at index 1 is just wrong: The first capturing group was entered, but that branch failed (because the target string didn't start with an <code>'a'</code>). At this point all captures from this branch should have been reset to their previous state (in this case <code>undefined</code> (or <code>''</code> for IE)). That didn't happen.</p>

<p>End result: we get a successful match, but the captured strings may have completely bogus values.</p>

<p>I think this is pretty funny because I once wrote a toy "regex engine" when I didn't really know anything about byecode or automata or anything. It used "brute force" backtracking based on recursive function calls (no explicit stack). Well, it had that exact bug ... until I noticed and fixed it a few months later. In other words, this is a beginner's mistake in state management/backtracking.</p>

<p>I'm pretty sure Microsoft does some testing before it releases software. Didn't anyone notice this?</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Javascript: adding a unique ID to every object</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/mauke/2010/08/javascript-adding-a-unique-id-to-every-object.html" />
    <id>tag:blogs.perl.org,2010:/users/mauke//343.938</id>

    <published>2010-08-24T21:33:33Z</published>
    <updated>2010-08-24T21:58:54Z</updated>

    <summary>This entry is about Javascript, not Perl. It&apos;s about object identity in particular. If you have two objects in x and y, you can check whether they&apos;re really the same object with x === y. However, as far as I...</summary>
    <author>
        <name>mauke</name>
        
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/mauke/">
        <![CDATA[<p>This entry is about Javascript, not Perl. It's about object identity in particular.</p>

<p>If you have two objects in <code>x</code> and <code>y</code>, you can check whether they're really the same object with <code>x === y</code>. However, as far as I know Javascript provides no way to get an object's address (which you could use as a key in a hashtable or whatever). The following code attempts to fix this problem by adding a unique ID to every object (and I do mean "every"):</p>

<pre><code>var enchant = (function () {
    var k = 'id';
    var uniq = 0;

    return function enchant(o) {
        var t = uniq++;
        Object.prototype.__defineGetter__.call(o, k,
            function () {
                return this === o ? t : enchant(this, k);
            }
        );
        return t;
    };
}());

enchant(Object.prototype);
</code></pre>

<p>Now each object <code>foo</code> has a (unique) <code>foo.id</code> property.</p>

<p>I've only tried this in Mozilla's Javascript engine, so I wouldn't be surprised if this completely fails to work in anything but Firefox (or at least Internet Explorer). It's not hard to make this code portable though, at the expense of the "nice" <code>foo.id</code> syntax; you have to write <code>foo.id()</code> instead:</p>

<pre><code>var enchant = (function () {
    var k = 'id';
    var uniq = 0;

    return function enchant(o) {
        var t = uniq++;
        o[k] = function () {
            return this === o ? t : enchant(this, k);
        };
        return t;
    };
}());

enchant(Object.prototype);
</code></pre>

<p>Anyway, I think this is a pretty cool hack. But to be honest, it feels like the equivalent of <code>Acme::</code> code: fun and thought provoking, but not necessarily something for real-world use.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Stripping color codes in irssi scripts</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/mauke/2010/05/stripping-color-codes-in-irssi-scripts.html" />
    <id>tag:blogs.perl.org,2010:/users/mauke//343.580</id>

    <published>2010-05-23T20:16:56Z</published>
    <updated>2010-05-23T20:35:41Z</updated>

    <summary>So you&apos;re writing an IRC script for irssi and you want to strip formatting codes (including colors, bold, underline, etc) from some variable. This is possible with s///, and google will show many (usually not very readable) examples. But there&apos;s...</summary>
    <author>
        <name>mauke</name>
        
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/mauke/">
        <![CDATA[<p>So you're writing an IRC script for <a href="http://irssi.org/">irssi</a> and you want to strip formatting codes (including colors, bold, underline, etc) from some variable. This is possible with <code>s///</code>, and <a href="http://google.com/">google</a> will show many (usually not very readable) examples.</p>

<p>But there's an easier way: irssi has an undocumented function called <code>Irssi::strip_codes</code> that does all the work for you. And since irssi exports all functions into your script's namespace unconditionally, you don't even need to type the <code>Irssi::</code> part:</p>

<pre><code>my $clean = strip_codes($dirrrty);
</code></pre>

<p>This will remove so-called “mIRC colors”, irssi's internal formatting codes, and <a href="http://en.wikipedia.org/wiki/ANSI_escape_code#graphics">ANSI color sequences</a>.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>No semicolon after return values</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/mauke/2010/05/no-semicolon-after-return-values.html" />
    <id>tag:blogs.perl.org,2010:/users/mauke//343.559</id>

    <published>2010-05-18T19:09:25Z</published>
    <updated>2010-05-18T19:17:46Z</updated>

    <summary>Perl lets you omit semicolons at the end of a block. That is, you can treat ; as a statement separator, not a terminator, as in Pascal. OK, but why would you want to do that? The advantage of terminating...</summary>
    <author>
        <name>mauke</name>
        
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/mauke/">
        <![CDATA[<p>Perl lets you omit semicolons at the end of a block. That is, you can treat <code>;</code>
as a statement separator, not a terminator, as in Pascal.</p>

<p>OK, but why would you want to do that? The advantage of terminating each
statement is that you don't need to do anything special for the first and last
lines: You can insert or remove lines at any point without worrying about the
rest of the code. Why throw that away?</p>

<p>Because sometimes it doesn't make sense to add code at the end. Consider this
code:</p>

<pre><code>sub foo {
  my ($s) = @_;
  $s =~ s/%/%%/g;
  $s
}
</code></pre>

<p>The last statement <code>$s</code> is the return value. Adding statements after it could
silently break this function. By omitting the last semicolon I can make the
code a bit more robust, because now I get a syntax error when I try to put more
code at the end without paying attention.</p>

<p>Maybe you don't use this form of code, though. Maybe you always write an
explicit <code>return</code>. In that case any following code is silently ignored, so in
the above scenario you wouldn't break anything, but your changes wouldn't have
any effect either.</p>

<p>And there's another case that affects everyone who writes modules. Files loaded
by <code>require</code> (directly or indirectly via <code>use</code>) need to return a true value.
Most people simply write <code>1;</code> at the end of their modules. I think it makes
sense to omit the <code>;</code> here as well, because nothing should come after it.</p>

<p>I've actually seen people cargo-cult module code, putting <code>1;</code> in the middle of
their Perl files. For those people: <code>1;</code> doesn't make sense unless it's the
last statement in a file and that file is a module. Everyone: you should end
your modules with <code>1</code>, not <code>1;</code>.</p>

<p>(That's what I think, anyway. I hope this posting makes some sense.)</p>
]]>
        

    </content>
</entry>

</feed>
