improved indentation and whitespace for markdown code blocks

All code blocks in markdown have been intended by at least 4 spaces.

We add `--tab-stop=8` to all `pandoc(1)` executions in order to set
a better tab stop indentation, especially for tab intended code blocks.

Changed `bin/pandoc-wrapper.sh` VERSION from "1.5.3 2024-03-26"
to "1.6 2024-03-31".

Fixed `1991/brnstnd/sorta.README.md` so that the sorta code
is code blocks.

Removed unneeded paragraph group in copyright in `inc/footer.default.html`.

Fixed excess whitespace after list Author on entry `index.html` page.

Changed `bin/output-index-author.sh` VERSION from "1.5.2 2024-03-26"
to "1.6 2024-03-31".

Performed `make www` to perform the above and test under macOS.

TODO: Fix the problem of the initial line of code being extra intended.
TODO: Fix excess whitespace around code that is inline.
This commit is contained in:
Landon Curt Noll committed 2024-04-01 04:48:48 -07:00
1 parent b84c27ce02
commit a996f8d2b8
734 files changed
+16723 -16963

No files matched your search

+57 -57
View File
@@ -125,9 +125,9 @@
<h1 id="information-about-this-entry">Information about this entry</h1>
<p>Morse codes for letters and digits use sequences of 1 to 5 (inclusive)
Morse symbols (denoted as <code>.</code> or <code>-</code>), e.g.</p>
<pre><code>E .
Z --..
3 ...--</code></pre>
<pre><code> E .
Z --..
3 ...--</code></pre>
<p>(BTW: digits always have 5 symbols, letters 1 to 4. I didn’t use this fact.)</p>
<p>Of course we can encode these symbols with bits in a byte. I chose <code>-</code>
to be a bit set to 0, <code>.</code> to be a bit set to 1. Characters in C are at
@@ -138,62 +138,62 @@ can use type <code>char</code> (using <code>unsigned char</code> for an extra bi
the source code excessively large ;-)</p>
<p>The least significant bit contains the first symbol of a Morse code, so
we have</p>
<pre><code>E &gt; 0......1
Z &gt; 0...1100
3 &gt; 0..00111</code></pre>
<pre><code> E &gt; 0......1
Z &gt; 0...1100
3 &gt; 0..00111</code></pre>
<p>The dots still have to be determined. But we also need to encode the
length of the sequence. Since there are only 4 different kind of lengths,
two bits would suffice, e.g.</p>
<pre><code>E &gt; 000....1
Z &gt; 010.1100
3 &gt; 01100111</code></pre>
<pre><code> E &gt; 000....1
Z &gt; 010.1100
3 &gt; 01100111</code></pre>
<p>That means bits 6 and 5 set to 00 is length 1, set to 01 is length 2, etc.
But this would mean that we would have to extract the length into a
counter before shifting out each symbol, such as</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>length <span class="op">=</span> <span class="op">(</span>encoding <span class="op">&amp;</span> <span class="dv">96</span><span class="op">)</span> <span class="op">&gt;&gt;</span> <span class="dv">5</span><span class="op">;</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="cf">do</span> <span class="op">{</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> putchar<span class="op">(</span>encoding <span class="op">&amp;</span> <span class="dv">1</span> <span class="op">?</span> <span class="ch">&#39;-&#39;</span> <span class="op">:</span> <span class="ch">&#39;.&#39;</span><span class="op">);</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> encoding <span class="op">&gt;&gt;=</span> <span class="dv">1</span><span class="op">;</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a><span class="op">}</span> <span class="cf">while</span> <span class="op">(</span>length<span class="op">--);</span></span></code></pre></div>
<div class="sourceCode" id="cb4"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> length <span class="op">=</span> <span class="op">(</span>encoding <span class="op">&amp;</span> <span class="dv">96</span><span class="op">)</span> <span class="op">&gt;&gt;</span> <span class="dv">5</span><span class="op">;</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">do</span> <span class="op">{</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> putchar<span class="op">(</span>encoding <span class="op">&amp;</span> <span class="dv">1</span> <span class="op">?</span> <span class="ch">&#39;-&#39;</span> <span class="op">:</span> <span class="ch">&#39;.&#39;</span><span class="op">);</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> encoding <span class="op">&gt;&gt;=</span> <span class="dv">1</span><span class="op">;</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span> <span class="cf">while</span> <span class="op">(</span>length<span class="op">--);</span></span></code></pre></div>
<p>We can also use the remaining bits to <em>include</em> the counter</p>
<pre><code>length 1: 00000.1x E &gt; 00000.11
length 2: 0000.1xx
length 3: 000.1xxx
length 4: 00.1xxxx Z &gt; 00.11100
length 5: 0.1xxxxx 3 &gt; 0.100111</code></pre>
<pre><code> length 1: 00000.1x E &gt; 00000.11
length 2: 0000.1xx
length 3: 000.1xxx
length 4: 00.1xxxx Z &gt; 00.11100
length 5: 0.1xxxxx 3 &gt; 0.100111</code></pre>
<p>with 1 bit still to be chosen freely (let’s assume it is 0). Now we can do</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="cf">do</span> <span class="op">{</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> putchar<span class="op">(</span>encoding <span class="op">&amp;</span> <span class="dv">1</span> <span class="op">?</span> <span class="ch">&#39;-&#39;</span> <span class="op">:</span> <span class="ch">&#39;.&#39;</span><span class="op">);</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> encoding <span class="op">&gt;&gt;=</span> <span class="dv">1</span><span class="op">;</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="cf">while</span> <span class="op">(</span>encoding <span class="op">&gt;</span> <span class="dv">1</span><span class="op">);</span></span></code></pre></div>
<div class="sourceCode" id="cb6"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">do</span> <span class="op">{</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> putchar<span class="op">(</span>encoding <span class="op">&amp;</span> <span class="dv">1</span> <span class="op">?</span> <span class="ch">&#39;-&#39;</span> <span class="op">:</span> <span class="ch">&#39;.&#39;</span><span class="op">);</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> encoding <span class="op">&gt;&gt;=</span> <span class="dv">1</span><span class="op">;</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">while</span> <span class="op">(</span>encoding <span class="op">&gt;</span> <span class="dv">1</span><span class="op">);</span></span></code></pre></div>
<p>As you see, the encoded Morse sequence can be the counter itself. But
this is not very pleasant, as some Morse sequences will end up having
an ASCII value &lt; 32, i.e. they will be control codes. This would make
the initializing (encoding) string awkward. Hence I came up with the
following</p>
<pre><code>length 1: 0010010x E &gt; 00100101 (= &#39;%&#39;)
length 2: 001010xx
length 3: 00110xxx
length 4: 0100xxxx Z &gt; 01001100 (= &#39;L&#39;)
length 5: 011xxxxx 3 &gt; 01100111 (= &#39;g&#39;)</code></pre>
<pre><code> length 1: 0010010x E &gt; 00100101 (= &#39;%&#39;)
length 2: 001010xx
length 3: 00110xxx
length 4: 0100xxxx Z &gt; 01001100 (= &#39;L&#39;)
length 5: 011xxxxx 3 &gt; 01100111 (= &#39;g&#39;)</code></pre>
<p>Notice these encodings in the initialization string. Only the coding for
<code>5</code> needs an escape (<code>5 = ..... &gt; 01111111 = '\177'</code>). The way the length
is encoded still allows the encoding to be its own counter:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="cf">do</span> <span class="op">{</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> putchar<span class="op">(</span>encoding <span class="op">&amp;</span> <span class="dv">1</span> <span class="op">?</span> <span class="ch">&#39;-&#39;</span> <span class="op">:</span> <span class="ch">&#39;.&#39;</span><span class="op">);</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> encoding <span class="op">=</span> <span class="op">(</span>encoding <span class="op">+</span> <span class="dv">32</span><span class="op">)</span> <span class="op">&gt;&gt;</span> <span class="dv">1</span><span class="op">;</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a><span class="op">}</span> <span class="cf">while</span> <span class="op">(</span>encoding <span class="op">&gt;</span> <span class="dv">35</span><span class="op">);</span></span></code></pre></div>
<div class="sourceCode" id="cb8"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">do</span> <span class="op">{</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> putchar<span class="op">(</span>encoding <span class="op">&amp;</span> <span class="dv">1</span> <span class="op">?</span> <span class="ch">&#39;-&#39;</span> <span class="op">:</span> <span class="ch">&#39;.&#39;</span><span class="op">);</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> encoding <span class="op">=</span> <span class="op">(</span>encoding <span class="op">+</span> <span class="dv">32</span><span class="op">)</span> <span class="op">&gt;&gt;</span> <span class="dv">1</span><span class="op">;</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span> <span class="cf">while</span> <span class="op">(</span>encoding <span class="op">&gt;</span> <span class="dv">35</span><span class="op">);</span></span></code></pre></div>
<p>The last shift will always result in <code>00100010</code>, hence the test for <code>&gt;35</code>.
Note that the calculation for the next value of <code>encoding</code> is done at <code>int</code>
precision, so that the actual value of the <code>char</code> remains <code>&lt;= 127</code>.</p>
<p>The character <code>'-'</code> (ASCII 45) and <code>'.'</code> (ASCII 46) are conveniently in
sequence, so the putchar can simply be</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>putchar<span class="op">(</span><span class="dv">45</span> <span class="op">+</span> encoding <span class="op">%</span> <span class="dv">2</span><span class="op">);</span></span></code></pre></div>
<div class="sourceCode" id="cb9"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> putchar<span class="op">(</span><span class="dv">45</span> <span class="op">+</span> encoding <span class="op">%</span> <span class="dv">2</span><span class="op">);</span></span></code></pre></div>
<p>I used the modulo operator this time, because <code>+</code> takes precedence over <code>&amp;</code>.
The assignment can be incorporated into the <code>while</code> control test, and a
<code>do-while</code> loop with a body of a single expression statement can be written
as a <code>while</code> loop with a comma operator in the test:</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="cf">while</span><span class="op">(</span>putchar<span class="op">(</span><span class="dv">45</span> <span class="op">+</span> encoding <span class="op">%</span> <span class="dv">2</span><span class="op">),</span> encoding <span class="op">=</span> encoding <span class="op">+</span> <span class="dv">32</span> <span class="op">&gt;&gt;</span> <span class="dv">1</span><span class="op">);</span></span></code></pre></div>
<div class="sourceCode" id="cb10"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">while</span><span class="op">(</span>putchar<span class="op">(</span><span class="dv">45</span> <span class="op">+</span> encoding <span class="op">%</span> <span class="dv">2</span><span class="op">),</span> encoding <span class="op">=</span> encoding <span class="op">+</span> <span class="dv">32</span> <span class="op">&gt;&gt;</span> <span class="dv">1</span><span class="op">);</span></span></code></pre></div>
<p>Voila.</p>
<p>Now, the decoding of Morse codes is just the reverse. We shift in <code>0</code>s
and <code>1</code>s as we scan the line. But: we have to scan from back to front
@@ -218,22 +218,22 @@ is a valid encoding ! We must, however, use <code>memchr(3)</code> instead of <c
the decoding lookup because of this <code>'\0'</code>. Since it is far more obscure
this way, I hope you’ll forgive me.</p>
<p>The outline of the program is roughly as follows</p>
<pre><code>while (more lines) {
if (line is in morse) {
while (more characters) {
skip next sequence
if (&#39; &#39;)
putchar(&#39; &#39;);
else
decode_sequence; /* backwards */
}
} else {
while (more characters) {
if (isalnum)
encode_character;
putchar(&#39; &#39;);
}
}</code></pre>
<pre><code> while (more lines) {
if (line is in morse) {
while (more characters) {
skip next sequence
if (&#39; &#39;)
putchar(&#39; &#39;);
else
decode_sequence; /* backwards */
}
} else {
while (more characters) {
if (isalnum)
encode_character;
putchar(&#39; &#39;);
}
}</code></pre>
<p>Because of the <em>two</em> <code>while(more characters)</code> loops are the same, I’ve
exchanged the <code>if(line is in morse)</code> and the two <code>while</code> loops (so there
is <em>single</em> <code>while</code> loop). However, we must now store the <code>if(line is in morse)</code> test for efficiency (it would be stupid to test the entire line
@@ -246,13 +246,13 @@ as the temporary <code>l[0]</code> will remain <code>!= 0</code>.</p>
<p>I’ve put the <code>if</code>s in the above layout into a single switch. Hope you don’t
mind ;-)</p>
<p>Summary of the use of l[999]:</p>
<pre><code>l[0] result of &quot;is this line in morse&quot; test
l[0] temporary shift during encoding
l[0] - l[33] Morse codings (letters and digits, plus garbage)
l[11] - l[14] strspn argument
l[12] - l[14] strspn argument
l[34] terminator for backward decoding
l[35] - l[998] input line</code></pre>
<pre><code> l[0] result of &quot;is this line in morse&quot; test
l[0] temporary shift during encoding
l[0] - l[33] Morse codings (letters and digits, plus garbage)
l[11] - l[14] strspn argument
l[12] - l[14] strspn argument
l[34] terminator for backward decoding
l[35] - l[998] input line</code></pre>
<hr />
<p>Selected notes:
- We don’t need to declare <code>isalnum(3)</code> (or include ctype.h) as its implicit