]>
Commit | Line | Data |
---|---|---|
5b25ff5f | 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; | |
56 | struct timeval tv; | |
57 | FILE *f; | |
58 | char ch[1]; | |
59 | ||
60 | srand((gettimeofday(&tv,NULL),tv.tv_usec)); | |
61 | if (argc==1) { | |
62 | f=stdin; | |
63 | while(fread(ch,1,1,f)) { | |
64 | for(c=0; c<strlen(normal); c++) { | |
65 | if(normal[c]==ch[0]) { | |
66 | switch(myrandom(5)) { | |
67 | case 4: if(nethack5[c]!=' ') ch[0]=nethack5[c]; | |
68 | case 3: if(nethack4[c]!=' ') ch[0]=nethack4[c]; | |
69 | case 2: if(nethack3[c]!=' ') ch[0]=nethack3[c]; break; | |
70 | case 1: if(nethack2[c]!=' ') ch[0]=nethack2[c]; break; | |
71 | case 0: ch[0]=nethack1[c]; break; | |
72 | default: break; | |
73 | } | |
74 | } | |
75 | } | |
76 | printf("%c",ch[0]); | |
77 | } | |
78 | fclose(f); | |
79 | } else { | |
80 | for(i=1; i<argc; i++) { | |
81 | nethackify(argv[i]); | |
82 | } | |
83 | printf("\n"); | |
84 | } | |
85 | ||
86 | return 0; | |
87 | } |