initial commit
This commit is contained in:
commit
b47726194f
5
Makefile
Normal file
5
Makefile
Normal 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
8
README.md
Normal 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,
|
||||
15
j.1
Normal file
15
j.1
Normal 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
27
main.c
Normal 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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user