From 3f6b64304a8a11f0505e91681384327696983928 Mon Sep 17 00:00:00 2001 From: Epoch Qwert Date: Fri, 9 Jan 2015 19:25:02 -0600 Subject: XuntilY.awk is actually a shell script, but mostly written in awk to make XuntilY easier to use for people without Perl gopherd.sh... I don't remember the change. music.c is to practice reading music. sockip is to get the IP of the listening socket, like if ran from inetd --- src/games/music.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/libexec/sockip.c | 15 +++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/games/music.c create mode 100644 src/libexec/sockip.c (limited to 'src') diff --git a/src/games/music.c b/src/games/music.c new file mode 100644 index 0000000..3b52b4e --- /dev/null +++ b/src/games/music.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include + +char cheat; + +void print_note(char n) { + printf(" %c \n",n=='G'?cheat?n:'o':' '); + printf("--%c--\n",n=='F'?cheat?n:'o':'-'); + printf(" %c \n",n=='E'?cheat?n:'o':' '); + printf("--%c--\n",n=='D'?cheat?n:'o':'-'); + printf(" %c \n",n=='C'?cheat?n:'o':' '); + printf("--%c--\n",n=='B'?cheat?n:'o':'-'); + printf(" %c \n",n=='A'?cheat?n:'o':' '); + printf("--%c--\n",n=='g'?cheat?n:'o':'-'); + printf(" %c \n",n=='f'?cheat?n:'o':' '); + printf("--%c--\n",n=='e'?cheat?n:'o':'-'); + printf(" %c \n",n=='d'?cheat?n:'o':' '); + printf(" %c \n",n=='c'?cheat?n:'o':' '); + printf(" %c \n",n=='b'?cheat?n:'o':' '); + printf(" %c \n",n=='a'?cheat?n:'o':' '); +} + +char notes[]="ABCDEFGabcdefg"; + +int main(int argc,char *argv[]) { + int count; + int correct=0; + int total=20; + char note; + cheat=argc > 1; + short in; + srandom(time(0)); + total=20; + count=total; + printf("\x1b[H\x1b[J"); + time_t end; + time_t start=time(0); + for(;in != -1 && count;count--) { + note=notes[random()%strlen(notes)]; + print_note(note); + in=fgetc(stdin); + if(in == note || in == note+' ') { + printf("\x1b[H\x1b[J"); + printf("Yay!\n"); + correct++; + in=fgetc(stdin);//kill the newline + } else { + printf("\x1b[H\x1b[J"); + printf("boo!\n"); + in=fgetc(stdin);//kill the newline + } + } + end=time(0); + printf("took you %lld seconds\n",end-start); + printf("got %d/%d right.\n",correct,total); + return 0; +} diff --git a/src/libexec/sockip.c b/src/libexec/sockip.c new file mode 100644 index 0000000..542a88d --- /dev/null +++ b/src/libexec/sockip.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include + +int main(int argc,char *argv[]) { + struct sockaddr_in6 sa6; + unsigned int sl=sizeof(sa6); + char h[NI_MAXHOST], s[NI_MAXSERV]; + if(getsockname(0,(struct sockaddr *)&sa6,&sl) == -1) return 1; + if(getnameinfo((struct sockaddr *)&sa6,sl,h,sizeof(h),s,sizeof(s),NI_NUMERICHOST|NI_NUMERICSERV)) return 2; + puts(h); + puts(s); + return 0; +} -- cgit v1.2.3