[PATCH] tests: CuTmpdir.pm: avoid use of undefined variable in warning

2009-03-25 Thread Jim Meyering
Thanks, Ralf!
I've applied this:

>From 26559b513dd51a8adb941829b46c162d90434f7d Mon Sep 17 00:00:00 2001
From: Ralf Wildenhues 
Date: Wed, 25 Mar 2009 10:15:46 +0100
Subject: [PATCH] tests: CuTmpdir.pm: avoid use of undefined variable in warning

* tests/CuTmpdir.pm (chmod_tree): Do not warn if $dir is undefined.
---
 tests/CuTmpdir.pm |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/tests/CuTmpdir.pm b/tests/CuTmpdir.pm
index 166e50b..1e52640 100644
--- a/tests/CuTmpdir.pm
+++ b/tests/CuTmpdir.pm
@@ -1,7 +1,7 @@
 package CuTmpdir;
 # create, then chdir into a temporary sub-directory

-# Copyright (C) 2007-2008 Free Software Foundation, Inc.
+# Copyright (C) 2007-2009 Free Software Foundation, Inc.

 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -45,7 +45,11 @@ sub chmod_1

 sub chmod_tree
 {
-  if (defined $dir && chdir $dir)
+  # When tempdir fails, it croaks, which leaves $dir undefined.
+  defined $dir
+or return;
+
+  if (chdir $dir)
 {
   # Perform the equivalent of find . -type d -print0|xargs -0 chmod -R 700.
   my $options = {untaint => 1, wanted => \&chmod_1};
--
1.6.2.rc1.285.gc5f54


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: ls -v is still inconsistent

2009-03-25 Thread Ondřej Vašík
Jim Meyering wrote:
> Pushed.
> 
> http://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=1721cf06d9

I guess info doc about suffix regex should be updated too...

Greetings,
 Ondrej

From 88ebd00c46668f2b677c8da9a7e40584d5b97d9b Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= 
Date: Wed, 25 Mar 2009 12:04:11 +0100
Subject: [PATCH] doc: Update suffix regex in version sort

* doc/coreutils.texi: Reflect current filevercmp regex
---
 doc/coreutils.texi |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 04db676..9c8b8c3 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -6667,7 +6667,7 @@ foo.zml-6.gz   foo.zml-100.gz
 
 Version-sorted strings are compared such that if @var{ver1} and @var{ver2}
 are version numbers and @var{prefix} and @var{suffix} (@var{suffix} matching
-the regular expression @samp{(\.[A-Za-z][A-Za-z0-9]*)*}) are strings then
+the regular expression @samp{(\.[A-Za-z~][A-Za-z0-9~]*)*}) are strings then
 @var{ver1} < @var{ver2} implies that the name composed of
 `...@var{prefix} @var{ver1} @var{suffix}'' sorts before
 `...@var{prefix} @var{ver2} @var{suffix}''.
-- 
1.5.6.1.156.ge903b



signature.asc
Description: Toto je digitálně	 podepsaná část	 zprávy
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: ls -v is still inconsistent

2009-03-25 Thread Jim Meyering
Ondřej Vašík wrote:
> Subject: [PATCH] doc: Update suffix regex in version sort
>
> * doc/coreutils.texi: Reflect current filevercmp regex

Thanks!
Pushed.


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Reporting "who am i" command BUG

2009-03-25 Thread Harsh Rajesh Vachhani
Hi,

There seems to be strange behavior on executing the following command.

$who (anystring) (anystring)

The output which comes is same as  :

$who am I

Is this intentional or a bug. If its intentional, can you kindly reply back its 
significance.

Thanks,
Harsh Vachhani

 CAUTION - Disclaimer *
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
for the use of the addressee(s). If you are not the intended recipient, please 
notify the sender by e-mail and delete the original message. Further, you are 
not 
to copy, disclose, or distribute this e-mail or its contents to any other 
person and 
any such actions are unlawful. This e-mail may contain viruses. Infosys has 
taken 
every reasonable precaution to minimize this risk, but is not liable for any 
damage 
you may sustain as a result of any virus in this e-mail. You should carry out 
your 
own virus checks before opening the e-mail or attachment. Infosys reserves the 
right to monitor and review the content of all messages sent to or from this 
e-mail 
address. Messages sent to or from this e-mail address may be stored on the 
Infosys e-mail system.
***INFOSYS End of Disclaimer INFOSYS***
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: Reporting "who am i" command BUG

2009-03-25 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

According to Harsh Rajesh Vachhani on 3/24/2009 9:52 PM:
> $who (anystring) (anystring)
> 
> The output which comes is same as  :
> 
> $who am I
> 
> Is this intentional or a bug. If its intentional, can you kindly reply back 
> its significance.

Intentional - reread 'who --help':

If ARG1 ARG2 given, -m presumed: `am i' or `mom likes' are usual.

It matches historical behavior, where it is the value of argc, and not the
contents of argv, that trigger the behavior.  And you are not the first
person to ask this question.

> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION

As a note of netiquette, note that it is generally frowned upon to send
email to a publicly archived list with a disclaimer that cannot be
enforced and which occupies more storage than the original message.  Some
people refuse to reply to such messages on principle, so you are
effectively reducing the chance for a meaningful reply.  There are plenty
of free email servers available without having to resort to your
employer's disclaimer.

- --
Don't work too hard, make some time for fun as well!

Eric Blake e...@byu.net
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknKGGgACgkQ84KuGfSFAYDoWACg2Y6Zy9/MgjGCCnrFTcNYxyus
w9wAoK508Bzd4PsWEaiVVU+FgDiLLq9c
=FTUz
-END PGP SIGNATURE-


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [bug #24949] coreutils pwd not implementing latest POSIX features

2009-03-25 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

According to Jim Meyering on 3/24/2009 12:41 PM:
>> Subject: [PATCH] pwd: support -L and -P
>>
> 
> Thanks for doing that!  It looks fine, modulo a couple nits:
>   - remove this item from TODO
>   - use SAME_INODE
>   - use $(...) rather than `...` in the test
> and please make the "case" labels align consistently.

One other nit - 'make syntax-check' failed because I forgot to prune
#include "long-option.h".  Everything is now fixed, and the final patch
applied.

- --
Don't work too hard, make some time for fun as well!

Eric Blake e...@byu.net
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknKJOMACgkQ84KuGfSFAYCC3QCdGk7agpMfYH1DpzpVd5aWYt+d
QDQAn27JRZ4uOqQQuMeqocYaJ4gxvTye
=b+Qy
-END PGP SIGNATURE-


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


md5sum and binary vs. text

2009-03-25 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I really hate the fact that md5sum and friends output * for binary files,
and blank for text files, when used on cygwin or other platforms where
O_TEXT matters.  This poor choice of defaults makes 'make
sc_immutable_NEWS' fail, because md5sum outputs:

fa6cba1740b3f385520c1b54d90859ca *-

and the extra * breaks the check.  I'd really like to switch md5sum and
friends to match Linux output when O_BINARY, and add a different marker
character (but what?) when summing a file in O_TEXT mode, since generally
you WANT binary mode to be the default.  Thoughts?

- --
Don't work too hard, make some time for fun as well!

Eric Blake e...@byu.net
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknKJqgACgkQ84KuGfSFAYD1QwCgpluiK23NOPJTwdWGQvraKfOb
+zsAoKADRjTGZU+VqAzfJH+6IhXmpuuN
=AIzY
-END PGP SIGNATURE-


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


su command...

2009-03-25 Thread Adilson Bonanovisky
Hi Kids!

Please, how can I execute the following idea: $ su gimp &
but really in bacground?

Thanks
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


[PATCH] sort: Add --threads option, which parallelizes internal sort.

2009-03-25 Thread Paul Eggert
This patch is by Glen Lenker, Matt Pham, Benjamin Nuernberger, Sky
Lin, TaeSung Roh, and Paul Eggert.  It adds support for parallelism
within an internal sort.  On our simple tests on a 2-core desktop x86,
overall performance improved by roughly a factor of 1.6.
* THANKS: Add Benjamin Nuernberger, Sky Lin, TaeSung Roh.  Sort.
* TODO: Add note about how to make this algorithm better.
* bootstrap.conf: Add nproc, pthread.
* doc/coreutils.texi (sort invocation): Document new --threads option.
* src/Makefile.am (sort_LDADD): Add $(LIB_PTHREAD).
* src/sort.c: Include pthread.h, nproc.h.
(SUBTHREAD_LINES_HEURISTIC, THREADS_OPTION): New constants.
(sortlines_temp): Remove decl.
(usage, long_options, main): New option --threads.
(specify_nthreads): New function.
(mergelines): New signature, to emphasize the fact that the HI area must be
part of the destination.  All callers changed.
(sortlines): Rewrite to support and use parallelism, with a new signature.
All uses changed.  Merge in the functionality of sortlines_temp.
(struct thread_args): New struct.
(sortlines_thread): New function.
(sortlines_temp): Remove.
(sort): New arg NTHREADS.  All uses changed.
(main): Disable threading if we are sorting at random.
* tests/Makefile.am (TESTS): Add misc/sort-benchmark-random.
* tests/misc/sort-benchmark-random: New file.
---
 THANKS   |   23 +++--
 TODO |8 ++
 bootstrap.conf   |9 ++-
 doc/coreutils.texi   |8 ++
 src/Makefile.am  |2 +-
 src/sort.c   |  220 +++---
 tests/Makefile.am|1 +
 tests/misc/sort-benchmark-random |   67 
 8 files changed, 263 insertions(+), 75 deletions(-)
 create mode 100644 tests/misc/sort-benchmark-random

diff --git a/THANKS b/THANKS
index 665a9ef..e37fdb3 100644
--- a/THANKS
+++ b/THANKS
@@ -24,12 +24,11 @@ aldomel aldo...@ix.netcom.com
 Alen Muziniczv...@fly.cc.fer.hr
 Alexander Nguyenv...@seas.ucla.edu
 Alexander V. Lukyanov   l...@netis.ru
-Allen Hewes al...@decisiv.net
-Axel Dörflerax...@pinc-software.de
 Alexandre Duret-Lutzdure...@epita.fr
 Alexey Solovyov ale...@math.uu.se
 Alexey Vyskubov ale...@pippuri.mawhrin.net
 Alfred M. Szmidta...@kemisten.nu
+Allen Hewes al...@decisiv.net
 Andi Kleen  frei...@alancoxonachip.com
 Andre Novaes Cunha  andre.cu...@br.global-one.net
 Andreas Frische andreasfris...@gmail.com
@@ -61,13 +60,15 @@ Arvind Autarautar...@planet.nl
 Augey Mikus mi...@dqc.org
 Aurelien Jarno  aure...@debian.org
 Austin Donnelly austin.donne...@cl.cam.ac.uk
+Axel Dörflerax...@pinc-software.de
 Axel Kittenberger   ans...@gmx.net
 Barry Kelly http://barrkel.blogspot.com/
 Bauke Jan Douma bjdo...@xs4all.nl
 Ben Ellistonb...@air.net.au
 Ben Harris  bj...@netbsd.org
-Benjamin Cutler cutle...@simla.colostate.edu
 Bengt Martenssonbe...@mathematik.uni-bremen.de
+Benjamin Cutler cutle...@simla.colostate.edu
+Benjamin Nuernbergerbenjamin...@gmail.com
 Bernard Giroud  bernard.gir...@creditlyonnais.ch
 Bernd Eckenfels e...@debian.org
 Bernd Leibing   bernd.leib...@rz.uni-ulm.de
@@ -169,12 +170,12 @@ Elbert Pol  elbert@gmail.com
 Eli Zaretskii   e...@is.elta.co.il
 Elias Pipping   pipp...@gentoo.org
 Emile LeBlanc   lebl...@math.toronto.edu
-Erik Auerswald  auers...@unix-ag.uni-kl.de
 Eric Backus er...@lsid.hp.com
 Eric Blake  e...@byu.net
 Eric G. Miller  e...@jps.net
 Eric Pementepeme...@northpark.edu
 Eric S. Raymond e...@snark.thyrsus.com
+Erik Auerswald  auers...@unix-ag.uni-kl.de
 Erik Bennettbenn...@cvo.oneworld.com
 Erik Corry  e...@kroete2.freinet.de
 Evan Hunt   etha...@armory.com
@@ -207,7 +208,6 @@ Gerhard Poulgp...@gnu.org
 Germano Leichsenringgerm...@jedi.cs.kobe-u.ac.jp
 Glen Lenker glen.len...@gmail.com
 Göran Uddeborg  goe...@uddeborg.se
-Guochun Shi g...@ncsa.uiuc.edu
 GOTO Masanori   go...@debian.or.jp
 Greg Lou

Re: su command...

2009-03-25 Thread Olivier Delhomme
Le Wed, 25 Mar 2009 18:51:41 +0100, Adilson Bonanovisky disait :

> Hi Kids!

Hello,

> Please, how can I execute the following idea: $ su gimp &
> but really in bacground?

I can not figure out what you want to do, but you might try 
this :

if [[ $(grep gimp /etc/passwd | cut -d':' -f1) == "gimp" ]]; then su - gimp; 
else su -; export DISPLAY=:0.0; gimp &; logout; fi;

In the hope that this may help.

Cheers,

-- 
Olivier Delhomme : http://blog.delhomme.org/[fr]
"Quand la vérité n'est pas libre, la liberté n'est pas vraie."
 [Jacques Prévert]


signature.asc
Description: PGP signature
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


[PATCH] df: Fix bug when totaling unknown values.

2009-03-25 Thread Paul Eggert
This fixes a bug reported by "make check" on a Solaris 10 host with
some funky file systems.

* src/df.c (show_dev): Don't add UINTMAX_MAX to grand totals, as that
value indicates that the true value is unknown; adding it effectively
subtracts 1 from the total, whereas we want to leave the total alone.
---
 src/df.c |   19 ---
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/df.c b/src/df.c
index 0bb3b1e..bb24934 100644
--- a/src/df.c
+++ b/src/df.c
@@ -393,8 +393,10 @@ show_dev (char const *disk, char const *mount_point,
   negate_available = false;
   available_to_root = available;
 
-  grand_fsu.fsu_files += total;
-  grand_fsu.fsu_ffree += available;
+  if (total != UINTMAX_MAX)
+   grand_fsu.fsu_files += total;
+  if (available != UINTMAX_MAX)
+   grand_fsu.fsu_ffree += available;
 }
   else
 {
@@ -422,11 +424,14 @@ show_dev (char const *disk, char const *mount_point,
  & (available != UINTMAX_MAX));
   available_to_root = fsu.fsu_bfree;
 
-  grand_fsu.fsu_blocks += input_units * total;
-  grand_fsu.fsu_bfree  += input_units * available_to_root;
-  add_uint_with_neg_flag (&grand_fsu.fsu_bavail,
- &grand_fsu.fsu_bavail_top_bit_set,
- input_units * available, negate_available);
+  if (total != UINTMAX_MAX)
+   grand_fsu.fsu_blocks += input_units * total;
+  if (available_to_root != UINTMAX_MAX)
+   grand_fsu.fsu_bfree  += input_units * available_to_root;
+  if (available != UINTMAX_MAX)
+   add_uint_with_neg_flag (&grand_fsu.fsu_bavail,
+   &grand_fsu.fsu_bavail_top_bit_set,
+   input_units * available, negate_available);
 }
 
   used = UINTMAX_MAX;
-- 
1.6.2.1



___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: md5sum and binary vs. text

2009-03-25 Thread Jim Meyering
Eric Blake wrote:
> I really hate the fact that md5sum and friends output * for binary files,
> and blank for text files, when used on cygwin or other platforms where
> O_TEXT matters.  This poor choice of defaults makes 'make
> sc_immutable_NEWS' fail, because md5sum outputs:
>
> fa6cba1740b3f385520c1b54d90859ca *-
>
> and the extra * breaks the check.  I'd really like to switch md5sum and
> friends to match Linux output when O_BINARY, and add a different marker
> character (but what?) when summing a file in O_TEXT mode, since generally
> you WANT binary mode to be the default.  Thoughts?

I see what you mean, but what about people who use -b on Linux.
They'd still have to get the "*".
Seems like it'd be hard to arrange such a change
without causing too much disruption.

To address the failure, I'll probably push this tomorrow:

>From b102ed9ba6e529cc3dcf6be63c95d0f93d5499e0 Mon Sep 17 00:00:00 2001
From: Jim Meyering 
Date: Wed, 25 Mar 2009 22:49:09 +0100
Subject: [PATCH] tests: don't fail "make syntax-check" on cygwin

* maint.mk (NEWS_hash): Remove trailing " -" or " *-".
* cfg.mk (old_NEWS_hash): Regenerate, removing " -".
Reported by Eric Blake.
---
 cfg.mk   |2 +-
 maint.mk |9 ++---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index c6b6e9b..29a03a7 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -45,7 +45,7 @@ gnulib_dir = /gnulib
 # Now that we have better (check.mk) tests, make this the default.
 export VERBOSE = yes

-old_NEWS_hash = fa6cba1740b3f385520c1b54d90859ca  -
+old_NEWS_hash = fa6cba1740b3f385520c1b54d90859ca

 # Ensure that the list of O_ symbols used to compute O_FULLBLOCK is complete.
 dd = $(srcdir)/src/dd.c
diff --git a/maint.mk b/maint.mk
index 536..554b90a 100644
--- a/maint.mk
+++ b/maint.mk
@@ -460,9 +460,12 @@ sc_const_long_option:
  echo 1>&2 '$(ME): add "const" to the above declarations'; \
  exit 1; } || :

-NEWS_hash = \
-  $$(sed -n '/^\*.* $(PREV_VERSION_REGEXP) ([0-9-]*)/,$$p' \
- $(srcdir)/NEWS | grep -v '^Copyright .*Free Software' | md5sum -)
+NEWS_hash =\
+  $$(sed -n '/^\*.* $(PREV_VERSION_REGEXP) ([0-9-]*)/,$$p' \
+   $(srcdir)/NEWS  \
+ | grep -v '^Copyright .*Free Software'\
+ | md5sum -
\
+ | sed 's/ .*//')

 # Ensure that we don't accidentally insert an entry into an old NEWS block.
 sc_immutable_NEWS:
--
1.6.2.rc1.285.gc5f54


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [PATCH] df: Fix bug when totaling unknown values.

2009-03-25 Thread Jim Meyering
Paul Eggert wrote:
> This fixes a bug reported by "make check" on a Solaris 10 host with
> some funky file systems.
>
> * src/df.c (show_dev): Don't add UINTMAX_MAX to grand totals, as that
> value indicates that the true value is unknown; adding it effectively
> subtracts 1 from the total, whereas we want to leave the total alone.
> ---
>  src/df.c |   19 ---
>  1 files changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/src/df.c b/src/df.c
> index 0bb3b1e..bb24934 100644
> --- a/src/df.c
> +++ b/src/df.c
> @@ -393,8 +393,10 @@ show_dev (char const *disk, char const *mount_point,
>negate_available = false;
>available_to_root = available;
>
> -  grand_fsu.fsu_files += total;
> -  grand_fsu.fsu_ffree += available;

Good timing.
Matthew Woehlke recently reported failure of the df/total-verify test.
Looking into it, we found that one of those values was UINTMAX_MAX - 1.
So how about a function like summable (uintmax_t val) to be used
in place of each of those 5 tests?

> +  if (total != UINTMAX_MAX)
> + grand_fsu.fsu_files += total;
> +  if (available != UINTMAX_MAX)
> + grand_fsu.fsu_ffree += available;
>  }
>else
>  {
> @@ -422,11 +424,14 @@ show_dev (char const *disk, char const *mount_point,
> & (available != UINTMAX_MAX));
>available_to_root = fsu.fsu_bfree;
>
> -  grand_fsu.fsu_blocks += input_units * total;
> -  grand_fsu.fsu_bfree  += input_units * available_to_root;
> -  add_uint_with_neg_flag (&grand_fsu.fsu_bavail,
> -   &grand_fsu.fsu_bavail_top_bit_set,
> -   input_units * available, negate_available);
> +  if (total != UINTMAX_MAX)
> + grand_fsu.fsu_blocks += input_units * total;
> +  if (available_to_root != UINTMAX_MAX)
> + grand_fsu.fsu_bfree  += input_units * available_to_root;
> +  if (available != UINTMAX_MAX)
> + add_uint_with_neg_flag (&grand_fsu.fsu_bavail,
> + &grand_fsu.fsu_bavail_top_bit_set,
> + input_units * available, negate_available);
>  }
>
>used = UINTMAX_MAX;


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [PATCH] df: Fix bug when totaling unknown values.

2009-03-25 Thread Matthew Woehlke

Paul Eggert wrote:

This fixes a bug reported by "make check" on a Solaris 10 host with
some funky file systems.


It was AIX ;-).


