/****************************** Module Header ******************************* * * Module Name: run.erx * * EPM REXX * Execute an action for the current file in EPM, depending on its mode * or extension. * * This REXX command is called when the menu item "Run -> Run current file" * or the toolbar button "Run" was pressed. * * This is coded in REXX to let users adjust it to their needs easily: * * o Copy this file to your %NEPMD_USERDIR%\bin directory. * o Change or extend the "select" expression below. * o In your "when" block, set the var "Action" to the command that * shall be executed. * o In your "when" block, set the var "Msg" to override the default * message. * * Available vars: * * Filename.1 current filename * Filename.2 like Filename.1, but enclosed in doublequotes if it * contains spaces * Filename.3 like Filename.1, but without path * Path path of Filename.1, including the trailing backslash * Basename like Filename.3, but without extension * Ext extension, without the dot * UpExt extension in uppercase * Mode mode for Filename.1 * * Notes: * * o Temporary files, starting with a dot, are ignored. * o If current file is modified, it will be saved first. * * Copyright (c) Netlabs EPM Distribution Project 2002 * * $Id: run.erx 3835 2020-01-28 07:47:55Z aschn $ * * =========================================================================== * * 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. * ****************************************************************************/ rc = Init() if (rc <> 0) then exit( rc) /* Determine action from mode or extension */ Msg = '' Action = '' select /* CMD and REXX files */ when Mode = 'CMD' | UPExt = 'CMD' then /*Action = 'os2 /k /f 'filename.2*/ Action = 'Shell 'Filename.2 /* EPM macro files */ when UpExt = 'E' | (UpExt = 'LOG' & pos( 'RECOMPILENEW', translate( Basename)) = 1) then Action = 'Postme RecompileNew' /* TeX source files */ when wordpos( UpExt, 'TEX TEXI TEXINFO') > 0 then Action = 'Shell vlatex.cmd 'Filename.3 /* LaTeX macro documentation source files */ when wordpos( UpExt, 'DRV DTX FDD') > 0 then Action = 'Shell vlatex.cmd 'Filename.3 /* C files */ when UpExt = 'C' then /*Action = 'os2 /k /f wcc386 'Filename.1*/ /*Action = 'os2 /k /f gcc 'Filename.1*/ Action = 'Shell nmake /nologo all' /* EPM REXX files */ when Mode = 'REXX' & UpExt = 'ERX' then Action = 'Postme Rx 'Filename.2 /* HTML files */ when Mode = 'HTML' then Action = 'OpenUrl 'Filename.2 otherwise do Msg = 'RUN.ERX: No action defined for this mode. Opening file...' Action = 'OpenObject' Filename.2 end end /* select */ /* Execute action */ if Msg <> '' then 'sayerror 'Msg else 'sayerror RUN.ERX: Executing 'Action Action /* /* Restore directory */ call directory '\' call directory SavedDir */ exit /*-------------------------------------------------------------------------*/ Init: rc = 0 rcx = setlocal() /* Get .filename and .modify fields */ 'Extract /filename/modify' /* Don't act on temp files */ if left( Filename.1, 1) = '.' then exit /* Save current file if modified */ if modify.1 > 0 then do 'Save' if rc <> 0 then return( rc) 'Refresh' /* refresh the bars before further actions */ end /* Get current .erx file */ parse source . . ThisFile /* Avoid endless loop when ThisFile executes itself */ if translate(ThisFile) = translate(Filename.1) then exit /* Get mode array field */ Mode = GetMode() /* Change to dir of current file */ SavedDir = directory() call directory '\' call directory Filename.1'\..' /* Filename.2: add ".." for spaces in Filename.1 */ if pos( ' ', Filename.1) > 0 then Filename.2 = '"'Filename.1'"' else Filename.2 = Filename.1 /* Filename.3: strip Path, use name only */ lp = lastpos( '\', Filename.1) Filename.3 = substr( Filename.1, lp + 1) Path = substr( Filename.1, 1, lp) /* Ext and Basename */ p = pos( '.', Filename.3) if p > 1 then do Ext = substr( Filename.3, p + 1) Basename = substr( Filename.3, 1, p - 1) end else do Ext = '' Basename = Filename.3 end UpExt = translate( Ext) /*'sayerror Mode for "'Filename.1'" = "'Mode'", UpExt = "'UpExt'"'*/ return( 0) /*-------------------------------------------------------------------------*/ GetMode: procedure 'SaveUserstring' 'FileAVar2Userstring mode' 'extract /userstring' Mode = userstring.1 'RestoreUserstring' return Mode