Re: snippet of configure script - explain please

2008-07-10 Thread Mel
On Thursday 10 July 2008 06:24:46 Malcolm Kay wrote:

 9255 if { as_var=$as_ac_var; eval test \\${$as_var+set}\ = set; };
  then

 I find this line somewhat strange as I've not been able
 to find documentation for the expansion of ${parameter+set} under the
 Bourne shell. (nor bash, nor ksh)
 *
 Presumably someone out there knows where to find it?
 *

It's shorthand for ${paramter:+set}, so if unset, you get , otherwise you 
get set:
$ echo ${foo+set}

$ echo ${HOME+set}
set


-- 
Mel

Problem with today's modular software: they start with the modules
and never get to the software part.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: snippet of configure script - explain please

2008-07-10 Thread Malcolm Kay
On Thu, 10 Jul 2008 09:45 pm, Mel wrote:
 On Thursday 10 July 2008 06:24:46 Malcolm Kay wrote:
 
  9255 if { as_var=$as_ac_var; eval test \\${$as_var+set}\ = set; };
   then
 
  I find this line somewhat strange as I've not been able
  to find documentation for the expansion of ${parameter+set} under the
  Bourne shell. (nor bash, nor ksh)
  *
  Presumably someone out there knows where to find it?
  *
 
 It's shorthand for ${paramter:+set}, so if unset, you get , otherwise you 
 get set:
 $ echo ${foo+set}
 
 $ echo ${HOME+set}
 set

So it appears; but is it stated anywhere that this shorthand is legitimate?
I find it quite frequently arising from the GNU configuring tools but
haven't found it elsewhere.

Is it a deliberate shorthand or just a consequence of the way sh and bash 
happen to have been programmed? In other words is it a safe shorthand?

Anyway thanks for the clarification,

Malcolm 

 
 
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: snippet of configure script - explain please

2008-07-10 Thread Thomas Dickey
On Fri, Jul 11, 2008 at 12:18:42AM +0930, Malcolm Kay wrote:
 On Thu, 10 Jul 2008 09:45 pm, Mel wrote:
  On Thursday 10 July 2008 06:24:46 Malcolm Kay wrote:
  
   9255 if { as_var=$as_ac_var; eval test \\${$as_var+set}\ = set; 
};
then

it's interesting, but config.log would probably show the actual check
that was made to fill in the shell variable...

   I find this line somewhat strange as I've not been able
   to find documentation for the expansion of ${parameter+set} under the
   Bourne shell. (nor bash, nor ksh)
   *
   Presumably someone out there knows where to find it?
   *
  
  It's shorthand for ${paramter:+set}, so if unset, you get , otherwise you 
  get set:
  $ echo ${foo+set}
  
  $ echo ${HOME+set}
  set
 
 So it appears; but is it stated anywhere that this shorthand is legitimate?
 I find it quite frequently arising from the GNU configuring tools but
 haven't found it elsewhere.
 
 Is it a deliberate shorthand or just a consequence of the way sh and bash 
 happen to have been programmed? In other words is it a safe shorthand?

man sh on Solaris for instance:

 ${parameter:+word}
   If parameter is set and is non-null, substitute  word;
   otherwise substitute nothing.

 In the above, word is not evaluated unless it is to be  used
 as  the  substituted string, so that, in the following exam-
 ple, pwd is executed only if d is not set or is null:

  echo ${d:-`pwd`}



SunOS 5.8Last change: 9 May 19974

The same feature is on OpenBSD - I don't have FreeBSD at hand, but
think it's likely to be found in the manpage - I just looked for

/+.*}

-- 
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net


pgp4mLtSA3Vx5.pgp
Description: PGP signature


Re: snippet of configure script - explain please

2008-07-10 Thread Mel
On Thursday 10 July 2008 16:48:42 Malcolm Kay wrote:
 On Thu, 10 Jul 2008 09:45 pm, Mel wrote:
  On Thursday 10 July 2008 06:24:46 Malcolm Kay wrote:
   9255 if { as_var=$as_ac_var; eval test \\${$as_var+set}\ =
set; }; then
  
   I find this line somewhat strange as I've not been able
   to find documentation for the expansion of ${parameter+set} under the
   Bourne shell. (nor bash, nor ksh)
   *
   Presumably someone out there knows where to find it?
   *
 
  It's shorthand for ${paramter:+set}, so if unset, you get , otherwise
  you get set:
  $ echo ${foo+set}
 
  $ echo ${HOME+set}
  set

 So it appears; but is it stated anywhere that this shorthand is legitimate?
 I find it quite frequently arising from the GNU configuring tools but
 haven't found it elsewhere.

 Is it a deliberate shorthand or just a consequence of the way sh and bash
 happen to have been programmed? In other words is it a safe shorthand?

 Anyway thanks for the clarification,

