commit 46e27e9ab6b642fc1ac57cda2e7eacb43956ee24
parent 941edcb2fd8369e4a60c2e7e32087e500706f600
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Sat, 11 Sep 2021 20:47:06 +0200
reimplement transpose in C
Diffstat:
5 files changed, 11 insertions(+), 31 deletions(-)
diff --git a/Makefile b/Makefile
@@ -14,10 +14,10 @@ BIN =\
min\
rangetest\
sum\
+ transpose\
SCRIPTS =\
histpdf\
- transpose\
SRC =\
util.c
@@ -55,6 +55,7 @@ mean: mean.o
min: min.o
rangetest: rangetest.o
sum: sum.o
+transpose: transpose.o
${BIN}: ${LIB} ${OBJ}
${CC} ${_LDFLAGS} -o $@ ${@:=.o} ${OBJ}
@@ -65,7 +66,7 @@ ${BIN}: ${LIB} ${OBJ}
install:
# installing executable files and scripts.
mkdir -p "${DESTDIR}${PREFIX}/bin"
- cp -f ${SCRIPTS} "${DESTDIR}${PREFIX}/bin"
+ cp -f ${BIN} ${SCRIPTS} "${DESTDIR}${PREFIX}/bin"
for f in ${BIN} ${SCRIPTS}; do chmod 755 "${DESTDIR}${PREFIX}/bin/$$f"; done
# installing documentation files.
mkdir -p "${DESTDIR}${DOCPREFIX}"
diff --git a/transpose b/transpose
@@ -1,15 +0,0 @@
-#!/usr/bin/awk -f
-{
- for (i = 1; i <= NF; i++)
- d[NR][i] = $i
-}
-END {
- for (i = 1; i <= NF; i++) {
- for (j = 1; j <= NR; j++) {
- printf("%s", d[j][i])
- if (j < NR)
- printf("\t")
- }
- printf("\n")
- }
-}
diff --git a/transpose.1 b/transpose.1
@@ -6,20 +6,13 @@
.Nd interchanges the row and column positions for each field
.Sh SYNOPSIS
.Nm
-.Op Ar
.Sh DESCRIPTION
.Nm
-flips the rows and columns, effectively transposing it around the
-diagonal axis.
-This means that an input file with N colums and M rows is output as M
-colums and N rows.
-The input is
-.Ar file
-or standard input, if no
-.Ar file
-is given.
+flips the rows and columns of a matrix given by standard input,
+effectively transposing it around the diagonal axis.
+This means that an input file with N colums and M rows is output
+as M colums and N rows.
.Sh SEE ALSO
-.Xr awk 1 ,
.Xr max 1 ,
.Xr mean 1 ,
.Xr min 1 ,
diff --git a/util.c b/util.c
@@ -1,9 +1,7 @@
#include <err.h>
#include <stdlib.h>
#include <stdio.h>
-
-#define DELIM '\t'
-#define DELIMSTR "\t"
+#include "util.h"
size_t
allocarr(double **arr, const char *str, size_t maxlen)
diff --git a/util.h b/util.h
@@ -8,6 +8,9 @@
#define unveil(p1, p2) 0
#endif
+#define DELIM '\t'
+#define DELIMSTR "\t"
+
#undef strlcpy
size_t strlcpy(char *dst, const char *src, size_t dsize);