Add support for displaying multi-byte filenames to colorls.
ok naddy
This commit is contained in:
parent
1e84e3e64b
commit
62f1a5cb4a
@ -1,10 +1,10 @@
|
||||
# $OpenBSD: Makefile,v 1.21 2011/06/23 22:50:28 naddy Exp $
|
||||
# $OpenBSD: Makefile,v 1.22 2011/09/22 08:28:56 stsp Exp $
|
||||
|
||||
COMMENT= ls that can use color to display file attributes
|
||||
|
||||
DISTNAME= ls-4.8
|
||||
PKGNAME= color${DISTNAME}
|
||||
REVISION= 0
|
||||
REVISION= 1
|
||||
CATEGORIES= sysutils
|
||||
|
||||
MAINTAINER= Christian Weisgerber <naddy@openbsd.org>
|
||||
|
@ -1,7 +1,14 @@
|
||||
$OpenBSD: patch-ls_c,v 1.11 2009/10/29 20:10:39 naddy Exp $
|
||||
--- ls.c.orig Wed Oct 28 00:59:21 2009
|
||||
+++ ls.c Thu Oct 29 20:21:13 2009
|
||||
@@ -48,6 +48,10 @@
|
||||
$OpenBSD: patch-ls_c,v 1.12 2011/09/22 08:28:56 stsp Exp $
|
||||
--- ls.c.orig Tue Oct 19 16:28:14 2010
|
||||
+++ ls.c Thu Sep 22 09:41:24 2011
|
||||
@@ -42,12 +42,17 @@
|
||||
#include <errno.h>
|
||||
#include <fts.h>
|
||||
#include <grp.h>
|
||||
+#include <locale.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
@ -12,7 +19,7 @@ $OpenBSD: patch-ls_c,v 1.11 2009/10/29 20:10:39 naddy Exp $
|
||||
|
||||
#include "ls.h"
|
||||
#include "extern.h"
|
||||
@@ -90,6 +94,15 @@ int f_statustime; /* use time of last mode change */
|
||||
@@ -90,6 +95,15 @@ int f_statustime; /* use time of last mode change */
|
||||
int f_stream; /* stream format */
|
||||
int f_type; /* add type character for non-regular files */
|
||||
int f_typedir; /* add type character for directories */
|
||||
@ -28,7 +35,7 @@ $OpenBSD: patch-ls_c,v 1.11 2009/10/29 20:10:39 naddy Exp $
|
||||
|
||||
int rval;
|
||||
|
||||
@@ -101,6 +114,11 @@ ls_main(int argc, char *argv[])
|
||||
@@ -101,7 +115,14 @@ ls_main(int argc, char *argv[])
|
||||
int ch, fts_options, notused;
|
||||
int kflag = 0;
|
||||
char *p;
|
||||
@ -38,9 +45,12 @@ $OpenBSD: patch-ls_c,v 1.11 2009/10/29 20:10:39 naddy Exp $
|
||||
+ char *bp = tcapbuf;
|
||||
+#endif
|
||||
|
||||
+ setlocale(LC_CTYPE, "");
|
||||
+
|
||||
/* Terminal defaults to -Cq, non-terminal defaults to -1. */
|
||||
if (isatty(STDOUT_FILENO)) {
|
||||
@@ -122,7 +140,7 @@ ls_main(int argc, char *argv[])
|
||||
if ((p = getenv("COLUMNS")) != NULL)
|
||||
@@ -122,7 +143,7 @@ ls_main(int argc, char *argv[])
|
||||
f_listdot = 1;
|
||||
|
||||
fts_options = FTS_PHYSICAL;
|
||||
@ -49,7 +59,7 @@ $OpenBSD: patch-ls_c,v 1.11 2009/10/29 20:10:39 naddy Exp $
|
||||
switch (ch) {
|
||||
/*
|
||||
* The -1, -C and -l, -m, -n and -x options all override each
|
||||
@@ -176,6 +194,9 @@ ls_main(int argc, char *argv[])
|
||||
@@ -176,6 +197,9 @@ ls_main(int argc, char *argv[])
|
||||
case 'F':
|
||||
f_type = 1;
|
||||
break;
|
||||
@ -59,7 +69,7 @@ $OpenBSD: patch-ls_c,v 1.11 2009/10/29 20:10:39 naddy Exp $
|
||||
case 'L':
|
||||
fts_options &= ~FTS_PHYSICAL;
|
||||
fts_options |= FTS_LOGICAL;
|
||||
@@ -245,11 +266,46 @@ ls_main(int argc, char *argv[])
|
||||
@@ -245,11 +269,46 @@ ls_main(int argc, char *argv[])
|
||||
if (f_grouponly == -1)
|
||||
f_grouponly = 0;
|
||||
|
||||
|
@ -1,7 +1,66 @@
|
||||
$OpenBSD: patch-util_c,v 1.6 2009/10/29 20:10:39 naddy Exp $
|
||||
$OpenBSD: patch-util_c,v 1.7 2011/09/22 08:28:56 stsp Exp $
|
||||
--- util.c.orig Wed Oct 28 00:59:21 2009
|
||||
+++ util.c Thu Oct 29 20:21:26 2009
|
||||
@@ -59,7 +59,11 @@ void
|
||||
+++ util.c Thu Sep 22 09:53:40 2011
|
||||
@@ -41,10 +41,12 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
+#include <wchar.h>
|
||||
|
||||
#include "ls.h"
|
||||
#include "extern.h"
|
||||
|
||||
+#ifdef SMALL
|
||||
int
|
||||
putname(char *name)
|
||||
{
|
||||
@@ -54,12 +56,57 @@ putname(char *name)
|
||||
putchar((!isprint(*name) && f_nonprint) ? '?' : *name);
|
||||
return len;
|
||||
}
|
||||
+#else
|
||||
+int
|
||||
+putname(char *name)
|
||||
+{
|
||||
+ int len;
|
||||
+ wchar_t wc;
|
||||
+ size_t n;
|
||||
+ mbstate_t mbs;
|
||||
+ int w;
|
||||
|
||||
+ len = 0;
|
||||
+ bzero(&mbs, sizeof(mbs));
|
||||
+ while (*name) {
|
||||
+ n = mbrtowc(&wc, name, MB_CUR_MAX, &mbs);
|
||||
+ if (n == 0)
|
||||
+ break;
|
||||
+ if (n == (size_t)-1 || n == (size_t)-2) {
|
||||
+ /* Filename encoding doesn't match locale encoding.
|
||||
+ * Fall back to printing single bytes. */
|
||||
+ while (*name) {
|
||||
+ putchar((!isprint(*name) && f_nonprint)
|
||||
+ ? '?' : *name);
|
||||
+ len++;
|
||||
+ name++;
|
||||
+ }
|
||||
+ return len;
|
||||
+ }
|
||||
+ name += n;
|
||||
+ if (!iswprint(wc) && f_nonprint) {
|
||||
+ putchar('?');
|
||||
+ len++;
|
||||
+ } else {
|
||||
+ putwchar(wc);
|
||||
+ w = wcwidth(wc);
|
||||
+ if (w > 0)
|
||||
+ len += w;
|
||||
+ }
|
||||
+ }
|
||||
+ return len;
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
|
Loading…
x
Reference in New Issue
Block a user