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:
1 parent
b84c27ce02
commit
a996f8d2b8
734 files changed
+16723
-16963
No files matched your search
+46
-47
@@ -1,7 +1,7 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
make all
|
||||
make all
|
||||
```
|
||||
|
||||
There is an alternate version of this entry that will work with macOS. See the
|
||||
@@ -13,7 +13,7 @@ includes some interesting details about the entry.
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
./schweikh1
|
||||
./schweikh1
|
||||
```
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ if you don't have a Mac as it has some interesting details about the entry.
|
||||
### Alternate build:
|
||||
|
||||
```sh
|
||||
make alt
|
||||
make alt
|
||||
```
|
||||
|
||||
|
||||
@@ -88,15 +88,15 @@ the most likely result is no output and/or an exit status of 1.
|
||||
If Amendment One headers are missing you will see something like:
|
||||
|
||||
```
|
||||
<iso646.h>:
|
||||
gcc: /usr/include/iso646.h: No such file or directory
|
||||
gcc: No input files specified
|
||||
<wctype.h>:
|
||||
gcc: /usr/include/wctype.h: No such file or directory
|
||||
gcc: No input files specified
|
||||
<wchar.h>:
|
||||
gcc: /usr/include/wchar.h: No such file or directory
|
||||
gcc: No input files specified
|
||||
<iso646.h>:
|
||||
gcc: /usr/include/iso646.h: No such file or directory
|
||||
gcc: No input files specified
|
||||
<wctype.h>:
|
||||
gcc: /usr/include/wctype.h: No such file or directory
|
||||
gcc: No input files specified
|
||||
<wchar.h>:
|
||||
gcc: /usr/include/wchar.h: No such file or directory
|
||||
gcc: No input files specified
|
||||
```
|
||||
|
||||
Bug your vendor for an upgrade.
|
||||
@@ -127,17 +127,17 @@ programs that may fail to compile due to syntax errors: supposing that
|
||||
`<stdio.h>` defines `PIPE_BUF`, then the conforming
|
||||
|
||||
```c
|
||||
#include <assert.h>
|
||||
#include <stdio.h> /* <- or where the bogus macro is defined */
|
||||
#include <string.h>
|
||||
#define STR(x) #x
|
||||
#define XSTR(x) STR(x)
|
||||
int main (void)
|
||||
{
|
||||
int PIPE_BUF = 0;
|
||||
assert (strcmp ("PIPE_BUF", XSTR (PIPE_BUF)) == 0);
|
||||
return 0;
|
||||
}
|
||||
#include <assert.h>
|
||||
#include <stdio.h> /* <- or where the bogus macro is defined */
|
||||
#include <string.h>
|
||||
#define STR(x) #x
|
||||
#define XSTR(x) STR(x)
|
||||
int main (void)
|
||||
{
|
||||
int PIPE_BUF = 0;
|
||||
assert (strcmp ("PIPE_BUF", XSTR (PIPE_BUF)) == 0);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
is expected to compile and meet the assertion. If it does not, your
|
||||
@@ -155,18 +155,18 @@ C compilers.
|
||||
must resemble one of the canonical forms, `"foo.h"` or `<bar.h>`.
|
||||
This lets us write things like
|
||||
|
||||
```c
|
||||
#define HEADER "foo.h"
|
||||
#include HEADER
|
||||
```
|
||||
```c
|
||||
#define HEADER "foo.h"
|
||||
#include HEADER
|
||||
```
|
||||
|
||||
I could not find a compiler rejecting this. However, if we're
|
||||
torturing the preprocessor a little more, by using token pasting,
|
||||
at least one compiler falls over.
|
||||
|
||||
```c
|
||||
#define H(x) <st##x##.h>
|
||||
#include H(dio) /* expands to <stdio.h> */
|
||||
#define H(x) <st##x##.h>
|
||||
#include H(dio) /* expands to <stdio.h> */
|
||||
```
|
||||
|
||||
is rejected by tcc version 4.1.2, the TenDRA compiler:
|
||||
@@ -188,19 +188,19 @@ C compilers.
|
||||
which may include octal escape sequences. Let's look at
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
#line 42 "foo\0bar"
|
||||
int main (void) {
|
||||
printf ("%s %d\n", __FILE__, (int)sizeof __FILE__);
|
||||
return 0;
|
||||
}
|
||||
#include <stdio.h>
|
||||
#line 42 "foo\0bar"
|
||||
int main (void) {
|
||||
printf ("%s %d\n", __FILE__, (int)sizeof __FILE__);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
This is supposed to output `'foo 8'`. Here's what happens in RL:
|
||||
|
||||
```
|
||||
foo 4 gcc 2.7.2.1, lcc
|
||||
foo\0bar 9 tcc 4.1.2, Sunsoft cc turn "\0" into "\\0", ugh!
|
||||
foo 4 gcc 2.7.2.1, lcc
|
||||
foo\0bar 9 tcc 4.1.2, Sunsoft cc turn "\0" into "\\0", ugh!
|
||||
```
|
||||
|
||||
(I have written a bug report for gcc. Newer versions and egcs are ok.)
|
||||
@@ -215,8 +215,8 @@ foo\0bar 9 tcc 4.1.2, Sunsoft cc turn "\0" into "\\0", ugh!
|
||||
no chance to use Standardese weasel words as an escape: can I have
|
||||
|
||||
```c
|
||||
case <some_token>:
|
||||
case <some_token>:
|
||||
case <some_token>:
|
||||
case <some_token>:
|
||||
```
|
||||
|
||||
in the same switch? (Note that you need the [invisible] newline. You
|
||||
@@ -256,19 +256,18 @@ The advantages of an independent clean room approach...
|
||||
|
||||
|
||||
```perl
|
||||
#!/usr/bin/perl -w
|
||||
$/ = "\0";
|
||||
$_ = <>;
|
||||
s/[;{}][ \t\n]/\n/g;
|
||||
s/[ \t\n]+//g;
|
||||
print length ($_),"\n";
|
||||
|
||||
#!/usr/bin/perl -w
|
||||
$/ = "\0";
|
||||
$_ = <>;
|
||||
s/[;{}][ \t\n]/\n/g;
|
||||
s/[ \t\n]+//g;
|
||||
print length ($_),"\n";
|
||||
```
|
||||
|
||||
To use, try:
|
||||
|
||||
```sh
|
||||
perl ./charcount.pl schweikh1.c
|
||||
perl ./charcount.pl schweikh1.c
|
||||
```
|
||||
|
||||
|
||||
|
||||
+45
-46
@@ -132,8 +132,7 @@
|
||||
<h2 id="author"><a name="author"></a>Author:</h2>
|
||||
<ul>
|
||||
<li>Name: <a href="../../authors.html#Jens_Schweikhardt">Jens Schweikhardt</a><br>
|
||||
Location: <a href="../../location.html#DE">DE</a> - <em>Federal Republic of Germany</em> (<em>Germany</em>)
|
||||
<br><br></li>
|
||||
Location: <a href="../../location.html#DE">DE</a> - <em>Federal Republic of Germany</em> (<em>Germany</em>)</li>
|
||||
</ul>
|
||||
|
||||
<!-- END: next line ends content generated by: bin/output-index-author.sh -->
|
||||
@@ -142,13 +141,13 @@ Location: <a href="../../location.html#DE">DE</a> - <em>Federal Republic of Germ
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<h2 id="to-build">To build:</h2>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">make</span> all</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> all</span></code></pre></div>
|
||||
<p>There is an alternate version of this entry that will work with macOS. See the
|
||||
<a href="#alternate-code">Alternate code</a> section below. We recommend you look at it
|
||||
even if you don’t have a Mac, unless you want to figure it out yourself, as it
|
||||
includes some interesting details about the entry.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./schweikh1</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./schweikh1</span></span></code></pre></div>
|
||||
<h2 id="alternate-code">Alternate code:</h2>
|
||||
<p>As noted above this entry will not work as it stands for macOS and there are
|
||||
some important notes as well as a description of how the fixed version works
|
||||
@@ -158,7 +157,7 @@ adjustments). For details of what had to change, see <a href="macos.html">macos.
|
||||
Unless you wish to figure it out yourself, we recommend that you read this even
|
||||
if you don’t have a Mac as it has some interesting details about the entry.</p>
|
||||
<h3 id="alternate-build">Alternate build:</h3>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">make</span> alt</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">make</span> alt</span></code></pre></div>
|
||||
<h3 id="alternate-build-1">Alternate build:</h3>
|
||||
<p>Use <code>schweikh1.alt</code> as you would <code>schweikh1</code> above.</p>
|
||||
<h3 id="alternate-try">Alternate try:</h3>
|
||||
@@ -193,15 +192,15 @@ When run, it is likely to uncover bugs in your system headers.</p>
|
||||
<p>The program is run without arguments. If your compiler is buggy,
|
||||
the most likely result is no output and/or an exit status of 1.</p>
|
||||
<p>If Amendment One headers are missing you will see something like:</p>
|
||||
<pre><code><iso646.h>:
|
||||
gcc: /usr/include/iso646.h: No such file or directory
|
||||
gcc: No input files specified
|
||||
<wctype.h>:
|
||||
gcc: /usr/include/wctype.h: No such file or directory
|
||||
gcc: No input files specified
|
||||
<wchar.h>:
|
||||
gcc: /usr/include/wchar.h: No such file or directory
|
||||
gcc: No input files specified</code></pre>
|
||||
<pre><code> <iso646.h>:
|
||||
gcc: /usr/include/iso646.h: No such file or directory
|
||||
gcc: No input files specified
|
||||
<wctype.h>:
|
||||
gcc: /usr/include/wctype.h: No such file or directory
|
||||
gcc: No input files specified
|
||||
<wchar.h>:
|
||||
gcc: /usr/include/wchar.h: No such file or directory
|
||||
gcc: No input files specified</code></pre>
|
||||
<p>Bug your vendor for an upgrade.</p>
|
||||
<p>The format of the info file is straightforward and described in the file
|
||||
itself. Just load it in your favorite editor.</p>
|
||||
@@ -221,17 +220,17 @@ macros are explicitly enumerated. In a compliant implementation no other
|
||||
macros can be defined, because you could write strictly conforming
|
||||
programs that may fail to compile due to syntax errors: supposing that
|
||||
<code><stdio.h></code> defines <code>PIPE_BUF</code>, then the conforming</p>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="pp">#include </span><span class="im"><assert.h></span></span>
|
||||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a><span class="pp">#include </span><span class="im"><stdio.h></span><span class="pp"> </span><span class="co">/* <- or where the bogus macro is defined */</span></span>
|
||||
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="pp">#include </span><span class="im"><string.h></span></span>
|
||||
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a><span class="pp">#define STR</span><span class="op">(</span><span class="pp">x</span><span class="op">)</span><span class="pp"> </span><span class="op">#</span><span class="pp">x</span></span>
|
||||
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a><span class="pp">#define XSTR</span><span class="op">(</span><span class="pp">x</span><span class="op">)</span><span class="pp"> STR</span><span class="op">(</span><span class="pp">x</span><span class="op">)</span></span>
|
||||
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a><span class="dt">int</span> main <span class="op">(</span><span class="dt">void</span><span class="op">)</span></span>
|
||||
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
|
||||
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span> PIPE_BUF <span class="op">=</span> <span class="dv">0</span><span class="op">;</span></span>
|
||||
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> assert <span class="op">(</span>strcmp <span class="op">(</span><span class="st">"PIPE_BUF"</span><span class="op">,</span> XSTR <span class="op">(</span>PIPE_BUF<span class="op">))</span> <span class="op">==</span> <span class="dv">0</span><span class="op">);</span></span>
|
||||
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="dv">0</span><span class="op">;</span></span>
|
||||
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb5"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#include </span><span class="im"><assert.h></span></span>
|
||||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="pp">#include </span><span class="im"><stdio.h></span><span class="pp"> </span><span class="co">/* <- or where the bogus macro is defined */</span></span>
|
||||
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <span class="pp">#include </span><span class="im"><string.h></span></span>
|
||||
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> <span class="pp">#define STR</span><span class="op">(</span><span class="pp">x</span><span class="op">)</span><span class="pp"> </span><span class="op">#</span><span class="pp">x</span></span>
|
||||
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="pp">#define XSTR</span><span class="op">(</span><span class="pp">x</span><span class="op">)</span><span class="pp"> STR</span><span class="op">(</span><span class="pp">x</span><span class="op">)</span></span>
|
||||
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span> main <span class="op">(</span><span class="dt">void</span><span class="op">)</span></span>
|
||||
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> <span class="op">{</span></span>
|
||||
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span> PIPE_BUF <span class="op">=</span> <span class="dv">0</span><span class="op">;</span></span>
|
||||
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> assert <span class="op">(</span>strcmp <span class="op">(</span><span class="st">"PIPE_BUF"</span><span class="op">,</span> XSTR <span class="op">(</span>PIPE_BUF<span class="op">))</span> <span class="op">==</span> <span class="dv">0</span><span class="op">);</span></span>
|
||||
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="dv">0</span><span class="op">;</span></span>
|
||||
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<p>is expected to compile and meet the assertion. If it does not, your
|
||||
compiler compiles some other language than ISO C.</p>
|
||||
<h3 id="why-i-think-my-program-is-obfuscated">Why I think my program is obfuscated</h3>
|
||||
@@ -244,13 +243,13 @@ C compilers.</p>
|
||||
must resemble one of the canonical forms, <code>"foo.h"</code> or <code><bar.h></code>.
|
||||
This lets us write things like</li>
|
||||
</ol>
|
||||
<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="pp">#define HEADER </span><span class="st">"foo.h"</span></span>
|
||||
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="pp">#include HEADER</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="pp">#define HEADER </span><span class="st">"foo.h"</span></span>
|
||||
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="pp">#include HEADER</span></span></code></pre></div>
|
||||
<p>I could not find a compiler rejecting this. However, if we’re
|
||||
torturing the preprocessor a little more, by using token pasting,
|
||||
at least one compiler falls over.</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="pp">#define H</span><span class="op">(</span><span class="pp">x</span><span class="op">)</span><span class="pp"> </span><span class="op"><</span><span class="pp">st</span><span class="op">##</span><span class="pp">x</span><span class="op">##.</span><span class="pp">h</span><span class="op">></span></span>
|
||||
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="pp">#include H(dio) </span><span class="co">/* expands to <stdio.h> */</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="pp">#define H</span><span class="op">(</span><span class="pp">x</span><span class="op">)</span><span class="pp"> </span><span class="op"><</span><span class="pp">st</span><span class="op">##</span><span class="pp">x</span><span class="op">##.</span><span class="pp">h</span><span class="op">></span></span>
|
||||
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="pp">#include H(dio) </span><span class="co">/* expands to <stdio.h> */</span></span></code></pre></div>
|
||||
<p>is rejected by tcc version 4.1.2, the TenDRA compiler:
|
||||
<code>"t.c", line 3: Error:\ [ISO 6.8.3.3]: Invalid result for '##' operator in macro 'H'.</code></p>
|
||||
<p>To be honest, I don’t know if the rules for pp-tokens and token
|
||||
@@ -265,15 +264,15 @@ allows: in <code>#line num "file"</code> the <code>"file"</code> is an s-char-se
|
||||
ISO 6.8.4. ISO 6.1.4 defines string literals as s-char-sequences,
|
||||
which may include octal escape sequences. Let’s look at</li>
|
||||
</ol>
|
||||
<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="pp">#include </span><span class="im"><stdio.h></span></span>
|
||||
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="pp">#line 42 "foo\0bar"</span></span>
|
||||
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a><span class="dt">int</span> main <span class="op">(</span><span class="dt">void</span><span class="op">)</span> <span class="op">{</span></span>
|
||||
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> printf <span class="op">(</span><span class="st">"</span><span class="sc">%s</span><span class="st"> </span><span class="sc">%d\n</span><span class="st">"</span><span class="op">,</span> __FILE__<span class="op">,</span> <span class="op">(</span><span class="dt">int</span><span class="op">)</span><span class="kw">sizeof</span> __FILE__<span class="op">);</span></span>
|
||||
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="dv">0</span><span class="op">;</span></span>
|
||||
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a><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="pp">#include </span><span class="im"><stdio.h></span></span>
|
||||
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="pp">#line 42 "foo\0bar"</span></span>
|
||||
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">int</span> main <span class="op">(</span><span class="dt">void</span><span class="op">)</span> <span class="op">{</span></span>
|
||||
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> printf <span class="op">(</span><span class="st">"</span><span class="sc">%s</span><span class="st"> </span><span class="sc">%d\n</span><span class="st">"</span><span class="op">,</span> __FILE__<span class="op">,</span> <span class="op">(</span><span class="dt">int</span><span class="op">)</span><span class="kw">sizeof</span> __FILE__<span class="op">);</span></span>
|
||||
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="dv">0</span><span class="op">;</span></span>
|
||||
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<p>This is supposed to output <code>'foo 8'</code>. Here’s what happens in RL:</p>
|
||||
<pre><code>foo 4 gcc 2.7.2.1, lcc
|
||||
foo\0bar 9 tcc 4.1.2, Sunsoft cc turn "\0" into "\\0", ugh!</code></pre>
|
||||
<pre><code> foo 4 gcc 2.7.2.1, lcc
|
||||
foo\0bar 9 tcc 4.1.2, Sunsoft cc turn "\0" into "\\0", ugh!</code></pre>
|
||||
<p>(I have written a bug report for gcc. Newer versions and egcs are ok.)</p>
|
||||
<ol start="3" type="1">
|
||||
<li><p>The <code>%:</code> and <code>%:%:</code> digraphs test for conformance to Amendment One.</p>
|
||||
@@ -284,8 +283,8 @@ ISO 6.6.4.2. Then make fun of the guru’s answer by waving <code>case __LINE__:
|
||||
under his/her nose. Easy money from a bet! Make sure your guru has
|
||||
no chance to use Standardese weasel words as an escape: can I have</p></li>
|
||||
</ol>
|
||||
<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">case</span> <span class="op"><</span>some_token<span class="op">>:</span></span>
|
||||
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">case</span> <span class="op"><</span>some_token<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">case</span> <span class="op"><</span>some_token<span class="op">>:</span></span>
|
||||
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">case</span> <span class="op"><</span>some_token<span class="op">>:</span></span></code></pre></div>
|
||||
<p>in the same switch? (Note that you need the [invisible] newline. You
|
||||
can generously allow the additional constraint that no <code>#undef</code>s or
|
||||
<code>#define</code>s are allowed between the two cases.)</p>
|
||||
@@ -316,14 +315,14 @@ I could have used a lot more <code>^K</code> and <code>^L</code> probably undete
|
||||
counter but decided to err on the side of safety. I use a perl
|
||||
script to compute the character count according to the rules.
|
||||
The advantages of an independent clean room approach…</p>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode perl"><code class="sourceCode perl"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="kw">#!/usr/bin/perl -w</span></span>
|
||||
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="wa">$/</span> = <span class="ot">"</span><span class="st">\0</span><span class="ot">"</span>;</span>
|
||||
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="wa">$_</span> = <>;</span>
|
||||
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a><span class="ot">s/</span><span class="ch">[</span><span class="bn">;{}</span><span class="ch">][</span><span class="bn"> \t\n</span><span class="ch">]</span><span class="ot">/</span><span class="ch">\n</span><span class="ot">/g</span>;</span>
|
||||
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a><span class="ot">s/</span><span class="ch">[</span><span class="bn"> \t\n</span><span class="ch">]+</span><span class="ot">//g</span>;</span>
|
||||
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span> <span class="fu">length</span> (<span class="wa">$_</span>),<span class="ot">"</span><span class="ch">\n</span><span class="ot">"</span>;</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode perl"><code class="sourceCode perl"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="co">#!/usr/bin/perl -w</span></span>
|
||||
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="wa">$/</span> = <span class="ot">"</span><span class="st">\0</span><span class="ot">"</span>;</span>
|
||||
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> <span class="wa">$_</span> = <>;</span>
|
||||
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> <span class="ot">s/</span><span class="ch">[</span><span class="bn">;{}</span><span class="ch">][</span><span class="bn"> \t\n</span><span class="ch">]</span><span class="ot">/</span><span class="ch">\n</span><span class="ot">/g</span>;</span>
|
||||
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a> <span class="ot">s/</span><span class="ch">[</span><span class="bn"> \t\n</span><span class="ch">]+</span><span class="ot">//g</span>;</span>
|
||||
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">print</span> <span class="fu">length</span> (<span class="wa">$_</span>),<span class="ot">"</span><span class="ch">\n</span><span class="ot">"</span>;</span></code></pre></div>
|
||||
<p>To use, try:</p>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">perl</span> ./charcount.pl schweikh1.c</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">perl</span> ./charcount.pl schweikh1.c</span></code></pre></div>
|
||||
<p>I have tried, as suggested in the guidelines, to let the code look
|
||||
like ordinary C code. Apart from a few long lines I think I left
|
||||
the indentation like I would in RL. You should however not try to
|
||||
|
||||
@@ -138,7 +138,7 @@ a file was not found (this limitation was removed in both versions in 2023). see
|
||||
<p>However, as noted, macOS does <strong>not</strong> have <code>/usr/include</code> so this would never
|
||||
work for macOS without some changes, described next. For macOS you will need the
|
||||
command line tools installed which can be done like:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">sudo</span> xcode-select <span class="at">--install</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">sudo</span> xcode-select <span class="at">--install</span></span></code></pre></div>
|
||||
<p>An important point is that the original version hard-coded <code>gcc</code> but just like
|
||||
the entry, the alternate version has also removed this limitation despite <code>gcc</code>
|
||||
existing (though it’s <code>clang</code>) in macOS.</p>
|
||||
@@ -150,13 +150,13 @@ string and the other a couple lines further below.</p>
|
||||
<p>In the original the numbers are, respectively, <code>44</code> and <code>46</code>, but with the gcc
|
||||
limitation removed the numbers now are <code>43</code> and <code>45</code>. But how does this work? Well
|
||||
the command is:</p>
|
||||
<pre><code>"0gcc -ansi -E -dM -undef %s /usr/include/%s>r\0 ("</code></pre>
|
||||
<pre><code> "0gcc -ansi -E -dM -undef %s /usr/include/%s>r\0 ("</code></pre>
|
||||
<p>which has been changed to be:</p>
|
||||
<pre><code>"0cc -ansi -E -dM -undef %s /usr/include/%s>r\0 ("</code></pre>
|
||||
<p>Shortly below that you will see, as noted above, the numbers:</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><span class="cf">if</span> <span class="op">((</span>H <span class="op">=</span> fopen <span class="op">(</span>__FILE__<span class="op">+</span><span class="dv">43</span><span class="op">,</span> <span class="dv">43</span><span class="op">+</span>__FILE__<span class="op">)))</span></span>
|
||||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="cf">while</span> <span class="op">((</span>fgets <span class="op">(</span>L<span class="op">,</span> <span class="op">(</span><span class="dt">int</span><span class="op">)</span><span class="kw">sizeof</span> L<span class="op">,</span> H<span class="op">))</span> <span class="op">!=</span> <span class="dv">0</span><span class="op">)</span> <span class="op">{</span></span>
|
||||
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> I<span class="op">[</span>strcspn <span class="op">(</span>I<span class="op">,</span> <span class="dv">45</span><span class="op">+</span>__FILE__<span class="op">)]</span> <span class="op">=</span> O <span class="op">=</span> <span class="dv">0</span><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> <span class="cf">if</span> <span class="op">((</span>H <span class="op">=</span> fopen <span class="op">(</span>__FILE__<span class="op">+</span><span class="dv">43</span><span class="op">,</span> <span class="dv">43</span><span class="op">+</span>__FILE__<span class="op">)))</span></span>
|
||||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">while</span> <span class="op">((</span>fgets <span class="op">(</span>L<span class="op">,</span> <span class="op">(</span><span class="dt">int</span><span class="op">)</span><span class="kw">sizeof</span> L<span class="op">,</span> H<span class="op">))</span> <span class="op">!=</span> <span class="dv">0</span><span class="op">)</span> <span class="op">{</span></span>
|
||||
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> I<span class="op">[</span>strcspn <span class="op">(</span>I<span class="op">,</span> <span class="dv">45</span><span class="op">+</span>__FILE__<span class="op">)]</span> <span class="op">=</span> O <span class="op">=</span> <span class="dv">0</span><span class="op">;</span></span></code></pre></div>
|
||||
<p>The first number in the above C means the length starting from 0 up through the
|
||||
<code>></code>. The second number is the same starting point but up through the <code>\0</code> which
|
||||
is why it’s <code>+2</code>. But what happens if only the first number is updated (from the
|
||||
|
||||
@@ -20,7 +20,7 @@ work for macOS without some changes, described next. For macOS you will need the
|
||||
command line tools installed which can be done like:
|
||||
|
||||
```sh
|
||||
sudo xcode-select --install
|
||||
sudo xcode-select --install
|
||||
```
|
||||
|
||||
An important point is that the original version hard-coded `gcc` but just like
|
||||
@@ -39,7 +39,7 @@ limitation removed the numbers now are `43` and `45`. But how does this work? We
|
||||
the command is:
|
||||
|
||||
```
|
||||
"0gcc -ansi -E -dM -undef %s /usr/include/%s>r\0 ("
|
||||
"0gcc -ansi -E -dM -undef %s /usr/include/%s>r\0 ("
|
||||
```
|
||||
|
||||
which has been changed to be:
|
||||
@@ -51,9 +51,9 @@ which has been changed to be:
|
||||
Shortly below that you will see, as noted above, the numbers:
|
||||
|
||||
```c
|
||||
if ((H = fopen (__FILE__+43, 43+__FILE__)))
|
||||
while ((fgets (L, (int)sizeof L, H)) != 0) {
|
||||
I[strcspn (I, 45+__FILE__)] = O = 0;
|
||||
if ((H = fopen (__FILE__+43, 43+__FILE__)))
|
||||
while ((fgets (L, (int)sizeof L, H)) != 0) {
|
||||
I[strcspn (I, 45+__FILE__)] = O = 0;
|
||||
```
|
||||
|
||||
The first number in the above C means the length starting from 0 up through the
|
||||
|
||||
Reference in new issue
Block a user