File: nethackify.c

package info (click to toggle)
filters 2.45
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 240 kB
  • ctags: 40
  • sloc: lex: 1,869; perl: 941; makefile: 76; ansic: 69; sh: 6
file content (87 lines) | stat: -rw-r--r-- 1,985 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

/*
nethackify
tries to write text ala nethack

cat /etc/motd/ | nethackify
/exec -o nethackify "good morning :)"

gurkan@linuks.mine.nu
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>

char *normal  ="ABCDEFGHIKLMNOPQRTUVWZbdeghjklmnoqwy:;01678";
char *nethack1="^P(|||C||||||CFCP|J/V/|cccni||nrccvv.,C|o/3";
char *nethack2="?b?)F-(-?<_??(?(F???/??|??????r???????(???o";
char *nethack3=" [ [L       \\                              ";
char *nethack4="    [              \\                       ";
char *nethack5="    _               \\                      ";

int myrandom(float max)
{
   return ((int)(max*rand()/(RAND_MAX+1.0)));
}

void nethackify(char* str)
{
    int i,c;
    for(i=0; i<strlen(str); i++) {
	for(c=0; c<strlen(normal); c++) {
	    if(normal[c]==str[i]) {
		if (myrandom(3)>0) {
		switch(myrandom(5)) {
		    case 4: if(nethack5[c]!=' ') str[i]=nethack5[c];
		    case 3: if(nethack4[c]!=' ') str[i]=nethack4[c];
		    case 2: if(nethack3[c]!=' ') str[i]=nethack3[c]; break;
		    case 1: if(nethack2[c]!=' ') str[i]=nethack2[c]; break;
		    case 0: str[i]=nethack1[c]; break;
		    default: break;
		}
		}
	    }
	}
	printf("%c",str[i]);
    }
    
    printf(" ");
}

int main(int argc, char **argv)
{
    int i,c;
    struct timeval tv;
    FILE *f;
    char ch[1];

    srand((gettimeofday(&tv,NULL),tv.tv_usec));
    if (argc==1) {
	f=stdin;
	while(fread(ch,1,1,f)) {
	    for(c=0; c<strlen(normal); c++) {
	        if(normal[c]==ch[0]) {
		    switch(myrandom(5)) {
			case 4: if(nethack5[c]!=' ') ch[0]=nethack5[c];
	    	        case 3: if(nethack4[c]!=' ') ch[0]=nethack4[c];
			case 2: if(nethack3[c]!=' ') ch[0]=nethack3[c]; break;
			case 1: if(nethack2[c]!=' ') ch[0]=nethack2[c]; break;
			case 0: ch[0]=nethack1[c]; break;
			default: break;
		    }
		}
	    }
	    printf("%c",ch[0]);
	}
	fclose(f);
    } else {
	for(i=1; i<argc; i++) {
	    nethackify(argv[i]);
	}
	printf("\n");
    }
    
    return 0;
}