/****************************** Module Header ******************************* * * Module Name: open.erx * * Copyright (c) Netlabs EPM Distribution Project 2002 * * $Id$ * * =========================================================================== * * This file is part of the Netlabs EPM Distribution package and is free * software. You can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * Netlabs EPM Distribution. This library is distributed in the hope that it * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * ****************************************************************************/ /* ERX (EPM-REXX) */ /* Opens arg(1). */ /* To be called from an EPM command line. */ /* */ /* Syntax: rx Open [object, [setup_string]] */ /* */ /* object may contain a relative filespec if it is a directory. */ /* Both args are submitted to SysSetObjectData. */ /* If setup_string is not specified, then OPEN=DEFAULT is assumed. */ env = 'OS2ENVIRONMENT' ObjectType = '' call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' call SysLoadFuncs parse arg args if left( args, 1) = '"' then /* object may be surrounded with doublequotes */ do parse value args with '"'arg1'"'rest parse value rest with ',' arg2 end /* do */ else parse value args with arg1',' arg2 Object = strip( arg1) Setup = strip( arg2) /*'sayerror Object = ['Object'], Setup = ['Setup']'*/ if Object = '' then return 1 if Setup = '' then Setup = 'OPEN=DEFAULT' /* resolve envvars */ Object = ResolveEnvVars( Object) /* test if dir and resolve filespec */ CurDir = directory() next = directory(Object) /* this resolves also: Filename'\..' */ call directory CurDir if next <> '' then /* if dir exists */ do Object = next ObjectType = 'FOLDER' end /* do */ /* open the object */ if ObjectType = 'FOLDER' then /* doesn't identify object ids for folders */ n = 2 else n = 1 /* better do it only once for other objects to avoid unhiding of */ /* minimized cmd windows */ do n /* the 2nd call is for to make it the topmost window */ rc = SysSetObjectData( Object, Setup) if rc <> 1 then /* rc = 1 ==> ok */ leave end /* do 2 */ return 0 ResolveEnvVars: Spec = arg(1) startp = 1 do forever p1 = pos( '%', Spec, startp) if p1 = 0 then leave startp = p1 + 1 p2 = pos( '%', Spec, startp) if p2 = 0 then leave else do startp = p2 + 1 Spec = substr( Spec, 1, p1 - 1) ||, value( substr( Spec, p1 + 1, p2 - p1 - 1), , env) ||, substr( Spec, p2 + 1 ) end end /* forever */ /* resolve ?: */ do while pos( '?:', Spec) <> 0 parse value Spec with first '?:' rest Spec = first''GetBootDrive()''rest end /* do while */ return Spec GetBootDrive: procedure if RxfuncQuery('SysBootDrive') = 0 then BootDrive = SysBootDrive() else do Path = value( 'PATH', , env) parse upper value Path with '\OS2\SYSTEM' -2 BootDrive +2 end /* do */ return BootDrive