Hmm, I'm not sure if the colon syntax came first. Autotools claims to create 
portable shell code, though they also claim to make software developer's 
lives easier.
The person to ask would probably be Doug Barton, since he's capable of writing 
things in shell, normal people would jump to a real language ;)
-- 
Mel

Problem with today's modular software: they start with the modules
and never get to the software part.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: snippet of configure script - explain please

2008-07-10 Thread Giorgos Keramidas
On Fri, 11 Jul 2008 00:18:42 +0930, Malcolm Kay [EMAIL PROTECTED] wrote:
 On Thu, 10 Jul 2008 09:45 pm, Mel wrote:
 On Thursday 10 July 2008 06:24:46 Malcolm Kay wrote:

  9255 if { as_var=$as_ac_var; eval test \\${$as_var+set}\ = set; };
   then
 
  I find this line somewhat strange as I've not been able
  to find documentation for the expansion of ${parameter+set} under the
  Bourne shell. (nor bash, nor ksh)
  *
  Presumably someone out there knows where to find it?
  *

 It's shorthand for ${paramter:+set}, so if unset, you get , otherwise you
 get set:
 $ echo ${foo+set}

 $ echo ${HOME+set}
 set

 So it appears; but is it stated anywhere that this shorthand is
 legitimate?  I find it quite frequently arising from the GNU
 configuring tools but haven't found it elsewhere.

It's legitimate.

 Is it a deliberate shorthand or just a consequence of the way sh and
 bash happen to have been programmed? In other words is it a safe
 shorthand?

The shorthand version would work too:

  if ${foo+set} = 'set' ; then
 bar
  fi

The interesting bits in the Autoconf generated code are, however, the
side-effects of the expression:

  * ${ac_var} is set to the name of the variable to check.

  * The `ac_var' variable is expanded *twice* in the check.  It is
expanded once before eval runs, to get the _name_ of the variable to
check, and then eval sees something like ${foo+set}.

  * The assignment to `ac_var' is done inside a { ... } pair of