* src/df.c (show_dev): Don't add UINTMAX_MAX to grand totals, as that
value indicates that the true value is unknown; adding it effectively
subtracts 1 from the total, whereas we want to leave the total alone.


I thought the check needs to be against (unsigned)-2?

--
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
--
"Yoda of Borg am I. Futile is resistance. Assimilate you, I will."
  -- from http://en.wikipedia.org/wiki/Wikipedia:Yet_more_Best_of_BJAODN



___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [PATCH] df: Fix bug when totaling unknown values.

2009-03-25 Thread Matthew Woehlke

Jim Meyering wrote:

Good timing.
Matthew Woehlke recently reported failure of the df/total-verify test.
Looking into it, we found that one of those values was UINTMAX_MAX - 1.


Oops, I saw what the patch was and assumed you (Jim) sent it. Sorry for 
the confusion, Paul! (...that would explain why you mentioned a 
different platform ;-).)


As Jim notes, AIX gives (unsigned)-2 (i.e. UINTMAX_MAX - 1), not 
(unsigned)-1 (UINTMAX_MAX), so the previous patch won't actually fix the 
problem on AIX.


Adjusting
  if (total != UINTMAX_MAX)
to
  if (total < UINTMAX_MAX - 1)
should suffice.

--
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
--
"Yoda of Borg am I. Futile is resistance. Assimilate you, I will."
  -- from http://en.wikipedia.org/wiki/Wikipedia:Yet_more_Best_of_BJAODN



