[hackers] [sbase] Rename mc(1) to cols(1) || sin

From: <git_AT_suckless.org>
Date: Wed, 12 Mar 2014 15:47:53 +0100

commit bc0de5e7e541a6fc45774ac3a03248c2a533f9cf
Author: sin <sin_AT_2f39.org>
Date: Wed Mar 12 16:43:45 2014 +0200

    Rename mc(1) to cols(1)
    
    There is an obvious name collision with the popular file manager
    midnight commander.

diff --git a/Makefile b/Makefile
index 9aa8723..ceed44f 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -36,6 +36,7 @@ SRC = \
         chroot.c \
         cksum.c \
         cmp.c \
+ cols.c \
         comm.c \
         cp.c \
         cut.c \
_AT_@ -53,7 +54,6 @@ SRC = \
         kill.c \
         ln.c \
         ls.c \
- mc.c \
         md5sum.c \
         mkdir.c \
         mkfifo.c \
diff --git a/cols.1 b/cols.1
new file mode 100644
index 0000000..8f15cb3
--- /dev/null
+++ b/cols.1
_AT_@ -0,0 +1,35 @@
+.TH COLS 1 sbase\-VERSION
+.SH NAME
+cols \- columnize output
+.SH SYNOPSIS
+.B cols
+.RB [ \-c
+.IR chars ]
+.RI [ file ...]
+.SH DESCRIPTION
+.B cols
+reads each file in sequence and writes them to stdout,
+in as many vertical columns as will fit in
+.I chars
+character columns.
+If no file is given, cols reads from stdin.
+.SH OPTIONS
+.TP
+.BI \-c " chars"
+specifies the maximum number of character columns to use
+(unless the input contains lines longer than
+.I chars
+characters). By default cols tries to figure out the width
+of the output device, if that fails it defaults to 65
+chars.
+.SH BUGS
+This implementation of
+.B cols
+assumes that every byte is a character
+which takes up one column on the screen.
+It does not handle non-ASCII UTF-8 runes
+or TAB characters correctly.
+.B cols
+currently mangles files which contain embedded NULs.
+.B cols
+does not allow the user to set a default width in its environment.
diff --git a/cols.c b/cols.c
new file mode 100644
index 0000000..411ce58
--- /dev/null
+++ b/cols.c
_AT_@ -0,0 +1,96 @@
+/* See LICENSE file for copyright and license details. */
+#include <assert.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include "text.h"
+#include "util.h"
+
+static long chars = 65;
+static int cflag;
+static struct linebuf b = EMPTY_LINEBUF;
+
+static long n_columns;
+static long n_rows;
+
+static void
+usage(void)
+{
+ eprintf("usage: %s [-c chars] [FILE...]
", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+ long i, l, col;
+ size_t maxlen = 0;
+ char *space;
+ struct winsize w;
+ FILE *fp;
+
+ ARGBEGIN {
+ case 'c':
+ cflag = 1;
+ chars = estrtol(EARGF(usage()), 0);
+ if(chars < 3)
+ eprintf("%d: too few character columns");
+ break;
+ default:
+ usage();
+ } ARGEND;
+
+ if (cflag == 0) {
+ ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
+ if (w.ws_col != 0)
+ chars = w.ws_col;
+ }
+
+ /* XXX librarify this chunk, too? only useful in sponges though */
+ if(argc == 0) {
+ getlines(stdin, &b);
+ } else for(; argc > 0; argc--, argv++) {
+ if(!(fp = fopen(argv[0], "r")))
+ eprintf("fopen %s:", argv[0]);
+ getlines(fp, &b);
+ fclose(fp);
+ }
+
+ for(l = 0; l < b.nlines; ++l) {
+ size_t len = strlen(b.lines[l]);
+ if(len > 0 && b.lines[l][len-1] == '
')
+ b.lines[l][--len] = '
Received on Wed Mar 12 2014 - 15:47:53 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 12 2014 - 15:48:33 CET