чување cb27e4a24dc3a613de78dffda843f8c69e44be36
родитељ 13d6a073f58a1834e770d528b5efcfedf9104d9c
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Tue, 4 Apr 2023 16:56:02 +0200
CHANGES,tablep,tsvtable: Remove file; install.do: Turn tsvtable and tablep indo symlinks, install README and examples into DOCDIR; table.c: Add -p
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 7, додавања: 67(+), брисања: 73(-)
diff --git a/CHANGES b/CHANGES
@@ -1,55 +0,0 @@
- Changelog
- =========
-* v0.3
-
- - Removed libunistring as a dependency
-
-
-* v0.2.2
-
- - Optimizations and bugfixes
- - Added description how to configure table as a viewer for GNU MC
- - Added the --msdos option
- - Changed URLs to sourcehut
-
-
-* v0.2.1
-
- - Added format support
-
-
-* v0.2
-
- - Switched to apenwarr/redo
-
- - Core code rewrite. Prevented leaks with valgrind
-
- - New examples directory, updated scripts in tests
-
- - Updated manpage
-
-
-* v0.1.2-beta
-
- - Add --border-mode
-
- - Fix last row in ls -mw30 | table when last input line has only one
- column
-
-
-* v0.1.1-beta
-
- - Ignore malformed UTF-8 sequences. Segmentation faulted
- (test/who-Huw.sh with LC_ALL=sr_RS.UTF8 and cyrillic user names)
-
- - Use "T" connector chars; connector selection similar to -s
-
-
-* v0.1-alpha
-
- - Read and display columns
-
- - Handle tabs - unwrap to spaces at tab stops (test/lsb_release.sh)
-
- - Better UTF-8 substring code based on screen columns
-
diff --git a/install.do b/install.do
@@ -1,11 +1,16 @@
redo-ifchange all
PREFIX=${PREFIX:-/usr/local}
BINDIR=$PREFIX/bin
-#DOCDIR=$PREFIX/share/doc/table
+DOCDIR=$PREFIX/share/doc/table
MANDIR=$PREFIX/share/man/man1
-#install -d $DOCDIR
-for executable in table tablep tsvtable; do
+install -d $DOCDIR
+for executable in table; do
install -Dm 0755 "${executable}" "${BINDIR}/${executable}"
done
-#install -Dm 0644 table.pdf "${DOCDIR}/table.pdf"
+for synonym in tablep tsvtable; do
+ ln -sf table "${BINDIR}/${synonym}"
+done
+for docfile in README $(find examples -type f); do
+ install -Dm 0644 "${docfile}" "${DOCDIR}/${docfile}"
+done
install -Dm 0644 table.1.gz "${MANDIR}/table.1.gz"
diff --git a/table.1.in b/table.1.in
@@ -18,6 +18,15 @@
.SH NAME
table \- Command line utility to format and display CSV.
.
+.SH COMMAND ALIASES
+.B tablep
+is a synonym for
+.BR "table -p" .
+.br
+.B tsvtable
+is a synonym for
+.BR "table -d \(dq$(printf '\et')\(dq" .
+.
.SH SYNOPSIS
.
.SY table
@@ -35,6 +44,7 @@ table \- Command line utility to format and display CSV.
.OP "\-f \fR|\fP \-\-format=" format
.OP "\-m \fR|\fP \-\-msdos"
.OP "\-n \fR|\fP \-\-no\-ansi"
+.OP "\-p \fR|\fP \-\-pause"
.OP "\-s \fR|\fP \-\-symbols=" set
.OP "\-t \fR|\fP \-\-expand-tabs"
.YS
@@ -145,6 +155,17 @@ codes in the output. By default, the header row is printed in bold using
codes. This switch prevents that.
.
.TP
+.B \-p
+.TQ
+.B \-\-pause
+.br
+Presents the message "Press Enter to continue" and waits for input after
+outputting the table. This accounts for executing
+.B table
+from file managers which don't pause after executing programs or as a single
+command from terminal emulators.
+.
+.TP
.BI \-s " set"
.TQ
.BI \-\-symbols= set
diff --git a/table.c b/table.c
@@ -79,6 +79,7 @@ ULONG format_value = 0;
int border_mode = 0;
int handle_ansi = 1;
int msdos = 0;
+int pause = 0;
int expand_tabs = 0;
int
@@ -94,7 +95,7 @@ usage()
printf("Usage: %s [-b|--border-mode] [-c <cols>|--columns=<cols>] [-d"
" <delim>|--delimiter=<delim>] [-f <format>|--format=<format>]"
" [-h|--help] [-m|--msdos] [-n|--no-ansi]"
- " [-s <set>|--symbols=<set>] [-t|--expand-tabs] "
+ " [-p|--pause] [-s <set>|--symbols=<set>] [-t|--expand-tabs] "
"[-v|--version]\n",
PROGRAMNAME);
return 0;
@@ -364,6 +365,18 @@ main(int argc, char** argv)
char* arg;
Command cmd = CMD_NONE;
char* filename = NULL;
+ char* sep = NULL;
+ char* progname = NULL;
+
+ sep = strrchr(argv[0], '/');
+ progname = argv[0];
+ if (sep)
+ progname = sep + 1;
+
+ if (!strcmp(progname, "tsvtable"))
+ delimiter = L'\t';
+ else if (!strcmp(progname, "tablep"))
+ pause = 1;
do_arg:
arg = *++argv;
@@ -378,7 +391,7 @@ do_arg:
{
if (!strcmp(arg, "version"))
cmd = CMD_VERSION;
- else if (startswith(arg, "border-mode"))
+ else if (!strcmp(arg, "border-mode"))
{
arg += strlen("border-mode");
border_mode = 1;
@@ -401,7 +414,7 @@ do_arg:
"'%s'",
arg);
}
- else if (startswith(arg, "expand-tabs"))
+ else if (!strcmp(arg, "expand-tabs"))
{
arg += strlen("expand-tabs");
expand_tabs = 1;
@@ -411,16 +424,21 @@ do_arg:
arg += strlen("format=");
set_format(arg, &format, &format_size);
}
- else if (startswith(arg, "msdos"))
+ else if (!strcmp(arg, "msdos"))
{
arg += strlen("msdos");
msdos = 1;
}
- else if (startswith(arg, "no-ansi"))
+ else if (!strcmp(arg, "no-ansi"))
{
arg += strlen("no-ansi");
handle_ansi = 0;
}
+ else if (!strcmp(arg, "pause"))
+ {
+ arg += strlen("pause");
+ pause = 1;
+ }
else if (startswith(arg, "symbols="))
{
arg += strlen("symbols=");
@@ -464,6 +482,9 @@ do_arg:
case 'n':
handle_ansi = 0;
break;
+ case 'p':
+ pause = 1;
+ break;
case 's':
cmd = CMD_SYMBOLS;
break;
@@ -835,7 +856,6 @@ done_line:;
goto do_input;
done_input:
- fclose(input);
free(line);
/* Bottom border */
@@ -897,5 +917,14 @@ done_input:
free(format);
+ if (pause)
+ {
+ char buf[BUFSIZE];
+ printf("Press Enter to continue\n");
+ clearerr(stdin);
+ fgets(buf, BUFSIZE, stdin);
+ }
+ fclose(input);
+
return 0;
}
diff --git a/tablep b/tablep
@@ -1,4 +0,0 @@
-#!/bin/sh
-table "$@"
-printf "Press Enter to continue... "
-read line
diff --git a/tsvtable b/tsvtable
@@ -1,2 +0,0 @@
-#!/bin/sh
-table -d "$(printf '\t')" "$@"
diff --git a/uninstall.do b/uninstall.do
@@ -1,7 +1,7 @@
redo-always
-PREFIX=/usr/local
+PREFIX=${PREFIX:-/usr/local}
BINDIR=$PREFIX/bin
DOCDIR=$PREFIX/share/doc/table
MANDIR=$PREFIX/share/man/man1
-rm -f $BINDIR/table $BINDIR/tablep $BINDIR/tsvtable $DOCDIR/table.pdf \
+rm -f $BINDIR/table $BINDIR/tablep $BINDIR/tsvtable $(find $DOCDIR -type f) \
$MANDIR/table.1.gz