aboutsummaryrefslogtreecommitdiff
path: root/system/csvutils
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2022-01-26 14:04:52 -0500
committerWilly Sudiarto Raharjo <willysr@slackbuilds.org>2022-01-30 08:36:00 +0700
commitb5e76f14590bd2128436521f7c44a1100e6fb02a (patch)
tree7cc3c6b488382cf4540ae5050e4fdc759710fde0 /system/csvutils
parentb7da3c85f01bcadeb607f48b3d9e73bef9539c4b (diff)
system/csvutils: Added (inspect/manipulate CSV data).
Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
Diffstat (limited to 'system/csvutils')
-rw-r--r--system/csvutils/README16
-rw-r--r--system/csvutils/csvcheck_exit_status.diff51
-rw-r--r--system/csvutils/csvutils.SlackBuild99
-rw-r--r--system/csvutils/csvutils.info10
-rw-r--r--system/csvutils/fix_i_option.diff21
-rw-r--r--system/csvutils/git2tarxz.sh48
-rw-r--r--system/csvutils/slack-desc19
7 files changed, 264 insertions, 0 deletions
diff --git a/system/csvutils/README b/system/csvutils/README
new file mode 100644
index 000000000000..01c799a3431a
--- /dev/null
+++ b/system/csvutils/README
@@ -0,0 +1,16 @@
+csvutils (inspect and manipulate CSV data)
+
+csvutils is a set of command-line utilities that use libcsv to access
+comma (or actually, any delimiter) separated data files. Included
+programs:
+
+csvcount - print the number of fields and rows in CSV files.
+csvcheck - determine the validity of CSV data.
+csvfix - convert malformed CSV data into well formed data, and convert
+ to CSV data with different quotes and/or delimiters.
+csvgrep - search specific fields of CSV data for a pattern.
+csvcut - output only the specified fields of a CSV file.
+csvbreak - break a file into multiple pieces based on the value of the
+ specified field.
+
+Each utility has a man page.
diff --git a/system/csvutils/csvcheck_exit_status.diff b/system/csvutils/csvcheck_exit_status.diff
new file mode 100644
index 000000000000..df395e061fdf
--- /dev/null
+++ b/system/csvutils/csvcheck_exit_status.diff
@@ -0,0 +1,51 @@
+diff -Naur csvutils-0.9.3+20161218_e57951b/src/csvcheck.c csvutils-0.9.3+20161218_e57951b.patched/src/csvcheck.c
+--- csvutils-0.9.3+20161218_e57951b/src/csvcheck.c 2022-01-26 02:05:12.660602834 -0500
++++ csvutils-0.9.3+20161218_e57951b.patched/src/csvcheck.c 2022-01-26 02:33:11.553450216 -0500
+@@ -89,6 +89,8 @@
+ }
+ }
+
++int errcnt = 0;
++
+ void
+ check_file(char *filename)
+ {
+@@ -112,6 +114,7 @@
+ fp = fopen(filename, "rb");
+ if (fp == NULL) {
+ fprintf(stderr, "Failed to open file %s: %s\n", filename, strerror(errno));
++ errcnt++;
+ csv_free(&p);
+ return;
+ }
+@@ -121,18 +124,21 @@
+ if ((retval = csv_parse(&p, buf, bytes_read, NULL, NULL, NULL)) != bytes_read) {
+ if (csv_error(&p) == CSV_EPARSE) {
+ printf("%s: malformed at byte %lu\n", filename ? filename : "stdin", (unsigned long)pos + retval + 1);
++ errcnt++;
+ goto end;
+ } else {
+ printf("Error while processing %s: %s\n", filename ? filename : "stdin", csv_strerror(csv_error(&p)));
++ errcnt++;
+ goto end;
+ }
+ }
+ pos += 1024;
+ }
+
+- if (csv_fini(&p, NULL, NULL, NULL) != 0)
++ if (csv_fini(&p, NULL, NULL, NULL) != 0) {
+ printf("%s: missing closing quote at end of input\n", filename ? filename : "stdin");
+- else
++ errcnt++;
++ } else
+ printf("%s well-formed\n", filename ? filename : "data is");
+
+ end:
+@@ -186,5 +192,5 @@
+ check_file(NULL);
+ }
+
+- return EXIT_SUCCESS;
++ return (errcnt ? EXIT_FAILURE : EXIT_SUCCESS);
+ }
diff --git a/system/csvutils/csvutils.SlackBuild b/system/csvutils/csvutils.SlackBuild
new file mode 100644
index 000000000000..9df95d9f6ddd
--- /dev/null
+++ b/system/csvutils/csvutils.SlackBuild
@@ -0,0 +1,99 @@
+#!/bin/bash
+
+# Slackware build script for csvutils
+
+# Written by B. Watson (yalhcru@gmail.com)
+
+# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.
+
+cd $(dirname $0) ; CWD=$(pwd)
+
+PRGNAM=csvutils
+VERSION=${VERSION:-0.9.3+20161218_e57951b}
+BUILD=${BUILD:-1}
+TAG=${TAG:-_SBo}
+PKGTYPE=${PKGTYPE:-tgz}
+
+if [ -z "$ARCH" ]; then
+ case "$( uname -m )" in
+ i?86) ARCH=i586 ;;
+ arm*) ARCH=arm ;;
+ *) ARCH=$( uname -m ) ;;
+ esac
+fi
+
+if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
+ echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
+ exit 0
+fi
+
+TMP=${TMP:-/tmp/SBo}
+PKG=$TMP/package-$PRGNAM
+OUTPUT=${OUTPUT:-/tmp}
+
+if [ "$ARCH" = "i586" ]; then
+ SLKCFLAGS="-O2 -march=i586 -mtune=i686"
+ LIBDIRSUFFIX=""
+elif [ "$ARCH" = "i686" ]; then
+ SLKCFLAGS="-O2 -march=i686 -mtune=i686"
+ LIBDIRSUFFIX=""
+elif [ "$ARCH" = "x86_64" ]; then
+ SLKCFLAGS="-O2 -fPIC"
+ LIBDIRSUFFIX="64"
+else
+ SLKCFLAGS="-O2"
+ LIBDIRSUFFIX=""
+fi
+
+set -e
+
+rm -rf $PKG
+mkdir -p $TMP $PKG $OUTPUT
+cd $TMP
+rm -rf $PRGNAM-$VERSION
+tar xvf $CWD/$PRGNAM-$VERSION.tar.xz
+cd $PRGNAM-$VERSION
+chown -R root:root .
+find -L . -perm /111 -a \! -perm 755 -a -exec chmod 755 {} \+ -o \
+ \! -perm /111 -a \! -perm 644 -a -exec chmod 644 {} \+
+
+### Patches by SlackBuild author:
+
+# Fix the csvgrep -i option (which was broken for both POSIX and PCRE
+# regex matches, and only worked for fixed-string matches).
+patch -p1 < $CWD/fix_i_option.diff
+
+# Make csvcheck exit with nonzero status if any file failed the check.
+patch -p1 < $CWD/csvcheck_exit_status.diff
+
+# There's also a bug that makes cvsfix change this:
+# "broken,"bad","line"
+# to this:
+# "broken,""bad","line"
+# ...which csvcheck says is valid (which is another bug).
+# It should be:
+# "broken","bad","line"
+
+###
+
+make CPPFLAGS="$SLKCFLAGS -Wl,-s"
+
+# N.B. non-canonical use of DESTDIR and MANDIR.
+mkdir -p $PKG/usr/bin $PKG/usr/man/man1
+make install DESTDIR=$PKG/usr/bin MANDIR=$PKG/usr/man/man1
+
+# Amazingly, the man pages are already gzipped. Might be a first.
+# Annoyingly, they're distributed gzipped, so I didn't patch them for
+# typos (of which there are a few).
+
+# pdf/*.pdf are just PDF copies of the man pages, don't install.
+PKGDOC=$PKG/usr/doc/$PRGNAM-$VERSION
+mkdir -p $PKGDOC
+cp -a Changelog LICENSE README $PKGDOC
+cat $CWD/$PRGNAM.SlackBuild > $PKGDOC/$PRGNAM.SlackBuild
+
+mkdir -p $PKG/install
+cat $CWD/slack-desc > $PKG/install/slack-desc
+
+cd $PKG
+/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
diff --git a/system/csvutils/csvutils.info b/system/csvutils/csvutils.info
new file mode 100644
index 000000000000..baf19c775f23
--- /dev/null
+++ b/system/csvutils/csvutils.info
@@ -0,0 +1,10 @@
+PRGNAM="csvutils"
+VERSION="0.9.3+20161218_e57951b"
+HOMEPAGE="https://sourceforge.net/projects/csvutils/"
+DOWNLOAD="https://slackware.uk/~urchlay/src/csvutils-0.9.3+20161218_e57951b.tar.xz"
+MD5SUM="f312aa2c65db7b4ba45a3037c7a90be2"
+DOWNLOAD_x86_64=""
+MD5SUM_x86_64=""
+REQUIRES="libcsv"
+MAINTAINER="B. Watson"
+EMAIL="yalhcru@gmail.com"
diff --git a/system/csvutils/fix_i_option.diff b/system/csvutils/fix_i_option.diff
new file mode 100644
index 000000000000..b00c56904f4f
--- /dev/null
+++ b/system/csvutils/fix_i_option.diff
@@ -0,0 +1,21 @@
+diff -Naur csvutils-0.9.3+20161218_e57951b/src/csvgrep.c csvutils-0.9.3+20161218_e57951b.patched/src/csvgrep.c
+--- csvutils-0.9.3+20161218_e57951b/src/csvgrep.c 2022-01-26 02:05:12.660602834 -0500
++++ csvutils-0.9.3+20161218_e57951b.patched/src/csvgrep.c 2022-01-26 02:22:34.393508136 -0500
+@@ -788,7 +788,7 @@
+ #ifdef WITHOUT_PCRE
+ err("not compiled with pcre support");
+ #else
+- re = pcre_compile(pattern, 0, &err_ptr, &rv, NULL);
++ re = pcre_compile(pattern, (ignore_case ? PCRE_CASELESS : 0), &err_ptr, &rv, NULL);
+ if (rv) {
+ fprintf(stderr, "Error parsing pattern expression: %s\n", err_ptr);
+ exit(EXIT_FAILURE);
+@@ -798,7 +798,7 @@
+ #ifdef WITHOUT_POSIX
+ err("not compiled with posix support");
+ #else
+- if ((rv = regcomp(&preg, pattern, REG_EXTENDED | REG_NOSUB )) != 0) {
++ if ((rv = regcomp(&preg, pattern, REG_EXTENDED | REG_NOSUB | (ignore_case ? REG_ICASE : 0))) != 0) {
+ regerror(rv, &preg, errbuf, sizeof errbuf);
+ fprintf(stderr, "Error parsing pattern expression: %s\n", errbuf);
+ exit(EXIT_FAILURE);
diff --git a/system/csvutils/git2tarxz.sh b/system/csvutils/git2tarxz.sh
new file mode 100644
index 000000000000..10c1aa690970
--- /dev/null
+++ b/system/csvutils/git2tarxz.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+# Create source tarball from git repo, with generated version
+# number.
+
+# Note that this script doesn't need to be run as root. It does
+# need to be able to write to the current directory it's run from.
+
+# Takes one optional argument, which is the commit or tag to create
+# a tarball of. With no arg, HEAD is used.
+
+PRGNAM=csvutils
+CLONE_URL=https://github.com/rgamble/csvutils
+
+# upstream doesn't use tags. csvutils was moved to github after
+# this release.
+OLDVER=0.9.3
+
+set -e
+
+GITDIR=$( mktemp -dt $PRGNAM.git.XXXXXX )
+rm -rf $GITDIR
+git clone $CLONE_URL $GITDIR
+
+CWD="$( pwd )"
+cd $GITDIR
+
+if [ "$1" != "" ]; then
+ git reset --hard "$1" || exit 1
+fi
+
+GIT_SHA=$( git rev-parse --short HEAD )
+
+DATE=$( git log --date=format:%Y%m%d --format=%cd | head -1 )
+
+VERSION=$OLDVER+${DATE}_${GIT_SHA}
+
+rm -rf .git
+find . -name .gitignore -print0 | xargs -0 rm -f
+
+cd "$CWD"
+rm -rf $PRGNAM-$VERSION $PRGNAM-$VERSION.tar.xz
+mv $GITDIR $PRGNAM-$VERSION
+tar cvfJ $PRGNAM-$VERSION.tar.xz $PRGNAM-$VERSION
+
+echo
+echo "Created tarball: $PRGNAM-$VERSION.tar.xz"
+echo "VERSION=$VERSION"
diff --git a/system/csvutils/slack-desc b/system/csvutils/slack-desc
new file mode 100644
index 000000000000..df7f28db3ec9
--- /dev/null
+++ b/system/csvutils/slack-desc
@@ -0,0 +1,19 @@
+# HOW TO EDIT THIS FILE:
+# The "handy ruler" below makes it easier to edit a package description.
+# Line up the first '|' above the ':' following the base package name, and
+# the '|' on the right side marks the last column you can put a character in.
+# You must make exactly 11 lines for the formatting to be correct. It's also
+# customary to leave one space after the ':' except on otherwise blank lines.
+
+ |-----handy-ruler------------------------------------------------------|
+csvutils: csvutils (inspect and manipulate CSV data)
+csvutils:
+csvutils: csvutils is a set of command-line utilities that use libcsv to access
+csvutils: comma (or actually, any delimiter) separated data files. Included
+csvutils: programs: csvcount, csvcheck, csvfix, csvgrep, csvcut, csvbreak.
+csvutils:
+csvutils:
+csvutils:
+csvutils:
+csvutils:
+csvutils: