nleet.c (2297B)
1 #include <stdlib.h> 2 #include <ctype.h> 3 #include <stdio.h> 4 #include <errno.h> 5 #include <string.h> 6 7 /* 8 * Nhance - Narthex leetifier 9 * 10 * By Michael Constantine Dimopoulos 11 * https://mcdim.xyz <mk@mcdim.xyz> 12 * License: GNU GPL v3 13 * 14 */ 15 16 17 #define VERSION "v1.2" 18 #define BUFFER_SIZE 256 19 20 FILE * 21 save_stdin(FILE *f) 22 { 23 FILE *f2 = tmpfile(); 24 char buffer[BUFFER_SIZE]; 25 while(fgets(buffer, sizeof(buffer), f) != NULL) { 26 fprintf(f2, "%s", buffer); 27 } 28 fclose(f); 29 return f2; 30 } 31 32 void 33 print_only(FILE *f) 34 { 35 char buffer[BUFFER_SIZE]; 36 while(fgets(buffer, sizeof(buffer), f) != NULL) { 37 printf("%s",buffer); 38 } 39 } 40 41 void 42 leetify(FILE *f, int full_upper) 43 { 44 char buffer[BUFFER_SIZE]; 45 while(fgets(buffer, sizeof(buffer), f) != NULL) { 46 int i; 47 48 /* 49 * 50 * vv EDIT THIS PART vv 51 * 52 */ 53 54 int npflag = 0; 55 for (i=0; i<=BUFFER_SIZE; i++) { 56 if (buffer[i] == 'a' || buffer[i] == 'A') { 57 buffer[i] = '@'; 58 npflag = 1; 59 } else if (buffer[i] == 'o' || buffer[i] == 'O') { 60 buffer[i] = '0'; 61 npflag = 1; 62 } else if (buffer[i] == 'i' || buffer[i] == 'I') { 63 buffer[i] = '1'; 64 npflag = 1; 65 } else if (buffer[i] == 'e' || buffer[i] == 'E') { 66 buffer[i] = '3'; 67 npflag = 1; 68 /* } else if (buffer[i] == 't' || buffer[i] == 'T') { 69 * buffer[i] = '7'; 70 * npflag = 1; */ 71 } 72 } 73 if (npflag == 1) printf("%s",buffer); 74 } 75 } 76 77 void die(char * str) 78 { 79 printf("%s\n", str); 80 exit(0); 81 } 82 83 void help(char * exename) 84 { 85 printf( "Nhance - Narthex leetfier %s\n" 86 "By Michael C. Dim. <mk@mcdim.xyz>\n\n" 87 88 "-h Print this panel & exit\n" 89 "-v Print current version & exit\n\n" 90 "Usage: cat [FILENAME] | %s\n" 91 " %s [FILENAME]\n", 92 VERSION, exename, exename); 93 exit(0); 94 } 95 96 void 97 main(int argc, char* argv[]) 98 { 99 int full_upper, file = 0, i; 100 for (i=0; i<argc; i++) { 101 if (strcmp(argv[i],"-v")==0) 102 die(VERSION); 103 else if (strcmp(argv[i],"-h")==0) 104 help(argv[0]); 105 else 106 file = i; 107 } 108 109 FILE *f2; 110 if (file != 0) { 111 FILE *f = fopen(argv[file], "r"); 112 113 if (f) 114 f2= save_stdin(f); 115 else 116 fprintf(stderr, "%s: %s\n", argv[0], strerror(errno)); 117 exit(1); 118 } else { 119 f2 = save_stdin(stdin); 120 } 121 122 rewind(f2); 123 print_only(f2); 124 rewind(f2); 125 leetify(f2,0); 126 if (full_upper == 1) { 127 rewind(f2); 128 leetify(f2,1); 129 } 130 fclose(f2); 131 132 exit(0); 133 }