fix Makefile and README.md for 2018/burton2
Rename `README.txt` to `READ_ME.txt`. Help shell scripts to find the shell and make them executable.
This commit is contained in:
1 parent
d30627e1e0
commit
8ce9755c63
8 files changed
+269
-199
No files matched your search
+161
-107
@@ -1,40 +1,52 @@
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# 2018 makefile
|
||||
# IOCCC 2018 winning entry - burton2
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# This work by Landon Curt Noll, Simon Cooper, and Leonid A. Broukhis
|
||||
# is licensed under:
|
||||
# Regarding individual entries:
|
||||
#
|
||||
# IOCCC winning entry code may not work on your system. Even with standards,
|
||||
# conditions and build environments change, especially when it comes to more
|
||||
# extreme code such you might find in an IOCCC winner. Moreover, what was
|
||||
# allowed and liked in one IOCCC contest may no longer be liked/allowed in
|
||||
# later IOCCC years.
|
||||
#
|
||||
# Corrections on winning author and fixing typos in remarks are VERY WELCOME.
|
||||
#
|
||||
# GitHub pull requests are welcome:
|
||||
#
|
||||
# If you have a patch that might make running an entry work in modern Unix-like
|
||||
# environments, please create a GitHub pull request for the IOCCC judges to
|
||||
# consider.
|
||||
#
|
||||
# Suggestions and corrections regarding Makefiles, winning author information,
|
||||
# fixing typos in remarks, and code patches are welcome via opening a GitHub
|
||||
# issue or better yet, by creating a GitHub pull request for the IOCCC judges
|
||||
# to consider. To form a GitHub issue or GitHub pull, please visit:
|
||||
#
|
||||
# https://github.com/ioccc-src/winner
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# This work by Landon Curt Noll and Leonid A. Broukhis is licensed under:
|
||||
#
|
||||
# Creative Commons Attribution-ShareAlike 3.0 Unported License.
|
||||
#
|
||||
# See: http://creativecommons.org/licenses/by-sa/3.0/
|
||||
|
||||
|
||||
################
|
||||
# tool locations
|
||||
################
|
||||
#############################
|
||||
# shell used by this Makefile
|
||||
#############################
|
||||
#
|
||||
SHELL= bash
|
||||
CP= cp
|
||||
CPP= cpp
|
||||
GUNZIP= gunzip
|
||||
BUNZIP2= bunzip2
|
||||
GZIP_PROG= gzip
|
||||
BZIP2= bzip2
|
||||
CURL= curl
|
||||
DD= dd
|
||||
LD= ld
|
||||
MAKE= make
|
||||
RM= rm
|
||||
SED= sed
|
||||
TAR= tar
|
||||
TRUE= true
|
||||
MKDIR= mkdir
|
||||
MV= mv
|
||||
TR= tr
|
||||
GREP= grep
|
||||
SORT= sort
|
||||
UNIQ= uniq
|
||||
|
||||
#######################
|
||||
# common tool locations
|
||||
#######################
|
||||
#
|
||||
include ../../var.mk
|
||||
|
||||
# Set X11_LIBDIR to the directory where the X11 library resides
|
||||
#
|
||||
@@ -48,29 +60,27 @@ X11_LIBDIR= /opt/X11/lib
|
||||
#X11_INCDIR= /usr/X11/include
|
||||
X11_INCDIR= /opt/X11/include
|
||||
|
||||
# Compiler warnings
|
||||
# Common C compiler warnings to silence
|
||||
#
|
||||
#CWARN=
|
||||
#CWARN= -Wall
|
||||
#CWARN= -Wall -Wextra
|
||||
#CSILENCE=
|
||||
CSILENCE= -Wno-bitwise-op-parentheses -Wno-char-subscripts -Wno-empty-body \
|
||||
-Wno-logical-op-parentheses -Wno-parentheses -Wno-pointer-sign \
|
||||
-Wno-sign-compare -Wno-trigraphs
|
||||
|
||||
# Common C compiler warning flags
|
||||
#
|
||||
#CWARN= ${CSILENCE}
|
||||
#CWARN= -Wall ${CSILENCE}
|
||||
CWARN= -Wall -Wextra ${CSILENCE}
|
||||
#CWARN= -Wall -Wextra -pedantic ${CSILENCE}
|
||||
#CWARN= -Wall -Wextra -Weverything
|
||||
#CWARN= -Wall -Wextra -Weverything -pedantic
|
||||
#CWARN= -Wall -Wextra -Weverything -pedantic ${CSILENCE}
|
||||
|
||||
# Silence warnings that ${CWARN} would normally complain about
|
||||
#
|
||||
CSILENCE= -Wno-empty-body -Wno-parentheses -Wno-pointer-sign -Wno-char-subscripts -Wno-trigraphs -Wno-sign-compare
|
||||
#CSILENCE= -Wno-implicit-int
|
||||
|
||||
# compiler standard
|
||||
# Compiler standard
|
||||
#
|
||||
#CSTD=
|
||||
#CSTD= -ansi
|
||||
CSTD= -std=c11
|
||||
CSTD= -std=gnu17
|
||||
|
||||
# compiler bit architecture
|
||||
# Compiler bit architecture
|
||||
#
|
||||
# Some entries require 32-bitness:
|
||||
# ARCH= -m32
|
||||
@@ -82,20 +92,21 @@ CSTD= -std=c11
|
||||
#
|
||||
ARCH=
|
||||
|
||||
# defines that are needed to compile
|
||||
# Defines that are needed to compile
|
||||
#
|
||||
CDEFINE= -trigraphs -DW=\"keywords\" -DU=$(USAGE)
|
||||
#CDEFINE= -DIOCCC=25
|
||||
#CDEFINE=
|
||||
CDEFINE= -DW=\"keywords\" -DU=${USAGE}
|
||||
|
||||
# include files that are needed to compile
|
||||
# Include files that are needed to compile
|
||||
#
|
||||
CINCLUDE=
|
||||
#CINCLUDE= -include stdlib.h
|
||||
#CINCLUDE= -include stdio.h
|
||||
#CINCLUDE= -include stdlib.h -include stdio.h
|
||||
#CINCLUDE= -I ${X11_INCDIR}
|
||||
#CINCLUDE= -I ${X11_INCDIR} -I ${X11_INCDIR}/X11
|
||||
#CINCLUDE= `${SDL2_CONFIG} --cflags`
|
||||
|
||||
# optimization
|
||||
# Optimization
|
||||
#
|
||||
# Most compiles will safely use -O2. Some can use only -O1 or -O.
|
||||
# A few compilers have broken optimizers or this entry make break
|
||||
@@ -108,37 +119,62 @@ CINCLUDE=
|
||||
#OPT= -O2
|
||||
OPT= -O3
|
||||
|
||||
# default flags for ANSI C compilation
|
||||
# Default flags for ANSI C compilation
|
||||
#
|
||||
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}
|
||||
|
||||
# Libraries needed to build
|
||||
#
|
||||
LIBS=
|
||||
#LIBS= -L ${X11_LIBDIR}
|
||||
#LIBS= -lm
|
||||
#LIBS= -L ${X11_LIBDIR} -lX11
|
||||
#LIBS= `${SDL2_CONFIG} --libs`
|
||||
|
||||
# ANSI compiler
|
||||
#
|
||||
# Set CC to the name of your ANSI compiler.
|
||||
#
|
||||
# Some entries seem to need gcc. If you have gcc, set
|
||||
# both CC and MAY_NEED_GCC to gcc.
|
||||
#
|
||||
# If you do not have gcc, set CC to the name of your ANSI compiler, and
|
||||
# set MAY_NEED_GCC to either ${CC} (and hope for the best) or to just :
|
||||
# to disable such programs.
|
||||
# C compiler to use
|
||||
#
|
||||
CC= cc
|
||||
#CC=clang
|
||||
MAY_NEED_GCC= gcc
|
||||
#CC=gcc
|
||||
|
||||
# Compiler add-ons or replacements for clang only
|
||||
#
|
||||
ifeq ($(CC),clang)
|
||||
#
|
||||
CSILENCE+= -Wno-cast-align -Wno-comma -Wno-extra-semi -Wno-implicit-int-conversion \
|
||||
-Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-pedantic \
|
||||
-Wno-poison-system-directories -Wno-shadow -Wno-shorten-64-to-32 \
|
||||
-Wno-sign-conversion -Wno-strict-prototypes
|
||||
#
|
||||
CWARN+= -Weverything
|
||||
#
|
||||
endif
|
||||
|
||||
# Specific add-ons or replacements for gcc only
|
||||
#
|
||||
ifeq ($(CC),gcc)
|
||||
#
|
||||
#CSILENCE+=
|
||||
#
|
||||
#CWARN+=
|
||||
#
|
||||
endif
|
||||
|
||||
|
||||
##############################
|
||||
# Special flags for this entry
|
||||
##############################
|
||||
#
|
||||
OBJ= prog.o
|
||||
DATA= keywords
|
||||
ENTRY= burton2
|
||||
PROG= prog
|
||||
#
|
||||
OBJ= ${PROG}.o
|
||||
CSRC= ${PROG}.o
|
||||
DATA= READ_ME.txt manpage java8 kandr kandr2 v7unix
|
||||
TARGET= ${PROG}
|
||||
#
|
||||
ALT_OBJ=
|
||||
ALT_TARGET=
|
||||
|
||||
EXTRA_DATA= ansi c++11 c++14 c++98 c11 c99 discrepancies \
|
||||
test01.c test02.c test03.c test04.c test05.c test06.c test07.c \
|
||||
test08.c test09.c test10.c test11.c test12.c test13.c test14.c \
|
||||
@@ -146,34 +182,39 @@ EXTRA_DATA= ansi c++11 c++14 c++98 c11 c99 discrepancies \
|
||||
iocccbug06.c results results.k src.doc.rot13 patch tac.man author-README.txt \
|
||||
ioc_without_quote
|
||||
UTILITIES= unob.sh tokenfix spotcheck spotdiff freqcount
|
||||
TARGET= prog
|
||||
#
|
||||
ALT_OBJ=
|
||||
ALT_TARGET=
|
||||
##
|
||||
USAGE="\"prog [-tcksri] < file.c\ntokenize and count stdin\n\t-t\ttokens only\n\t-c\tcompatible counts\n\t-k\tkeep comments\n\t-s\tsuppress output\n\t-r\treserved words count as 1\n\t-i\tioccc count only\n\""
|
||||
|
||||
# this tool requires -trigraphs
|
||||
#
|
||||
CFLAGS+= -trigraphs
|
||||
|
||||
|
||||
#################
|
||||
# build the entry
|
||||
#################
|
||||
#
|
||||
all: ${TARGET} ${DATA} ${UTILITIES}
|
||||
all: data ${TARGET}
|
||||
@${TRUE}
|
||||
|
||||
prog: prog.c keywords
|
||||
.PHONY: all alt data everything clean clobber install \
|
||||
love haste waste maker easter_egg sandwich \
|
||||
supernova deep_magic magic charon pluto
|
||||
|
||||
${PROG}: ${PROG}.c keywords
|
||||
${CC} ${CFLAGS} $< -o $@ ${LIBS}
|
||||
|
||||
tac: tac.c
|
||||
${CC} ${CFLAGS} $< -o $@ ${LIBS}
|
||||
|
||||
|
||||
# alternative executable
|
||||
#
|
||||
alt: ${ALT_TARGET}
|
||||
alt: data ${ALT_TARGET}
|
||||
@${TRUE}
|
||||
|
||||
# data files
|
||||
#
|
||||
data: ${DATA}
|
||||
data: ${DATA} ${EXTRA_DATA}
|
||||
@${TRUE}
|
||||
|
||||
# keywords: c11
|
||||
@@ -191,14 +232,21 @@ test: prog tac runtest fixed_iocccsize ${EXTRA_DATA}
|
||||
./fixed_iocccsize -rs < prog.c
|
||||
./tac -rs prog.c
|
||||
|
||||
# both all and alt
|
||||
#
|
||||
everything: all alt
|
||||
|
||||
|
||||
###############
|
||||
# utility rules
|
||||
###############
|
||||
#
|
||||
everything: all alt
|
||||
|
||||
clean:
|
||||
${RM} -f ${OBJ} ${ALT_OBJ}
|
||||
@-if [ -f indent.c ]; then \
|
||||
echo ${RM} -f indent.c; \
|
||||
${RM} -f indent.c; \
|
||||
fi
|
||||
|
||||
clobber: clean
|
||||
${RM} -f ${TARGET} ${ALT_TARGET}
|
||||
@@ -208,20 +256,28 @@ clobber: clean
|
||||
echo 'ate sandwich'; \
|
||||
fi
|
||||
|
||||
nuke: clobber
|
||||
@${TRUE}
|
||||
|
||||
dist_clean: nuke
|
||||
@${TRUE}
|
||||
|
||||
install:
|
||||
@echo "Surely you are performing, Dr. May!"
|
||||
@echo "Dr. Spock says that is not logical!"
|
||||
@${TRUE}
|
||||
|
||||
# backwards compatibility
|
||||
# you may be able to misunderstand the source by reading indent.c
|
||||
#
|
||||
build: all
|
||||
@${TRUE}
|
||||
indent.c: ${PROG}.c
|
||||
@if which "${GINDENT}" >/dev/null 2>&1; then \
|
||||
echo ${RM} -f $@; \
|
||||
${RM} -f $@; \
|
||||
echo "${GINDENT} < $< > $@"; \
|
||||
${GINDENT} < $< > $@; \
|
||||
elif which "${INDENT}" >/dev/null 2>&1; then \
|
||||
echo ${RM} -f $@; \
|
||||
${RM} -f $@; \
|
||||
echo "${INDENT} < $< > $@"; \
|
||||
${INDENT} < $< > $@; \
|
||||
else \
|
||||
echo "no intent tool found, ident $< yourself, sorry"; \
|
||||
echo "exit 1"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
|
||||
##################
|
||||
@@ -240,22 +296,19 @@ waste:
|
||||
@echo 'haste'
|
||||
@${TRUE}
|
||||
|
||||
make:
|
||||
@echo 'Attend a maker faire'
|
||||
maker:
|
||||
@echo 'Participate in a maker faire'
|
||||
@${TRUE}
|
||||
|
||||
easter_egg:
|
||||
@echo you expected to often mis-understand this $${RANDOM} magic
|
||||
@echo chongo '<was here>' "/\\oo/\\"
|
||||
@echo Eggy
|
||||
@echo "you expected to often misunderstand this $${RANDOM} magic"
|
||||
@echo "chongo '<was here>' /\\oo/\\"
|
||||
@echo "Eggy"
|
||||
|
||||
fabricate fashion form frame manufacture produce: make
|
||||
@${TRUE}
|
||||
|
||||
sandwich:
|
||||
sandwich: easter_egg
|
||||
@if [ `id -u` -eq 0 ]; then \
|
||||
echo 'Okay.'; \
|
||||
echo $${RANDOM}`date +%s`$${RANDOM} > $@; \
|
||||
echo "$${RANDOM}`date +%s`$${RANDOM}" > $@; \
|
||||
else \
|
||||
echo 'What? Make it yourself.'; \
|
||||
exit 1; \
|
||||
@@ -265,18 +318,19 @@ sandwich:
|
||||
# as well as the West Coast Computer Faire and
|
||||
# you might be confused different. :-)
|
||||
#
|
||||
supernova: nuke
|
||||
supernova: sandwich
|
||||
@-if [ -r .code_anal ]; then \
|
||||
${RM} -f .code_anal_v6; \
|
||||
else \
|
||||
echo "planet deniers, like some members of the IAU, are so cute when they try to defend their logic"; \
|
||||
fi
|
||||
@echo A $@ helps ${MAKE} the elements that help form planets
|
||||
@echo "A $@ helps ${MAKE} the elements that help form planets"
|
||||
@${TRUE}
|
||||
|
||||
deep_magic:
|
||||
deep_magic: supernova
|
||||
@-if [ -r .code_anal ]; then \
|
||||
ccode_analysis --deep_magic 3a3fabb90892eeb2f610ae0f74a35a970060665a063ab702bd686c17c4ae07f6 --FNV1a_hash_256_bit "prog"; \
|
||||
ccode_analysis --deep_magic 7889066cdbdf09b0408021754586e895be641cc9be29e7eafd3ca65359541f17 \
|
||||
--FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \
|
||||
else \
|
||||
echo "Wrong! Do it again!"; \
|
||||
sleep 2; \
|
||||
@@ -288,7 +342,7 @@ deep_magic:
|
||||
|
||||
magic: deep_magic
|
||||
@-if [ -r .code_anal ]; then \
|
||||
ccode_analysis --mode 216091 --level 216193 --FNV1a_hash_256_bit "prog"; \
|
||||
ccode_analysis --level 20003 --mode 5717175 --FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \
|
||||
else \
|
||||
echo "If you don't eat yer meat, you can't have any pudding!"; \
|
||||
echo "How can you have any pudding if you don't eat yer meat?!"; \
|
||||
@@ -297,14 +351,14 @@ magic: deep_magic
|
||||
|
||||
# The IOCCC resident astronomer states
|
||||
#
|
||||
charon: supernova
|
||||
@echo $@ is a dwarf planet
|
||||
@echo dwarf is a type of planet
|
||||
@echo $@ is a planet
|
||||
charon: magic
|
||||
@echo "$@ is a dwarf planet"
|
||||
@echo "dwarf is a type of planet"
|
||||
@echo "therefore IAU, $@ is a planet"
|
||||
|
||||
pluto: supernova
|
||||
pluto: charon
|
||||
${MAKE} charon
|
||||
@echo $@ is a dwarf planet
|
||||
@echo dwarf is a type of planet
|
||||
@echo $@ is a planet
|
||||
@echo get used to having lots of planets becasue supernovae can ${MAKE} a lot of them
|
||||
@echo "$@ is a dwarf planet"
|
||||
@echo "dwarf is a type of planet"
|
||||
@echo "therefore, $@ is a planet"
|
||||
@echo "having lots of planets is good feature because supernovae can help ${MAKE} a lot of them"
|
||||
+103
-87
@@ -1,41 +1,50 @@
|
||||
# Best abuse of the rules
|
||||
|
||||
Dave Burton
|
||||
<http://ioccc.snox.net>
|
||||
Dave Burton
|
||||
<http://ioccc.snox.net>
|
||||
|
||||
# To build:
|
||||
|
||||
## Judges' comments:
|
||||
### To use:
|
||||
```sh
|
||||
make
|
||||
```
|
||||
|
||||
make
|
||||
### To run:
|
||||
|
||||
./prog [-tcksri] < file.c
|
||||
```sh
|
||||
./prog [-tcksri] < file.c
|
||||
```
|
||||
|
||||
### Try:
|
||||
|
||||
./prog -i < prog.c
|
||||
./prog -s < prog.c
|
||||
./prog -sk < prog.c
|
||||
```sh
|
||||
./prog -i < prog.c
|
||||
./prog -s < prog.c
|
||||
./prog -sk < prog.c
|
||||
```
|
||||
|
||||
If you get stuck, try:
|
||||
|
||||
make test
|
||||
```sh
|
||||
make test
|
||||
```
|
||||
|
||||
If you get really stuck, try:
|
||||
|
||||
man ./tac.man
|
||||
```sh
|
||||
man ./tac.man
|
||||
```
|
||||
|
||||
### Selected Judges Remarks:
|
||||
## Judges' comments:
|
||||
|
||||
They say size isn't everything, and in the case of IOCCC [iocccsize.c](http://www.ioccc.org/2018/iocccsize.c)
|
||||
that is saying something! What is this program weighing and how much does it weigh?
|
||||
|
||||
|
||||
## Author's comments:
|
||||
tac - tokenize and count C and derivative languages
|
||||
---------------------------------------------------
|
||||
|
||||
<blockquote><pre style="font-style:italic">
|
||||
### tac - tokenize and count C and derivative languages
|
||||
|
||||
```
|
||||
tac computes C program size
|
||||
(obfuscated / otherwise)
|
||||
by splitting code as tokens small,
|
||||
@@ -75,10 +84,9 @@ I hope you find this code obscure
|
||||
enough to win, and thus procure
|
||||
a public place for all to see
|
||||
how badly I can butcher C!
|
||||
</pre></blockquote>
|
||||
```
|
||||
|
||||
Said another way....
|
||||
--------------------
|
||||
### Said another way....
|
||||
|
||||
`tac` is the inverse of `cat`(1): it un-concatenates its input into C tokens,
|
||||
writing the token stream to stdout. There are options to suppress the token ids,
|
||||
@@ -120,17 +128,20 @@ counting words correctly absent -k.
|
||||
|
||||
[1]: http://ioccc.org/2014/birken/hint.html "Best use of port 1701"
|
||||
|
||||
Backwards Compatibility
|
||||
-----------------------
|
||||
### Backwards Compatibility
|
||||
|
||||
`tac` was run over all 366 previous IOCCC winning entries:
|
||||
|
||||
find ~/src/obc -type f -name \*.c | wc
|
||||
```sh
|
||||
find ~/src/obc -type f -name \*.c | wc
|
||||
```
|
||||
|
||||
The discrepancies found are documented and explained in the file "discrepancies".
|
||||
|
||||
find ~/src/obc -type f -a -name "*.c" | xargs ./spotcheck ./prog | ./spotdiff |
|
||||
grep -v keep | diff -bw - discrep* | grep "[<>] cl "
|
||||
```sh
|
||||
find ~/src/obc -type f -a -name "*.c" | xargs ./spotcheck ./prog | ./spotdiff |
|
||||
grep -v keep | diff -bw - discrep* | grep "[<>] cl "
|
||||
```
|
||||
|
||||
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
|
||||
@@ -159,8 +170,7 @@ NB: `iocccsize` gets a different answer from `tac` on its own (iocccsize.c) sour
|
||||
proved by fixing iocccsize.c with the included patch, so `iocccsize` reports
|
||||
the correct answer for itself.
|
||||
|
||||
But wait... There's More!
|
||||
-------------------------
|
||||
### But wait... There's More!
|
||||
|
||||
There is no limit on line length, file length, comment length, or identifier length.
|
||||
|
||||
@@ -171,17 +181,20 @@ For instance, here is a simple token counter, useful in finding repeated long to
|
||||
frequency, or counting the references to identifiers, constants, or breadth of use of the
|
||||
language:
|
||||
|
||||
!/bin/sh
|
||||
cat $* | ./prog -t | sort | uniq -c | sort -k1nr
|
||||
```sh
|
||||
#!/usr/bin/env bash
|
||||
cat $* | ./prog -t | sort | uniq -c | sort -k1nr
|
||||
```
|
||||
|
||||
And here is a C keyword frequency counter:
|
||||
|
||||
#!/bin/sh
|
||||
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
|
||||
```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
|
||||
```
|
||||
|
||||
This script was used to "optimize" the reserved word order so the most frequent IOCCC
|
||||
winning entry keywords are checked first.
|
||||
@@ -206,50 +219,51 @@ A more refined version of this is included in the file `unob.sh`,
|
||||
but the simple code below is a serviceable obfuscated C de-obfuscator in a _scripting language_.
|
||||
It really is this easy with `tac`:
|
||||
|
||||
#!/bin/sh
|
||||
script='
|
||||
BEGIN {
|
||||
last=nl="\n";
|
||||
f="c11"; while(getline <f > 0) kw[$0]++; close(f);
|
||||
}
|
||||
```sh
|
||||
#!/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
|
||||
------------------------------
|
||||
### On the question of obfuscation
|
||||
|
||||
* I assume you noticed the [braces][2]?
|
||||
|
||||
@@ -287,8 +301,7 @@ On the question of obfuscation
|
||||
[3]: https://www.youtube.com/watch?v=OHVjs4aobqs "Inconceivable"
|
||||
[4]: https://www.youtube.com/watch?v=Ug75diEyiA0 "Where's the beef?"
|
||||
|
||||
Rule 2
|
||||
------
|
||||
### Rule 2
|
||||
|
||||
The keyword list is externalized as an include file. This presents a useful
|
||||
feature for the source code: not only can the reserved word script above be
|
||||
@@ -322,7 +335,9 @@ which is neither complete (`#define`, `#ifndef`, `#undef` are missing
|
||||
-- yes, Virginia knows about `#define` omitted on purpose),
|
||||
nor correct (many more are added: `I`, `true`, `bool`, `compl`, ...):
|
||||
|
||||
(sed -n '1p' c11; sed -n '2,$p' ioccc.kw.freq | sort) | comm -3 - c11
|
||||
```sh
|
||||
(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.
|
||||
|
||||
@@ -344,8 +359,7 @@ apart from the program, and because Freecode is not entirely free.*)
|
||||
|
||||
[5]: https://www.youtube.com/watch?v=VU0GYSA1POs "Ants"
|
||||
|
||||
Compilation
|
||||
-----------
|
||||
### Compilation
|
||||
|
||||
The code is ANSI compliant, but it does have a string longer than 509 characters.
|
||||
It has been tested on OSX and Linux, Clang and GCC.
|
||||
@@ -361,10 +375,11 @@ NB: This is *not* a portability concern, the one string holds only printable ASC
|
||||
|
||||
Thus:
|
||||
|
||||
clang -ansi -Wall -trigraphs -Wno-trigraphs -Wno-parentheses -Wno-empty-body -Wno-char-subscripts -Wno-pointer-sign -DU=O -DW=\"keywords\" -o prog prog.c
|
||||
```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
|
||||
```
|
||||
|
||||
Coda
|
||||
----
|
||||
### Coda
|
||||
|
||||
Cody Ferguson was relentless in his pursuit of bugs.
|
||||
Thanks to his reports, the version of `unob.sh` is stronger,
|
||||
@@ -380,18 +395,19 @@ such as combined arguments
|
||||
|
||||
Try:
|
||||
|
||||
manpage tac
|
||||
```sh
|
||||
manpage tac
|
||||
|
||||
manpage -h
|
||||
manpage -h | manpage
|
||||
manpage -h | manpage -R | less
|
||||
manpage -h | manpage -P | lpr
|
||||
manpage -h
|
||||
manpage -h | manpage
|
||||
manpage -h | manpage -R | less
|
||||
manpage -h | manpage -P | lpr
|
||||
```
|
||||
|
||||
## Copyright:
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
<!--
|
||||
(c) Copyright 1984-2018, [Leo Broukhis, Simon Cooper, Landon Curt Noll][judges] - All rights reserved
|
||||
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License][cc].
|
||||
|
||||
[judges]: http://www.ioccc.org/judges.html
|
||||
[cc]: http://creativecommons.org/licenses/by-sa/3.0/
|
||||
-->
|
||||
File renamed without changes.
Regular → Executable
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/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}'
|
||||
|
||||
Regular → Executable
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
ioc=$1
|
||||
: ${iocccsize:=iocccsize}
|
||||
|
||||
Regular → Executable
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# filename is 17
|
||||
# 1=cl 2=cw 3=cc 4=ci 5=ts 6=kw 7=kws
|
||||
|
||||
Regular → Executable
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
awk '
|
||||
r==1 { r=0; if (/>=/){print ">>>="; next}
|
||||
|
||||
Regular → Executable
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# unob is a proof-of-concept script.
|
||||
# Prior to tac, scripting the layout of C code was intractable.
|
||||
|
||||
Reference in new issue
Block a user