cygwin-ENV-Variable
Igor Pechtchanski
pechtcha@cs.nyu.edu
Wed Aug 7 11:23:00 GMT 2002
On 5 Aug 2002, Robert Collins wrote:
> On Mon, 2002-08-05 at 12:39, Igor Pechtchanski wrote:
> > On Sun, 4 Aug 2002, Christopher Faylor wrote:
>
> > > The main reason this this is not documented is that there is no
> > > programmatic way to manipulate it and I am not comfortable with telling
> > > people how to edit the registry "by hand".
> > >
> > > However, if you are familiar with the registry, then setting this value
> > > should not be a big deal.
> > > cgf
> >
> > What about regtool? Or am I missing something?
>
> There is no abstracted way to manipulate it.
>
> i.e.:
> $ cygtweak --add-program-override --program=sshd --environment="foobar"
>
> regtool is the same as regedit from a user perspective.
>
> Rob
Robert,
Thanks for the explanation. I've attached a cygtweak script ;-). It
requires a patch to regtool (also attached), since the current version is
unable to create/modify values with '\\' in them. Does it look
reasonable?
Igor
P.S. cygtweak sounds wrong. Feel free to rename it.
--
http://cs.nyu.edu/~pechtcha/
|\ _,,,---,,_ pechtcha@cs.nyu.edu
ZZZzz /,`.-'`' -. ;-;;,_ igor@watson.ibm.com
|,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski
'---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!
It took the computational power of three Commodore 64s to fly to the moon.
It takes a 486 to run Windows 95. Something is wrong here. -- SC sig file
-------------- next part --------------
#!/bin/sh
#
# cygtweak -- add or remove program-specific values for the CYGWIN
# environment variable.
#
# Copyright (c) 2002, Igor Pechtchanski.
#
# You may distribute under the terms of the GNU General Public
# License.
#
# Igor Pechtchanski
# pechtcha@cs.nyu.edu
# Department of Computer Science
# New York University
# New York, NY 10003
#
# cygtweak v0.1
#
if [ "$1" = debug ]; then
set -x
shift
fi
progname=`basename $0`
version='0.1'
REGTOOL=/usr/bin/regtool
REGKEY="/HKLM/SOFTWARE/Cygnus Solutions/Cygwin/Program Options"
if [ ! -x $REGTOOL ]; then
echo "$progname: Can't find $REGTOOL, exiting." 1>&2
exit 1
fi
while [ $# -ne 0 ]; do
case $1 in
-v | --verbose)
verbose="YES" ;;
-n | --noexec)
verbose="YES"
noexec="YES" ;;
-a | --add-program-override)
if [ -n "$action" ]; then
echo "$progname: Please specify only one action." 1>&2
exit 0
fi
action="ADD"
program="$2"
cygwin="$3"
shift
shift;;
-r | --remove-program-override)
if [ -n "$action" ]; then
echo "$progname: Please specify only one action." 1>&2
exit 0
fi
action="REMOVE"
program="$2"
shift;;
-e | --export)
if [ -z "$action" ]; then
echo "$progname: Please specify an action first." 1>&2
elif [ "$action" != ADD ]; then
echo "$progname: Warning: -e ignored for -r." 1>&2
else
export="YES"
fi;;
-V | -?version)
echo $progname: version $version 1>&2
exit 0 ;;
-h | -?help)
echo "Usage: $progname [-v|-n] action action-specific-params" 1>&2
echo " where action is one of" 1>&2
echo " -a|--add-program-override program \$CYGWIN-value [-e|--export]" 1>&2
echo " adds an override for the value of the CYGWIN variable" 1>&2
echo " when invoking the program" 1>&2
echo " --export exports the value to all children of the given program" 1>&2
echo " -r|--remove-program-override program" 1>&2
echo " removes an override for a given program" 1>&2
echo 1>&2
echo "If --verbose or -v is specified, the registry modification actions are printed" 1>&2
echo "If --noexec or -n is specified, no commands that change the registry will be run" 1>&2
echo " Note that --noexec implies --verbose" 1>&2
echo 1>&2
echo "Examples: $progname -v --add-program-override /usr/sbin/inetd 'tty' -export" 1>&2
echo " $progname --remove-program-override /usr/sbin/sshd" 1>&2
exit 0 ;;
*)
echo "$progname: Invalid argument(s)." 1>&2
echo "Try '$progname --help' for more information." 1>&2
exit 1 ;;
esac
shift
done
if [ -z "$action" ]; then
echo "$progname: Missing argument(s)." 1>&2
echo "Try '$progname --help' for more information." 1>&2
exit 1
fi
case $program in
/*) program=`cygpath -w "$program" | sed 's/\\\\/\\\\\\\\/g'` ;;
esac
case $action in
ADD)
# First check if the key exists
if ! $REGTOOL -q check "$REGKEY"; then
if [ -n "$verbose" ]; then
echo "$progname: \"$REGKEY\" not found, adding."
fi
if [ -z "$noexec" ]; then
$REGTOOL add "$REGKEY"
else
echo "$REGTOOL add \"$REGKEY\""
fi
fi
# Tack on "export" if needed
if [ -n "$export" ]; then
cygwin="$cygwin export"
fi
# Now add the corresponding value
if [ -z "$noexec" ]; then
$REGTOOL -K@ -s set "$REGKEY@$program" "$cygwin"
exit $?
else
echo "$REGTOOL -K@ -s set \"$REGKEY@$program\" \"$cygwin\""
fi
;;
REMOVE)
# Remove the corresponding value
if [ -z "$noexec" ]; then
$REGTOOL -K@ unset "$REGKEY@$program"
exit $?
else
echo "$REGTOOL -K@ unset \"$REGKEY@$program\""
fi
;;
esac
-------------- next part --------------
Index: utils/regtool.cc
===================================================================
RCS file: /cvs/src/src/winsup/utils/regtool.cc,v
retrieving revision 1.10
diff -u -p -2 -r1.10 regtool.cc
--- utils/regtool.cc 7 Jun 2002 11:12:16 -0000 1.10
+++ utils/regtool.cc 7 Aug 2002 16:53:46 -0000
@@ -15,4 +15,6 @@ details. */
#include <windows.h>
+#define DEFAULT_KEY_SEPARATOR '\\'
+
enum
{
@@ -20,4 +22,6 @@ enum
} key_type = KT_AUTO;
+char key_sep = DEFAULT_KEY_SEPARATOR;
+
#define LIST_KEYS 0x01
#define LIST_VALS 0x02
@@ -40,8 +44,9 @@ static struct option longopts[] =
{"verbose", no_argument, NULL, 'v'},
{"version", no_argument, NULL, 'V'},
+ {"key-separator", required_argument, NULL, 'K'},
{NULL, 0, NULL, 0}
};
-static char opts[] = "ehiklmpqsvV";
+static char opts[] = "ehiklmpqsvVK::";
int listwhat = 0;
@@ -84,4 +89,7 @@ usage (FILE *where = stderr)
" -s, --string set type to REG_SZ\n"
"\n"
+ "Options for 'set' and 'unset' Actions:\n"
+ " -K<c>, --key-separator[=]<c> set key separator to <c> instead of '\\'\n"
+ "\n"
"Other Options:\n"
" -h, --help output usage information and exit\n"
@@ -309,7 +317,7 @@ find_key (int howmanyparts, REGSAM acces
if (howmanyparts > 1)
{
- while (n < e && *e != '\\')
+ while (n < e && *e != key_sep)
e--;
- if (*e != '\\')
+ if (*e != key_sep)
{
key = wkprefixes[i].key;
@@ -662,4 +670,7 @@ main (int argc, char **_argv)
print_version ();
exit (0);
+ case 'K':
+ key_sep = *optarg;
+ break;
default :
usage ();
-------------- next part --------------
2002-08-07 Igor Pechtchanski <pechtcha@cs.nyu.edu>
* regtool.cc (find_key): Add support for custom key separator.
(usage): Document it.
-------------- next part --------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list