2 echo this is a rexx script
!
7 * Environment setup script
for OS
/2.
12 * Copyright
(c
) 1999-2009 knut st. osmundsen
<bird
-kBuild
-spamix@anduin.
net>
14 * This file is part of kBuild.
16 * kBuild is free software
; you can redistribute it and
/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation
; either version
2 of the License
, or
19 * (at your option
) any later version.
21 * kBuild is distributed in the hope that it will be useful
,
22 * but WITHOUT ANY WARRANTY
; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License
for more details.
26 * You should have received a
copy of the GNU General Public License
27 * along with kBuild
; if not, write to the Free Software
28 * Foundation
, Inc.
, 59 Temple Place
, Suite
330, Boston
, MA
02111-1307 USA
34 * Setup the usual suspects.
36 Address
CMD '@echo off';
37 signal on novalue name NoValueHandler
38 if (RxFuncQuery
('SysLoadFuncs') = 1) then
40 call RxFuncAdd
'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs';
45 * Apply the
CMD.EXE workaround.
52 skBuildPath
= EnvGet
("KBUILD_PATH");
53 skBuildBinPath
= EnvGet
("KBUILD_BIN_PATH");
54 skBuildType
= EnvGet
("KBUILD_TYPE");
55 skBuildTarget
= EnvGet
("KBUILD_TARGET");
56 skBuildTargetArch
= EnvGet
("KBUILD_TARGET_ARCH");
57 skBuildTargetCpu
= EnvGet
("KBUILD_TARGET_CPU");
58 skBuildHost
= EnvGet
("KBUILD_HOST");
59 skBuildHostArch
= EnvGet
("KBUILD_HOST_ARCH");
60 skBuildHostCpu
= EnvGet
("KBUILD_HOST_CPU");
75 fOptOverrideTarget
= 0;
76 fOptOverrideTargetArch
= 0;
80 do while
(sArgs
<> '')
81 parse value sArgs with sArg sRest
87 when (sArg
= "--debug-script") then do
90 when (sArg
= "--no-debug-script") then do
93 when (sArg
= "--quiet") then do
96 when (sArg
= "--verbose") then do
99 when (sArg
= "--full") then do
102 when (sArg
= "--normal") then do
105 when (sArg
= "--legacy") then do
108 when (sArg
= "--no-legacy") then do
111 when (sArg
= "--eval") then do
112 say "error: --eval is not supported on OS/2."
114 when (sArg
= "--var") then do
115 parse value sRest with sVar sRest2
117 if (sVar
= '') then do
118 say "syntax error: --var is missing the variable name";
122 if (sVar
= "all" | sOptVars
= "all") then
125 sOptVars
= sOptVars ||
" " || sVar
;
127 when (sArg
= "--set") then do
128 sShowVarPrefix
= "SET ";
130 when (sArg
= "--no-set") then do
133 when (sArg
= "--value-only") then do
136 when (sArg
= "--name-and-value") then do
139 when (sArg
= "--release") then do
140 fOptOverrideType
= 1;
142 skBuildType
= 'release';
144 when (sArg
= "--debug") then do
145 fOptOverrideType
= 1;
147 skBuildType
= 'debug';
149 when (sArg
= "--profile") then do
150 fOptOverrideType
= 1;
152 skBuildType
= 'profile';
154 when (sArg
= "--defaults") then do
158 skBuildTargetArch
= "";
159 skBuildTargetCpu
= "";
161 skBuildHostArch
= "";
167 when (sArg
= "--help" | sArg
= "-h" | sArg
= "-?" | sArg
= "/?" | sArg
= "/h") then do
168 say "kBuild Environment Setup Script, v0.1.4"
170 say "syntax: envos2.cmd [options] [command [args]]"
171 say " or: envos2.cmd [options] --var <varname>"
173 say "The first form will execute the command, or if no command is given"
174 say "modify the current invoking shell."
175 say "The second form will print the specfified variable(s)."
178 say " --debug, --release, --profile"
179 say " Alternative way of specifying KBUILD_TYPE."
181 say " Enforce defaults for all the KBUILD_* values."
182 say " --debug-script, --no-debug-script"
183 say " Controls debug output. Default: --no-debug-script"
184 say " --quiet, --verbose"
185 say " Controls informational output. Default: --verbose"
186 say " --full, --normal"
187 say " Controls the variable set. Default: --normal"
188 say " --legacy, --no-legacy"
189 say " Include legacy variables in result. Default: --no-legacy"
190 say " --value-only, --name-and-value"
191 say " Controls what the result of a --var query. Default: --name-and-value"
192 say " --set, --no-set"
193 say " Whether to prefix the variable output with 'SET'."
194 say " Default: --no-set"
199 when (sArg
= "--") then do
204 when (left
(sArg
, 2) = '--') then do
205 say 'syntax error: unknown option: '||sArg
216 sCommand
= strip
(sArgs
);
219 * Deal with legacy environment variables.
221 if (\fOptOverrideAll
) then do
222 if (EnvGet
("PATH_KBUILD") <> '') then do
223 if (skBuildPath
<> '' & skBuildPath
<> EnvGet
("PATH_KBUILD")) then do
224 say "error: KBUILD_PATH ("||skBuildPath||
") and PATH_KBUILD ("||EnvGet
("PATH_KBUILD")||
") disagree."
228 skBuildPath
= EnvGet
("PATH_KBUILD");
231 if (EnvGet
("PATH_KBUILD_BIN") <> '') then do
232 if (skBuildPath
<> '' & skBuildBinPath
<> EnvGet
("PATH_KBUILD_BIN")) then do
233 say "error: KBUILD_BIN_PATH ("||skBuildBinPath||
") and PATH_KBUILD_BIN ("||EnvGet
("PATH_KBUILD_BIN")||
") disagree."
237 skBuildBinPath
= EnvGet
("PATH_KBUILD_BIN");
240 if (EnvGet
("BUILD_TYPE") <> '') then do
241 if (skBuildType
<> '' & skBuildType
<> EnvGet
("BUILD_TYPE")) then do
242 say "error: KBUILD_TYPE ("||skBuildType||
") and BUILD_TYPE ("||EnvGet
("BUILD_TYPE")||
") disagree."
246 skBuildType
= EnvGet
("BUILD_TYPE");
249 if (EnvGet
("BUILD_TARGET") <> '') then do
250 if (skBuildTarget
<> '' & skBuildTarget
<> EnvGet
("BUILD_TARGET")) then do
251 say "error: KBUILD_TARGET ("||skBuildTarget||
") and BUILD_TARGET ("||EnvGet
("BUILD_TARGET")||
") disagree."
255 skBuildTarget
= EnvGet
("BUILD_TARGET");
258 if (EnvGet
("BUILD_TARGET_ARCH") <> '') then do
259 if (skBuildTargetArch
<> '' & skBuildTargetArch
<> EnvGet
("BUILD_TARGET_ARCH")) then do
260 say "error: KBUILD_TARGET_ARCH ("||skBuildTargetArch ||
") and BUILD_TARGET_ARCH ("||EnvGet
("BUILD_TARGET_ARCH")||
") disagree."
264 skBuildTargetArch
= EnvGet
("BUILD_TARGET_ARCH");
267 if (EnvGet
("BUILD_TARGET_CPU") <> '') then do
268 if (skBuildTargetCpu
<> '' & skBuildTargetCpu
<> EnvGet
("BUILD_TARGET_CPU")) then do
269 say "error: KBUILD_TARGET_CPU ("||skBuildTargetCpu ||
") and BUILD_TARGET_CPU ("||EnvGet
("BUILD_TARGET_CPU")||
") disagree."
273 skBuildTargetCpu
= EnvGet
("BUILD_TARGET_CPU");
276 if (EnvGet
("BUILD_PLATFORM") <> '') then do
277 if (skBuildHost
<> '' & skBuildHost
<> EnvGet
("BUILD_PLATFORM")) then do
278 say "error: KBUILD_HOST ("||skBuildHost||
") and BUILD_PLATFORM ("||EnvGet
("BUILD_PLATFORM")||
") disagree."
282 if (skBuildHost
= '' & EnvGet
("BUILD_PLATFORM") = "OS2") then do
283 say "error: BUILD_PLATFORM=OS2! Please unset it or change it to 'os2'."
287 skBuildHost
= EnvGet
("BUILD_PLATFORM");
290 if (EnvGet
("BUILD_PLATFORM_ARCH") <> '') then do
291 if (skBuildHostArch
<> '' & skBuildHostArch
<> EnvGet
("BUILD_PLATFORM_ARCH")) then do
292 say "error: KBUILD_HOST_ARCH ("||skBuildHostArch ||
") and BUILD_PLATFORM_ARCH ("||EnvGet
("BUILD_PLATFORM_ARCH")||
") disagree."
296 skBuildHostArch
= EnvGet
("BUILD_PLATFORM_ARCH");
299 if (EnvGet
("BUILD_PLATFORM_CPU") <> '') then do
300 if (skBuildHostCpu
<> '' & skBuildHostCpu
<> EnvGet
("BUILD_PLATFORM_CPU")) then do
301 say "error: KBUILD_HOST_CPU ("||skBuildHostCpu ||
") and BUILD_PLATFORM_CPU ("||EnvGet
("BUILD_PLATFORM_CPU")||
") disagree."
305 skBuildHostCpu
= EnvGet
("BUILD_PLATFORM_CPU");
310 * Set default build
type.
312 if (skBuildType
= '') then
313 skBuildType
= 'release';
314 if (fOptDbg
<> 0) then say "dbg: KBUILD_TYPE="||skBuildType
317 * Determin the host platform
(OS
/2)
319 if (skBuildHost
= '') then
321 if (fOptDbg
<> 0) then say "dbg: KBUILD_HOST="||skBuildHost
323 if (skBuildHostArch
= '') then do
325 when (skBuildHostCpu
= 'i386',
326 | skBuildHostCpu
= 'i486',
327 | skBuildHostCpu
= 'i586',
328 | skBuildHostCpu
= 'i686',
329 | skBuildHostCpu
= 'i786',
330 | skBuildHostCpu
= 'i886',
331 | skBuildHostCpu
= 'i986') then do
332 skBuildHostArch
= "x86";
335 skBuildHostArch
= "x86";
339 if (fOptDbg
<> 0) then say "dbg: KBUILD_HOST_ARCH="||skBuildHostArch
341 if (skBuildHostCpu
= '') then
342 skBuildHostCpu
= 'blend';
343 if (fOptDbg
<> 0) then say "dbg: KBUILD_HOST_CPU="||skBuildHostCpu
347 * The target platform.
348 * Defaults to the host
when not specified.
350 if (skBuildTarget
= '') then
351 skBuildTarget
= skBuildHost
;
352 if (fOptDbg
<> 0) then say "dbg: KBUILD_TARGET="||skBuildTarget
354 if (skBuildTargetArch
= '') then
355 skBuildTargetArch
= skBuildHostArch
;
356 if (fOptDbg
<> 0) then say "dbg: KBUILD_TARGET_ARCH="||skBuildTargetArch
358 if (skBuildTargetCpu
= '') then do
359 if (skBuildTargetArch
= skBuildHostArch
) then
360 skBuildTargetCpu
= skBuildHostCpu
;
362 skBuildTargetCpu
= "blend";
364 if (fOptDbg
<> 0) then say "dbg: KBUILD_TARGET_CPU="||skBuildTargetCpu
368 * Determin KBUILD_PATH from the script location and calc KBUILD_BIN_PATH from there.
370 if (skBuildPath
= '') then do
371 skBuildPath
= GetScriptDir
()
373 skBuildPath
= translate
(skBuildPath
, '/', '\')
374 if ( FileExists(skBuildPath||"/footer.kmk") = 0,
375 | FileExists(skBuildPath||"/header.kmk") = 0,
376 | FileExists(skBuildPath||"/rules.kmk") = 0) then do
377 say "error: KBUILD_PATH ("skBuildPath||") is not pointing to a popluated kBuild directory."
381 if (fOptDbg <> 0) then say "dbg: KBUILD_PATH="||skBuildPath;
383 if (skBuildBinPath = '') then do
384 skBuildBinPath = skBuildPath||'/bin
/'||skBuildHost||'.
'||skBuildHostArch;
386 skBuildBinPath = translate(skBuildBinPath, '/', '\')
387 if (fOptDbg
<> 0) then say "dbg: KBUILD_BIN_PATH="||skBuildBinPath
;
390 * Add the bin
/x.y
/ directory to the
PATH and BEGINLIBPATH.
391 * NOTE
! Once bootstrapped this is the only thing that is actually necessary.
393 sOldPath
= EnvGet
("PATH");
394 call EnvAddFront
0, "PATH", translate
(skBuildBinPath
, '\', '/');
395 sNewPath = EnvGet("PATH");
396 call EnvSet 0, "PATH", sOldPath;
397 if (fOptDbg <> 0) then say "dbg: PATH="||sNewPath;
399 sOldBeginLibPath = EnvGet("BEGINLIBPATH");
400 call EnvAddFront 0, "BEGINLIBPATH", translate(skBuildBinPath, '\', '/');
401 sNewBeginLibPath
= EnvGet
("BEGINLIBPATH");
402 call EnvSet
0, "BEGINLIBPATH", sOldBeginLibPath
;
403 if (fOptDbg
<> 0) then say "dbg: BEGINLIBPATH="||sNewBeginLibPath
;
408 if (DirExists
(skBuildBinPath
) = 0) then
409 say "warning: The bin directory for the build platform doesn't exist. ("||skBuildBinPath||
")";
412 sPrograms
= "kmk kDepPre kDepIDB kmk_append kmk_ash kmk_cat kmk_cp kmk_echo kmk_install kmk_ln kmk_mkdir kmk_mv kmk_redirect kmk_rm kmk_rmdir kmk_sed";
413 do i
= 1 to words
(sPrograms
)
414 sProgram
= word
(sPrograms
, i
);
415 if (FileExists
(skBuildBinPath||
"\"||sProgram||".exe
") = 0) then
416 say "warning
: The
"||sProgram||" program doesn
't exit for this platform. ("||skBuildBinPath||")";
422 * The environment is in place, now take the requested action.
425 if (sOptVars <> '') then
427 if (sOptVars = "all") then
428 sOptVars = "KBUILD_PATH KBUILD_BIN_PATH KBUILD_TYPE ",
429 || "KBUILD_TARGET KBUILD_TARGET_ARCH KBUILD_TARGET_CPU ",
430 || "KBUILD_HOST KBUILD_HOST_ARCH KBUILD_HOST_CPU ";
432 /* Echo variable values or variable export statements. */
433 do i = 1 to words(sOptVars)
434 sVar = word(sOptVars, i)
437 when (sVar = "PATH") then sVal = sNewPath;
438 when (sVar = "BEGINLIBPATH") then sVal = sNewBeginLibPath;
439 when (sVar = "KBUILD_PATH") then sVal = skBuildPath;
440 when (sVar = "KBUILD_BIN_PATH") then sVal = skBuildBinPath;
441 when (sVar = "KBUILD_TYPE") then sVal = skBuildType;
442 when (sVar = "KBUILD_HOST") then sVal = skBuildHost;
443 when (sVar = "KBUILD_HOST_ARCH") then sVal = skBuildHostArch;
444 when (sVar = "KBUILD_HOST_CPU") then sVal = skBuildHostCpu;
445 when (sVar = "KBUILD_TARGET") then sVal = skBuildTarget;
446 when (sVar = "KBUILD_TARGET_ARCH") then sVal = skBuildTargetArch;
447 when (sVar = "KBUILD_TARGET_CPU") then sVal = skBuildTargetCpu;
449 say "error: Unknown variable "||sVar||" specified in --var request."
455 if (fOptValueOnly <> 0) then
458 say sShowVarPrefix||sVar||"="||sVal;
463 /* Wipe out all variables - legacy included - with --default. */
464 if (fOptOverrideAll <> 0) then do
465 call EnvSet 0, KBUILD_PATH, ''
466 call EnvSet 0, KBUILD_BIN_PATH, ''
467 call EnvSet 0, KBUILD_HOST, ''
468 call EnvSet 0, KBUILD_HOST_ARCH, ''
469 call EnvSet 0, KBUILD_HOST_CPU, ''
470 call EnvSet 0, KBUILD_TARGET, ''
471 call EnvSet 0, KBUILD_TARGET_ARCH, ''
472 call EnvSet 0, KBUILD_TARGET_CPU, ''
474 call EnvSet 0, PATH_KBUILD, ''
475 call EnvSet 0, PATH_KBUILD_BIN, ''
476 call EnvSet 0, BUILD_PLATFORM, ''
477 call EnvSet 0, BUILD_PLATFORM_ARCH, ''
478 call EnvSet 0, BUILD_PLATFORM_CPU, ''
479 call EnvSet 0, BUILD_TARGET, ''
480 call EnvSet 0, BUILD_TARGET_ARCH, ''
481 call EnvSet 0, BUILD_TARGET_CPU, ''
484 /* Export the variables. */
485 call EnvSet 0, "PATH", sNewPath
486 call EnvSet 0, "BEGINLIBPATH", sNewBeginLibPath
487 if (fOptOverrideType <> 0) then call EnvSet 0, "KBUILD_TYPE", skBuildType
488 if (fOptFull <> 0) then do
489 call EnvSet 0, KBUILD_PATH, skBuildPath
490 call EnvSet 0, KBUILD_HOST, skBuildHost
491 call EnvSet 0, KBUILD_HOST_ARCH, skBuildHostArch
492 call EnvSet 0, KBUILD_HOST_CPU, skBuildHostCpu
493 call EnvSet 0, KBUILD_TARGET, skBuildTarget
494 call EnvSet 0, KBUILD_TARGET_ARCH, skBuildTargetArch
495 call EnvSet 0, KBUILD_TARGET_CPU, skBuildTargetCpu
497 if (fOptLegacy <> 0) then do
498 call EnvSet 0, PATH_KBUILD, skBuildPath
499 call EnvSet 0, BUILD_PLATFORM, skBuildHost
500 call EnvSet 0, BUILD_PLATFORM_ARCH, skBuildHostArch
501 call EnvSet 0, BUILD_PLATFORM_CPU, skBuildHostCpu
502 call EnvSet 0, BUILD_TARGET, skBuildTarget
503 call EnvSet 0, BUILD_TARGET_ARCH, skBuildTargetArch
504 call EnvSet 0, BUILD_TARGET_CPU, skBuildTargetCpu
509 * Execute left over arguments.
511 if (strip(sCommand) <> '') then do
512 if (fOptQuiet <> 0) then say "info: Executing command: "|| sCommand
515 if (fOptQuiet <> 0 & iRc <> 0) then say "info: rc="||iRc||": "|| sCommand
518 if (fOptDbg <> 0) then say "dbg: finished (rc="||rc||")"
522 /*******************************************************************************
523 * Procedure Section *
524 *******************************************************************************/
527 * Give the script syntax
530 say 'syntax
: envos2.
cmd [command to be executed and its arguments
]'
539 say 'NoValueHandler
: line
'SIGL;
545 * Add sToAdd in front of sEnvVar.
546 * Note: sToAdd now is allowed to be alist!
548 * Known features: Don't remove sToAdd from original value
if sToAdd
549 * is at the
end and don
't end with a ';'.
551 EnvAddFront: procedure
552 parse arg fRM, sEnvVar, sToAdd, sSeparator
554 /* sets default separator if not specified. */
555 if (sSeparator = '') then sSeparator = ';';
557 /* checks that sToAdd ends with an ';'. Adds one if not. */
558 if (substr(sToAdd, length(sToAdd), 1) <> sSeparator) then
559 sToAdd = sToAdd || sSeparator;
561 /* check and evt. remove ';' at start of sToAdd */
562 if (substr(sToAdd, 1, 1) = ';') then
563 sToAdd = substr(sToAdd, 2);
565 /* loop thru sToAdd */
568 do while i > 1 & rc = 0
569 j = lastpos(sSeparator, sToAdd, i-1);
570 rc = EnvAddFront2(fRM, sEnvVar, substr(sToAdd, j+1, i - j), sSeparator);
577 * Add sToAdd in front of sEnvVar.
579 * Known features: Don't remove sToAdd from original value
if sToAdd
580 * is at the
end and don
't end with a ';'.
582 EnvAddFront2: procedure
583 parse arg fRM, sEnvVar, sToAdd, sSeparator
585 /* sets default separator if not specified. */
586 if (sSeparator = '') then sSeparator = ';';
588 /* checks that sToAdd ends with a separator. Adds one if not. */
589 if (substr(sToAdd, length(sToAdd), 1) <> sSeparator) then
590 sToAdd = sToAdd || sSeparator;
592 /* check and evt. remove the separator at start of sToAdd */
593 if (substr(sToAdd, 1, 1) = sSeparator) then
594 sToAdd = substr(sToAdd, 2);
596 /* Get original variable value */
597 sOrgEnvVar = EnvGet(sEnvVar);
599 /* Remove previously sToAdd if exists. (Changing sOrgEnvVar). */
600 i = pos(translate(sToAdd), translate(sOrgEnvVar));
602 sOrgEnvVar = substr(sOrgEnvVar, 1, i-1) || substr(sOrgEnvVar, i + length(sToAdd));
604 /* set environment */
606 return EnvSet(0, sEnvVar, sOrgEnvVar);
607 return EnvSet(0, sEnvVar, sToAdd||sOrgEnvVar);
611 * Add sToAdd as the end of sEnvVar.
612 * Note: sToAdd now is allowed to be alist!
614 * Known features: Don't remove sToAdd from original value
if sToAdd
615 * is at the
end and don
't end with a ';'.
618 parse arg fRM, sEnvVar, sToAdd, sSeparator
620 /* sets default separator if not specified. */
621 if (sSeparator = '') then sSeparator = ';';
623 /* checks that sToAdd ends with a separator. Adds one if not. */
624 if (substr(sToAdd, length(sToAdd), 1) <> sSeparator) then
625 sToAdd = sToAdd || sSeparator;
627 /* check and evt. remove ';' at start of sToAdd */
628 if (substr(sToAdd, 1, 1) = sSeparator) then
629 sToAdd = substr(sToAdd, 2);
631 /* loop thru sToAdd */
634 do while i > 1 & rc = 0
635 j = lastpos(sSeparator, sToAdd, i-1);
636 rc = EnvAddEnd2(fRM, sEnvVar, substr(sToAdd, j+1, i - j), sSeparator);
644 * Add sToAdd as the end of sEnvVar.
646 * Known features: Don't remove sToAdd from original value
if sToAdd
647 * is at the
end and don
't end with a ';'.
649 EnvAddEnd2: procedure
650 parse arg fRM, sEnvVar, sToAdd, sSeparator
652 /* sets default separator if not specified. */
653 if (sSeparator = '') then sSeparator = ';';
655 /* checks that sToAdd ends with a separator. Adds one if not. */
656 if (substr(sToAdd, length(sToAdd), 1) <> sSeparator) then
657 sToAdd = sToAdd || sSeparator;
659 /* check and evt. remove separator at start of sToAdd */
660 if (substr(sToAdd, 1, 1) = sSeparator) then
661 sToAdd = substr(sToAdd, 2);
663 /* Get original variable value */
664 sOrgEnvVar = EnvGet(sEnvVar);
666 if (sOrgEnvVar <> '') then
668 /* Remove previously sToAdd if exists. (Changing sOrgEnvVar). */
669 i = pos(translate(sToAdd), translate(sOrgEnvVar));
671 sOrgEnvVar = substr(sOrgEnvVar, 1, i-1) || substr(sOrgEnvVar, i + length(sToAdd));
673 /* checks that sOrgEnvVar ends with a separator. Adds one if not. */
674 if (sOrgEnvVar = '') then
675 if (right(sOrgEnvVar,1) <> sSeparator) then
676 sOrgEnvVar = sOrgEnvVar || sSeparator;
679 /* set environment */
680 if (fRM) then return EnvSet(0, sEnvVar, sOrgEnvVar);
681 return EnvSet(0, sEnvVar, sOrgEnvVar||sToAdd);
685 * Sets sEnvVar to sValue.
688 parse arg fRM, sEnvVar, sValue
690 /* if we're to remove this
, make valuestring empty
! */
693 sEnvVar
= translate
(sEnvVar
);
696 * Begin
/EndLibpath fix
:
697 * We
'll have to set internal these using both commandline 'SET'
698 * and internal VALUE in order to export it and to be able to
699 * get it (with EnvGet) again.
701 if ((sEnvVar = 'BEGINLIBPATH
') | (sEnvVar = 'ENDLIBPATH
')) then
703 if (length(sValue) >= 1024) then
704 say 'Warning
: 'sEnvVar' is too long
,' length(sValue)' char.
';
705 return SysSetExtLibPath(sValue, substr(sEnvVar, 1, 1));
708 if (length(sValue) >= 1024) then
710 say 'Warning
: 'sEnvVar' is too long
,' length(sValue)' char.
';
711 say ' This may make
CMD.EXE unstable after a
SET operation to
print the environment.
';
713 sRc = VALUE(sEnvVar, sValue, 'OS2ENVIRONMENT
');
718 * Gets the value of sEnvVar.
722 if ((translate(sEnvVar) = 'BEGINLIBPATH
') | (translate(sEnvVar) = 'ENDLIBPATH
')) then
723 return SysQueryExtLibPath(substr(sEnvVar, 1, 1));
724 return value(sEnvVar,, 'OS2ENVIRONMENT
');
728 * Checks if a file exists.
729 * @param sFile Name of the file to look for.
730 * @param sComplain Complaint text. Complain if non empty and not found.
731 * @returns TRUE if file exists.
732 * FALSE if file doesn't exists.
734 FileExists
: procedure
735 parse arg sFile
, sComplain
736 rc
= stream
(sFile
, 'c', 'query exist');
737 if ((rc
= '') & (sComplain
<> '')) then
738 say sComplain
''''sFile
'''.';
743 * Checks
if a directory exists.
744 * @param sDir Name of the directory to look
for.
745 * @param sComplain Complaint text. Complain
if non empty and
not found.
746 * @returns TRUE
if file exists.
747 * FALSE
if file doesn
't exists.
750 parse arg sDir, sComplain
751 rc = SysFileTree(sDir, 'sDirs
', 'DO');
752 if (rc = 0 & sDirs.0 = 1) then
754 if (sComplain <> '') then
755 say sComplain ''''sDir'''.
';
760 * Workaround for bug in CMD.EXE.
761 * It messes up when REXX have expanded the environment.
765 /* check for 4OS2 first */
766 Address CMD 'set 4os2test_env
=%@eval
[2 + 2]';
767 if (value('4os2test_env
',, 'OS2ENVIRONMENT
') = '4') then
771 /* force environment expansion by setting a lot of variables and freeing them.
774 Address CMD '@
set dummyenvvar
'||i'=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
';
777 Address CMD '@
set dummyenvvar
'||i'=';
783 * Translate a string to lower case.
787 return translate(sString, 'abcdefghijklmnopqrstuvwxyz
', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ
');
791 * Gets the script directory.
793 GetScriptDir: procedure
795 * Assuming this script is in the root directory, we can determing
796 * the abs path to it by using the 'parse source
' feature in rexx.
798 parse source . . sScript
799 sScriptDir = filespec('drive
', sScript) || strip(filespec('path', sScript), 'T
', '\');
800 return ToLower
(sScriptDir
);