commit b47726194f59bce87782af72faf9ad2f2edf1b34 Author: hollorol Date: Wed Jul 31 23:18:07 2024 +0200 initial commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..276bad5 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +j: main.c + gcc -pedantic -Wall -Wextra main.c -o j +install: j j.1 + cp j $(HOME)/.local/bin/ + cp j.1 $(HOME)/.local/man/man1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..c9a98c1 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +This is a simple program which can join lines from stdin. The program is +only 27 loc. I won\'t add features like pasting lines inside of a file. +You can do everything just using stdin/stdout. Another advantage of this +simple implementation that it does not use heap, only stack. This +reduces the chance of getting corrupted memory. Althought This program +provides better defaults (coma is the default separator), we sacrifice +the speed for input containing many line. For that purpoce: use paste +-sd, diff --git a/j b/j new file mode 100755 index 0000000..187dcc3 Binary files /dev/null and b/j differ diff --git a/j.1 b/j.1 new file mode 100644 index 0000000..4f0504e --- /dev/null +++ b/j.1 @@ -0,0 +1,15 @@ +.Dd 2021-Jul-04 01:22:05 PM CEST +.Dt j 1 +.Os +.Sh NAME +.Nm j +.Nd A simple joiner program, even more simple than paste +.Sh SYNOPSIS +.Nm +.Op Ar separator +.Sh DESCRIPTION +.Nm +This is a simple program which can join lines from stdin. The program is only 27 loc. I won't add features like pasting lines inside of a file. You can do everything just using stdin/stdout. Another advantage of this simple implementation that it does not use heap, only stack. This reduces the chance of getting corrupted memory. Althought This program provides better defaults (coma is the default separator), We sacrifice the speed for input containing many line. For that purpoce: use paste -sd, + +.Sh AUTHOR +.An Roland Hollós Aq Mt hollorol@rolandhollos.xyz diff --git a/main.c b/main.c new file mode 100644 index 0000000..2e77a05 --- /dev/null +++ b/main.c @@ -0,0 +1,27 @@ +#include +#include +#include + +#define MAX_LINE_LENGTH 200 + +int main(int argc, char** argv){ + char sep = ','; + if(argc > 1){ + sep = argv[1][0]; + } + + char line[MAX_LINE_LENGTH]; + fgets(line,MAX_LINE_LENGTH, stdin); + line[strlen(line)-1] = '\0'; + printf("%s",line); + + while(fgets(line,MAX_LINE_LENGTH, stdin) != NULL){ + line[strlen(line)-1] = '\0'; + printf("%c%s",sep,line); + } + + printf("\n"); + + + return 0; +}