___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


ls -l --show-me-each-link-in-the-symlink-chain

2009-03-25 Thread jidanni
ls -l  shows you the start of the symlink chain,
ls -lL shows you the end   of the symlink chain,
but to see each link, one needs many ls -l's.
There ought to be an option to see each link.
Sure, there is usually just one link,
but sometimes there is more.


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: su command...

2009-03-25 Thread Mike Frysinger
On Wednesday 25 March 2009 16:57:26 Olivier Delhomme wrote:
> Le Wed, 25 Mar 2009 18:51:41 +0100, Adilson Bonanovisky disait :
> > Please, how can I execute the following idea: $ su gimp &
> > but really in bacground?
>
> I can not figure out what you want to do, but you might try
> this :
>
> if [[ $(grep gimp /etc/passwd | cut -d':' -f1) == "gimp" ]]

if running on a glibc system, getent may be a cleaner solution.
if getent passwd gimp >/dev/null ; then ...
-mike


signature.asc
Description: This is a digitally signed message part.
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: misalignment in ls -l in fr_FR locale

2009-03-25 Thread Pádraig Brady
I expect to push the attached updated patch soon.

cheers,
Pádraig.
>From f687f88bef0589b5fe1c2a73e7ea9ee475db81b8 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= 
Date: Tue, 24 Mar 2009 14:29:21 +
Subject: [PATCH] ls: Fix alignment when month names have varying widths