brackets; not in parentheses.  This means that the rest of the
script can keep using ${ac_var} to find the name of the `autoconf
variable' this part of the script has set (the assignment to ac_var
happens in the current shell, and not in a sub-process).

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: snippet of configure script - explain please

2008-07-10 Thread Malcolm Kay
On Fri, 11 Jul 2008 12:34 am, Mel wrote:
 On Thursday 10 July 2008 16:48:42 Malcolm Kay wrote:
  On Thu, 10 Jul 2008 09:45 pm, Mel wrote:
   On Thursday 10 July 2008 06:24:46 Malcolm Kay wrote:
9255 if { as_var=$as_ac_var; eval test \\${$as_var+set}\ =
 set; }; then
   
I find this line somewhat strange as I've not been able
to find documentation for the expansion of ${parameter+set} under the
Bourne shell. (nor bash, nor ksh)
*
Presumably someone out there knows where to find it?
*
  
   It's shorthand for ${paramter:+set}, so if unset, you get , otherwise
   you get set:
   $ echo ${foo+set}
  
   $ echo ${HOME+set}
   set
 
  So it appears; but is it stated anywhere that this shorthand is legitimate?
  I find it quite frequently arising from the GNU configuring tools but
  haven't found it elsewhere.
 
  Is it a deliberate shorthand or just a consequence of the way sh and bash
  happen to have been programmed? In other words is it a safe shorthand?
 
  Anyway thanks for the clarification,
 
 Hmm, I'm not sure if the colon syntax came first.

Looks like your supposition is correct. I dug out an old DEC Ultrix manual 
which ducuments an 'sh' shell and a 'sh5' shell the 'sh' being the normal 
bsd version of the Bourne shell and 'sh5' being a compatibility version 
for system V scripts. The former (bsd version) does not use the ':' in 
parameter substitutions. But the system V version does.

 Autotools claims to create 
 portable shell code, though they 
 also claim to make software developer's 
 lives easier.


Malcolm
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: snippet of configure script - explain please

2008-07-10 Thread Matthew Seaman

Malcolm Kay wrote:

On Thu, 10 Jul 2008 09:45 pm, Mel wrote:

On Thursday 10 July 2008 06:24:46 Malcolm Kay wrote:


   9255 if { as_var=$as_ac_var; eval test \\${$as_var+set}\ = set; };
then

I find this line somewhat strange as I've not been able
to find documentation for the expansion of ${parameter+set} under the
Bourne shell. (nor bash, nor ksh)
*
Presumably someone out there knows where to find it?
*
It's shorthand for ${paramter:+set}, so if unset, you get , otherwise you 
get set:

$ echo ${foo+set}

$ echo ${HOME+set}
set


So it appears; but is it stated anywhere that this shorthand is legitimate?
I find it quite frequently arising from the GNU configuring tools but
haven't found it elsewhere.

Is it a deliberate shorthand or just a consequence of the way sh and bash 
happen to have been programmed? In other words is it a safe shorthand?


Anyway thanks for the clarification,


This syntax is certainly legitimate, and it is covered in the sh(1)
man page.  However, the relevant section talks mostly about the related
form:

 ${parameter:+word}

which means 'evaluate to null unless ${parameter} is unset or null, otherwise evaluate to 
word'.  Then there's a very small and easily
missed note to the effect:

 In the parameter expansions shown previously, use of the colon in the
  format results in a test for a parameter that is unset or null; omission
  of the colon results in a test for a parameter that is only unset.

So ${parameter+word} means 'evaluate to null unless ${parameter} is unset,
otherwise evaluate to word'

Cheers,

Matthew

--
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
 Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
 Kent, CT11 9PW



signature.asc
Description: OpenPGP digital signature


Re: snippet of configure script - explain please

2008-07-09 Thread Malcolm Kay
On Thu, 10 Jul 2008 02:55 am, Anton Shterenlikht wrote:
 I get errors building ports/graphviz on FBSD 6.3 on alpha.
 It seems the error is due to configure script erroneously
 deciding that there is no strncasecmp function on OS.
 
 Based on config.log:
 
 configure:9333: result: no
This probably the result for the previous check; probably strcasecmp

 configure:9253: checking for strncasecmp
 
 I think the following configure snippet is to blame.
 Could somebody explain, at least in general terms,
 what this piece of code does.
 
 many thanks
 anton
 
9249
9250 for ac_func in strcasecmp strncasecmp
9251 do
9252 as_ac_var=`echo ac_cv_func_$ac_func | $as_tr_sh`
This is eqivalent to:
  as_ac_var=ac_cv_func_strcasecmp
or:
  as_ac_var=ac_cv_func_strncasecmp
depending on which time through the loop.

9253 { echo $as_me:$LINENO: checking for $ac_func 5
9254 echo $ECHO_N checking for $ac_func... $ECHO_C 6; }
These lines simplly write reports of one type or another (including to 
config.log ?)
The $ECHO_N and $ECHO_C are to cater for different versions of 'echo' wrt line 
feeds.

9255 if { as_var=$as_ac_var; eval test \\${$as_var+set}\ = set; }; then
I find this line somewhat strange as I've not been able
to find documentation for the expansion of ${parameter+set} under the Bourne 
shell.
(nor bash, nor ksh)
*
Presumably someone out there knows where to find it?
*
But it seems that it returns set if parameter has been assigned a value and 
null otherwise.

Unless strcasecmp, strncasecmp have already been checked one expects these will 
fail
so the 'else' section is executed.


9256   echo $ECHO_N (cached) $ECHO_C 6
9257 else
9258   cat conftest.$ac_ext _ACEOF
9259 /* confdefs.h.  */
9260 _ACEOF
9261 cat confdefs.h conftest.$ac_ext
9262 cat conftest.$ac_ext _ACEOF
9263 /* end confdefs.h.  */
This is the start of the build of a C program to test if the library function 
exists.
But we've barely started -- the guts of the check is still to come.

One would expect that if it does not exist the configuration would implement
some alternative action so even then I would not expect the built to fail.

 where
 
 as_tr_sh :
 
 549 # Sed expression to map a string onto a valid variable name.
 550 as_tr_sh=eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'
 
 as_cr_alnum :
 
  40 as_cr_alnum=$as_cr_Letters$as_cr_digits
 
 as_me :
 
 132 # Name of the executable.
 133 as_me=`$as_basename -- $0 ||
 
 ECHO_N and ECHO_C :
 
 474 ECHO_C= ECHO_N= ECHO_T=
 475 case `echo -n x` in
 476 -n*)
 477   case `echo 'x\c'` in
 478   *c*) ECHO_T=' ';; # ECHO_T is single tab character.
 479   *)   ECHO_C='\c';;
 480   esac;;
 481 *)
 482   ECHO_N='-n';;
 483 esac
  
 

Best of luck,
Malcolm Kay
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]