Narthex

Modular dictionary generator
git clone git@git.mcdim.xyz:/var/www/git/Narthex.git
Log | Files | Refs | README | LICENSE

commit c51cd47d4e79b53398fe2cde2c5784d8680e1b27
parent 332e5b1eb083a949473281480f1a5ea16c32a994
Author: Michael Constantine Dimopoulos <mk@mcdim.xyz>
Date:   Sun, 27 Feb 2022 22:56:53 +0000

Flexible nleet, fixed ninc typo

Diffstat:
Minc/nin.c | 2+-
Mleet/nleet.1 | 8+++++---
Mleet/nleet.c | 77+++++++++++++++++++++++++++++++++++------------------------------------------
3 files changed, 41 insertions(+), 46 deletions(-)

diff --git a/inc/nin.c b/inc/nin.c @@ -42,7 +42,7 @@ help(char *exename) printf( "ninc - Narthex incrementor %s\n" "By Michael Constantine Dimopoulos <mk@mcdim.xyz>\n\n" - "-d use delimiters (specify in a string)\n" + "-d use delimiters (specified in a string)\n" "-n increment numerical lines as well\n" "-h print this panel & exit\n" "-v print current version & exit\n\n" diff --git a/leet/nleet.1 b/leet/nleet.1 @@ -1,13 +1,15 @@ .\" Manpage for nleet -.TH man 8 "15 Jul 2021" "1.3.2" "nleet manual page" +.TH man 8 "15 Jul 2021" "1.4.0" "nleet manual page" .SH NAME nleet \- Narthex leetifier .SH SYNOPSIS cat dictionary.txt | nleet > output.txt -nhance dictionary.txt +cat dictionary.txt | nleet a:4 t:7 > output.txt +nleet dictionary.txt +nleet dictionary.txt e:3 .SH DESCRIPTION -nleet reads from standard input or a file and appends to it the lines leetified (hello -> h3ll0). It prints to standard output. +nleet reads from standard input or a file and appends to it the lines leetified (hello -> h3ll0) as pre-determined, or as the user specified. It prints to standard output. .SH OPTIONS -v print version and exit diff --git a/leet/nleet.c b/leet/nleet.c @@ -2,14 +2,11 @@ * nleet - Narthex leetifier * * By Michael Constantine Dimopoulos https://mcdim.xyz <mk@mcdim.xyz> - * License: GNU GPL v3 - * + * License: GNU GPL v3 * * nleet will iterate over stdin or a file and, after printing the * dictionary as is, it will reprint it this time with some characters - * replaced with their leet equivalents. (hello -> h3ll0) - * - * You are encouraged to edit & recompile this file if you want to edit - * the substitution rules. + * replaced with their leet equivalents (hello -> h3ll0), as determined + * by nleet, or, alternatively, as specified by the user. * * * * * * * * * * @@ -34,7 +31,7 @@ #include <errno.h> #include <string.h> -#define VERSION "v1.3.2" +#define VERSION "v1.4.0" #define BUFFER_SIZE 256 @@ -46,8 +43,8 @@ help(char *exename) "-h print this panel & exit\n" "-v print current version & exit\n\n" - "Usage: cat [FILENAME] | %s\n" - " %s [FILENAME]\n", + "Usage: cat [FILENAME] | %s [OPTIONS]\n" + " %s [FILENAME] [OPTIONS]\n", VERSION, exename, exename); exit(EXIT_SUCCESS); } @@ -81,33 +78,19 @@ print_only(FILE *f) } static void -leetify(FILE *f, int full_upper) +leetify(FILE *f, char a[], char b[], int len) { char buffer[BUFFER_SIZE]; while (fgets(buffer, sizeof(buffer), f) != NULL) { - int i; - - /* - * vv EDIT THIS PART vv - */ + int i, j; int npflag = 0; - for (i=0; i<=BUFFER_SIZE; i++) { - if (buffer[i] == 'a' || buffer[i] == 'A') { - buffer[i] = '@'; - npflag = 1; - } else if (buffer[i] == 'o' || buffer[i] == 'O') { - buffer[i] = '0'; - npflag = 1; - } else if (buffer[i] == 'i' || buffer[i] == 'I') { - buffer[i] = '1'; - npflag = 1; - } else if (buffer[i] == 'e' || buffer[i] == 'E') { - buffer[i] = '3'; - npflag = 1; - /* } else if (buffer[i] == 't' || buffer[i] == 'T') { - * buffer[i] = '7'; - * npflag = 1; */ + for (i = 0; i < BUFFER_SIZE; i++) { + for (j = 0; j < len; j++) { + if (buffer[i] == a[j]) { + npflag = 1; + buffer[i] = b[j]; + } } } @@ -118,14 +101,23 @@ leetify(FILE *f, int full_upper) void main(int argc, char* argv[]) { - int full_upper, file = 0, i; - for (i=0; i<argc; i++) { - if (strcmp(argv[i],"-v")==0) + int file = 0, args = 0, j = 0; + char a[100], b[100]; + for (int i = 0; i < argc; i++) { + if (strcmp(argv[i],"-v") == 0) { die(VERSION); - else if (strcmp(argv[i],"-h")==0) + } else if (strcmp(argv[i], "-h") == 0) { help(argv[0]); - else - file = i; + } else { + if (strlen(argv[i]) == 3 && i<100) { + args = 1; + a[j] = argv[i][0]; + b[j] = argv[i][2]; + j++; + } else { + file = i; + } + } } FILE *f2; @@ -145,11 +137,12 @@ main(int argc, char* argv[]) rewind(f2); print_only(f2); rewind(f2); - leetify(f2,0); - - if (full_upper == 1) { - rewind(f2); - leetify(f2,1); + if (args == 1) { + leetify(f2, a, b, j); + } else { + char c[4] = {'a', 'e', 'i', 'o'}; + char d[4] = {'@', '3', '1', '0'}; + leetify(f2, c, d, 4); } fclose(f2);