* NEWS: Mention the fix
* gl/lib/mbsalign.c: A new module to align and truncate a
string in a specified number of screen cells, while handling
multi-byte characters appropriately.
* gl/lib/mbsalign.h: Ditto
* gl/modules/mbsalign: Ditto
* bootstrap.conf: Reference the new module
* src/ls.c (abmon_init): New function, precompute the abbreviated
months aligned left in a minimum width column <= 5 screen cells.
(align_nstrftime): New function, replace the first %b in the
format specification to strftime with the precomputed month string.
Note using the cached month strings speeds up `ls -l` by around 10%
on glibc-2.7-2 on linux at least.  Also if we implement this function
using heap storage rather than automatic storage, and use snprintf
instead of strcat, ls will slow down by 2% and 1% respectively
(i.e. a net gain of 7% rather than 10%).
---
 NEWS|3 +
 bootstrap.conf  |1 +
 gl/lib/mbsalign.c   |  176 +++
 gl/lib/mbsalign.h   |   23 +++
 gl/modules/mbsalign |   26 
 src/ls.c|  100 -
 6 files changed, 327 insertions(+), 2 deletions(-)
 create mode 100644 gl/lib/mbsalign.c
 create mode 100644 gl/lib/mbsalign.h
 create mode 100644 gl/modules/mbsalign

