source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/bootstrap/bin/envset.cmd@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.0 KB
Line 
1/*
2
3 Copyright 2003-2004 The Apache Software Foundation
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17SET environment variables
18First optional parameter:
19 ; parameters are considered parts of a path variable, semicolons are
20 appended to each element if not already present
21 -D parameters are properties for Java or Makefile etc., -D will be
22 prepended and the parameters will be separated by a space
23 =D the same as above but equal sign is not required
24 , parameters should be comma separated in the environment variable
25 - parameters should be separated by the next parameter
26 Other values mean that the first parameter is missing and the environment
27 variable will be set to the space separated parameters
28
29Second parameter: name of the environment variable
30
31Next parameters: values
32; implies that the equal sign is considered a part of the parameter and is
33not interpreted
34
35-D requires parameters in the form name=value. If the equal sign is not found,
36the parameters are changed to name=expanded_name
37
38Other options have optional equal sign. If it is found, only the part after
39the equal sign will be oprionally expanded.
40
41If the parameter is the minus sign, the next parameter will not be expanded.
42If the parameter is a single dot, it will be replaced with the value of the
43environment variable as it existed before envset was invoked.
44
45For other parameters the batch looks for the environment variable with the
46same name (in uppercase). If it is found, it forms the expanded_name. If
47the environment variable with such a name does not exist, the expanded_name
48will hold the parameter name without case conversion.
49*/
50
51parse arg mode envar args
52
53equal = 0
54sep = ' '
55
56/* Parse command line parameters */
57select
58 when mode='-' then do
59 sep = envar
60 parse var args envar args
61 end
62 when mode=';' then do
63 sep = ''
64 equal = -1
65 end
66 when mode='-D' then equal = 1
67 when mode='=D' then mode = '-D'
68 when mode=',' then sep = ','
69otherwise
70 args = envar args
71 envar = mode
72 mode = ''
73end
74
75env = 'OS2ENVIRONMENT'
76envar = translate(envar)
77orig = value(envar,,env)
78newval = ''
79expand = 1
80
81/* for each parameter... */
82do i = 1 to words(args)
83 if expand > 0 & word(args, i) = '-' then expand = 0
84 else call addval word(args, i)
85end
86
87/* Optionally enclose path variable by quotes */
88if mode = ';' & pos(' ', newval) > 0 then newval = '"' || newval || '"'
89
90/* Set the new value, 'SET' cannot be used since it does not allow '=' */
91x = value(envar, newval, env)
92exit 0
93
94addval: procedure expose sep equal orig expand newval mode env
95parse arg var
96
97if var = '.' then expvar = orig
98else do
99 if equal >= 0 then do
100 parse var var name '=' val
101 if val = '' then var = name
102 else var = val
103 end
104 if expand = 0 then expvar = var
105 else expvar = value(translate(var),,env)
106 if expvar = '' then expvar = var
107 if equal >= 0 then do
108 if val = '' then do
109 parse var expvar key '=' val
110 if val <> '' then name = key
111 else do
112 if equal > 0 then val = key
113 else name = key
114 end
115 end
116 else val = expvar
117 if pos(' ', val) > 0 | pos('=', val) > 0 then val = '"' || val || '"'
118 if val = '' then expvar = name
119 else expvar = name || '=' || val
120 end
121 if mode = '-D' then expvar = '-D' || expvar
122 if mode = ';' then do
123 if right(expvar, 1) <> ';' then expvar = expvar || ';'
124 end
125end
126
127if newval = '' then newval = expvar
128else newval = newval || sep || expvar
129expand = 1
130return
Note: See TracBrowser for help on using the repository browser.