[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] echo -n is not portable and used too much

From: Blair Zajac <blair_at_orcaware.com>
Date: 2002-02-12 04:41:25 CET

Greg Hudson wrote:
> The particular tr trick advocated by Kirby Bohling is poor because it
> embeds NUL characters in the output, although "tr -d '\012'" might
> serve.
>
> All a question of just how much ugliness we want to spend on being
> portable.

Turns out that autoconf is nice enough to supply us with $ECHO_C, $ECHO_N
and $ECHO_T for exactly this case.

The supplied patch does the following:

1) Makefile.in: Use @ECHO_C@ and @ECHO_N@ supplied by autoconf to have
   echo not print a newline.
2) Makefile.in: Rebuild Makefile from Makefile.in using config.status
   automatically.
3) ./ac-helpers/gnu-diff.sh: Determine how to have echo not print a newline.

For 3), I decided not to use autoconf, because that would mean creating
another autoconf generated file and having Makefile clean it up. This
seemed easier and the file is portable to different OSes without
autogenerating.

Best,
Blair

-- 
Blair Zajac <blair@orcaware.com>
Web and OS performance plots - http://www.orcaware.com/orca/

Index: ./Makefile.in
===================================================================
--- ./Makefile.in
+++ ./Makefile.in Mon Feb 11 19:37:21 2002
@@ -1,4 +1,3 @@
-
 top_builddir = .
 top_srcdir = @top_srcdir@
 abs_builddir = @abs_builddir@
@@ -92,6 +91,9 @@
 
 PYTHON = @PYTHON@
 
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+
 all: external-all local-all
 clean: external-clean local-clean
 distclean: external-distclean local-distclean
@@ -100,7 +102,7 @@
 
 @INCLUDE_OUTPUTS@
 
-local-all: @BUILD_RULES@ @SWIG_BUILD_RULES@
+local-all: Makefile @BUILD_RULES@ @SWIG_BUILD_RULES@
 
 local-clean: doc-clean
         @list='$(BUILD_DIRS)'; for i in $$list; do \
@@ -119,7 +121,7 @@
                 ac-helpers/libtool.m4 ac-helpers/ltconfig \
                 ac-helpers/ltmain.sh
 
-local-install: @INSTALL_RULES@ @SWIG_INSTALL_RULES@
+local-install: Makefile @INSTALL_RULES@ @SWIG_INSTALL_RULES@
 
 check: $(TEST_DEPS) @FS_TEST_DEPS@
         @logfile=`pwd`/tests.log ; \
@@ -129,7 +131,7 @@
         list='$(TEST_PROGRAMS) @FS_TEST_PROGRAMS@'; for prog in $$list; do \
             progbase=`echo $$prog | sed 's?.*/??'` ; \
             progdir=`echo $$prog | sed 's?/[^/]*$$??'` ; \
- echo -n "Running all tests in $$progbase..." ; \
+ echo $(ECHO_N) "Running all tests in $$progbase...$(ECHO_C)" ; \
             echo "START: $$progbase" >> $$logfile ; \
             if echo $$progbase | grep \\.py$$ > /dev/null; then \
                 runprog="$(PYTHON) $(abs_srcdir)/$$prog" ; \
@@ -155,6 +157,9 @@
             grep FAIL $$logfile || true ; \
         fi
 
+Makefile: Makefile.in
+ CONFIG_FILES=Makefile ./config.status
+
 mkdir-init:
         @list='$(BUILD_DIRS) $(DOC_DIRS)'; for i in $$list doc; do \
             echo "mkdir $$i" ; \
@@ -162,7 +167,7 @@
         done
 
 # recursive targets to handle external projects (e.g. APR, Neon)
-external-all external-clean external-distclean external-install:
+external-all external-clean external-distclean external-install: Makefile
         @target=`echo $@ | sed s/external-//`; \
         list='$(EXTERNAL_PROJECT_DIRS)'; \
         for i in $$list; do \
Index: ./ac-helpers/gnu-diff.sh
===================================================================
--- ./ac-helpers/gnu-diff.sh
+++ ./ac-helpers/gnu-diff.sh Mon Feb 11 19:03:11 2002
@@ -26,6 +26,14 @@
 
 patch=$1
 
+# Determine how to tell echo not to print the trailing \n.
+case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
+ *c*,-n*) ECHO_N= ECHO_C='
+' ECHO_T=' ' ;;
+ *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;;
+ *) ECHO_N= ECHO_C='\c' ECHO_T= ;;
+esac
+
 # Loop over $PATH, looking for `diff' binaries
 
 IFS=':'
@@ -36,11 +44,11 @@
         diff=$searchdir/$name
         if test -x $diff; then
             # create two identical one-line files (no newline endings)
- echo -n "some text, no newline" > foofile
+ echo $ECHO_N "some text, no newline$ECHO_C" > foofile
             cp foofile foofile2
 
             # append to the first file
- echo -n "...extra text, still no newline" >> foofile
+ echo $ECHO_N "...extra text, still no newline$ECHO_C" >> foofile
 
             # do a diff, create a patch.
             $diff -u foofile foofile2 > foofile.patch 2>/dev/null

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Oct 21 14:37:06 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.