add revwords package

This commit is contained in:
Neale Pickett 2011-11-01 18:56:04 -06:00
parent ce9b172ecb
commit 99c3ed20ab
11 changed files with 171 additions and 1 deletions

View File

@ -0,0 +1,3 @@
#! /bin/sh
exec /opt/fizzbuzz/bin/fizzbuzz 3</opt/fizzbuzz/token.enc

View File

@ -5,4 +5,4 @@ exec 2>&1
IP=$(cat ip.txt) IP=$(cat ip.txt)
ip addr add $IP dev eth0 || true ip addr add $IP dev eth0 || true
exec tcpsvd -u nobody ${IP%/*} 1013 /opt/fizzbuzz/bin/fizzbuzz 3</opt/fizzbuzz/token.enc exec tcpsvd -u nobody ${IP%/*} 1013 ./go

View File

@ -0,0 +1,20 @@
REVWORDS_PKGDIR = $(TARGET)/revwords
REVWORDS_BUILDDIR = $(BUILD)/revwords
revwords-install: revwords-build
mkdir -p $(REVWORDS_PKGDIR)/bin/
$(call COPYTREE, packages/revwords/service, $(REVWORDS_PKGDIR)/service)
cp packages/revwords/tokens.txt $(REVWORDS_PKGDIR)/
cp $(REVWORDS_BUILDDIR)/token.enc $(REVWORDS_PKGDIR)/
cp packages/revwords/src/revwords $(REVWORDS_PKGDIR)/bin/
revwords-clean:
rm -rf $(REVWORDS_PKGDIR) $(REVWORDS_BUILDDIR)
$(MAKE) -C packages/revwords/src clean
revwords-build: $(REVWORDS_BUILDDIR)/token.enc
$(MAKE) -C packages/revwords/src build
PACKAGES += revwords

View File

@ -0,0 +1,3 @@
#! /bin/sh
exec /opt/revwords/bin/revwords 3</opt/revwords/tokens.txt

View File

@ -0,0 +1 @@
fd84:b410:3441::c3/64

View File

@ -0,0 +1,3 @@
#! /bin/sh
exec svlogd -tt $PWD

View File

@ -0,0 +1,9 @@
#! /bin/sh -e
exec 2>&1
IP=$(cat ip.txt)
ip addr add $IP dev eth0 || true
exec tcpsvd -u nobody ${IP%/*} 1013 ./go

View File

@ -0,0 +1,6 @@
CFLAGS = -Wall -Werror
build: revwords
clean:
rm -f revwords

View File

@ -0,0 +1,105 @@
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#define XDEBUG
int
once()
{
char sdrow[25][10];
int nwords = 5 + (rand() % 2);
int i;
#ifdef DEBUG
nwords = 2;
#endif
for (i = 0; i < nwords; i += 1) {
char *drow = sdrow[i];
int len = 4 + (rand() % 6);
int j;
if (i > 0) putchar(' ');
for (j = 0; j < len; j += 1) {
char c = 'a' + (rand() % 26);
putchar(c);
drow[len-j-1] = c;
}
drow[j] = 0;
}
#ifdef DEBUG
printf (" (answer: ");
for (i = 0; i < nwords; i += 1) {
if (i > 0) putchar(' ');
printf("%s", sdrow[i]);
}
putchar(')');
#endif
putchar('\n');
fflush(stdout);
for (i = 0; i < nwords; i += 1) {
char *p;
if (i > 0) {
if (getchar() != ' ') return -1;
}
for (p = sdrow[i]; *p; p += 1) {
int c = getchar();
if (c != *p) return -1;
}
}
if (getchar() != '\n') return -1;
return 0;
}
int
main(int argc, char *argv[])
{
char token[100];
int i;
{
FILE *tokenin = fdopen(3, "r");
if (! tokenin) {
fprintf(stderr, "Somebody didn't read the instructions.\n");
return 1;
}
if (NULL == fgets(token, sizeof(token), tokenin)) {
fprintf(stderr, "Error reading token.\n");
return 1;
}
fclose(tokenin);
}
#ifndef DEBUG
/* don't hang around forever waiting for input */
alarm(3);
#endif
srandom(time(NULL) * getpid());
for (i = 0; i < 12; i += 1) {
if (-1 == once()) {
printf("tahT saw ton tahw I saw gnitcepxe\n");
return 1;
}
}
fputs(token, stdout);
return 0;
}

View File

@ -0,0 +1,19 @@
#! /bin/sh
## Run like this:
##
## socat EXEC:./solution.sh EXEC:./revwords 3<token.txt
##
lrev () {
while [ -n "$1" ]; do
echo $1 | rev
shift
done
}
while read line; do
echo $line 1>&2
enil=$(lrev $line)
echo $enil
done

View File

@ -0,0 +1 @@
net:xetil-tuhet-calyx