force use of pandoc version >= 3.1.12.2
The `bin/pandoc-wrapper.sh` tool will verify that the ssytem has a recent enough version of `pandoc(1)`. We explain why we insist on `pandoc(1)`. version >= 3.1.12.2 in comments where the $PANDOC_MIN_VERSION is set. Added `--wrap=preserve` as a default argument to `pandoc(1)`. While this change will impact every HTML file generated, we believe this will improve the ability of someone to look at the generated HTML and correlate with the original markdown. Changed `bin/pandoc-wrapper.sh` VERSION from "1.4.2 2024-03-17" to "1.4.3 2024-03-18". Performed `make www` to achieve all of the above and to generate HTML using the new `--wrap=preserve` `pandoc(1)` mode.
This commit is contained in:
1 parent
9eb7a54e9f
commit
b0b212acb1
402 files changed
+37061
-55132
No files matched your search
+128
-173
@@ -129,9 +129,9 @@
|
||||
|
||||
<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>
|
||||
<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>
|
||||
</ul>
|
||||
|
||||
<!-- END: next line ends content generated by: bin/output-index-author.sh -->
|
||||
@@ -141,58 +141,55 @@ Schweikhardt</a><br> Location: <a href="../../location.html#DE">DE</a> -
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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 (the details of which are relevant to the original entry
|
||||
that no longer works as well as the fixed version but are described in
|
||||
the context of the macOS adjustments). For details of what had to
|
||||
change, see <a href="macos.html">macos.html</a>. 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>
|
||||
<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
|
||||
(the details of which are relevant to the original entry that no longer works as
|
||||
well as the fixed version but are described in the context of the macOS
|
||||
adjustments). For details of what had to change, see <a href="macos.html">macos.html</a>.
|
||||
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>
|
||||
<h3 id="alternate-build-1">Alternate build:</h3>
|
||||
<p>Use <code>schweikh1.alt</code> as you would <code>schweikh1</code>
|
||||
above.</p>
|
||||
<p>Use <code>schweikh1.alt</code> as you would <code>schweikh1</code> above.</p>
|
||||
<h3 id="alternate-try">Alternate try:</h3>
|
||||
<p>Bonus exercise: modify the code to provide a different compiler.</p>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
<p>What does it do? It seems to print a list of system headers, perhaps
|
||||
with words after them. Curiously, if you look at the list of words
|
||||
defined in a given standard header, they are never printed directly
|
||||
after that header’s name. Aha! It’s a conformance test for the standard
|
||||
headers.</p>
|
||||
after that header’s name. Aha! It’s a conformance test for the
|
||||
standard headers.</p>
|
||||
<p>This code is a wonder; it’s a wonder that it compiles. I wonder
|
||||
whether or not it should. The innovative realization that you can use
|
||||
special characters, such as <code>'\n'</code>, in <code>#file</code>
|
||||
directives alone merits some recognition.</p>
|
||||
whether or not it should. The innovative realization that you can
|
||||
use special characters, such as <code>'\n'</code>, in <code>#file</code> directives alone
|
||||
merits some recognition.</p>
|
||||
<p>I’ve included most of the author’s remarks; they’re fairly thorough.
|
||||
Do not read them if you want to figure this out yourself. “Amendment
|
||||
One” refers to “NA1”, the add-on to C89 which added some fairly crufty
|
||||
internationalization support.</p>
|
||||
One” refers to “NA1”, the add-on to C89 which added some fairly
|
||||
crufty internationalization support.</p>
|
||||
<h4 id="historical-note">Historical note:</h4>
|
||||
<p>Some non-gcc compilers that were not fully ANSI standard did not
|
||||
compile this entry correctly. Using cc by default was not helpful most
|
||||
of the time on this entry, because the program had a hardcoded gcc
|
||||
invocation anyway. Anyone who uses egcs and has no plain gcc will need
|
||||
to frob the source anyway and can be expected to do the right thing with
|
||||
<code>${CC}</code>. This limitation was removed in 2023 but in the past
|
||||
compile this entry correctly. Using cc by default was not helpful
|
||||
most of the time on this entry, because the program had a hardcoded
|
||||
gcc invocation anyway. Anyone who uses egcs and has no plain gcc
|
||||
will need to frob the source anyway and can be expected to do the
|
||||
right thing with <code>${CC}</code>. This limitation was removed in 2023 but in the past
|
||||
one should have used gcc.</p>
|
||||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||||
<p>Important! This program, if it compiles at all, is mis-compiled by
|
||||
many compilers due to compiler bugs. It could be the “least likely to
|
||||
compile and execute” in conjunction with preprocessor abuse. 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>Important! This program, if it compiles at all, is mis-compiled by many
|
||||
compilers due to compiler bugs. It could be the “least likely
|
||||
to compile and execute” in conjunction with preprocessor abuse.
|
||||
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
|
||||
@@ -204,27 +201,24 @@ gcc: No input files specified
|
||||
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>
|
||||
<p>The format of the info file is straightforward and described in the file
|
||||
itself. Just load it in your favorite editor.</p>
|
||||
<h3 id="requirements">Requirements</h3>
|
||||
<p><code>gcc</code> (the GNU C compiler) must be available at runtime.
|
||||
It is assumed that your C implementation keeps headers as files in the
|
||||
<code>/usr/include</code> directory. The <a href="info">info</a> file
|
||||
must be readable and reside in the current working directory. The
|
||||
current working directory must be writable in order to create a
|
||||
temporary file (which is removed upon program termination). In case you
|
||||
don’t have gcc at runtime, not all is lost if your compiler or
|
||||
preprocessor can produce a list of defined macros in the format output
|
||||
by <code>gcc -dM</code>, i.e. lines of the form
|
||||
<p><code>gcc</code> (the GNU C compiler) must be available at runtime. It is assumed that your
|
||||
C implementation keeps headers as files in the <code>/usr/include</code> directory. The
|
||||
<a href="info">info</a> file must be readable and reside in the current working directory.
|
||||
The current working directory must be writable in order to create a temporary
|
||||
file (which is removed upon program termination). In case you don’t have gcc at
|
||||
runtime, not all is lost if your compiler or preprocessor can produce a list of
|
||||
defined macros in the format output by <code>gcc -dM</code>, i.e. lines of the form
|
||||
<code>#define MACRO value</code>.</p>
|
||||
<p>Edit the source at line 55 in this case.</p>
|
||||
<h3 id="background">Background</h3>
|
||||
<p>ISO C has a very strict idea of visibility of identifiers. All
|
||||
possible 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>
|
||||
<p>ISO C has a very strict idea of visibility of identifiers. All possible
|
||||
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>
|
||||
@@ -238,38 +232,36 @@ supposing that <code><stdio.h></code> defines
|
||||
<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>
|
||||
<h3 id="why-i-think-my-program-is-obfuscated">Why I think my program is obfuscated</h3>
|
||||
<p>Not only is the program’s purpose a thorough standard conformance
|
||||
test, the source itself is a beast and has uncovered bugs in many C
|
||||
compilers.</p>
|
||||
test, the source itself is a beast and has uncovered bugs in many
|
||||
C compilers.</p>
|
||||
<ol type="1">
|
||||
<li>The token sequence after <code>#include</code> can consist of
|
||||
pp-tokens and “are processed just as in normal text.” [ISO 6.8.2] The
|
||||
result must resemble one of the canonical forms, <code>"foo.h"</code> or
|
||||
<code><bar.h></code>. This lets us write things like</li>
|
||||
<li>The token sequence after <code>#include</code> can consist of pp-tokens and
|
||||
“are processed just as in normal text.” [ISO 6.8.2] The result
|
||||
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>
|
||||
<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>
|
||||
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>
|
||||
<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
|
||||
pasting don’t forbid what I do (and thus tcc is correct in rejecting
|
||||
it). In this case, all other compilers I tried are buggy, or the
|
||||
Standard itself :-)</p>
|
||||
pasting don’t forbid what I do (and thus tcc is correct in rejecting it).
|
||||
In this case, all other compilers I tried are buggy, or the Standard
|
||||
itself :-)</p>
|
||||
<ol start="2" type="1">
|
||||
<li>The <code>#line</code> directive allows to set a line number, and
|
||||
optionally a file name, i.e. modify <code>__LINE__</code> and
|
||||
<code>__FILE__</code>. Strange things happen if the file name contains a
|
||||
NUL byte – which the Standard allows: in <code>#line num "file"</code>
|
||||
the <code>"file"</code> is an s-char-sequence per 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>
|
||||
<li>The <code>#line</code> directive allows to set a line number, and optionally
|
||||
a file name, i.e. modify <code>__LINE__</code> and <code>__FILE__</code>. Strange things
|
||||
happen if the file name contains a NUL byte – which the Standard
|
||||
allows: in <code>#line num "file"</code> the <code>"file"</code> is an s-char-sequence per
|
||||
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>
|
||||
@@ -277,22 +269,18 @@ escape sequences. Let’s look at</li>
|
||||
<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>
|
||||
<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>
|
||||
<p>(I have written a bug report for gcc. Newer versions and egcs are
|
||||
ok.)</p>
|
||||
<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>
|
||||
<p>Ask your local guru if C allows the same case label in the same
|
||||
switch statement to appear more than once. Ask him/her to think real
|
||||
hard. The answer will be “no”. The true guru will cite a constraint in
|
||||
ISO 6.6.4.2. Then make fun of the guru’s answer by waving
|
||||
<code>case __LINE__:</code> 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>
|
||||
<li><p>The <code>%:</code> and <code>%:%:</code> digraphs test for conformance to Amendment One.</p>
|
||||
<p>Ask your local guru if C allows the same case label in the same switch
|
||||
statement to appear more than once. Ask him/her to think real hard.
|
||||
The answer will be “no”. The true guru will cite a constraint in
|
||||
ISO 6.6.4.2. Then make fun of the guru’s answer by waving <code>case __LINE__:</code>
|
||||
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>
|
||||
@@ -300,116 +288,83 @@ escape: can I have</p></li>
|
||||
can generously allow the additional constraint that no `#undef`s or
|
||||
`#define`s are allowed between the two cases.)</code></pre>
|
||||
<p>Lots of integer constants and string literals come into the source
|
||||
via <code>__LINE__</code> and <code>__FILE__</code> which are redefined
|
||||
at various places. Sometimes the <code>__FILE__</code> contains
|
||||
<code>\0</code> bytes; different strings or characters are then accessed
|
||||
with offsets, say <code>10+__FILE__</code> or
|
||||
<code>__LINE__+__FILE__</code> or <code>2[__FILE__]</code>. One integral
|
||||
constant in octal. This makes the source and header input depend on
|
||||
ASCII.</p>
|
||||
<p>A few old obfuscations, like one character identifiers, not too many
|
||||
macros, a <code>goto O</code>, “needless” assignments to satisfy lint
|
||||
with its “function value ignored” warnings. My lint has nothing to
|
||||
complain about.</p>
|
||||
<p>There’s more whitespace in the Standard than just space, tab and
|
||||
newline. In particular, there are vertical tab and form-feed that can be
|
||||
used in certain places (outside of preprocessing directives, i.e. they
|
||||
are not allowed from just after the <code>#</code> up to the final
|
||||
newline. See 6.8 for details.) On many implementations these appear as
|
||||
<code>^L</code> and <code>^K</code>. My source starts with an extremely
|
||||
uncommon 32bit word consisting of <code>^L</code>, <code>^K</code>,
|
||||
<code>%</code> and <code>:</code>. I have grepped old winning entries
|
||||
for ^K, none of them contains one, so this is something new – after 14
|
||||
years of IOCCC. Be sure to have enough paper in your printer when you
|
||||
make a hard copy of the source…</p>
|
||||
<p>While I’m at it, the rules state that only space, tab and newline are
|
||||
ignored for the count (plus ‘<code>{</code>’, ‘<code>}</code>’,
|
||||
‘<code>;</code>’ followed by whitespace). The <a
|
||||
href="../mkentry.c">mkentry.c</a> program, however, uses
|
||||
<code>isspace(3)</code> which returns nonzero for <code>\v</code> and
|
||||
<code>\f</code> and other characters as well. I could have used a lot
|
||||
more <code>^K</code> and <code>^L</code> probably undetected by your
|
||||
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="cb12"><pre
|
||||
class="sourceCode perl"><code class="sourceCode perl"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="kw">#!/usr/bin/perl -w</span></span>
|
||||
via <code>__LINE__</code> and <code>__FILE__</code> which are redefined at various places.
|
||||
Sometimes the <code>__FILE__</code> contains <code>\0</code> bytes; different strings or
|
||||
characters are then accessed with offsets, say <code>10+__FILE__</code> or
|
||||
<code>__LINE__+__FILE__</code> or <code>2[__FILE__]</code>. One integral constant in octal.
|
||||
This makes the source and header input depend on ASCII.</p>
|
||||
<p>A few old obfuscations, like one character identifiers, not too
|
||||
many macros, a <code>goto O</code>, “needless” assignments to satisfy lint
|
||||
with its “function value ignored” warnings. My lint has nothing
|
||||
to complain about.</p>
|
||||
<p>There’s more whitespace in the Standard than just space, tab and newline. In
|
||||
particular, there are vertical tab and form-feed that can be used in certain
|
||||
places (outside of preprocessing directives, i.e. they are not allowed from just
|
||||
after the <code>#</code> up to the final newline. See 6.8 for details.) On many
|
||||
implementations these appear as <code>^L</code> and <code>^K</code>. My source starts with an
|
||||
extremely uncommon 32bit word consisting of <code>^L</code>, <code>^K</code>, <code>%</code> and <code>:</code>. I have
|
||||
grepped old winning entries for ^K, none of them contains one, so this is
|
||||
something new – after 14 years of IOCCC. Be sure to have enough paper in your
|
||||
printer when you make a hard copy of the source…</p>
|
||||
<p>While I’m at it, the rules state that only space, tab and newline
|
||||
are ignored for the count (plus ‘<code>{</code>’, ‘<code>}</code>’, ‘<code>;</code>’ followed by
|
||||
whitespace). The <a href="../mkentry.c">mkentry.c</a> program, however, uses <code>isspace(3)</code> which
|
||||
returns nonzero for <code>\v</code> and <code>\f</code> and other characters as well.
|
||||
I could have used a lot more <code>^K</code> and <code>^L</code> probably undetected by your
|
||||
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="cb12"><pre class="sourceCode perl"><code class="sourceCode perl"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="kw">#!/usr/bin/perl -w</span></span>
|
||||
<span id="cb12-2"><a href="#cb12-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="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a><span class="wa">$_</span> = <>;</span>
|
||||
<span id="cb12-4"><a href="#cb12-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="cb12-5"><a href="#cb12-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="cb12-6"><a href="#cb12-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="cb13"><pre
|
||||
class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="fu">perl</span> ./charcount.pl schweikh1.c</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb13"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-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 use
|
||||
<code>indent</code> on the source. The code is extremely fragile because
|
||||
of the myriads of <code>__LINE__</code> macros – indenting is a sure way
|
||||
to break the program. Don’t even think of maintaining that beast; I’ve
|
||||
had my share of core dumps during development :-) A test suite was used
|
||||
after every minor change to find out if the program still does what it
|
||||
should.</p>
|
||||
<p>From the goals: “To stress C compilers with unusual code.” That
|
||||
describes exactly my modest attempts…</p>
|
||||
<h2 id="copyright-and-cc-by-sa-4.0-license">Copyright and CC BY-SA 4.0
|
||||
License:</h2>
|
||||
<p>This file is Copyright (c) 2023 by Landon Curt Noll. All Rights
|
||||
Reserved. You are free to share and adapt this file under the terms of
|
||||
this license:</p>
|
||||
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
|
||||
use <code>indent</code> on the source. The code is extremely fragile because of the
|
||||
myriads of <code>__LINE__</code> macros – indenting is a sure way to break
|
||||
the program. Don’t even think of maintaining that beast; I’ve
|
||||
had my share of core dumps during development :-) A test suite
|
||||
was used after every minor change to find out if the program still
|
||||
does what it should.</p>
|
||||
<p>From the goals: “To stress C compilers with unusual code.”
|
||||
That describes exactly my modest attempts…</p>
|
||||
<h2 id="copyright-and-cc-by-sa-4.0-license">Copyright and CC BY-SA 4.0 License:</h2>
|
||||
<p>This file is Copyright (c) 2023 by Landon Curt Noll. All Rights Reserved.
|
||||
You are free to share and adapt this file under the terms of this license:</p>
|
||||
<pre><code>Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)</code></pre>
|
||||
<p>For more information, see:
|
||||
https://creativecommons.org/licenses/by-sa/4.0/</p>
|
||||
<p>For more information, see: https://creativecommons.org/licenses/by-sa/4.0/</p>
|
||||
|
||||
<!-- END: this line ends content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
<!-- START: this line starts content for HTML phase 22 by: bin/output-index-inventory.sh via bin/md2html.sh -->
|
||||
|
||||
<!-- START: this line starts content generated by: bin/output-index-inventory.sh -->
|
||||
|
||||
<h1 id="inventory-for-1998schweikh1"><a name="inventory"></a>Inventory
|
||||
for 1998/schweikh1</h1>
|
||||
<h1 id="inventory-for-1998schweikh1"><a name="inventory"></a>Inventory for 1998/schweikh1</h1>
|
||||
<p><a href="#top">Jump to top</a></p>
|
||||
<h2 id="primary-files">Primary files</h2>
|
||||
<ul>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/schweikh1.c">schweikh1.c</a>
|
||||
- entry source</li>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/Makefile">Makefile</a>
|
||||
- entry Makefile</li>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/schweikh1.alt.c">schweikh1.alt.c</a>
|
||||
- alternative source</li>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/schweikh1.orig.c">schweikh1.orig.c</a>
|
||||
- original source</li>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/charcount.pl">charcount.pl</a>
|
||||
- character counter</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/schweikh1.c">schweikh1.c</a> - entry source</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/Makefile">Makefile</a> - entry Makefile</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/schweikh1.alt.c">schweikh1.alt.c</a> - alternative source</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/schweikh1.orig.c">schweikh1.orig.c</a> - original source</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/charcount.pl">charcount.pl</a> - character counter</li>
|
||||
<li><a href="macos.html">macos.html</a> - work with macOS</li>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/info">info</a>
|
||||
- standards compliance</li>
|
||||
<li><a href="1998_schweikh1.tar.bz2">1998_schweikh1.tar.bz2</a> -
|
||||
download entry source</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/info">info</a> - standards compliance</li>
|
||||
<li><a href="1998_schweikh1.tar.bz2">1998_schweikh1.tar.bz2</a> - download entry source</li>
|
||||
</ul>
|
||||
<h2 id="secondary-files">Secondary files</h2>
|
||||
<ul>
|
||||
<li><a href="index.html">index.html</a> - entry home page</li>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/.entry.json">.entry.json</a>
|
||||
- description of entry in JSON</li>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/.gitignore">.gitignore</a>
|
||||
- list of files that should not be committed under git</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/.entry.json">.entry.json</a> - description of entry in JSON</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/.gitignore">.gitignore</a> - list of files that should not be committed under git</li>
|
||||
<li><a href=".path">.path</a> - directory path from top directory</li>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/README.md">README.md</a>
|
||||
- markdown source for index.html</li>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/macos.md">macos.md</a>
|
||||
- markdown source for marcos.html</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/README.md">README.md</a> - markdown source for index.html</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/1998/schweikh1/macos.md">macos.md</a> - markdown source for marcos.html</li>
|
||||
</ul>
|
||||
|
||||
<!-- END: next line ends content generated by: bin/output-index-inventory.sh -->
|
||||
|
||||
+37
-47
@@ -120,40 +120,34 @@
|
||||
<!-- END: this line ends content from: inc/before-content.default.html -->
|
||||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
|
||||
<p>This document describes how this was fixed to work with macOS as well
|
||||
as some of the magic in the entry. Even if you don’t have a Mac it might
|
||||
be worth your time reading especially as some of it details some
|
||||
important fixes and changes in the original entry as well.</p>
|
||||
<p>This document describes how this was fixed to work with macOS as well as some of
|
||||
the magic in the entry. Even if you don’t have a Mac it might be worth your time
|
||||
reading especially as some of it details some important fixes and changes in the
|
||||
original entry as well.</p>
|
||||
<h1 id="macos-changes">macOS changes</h1>
|
||||
<p>As an aside: if you have a Mac with the Apple chip, some of the
|
||||
header files will report an unsupported architecture and unsupported
|
||||
compiler (error, warning). This will not make the program abort,
|
||||
however, but even with an Intel CPU though, the original entry will not
|
||||
work in macOS as it stands because <code>/usr/include</code> is
|
||||
hard-coded in the code and macOS does not have it.</p>
|
||||
<p>Nevertheless, although some of it would not work in other systems
|
||||
where <code>/usr/include</code> exists, the <code>#define</code>s would
|
||||
still be found okay, at least until a file was not found (this
|
||||
limitation was removed in both versions in 2023). see</p>
|
||||
<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>
|
||||
<p>As an aside: if you have a Mac with the Apple chip, some of the header files
|
||||
will report an unsupported architecture and unsupported compiler (error,
|
||||
warning). This will not make the program abort, however, but even with an Intel
|
||||
CPU though, the original entry will not work in macOS as it stands because
|
||||
<code>/usr/include</code> is hard-coded in the code and macOS does not have it.</p>
|
||||
<p>Nevertheless, although some of it would not work in other systems where
|
||||
<code>/usr/include</code> exists, the <code>#define</code>s would still be found okay, at least until
|
||||
a file was not found (this limitation was removed in both versions in 2023). see</p>
|
||||
<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>
|
||||
<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>
|
||||
<p>Now as far as how this works if you look at the code of <a
|
||||
href="schweikh1.c">schweikh1.c</a>, on line 55 you’ll see a funny
|
||||
command (this goes for the alternate version as well but a bit
|
||||
different).</p>
|
||||
<p>Now the key is two magic numbers, one (two times) on a different line
|
||||
shortly below the 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>
|
||||
<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>
|
||||
<p>Now as far as how this works if you look at the code of
|
||||
<a href="schweikh1.c">schweikh1.c</a>, on line 55 you’ll see a funny command (this goes for
|
||||
the alternate version as well but a bit different).</p>
|
||||
<p>Now the key is two magic numbers, one (two times) on a different line shortly below the
|
||||
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>
|
||||
<p>which has been changed to be:</p>
|
||||
<pre><code>"0cc -ansi -E -dM -undef %s /usr/include/%s>r\0 ("</code></pre>
|
||||
@@ -161,21 +155,17 @@ command is:</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>
|
||||
<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 original)? Most of the output will be just
|
||||
<code>#define</code> by itself; in the cases where there was text after
|
||||
that it was macros that certainly were not defined. There might have
|
||||
been other errors as well.</p>
|
||||
<p>Changing this for macOS allows for opening the right files; the
|
||||
problem with macOS is <code>/usr/include</code> does not exist: instead
|
||||
it’s
|
||||
<code>/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include</code>
|
||||
which is why the different command line and the different numbers. The
|
||||
change of the numbers can be found in the alternate code and the
|
||||
explanation is the same.</p>
|
||||
<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
|
||||
original)? Most of the output will be just <code>#define</code> by itself; in the cases
|
||||
where there was text after that it was macros that certainly were not defined.
|
||||
There might have been other errors as well.</p>
|
||||
<p>Changing this for macOS allows for opening the right files; the problem with
|
||||
macOS is <code>/usr/include</code> does not exist: instead it’s
|
||||
<code>/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include</code> which is why
|
||||
the different command line and the different numbers. The change of the numbers
|
||||
can be found in the alternate code and the explanation is the same.</p>
|
||||
|
||||
<!-- END: this line ends content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||||
<!-- START: this line starts content from: inc/after-content.default.html -->
|
||||
|
||||
Reference in new issue
Block a user