diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2002-11-20 12:37:43 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2002-11-20 12:37:43 +0000 |
commit | bbbc5536da957313a7306892790fb34fdb2f96cc (patch) | |
tree | 569cbc2bf63089573c483e556b6a2a091f7eda34 | |
parent | e580d5d76782baa6862eb484e3e85bc5658e216f (diff) | |
download | zsh-bbbc5536da957313a7306892790fb34fdb2f96cc.tar.gz zsh-bbbc5536da957313a7306892790fb34fdb2f96cc.tar.xz zsh-bbbc5536da957313a7306892790fb34fdb2f96cc.zip |
17940: Add -C and -a options to print builtin
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Doc/Zsh/builtins.yo | 74 | ||||
-rw-r--r-- | Src/builtin.c | 74 |
3 files changed, 106 insertions, 48 deletions
diff --git a/ChangeLog b/ChangeLog index d232a669a..8aed52d94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2002-11-20 Peter Stephenson <pws@csr.com> + + * 17940: Src/builtin.c, Doc/Zsh/builtin.yo: print -C <cols> prints + given number of columns, -a with -c or -C prints arguments across + before down. + 2002-11-13 Clint Adams <clint@zsh.org> * 17935: Src/text.c: beautify bin_whence indentation of () diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 599a2bf9a..6bd0084df 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -655,7 +655,8 @@ If the tt(PUSHD_MINUS) option is set, the meanings of `tt(PLUS())' and `tt(-)' in this context are swapped. ) findex(print) -item(tt(print) [ tt(-bnrslzpNDPoOicm) ] [ tt(-u)var(n) ] [ tt(-f) var(format) ] [ tt(-R) [ tt(-en) ]] [ var(arg) ... ])( +xitem(tt(print) [ tt(-abcDilmnNoOpPrsz) ] [ tt(-u)var(n) ] [ tt(-f) var(format) ] [ tt(-C) var(cols) ]) +item( [ tt(-R) [ tt(-en) ]] [ var(arg) ... ])( With the `tt(-f)' option the arguments are printed as described by tt(printf). With no flags or with the flag `tt(-)', the arguments are printed on the standard output as described by tt(echo), with the following differences: @@ -667,14 +668,9 @@ Finally, if not in an escape sequence, `tt(\)' escapes the following character and is not printed. startitem() -item(tt(-r))( -Ignore the escape conventions of tt(echo). -) -item(tt(-R))( -Emulate the BSD tt(echo) command, which does not process escape sequences -unless the tt(-e) flag is given. The tt(-n) flag suppresses the trailing -newline. Only the tt(-e) and tt(-n) flags are recognized after -tt(-R); all other arguments and options are printed. +item(tt(-a))( +Print arguments with the column incrementing first. Only useful with the +tt(-c) and tt(-C) options. ) item(tt(-b))( Recognize all the escape sequences defined for the tt(bindkey) command, @@ -683,20 +679,33 @@ ifzman(zmanref(zshzle))\ ifnzman(noderef(Zle Builtins))\ . ) +item(tt(-c))( +Print the arguments in columns. Unless tt(-a) is also given, arguments are +printed with the row incrementing first. +) +item(tt(-C) var(cols))( +Print the arguments in var(cols) columns. Unless tt(-a) is also given, +arguments are printed with the row incrementing first. +) +item(tt(-D))( +Treat the arguments as directory names, replacing prefixes with tt(~) +expressions, as appropriate. +) +item(tt(-i))( +If given together with tt(-o) or tt(-O), sorting is performed +case-independently. +) +item(tt(-l))( +Print the arguments separated by newlines instead of spaces. +) item(tt(-m))( Take the first argument as a pattern (should be quoted), and remove it from the argument list together with subsequent arguments that do not match this pattern. ) -item(tt(-s))( -Place the results in the history list instead of on the standard output. -) item(tt(-n))( Do not add a newline to the output. ) -item(tt(-l))( -Print the arguments separated by newlines instead of spaces. -) item(tt(-N))( Print the arguments separated and terminated by nulls. ) @@ -706,32 +715,33 @@ Print the arguments sorted in ascending order. item(tt(-O))( Print the arguments sorted in descending order. ) -item(tt(-i))( -If given together with tt(-o) or tt(-O), sorting is performed -case-independently. -) -item(tt(-c))( -Print the arguments in columns. -) -item(tt(-u)var(n))( -Print the arguments to file descriptor var(n). -) item(tt(-p))( Print the arguments to the input of the coprocess. ) -item(tt(-z))( -Push the arguments onto the editing buffer stack, separated by spaces. -) -item(tt(-D))( -Treat the arguments as directory names, replacing prefixes with tt(~) -expressions, as appropriate. -) item(tt(-P))( Perform prompt expansion (see ifzman(zmanref(zshmisc))\ ifnzman(noderef(Prompt Expansion))\ ). ) +item(tt(-r))( +Ignore the escape conventions of tt(echo). +) +item(tt(-R))( +Emulate the BSD tt(echo) command, which does not process escape sequences +unless the tt(-e) flag is given. The tt(-n) flag suppresses the trailing +newline. Only the tt(-e) and tt(-n) flags are recognized after +tt(-R); all other arguments and options are printed. +) +item(tt(-s))( +Place the results in the history list instead of on the standard output. +) +item(tt(-u)var(n))( +Print the arguments to file descriptor var(n). +) +item(tt(-z))( +Push the arguments onto the editing buffer stack, separated by spaces. +) enditem() If any of `tt(-m)', `tt(-o)' or `tt(-O)' are used in combination with diff --git a/Src/builtin.c b/Src/builtin.c index 5f7203fbe..e7ae06ed7 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -100,7 +100,7 @@ static struct builtin builtins[] = #endif BUILTIN("popd", 0, bin_cd, 0, 1, BIN_POPD, NULL, NULL), - BUILTIN("print", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, "RDPbnrsf:lzNu:pioOcm-", NULL), + BUILTIN("print", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, "abcC:Df:ilmnNoOpPrRsu:z-", NULL), BUILTIN("printf", 0, bin_print, 1, -1, BIN_PRINTF, NULL, NULL), BUILTIN("pushd", BINF_SKIPINVALID | BINF_SKIPDASH | BINF_DASHDASHVALID, bin_cd, 0, 2, BIN_PUSHD, "sPL", NULL), BUILTIN("pushln", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, NULL, "-nz"), @@ -3172,7 +3172,8 @@ bin_print(char *name, char **args, Options ops, int func) } else { fd = (int)zstrtol(argptr, &eptr, 10); if (*eptr) { - zwarnnam(name, "number expected after -u: %s", argptr, 0); + zwarnnam(name, "number expected after -%c: %s", argptr, + 'u'); return 1; } } @@ -3209,30 +3210,71 @@ bin_print(char *name, char **args, Options ops, int func) len[n] = strlen(args[n]); /* -c -- output in columns */ - if (OPT_ISSET(ops,'c')) { + if (OPT_ISSET(ops,'c') || OPT_ISSET(ops,'C')) { int l, nc, nr, sc, n, t, i; char **ap; + /* + * n: loop counter + * ap: array iterator + * l: maximum length seen + */ for (n = l = 0, ap = args; *ap; ap++, n++) if (l < (t = strlen(*ap))) l = t; + /* + * sc: column width + * nc: number of columns (at least one) + */ sc = l + 2; - nc = (columns + 1) / sc; - if (!nc) - nc = 1; + if (OPT_ISSET(ops,'C')) { + char *eptr, *argptr = OPT_ARG(ops,'C'); + nc = (int)zstrtol(argptr, &eptr, 10); + if (*eptr) { + zwarnnam(name, "number expected after -%c: %s", argptr, 'C'); + return 1; + } + if (nc <= 0) { + zwarnnam(name, "invalid number of columns: %s", argptr, 0); + return 1; + } + } + else + { + nc = (columns + 1) / sc; + if (!nc) + nc = 1; + } nr = (n + nc - 1) / nc; + if (OPT_ISSET(ops,'a')) /* print across, i.e. columns first */ + ap = args; for (i = 0; i < nr; i++) { - ap = args + i; - do { - l = strlen(*ap); - fprintf(fout, "%s", *ap); - for (t = nr; t && *ap; t--, ap++); - if(*ap) - for (; l < sc; l++) - fputc(' ', fout); - } while (*ap); + if (OPT_ISSET(ops,'a')) + { + int ic; + for (ic = 0; ic < nc && *ap; ic++, ap++) + { + l = strlen(*ap); + fprintf(fout, "%s", *ap); + if (*ap) + for (; l < sc; l++) + fputc(' ', fout); + } + } + else + { + ap = args + i; + do { + l = strlen(*ap); + fprintf(fout, "%s", *ap); + for (t = nr; t && *ap; t--, ap++); + if(*ap) + for (; l < sc; l++) + fputc(' ', fout); + } while (*ap); + } fputc(OPT_ISSET(ops,'N') ? '\0' : '\n', fout); } /* Testing EBADF special-cases >&- redirections */ @@ -4104,7 +4146,7 @@ bin_read(char *name, char **args, Options ops, int func) } else { readfd = (int)zstrtol(argptr, &eptr, 10); if (*eptr) { - zwarnnam(name, "number expected after -u: %s", argptr, 0); + zwarnnam(name, "number expected after -%c: %s", argptr, 'u'); return 1; } } |