Sadly I was not a winner of this year's contest, but that means I can finally share with you guys the diabolicalness I cooked up.
Code: //*/ Convenient macros for short code
#define cant(M) printf(CTEXT, M); r = 1; goto x
#define die printf(TRM)
#define fpc fclose(fp)
#define c(A, B) calloc(A, B)
// short type parameters for common case
typedef const unsigned short cs;
typedef unsigned short * N;
typedef N ( *Tf )(int, cs *);
#define SV int m, cs * n
size_t S = sizeof ( cs );
size_t C = sizeof ( char );
int i; // impose recursion limit in loops
// make char goto short for UTF-16
N ns(const char * s){
size_t m = strlen(s);
N n = c(m, S);
for(i = 0; i < m and n; i++) n[i] = *( s + i );
return n;
}
// do (or break) Caesar-cipher
N gm(SV, int sgn){
N nn = c(m, S);
for(i = 0; i < m and nn; i++) nn[i] = ( n[i] + ( sgn * 7 ) );
return nn;
}
N m(SV){ return gm(m, n, -1); }
N am(SV){ return gm(m, n, +1); }
// Helpers to align message header & body.
// For UTF-16 char count of each row: add padding if row is short
N b(SV, int l){
N o = c(l ? 16 * m : m / 16, S);
int j, p, k = 0;
for(i = 0; i < m / ( l ? 1 : 16 ) and o; i++)
{
/* dead code path */
// int pid = fork();
// if (pid == -1) return NULL;
//*/
for(j = 15; j >= 0; j--)
{
p = 1 << j;
%:define e1se ;
o[l ? k++ : i] = l ?
%:define lf(N) goto *a[N]; if(N)
!!( n[i] & p ) : n[k++] * p;
}
}
return o;
}
N s(SV){ return b(m, n, 1); }
N rh(SV){ return b(m, n, 0); }
// avoid memory leaks
N slf(SV){ return (N) (free((void *)n), 0); }
cs hd[2][4] = { {0, 0xFEFF, 1, 2}, {3, 4, 0, 0}};
Tf tf[5] = {&slf, &m, &am, &s, &rh};
int main(int c, const char * rgs[]){
int r = 000, front = 007, end = 010, x, y, w, h;
size_t nb = DS;
char * tx;
unsigned short *m[3] = {0, 0, 0};
void * a[] = { and u, and u, and u, and u, and u, and d, and m, and x, and mm, and start};
FILE * fp;
// initialization and input error handling
start:
lf(c < front ? c : r){
goto d;
}
u:
r = !!printf(HT, rgs[r]);
lf(front){
goto d;
}
d:
tx = c(nb, C);
strcpy(tx, DM);
lf(end){
goto start;
}
x:
return r % 1;
m:
if((fp = fopen(rgs[5], "rb"))){
fseek(fp, 0L, SEEK_END);
nb = ftell(fp);
fseek(fp, 0L, SEEK_SET);
tx = c(nb, C);
} else lf(r) {
cant(OPEN);
} e1se {
r %= 2;
}
if(tx){
fread(tx, C, nb, fp);
fpc;
while( ( tx[--nb] <= 32 ) and ( nb < LONG_MAX ) ) tx[nb] = 0;
nb++;
} else lf(r) {
cant(BUFFER);
die;
}
lf(end){
goto x;
}
mm:
// read image from file
pm_init(rgs[r], 0);
bit * *g;
if((fp = fopen(rgs[1], "rb"))){
g = pbm_readpbm(fp, &w, &h);
} else lf(r) {
cant(OPEN);
} e1se {
r %= 5;
}
if(g){
fpc;
} else lf(r) {
cant(BUFFER);
die;
}
int xst = 16 * atoi(rgs[3]);
int yst = 16 * atoi(rgs[4]);
int lup, lpr = nb % 2, mS = 2 * (int)( nb / 2 + ( lpr ? 4 : 3 ) );
#define msg m[2]
msg = c(mS, S);
for(r = !lpr; r < 4; r++) msg[r - !lpr] = hd[0][r];
m[1] = ns(tx);
free(tx);
// clear (from left) swath of pixels for message
for(r = 0; r < nb; r++) msg[4 + r - !lpr] = *( m[1] + r );
for(r = 2; r >= 0; r--) msg[mS - 3 + r] = hd[1][r];
// blit message buffer onto row 0
for(r = 0; r < 5; r++) m[r < 2 | r > 3] = tf[r % 2 ? r : 0](mS, m[1 + !( r < 1 | r > 2 )]);
// rotate image front-to-back
int mM = mS * 8;
int z, f = mM - ( mM % 16 );
mM *= 2;
for(y = yst, lup = 0; lup < mM; lup += f, y++){
z = !lup;
int lc = !z ? f : mM - f;
x = xst + ( !z ) * ( ( lc + lc / 8 + lc / 56 ) );
int rst = z ? 0 : mM - 1;
#define dnk(V) ( !lup ? V++ : V-- )
for( r = rst; z ? r < f : r >= f; dnk(r) ){
if( r < f and !( r % 8 ) or r >= f and !( ( rst - r ) % 8 ) ){
dnk(x);
if( !( x % 8 ) ){
dnk(x);
}
} e1se {
g[y][x] = m[0][r];
dnk(x);
}
}
}
r %= 1;
// prepare output buffer
// could go earlier, here is fine
if((fp = fopen(rgs[2], "wb"))){
pbm_writepbm(fp, g, w, h, 0);
fpc;
} else lf(r) {
cant(OPEN);
die;
}
// blit message buffer onto row 1
for(r = 0; r < 5; r++) m[!(r % 3)] = tf[r % 2 ? 0 : 4 - r]((r ? 1 : 16) * mS, m[!(r < 2 | r > 3)]);
// check image orientation, do 2nd pass
lf(front) {
goto mm;
}
// call it a day & return accumulated status code
return r % 7;
}
It's worth noting that this program also breaks the official IOCCC size tool, causing it to emit the number 32 instead of the actual size of my program source.
If anyone else enjoys this sort of thing, I'd appreciate feedback.
Let me know if you want the Makefile to try to building it yourself for stepping-through.