diff --git a/NEWS b/NEWS
index 3ef5f94..6538071 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,9 @@ GNU coreutils NEWS-*- outline -*-
   ls --sort=version (-v) sorted names beginning with "." inconsistently.
   Now, names that start with "." are always listed before those that don't.
 
+  ls now aligns output correctly in the presence of abbreviated month names
+  from the locale database that have differing widths.
+
   pr: fix the bug whereby --indent=N (-o) did not indent header lines
   [bug introduced in coreutils-6.9.90]
 
diff --git a/bootstrap.conf b/bootstrap.conf
index 0747bb8..ae033d9 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -70,6 +70,7 @@ gnulib_modules="
 	long-options lstat malloc
 	manywarnings
 	mbrtowc
+	mbsalign
 	mbswidth
 	memcasecmp memcmp2 mempcpy
 	memrchr mgetgroups
diff --git a/gl/lib/mbsalign.c b/gl/lib/mbsalign.c
new file mode 100644
index 000..95e303a
--- /dev/null
+++ b/gl/lib/mbsalign.c
@@ -0,0 +1,176 @@
+/* Align/Truncate a string in a given screen width
+   Copyright (C) 2009 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see .  */
+
+/* Written by Pádraig Brady.  */
+
+#include 
+#include "mbsalign.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "xalloc.h"
+
+static int wc_ensure_printable (wchar_t * wchars);
+static size_t wc_truncate (wchar_t * wchars, size_t width);
+static int rpl_wcswidth (const wchar_t *s, size_t n);
+
+/* Align a string in a given screen width, handling multi-byte characters.
+   In addition if the string is too large for the width it's truncated.
+   When centering, the number of trailing spaces may be 1 less than the
+   number of leading spaces.
+   Returned is the number of bytes written to or required in dest (without
+   the trailing NUL).  A value >= dest_size means there wasn't enough space.
+   The width parameter both specifies the width to align/pad/truncate to,
+   and is updated to return the width used before padding.  */
+
+int
+mbsalign (const char *src, char *dest, size_t dest_size,
+  int *width, mbs_align_t align)
+{
+  int src_len = strlen (src);
+  int ret = 0;
+  char *newstr = NULL;
+  wchar_t *str_wc = NULL;
+  const char *str_to_print = src;
+  int used = src_len, spaces, wc_conversion = 0, wc_enabled = 0;
+
+  if (MB_CUR_MAX > 1)
+{
+  int src_chars = mbstowcs (NULL, src, 0) + 1;
+  str_wc = xmalloc (src_chars * sizeof (wchar_t));
+  if (mbstowcs (str_wc, src, src_chars) > 0)
+{
+  str_wc[src_chars - 1] = L'\0';
+  wc_enabled = 1;
+  wc_conversion = wc_ensure_printable (str_wc);
+  used = rpl_wcswidth (str_wc, src_chars);
+}
+}
+
+  if (wc_conversion || used > *width)
+{
+  newstr = xmalloc (src_len);

Re: md5sum and binary vs. text

2009-03-25 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

According to Jim Meyering on 3/25/2009 3:57 PM:
>> and the extra * breaks the check.  I'd really like to switch md5sum and
>> friends to match Linux output when O_BINARY, and add a different marker
>> character (but what?) when summing a file in O_TEXT mode, since generally
>> you WANT binary mode to be the default.  Thoughts?
> 
> I see what you mean, but what about people who use -b on Linux.
> They'd still have to get the "*".

People who use -b on Linux would see no change in behavior, because there,
like any other sane system, text and binary mode files are
indistinguishable, so there is no need for a marker.

> Seems like it'd be hard to arrange such a change
> without causing too much disruption.

It seems to me that only platforms like Cygwin would be impacted.  In
fact, one of the commits that impacts binary mode (4d87cd7, back in 2001)
is attributed to Chris Faylor, who was the person responsible for porting
coreutils to cygwin back in the days where the cygwin community was not
very sure about text vs. binary decisions; since then, the cygwin
community has stabilized to preferring binary over text as a default.

For md5sum -c purposes, we will have to continue accepting * in files that
we validate.  But for generation purposes, it seems like we should
generate space (binary, and make it the default on cygwin) or a new marker
(text, when requested, and only on platforms where it matters).  And since
the BSD format is different altogether, it seems like only GNU md5sum
would be impacted by a change in the marker character.

And I've also been meaning to add an escape sequence \r rather than raw
carriage returns, also helpful in the case of text file confusion.  I
guess at this point, patches speak louder than words, so I'll have to
draft something up.  But don't hold up the release of 7.2 for this.

> 
> To address the failure, I'll probably push this tomorrow:
> 
> * maint.mk (NEWS_hash): Remove trailing " -" or " *-".

Thanks - that looks nice.

- --
Don't work too hard, make some time for fun as well!

Eric Blake e...@byu.net
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknK4nIACgkQ84KuGfSFAYBFPQCfWOyfyfD5dn/Idc4QVm0vTmmW
ky0AoKfiz6zYArNTUm2k91kxbJ9uo/jZ
=UVdV
-END PGP SIGNATURE-


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: ls -l --show-me-each-link-in-the-symlink-chain

2009-03-25 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

According to jida...@jidanni.org on 3/25/2009 12:23 PM:
> ls -l  shows you the start of the symlink chain,
> ls -lL shows you the end   of the symlink chain,
> but to see each link, one needs many ls -l's.
> There ought to be an option to see each link.

readlink is what you're looking for.

- --
Don't work too hard, make some time for fun as well!

Eric Blake e...@byu.net
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknK4uAACgkQ84KuGfSFAYDunwCgh6YWiZ3P5PNere91db6qn6c/
F1oAn2LPY8M+Fx2Z70xhgotwI/Sm0zIt
=Af70
-END PGP SIGNATURE-


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: ls -l --show-me-each-link-in-the-symlink-chain

2009-03-25 Thread jidanni
> "EB" == Eric Blake  writes:

EB> According to jida...@jidanni.org on 3/25/2009 12:23 PM:
>> ls -l  shows you the start of the symlink chain,
>> ls -lL shows you the end   of the symlink chain,
>> but to see each link, one needs many ls -l's.
>> There ought to be an option to see each link.

EB> readlink is what you're looking for.

OK, please add a note to that effect at ls -L.

And readlink needs an option to show each link in the chain!


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [PATCH] df: Fix bug when totaling unknown values.

2009-03-25 Thread Paul Eggert
Jim Meyering  writes:

> So how about a function like summable (uintmax_t val) to be used
> in place of each of those 5 tests?

Sure thing, though I count 11 tests total, not just the 5 in the
previous patch.  I prefer a name like 'known_value' to 'summable', as
it's a bit more specific.  Here's that same patch, followed by a further
patch to add known_value, generated by git-format-patch.

===

>From abc8e21a0b5a55bed938b30adf217a26c1a17bac Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Wed, 25 Mar 2009 14:16:46 -0700
Subject: [PATCH] df: Fix bug when totaling unknown values.

* src/df.c (show_dev): Don't add UINTMAX_MAX to grand totals, as that
value indicates that the true value is unknown; adding it effectively
subtracts 1 from the total, whereas we want to leave the total alone.
---
 src/df.c |   19 ---
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/df.c b/src/df.c
index 0bb3b1e..bb24934 100644
--- a/src/df.c
+++ b/src/df.c
@@ -393,8 +393,10 @@ show_dev (char const *disk, char const *mount_point,
   negate_available = false;
   available_to_root = available;
 
-  grand_fsu.fsu_files += total;
-  grand_fsu.fsu_ffree += available;
+  if (total != UINTMAX_MAX)
+   grand_fsu.fsu_files += total;
+  if (available != UINTMAX_MAX)
+   grand_fsu.fsu_ffree += available;
 }
   else
 {
@@ -422,11 +424,14 @@ show_dev (char const *disk, char const *mount_point,
  & (available != UINTMAX_MAX));
   available_to_root = fsu.fsu_bfree;
 
-  grand_fsu.fsu_blocks += input_units * total;
-  grand_fsu.fsu_bfree  += input_units * available_to_root;
-  add_uint_with_neg_flag (&grand_fsu.fsu_bavail,
- &grand_fsu.fsu_bavail_top_bit_set,
- input_units * available, negate_available);
+  if (total != UINTMAX_MAX)
+   grand_fsu.fsu_blocks += input_units * total;
+  if (available_to_root != UINTMAX_MAX)
+   grand_fsu.fsu_bfree  += input_units * available_to_root;
+  if (available != UINTMAX_MAX)
+   add_uint_with_neg_flag (&grand_fsu.fsu_bavail,
+   &grand_fsu.fsu_bavail_top_bit_set,
+   input_units * available, negate_available);
 }
 
   used = UINTMAX_MAX;
-- 
1.5.3.2


>From 2c35010ca7651251376f113983141d08b6ecce0a Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Wed, 25 Mar 2009 20:50:17 -0700
Subject: [PATCH] df: Port the known-value fix to AIX as well.

* src/df.c (known_value): New function, which also works on AIX file systems.
(df_readable, show_dev): Use it instead of hardcoding comparison to
UINTMAX_MAX.  Suggested by Jim Meyering and Matthew Woehlke.
---
 src/df.c |   30 --
 1 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/df.c b/src/df.c
index bb24934..47d 100644
--- a/src/df.c
+++ b/src/df.c
@@ -231,18 +231,28 @@ excluded_fstype (const char *fstype)
   return false;
 }
 
+/* Return true if N is a known integer value.  On many file systems,
+   UINTMAX_MAX represents an unknown value; on AIX, UINTMAX_MAX - 1
+   represents unknown.  Use a rule that works on AIX file systems, and
+   that almost-always works on other types.  */
+static bool
+known_value (uintmax_t n)
+{
+  return n < UINTMAX_MAX - 1;
+}
+
 /* Like human_readable (N, BUF, human_output_opts, INPUT_UNITS, OUTPUT_UNITS),
except:
 
 - If NEGATIVE, then N represents a negative number,
   expressed in two's complement.
-- Otherwise, return "-" if N is UINTMAX_MAX.  */
+- Otherwise, return "-" if N is unknown.  */
 
 static char const *
 df_readable (bool negative, uintmax_t n, char *buf,
 uintmax_t input_units, uintmax_t output_units)
 {
-  if (n == UINTMAX_MAX && !negative)
+  if (! known_value (n) && !negative)
 return "-";
   else
 {
@@ -393,9 +403,9 @@ show_dev (char const *disk, char const *mount_point,
   negate_available = false;
   available_to_root = available;
 
-  if (total != UINTMAX_MAX)
+  if (known_value (total))
grand_fsu.fsu_files += total;
-  if (available != UINTMAX_MAX)
+  if (known_value (available))
grand_fsu.fsu_ffree += available;
 }
   else
@@ -421,14 +431,14 @@ show_dev (char const *disk, char const *mount_point,
   total = fsu.fsu_blocks;
   available = fsu.fsu_bavail;
   negate_available = (fsu.fsu_bavail_top_bit_set
- & (available != UINTMAX_MAX));
+ & known_value (available));
   available_to_root = fsu.fsu_bfree;
 
-  if (total != UINTMAX_MAX)
+  if (known_value (total))
grand_fsu.fsu_blocks += input_units * total;
-  if (available_to_root != UINTMAX_MAX)
+  if (known_value (available_to_root))
grand_fsu.fsu_bfree  += input_units * available_to_root;
-  if (available != UINTMAX_MAX)
+  if (known_value (available))
add_uint_wit

Re: misalignment in ls -l in fr_FR locale

2009-03-25 Thread Jim Meyering
Pádraig Brady wrote:
> I expect to push the attached updated patch soon.

Hi Pádraig,

Thanks for working on this, but please hold off until after 7.2.
I'm trying to stabilize for a bug-fix(was "-only") release.

> Subject: [PATCH] ls: Fix alignment when month names have varying widths
...
> diff --git a/gl/lib/mbsalign.c b/gl/lib/mbsalign.c
> new file mode 100644
> index 000..95e303a
> --- /dev/null
> +++ b/gl/lib/mbsalign.c
> @@ -0,0 +1,176 @@
> +/* Align/Truncate a string in a given screen width
> +   Copyright (C) 2009 Free Software Foundation, Inc.
> +
> +   This program is free software: you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation, either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see .  */
> +
> +/* Written by Pádraig Brady.  */
> +
> +#include 
> +#include "mbsalign.h"
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "xalloc.h"
> +
> +static int wc_ensure_printable (wchar_t * wchars);
> +static size_t wc_truncate (wchar_t * wchars, size_t width);
> +static int rpl_wcswidth (const wchar_t *s, size_t n);
> +
> +/* Align a string in a given screen width, handling multi-byte characters.
> +   In addition if the string is too large for the width it's truncated.

use active voice, i.e.,

   In addition if the string is too large for the width, truncate it to fit.

> +   When centering, the number of trailing spaces may be 1 less than the
> +   number of leading spaces.
> +   Returned is the number of bytes written to or required in dest (without

Return the number...

> +   the trailing NUL).  A value >= dest_size means there wasn't enough space.
> +   The width parameter both specifies the width to align/pad/truncate to,
> +   and is updated to return the width used before padding.  */

Would "desired_width" be a better parameter name for dest_size?
"size" makes me think of a buffer size, i.e., number of bytes allocated.

> +int
> +mbsalign (const char *src, char *dest, size_t dest_size,
> +  int *width, mbs_align_t align)
> +{
> +  int src_len = strlen (src);

Please use size_t, not int for anything length-related.
And especially for things you pass to malloc.

> +  int ret = 0;
> +  char *newstr = NULL;
> +  wchar_t *str_wc = NULL;
> +  const char *str_to_print = src;
> +  int used = src_len, spaces, wc_conversion = 0, wc_enabled = 0;

The name "used" could mean something boolean, or a length.
Call it "n_used" and there is no ambiguity.
n_spaces would be clearer, in the same way.
use size_t for those two.

wc_conversion and wc_enabled should be of type "bool".

> +  if (MB_CUR_MAX > 1)
> +{
> +  int src_chars = mbstowcs (NULL, src, 0) + 1;
> +  str_wc = xmalloc (src_chars * sizeof (wchar_t));

This function would be more generally useful (usable in a library) if it
did not rely on xmalloc (i.e., use malloc instead and handle failure),
and probably not much harder to implement.  maybe worth the trouble...

> +  if (mbstowcs (str_wc, src, src_chars) > 0)
> +{
> +  str_wc[src_chars - 1] = L'\0';
> +  wc_enabled = 1;
> +  wc_conversion = wc_ensure_printable (str_wc);
> +  used = rpl_wcswidth (str_wc, src_chars);
> +}
> +}
> +
> +  if (wc_conversion || used > *width)
> +{
> +  newstr = xmalloc (src_len);
> +  str_to_print = newstr;
> +  if (wc_enabled)
> +{
> +  used = wc_truncate (str_wc, *width);
> +  wcstombs (newstr, str_wc, src_len);
> +}
> +  else
> +{
> +  memcpy (newstr, src, *width);
> +  newstr[*width] = '\0';
> +}
> +}
> +
> +  spaces = *width - used;
> +  spaces = (spaces < 0 ? 0 : spaces);
> +  *width = used;  /* indicate to called how many cells used.  */
> +
> +  /* FIXME: Should I be padding with "figure space" (\u2007)
> + rather than spaces below? (only if non ascii data present)  */
> +  switch (align)
> +{
> +case MBS_ALIGN_CENTER:
> +  ret = snprintf (dest, dest_size, "%*s%s%*s",
> +  spaces / 2 + spaces % 2, "",
> +  str_to_print, spaces / 2, "");

For a potential-library function like this, I'd be inclined
to use stpcpy+memchr rather than the heavy-weight snprintf.

> +  break;
> +case MBS_ALIGN_LEFT:
> +  ret = snprintf (dest, dest_size, "%s%*s", str_to_print, spaces, "");
> +  break;
> +case MBS_ALIGN_RIGHT:
> +  ret = snprintf (dest, dest_size, "%*s%s", spaces, "", str_to_p

Re: misalignment in ls -l in fr_FR locale

2009-03-25 Thread Jim Meyering
Pádraig Brady wrote:
> I expect to push the attached updated patch soon.

Hi Pádraig,

Thanks for working on this, but please hold off until after 7.2.
I'm trying to stabilize for a bug-fix(was "-only") release.

> Subject: [PATCH] ls: Fix alignment when month names have varying widths
...
> diff --git a/gl/lib/mbsalign.c b/gl/lib/mbsalign.c
...

I much prefer to order functions (defined before used) so that
static prototypes are not needed.  Then, when you change the return
type of e.g., wc_ensure_printable to "bool" you'll have to change it
in only one place.

> +static int wc_ensure_printable (wchar_t * wchars);
> +static size_t wc_truncate (wchar_t * wchars, size_t width);
> +static int rpl_wcswidth (const wchar_t *s, size_t n);
> +
> +/* Align a string in a given screen width, handling multi-byte characters.
> +   In addition if the string is too large for the width it's truncated.

use active voice, i.e.,

   In addition if the string is too large for the width, truncate it to fit.

> +   When centering, the number of trailing spaces may be 1 less than the
> +   number of leading spaces.
> +   Returned is the number of bytes written to or required in dest (without

Return the number...

> +   the trailing NUL).  A value >= dest_size means there wasn't enough space.
> +   The width parameter both specifies the width to align/pad/truncate to,
> +   and is updated to return the width used before padding.  */

Would "desired_width" be a better parameter name for dest_size?
"size" makes me think of a buffer size, i.e., number of bytes allocated.

> +int
> +mbsalign (const char *src, char *dest, size_t dest_size,
> +  int *width, mbs_align_t align)
> +{
> +  int src_len = strlen (src);

Please use size_t, not int for anything length-related.
And especially for things you pass to malloc.

> +  int ret = 0;
> +  char *newstr = NULL;
> +  wchar_t *str_wc = NULL;
> +  const char *str_to_print = src;
> +  int used = src_len, spaces, wc_conversion = 0, wc_enabled = 0;

The name "used" could mean something boolean, or a length.
Call it "n_used" and there is no ambiguity.
n_spaces would be clearer, in the same way.
use size_t for those two.

wc_conversion and wc_enabled should be of type "bool".

> +  if (MB_CUR_MAX > 1)
> +{
> +  int src_chars = mbstowcs (NULL, src, 0) + 1;
> +  str_wc = xmalloc (src_chars * sizeof (wchar_t));

This function would be more generally useful (usable in a library) if it
did not rely on xmalloc (i.e., use malloc instead and handle failure),
and probably not much harder to implement.  maybe worth the trouble...

> +  if (mbstowcs (str_wc, src, src_chars) > 0)
> +{
> +  str_wc[src_chars - 1] = L'\0';
> +  wc_enabled = 1;
> +  wc_conversion = wc_ensure_printable (str_wc);
> +  used = rpl_wcswidth (str_wc, src_chars);
> +}
> +}
> +
> +  if (wc_conversion || used > *width)
> +{
> +  newstr = xmalloc (src_len);
> +  str_to_print = newstr;
> +  if (wc_enabled)
> +{
> +  used = wc_truncate (str_wc, *width);
> +  wcstombs (newstr, str_wc, src_len);
> +}
> +  else
> +{
> +  memcpy (newstr, src, *width);
> +  newstr[*width] = '\0';
> +}
> +}
> +
> +  spaces = *width - used;
> +  spaces = (spaces < 0 ? 0 : spaces);
> +  *width = used;  /* indicate to called how many cells used.  */
> +
> +  /* FIXME: Should I be padding with "figure space" (\u2007)
> + rather than spaces below? (only if non ascii data present)  */
> +  switch (align)
> +{
> +case MBS_ALIGN_CENTER:
> +  ret = snprintf (dest, dest_size, "%*s%s%*s",
> +  spaces / 2 + spaces % 2, "",
> +  str_to_print, spaces / 2, "");

For a potential-library function like this, I'd be inclined
to use stpcpy+memchr rather than the heavy-weight snprintf.

> +  break;
> +case MBS_ALIGN_LEFT:
> +  ret = snprintf (dest, dest_size, "%s%*s", str_to_print, spaces, "");
> +  break;
> +case MBS_ALIGN_RIGHT:
> +  ret = snprintf (dest, dest_size, "%*s%s", spaces, "", str_to_print);
> +  break;
> +}
> +
> +  free (str_wc);
> +  free (newstr);
> +
> +  return ret;
> +}
> +
> +/* Replace non printable chars.
> +   Return 1 if replacement made, 0 otherwise.  */
> +
> +static int

static bool

> +wc_ensure_printable (wchar_t * wchars)

this spacing, "wchar_t * wchars", looks like an artifact of running
the code through indent.  You can make it format properly by
adding -Twchar_t to ~/.indent.pro.  I wonder if GNU indent is
still maintained...

> +{
> +  int replaced = 0;

bool

> +  wchar_t *wc = wchars;
> +  while (*wc)
> +{
> +  if (!iswprint ((wint_t) * wc))

spacing: s/ wc/wc/

> +{
> +  *wc = 0xFFFD; /* L'\uFFFD' (replacement char) */
> +  replaced = 1;

... = true

> +}
> +  wc++;
> +}
> +  return replaced;
> +}

I'm stopping here, for now.


__