emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Supporting parameters that include the = character in configure.bat


From: Ben Key
Subject: Supporting parameters that include the = character in configure.bat
Date: Sun, 10 Apr 2011 02:51:34 -0500

Hello,

I have seen several mentions on this list of the desire to make configure.bat support parameters that include the = character.  The --cflags parameter was mentioned specifically.  For example Eli Zaretskii wanted to be able to call configure.bat with --cflags -DSITELOAD_PURESIZE_EXTRA=100000.

There is a way to do this on Windows operating systems based on Windows NT.  The following batch file demonstrates how this might be accomplished.

<batch_file>
@echo off

set sep1=
:again

if "%1" == "--cflags" goto usercflags
if "%1" == "" goto checkutils

:usercflags
shift
set usercflags=%usercflags%%sep1%%~1
set sep1= %nothing%
shift
goto again

:checkutils

echo usercflags=%usercflags%
</batch_file>

The key here is the usage of the ~ character between the % and the 1.  This essentially causes " characters around the parameter to be removed.  Thus when this batch file is called as follows
  test.bat --cflags "-DSITELOAD_PURESIZE_EXTRA=100000" --cflags "-DTEST=1"
the output is as follows
  usercflags=-DSITELOAD_PURESIZE_EXTRA=100000 -DTEST=1

As long as the parameter is surrounded by " characters, the = character will not be treated as a separator.

The major drawback of this is that it will not work on Windows 9x because command.com does not support this functionality.  I see two possible solutions to this problem.  The first is to have two versions of configure.bat, a main version that uses this trick and another version that is backwards compatible with Windows 9x.  Another possible solution is to somehow have configure.bat test to see if this functionality is supported and use it if it is available and otherwise not use the functionality.  The following batch file shows how this might be accomplished.

<batch_file>
@echo off

set sep1=
:again

if "%1" == "--cflags" goto usercflags
if "%1" == "" goto checkutils

:usercflags

if "%OS%" == "Windows_NT" goto ucflagnt
goto ucflag9x

:ucflagnt
shift
set usercflags=%usercflags%%sep1%%~1
set sep1= %nothing%
shift
goto again

:ucflag9x
shift
set usercflags=%usercflags%%sep1%%1
set sep1= %nothing%
shift
goto again

:checkutils

echo usercflags=%usercflags%
</batch_file>

The drawback of this approach is that it would make an already complex batch file even more complex.  It does however make it possible to support a much needed feature, at least on Windows operating systems based on Windows NT, without the maintenance headache that using two batch files would introduce.


What do you all think about this approach?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]