diff --git a/2001/coupard/Makefile b/2001/coupard/Makefile index 49e7cf5a9..092dde015 100644 --- a/2001/coupard/Makefile +++ b/2001/coupard/Makefile @@ -1,18 +1,9 @@ #!/usr/bin/env make # -# IOCCC 2001 entry Makefile +# IOCCC 2001 winning entry - coupard ################################################################################ # -# An Historical Makefile NOTE: -# -# The orig.Makefile, if it exits, is the original Makefile before this IOCCC -# year directory was reworked so that entries are in separate directories. -# This also applies to any orig.ansi.mk and orig.common.mk files. -# -# Several Makefiles were modified / formed in 2022, and as such it may have -# elements that are not historically compatible with way entries were built. -# # Regarding individual entries: # # IOCCC winning entry code may not work on your system. Even with standards, @@ -45,192 +36,292 @@ # See: http://creativecommons.org/licenses/by-sa/3.0/ -SHELL= /bin/sh -CAT= cat -RM= rm -SED= sed -TRUE= true -#CINCLUDE= -I ${HOMEBREW_PREFIX}/include/SDL2 - -# optimization +############################# +# shell used by this Makefile +############################# # -# Most compiles will safely use -O2. Some can use only -O. -# A few compilers have broken optimizers and thus you may -# not want anything. +SHELL= bash + +####################### +# common tool locations +####################### +# +include ../../var.mk + +# Set X11_LIBDIR to the directory where the X11 library resides +# +#X11_LIBDIR= /usr/X11R6/lib +#X11_LIBDIR= /usr/X11/lib +X11_LIBDIR= /opt/X11/lib + +# Set X11_INCLUDEDIR to the directory where the X11 include files reside +# +#X11_INCDIR= /usr/X11R6/include +#X11_INCDIR= /usr/X11/include +X11_INCDIR= /opt/X11/include + +# Common C compiler warnings to silence +# +#CSILENCE= +CSILENCE= -Wno-empty-body -Wno-pointer-sign -Wno-return-type + +# Common C compiler warning flags +# +#CWARN= ${CSILENCE} +#CWARN= -Wall ${CSILENCE} +CWARN= -Wall -Wextra ${CSILENCE} +#CWARN= -Wall -Wextra -pedantic ${CSILENCE} + +# Compiler standard +# +#CSTD= +#CSTD= -ansi +CSTD= -std=gnu99 + +# Compiler bit architecture +# +# Some entries require 32-bitness: +# ARCH= -m32 +# +# Some entries require 64-bitness: +# ARCH= -m64 +# +# By default we assume nothing: +# +ARCH= + +# Defines that are needed to compile +# +CDEFINE= +#CDEFINE= -DIOCCC + +# 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} -I ${X11_INCDIR}/X11 +#CINCLUDE= `${SDL2_CONFIG} --cflags` + +# 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 +# under those buggy optimizers and thus you may not want anything. +# Reasonable compilers will allow for -O3. # #OPT= #OPT= -O -OPT= -O2 +#OPT= -O1 +#OPT= -O2 +OPT= -O3 -# flags for ANSI compiles +# Default flags for ANSI C compilation # -# NOTE: Some ANSI compilers make use of -Xa to turn on ANSI mode, -# others such as gcc may want -ansi, others (Compaq Tru64 Unix) -# want -std1, and others may want nothing at all. -# Adjust the CFLAGS line as needed. -# -# NOTE: Some compilers cannot optimize, or optimize some entries -# incorrectly. You might want to turn on -O to see if your -# compiler can handle them. -# -# -#CFLAGS= -Xa ${OPT} -#CFLAGS= -std1 $(OPT) -CFLAGS= -ansi ${OPT} +CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT} -# NOTE: On some systems, the library path does not include the location -# of the X11 libraries. You might need to use a -L/path/to/X11/lib/dir -# in order to compile with these libs. +# Libraries needed to build # -X11CCFLAGS= -I/usr/X11R6/include -I/usr/X11R6/include/X11 -I/usr/include/X11 -#X11CCFLAGS= -X11LDFLAGS= -L/usr/X11R6/lib -Wl,-R/usr/X11R6/lib -#X11LDFLAGS= +LIBS= +#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 -MAY_NEED_GCC= gcc +#CC=clang +#CC=gcc -# winners that compile under ANSI C +# Compiler add-ons or replacements for clang only # -WINNERS= anonymous bellard bellard.otccex cheong coupard \ - ctk dgbeards herrmann1 herrmann2 jason kev ollinger rosten \ - schweikh westley williams -ALT_NAMES= westley.orig -DATA_FILES= anonymous_files bellard_files herrmann1_files herrmann2_files - - -all: ${WINNERS} - -# Most likely to amaze +ifeq ($(CC),clang) # -anonymous: anonymous.c - magic='${MAY_NEED_GCC} -O1'; \ - X='-DA(X)=#X'; \ - warning='-pedantic -Dprocessor'; \ - $$magic $$warning -Dmagic= $$X "-DX=A($$magic \"$$X\")" \ - -o anonymous anonymous.c - -anonymous_files: anonymous.ten.c - -# Best abuse of the rules +CSILENCE+= -Wno-implicit-int-conversion -Wno-missing-prototypes \ + -Wno-missing-variable-declarations -Wno-pedantic \ + -Wno-poison-system-directories -Wno-sign-conversion -Wno-strict-prototypes # -bellard: bellard.c - ${CC} -rdynamic ${CFLAGS} bellard.c -o bellard -ldl - -bellard_files: bellard.otccex.c - -# Best short program +CWARN+= -Weverything # -cheong: cheong.c - ${CC} ${CFLAGS} cheong.c -o cheong +endif -# Most obfuscated sound +# Specific add-ons or replacements for gcc only # -coupard: coupard.c - ${CC} ${CFLAGS} -o coupard coupard.c - -# Worst Driver +ifeq ($(CC),gcc) # -ctk: ctk.c - ${CC} ${CFLAGS} -o ctk ctk.c - -# Worst AI +#CSILENCE+= # -dgbeards: dgbeards.c - ${CC} ${CFLAGS} -DE=break -DF=char -DK=case -DP=int -DR=return \ - -DI=0xFFFF dgbeards.c -o dgbeards - -# Best abuse of the C preprocessor +#CWARN+= # -herrmann1: herrmann1.c herrmann1.sh - @echo "NOTE: $@ must be built/run using the script $@.sh" - ${SHELL} ./herrmann1.sh +endif -herrmann1_files: herrmann1.gcd herrmann1.sh herrmann1.times2 -# Most eye-crossing +############################## +# Special flags for this entry +############################## # -# This entry requires the GCC -include feature. +ENTRY= coupard +PROG= ${ENTRY} # -herrmann2: herrmann2.c - ${MAY_NEED_GCC} ${CFLAGS} herrmann2.c -o herrmann2 \ - -include /usr/include/stdlib.h -include /usr/include/stdio.h \ - -include /usr/include/time.h -include /usr/include/unistd.h - -herrmann2_files: herrmann2.cup herrmann2.ioccc - -# Best Of Show +OBJ= ${PROG}.o +DATA= +TARGET= ${PROG} # -jason: jason.c - ${CC} ${CFLAGS} -o jason jason.c +ALT_OBJ= +ALT_TARGET= -# Best Curses Game + +################# +# build the entry +################# # -kev: kev.c - ${CC} ${CFLAGS} -DPORT=5455 -DSPEED=50 -o kev kev.c \ - -lcurses -ltermcap \ - -Dl_="socket(il.sin_family=AF_INET,SOCK_STREAM,0)" - -# Best primal ASCII graphics -# -ollinger: ollinger.c - ${CC} ${CFLAGS} ollinger.c -o ollinger - -# Best abuse of the user -# -rosten: rosten.c - ${CC} ${CFLAGS} rosten.c ${X11CCFLAGS} ${X11LDFLAGS} -pedantic -lX11 \ - -o rosten - -# Best one-liner -# -schweikh: schweikh.c - ${CC} ${CFLAGS} schweikh.c -o schweikh - -# Best position-independant code -# -westley: westley.c - ${CC} ${CFLAGS} westley.c -o westley - -westley.orig: westley.orig.c - ${CC} ${CFLAGS} westley.orig.c -o westley.orig - -# Best position-independant code -# -williams: williams.c - ${CC} williams.c ${X11CCFLAGS} ${X11LDFLAGS} -lX11 -o williams - -everything: ${WINNERS} ${ALT_NAMES} ${DATA_FILES} - -love: - @echo 'not war?' - -haste: - ${MAKE} waste - -waste: - @echo 'waste' - -clean: - ${RM} -f *.o a.out core ${WINNERS} - -clobber: clean - ${RM} -f ${WINNERS} - ${RM} -f ${ALT_NAMES} - -nuke: clobber +all: data ${TARGET} @${TRUE} -install: all - ${CAT} ${WINNERS} ${ALT_NAMES} > /dev/null +.PHONY: all alt data everything clean clobber install \ + love haste waste maker easter_egg sandwich \ + supernova deep_magic magic charon pluto + +${PROG}: ${PROG}.c + ${CC} ${CFLAGS} $< -o $@ ${LIBS} + +# alternative executable +# +alt: data ${ALT_TARGET} + @${TRUE} + +# data files +# +data: ${DATA} + @${TRUE} + +# both all and alt +# +everything: all alt + + +############### +# utility rules +############### +# +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} + @-if [ -e sandwich ]; then \ + ${RM} -f sandwich; \ + echo 'ate sandwich'; \ + fi + +install: + @echo "Dr. Spock says that is not logical!" + @${TRUE} + +# you may be able to misunderstand the source by reading indent.c +# +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 + + +################## +# 133t hacker rulz +################## +# +love: + @echo 'not war?' + @${TRUE} + +haste: + $(MAKE) waste + @${TRUE} + +waste: + @echo 'haste' + @${TRUE} + +maker: + @echo 'Participate in a maker faire' + @${TRUE} + +easter_egg: + @echo "you expected to often misunderstand this $${RANDOM} magic" + @echo "chongo '' /\\oo/\\" + @echo "Eggy" + +sandwich: easter_egg + @if [ `id -u` -eq 0 ]; then \ + echo 'Okay.'; \ + echo "$${RANDOM}`date +%s`$${RANDOM}" > $@; \ + else \ + echo 'What? Make it yourself.'; \ + exit 1; \ + fi + +# Understand the history of the Homebrew Computer Club +# as well as the West Coast Computer Faire and +# you might be confused different. :-) +# +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" + @${TRUE} + +deep_magic: supernova + @-if [ -r .code_anal ]; then \ + ccode_analysis --deep_magic 7889066cdbdf09b0408021754586e895be641cc9be29e7eafd3ca65359541f17 \ + --FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \ + else \ + echo "Wrong! Do it again!"; \ + sleep 2; \ + echo "Wrong! Do it again!"; \ + sleep 2; \ + echo "Wrong! Do it again!"; \ + fi + @${TRUE} + +magic: deep_magic + @-if [ -r .code_anal ]; then \ + 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?!"; \ + fi + @${TRUE} + +# The IOCCC resident astronomer states +# +charon: magic + @echo "$@ is a dwarf planet" + @echo "dwarf is a type of planet" + @echo "therefore IAU, $@ is a planet" + +pluto: charon + ${MAKE} charon + @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" diff --git a/2001/coupard/README.md b/2001/coupard/README.md index 52054f0ac..479e09b14 100644 --- a/2001/coupard/README.md +++ b/2001/coupard/README.md @@ -1,4 +1,4 @@ -Most obfuscated sound: +# Most obfuscated sound: Pierre-Philippe Coupard Lineo, Inc. @@ -7,130 +7,142 @@ Most obfuscated sound: Lindon, UT 84042 USA +# To build: -Judges' Comments: +```sh +make +``` - To build: +### To run: - make coupard +```sh +./coupard +``` - Try: +### Try: - ./coupard > /dev/audio - -or- - ./coupard > /dev/sound/dsp +```sh +./coupard > /dev/audio +-or- +./coupard > /dev/sound/dsp +``` - You may need to run this a few times to understand exactly what is - being said. You might even need to look somewhere on your desktop, - your arm or the wall for confirmation. +## Judges' comments: +You may need to run this a few times to understand exactly what is +being said. You might even need to look somewhere on your desktop, +your arm or the wall for confirmation. -Selected Author's Comments: +## Author's comments: - Past years' IOCCC entries do many marvellous things in small packages, - such as console utilities, games, math, languages or even X - applications. But they all have one thing in common (despite being hard - to read obviously) : when they interact with the user, they only - *display* things, i.e. they display either text or drawings. +Past years' IOCCC entries do many marvellous things in small packages, +such as console utilities, games, math, languages or even X +applications. But they all have one thing in common (despite being hard +to read obviously) : when they interact with the user, they only +*display* things, i.e. they display either text or drawings. - So, for a change, this program titillates the sense of hearing instead - of sight : this program is a self-contained speech synthesizer that - tells the current time through the computer's sound card - in just under - 2 Kb of source code ! +So, for a change, this program titillates the sense of hearing instead +of sight : this program is a self-contained speech synthesizer that +tells the current time through the computer's sound card - in just under +2 Kb of source code ! - In the 2001 IOCCC rules and guidelines documents, there is no mention of - what is or isn't acceptable regarding audio I/Os, but it is mentioned - that hardware-specific and/or non-portable programs are not welcome. So, - in order to do audio and satisfy those requirements, the format required - by /dev/audio has been chosen : /dev/audio is a rather ancient - fixed-format audio interface that is supported by the majority of Unices - that can do sound, as a lowest-denominator sound I/Os interface. +In the 2001 IOCCC rules and guidelines documents, there is no mention of +what is or isn't acceptable regarding audio I/Os, but it is mentioned +that hardware-specific and/or non-portable programs are not welcome. So, +in order to do audio and satisfy those requirements, the format required +by /dev/audio has been chosen : /dev/audio is a rather ancient +fixed-format audio interface that is supported by the majority of Unices +that can do sound, as a lowest-denominator sound I/Os interface. - Program usage : +### Program usage: - * To listen to what the program says directly, invoke +* To listen to what the program says directly, invoke - ./coupard > /dev/audio +```sh +./coupard > /dev/audio +``` - the program then speaks out something like +the program then speaks out something like - "The time is HH hours MM minutes SS seconds" + "The time is HH hours MM minutes SS seconds" - in military time (24 hours). Of course, you need to have permissions - to write to /dev/audio, have your sound card enabled, the volume up, - the speakers connected ... :-) +in military time (24 hours). Of course, you need to have permissions +to write to /dev/audio, have your sound card enabled, the volume up, +the speakers connected ... :-) - * If you want to convert the audio output of the program into another - audio format, you can pipe it to sox for example (sox is the - Swiss army knife of Unix audio tools) : the command +* If you want to convert the audio output of the program into another +audio format, you can pipe it to sox for example (sox is the +Swiss army knife of Unix audio tools) : the command - ./coupard | sox -c1 -r8000 -tub - -c2 -r44100 -twav test.wav +```sh +./coupard | sox -c1 -r8000 -tub - -c2 -r44100 -twav test.wav +``` - converts the output of the program into a 44.1KHz stereo .WAV - file and saves it into "test.wav". +converts the output of the program into a 44.1KHz stereo .WAV +file and saves it into "test.wav". - The output format of the program is 8KHz, unsigned 8-bit samples. +The output format of the program is 8KHz, unsigned 8-bit samples. - NOTE : the program's return code is meaningless +NOTE : the program's return code is meaningless - Audio quality : +### Audio quality: - The quality of the sound produced by the program is cross between a - yogurt-pot-and-string telephone and a bad gramophone, i.e. the S/N - ratio is very low and the signal's top frequency is very low as well. - This is because the audio is stored internally at a sampling rate of - 4KHz (the Nyquist frequency is only 2KHz) with only 4-bit samples - (adding 24db of quantization noise to an already poor signal). +The quality of the sound produced by the program is cross between a +yogurt-pot-and-string telephone and a bad gramophone, i.e. the S/N +ratio is very low and the signal's top frequency is very low as well. +This is because the audio is stored internally at a sampling rate of +4KHz (the Nyquist frequency is only 2KHz) with only 4-bit samples +(adding 24db of quantization noise to an already poor signal). - In short, you might have to listen twice to understand what the - program is saying. 2048 bytes including the sound generation program - doesn't leave much room for audio quality ;-) +In short, you might have to listen twice to understand what the +program is saying. 2048 bytes including the sound generation program +doesn't leave much room for audio quality ;-) - Speech generation : +### Speech generation: - Only 9 phonemes are used to generate the speech. Beside the limited - number of words the program has to generate (66 words), the low sound - quality is actually exploited to take liberties with certain - consonants (for example, "s" and "f" sound very much the same at 4KHz, - so they can be merged into one phoneme). Because the psychoacoustic - context around those phonemes is just sufficient, the words can be - interpreted correctly most of the time despite the fact that they are - pronounced quite wrongly. +Only 9 phonemes are used to generate the speech. Beside the limited +number of words the program has to generate (66 words), the low sound +quality is actually exploited to take liberties with certain +consonants (for example, "s" and "f" sound very much the same at 4KHz, +so they can be merged into one phoneme). Because the psychoacoustic +context around those phonemes is just sufficient, the words can be +interpreted correctly most of the time despite the fact that they are +pronounced quite wrongly. - Internally, a table is used to generate most of the words, and - composite words such as "thirty-five" are made up by the C code - externally. +Internally, a table is used to generate most of the words, and +composite words such as "thirty-five" are made up by the C code +externally. - Data compression : +### Data compression: - Even at 4KHz / 4 bits, the weight of all the phoneme samples and the - word-to-phonemes table put together is over 1600 bytes, which is well - over 2048 bytes when encoded in a C string made of printable - characters. Therefore, a compression method was needed that's both - efficient and with a decompressor that is implementable in the - shortest amount of code possible. GSM compression is very good, but - needs large psychoacoustic tables to regenerate the original - signal. Raw FFT spectral compression is efficient too, but the - decompression code can't be made small enough. +Even at 4KHz / 4 bits, the weight of all the phoneme samples and the +word-to-phonemes table put together is over 1600 bytes, which is well +over 2048 bytes when encoded in a C string made of printable +characters. Therefore, a compression method was needed that's both +efficient and with a decompressor that is implementable in the +shortest amount of code possible. GSM compression is very good, but +needs large psychoacoustic tables to regenerate the original +signal. Raw FFT spectral compression is efficient too, but the +decompression code can't be made small enough. - The best compression compromise was found using a simple Huffman - compressor, and encoding the compressed data by blocks of 13 bits in - pairs of printable ASCII characters : the raw data is compressed to - 8465 bits, and the resulting C string is therefore about 1300 - characters, which leaves just enough room for the decompressor with a - hard-coded Huffman tree, and the code that plays the phonemes in the - right order. +The best compression compromise was found using a simple Huffman +compressor, and encoding the compressed data by blocks of 13 bits in +pairs of printable ASCII characters : the raw data is compressed to +8465 bits, and the resulting C string is therefore about 1300 +characters, which leaves just enough room for the decompressor with a +hard-coded Huffman tree, and the code that plays the phonemes in the +right order. - Note on compiler warnings and lint : +### Note on compiler warnings and lint: - The program should build with gcc's -Wall -Werror and -ansi flags. If - the -pedantic flag is used, gcc will complain about the length of the - data string and the sign of its type, and also the fact that main() - returns with no value. The confusion with the sign of the char type - doesn't matter with the data string because it's composed only of - printable characters under 127. +The program should build with gcc's -Wall -Werror and -ansi flags. If +the -pedantic flag is used, gcc will complain about the length of the +data string and the sign of its type, and also the fact that main() +returns with no value. The confusion with the sign of the char type +doesn't matter with the data string because it's composed only of +printable characters under 127. - When linting the program with lclint, it complains about a huge list - of things that, if corrected to make lint happy, would probably double - the size of the source code. +When linting the program with lclint, it complains about a huge list +of things that, if corrected to make lint happy, would probably double +the size of the source code.