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
+64
-64
@@ -1,27 +1,27 @@
|
||||
## To build:
|
||||
|
||||
```sh
|
||||
make
|
||||
make
|
||||
```
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
./prog [-tcksri] < file.c
|
||||
./prog [-tcksri] < file.c
|
||||
```
|
||||
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
./try.sh
|
||||
./try.sh
|
||||
```
|
||||
|
||||
If you get really stuck, try:
|
||||
|
||||
```sh
|
||||
man ./tac.1
|
||||
man ./tac.1
|
||||
```
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ There is one (known) remaining problem with detection:
|
||||
the following counts #include as two tokens, `#` and `include` (not as a reserved word):
|
||||
|
||||
```c
|
||||
#/*this will not be counted*/include/*correctly*/<stdio.h>
|
||||
#/*this will not be counted*/include/*correctly*/<stdio.h>
|
||||
```
|
||||
|
||||
Fixing this properly hampers backwards compatibility in counting. This requires
|
||||
@@ -129,15 +129,15 @@ counting words correctly absent `-k`.
|
||||
`tac` was run over all 366 previous IOCCC winning entries:
|
||||
|
||||
```sh
|
||||
find ~/src/obc -type f -name \*.c | wc
|
||||
find ~/src/obc -type f -name \*.c | wc
|
||||
```
|
||||
|
||||
The discrepancies found are documented and explained in the file
|
||||
[discrepancies.html](discrepancies.html).
|
||||
|
||||
```sh
|
||||
find ~/src/obc -type f -a -name "*.c" | xargs ./spotcheck.sh ./prog | ./spotdiff.sh |
|
||||
grep -v keep | diff -bw - discrep* | grep "[<>] cl "
|
||||
find ~/src/obc -type f -a -name "*.c" | xargs ./spotcheck.sh ./prog | ./spotdiff.sh |
|
||||
grep -v keep | diff -bw - discrep* | grep "[<>] cl "
|
||||
```
|
||||
|
||||
In summary, there are only 6 unique entries out of 366 that have any variation
|
||||
@@ -182,18 +182,18 @@ frequency, or counting the references to identifiers, constants, or breadth of u
|
||||
language:
|
||||
|
||||
```sh
|
||||
#!/usr/bin/env bash
|
||||
cat $* | ./prog -t | sort | uniq -c | sort -k1nr
|
||||
#!/usr/bin/env bash
|
||||
cat $* | ./prog -t | sort | uniq -c | sort -k1nr
|
||||
```
|
||||
|
||||
And here is a C keyword frequency counter:
|
||||
|
||||
```sh
|
||||
#!/usr/bin/env bash
|
||||
function iskeyword {
|
||||
awk 'BEGIN{f="c11";while(getline<f)k[$1]=0} {if($1 in k)k[$1]++}END{for(i in k)print k[i],i}'
|
||||
}
|
||||
cat $* | ./prog -t | iskeyword | sort -k1nr
|
||||
#!/usr/bin/env bash
|
||||
function iskeyword {
|
||||
awk 'BEGIN{f="c11";while(getline<f)k[$1]=0} {if($1 in k)k[$1]++}END{for(i in k)print k[i],i}'
|
||||
}
|
||||
cat $* | ./prog -t | iskeyword | sort -k1nr
|
||||
```
|
||||
|
||||
This script was used to "optimize" the reserved word order so the most frequent IOCCC
|
||||
@@ -203,13 +203,13 @@ An interesting aside: as might be expected, obfuscation has changed the frequenc
|
||||
keyword distribution over time. The top five for the decades:
|
||||
|
||||
```
|
||||
1980s 1990s 2000s 2010s
|
||||
----- ----- ----- -----
|
||||
94 if 532 char 375 if 254 int
|
||||
69 for 524 if 372 char 217 for
|
||||
59 while 417 int 332 int 198 if
|
||||
48 char 223 for 184 for 121 return
|
||||
43 int 223 void 165 return 104 char
|
||||
1980s 1990s 2000s 2010s
|
||||
----- ----- ----- -----
|
||||
94 if 532 char 375 if 254 int
|
||||
69 for 524 if 372 char 217 for
|
||||
59 while 417 int 332 int 198 if
|
||||
48 char 223 for 184 for 121 return
|
||||
43 int 223 void 165 return 104 char
|
||||
```
|
||||
|
||||
The keyword list is external to the program, and is easily changed, sorted, checked, verified.
|
||||
@@ -223,47 +223,47 @@ language_. It really is this easy with `tac`:
|
||||
|
||||
|
||||
```sh
|
||||
#!/usr/bin/env bash
|
||||
script='
|
||||
BEGIN {
|
||||
last=nl="\n";
|
||||
f="c11"; while(getline <f > 0) kw[$0]++; close(f);
|
||||
}
|
||||
#!/usr/bin/env bash
|
||||
script='
|
||||
BEGIN {
|
||||
last=nl="\n";
|
||||
f="c11"; while(getline <f > 0) kw[$0]++; close(f);
|
||||
}
|
||||
|
||||
function iskw(a) { return a in kw }
|
||||
function indent(a) { return sprintf("%*s", n*3, " ") }
|
||||
function newline() { if (!infor && last != nl) printf last=nl; }
|
||||
function show(a) {
|
||||
if (last==nl) printf "%s", indent()
|
||||
printf "%s%s", space(), a
|
||||
last=a
|
||||
}
|
||||
function space() {
|
||||
return iskw(last) ||
|
||||
(last ~ /[A-Za-z0-9_+-\/%^[&\]\)=:<>;]$/ && $0 !~ /[:;()\[\],]/) ? " " : ""
|
||||
}
|
||||
function iskw(a) { return a in kw }
|
||||
function indent(a) { return sprintf("%*s", n*3, " ") }
|
||||
function newline() { if (!infor && last != nl) printf last=nl; }
|
||||
function show(a) {
|
||||
if (last==nl) printf "%s", indent()
|
||||
printf "%s%s", space(), a
|
||||
last=a
|
||||
}
|
||||
function space() {
|
||||
return iskw(last) ||
|
||||
(last ~ /[A-Za-z0-9_+-\/%^[&\]\)=:<>;]$/ && $0 !~ /[:;()\[\],]/) ? " " : ""
|
||||
}
|
||||
|
||||
/^\(/ { ++paren }
|
||||
/^\)/ { --paren }
|
||||
/^\(/ { ++paren }
|
||||
/^\)/ { --paren }
|
||||
|
||||
/^for/ { newline(); infor=1 }
|
||||
infor && /^;/ { ++infor; show($0 " "); next }
|
||||
infor==1 && /^:/ { ++infor }
|
||||
infor>1 && paren==0 { infor=0 }
|
||||
/^for/ { newline(); infor=1 }
|
||||
infor && /^;/ { ++infor; show($0 " "); next }
|
||||
infor==1 && /^:/ { ++infor }
|
||||
infor>1 && paren==0 { infor=0 }
|
||||
|
||||
/^\?/ { tern++; n++; newline(); show($0 " "); next }
|
||||
tern && /^:/ { newline(); show($0); --tern; --n; next }
|
||||
/^\?/ { tern++; n++; newline(); show($0 " "); next }
|
||||
tern && /^:/ { newline(); show($0); --tern; --n; next }
|
||||
|
||||
/^#/ { newline(); show($0); newline(); next }
|
||||
/^;/ { show($0); newline(); next }
|
||||
/^{/ { show($0); ++n; newline(); next }
|
||||
/^}/ { n--; newline(); show($0); newline(); next }
|
||||
/^#/ { newline(); show($0); newline(); next }
|
||||
/^;/ { show($0); newline(); next }
|
||||
/^{/ { show($0); ++n; newline(); next }
|
||||
/^}/ { n--; newline(); show($0); newline(); next }
|
||||
|
||||
{ show($0) }
|
||||
'
|
||||
cat $* | sed 's/#include/##include/' | cpp -E -trigraphs |
|
||||
sed 's/^# .*$//' | sed 's/^#//' |
|
||||
./prog -t | awk "$script"
|
||||
{ show($0) }
|
||||
'
|
||||
cat $* | sed 's/#include/##include/' | cpp -E -trigraphs |
|
||||
sed 's/^# .*$//' | sed 's/^#//' |
|
||||
./prog -t | awk "$script"
|
||||
```
|
||||
|
||||
### On the question of obfuscation:
|
||||
@@ -343,7 +343,7 @@ which is neither complete (`#define`, `#ifndef`, `#undef` are missing
|
||||
nor correct (many more are added: `I`, `true`, `bool`, `compl`, ...):
|
||||
|
||||
```sh
|
||||
(sed -n '1p' c11; sed -n '2,$p' ioccc.kw.freq | sort) | comm -3 - c11
|
||||
(sed -n '1p' c11; sed -n '2,$p' ioccc.kw.freq | sort) | comm -3 - c11
|
||||
```
|
||||
|
||||
That is an obfuscated way to say "diff". But it also more clearly shows the, um, diffs.
|
||||
@@ -384,7 +384,7 @@ NB: This is *not* a portability concern, the one string holds only printable ASC
|
||||
Thus:
|
||||
|
||||
```sh
|
||||
cc -ansi -Wall -trigraphs -Wno-trigraphs -Wno-parentheses -Wno-empty-body -Wno-char-subscripts -Wno-pointer-sign -DU=O -DW=\"keywords\" -o prog prog.c
|
||||
cc -ansi -Wall -trigraphs -Wno-trigraphs -Wno-parentheses -Wno-empty-body -Wno-char-subscripts -Wno-pointer-sign -DU=O -DW=\"keywords\" -o prog prog.c
|
||||
```
|
||||
|
||||
### Coda:
|
||||
@@ -404,12 +404,12 @@ are not recognised when written as `-rs` in prose).
|
||||
Try:
|
||||
|
||||
```sh
|
||||
./manpage.sh tac
|
||||
./manpage.sh tac
|
||||
|
||||
./manpage.sh -h
|
||||
./manpage.sh -h | ./manpage.sh
|
||||
./manpage.sh -h | ./manpage.sh -R | less
|
||||
./manpage.sh -h | ./manpage.sh -P | lpr
|
||||
./manpage.sh -h
|
||||
./manpage.sh -h | ./manpage.sh
|
||||
./manpage.sh -h | ./manpage.sh -R | less
|
||||
./manpage.sh -h | ./manpage.sh -P | lpr
|
||||
```
|
||||
|
||||
NOTE: in 2023 the `tac.man` was updated to proper man format and renamed
|
||||
|
||||
@@ -124,65 +124,66 @@
|
||||
|
||||
<p>The values below are the field-by-field difference <code>iocccsize - ioc</code>.
|
||||
(<code>>0</code> means <code>iocccsize</code> counted more than <code>ioc</code>, <code><0</code> <code>ioc</code> counted more)</p>
|
||||
<p>cl: lines, cw: words, cc: chars, ci: rule2, ts: saved, kw: keywords, ks: kw_saved</p>
|
||||
<p>cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1986/pawka.c
|
||||
cl -45 cw -55 cc -617 ci -463 ts -85 kw -26 ks -69 src/obc/1990/theorem/theorem.c</p>
|
||||
<pre><code> cl: lines, cw: words, cc: chars, ci: rule2, ts: saved, kw: keywords, ks: kw_saved
|
||||
|
||||
cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1986/pawka.c
|
||||
cl -45 cw -55 cc -617 ci -463 ts -85 kw -26 ks -69 src/obc/1990/theorem/theorem.c</code></pre>
|
||||
<p><code>ioc</code> is correct; cl is correct even in compat (91) due to comments eating newlines
|
||||
<code>iocccsize</code> fails at <code>z;/*/</code>, eating everything until the following <code>/**/main(</code>
|
||||
looks to be due to mis-identification of a comment closing block as opening block</p>
|
||||
<p>cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1991/westley/westley.c
|
||||
cl 0 cw -3 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1992/gmariano/gmariano.c
|
||||
cl 0 cw -3 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1992/gmariano/gmariano.orig.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1994/shapiro/shapiro.c
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1996/gandalf/gandalf.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1996/schweikh1/schweikh1.c
|
||||
cl 0 cw -2 cc 0 ci -2 ts 0 kw 1 ks 2 src/obc/1998/df/df.c</p>
|
||||
<pre><code> cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1991/westley/westley.c
|
||||
cl 0 cw -3 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1992/gmariano/gmariano.c
|
||||
cl 0 cw -3 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1992/gmariano/gmariano.orig.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1994/shapiro/shapiro.c
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1996/gandalf/gandalf.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1996/schweikh1/schweikh1.c
|
||||
cl 0 cw -2 cc 0 ci -2 ts 0 kw 1 ks 2 src/obc/1998/df/df.c</code></pre>
|
||||
<p><code>iocccsize</code> counts as keyword <code>__##int##__</code>, and saving two characters but int
|
||||
is not a plausible keyword</p>
|
||||
<p>cl 0 cw -1 cc 3 ci 2 ts 1 kw 0 ks 0 src/obc/2001/herrmann1/herrmann1.c</p>
|
||||
<pre><code> cl 0 cw -1 cc 3 ci 2 ts 1 kw 0 ks 0 src/obc/2001/herrmann1/herrmann1.c</code></pre>
|
||||
<p>the text:</p>
|
||||
<pre><code> d M Y(O)/* state to */
|
||||
d</code></pre>
|
||||
<pre><code> d M Y(O)/* state to */
|
||||
d</code></pre>
|
||||
<p>counts as cw 3 in iocccsize, but this is clearly 4
|
||||
and the cc,ci,ts is due entirely to:</p>
|
||||
<pre><code> /*/*/*/*/*/ /*/*/
|
||||
E E /*/*/*/*/*/,/) F</code></pre>
|
||||
<pre><code> /*/*/*/*/*/ /*/*/
|
||||
E E /*/*/*/*/*/,/) F</code></pre>
|
||||
<p>which reduces to:</p>
|
||||
<pre><code> * E E * ,/) F</code></pre>
|
||||
<pre><code> * E E * ,/) F</code></pre>
|
||||
<p>but iocccsize counts this as <code>* E E *,/) F</code>, whereas ANSI C says comments are
|
||||
replaced with a single space equivalent (non-portable token-paste with comments)</p>
|
||||
<p>cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2004/arachnid/arachnid.c
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2004/arachnid/arachnid.orig.c
|
||||
cl 0 cw 0 cc 0 ci -4 ts 0 kw 2 ks 4 src/obc/2004/hoyle/hoyle.c
|
||||
cl 0 cw 0 cc 0 ci -4 ts 0 kw 2 ks 4 src/obc/2004/hoyle/hoyle.orig.c</p>
|
||||
<pre><code> cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2004/arachnid/arachnid.c
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2004/arachnid/arachnid.orig.c
|
||||
cl 0 cw 0 cc 0 ci -4 ts 0 kw 2 ks 4 src/obc/2004/hoyle/hoyle.c
|
||||
cl 0 cw 0 cc 0 ci -4 ts 0 kw 2 ks 4 src/obc/2004/hoyle/hoyle.orig.c</code></pre>
|
||||
<p><code>iocccsize</code> counts as two keywords the token-pasted <code>int##if</code>(e.g int1)
|
||||
thus the <code>kw 2</code>, and another bug in <code>iocccsize</code> counts <code>#if</code> as a keyword to 1
|
||||
thus saving 2 bytes on int, and 2 more on <code>#if</code>, when neither is a plausible keyword</p>
|
||||
<p>cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2004/omoikane/omoikane.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2005/chia/chia.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2005/mikeash/mikeash.c
|
||||
cl 0 cw 0 cc 0 ci 1 ts 1 kw 0 ks 0 src/obc/2005/toledo/toledo.c
|
||||
cl 0 cw 0 cc 0 ci 1 ts 1 kw 0 ks 0 src/obc/2005/toledo/toledo2.c
|
||||
cl 0 cw 0 cc 0 ci 1 ts 1 kw 0 ks 0 src/obc/2005/toledo/toledo3.c</p>
|
||||
<pre><code> cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2004/omoikane/omoikane.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2005/chia/chia.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2005/mikeash/mikeash.c
|
||||
cl 0 cw 0 cc 0 ci 1 ts 1 kw 0 ks 0 src/obc/2005/toledo/toledo.c
|
||||
cl 0 cw 0 cc 0 ci 1 ts 1 kw 0 ks 0 src/obc/2005/toledo/toledo2.c
|
||||
cl 0 cw 0 cc 0 ci 1 ts 1 kw 0 ks 0 src/obc/2005/toledo/toledo3.c</code></pre>
|
||||
<p>these three discrepancies are due to backslash-newline of <code>longjm\p</code> –
|
||||
at exactly the 521 byte line length boundary (which is arbitrary)
|
||||
<code>ioc</code> is correct, because it has no line length limit</p>
|
||||
<p>cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2011/akari/akari.c
|
||||
cl 0 cw -7 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2011/hamaji/hamaji.c
|
||||
cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2012/endoh1/endoh1.c
|
||||
cl 0 cw -3 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2012/endoh1/endoh1_color.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2012/endoh1/endoh1_deobfuscate.c
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2012/omoikane/nyaruko.c
|
||||
cl 0 cw 0 cc 0 ci -3 ts 0 kw 1 ks 3 src/obc/2013/cable2/cable2.c</p>
|
||||
<pre><code> cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2011/akari/akari.c
|
||||
cl 0 cw -7 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2011/hamaji/hamaji.c
|
||||
cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2012/endoh1/endoh1.c
|
||||
cl 0 cw -3 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2012/endoh1/endoh1_color.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2012/endoh1/endoh1_deobfuscate.c
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2012/omoikane/nyaruko.c
|
||||
cl 0 cw 0 cc 0 ci -3 ts 0 kw 1 ks 3 src/obc/2013/cable2/cable2.c</code></pre>
|
||||
<p>this is due to token-pasting of <code>_##char</code>; <code>iocccsize</code> counts this as a keyword
|
||||
but it is a pre-processor token-pasted string of the arg to <code>Y()</code> and char
|
||||
rendering this not a keyword, even in disguise</p>
|
||||
<p>cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2013/endoh4/endoh4.c
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2013/misaka/misaka.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2014/endoh2/prog.c
|
||||
cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2014/maffiodo1/prog.c
|
||||
cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2014/maffiodo1/prog.orig.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2014/sinon/prog.c</p>
|
||||
<pre><code> cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2013/endoh4/endoh4.c
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2013/misaka/misaka.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2014/endoh2/prog.c
|
||||
cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2014/maffiodo1/prog.c
|
||||
cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2014/maffiodo1/prog.orig.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2014/sinon/prog.c</code></pre>
|
||||
<!--
|
||||
|
||||
Copyright © 1984-2024 by Landon Curt Noll. All Rights Reserved.
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
The values below are the field-by-field difference `iocccsize - ioc`.
|
||||
(`>0` means `iocccsize` counted more than `ioc`, `<0` `ioc` counted more)
|
||||
|
||||
```
|
||||
cl: lines, cw: words, cc: chars, ci: rule2, ts: saved, kw: keywords, ks: kw_saved
|
||||
|
||||
cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1986/pawka.c
|
||||
cl -45 cw -55 cc -617 ci -463 ts -85 kw -26 ks -69 src/obc/1990/theorem/theorem.c
|
||||
```
|
||||
|
||||
`ioc` is correct; cl is correct even in compat (91) due to comments eating newlines
|
||||
`iocccsize` fails at `z;/*/`, eating everything until the following `/**/main(`
|
||||
looks to be due to mis-identification of a comment closing block as opening block
|
||||
|
||||
|
||||
```
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1991/westley/westley.c
|
||||
cl 0 cw -3 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1992/gmariano/gmariano.c
|
||||
cl 0 cw -3 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1992/gmariano/gmariano.orig.c
|
||||
@@ -18,52 +20,64 @@ looks to be due to mis-identification of a comment closing block as opening bloc
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1996/gandalf/gandalf.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/1996/schweikh1/schweikh1.c
|
||||
cl 0 cw -2 cc 0 ci -2 ts 0 kw 1 ks 2 src/obc/1998/df/df.c
|
||||
```
|
||||
|
||||
`iocccsize` counts as keyword `__##int##__`, and saving two characters but int
|
||||
is not a plausible keyword
|
||||
|
||||
```
|
||||
cl 0 cw -1 cc 3 ci 2 ts 1 kw 0 ks 0 src/obc/2001/herrmann1/herrmann1.c
|
||||
```
|
||||
|
||||
the text:
|
||||
|
||||
d M Y(O)/* state to */
|
||||
d
|
||||
```
|
||||
d M Y(O)/* state to */
|
||||
d
|
||||
```
|
||||
|
||||
counts as cw 3 in iocccsize, but this is clearly 4
|
||||
and the cc,ci,ts is due entirely to:
|
||||
|
||||
/*/*/*/*/*/ /*/*/
|
||||
E E /*/*/*/*/*/,/) F
|
||||
|
||||
```
|
||||
/*/*/*/*/*/ /*/*/
|
||||
E E /*/*/*/*/*/,/) F
|
||||
```
|
||||
|
||||
which reduces to:
|
||||
|
||||
* E E * ,/) F
|
||||
```
|
||||
* E E * ,/) F
|
||||
```
|
||||
|
||||
but iocccsize counts this as `* E E *,/) F`, whereas ANSI C says comments are
|
||||
replaced with a single space equivalent (non-portable token-paste with comments)
|
||||
|
||||
```
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2004/arachnid/arachnid.c
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2004/arachnid/arachnid.orig.c
|
||||
cl 0 cw 0 cc 0 ci -4 ts 0 kw 2 ks 4 src/obc/2004/hoyle/hoyle.c
|
||||
cl 0 cw 0 cc 0 ci -4 ts 0 kw 2 ks 4 src/obc/2004/hoyle/hoyle.orig.c
|
||||
```
|
||||
|
||||
`iocccsize` counts as two keywords the token-pasted `int##if `(e.g int1)
|
||||
thus the `kw 2`, and another bug in `iocccsize` counts `#if` as a keyword to 1
|
||||
thus saving 2 bytes on int, and 2 more on `#if`, when neither is a plausible keyword
|
||||
|
||||
```
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2004/omoikane/omoikane.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2005/chia/chia.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2005/mikeash/mikeash.c
|
||||
cl 0 cw 0 cc 0 ci 1 ts 1 kw 0 ks 0 src/obc/2005/toledo/toledo.c
|
||||
cl 0 cw 0 cc 0 ci 1 ts 1 kw 0 ks 0 src/obc/2005/toledo/toledo2.c
|
||||
cl 0 cw 0 cc 0 ci 1 ts 1 kw 0 ks 0 src/obc/2005/toledo/toledo3.c
|
||||
```
|
||||
|
||||
these three discrepancies are due to backslash-newline of `longjm\p` --
|
||||
at exactly the 521 byte line length boundary (which is arbitrary)
|
||||
`ioc` is correct, because it has no line length limit
|
||||
|
||||
|
||||
```
|
||||
cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2011/akari/akari.c
|
||||
cl 0 cw -7 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2011/hamaji/hamaji.c
|
||||
cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2012/endoh1/endoh1.c
|
||||
@@ -71,17 +85,20 @@ at exactly the 521 byte line length boundary (which is arbitrary)
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2012/endoh1/endoh1_deobfuscate.c
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2012/omoikane/nyaruko.c
|
||||
cl 0 cw 0 cc 0 ci -3 ts 0 kw 1 ks 3 src/obc/2013/cable2/cable2.c
|
||||
```
|
||||
|
||||
this is due to token-pasting of `_##char`; `iocccsize` counts this as a keyword
|
||||
but it is a pre-processor token-pasted string of the arg to `Y()` and char
|
||||
rendering this not a keyword, even in disguise
|
||||
|
||||
```
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2013/endoh4/endoh4.c
|
||||
cl 0 cw -2 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2013/misaka/misaka.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2014/endoh2/prog.c
|
||||
cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2014/maffiodo1/prog.c
|
||||
cl 0 cw -4 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2014/maffiodo1/prog.orig.c
|
||||
cl 0 cw -1 cc 0 ci 0 ts 0 kw 0 ks 0 src/obc/2014/sinon/prog.c
|
||||
```
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
+65
-66
@@ -132,8 +132,7 @@
|
||||
<h2 id="author"><a name="author"></a>Author:</h2>
|
||||
<ul>
|
||||
<li>Name: <a href="../../authors.html#Dave_Burton">Dave Burton</a><br>
|
||||
Location: <a href="../../location.html#US">US</a> - <em>United States of America</em> (<em>United States</em>)
|
||||
<br><br></li>
|
||||
Location: <a href="../../location.html#US">US</a> - <em>United States of America</em> (<em>United States</em>)</li>
|
||||
</ul>
|
||||
|
||||
<!-- END: next line ends content generated by: bin/output-index-author.sh -->
|
||||
@@ -142,13 +141,13 @@ Location: <a href="../../location.html#US">US</a> - <em>United States of America
|
||||
<!-- 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></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></span></code></pre></div>
|
||||
<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">./prog</span> <span class="pp">[-</span><span class="ss">tcksri</span><span class="pp">]</span> <span class="op"><</span> file.c</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">./prog</span> <span class="pp">[-</span><span class="ss">tcksri</span><span class="pp">]</span> <span class="op"><</span> file.c</span></code></pre></div>
|
||||
<h2 id="try">Try:</h2>
|
||||
<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="ex">./try.sh</span></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="ex">./try.sh</span></span></code></pre></div>
|
||||
<p>If you get really stuck, try:</p>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">man</span> ./tac.1</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">man</span> ./tac.1</span></code></pre></div>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
<p>They say size isn’t everything, and in the case of IOCCC
|
||||
<a href="../../2018/iocccsize.c">iocccsize.c</a> that is saying something!
|
||||
@@ -229,17 +228,17 @@ quote consumes everything until the next quote</li>
|
||||
<li>Comments between preprocessor hash and keyword are not replaced with whitespace;
|
||||
the following counts #include as two tokens, <code>#</code> and <code>include</code> (not as a reserved word):</li>
|
||||
</ul>
|
||||
<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">#</span><span class="er">/*this will not be counted*/include/*correctly*/<stdio.h></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">#</span><span class="er">/*this will not be counted*/include/*correctly*/<stdio.h></span></span></code></pre></div>
|
||||
<p>Fixing this properly hampers backwards compatibility in counting. This requires
|
||||
eliding comments during the translation phases (ISO 5.1.1.2, phase 3), and yet still
|
||||
counting words correctly absent <code>-k</code>.</p>
|
||||
<h3 id="backwards-compatibility">Backwards Compatibility:</h3>
|
||||
<p><code>tac</code> was run over all 366 previous IOCCC winning entries:</p>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">find</span> ~/src/obc <span class="at">-type</span> f <span class="at">-name</span> <span class="dt">\*</span>.c <span class="kw">|</span> <span class="fu">wc</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">find</span> ~/src/obc <span class="at">-type</span> f <span class="at">-name</span> <span class="dt">\*</span>.c <span class="kw">|</span> <span class="fu">wc</span></span></code></pre></div>
|
||||
<p>The discrepancies found are documented and explained in the file
|
||||
<a href="discrepancies.html">discrepancies.html</a>.</p>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">find</span> ~/src/obc <span class="at">-type</span> f <span class="at">-a</span> <span class="at">-name</span> <span class="st">"*.c"</span> <span class="kw">|</span> <span class="fu">xargs</span> ./spotcheck.sh ./prog <span class="kw">|</span> <span class="ex">./spotdiff.sh</span> <span class="kw">|</span></span>
|
||||
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">grep</span> <span class="at">-v</span> keep <span class="kw">|</span> <span class="fu">diff</span> <span class="at">-bw</span> <span class="at">-</span> discrep<span class="pp">*</span> <span class="kw">|</span> <span class="fu">grep</span> <span class="st">"[<>] cl "</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> <span class="fu">find</span> ~/src/obc <span class="at">-type</span> f <span class="at">-a</span> <span class="at">-name</span> <span class="st">"*.c"</span> <span class="kw">|</span> <span class="fu">xargs</span> ./spotcheck.sh ./prog <span class="kw">|</span> <span class="ex">./spotdiff.sh</span> <span class="kw">|</span></span>
|
||||
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">grep</span> <span class="at">-v</span> keep <span class="kw">|</span> <span class="fu">diff</span> <span class="at">-bw</span> <span class="at">-</span> discrep<span class="pp">*</span> <span class="kw">|</span> <span class="fu">grep</span> <span class="st">"[<>] cl "</span></span></code></pre></div>
|
||||
<p>In summary, there are only 6 unique entries out of 366 that have any variation
|
||||
in Rule 2 counts; in all cases, the differences are due to bugs within
|
||||
<code>iocccsize</code>, described in detail in the file
|
||||
@@ -274,25 +273,25 @@ This feature enables interesting analyses of C (and C++) code that’s hard to g
|
||||
<p>For instance, here is a simple token counter, useful in finding repeated long tokens, or operator
|
||||
frequency, or counting the references to identifiers, constants, or breadth of use of the
|
||||
language:</p>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/usr/bin/env bash</span></span>
|
||||
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> <span class="va">$*</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-t</span> <span class="kw">|</span> <span class="fu">sort</span> <span class="kw">|</span> <span class="fu">uniq</span> <span class="at">-c</span> <span class="kw">|</span> <span class="fu">sort</span> <span class="at">-k1nr</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="co">#!/usr/bin/env bash</span></span>
|
||||
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> <span class="va">$*</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-t</span> <span class="kw">|</span> <span class="fu">sort</span> <span class="kw">|</span> <span class="fu">uniq</span> <span class="at">-c</span> <span class="kw">|</span> <span class="fu">sort</span> <span class="at">-k1nr</span></span></code></pre></div>
|
||||
<p>And here is a C keyword frequency counter:</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/usr/bin/env bash</span></span>
|
||||
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span><span class="fu"> iskeyword</span> <span class="kw">{</span></span>
|
||||
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">awk</span> <span class="st">'BEGIN{f="c11";while(getline<f)k[$1]=0} {if($1 in k)k[$1]++}END{for(i in k)print k[i],i}'</span></span>
|
||||
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a><span class="kw">}</span></span>
|
||||
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> <span class="va">$*</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-t</span> <span class="kw">|</span> <span class="ex">iskeyword</span> <span class="kw">|</span> <span class="fu">sort</span> <span class="at">-k1nr</span></span></code></pre></div>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="co">#!/usr/bin/env bash</span></span>
|
||||
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">function</span><span class="fu"> iskeyword</span> <span class="kw">{</span></span>
|
||||
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">awk</span> <span class="st">'BEGIN{f="c11";while(getline<f)k[$1]=0} {if($1 in k)k[$1]++}END{for(i in k)print k[i],i}'</span></span>
|
||||
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a> <span class="kw">}</span></span>
|
||||
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> <span class="va">$*</span> <span class="kw">|</span> <span class="ex">./prog</span> <span class="at">-t</span> <span class="kw">|</span> <span class="ex">iskeyword</span> <span class="kw">|</span> <span class="fu">sort</span> <span class="at">-k1nr</span></span></code></pre></div>
|
||||
<p>This script was used to “optimize” the reserved word order so the most frequent IOCCC
|
||||
winning entry keywords are checked first.</p>
|
||||
<p>An interesting aside: as might be expected, obfuscation has changed the frequency of
|
||||
keyword distribution over time. The top five for the decades:</p>
|
||||
<pre><code>1980s 1990s 2000s 2010s
|
||||
----- ----- ----- -----
|
||||
94 if 532 char 375 if 254 int
|
||||
69 for 524 if 372 char 217 for
|
||||
59 while 417 int 332 int 198 if
|
||||
48 char 223 for 184 for 121 return
|
||||
43 int 223 void 165 return 104 char</code></pre>
|
||||
<pre><code> 1980s 1990s 2000s 2010s
|
||||
----- ----- ----- -----
|
||||
94 if 532 char 375 if 254 int
|
||||
69 for 524 if 372 char 217 for
|
||||
59 while 417 int 332 int 198 if
|
||||
48 char 223 for 184 for 121 return
|
||||
43 int 223 void 165 return 104 char</code></pre>
|
||||
<p>The keyword list is external to the program, and is easily changed, sorted, checked, verified.
|
||||
This allows such additional programs in concert with the tool’s primary operation.</p>
|
||||
<p>A poor-man’s de-obfuscator can be based upon the output of <code>tac -t</code> and a
|
||||
@@ -300,47 +299,47 @@ handful of simple rules (and another use of the external keyword file). A more
|
||||
refined version of this is included in the file <a href="unob.sh">unob.sh</a>, but the
|
||||
simple code below is a serviceable obfuscated C de-obfuscator in a <em>scripting
|
||||
language</em>. It really is this easy with <code>tac</code>:</p>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/usr/bin/env bash</span></span>
|
||||
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="va">script</span><span class="op">=</span><span class="st">'</span></span>
|
||||
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="st">BEGIN {</span></span>
|
||||
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a><span class="st"> last=nl="\n";</span></span>
|
||||
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a><span class="st"> f="c11"; while(getline <f > 0) kw[$0]++; close(f);</span></span>
|
||||
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a><span class="st">}</span></span>
|
||||
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="co">#!/usr/bin/env bash</span></span>
|
||||
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="va">script</span><span class="op">=</span><span class="st">'</span></span>
|
||||
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="st"> BEGIN {</span></span>
|
||||
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a><span class="st"> last=nl="\n";</span></span>
|
||||
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a><span class="st"> f="c11"; while(getline <f > 0) kw[$0]++; close(f);</span></span>
|
||||
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a><span class="st"> }</span></span>
|
||||
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a><span class="st">function iskw(a) { return a in kw }</span></span>
|
||||
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a><span class="st">function indent(a) { return sprintf("%*s", n*3, " ") }</span></span>
|
||||
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a><span class="st">function newline() { if (!infor && last != nl) printf last=nl; }</span></span>
|
||||
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a><span class="st">function show(a) {</span></span>
|
||||
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a><span class="st"> if (last==nl) printf "%s", indent()</span></span>
|
||||
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a><span class="st"> printf "%s%s", space(), a</span></span>
|
||||
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a><span class="st"> last=a</span></span>
|
||||
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a><span class="st">}</span></span>
|
||||
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a><span class="st">function space() {</span></span>
|
||||
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a><span class="st"> return iskw(last) ||</span></span>
|
||||
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true" tabindex="-1"></a><span class="st"> (last ~ /[A-Za-z0-9_+-\/%^[&\]\)=:<>;]$/ && $0 !~ /[:;()\[\],]/) ? " " : ""</span></span>
|
||||
<span id="cb11-19"><a href="#cb11-19" aria-hidden="true" tabindex="-1"></a><span class="st">}</span></span>
|
||||
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a><span class="st"> function iskw(a) { return a in kw }</span></span>
|
||||
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a><span class="st"> function indent(a) { return sprintf("%*s", n*3, " ") }</span></span>
|
||||
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a><span class="st"> function newline() { if (!infor && last != nl) printf last=nl; }</span></span>
|
||||
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a><span class="st"> function show(a) {</span></span>
|
||||
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a><span class="st"> if (last==nl) printf "%s", indent()</span></span>
|
||||
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a><span class="st"> printf "%s%s", space(), a</span></span>
|
||||
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a><span class="st"> last=a</span></span>
|
||||
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a><span class="st"> }</span></span>
|
||||
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a><span class="st"> function space() {</span></span>
|
||||
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a><span class="st"> return iskw(last) ||</span></span>
|
||||
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true" tabindex="-1"></a><span class="st"> (last ~ /[A-Za-z0-9_+-\/%^[&\]\)=:<>;]$/ && $0 !~ /[:;()\[\],]/) ? " " : ""</span></span>
|
||||
<span id="cb11-19"><a href="#cb11-19" aria-hidden="true" tabindex="-1"></a><span class="st"> }</span></span>
|
||||
<span id="cb11-20"><a href="#cb11-20" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb11-21"><a href="#cb11-21" aria-hidden="true" tabindex="-1"></a><span class="st">/^\(/ { ++paren }</span></span>
|
||||
<span id="cb11-22"><a href="#cb11-22" aria-hidden="true" tabindex="-1"></a><span class="st">/^\)/ { --paren }</span></span>
|
||||
<span id="cb11-21"><a href="#cb11-21" aria-hidden="true" tabindex="-1"></a><span class="st"> /^\(/ { ++paren }</span></span>
|
||||
<span id="cb11-22"><a href="#cb11-22" aria-hidden="true" tabindex="-1"></a><span class="st"> /^\)/ { --paren }</span></span>
|
||||
<span id="cb11-23"><a href="#cb11-23" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb11-24"><a href="#cb11-24" aria-hidden="true" tabindex="-1"></a><span class="st">/^for/ { newline(); infor=1 }</span></span>
|
||||
<span id="cb11-25"><a href="#cb11-25" aria-hidden="true" tabindex="-1"></a><span class="st">infor && /^;/ { ++infor; show($0 " "); next }</span></span>
|
||||
<span id="cb11-26"><a href="#cb11-26" aria-hidden="true" tabindex="-1"></a><span class="st">infor==1 && /^:/ { ++infor }</span></span>
|
||||
<span id="cb11-27"><a href="#cb11-27" aria-hidden="true" tabindex="-1"></a><span class="st">infor>1 && paren==0 { infor=0 }</span></span>
|
||||
<span id="cb11-24"><a href="#cb11-24" aria-hidden="true" tabindex="-1"></a><span class="st"> /^for/ { newline(); infor=1 }</span></span>
|
||||
<span id="cb11-25"><a href="#cb11-25" aria-hidden="true" tabindex="-1"></a><span class="st"> infor && /^;/ { ++infor; show($0 " "); next }</span></span>
|
||||
<span id="cb11-26"><a href="#cb11-26" aria-hidden="true" tabindex="-1"></a><span class="st"> infor==1 && /^:/ { ++infor }</span></span>
|
||||
<span id="cb11-27"><a href="#cb11-27" aria-hidden="true" tabindex="-1"></a><span class="st"> infor>1 && paren==0 { infor=0 }</span></span>
|
||||
<span id="cb11-28"><a href="#cb11-28" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb11-29"><a href="#cb11-29" aria-hidden="true" tabindex="-1"></a><span class="st">/^\?/ { tern++; n++; newline(); show($0 " "); next }</span></span>
|
||||
<span id="cb11-30"><a href="#cb11-30" aria-hidden="true" tabindex="-1"></a><span class="st">tern && /^:/ { newline(); show($0); --tern; --n; next }</span></span>
|
||||
<span id="cb11-29"><a href="#cb11-29" aria-hidden="true" tabindex="-1"></a><span class="st"> /^\?/ { tern++; n++; newline(); show($0 " "); next }</span></span>
|
||||
<span id="cb11-30"><a href="#cb11-30" aria-hidden="true" tabindex="-1"></a><span class="st"> tern && /^:/ { newline(); show($0); --tern; --n; next }</span></span>
|
||||
<span id="cb11-31"><a href="#cb11-31" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb11-32"><a href="#cb11-32" aria-hidden="true" tabindex="-1"></a><span class="st">/^#/ { newline(); show($0); newline(); next }</span></span>
|
||||
<span id="cb11-33"><a href="#cb11-33" aria-hidden="true" tabindex="-1"></a><span class="st">/^;/ { show($0); newline(); next }</span></span>
|
||||
<span id="cb11-34"><a href="#cb11-34" aria-hidden="true" tabindex="-1"></a><span class="st">/^{/ { show($0); ++n; newline(); next }</span></span>
|
||||
<span id="cb11-35"><a href="#cb11-35" aria-hidden="true" tabindex="-1"></a><span class="st">/^}/ { n--; newline(); show($0); newline(); next }</span></span>
|
||||
<span id="cb11-32"><a href="#cb11-32" aria-hidden="true" tabindex="-1"></a><span class="st"> /^#/ { newline(); show($0); newline(); next }</span></span>
|
||||
<span id="cb11-33"><a href="#cb11-33" aria-hidden="true" tabindex="-1"></a><span class="st"> /^;/ { show($0); newline(); next }</span></span>
|
||||
<span id="cb11-34"><a href="#cb11-34" aria-hidden="true" tabindex="-1"></a><span class="st"> /^{/ { show($0); ++n; newline(); next }</span></span>
|
||||
<span id="cb11-35"><a href="#cb11-35" aria-hidden="true" tabindex="-1"></a><span class="st"> /^}/ { n--; newline(); show($0); newline(); next }</span></span>
|
||||
<span id="cb11-36"><a href="#cb11-36" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb11-37"><a href="#cb11-37" aria-hidden="true" tabindex="-1"></a><span class="st">{ show($0) }</span></span>
|
||||
<span id="cb11-38"><a href="#cb11-38" aria-hidden="true" tabindex="-1"></a><span class="st">'</span></span>
|
||||
<span id="cb11-39"><a href="#cb11-39" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> <span class="va">$*</span> <span class="kw">|</span> <span class="fu">sed</span> <span class="st">'s/#include/##include/'</span> <span class="kw">|</span> <span class="fu">cpp</span> <span class="at">-E</span> <span class="at">-trigraphs</span> <span class="kw">|</span></span>
|
||||
<span id="cb11-40"><a href="#cb11-40" aria-hidden="true" tabindex="-1"></a><span class="fu">sed</span> <span class="st">'s/^# .*$//'</span> <span class="kw">|</span> <span class="fu">sed</span> <span class="st">'s/^#//'</span> <span class="kw">|</span></span>
|
||||
<span id="cb11-41"><a href="#cb11-41" aria-hidden="true" tabindex="-1"></a><span class="ex">./prog</span> <span class="at">-t</span> <span class="kw">|</span> <span class="fu">awk</span> <span class="st">"</span><span class="va">$script</span><span class="st">"</span></span></code></pre></div>
|
||||
<span id="cb11-37"><a href="#cb11-37" aria-hidden="true" tabindex="-1"></a><span class="st"> { show($0) }</span></span>
|
||||
<span id="cb11-38"><a href="#cb11-38" aria-hidden="true" tabindex="-1"></a><span class="st"> '</span></span>
|
||||
<span id="cb11-39"><a href="#cb11-39" aria-hidden="true" tabindex="-1"></a> <span class="fu">cat</span> <span class="va">$*</span> <span class="kw">|</span> <span class="fu">sed</span> <span class="st">'s/#include/##include/'</span> <span class="kw">|</span> <span class="fu">cpp</span> <span class="at">-E</span> <span class="at">-trigraphs</span> <span class="kw">|</span></span>
|
||||
<span id="cb11-40"><a href="#cb11-40" aria-hidden="true" tabindex="-1"></a> <span class="fu">sed</span> <span class="st">'s/^# .*$//'</span> <span class="kw">|</span> <span class="fu">sed</span> <span class="st">'s/^#//'</span> <span class="kw">|</span></span>
|
||||
<span id="cb11-41"><a href="#cb11-41" aria-hidden="true" tabindex="-1"></a> <span class="ex">./prog</span> <span class="at">-t</span> <span class="kw">|</span> <span class="fu">awk</span> <span class="st">"</span><span class="va">$script</span><span class="st">"</span></span></code></pre></div>
|
||||
<h3 id="on-the-question-of-obfuscation">On the question of obfuscation:</h3>
|
||||
<ul>
|
||||
<li><p>I assume you noticed the <a href="https://www.youtube.com/watch?v=fUspLVStPbk&start=53" title="Meaning of Life">braces</a>?</p>
|
||||
@@ -402,7 +401,7 @@ the IOJCC trash can.</p>
|
||||
which is neither complete (<code>#define</code>, <code>#ifndef</code>, <code>#undef</code> are missing
|
||||
– yes, Virginia knows about <code>#define</code> omitted on purpose),
|
||||
nor correct (many more are added: <code>I</code>, <code>true</code>, <code>bool</code>, <code>compl</code>, …):</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="kw">(</span><span class="fu">sed</span> <span class="at">-n</span> <span class="st">'1p'</span> c11<span class="kw">;</span> <span class="fu">sed</span> <span class="at">-n</span> <span class="st">'2,$p'</span> ioccc.kw.freq <span class="kw">|</span> <span class="fu">sort</span><span class="kw">)</span> <span class="kw">|</span> <span class="fu">comm</span> <span class="at">-3</span> <span class="at">-</span> c11</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="kw">(</span><span class="fu">sed</span> <span class="at">-n</span> <span class="st">'1p'</span> c11<span class="kw">;</span> <span class="fu">sed</span> <span class="at">-n</span> <span class="st">'2,$p'</span> ioccc.kw.freq <span class="kw">|</span> <span class="fu">sort</span><span class="kw">)</span> <span class="kw">|</span> <span class="fu">comm</span> <span class="at">-3</span> <span class="at">-</span> c11</span></code></pre></div>
|
||||
<p>That is an obfuscated way to say “diff”. But it also more clearly shows the, um, diffs.</p>
|
||||
<p>The usage string is similarly externalized, providing a better usability string than
|
||||
the limits would otherwise allow. If this is considered bending the rules too far,
|
||||
@@ -430,7 +429,7 @@ for obfuscation. Thus <code>-trigraphs -Wno-trigraphs</code> (which is also humo
|
||||
<p>The code uses <code>unsigned char</code>s, but C strings are <code>signed</code>. Thus <code>-Wno-pointer-sign</code>.
|
||||
NB: This is <em>not</em> a portability concern, the one string holds only printable ASCII characters.</p>
|
||||
<p>Thus:</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">cc</span> <span class="at">-ansi</span> <span class="at">-Wall</span> <span class="at">-trigraphs</span> <span class="at">-Wno-trigraphs</span> <span class="at">-Wno-parentheses</span> <span class="at">-Wno-empty-body</span> <span class="at">-Wno-char-subscripts</span> <span class="at">-Wno-pointer-sign</span> <span class="at">-DU</span><span class="op">=</span>O <span class="at">-DW</span><span class="op">=</span><span class="dt">\"</span>keywords<span class="dt">\"</span> <span class="at">-o</span> prog prog.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">cc</span> <span class="at">-ansi</span> <span class="at">-Wall</span> <span class="at">-trigraphs</span> <span class="at">-Wno-trigraphs</span> <span class="at">-Wno-parentheses</span> <span class="at">-Wno-empty-body</span> <span class="at">-Wno-char-subscripts</span> <span class="at">-Wno-pointer-sign</span> <span class="at">-DU</span><span class="op">=</span>O <span class="at">-DW</span><span class="op">=</span><span class="dt">\"</span>keywords<span class="dt">\"</span> <span class="at">-o</span> prog prog.c</span></code></pre></div>
|
||||
<h3 id="coda">Coda:</h3>
|
||||
<p><a href="../../authors.html#Cody_Boone_Ferguson">Cody Boone Ferguson</a> was relentless in his pursuit of bugs.
|
||||
Thanks to his reports, the version of <a href="unob.sh">unob.sh</a> is stronger,
|
||||
@@ -443,12 +442,12 @@ works well on most inputs, but tends to need some raw nroff for more fancy
|
||||
constructions, such as combined arguments (e.g. the <code>-r</code> and <code>-s</code> arguments to tac
|
||||
are not recognised when written as <code>-rs</code> in prose).</p>
|
||||
<p>Try:</p>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./manpage.sh</span> tac</span>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">./manpage.sh</span> tac</span>
|
||||
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a><span class="ex">./manpage.sh</span> <span class="at">-h</span></span>
|
||||
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a><span class="ex">./manpage.sh</span> <span class="at">-h</span> <span class="kw">|</span> <span class="ex">./manpage.sh</span></span>
|
||||
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a><span class="ex">./manpage.sh</span> <span class="at">-h</span> <span class="kw">|</span> <span class="ex">./manpage.sh</span> <span class="at">-R</span> <span class="kw">|</span> <span class="fu">less</span></span>
|
||||
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a><span class="ex">./manpage.sh</span> <span class="at">-h</span> <span class="kw">|</span> <span class="ex">./manpage.sh</span> <span class="at">-P</span> <span class="kw">|</span> <span class="fu">lpr</span></span></code></pre></div>
|
||||
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">./manpage.sh</span> <span class="at">-h</span></span>
|
||||
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">./manpage.sh</span> <span class="at">-h</span> <span class="kw">|</span> <span class="ex">./manpage.sh</span></span>
|
||||
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a> <span class="ex">./manpage.sh</span> <span class="at">-h</span> <span class="kw">|</span> <span class="ex">./manpage.sh</span> <span class="at">-R</span> <span class="kw">|</span> <span class="fu">less</span></span>
|
||||
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">./manpage.sh</span> <span class="at">-h</span> <span class="kw">|</span> <span class="ex">./manpage.sh</span> <span class="at">-P</span> <span class="kw">|</span> <span class="fu">lpr</span></span></code></pre></div>
|
||||
<p>NOTE: in 2023 the <code>tac.man</code> was updated to proper man format and renamed
|
||||
<a href="tac.1">tac.1</a>.</p>
|
||||
<!--
|
||||
|
||||
Reference in new issue
Block a user