initial commit

This commit is contained in:
hollorol 2024-07-31 23:18:07 +02:00
commit b47726194f
5 changed files with 55 additions and 0 deletions

5
Makefile Normal file
View File

@ -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

8
README.md Normal file
View File

@ -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,

BIN
j Executable file

Binary file not shown.

15
j.1 Normal file
View File

@ -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

27
main.c Normal file
View File

@ -0,0 +1,27 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#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;
}