commit 99ceb8895f9104a881f55619e39e8967522e6025
parent 073f34e08db480be82b2138e97e863cecab9144d
Author: Michael Constantine Dimopoulos <mk@mcdim.xyz>
Date: Tue, 12 Oct 2021 02:11:32 +0000
Added new tool: napp
Diffstat:
M | Makefile | | | 8 | ++++++-- |
A | app/napp.1 | | | 40 | ++++++++++++++++++++++++++++++++++++++++ |
A | app/napp.c | | | 183 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 229 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
@@ -10,17 +10,19 @@ MD=/usr/share/man/man1/
# $(CC) leet/nleet.c -o nleet
# $(CC) com/ncom.c -o ncom
-install: inc/nin.c enhance/nhan.c leet/nleet.c com/ncom.c clean/nclean.c rev/nrev.sh wiz/nwiz.sh inc/ninc.1 enhance/nhance.1 rev/nrev.1 leet/nleet.1 com/ncom.1 clean/nclean.1
+install: inc/nin.c enhance/nhan.c leet/nleet.c com/ncom.c clean/nclean.c app/napp.c rev/nrev.sh wiz/nwiz.sh inc/ninc.1 enhance/nhance.1 rev/nrev.1 leet/nleet.1 com/ncom.1 clean/nclean.1 app/napp.1
$(CC) enhance/nhan.c -o nhance
$(CC) inc/nin.c -o ninc
$(CC) leet/nleet.c -o nleet
$(CC) com/ncom.c -o ncom
$(CC) clean/nclean.c -o nclean
+ $(CC) app/napp.c -o napp
sudo mv nhance /bin
sudo mv ninc /bin
sudo mv nleet /bin
sudo mv ncom /bin
sudo mv nclean /bin
+ sudo mv napp /bin
sudo cp rev/nrev.sh /bin/nrev
sudo cp wiz/nwiz.sh /bin/nwiz
mkdir -p /var/lib/narthex/
@@ -30,15 +32,17 @@ install: inc/nin.c enhance/nhan.c leet/nleet.c com/ncom.c clean/nclean.c rev/nre
sudo cp leet/nleet.1 $(MD)
sudo cp com/ncom.1 $(MD)
sudo cp clean/nclean.1 $(MD)
+ sudo cp app/napp.1 $(MD)
sudo cp rev/nrev.1 $(MD)
sudo mandb
-uninstall: /bin/ninc /bin/nhance /bin/nrev /bin/nleet /bin/ncom /bin/nclean /bin/nwiz $(MD)ninc.1 $(MD)nhance.1 $(MD)nrev.1 $(MD)nleet.1 $(MD)ncom.1 $(MD)nclean.1
+uninstall: /bin/ninc /bin/nhance /bin/nrev /bin/nleet /bin/ncom /bin/nclean /bin/napp /bin/nwiz $(MD)ninc.1 $(MD)nhance.1 $(MD)nrev.1 $(MD)nleet.1 $(MD)ncom.1 $(MD)nclean.1 $(MD)napp.1
rm /bin/ninc $(MD)ninc.1
rm /bin/nhance $(MD)nhance.1
rm /bin/nleet $(MD)nleet.1
rm /bin/nrev $(MD)nrev.1
rm /bin/ncom $(MD)ncom.1
rm /bin/nclean $(MD)nclean.1
+ rm /bin/napp $(MD)napp.1
rm /bin/nwiz
rm -r /var/lib/narthex/
diff --git a/app/napp.1 b/app/napp.1
@@ -0,0 +1,40 @@
+.\" Manpage for napp
+
+.TH man 8 "10 Oct 2021" "1.0" "napp manual page"
+.SH NAME
+napp \- Narthex appender
+.SH SYNOPSIS
+cat dictionary.txt | napp [OPTIONS] > output.txt
+.SH DESCRIPTION
+napp appends extra symbols or words to the end of each line.
+
+.SH OPTIONS
+-c specify charset
+
+-w specify wordlist
+
+-s salt mode (do not print stdin as-is in the beginning)
+
+-f insert to the front of the line, instead of appending
+
+-v print version and exit
+
+-h print help panel and exit
+
+.SH EXAMPLES
+
+This will append the symbols separately to the end of each line of stdin, after printing stdin as-is, and directs the output to output.txt
+
+cat dict.txt | napp -c #@?& > output.txt
+
+The following will insert the words of the file2.txt (-w) before each line (-f) of file1.txt, without first printing the stdin as-is (-s), and redirects the output to output.txt
+
+cat file1.txt | napp -w file2.txt -f -s > output.txt
+
+.SH AUTHOR
+Michael Constantine Dimopoulos <mk@mcdim.xyz>
+
+https://mcdim.xyz
+
+.SH LICENSE
+GNU General Public License 3.0 (GPL-3.0)
diff --git a/app/napp.c b/app/napp.c
@@ -0,0 +1,183 @@
+/*
+ * napp - Narthex appender
+ *
+ * By Michael Constantine Dimopoulos
+ * https://mcdim.xyz <mk@mcdim.xyz>
+ * License: GNU GPL v3
+ *
+ * napp will append to the end of,
+ * or insert to the front of, each
+ * line of stdin, characters from a
+ * a specified character set, or
+ * words from a wordlist. It may or
+ * may not print stdin as is (-s)
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <ctype.h>
+
+#define VERSION "v1.0"
+#define BUFFER_SIZE 256
+
+static void
+usage(char *exename)
+{
+ fprintf(stderr, "Usage: cat [FILENAME]"
+ "| %s [-c] [CHARSET] [-w] [FILE] [-s] [-f]\n",
+ exename);
+}
+
+static void
+help(char * exename)
+{
+ printf( "napp - Narthex appender %s\n"
+ "By Michael C. Dim. <mk@mcdim.xyz>\n\n"
+
+ "-c specify charset\n"
+ "-w specify dictionary of words\n"
+ "-f insert before the word (default is after)\n"
+ "-s salt mode (do not print wordlist as is)\n"
+ "-h print this panel & exit\n"
+ "-v print current version & exit\n\n"
+
+ "Usage: cat [FILENAME] | %s [-c] [CHARSET] [-w] [FILE]"
+ "[-s] [-f]\n", VERSION, exename);
+ exit(EXIT_SUCCESS);
+}
+
+static void
+die(char * str)
+{
+ printf("%s\n", str);
+ exit(EXIT_SUCCESS);
+}
+
+FILE *
+save_stdin(FILE *f)
+{
+ FILE *f2 = tmpfile();
+ char buffer[BUFFER_SIZE];
+ while(fgets(buffer, sizeof(buffer), f) != NULL) {
+ fprintf(f2, "%s", buffer);
+ }
+ fclose(f);
+ return f2;
+}
+
+static void
+nappc(FILE *f, int front, char c)
+{
+ char buffer[BUFFER_SIZE];
+ while (fgets(buffer, sizeof(buffer), f) != NULL) {
+ strtok(buffer, "\n");
+ if (front)
+ printf("%c%s\n", c, buffer);
+ else
+ printf("%s%c\n", buffer, c);
+ }
+}
+
+static void
+nappw(FILE *f, int front, char *w)
+{
+ char buffer[BUFFER_SIZE];
+ while (fgets(buffer, sizeof(buffer), f) != NULL) {
+ strtok(buffer, "\n");
+ if (front)
+ printf("%s%s\n", w, buffer);
+ else
+ printf("%s%s\n", buffer, w);
+ }
+}
+
+static void
+print_only(FILE *f)
+{
+ char buffer[BUFFER_SIZE];
+ while(fgets(buffer, sizeof(buffer), f) != NULL) {
+ printf("%s",buffer);
+ }
+}
+
+void
+main(int argc, char * argv[])
+{
+ int c1=0, w=0, s=0, front=0;
+ char cv[BUFFER_SIZE], wv[BUFFER_SIZE];
+ int index;
+ int c;
+ extern char *optarg;
+ int optind = 0;
+
+ while ( (c = getopt(argc, argv, "c:w:sfvh")) != -1 ) {
+ switch (c) {
+ case 'v':
+ die(VERSION);
+ case 'h':
+ help(argv[0]);
+ case 'c':
+ c1=1;
+ w=0;
+ strncpy(cv, optarg, BUFFER_SIZE);
+ break;
+ case 'w':
+ w=1;
+ c1=0;
+ strncpy(wv, optarg, BUFFER_SIZE);
+ break;
+ case 's':
+ s=1;
+ break;
+ case 'f':
+ front=1;
+ break;
+ case '?':
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ break;
+ }
+ }
+
+ if (c1 == 1 || w == 1) {
+ FILE * f;
+ f = save_stdin(stdin);
+ rewind(f);
+ if (!s) {
+ print_only(f);
+ rewind(f);
+ }
+
+ if (w) {
+ FILE * f2;
+ f2 = fopen(wv,"r");
+
+ if (f2 == NULL) {
+ fprintf(stdout, "Error opening file\n");
+ exit(EXIT_FAILURE);
+ }
+
+ char word[BUFFER_SIZE];
+ while(fgets(word, sizeof(word), f2) != NULL) {
+ strtok(word, "\n");
+ nappw(f, front, word);
+ rewind(f);
+ }
+ }
+
+ if (c1) {
+ for (int i = 0; cv[i] != '\0'; i++) {
+ nappc(f, front, cv[i]);
+ rewind(f);
+ }
+ }
+ } else {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ exit(EXIT_SUCCESS);
+}