| 1 | |
| 2 | /* |
| 3 | nethackify |
| 4 | tries to write text ala nethack |
| 5 | |
| 6 | cat /etc/motd/ | nethackify |
| 7 | /exec -o nethackify "good morning :)" |
| 8 | |
| 9 | gurkan@linuks.mine.nu |
| 10 | */ |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <string.h> |
| 14 | #include <stdlib.h> |
| 15 | #include <sys/time.h> |
| 16 | |
| 17 | char *normal ="ABCDEFGHIKLMNOPQRTUVWZbdeghjklmnoqwy:;01678"; |
| 18 | char *nethack1="^P(|||C||||||CFCP|J/V/|cccni||nrccvv.,C|o/3"; |
| 19 | char *nethack2="?b?)F-(-?<_??\(?(F??\?/??|??????r???????\(???o"; |
| 20 | char *nethack3=" [ [L \\ "; |
| 21 | char *nethack4=" [ \\ "; |
| 22 | char *nethack5=" _ \\ "; |
| 23 | |
| 24 | int myrandom(float max) |
| 25 | { |
| 26 | return ((int)(max*rand()/(RAND_MAX+1.0))); |
| 27 | } |
| 28 | |
| 29 | void nethackify(char* str) |
| 30 | { |
| 31 | int i,c; |
| 32 | for(i=0; i<strlen(str); i++) { |
| 33 | for(c=0; c<strlen(normal); c++) { |
| 34 | if(normal[c]==str[i]) { |
| 35 | if (myrandom(3)>0) { |
| 36 | switch(myrandom(5)) { |
| 37 | case 4: if(nethack5[c]!=' ') str[i]=nethack5[c]; |
| 38 | case 3: if(nethack4[c]!=' ') str[i]=nethack4[c]; |
| 39 | case 2: if(nethack3[c]!=' ') str[i]=nethack3[c]; break; |
| 40 | case 1: if(nethack2[c]!=' ') str[i]=nethack2[c]; break; |
| 41 | case 0: str[i]=nethack1[c]; break; |
| 42 | default: break; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | printf("%c",str[i]); |
| 48 | } |
| 49 | |
| 50 | printf(" "); |
| 51 | } |
| 52 | |
| 53 | int main(int argc, char **argv) |
| 54 | { |
| 55 | int i,c, ch; |
| 56 | struct timeval tv; |
| 57 | |
| 58 | srand((gettimeofday(&tv,NULL),tv.tv_usec)); |
| 59 | if (argc==1) { |
| 60 | while((ch = getchar()) != EOF) { |
| 61 | for(c=0; c<strlen(normal); c++) { |
| 62 | if(normal[c]==ch) { |
| 63 | switch(myrandom(5)) { |
| 64 | case 4: if(nethack5[c]!=' ') ch=nethack5[c]; |
| 65 | case 3: if(nethack4[c]!=' ') ch=nethack4[c]; |
| 66 | case 2: if(nethack3[c]!=' ') ch=nethack3[c]; break; |
| 67 | case 1: if(nethack2[c]!=' ') ch=nethack2[c]; break; |
| 68 | case 0: ch=nethack1[c]; break; |
| 69 | default: break; |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | printf("%c",ch); |
| 74 | } |
| 75 | } else { |
| 76 | for(i=1; i<argc; i++) { |
| 77 | nethackify(argv[i]); |
| 78 | } |
| 79 | printf("\n"); |
| 80 | } |
| 81 | |
| 82 | return 0; |
| 83 | } |