809N/A/*
809N/A
809N/A Licensed to the Apache Software Foundation (ASF) under one or more
809N/A contributor license agreements. See the NOTICE file distributed with
809N/A this work for additional information regarding copyright ownership.
809N/A The ASF licenses this file to You under the Apache License, Version 2.0
809N/A (the "License"); you may not use this file except in compliance with
809N/A the License. You may obtain a copy of the License at
809N/A
809N/A http://www.apache.org/licenses/LICENSE-2.0
809N/A
809N/A Unless required by applicable law or agreed to in writing, software
809N/A distributed under the License is distributed on an "AS IS" BASIS,
809N/A WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
809N/A See the License for the specific language governing permissions and
809N/A limitations under the License.
809N/A
809N/ASET environment variables
809N/AFirst optional parameter:
809N/A ; parameters are considered parts of a path variable, semicolons are
809N/A appended to each element if not already present
809N/A -D parameters are properties for Java or Makefile etc., -D will be
809N/A prepended and the parameters will be separated by a space
809N/A =D the same as above but equal sign is not required
809N/A , parameters should be comma separated in the environment variable
809N/A - parameters should be separated by the next parameter
809N/A Other values mean that the first parameter is missing and the environment
809N/A variable will be set to the space separated parameters
809N/A
809N/ASecond parameter: name of the environment variable
809N/A
809N/ANext parameters: values
809N/A; implies that the equal sign is considered a part of the parameter and is
809N/Anot interpreted
809N/A
809N/A-D requires parameters in the form name=value. If the equal sign is not found,
809N/Athe parameters are changed to name=expanded_name
809N/A
809N/AOther options have optional equal sign. If it is found, only the part after
809N/Athe equal sign will be oprionally expanded.
809N/A
809N/AIf the parameter is the minus sign, the next parameter will not be expanded.
809N/AIf the parameter is a single dot, it will be replaced with the value of the
809N/Aenvironment variable as it existed before envset was invoked.
809N/A
809N/AFor other parameters the batch looks for the environment variable with the
809N/Asame name (in uppercase). If it is found, it forms the expanded_name. If
809N/Athe environment variable with such a name does not exist, the expanded_name
809N/Awill hold the parameter name without case conversion.
809N/A*/
809N/A
809N/Aparse arg mode envar args
809N/A
809N/Aequal = 0
809N/Asep = ' '
809N/A
809N/A/* Parse command line parameters */
809N/Aselect
809N/A when mode='-' then do
809N/A sep = envar
809N/A parse var args envar args
809N/A end
809N/A when mode=';' then do
809N/A sep = ''
809N/A equal = -1
809N/A end
809N/A when mode='-D' then equal = 1
809N/A when mode='=D' then mode = '-D'
809N/A when mode=',' then sep = ','
809N/Aotherwise
809N/A args = envar args
809N/A envar = mode
809N/A mode = ''
809N/Aend
809N/A
809N/Aenv = 'OS2ENVIRONMENT'
809N/Aenvar = translate(envar)
809N/Aorig = value(envar,,env)
809N/Anewval = ''
809N/Aexpand = 1
809N/A
809N/A/* for each parameter... */
809N/Ado i = 1 to words(args)
809N/A if expand > 0 & word(args, i) = '-' then expand = 0
809N/A else call addval word(args, i)
809N/Aend
809N/A
809N/A/* Optionally enclose path variable by quotes */
809N/Aif mode = ';' & pos(' ', newval) > 0 then newval = '"' || newval || '"'
809N/A
809N/A/* Set the new value, 'SET' cannot be used since it does not allow '=' */
809N/Ax = value(envar, newval, env)
809N/Aexit 0
809N/A
809N/Aaddval: procedure expose sep equal orig expand newval mode env
809N/Aparse arg var
809N/A
809N/Aif var = '.' then expvar = orig
809N/Aelse do
809N/A if equal >= 0 then do
809N/A parse var var name '=' val
809N/A if val = '' then var = name
809N/A else var = val
809N/A end
809N/A if expand = 0 then expvar = var
809N/A else expvar = value(translate(var),,env)
809N/A if expvar = '' then expvar = var
809N/A if equal >= 0 then do
809N/A if val = '' then do
809N/A parse var expvar key '=' val
809N/A if val <> '' then name = key
809N/A else do
809N/A if equal > 0 then val = key
809N/A else name = key
809N/A end
809N/A end
809N/A else val = expvar
809N/A if pos(' ', val) > 0 | pos('=', val) > 0 then val = '"' || val || '"'
809N/A if val = '' then expvar = name
809N/A else expvar = name || '=' || val
809N/A end
809N/A if mode = '-D' then expvar = '-D' || expvar
809N/A if mode = ';' then do
809N/A if right(expvar, 1) <> ';' then expvar = expvar || ';'
809N/A end
809N/Aend
809N/A
809N/Aif newval = '' then newval = expvar
809N/Aelse newval = newval || sep || expvar
809N/Aexpand = 1
809N/Areturn