first implementation of “print -c” for columnising, currently hardcoded newlines
This commit is contained in:
4
edit.c
4
edit.c
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#ifndef MKSH_NO_CMDLINE_EDITING
|
#ifndef MKSH_NO_CMDLINE_EDITING
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.307 2016/09/01 12:59:08 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.308 2016/11/11 19:59:37 tg Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* in later versions we might use libtermcap for this, but since external
|
* in later versions we might use libtermcap for this, but since external
|
||||||
@ -271,7 +271,7 @@ x_print_expansions(int nwords, char * const *words, bool is_command)
|
|||||||
*/
|
*/
|
||||||
x_putc('\r');
|
x_putc('\r');
|
||||||
x_putc('\n');
|
x_putc('\n');
|
||||||
pr_list(use_copy ? (char **)XPptrv(l) : words);
|
pr_list(shl_out, use_copy ? (char **)XPptrv(l) : words);
|
||||||
|
|
||||||
if (use_copy)
|
if (use_copy)
|
||||||
/* not x_free_words() */
|
/* not x_free_words() */
|
||||||
|
6
exec.c
6
exec.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.182 2016/10/02 22:21:46 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.183 2016/11/11 19:59:39 tg Exp $");
|
||||||
|
|
||||||
#ifndef MKSH_DEFAULT_EXECSHELL
|
#ifndef MKSH_DEFAULT_EXECSHELL
|
||||||
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
|
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
|
||||||
@ -1696,7 +1696,7 @@ plain_fmt_entry(char *buf, size_t buflen, unsigned int i, const void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pr_list(char * const *ap)
|
pr_list(struct shf *shf, char * const *ap)
|
||||||
{
|
{
|
||||||
size_t acols = 0, aocts = 0, i;
|
size_t acols = 0, aocts = 0, i;
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
@ -1711,7 +1711,7 @@ pr_list(char * const *ap)
|
|||||||
acols = i;
|
acols = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
print_columns(shl_out, n, plain_fmt_entry, (const void *)ap,
|
print_columns(shf, n, plain_fmt_entry, (const void *)ap,
|
||||||
aocts, acols, false);
|
aocts, acols, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
42
funcs.c
42
funcs.c
@ -38,7 +38,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.312 2016/11/11 19:18:40 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.313 2016/11/11 19:59:39 tg Exp $");
|
||||||
|
|
||||||
#if HAVE_KILLPG
|
#if HAVE_KILLPG
|
||||||
/*
|
/*
|
||||||
@ -284,6 +284,7 @@ c_print(const char **wp)
|
|||||||
const char *s;
|
const char *s;
|
||||||
char *xp;
|
char *xp;
|
||||||
XString xs;
|
XString xs;
|
||||||
|
XPtrV words;
|
||||||
struct {
|
struct {
|
||||||
/* temporary storage for a wide character */
|
/* temporary storage for a wide character */
|
||||||
mksh_ari_t wc;
|
mksh_ari_t wc;
|
||||||
@ -297,6 +298,8 @@ c_print(const char **wp)
|
|||||||
char nl;
|
char nl;
|
||||||
/* expand backslash sequences? */
|
/* expand backslash sequences? */
|
||||||
bool exp;
|
bool exp;
|
||||||
|
/* columnise output? */
|
||||||
|
bool col;
|
||||||
/* print to history instead of file descriptor / stdout? */
|
/* print to history instead of file descriptor / stdout? */
|
||||||
bool hist;
|
bool hist;
|
||||||
/* print words as wide characters? */
|
/* print words as wide characters? */
|
||||||
@ -312,6 +315,7 @@ c_print(const char **wp)
|
|||||||
po.ws = ' ';
|
po.ws = ' ';
|
||||||
po.nl = '\n';
|
po.nl = '\n';
|
||||||
po.exp = true;
|
po.exp = true;
|
||||||
|
po.col = false;
|
||||||
po.hist = false;
|
po.hist = false;
|
||||||
po.chars = false;
|
po.chars = false;
|
||||||
|
|
||||||
@ -379,7 +383,7 @@ c_print(const char **wp)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* "print" builtin */
|
/* "print" builtin */
|
||||||
const char *opts = "AlNnpRrsu,";
|
const char *opts = "AclNnpRrsu,";
|
||||||
const char *emsg;
|
const char *emsg;
|
||||||
|
|
||||||
po.pminusminus = false;
|
po.pminusminus = false;
|
||||||
@ -389,6 +393,9 @@ c_print(const char **wp)
|
|||||||
case 'A':
|
case 'A':
|
||||||
po.chars = true;
|
po.chars = true;
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
po.col = true;
|
||||||
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
po.exp = true;
|
po.exp = true;
|
||||||
break;
|
break;
|
||||||
@ -446,6 +453,8 @@ c_print(const char **wp)
|
|||||||
|
|
||||||
if (*wp == NULL)
|
if (*wp == NULL)
|
||||||
goto print_no_arg;
|
goto print_no_arg;
|
||||||
|
if (po.col)
|
||||||
|
XPinit(words, 16);
|
||||||
print_read_arg:
|
print_read_arg:
|
||||||
if (po.chars) {
|
if (po.chars) {
|
||||||
while (*wp != NULL) {
|
while (*wp != NULL) {
|
||||||
@ -499,10 +508,37 @@ c_print(const char **wp)
|
|||||||
Xput(xs, xp, c);
|
Xput(xs, xp, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (po.col) {
|
||||||
|
Xput(xs, xp, '\0');
|
||||||
|
XPput(words, Xclose(xs, xp));
|
||||||
|
Xinit(xs, xp, 128, ATEMP);
|
||||||
|
}
|
||||||
if (*wp != NULL) {
|
if (*wp != NULL) {
|
||||||
Xput(xs, xp, po.ws);
|
if (!po.col)
|
||||||
|
Xput(xs, xp, po.ws);
|
||||||
goto print_read_arg;
|
goto print_read_arg;
|
||||||
}
|
}
|
||||||
|
if (po.col) {
|
||||||
|
size_t w = XPsize(words);
|
||||||
|
char *cp;
|
||||||
|
struct shf shf;
|
||||||
|
|
||||||
|
shf_sopen(NULL, 128, SHF_WR | SHF_DYNAMIC, &shf);
|
||||||
|
XPput(words, NULL);
|
||||||
|
pr_list(&shf, (char **)XPptrv(words));
|
||||||
|
while (w--)
|
||||||
|
afree(XPptrv(words)[w], ATEMP);
|
||||||
|
XPfree(words);
|
||||||
|
cp = shf_sclose(&shf);
|
||||||
|
w = strlen(cp);
|
||||||
|
|
||||||
|
XcheckN(xs, xp, w);
|
||||||
|
memcpy(xp, cp, w);
|
||||||
|
xp += w;
|
||||||
|
afree(cp, ATEMP);
|
||||||
|
|
||||||
|
po.nl = '!'; /* for now */
|
||||||
|
}
|
||||||
print_no_arg:
|
print_no_arg:
|
||||||
if (po.nl != '!')
|
if (po.nl != '!')
|
||||||
Xput(xs, xp, po.nl);
|
Xput(xs, xp, po.nl);
|
||||||
|
Reference in New Issue
Block a user