1/*
2   Licensed to the Apache Software Foundation (ASF) under one or more
3   contributor license agreements.  See the NOTICE file distributed with
4   this work for additional information regarding copyright ownership.
5   The ASF licenses this file to You under the Apache License, Version 2.0
6   (the "License"); you may not use this file except in compliance with
7   the License.  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*/
17
18'@echo off'
19call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
20call SysLoadFuncs
21
22/* Prepare the parameters for later use */
23parse arg argv
24mode = ''
25args = ''
26opts = ''
27cp = ''
28lcp = ''
29
30do i = 1 to words(argv)
31  param = word(argv, i)
32  select
33    when param='-lcp' then mode = 'l'
34    when param='-cp' | param='-classpath' then mode = 'c'
35    when abbrev('-opts', param, 4) then mode = 'o'
36    when abbrev('-args', param, 4) then mode = 'a'
37  otherwise
38    select
39      when mode = 'a' then args = space(args param, 1)
40      when mode = 'c' then cp = space(cp param, 1)
41      when mode = 'l' then lcp = space(lcp param, 1)
42      when mode = 'o' then opts = space(opts param, 1)
43    otherwise
44      say 'Option' param 'ignored'
45    end
46  end
47end
48
49env="OS2ENVIRONMENT"
50antconf = _getenv_('antconf' 'antconf.cmd')
51runrc = _getenv_('runrc')
52interpret 'call "' || runrc || '"' '"' || antconf || '"' 'ETC'
53ANT_HOME = value('ANT_HOME',,env)
54JAVA_HOME = value('JAVA_HOME',,env)
55classpath = value('CLASSPATH',,env)
56classes = stream(JAVA_HOME || "\lib\classes.zip", "C", "QUERY EXISTS")
57if classes \= '' then classpath = prepend(classpath classes)
58classes = stream(JAVA_HOME || "\lib\tools.jar", "C", "QUERY EXISTS")
59if classes \= '' then classpath = prepend(classpath classes)
60
61classpath = prepend(classpath ANT_HOME || '\lib\ant-launcher.jar')
62'SET CLASSPATH=' || classpath
63
64/* Setting classpathes, options and arguments */
65envset = _getenv_('envset')
66if cp\=''   then interpret 'call "' || envset || '"' '"; CLASSPATH"' '"' || cp || '"'
67if lcp\=''  then interpret 'call "' || envset || '"' '"; LOCALCLASSPATH"' '"' || lcp || '"'
68if opts\='' then interpret 'call "' || envset || '"' '"-D ANT_OPTS"' '"' || opts || '"'
69if args\='' then interpret 'call "' || envset || '"' '"ANT_ARGS"' '"' || args || '"'
70
71exit 0
72
73addpath: procedure
74parse arg path elem
75if elem = '' then do
76  if path\='' & right(path, 1)\=';' then path = path || ';'
77  return path
78end
79if substr(path, length(path)) = ';' then glue = ''
80else glue = ';'
81if pos(translate(elem), translate(path)) = 0 then path = path || glue || elem || ';'
82return path
83
84prepend: procedure
85parse arg path elem
86if elem = '' then do
87  if path\='' & right(path, 1)\=';' then path = path || ';'
88  return path
89end
90if pos(translate(elem), translate(path)) = 0 then path = elem || ';' || path
91return path
92
93_getenv_: procedure expose env
94parse arg envar default
95if default = '' then default = envar
96var = value(translate(envar),,env)
97if var = '' then var = default
98return var
99